1 /*
2 * Copyright (c) 2013-2014 Mozilla Corporation
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * Opus parser
24 *
25 * Determines the duration for each packet.
26 */
27
35
43
45 {
46 const uint8_t *buf = start + 1;
47 int start_trim_flag, end_trim_flag, control_extension_flag, control_extension_length;
49 uint64_t payload_len_tmp;
50
53
54 flags = bytestream2_get_byte(&gb);
55 start_trim_flag = (
flags >> 4) & 1;
56 end_trim_flag = (
flags >> 3) & 1;
57 control_extension_flag = (
flags >> 2) & 1;
58
59 payload_len_tmp = *payload_len = 0;
60 while (bytestream2_peek_byte(&gb) == 0xff)
61 payload_len_tmp += bytestream2_get_byte(&gb);
62
63 payload_len_tmp += bytestream2_get_byte(&gb);
64
65 if (start_trim_flag)
67 if (end_trim_flag)
69 if (control_extension_flag) {
70 control_extension_length = bytestream2_get_byte(&gb);
72 }
73
76
77 *payload_len = payload_len_tmp;
78
80 }
81
83 const uint8_t *buf, int buf_size)
84 {
86
90 }
91
93
94 return 0;
95 }
96
97 /**
98 * Find the end of the current frame in the bitstream.
99 * @return the position of the first byte of the next frame, or -1
100 */
102 const uint8_t *buf, int buf_size, int *header_len)
103 {
106 int ret, start_found,
i = 0, payload_len = 0;
107 const uint8_t *payload;
109 uint16_t hdr;
110 *header_len = 0;
111
112 if (!buf_size)
113 return 0;
114
117 payload = buf;
118
119 /* Check if we're using Opus in MPEG-TS framing */
120 if (!
s->ts_framing && buf_size > 2) {
124 }
125
126 if (
s->ts_framing && !start_found) {
127 for (
i = 0;
i < buf_size-2;
i++) {
131 if (!payload) {
134 }
135 *header_len = payload - buf;
136 start_found = 1;
137 break;
138 }
139 }
140 }
141
143 payload_len = buf_size;
144
145 if (payload_len <= buf_size && (!
s->ts_framing || start_found)) {
150 }
151 }
152
154 if (start_found) {
155 if (payload_len + *header_len <= buf_size) {
158 return payload_len + *header_len;
159 }
160 }
161
165 }
166
167 return buf_size;
168 }
169
171 const uint8_t **poutbuf, int *poutbuf_size,
172 const uint8_t *buf, int buf_size)
173 {
176 int next, header_len = 0;
177
179
180 if (avctx->
extradata && !
s->extradata_parsed) {
184 }
186 s->extradata_parsed = 1;
187 }
188
190 next = buf_size;
191
194 } else {
196
200 }
201
204 }
205 }
206
207 *poutbuf = buf + header_len;
208 *poutbuf_size = buf_size - header_len;
209 return next;
210
213 *poutbuf_size = 0;
214 return buf_size;
215 }
216
222 };