1 /*
2 * Opus parser for Ogg
3 * Copyright (c) 2012 Nicolas George
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <string.h>
23
28
33 };
34
35 #define OPUS_SEEK_PREROLL_MS 80
36 #define OPUS_HEAD_SIZE 19
37
39 {
46
47 if (!priv) {
49 if (!priv)
51 }
52
59
63 /*orig_sample_rate = AV_RL32(packet + 12);*/
64 /*gain = AV_RL16(packet + 16);*/
65 /*channel_map = AV_RL8 (packet + 18);*/
66
69
71
77 return 1;
78 }
79
81 if (os->
psize < 8 || memcmp(packet,
"OpusTags", 8))
85 return 1;
86 }
87
88 return 0;
89 }
90
92 {
93 unsigned nb_frames = 1;
94 unsigned toc =
src[0];
95 unsigned toc_config = toc >> 3;
96 unsigned toc_count = toc & 3;
97 unsigned frame_size = toc_config < 12 ?
FFMAX(480, 960 * (toc_config & 3)) :
98 toc_config < 16 ? 480 << (toc_config & 1) :
99 120 << (toc_config & 3);
100 if (toc_count == 3) {
103 nb_frames =
src[1] & 0x3F;
104 } else if (toc_count) {
105 nb_frames = 2;
106 }
107
109 }
110
112 {
119
122 if (os->
granule > (1LL << 62)) {
125 }
126
130 uint8_t *last_pkt = os->
buf + os->
pstart;
131 uint8_t *next_pkt = last_pkt;
132
138 return 0;
139 }
141 last_pkt = next_pkt = next_pkt + os->
psize;
142 for (; seg < os->
nsegs; seg++) {
144 if (os->
segments[seg] < 255 && next_pkt != last_pkt) {
148 last_pkt = next_pkt;
149 }
150 }
153 }
154
157
163 }
164
169 if (skip > 0) {
173 "Last packet was truncated to %d due to end trimming.\n",
175 }
176 }
177
178 return 0;
179 }
180
183 .magic = "OpusHead",
184 .magicsize = 8,
187 .nb_header = 1,
188 };