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
29
34 };
35
36 #define OPUS_SEEK_PREROLL_MS 80
37 #define OPUS_HEAD_SIZE 19
38
41 size_t psize)
42 {
45
48
51
57 }
58
60
64 /*orig_sample_rate = AV_RL32(packet + 12);*/
65 /*gain = AV_RL16(packet + 16);*/
66 /*channel_map = AV_RL8 (packet + 18);*/
67
71
73
78
80
81 return 1;
82 }
83
85 {
91
92 if (!priv) {
94 if (!priv)
96 }
97
100
102 if (os->
psize < 8 || memcmp(packet,
"OpusTags", 8))
106 return 1;
107 }
108
109 return 0;
110 }
111
113 {
114 unsigned nb_frames = 1;
115 unsigned toc =
src[0];
116 unsigned toc_config = toc >> 3;
117 unsigned toc_count = toc & 3;
118 unsigned frame_size = toc_config < 12 ?
FFMAX(480, 960 * (toc_config & 3)) :
119 toc_config < 16 ? 480 << (toc_config & 1) :
120 120 << (toc_config & 3);
121 if (toc_count == 3) {
124 nb_frames =
src[1] & 0x3F;
125 } else if (toc_count) {
126 nb_frames = 2;
127 }
128
130 }
131
133 {
140
143 if (os->
granule > (1LL << 62)) {
146 }
147
148 if (os->
psize > 8 && !memcmp(packet,
"OpusHead", 8)) {
152
153 return 1;
154 }
155
156 if (os->
psize > 8 && !memcmp(packet,
"OpusTags", 8)) {
161
163 return 1;
164 }
165
167 int seg, d;
169 uint8_t *last_pkt = os->
buf + os->
pstart;
170 uint8_t *next_pkt = last_pkt;
171
175 if (d < 0) {
177 return 0;
178 }
180 last_pkt = next_pkt = next_pkt + os->
psize;
181 for (; seg < os->
nsegs; seg++) {
183 if (os->
segments[seg] < 255 && next_pkt != last_pkt) {
185 if (d > 0)
187 last_pkt = next_pkt;
188 }
189 }
192 }
193
196
202 }
203
212 "Last packet was truncated to %d due to end trimming.\n",
214 }
215 }
216
217 return 0;
218 }
219
222 .magic = "OpusHead",
223 .magicsize = 8,
226 .nb_header = 1,
227 };