1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
24
26 {
30 }
31
33 {
37 }
38
41 {
42 void (*free_func)(void*, uint8_t*);
43
47
52 else
54
55 if (free_func) {
62 } else {
64 }
68 }
70
71 return 0;
72 }
73
75 {
76 void *ptr;
77 int old_count =
list->nb_messages_allocated;
78
80 if (
list->nb_messages + 1 > old_count) {
81 int new_count = 2 * old_count + 1;
82
84 new_count,
sizeof(*
list->messages));
85 if (!ptr)
87
89 list->nb_messages_allocated = new_count;
90
91 // Zero the newly-added entries.
92 memset(
list->messages + old_count, 0,
93 (new_count - old_count) *
sizeof(*
list->messages));
94 }
96 return 0;
97 }
98
100 {
101 for (
int i = 0;
i <
list->nb_messages;
i++) {
105 }
107 }
108
111 int prefix,
113 {
115 int sei_type, highest_vcl_type, err,
i, position;
116
117 switch (
ctx->codec->codec_id) {
119 // (We can ignore auxiliary slices because we only have prefix
120 // SEI in H.264 and an auxiliary picture must always follow a
121 // primary picture.)
123 if (prefix)
125 else
127 break;
130 if (prefix)
132 else
134 break;
135 default:
137 }
138
139 // Find an existing SEI NAL unit of the right type.
144 break;
145 }
146 }
147
148 if (unit) {
149 *sei_unit = unit;
150 return 0;
151 }
152
153 // Need to add a new SEI NAL unit ...
154 if (prefix) {
155 // ... before the first VCL NAL unit.
158 break;
159 }
161 } else {
162 // ... after the last VCL NAL unit.
165 break;
166 }
168 // No VCL units; just put it at the end.
170 } else {
172 }
173 }
174
177 if (err < 0)
178 return err;
179 unit = &au->
units[position];
180 unit->
type = sei_type;
181
183 if (err < 0)
184 return err;
185
186 switch (
ctx->codec->codec_id) {
188 {
190 .nal_unit_header = {
191 .nal_ref_idc = 0,
192 .nal_unit_type = sei_type,
193 },
194 };
196 }
197 break;
199 {
201 .nal_unit_header = {
202 .nal_unit_type = sei_type,
203 .nuh_layer_id = 0,
204 .nuh_temporal_id_plus1 = 1,
205 },
206 };
208 }
209 break;
210 default:
212 }
213
214 *sei_unit = unit;
215 return 0;
216 }
217
221 {
222 switch (
ctx->codec->codec_id) {
224 {
229 }
230 break;
232 {
238 }
239 break;
240 default:
242 }
243
244 return 0;
245 }
246
249 int prefix,
250 uint32_t payload_type,
251 void *payload_data,
253 {
259 int err;
260
264
265 // Find an existing SEI unit or make a new one to add to.
267 if (err < 0)
268 return err;
269
270 // Find the message list inside the codec-dependent unit.
272 if (err < 0)
273 return err;
274
275 // Add a new message to the message list.
277 if (err < 0)
278 return err;
279
280 if (payload_buf) {
282 if (!payload_ref)
284 } else {
286 }
287
289
290 message->payload_type = payload_type;
291 message->payload = payload_data;
292 message->payload_ref = payload_ref;
293
294 return 0;
295 }
296
299 uint32_t payload_type,
301 {
302 int err,
i, j, found;
303
304 found = 0;
308
310 if (err < 0)
311 continue;
312
313 for (j = 0; j <
list->nb_messages; j++) {
315
316 if (
message->payload_type == payload_type) {
317 if (!*iter || found) {
319 return 0;
320 }
322 found = 1;
323 }
324 }
325 }
326
328 }
329
331 int position)
332 {
334
335 av_assert0(0 <= position && position < list->nb_messages);
336
340
342
343 if (
list->nb_messages > 0) {
344 memmove(
list->messages + position,
345 list->messages + position + 1,
346 (
list->nb_messages - position) *
sizeof(*
list->messages));
347 }
348 }
349
352 uint32_t payload_type)
353 {
355
359
361 if (err < 0)
362 continue;
363
364 for (j =
list->nb_messages - 1; j >= 0; j--) {
365 if (
list->messages[j].payload_type == payload_type)
367 }
368 }
369 }