FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/decode.c
Date: 2025-06-01 09:29:47
Exec Total Coverage
Lines: 800 1203 66.5%
Functions: 66 69 95.7%
Branches: 489 851 57.5%

Line Branch Exec Source
1 /*
2 * generic decoding-related code
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 #include <stdint.h>
22 #include <stdbool.h>
23 #include <string.h>
24
25 #include "config.h"
26
27 #if CONFIG_ICONV
28 # include <iconv.h>
29 #endif
30
31 #include "libavutil/avassert.h"
32 #include "libavutil/channel_layout.h"
33 #include "libavutil/common.h"
34 #include "libavutil/emms.h"
35 #include "libavutil/frame.h"
36 #include "libavutil/hwcontext.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/internal.h"
39 #include "libavutil/mastering_display_metadata.h"
40 #include "libavutil/mem.h"
41 #include "libavutil/stereo3d.h"
42
43 #include "avcodec.h"
44 #include "avcodec_internal.h"
45 #include "bytestream.h"
46 #include "bsf.h"
47 #include "codec_desc.h"
48 #include "codec_internal.h"
49 #include "decode.h"
50 #include "hwaccel_internal.h"
51 #include "hwconfig.h"
52 #include "internal.h"
53 #include "lcevcdec.h"
54 #include "packet_internal.h"
55 #include "progressframe.h"
56 #include "libavutil/refstruct.h"
57 #include "thread.h"
58 #include "threadprogress.h"
59
60 typedef struct DecodeContext {
61 AVCodecInternal avci;
62
63 /**
64 * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
65 * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
66 * to set the flag generically.
67 */
68 int intra_only_flag;
69
70 /**
71 * This is set to AV_PICTURE_TYPE_I for intra only video decoders
72 * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
73 * the AVFrame's pict_type before the decoder receives it.
74 */
75 enum AVPictureType initial_pict_type;
76
77 /* to prevent infinite loop on errors when draining */
78 int nb_draining_errors;
79
80 /**
81 * The caller has submitted a NULL packet on input.
82 */
83 int draining_started;
84
85 int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far
86 int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far
87 int64_t pts_correction_last_pts; /// PTS of the last frame
88 int64_t pts_correction_last_dts; /// DTS of the last frame
89
90 /**
91 * Bitmask indicating for which side data types we prefer user-supplied
92 * (global or attached to packets) side data over bytestream.
93 */
94 uint64_t side_data_pref_mask;
95
96 FFLCEVCContext *lcevc;
97 int lcevc_frame;
98 int width;
99 int height;
100 } DecodeContext;
101
102 4349563 static DecodeContext *decode_ctx(AVCodecInternal *avci)
103 {
104 4349563 return (DecodeContext *)avci;
105 }
106
107 388604 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
108 {
109 int ret;
110 size_t size;
111 const uint8_t *data;
112 uint32_t flags;
113 int64_t val;
114
115 388604 data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size);
116
2/2
✓ Branch 0 taken 388602 times.
✓ Branch 1 taken 2 times.
388604 if (!data)
117 388602 return 0;
118
119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!(avctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE)) {
120 av_log(avctx, AV_LOG_ERROR, "This decoder does not support parameter "
121 "changes, but PARAM_CHANGE side data was sent to it.\n");
122 ret = AVERROR(EINVAL);
123 goto fail2;
124 }
125
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (size < 4)
127 goto fail;
128
129 2 flags = bytestream_get_le32(&data);
130 2 size -= 4;
131
132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
133 if (size < 4)
134 goto fail;
135 val = bytestream_get_le32(&data);
136 if (val <= 0 || val > INT_MAX) {
137 av_log(avctx, AV_LOG_ERROR, "Invalid sample rate");
138 ret = AVERROR_INVALIDDATA;
139 goto fail2;
140 }
141 avctx->sample_rate = val;
142 size -= 4;
143 }
144
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (size < 8)
146 goto fail;
147 2 avctx->width = bytestream_get_le32(&data);
148 2 avctx->height = bytestream_get_le32(&data);
149 2 size -= 8;
150 2 ret = ff_set_dimensions(avctx, avctx->width, avctx->height);
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0)
152 goto fail2;
153 }
154
155 2 return 0;
156 fail:
157 av_log(avctx, AV_LOG_ERROR, "PARAM_CHANGE side data too small.\n");
158 ret = AVERROR_INVALIDDATA;
159 fail2:
160 if (ret < 0) {
161 av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n");
162 if (avctx->err_recognition & AV_EF_EXPLODE)
163 return ret;
164 }
165 return 0;
166 }
167
168 388604 static int extract_packet_props(AVCodecInternal *avci, const AVPacket *pkt)
169 {
170 388604 int ret = 0;
171
172 388604 av_packet_unref(avci->last_pkt_props);
173
1/2
✓ Branch 0 taken 388604 times.
✗ Branch 1 not taken.
388604 if (pkt) {
174 388604 ret = av_packet_copy_props(avci->last_pkt_props, pkt);
175 }
176 388604 return ret;
177 }
178
179 15470 static int decode_bsfs_init(AVCodecContext *avctx)
180 {
181 15470 AVCodecInternal *avci = avctx->internal;
182 15470 const FFCodec *const codec = ffcodec(avctx->codec);
183 int ret;
184
185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if (avci->bsf)
186 return 0;
187
188 15470 ret = av_bsf_list_parse_str(codec->bsfs, &avci->bsf);
189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if (ret < 0) {
190 av_log(avctx, AV_LOG_ERROR, "Error parsing decoder bitstream filters '%s': %s\n", codec->bsfs, av_err2str(ret));
191 if (ret != AVERROR(ENOMEM))
192 ret = AVERROR_BUG;
193 goto fail;
194 }
195
196 /* We do not currently have an API for passing the input timebase into decoders,
197 * but no filters used here should actually need it.
198 * So we make up some plausible-looking number (the MPEG 90kHz timebase) */
199 15470 avci->bsf->time_base_in = (AVRational){ 1, 90000 };
200 15470 ret = avcodec_parameters_from_context(avci->bsf->par_in, avctx);
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if (ret < 0)
202 goto fail;
203
204 15470 ret = av_bsf_init(avci->bsf);
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if (ret < 0)
206 goto fail;
207 15470 ret = avcodec_parameters_to_context(avctx, avci->bsf->par_out);
208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if (ret < 0)
209 goto fail;
210
211 15470 return 0;
212 fail:
213 av_bsf_free(&avci->bsf);
214 return ret;
215 }
216
217 #if !HAVE_THREADS
218 #define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG)
219 #define ff_thread_receive_frame(avctx, frame) (AVERROR_BUG)
220 #endif
221
222 1168520 static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
223 {
224 1168520 AVCodecInternal *avci = avctx->internal;
225 int ret;
226
227 1168520 ret = av_bsf_receive_packet(avci->bsf, pkt);
228
2/2
✓ Branch 0 taken 779916 times.
✓ Branch 1 taken 388604 times.
1168520 if (ret < 0)
229 779916 return ret;
230
231
1/2
✓ Branch 1 taken 388604 times.
✗ Branch 2 not taken.
388604 if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
232 388604 ret = extract_packet_props(avctx->internal, pkt);
233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 388604 times.
388604 if (ret < 0)
234 goto finish;
235 }
236
237 388604 ret = apply_param_change(avctx, pkt);
238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 388604 times.
388604 if (ret < 0)
239 goto finish;
240
241 388604 return 0;
242 finish:
243 av_packet_unref(pkt);
244 return ret;
245 }
246
247 777826 int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
248 {
249 777826 AVCodecInternal *avci = avctx->internal;
250 777826 DecodeContext *dc = decode_ctx(avci);
251
252
2/2
✓ Branch 0 taken 193 times.
✓ Branch 1 taken 777633 times.
777826 if (avci->draining)
253 193 return AVERROR_EOF;
254
255 /* If we are a worker thread, get the next packet from the threading
256 * context. Otherwise we are the main (user-facing) context, so we get the
257 * next packet from the input filterchain.
258 */
259
2/2
✓ Branch 0 taken 776557 times.
✓ Branch 1 taken 1076 times.
777633 if (avctx->internal->is_frame_mt)
260 1076 return ff_thread_get_packet(avctx, pkt);
261
262 391963 while (1) {
263 1168520 int ret = decode_get_packet(avctx, pkt);
264
2/2
✓ Branch 0 taken 776493 times.
✓ Branch 1 taken 392027 times.
1168520 if (ret == AVERROR(EAGAIN) &&
265
5/6
✓ Branch 0 taken 387953 times.
✓ Branch 1 taken 388540 times.
✓ Branch 2 taken 387953 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3423 times.
✓ Branch 5 taken 384530 times.
776493 (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) {
266 391963 ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt);
267
1/2
✓ Branch 0 taken 391963 times.
✗ Branch 1 not taken.
391963 if (ret >= 0)
268 391963 continue;
269
270 av_packet_unref(avci->buffer_pkt);
271 }
272
273
2/2
✓ Branch 0 taken 3423 times.
✓ Branch 1 taken 773134 times.
776557 if (ret == AVERROR_EOF)
274 3423 avci->draining = 1;
275 776557 return ret;
276 }
277 }
278
279 /**
280 * Attempt to guess proper monotonic timestamps for decoded video frames
281 * which might have incorrect times. Input timestamps may wrap around, in
282 * which case the output will as well.
283 *
284 * @param pts the pts field of the decoded AVPacket, as passed through
285 * AVFrame.pts
286 * @param dts the dts field of the decoded AVPacket
287 * @return one of the input values, may be AV_NOPTS_VALUE
288 */
289 406724 static int64_t guess_correct_pts(DecodeContext *dc,
290 int64_t reordered_pts, int64_t dts)
291 {
292 406724 int64_t pts = AV_NOPTS_VALUE;
293
294
2/2
✓ Branch 0 taken 316652 times.
✓ Branch 1 taken 90072 times.
406724 if (dts != AV_NOPTS_VALUE) {
295 316652 dc->pts_correction_num_faulty_dts += dts <= dc->pts_correction_last_dts;
296 316652 dc->pts_correction_last_dts = dts;
297
2/2
✓ Branch 0 taken 359 times.
✓ Branch 1 taken 89713 times.
90072 } else if (reordered_pts != AV_NOPTS_VALUE)
298 359 dc->pts_correction_last_dts = reordered_pts;
299
300
2/2
✓ Branch 0 taken 316268 times.
✓ Branch 1 taken 90456 times.
406724 if (reordered_pts != AV_NOPTS_VALUE) {
301 316268 dc->pts_correction_num_faulty_pts += reordered_pts <= dc->pts_correction_last_pts;
302 316268 dc->pts_correction_last_pts = reordered_pts;
303
2/2
✓ Branch 0 taken 743 times.
✓ Branch 1 taken 89713 times.
90456 } else if(dts != AV_NOPTS_VALUE)
304 743 dc->pts_correction_last_pts = dts;
305
306
4/4
✓ Branch 0 taken 569 times.
✓ Branch 1 taken 406155 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 557 times.
406724 if ((dc->pts_correction_num_faulty_pts<=dc->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE)
307
2/2
✓ Branch 0 taken 315711 times.
✓ Branch 1 taken 90456 times.
406167 && reordered_pts != AV_NOPTS_VALUE)
308 315711 pts = reordered_pts;
309 else
310 91013 pts = dts;
311
312 406724 return pts;
313 }
314
315 261126 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
316 {
317 261126 AVCodecInternal *avci = avctx->internal;
318 AVFrameSideData *side;
319 261126 uint32_t discard_padding = 0;
320 261126 uint8_t skip_reason = 0;
321 261126 uint8_t discard_reason = 0;
322
323 261126 side = av_frame_get_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES);
324
3/4
✓ Branch 0 taken 123 times.
✓ Branch 1 taken 261003 times.
✓ Branch 2 taken 123 times.
✗ Branch 3 not taken.
261126 if (side && side->size >= 10) {
325 123 avci->skip_samples = AV_RL32(side->data);
326 123 avci->skip_samples = FFMAX(0, avci->skip_samples);
327 123 discard_padding = AV_RL32(side->data + 4);
328 123 av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
329 avci->skip_samples, (int)discard_padding);
330 123 skip_reason = AV_RL8(side->data + 8);
331 123 discard_reason = AV_RL8(side->data + 9);
332 }
333
334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 261126 times.
261126 if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
335 if (!side && (avci->skip_samples || discard_padding))
336 side = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10);
337 if (side && (avci->skip_samples || discard_padding)) {
338 AV_WL32(side->data, avci->skip_samples);
339 AV_WL32(side->data + 4, discard_padding);
340 AV_WL8(side->data + 8, skip_reason);
341 AV_WL8(side->data + 9, discard_reason);
342 avci->skip_samples = 0;
343 }
344 return 0;
345 }
346 261126 av_frame_remove_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES);
347
348
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 261106 times.
261126 if ((frame->flags & AV_FRAME_FLAG_DISCARD)) {
349 20 avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
350 20 *discarded_samples += frame->nb_samples;
351 20 return AVERROR(EAGAIN);
352 }
353
354
2/2
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 260877 times.
261106 if (avci->skip_samples > 0) {
355
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 71 times.
229 if (frame->nb_samples <= avci->skip_samples){
356 158 *discarded_samples += frame->nb_samples;
357 158 avci->skip_samples -= frame->nb_samples;
358 158 av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
359 avci->skip_samples);
360 158 return AVERROR(EAGAIN);
361 } else {
362 71 av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
363 71 frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
364
3/4
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
140 if (avctx->pkt_timebase.num && avctx->sample_rate) {
365 69 int64_t diff_ts = av_rescale_q(avci->skip_samples,
366 69 (AVRational){1, avctx->sample_rate},
367 avctx->pkt_timebase);
368
1/2
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
69 if (frame->pts != AV_NOPTS_VALUE)
369 69 frame->pts += diff_ts;
370
1/2
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
69 if (frame->pkt_dts != AV_NOPTS_VALUE)
371 69 frame->pkt_dts += diff_ts;
372
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 3 times.
69 if (frame->duration >= diff_ts)
373 66 frame->duration -= diff_ts;
374 } else
375 2 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
376
377 71 av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
378 avci->skip_samples, frame->nb_samples);
379 71 *discarded_samples += avci->skip_samples;
380 71 frame->nb_samples -= avci->skip_samples;
381 71 avci->skip_samples = 0;
382 }
383 }
384
385
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 260937 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
260948 if (discard_padding > 0 && discard_padding <= frame->nb_samples) {
386
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
11 if (discard_padding == frame->nb_samples) {
387 2 *discarded_samples += frame->nb_samples;
388 2 return AVERROR(EAGAIN);
389 } else {
390
3/4
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
9 if (avctx->pkt_timebase.num && avctx->sample_rate) {
391 5 int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
392 5 (AVRational){1, avctx->sample_rate},
393 avctx->pkt_timebase);
394 5 frame->duration = diff_ts;
395 } else
396 4 av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
397
398 9 av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
399 (int)discard_padding, frame->nb_samples);
400 9 frame->nb_samples -= discard_padding;
401 }
402 }
403
404 260946 return 0;
405 }
406
407 /*
408 * The core of the receive_frame_wrapper for the decoders implementing
409 * the simple API. Certain decoders might consume partial packets without
410 * returning any output, so this function needs to be called in a loop until it
411 * returns EAGAIN.
412 **/
413 784205 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
414 {
415 784205 AVCodecInternal *avci = avctx->internal;
416 784205 DecodeContext *dc = decode_ctx(avci);
417 784205 AVPacket *const pkt = avci->in_pkt;
418 784205 const FFCodec *const codec = ffcodec(avctx->codec);
419 int got_frame, consumed;
420 int ret;
421
422
4/4
✓ Branch 0 taken 755586 times.
✓ Branch 1 taken 28619 times.
✓ Branch 2 taken 754300 times.
✓ Branch 3 taken 1286 times.
784205 if (!pkt->data && !avci->draining) {
423 754300 av_packet_unref(pkt);
424 754300 ret = ff_decode_get_packet(avctx, pkt);
425
4/4
✓ Branch 0 taken 376872 times.
✓ Branch 1 taken 377428 times.
✓ Branch 2 taken 373653 times.
✓ Branch 3 taken 3219 times.
754300 if (ret < 0 && ret != AVERROR_EOF)
426 373653 return ret;
427 }
428
429 // Some codecs (at least wma lossless) will crash when feeding drain packets
430 // after EOF was signaled.
431
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 409988 times.
410552 if (avci->draining_done)
432 564 return AVERROR_EOF;
433
434
2/2
✓ Branch 0 taken 3941 times.
✓ Branch 1 taken 406047 times.
409988 if (!pkt->data &&
435
2/2
✓ Branch 0 taken 2723 times.
✓ Branch 1 taken 1218 times.
3941 !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
436 2723 return AVERROR_EOF;
437
438 407265 got_frame = 0;
439
440 407265 frame->pict_type = dc->initial_pict_type;
441 407265 frame->flags |= dc->intra_only_flag;
442 407265 consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
443
444
1/2
✓ Branch 0 taken 407265 times.
✗ Branch 1 not taken.
407265 if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
445 407265 frame->pkt_dts = pkt->dts;
446 407265 emms_c();
447
448
2/2
✓ Branch 0 taken 146564 times.
✓ Branch 1 taken 260701 times.
407265 if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
449
2/2
✓ Branch 0 taken 178 times.
✓ Branch 1 taken 135705 times.
282447 ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
450 ? AVERROR(EAGAIN)
451
2/2
✓ Branch 0 taken 135883 times.
✓ Branch 1 taken 10681 times.
282447 : 0;
452
1/2
✓ Branch 0 taken 260701 times.
✗ Branch 1 not taken.
260701 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
453 260701 ret = !got_frame ? AVERROR(EAGAIN)
454
2/2
✓ Branch 0 taken 259317 times.
✓ Branch 1 taken 1384 times.
260701 : discard_samples(avctx, frame, discarded_samples);
455 } else
456 av_assert0(0);
457
458
2/2
✓ Branch 0 taken 12423 times.
✓ Branch 1 taken 394842 times.
407265 if (ret == AVERROR(EAGAIN))
459 12423 av_frame_unref(frame);
460
461 // FF_CODEC_CB_TYPE_DECODE decoders must not return AVERROR EAGAIN
462 // code later will add AVERROR(EAGAIN) to a pointer
463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 407265 times.
407265 av_assert0(consumed != AVERROR(EAGAIN));
464
2/2
✓ Branch 0 taken 665 times.
✓ Branch 1 taken 406600 times.
407265 if (consumed < 0)
465 665 ret = consumed;
466
4/4
✓ Branch 0 taken 406600 times.
✓ Branch 1 taken 665 times.
✓ Branch 2 taken 145939 times.
✓ Branch 3 taken 260661 times.
407265 if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
467 145939 consumed = pkt->size;
468
469
2/2
✓ Branch 0 taken 394842 times.
✓ Branch 1 taken 12423 times.
407265 if (!ret)
470
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 394842 times.
394842 av_assert0(frame->buf[0]);
471
2/2
✓ Branch 0 taken 11758 times.
✓ Branch 1 taken 395507 times.
407265 if (ret == AVERROR(EAGAIN))
472 11758 ret = 0;
473
474 /* do not stop draining when got_frame != 0 or ret < 0 */
475
4/4
✓ Branch 0 taken 1218 times.
✓ Branch 1 taken 406047 times.
✓ Branch 2 taken 565 times.
✓ Branch 3 taken 653 times.
407265 if (avci->draining && !got_frame) {
476
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 564 times.
565 if (ret < 0) {
477 /* prevent infinite loop if a decoder wrongly always return error on draining */
478 /* reasonable nb_errors_max = maximum b frames + thread count */
479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 int nb_errors_max = 20 + (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME ?
480 avctx->thread_count : 1);
481
482
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (decode_ctx(avci)->nb_draining_errors++ >= nb_errors_max) {
483 av_log(avctx, AV_LOG_ERROR, "Too many errors when draining, this is a bug. "
484 "Stop draining and force EOF.\n");
485 avci->draining_done = 1;
486 ret = AVERROR_BUG;
487 }
488 } else {
489 564 avci->draining_done = 1;
490 }
491 }
492
493
4/4
✓ Branch 0 taken 29299 times.
✓ Branch 1 taken 377966 times.
✓ Branch 2 taken 665 times.
✓ Branch 3 taken 28634 times.
407265 if (consumed >= pkt->size || ret < 0) {
494 378631 av_packet_unref(pkt);
495 } else {
496 28634 pkt->data += consumed;
497 28634 pkt->size -= consumed;
498 28634 pkt->pts = AV_NOPTS_VALUE;
499 28634 pkt->dts = AV_NOPTS_VALUE;
500
1/2
✓ Branch 0 taken 28634 times.
✗ Branch 1 not taken.
28634 if (!(codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
501 28634 avci->last_pkt_props->pts = AV_NOPTS_VALUE;
502 28634 avci->last_pkt_props->dts = AV_NOPTS_VALUE;
503 }
504 }
505
506 407265 return ret;
507 }
508
509 #if CONFIG_LCMS2
510 static int detect_colorspace(AVCodecContext *avctx, AVFrame *frame)
511 {
512 AVCodecInternal *avci = avctx->internal;
513 enum AVColorTransferCharacteristic trc;
514 AVColorPrimariesDesc coeffs;
515 enum AVColorPrimaries prim;
516 cmsHPROFILE profile;
517 AVFrameSideData *sd;
518 int ret;
519 if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
520 return 0;
521
522 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_ICC_PROFILE);
523 if (!sd || !sd->size)
524 return 0;
525
526 if (!avci->icc.avctx) {
527 ret = ff_icc_context_init(&avci->icc, avctx);
528 if (ret < 0)
529 return ret;
530 }
531
532 profile = cmsOpenProfileFromMemTHR(avci->icc.ctx, sd->data, sd->size);
533 if (!profile)
534 return AVERROR_INVALIDDATA;
535
536 ret = ff_icc_profile_sanitize(&avci->icc, profile);
537 if (!ret)
538 ret = ff_icc_profile_read_primaries(&avci->icc, profile, &coeffs);
539 if (!ret)
540 ret = ff_icc_profile_detect_transfer(&avci->icc, profile, &trc);
541 cmsCloseProfile(profile);
542 if (ret < 0)
543 return ret;
544
545 prim = av_csp_primaries_id_from_desc(&coeffs);
546 if (prim != AVCOL_PRI_UNSPECIFIED)
547 frame->color_primaries = prim;
548 if (trc != AVCOL_TRC_UNSPECIFIED)
549 frame->color_trc = trc;
550 return 0;
551 }
552 #else /* !CONFIG_LCMS2 */
553 796377 static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f)
554 {
555 796377 return 0;
556 }
557 #endif
558
559 815901 static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
560 {
561 int ret;
562
563
2/2
✓ Branch 0 taken 554140 times.
✓ Branch 1 taken 261761 times.
815901 if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
564 554140 frame->color_primaries = avctx->color_primaries;
565
2/2
✓ Branch 0 taken 553779 times.
✓ Branch 1 taken 262122 times.
815901 if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
566 553779 frame->color_trc = avctx->color_trc;
567
2/2
✓ Branch 0 taken 547868 times.
✓ Branch 1 taken 268033 times.
815901 if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
568 547868 frame->colorspace = avctx->colorspace;
569
2/2
✓ Branch 0 taken 727209 times.
✓ Branch 1 taken 88692 times.
815901 if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
570 727209 frame->color_range = avctx->color_range;
571
2/2
✓ Branch 0 taken 787812 times.
✓ Branch 1 taken 28089 times.
815901 if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
572 787812 frame->chroma_location = avctx->chroma_sample_location;
573
574
2/2
✓ Branch 0 taken 293767 times.
✓ Branch 1 taken 522134 times.
815901 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
575
2/2
✓ Branch 0 taken 277672 times.
✓ Branch 1 taken 16095 times.
293767 if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
576
2/2
✓ Branch 0 taken 146400 times.
✓ Branch 1 taken 147367 times.
293767 if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
577
1/2
✓ Branch 0 taken 522134 times.
✗ Branch 1 not taken.
522134 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
578
2/2
✓ Branch 0 taken 261162 times.
✓ Branch 1 taken 260972 times.
522134 if (frame->format == AV_SAMPLE_FMT_NONE)
579 261162 frame->format = avctx->sample_fmt;
580
2/2
✓ Branch 0 taken 261162 times.
✓ Branch 1 taken 260972 times.
522134 if (!frame->ch_layout.nb_channels) {
581 261162 ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 261162 times.
261162 if (ret < 0)
583 return ret;
584 }
585
2/2
✓ Branch 0 taken 261021 times.
✓ Branch 1 taken 261113 times.
522134 if (!frame->sample_rate)
586 261021 frame->sample_rate = avctx->sample_rate;
587 }
588
589 815901 return 0;
590 }
591
592 772447 static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
593 {
594 int ret;
595 772447 int64_t discarded_samples = 0;
596
597
2/2
✓ Branch 0 taken 784205 times.
✓ Branch 1 taken 394842 times.
1179047 while (!frame->buf[0]) {
598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 784205 times.
784205 if (discarded_samples > avctx->max_samples)
599 return AVERROR(EAGAIN);
600 784205 ret = decode_simple_internal(avctx, frame, &discarded_samples);
601
2/2
✓ Branch 0 taken 377605 times.
✓ Branch 1 taken 406600 times.
784205 if (ret < 0)
602 377605 return ret;
603 }
604
605 394842 return 0;
606 }
607
608 796689 int ff_decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
609 {
610 796689 AVCodecInternal *avci = avctx->internal;
611 796689 DecodeContext *dc = decode_ctx(avci);
612 796689 const FFCodec *const codec = ffcodec(avctx->codec);
613 int ret;
614
615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 796689 times.
796689 av_assert0(!frame->buf[0]);
616
617
2/2
✓ Branch 0 taken 24242 times.
✓ Branch 1 taken 772447 times.
796689 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
618 while (1) {
619 24244 frame->pict_type = dc->initial_pict_type;
620 24244 frame->flags |= dc->intra_only_flag;
621 24244 ret = codec->cb.receive_frame(avctx, frame);
622 24244 emms_c();
623
2/2
✓ Branch 0 taken 11885 times.
✓ Branch 1 taken 12359 times.
24244 if (!ret) {
624
2/2
✓ Branch 0 taken 1809 times.
✓ Branch 1 taken 10076 times.
11885 if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
625 1809 int64_t discarded_samples = 0;
626 1809 ret = discard_samples(avctx, frame, &discarded_samples);
627 }
628
3/4
✓ Branch 0 taken 11885 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 11883 times.
11885 if (ret == AVERROR(EAGAIN) || (frame->flags & AV_FRAME_FLAG_DISCARD)) {
629 2 av_frame_unref(frame);
630 2 continue;
631 }
632 }
633 24242 break;
634 }
635 } else
636 772447 ret = decode_simple_receive_frame(avctx, frame);
637
638
2/2
✓ Branch 0 taken 3482 times.
✓ Branch 1 taken 793207 times.
796689 if (ret == AVERROR_EOF)
639 3482 avci->draining_done = 1;
640
641 796689 return ret;
642 }
643
644 796377 static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
645 {
646 796377 AVCodecInternal *avci = avctx->internal;
647 796377 DecodeContext *dc = decode_ctx(avci);
648 int ret, ok;
649
650
2/2
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 795545 times.
796377 if (avctx->active_thread_type & FF_THREAD_FRAME)
651 832 ret = ff_thread_receive_frame(avctx, frame);
652 else
653 795545 ret = ff_decode_receive_frame_internal(avctx, frame);
654
655 /* preserve ret */
656 796377 ok = detect_colorspace(avctx, frame);
657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 796377 times.
796377 if (ok < 0) {
658 av_frame_unref(frame);
659 return ok;
660 }
661
662
2/2
✓ Branch 0 taken 406724 times.
✓ Branch 1 taken 389653 times.
796377 if (!ret) {
663
2/2
✓ Branch 0 taken 145778 times.
✓ Branch 1 taken 260946 times.
406724 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
664
2/2
✓ Branch 0 taken 25462 times.
✓ Branch 1 taken 120316 times.
145778 if (!frame->width)
665 25462 frame->width = avctx->width;
666
2/2
✓ Branch 0 taken 25462 times.
✓ Branch 1 taken 120316 times.
145778 if (!frame->height)
667 25462 frame->height = avctx->height;
668 }
669
670 406724 ret = fill_frame_props(avctx, frame);
671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 406724 times.
406724 if (ret < 0) {
672 av_frame_unref(frame);
673 return ret;
674 }
675
676 406724 frame->best_effort_timestamp = guess_correct_pts(dc,
677 frame->pts,
678 frame->pkt_dts);
679
680 /* the only case where decode data is not set should be decoders
681 * that do not call ff_get_buffer() */
682
3/4
✓ Branch 0 taken 26181 times.
✓ Branch 1 taken 380543 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 26181 times.
406724 av_assert0(frame->private_ref ||
683 !(avctx->codec->capabilities & AV_CODEC_CAP_DR1));
684
685
2/2
✓ Branch 0 taken 380543 times.
✓ Branch 1 taken 26181 times.
406724 if (frame->private_ref) {
686 380543 FrameDecodeData *fdd = frame->private_ref;
687
688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380543 times.
380543 if (fdd->post_process) {
689 ret = fdd->post_process(avctx, frame);
690 if (ret < 0) {
691 av_frame_unref(frame);
692 return ret;
693 }
694 }
695 }
696 }
697
698 /* free the per-frame decode data */
699 796377 av_refstruct_unref(&frame->private_ref);
700
701 796377 return ret;
702 }
703
704 391993 int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
705 {
706 391993 AVCodecInternal *avci = avctx->internal;
707 391993 DecodeContext *dc = decode_ctx(avci);
708 int ret;
709
710
2/4
✓ Branch 1 taken 391993 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 391993 times.
391993 if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
711 return AVERROR(EINVAL);
712
713
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 391963 times.
391993 if (dc->draining_started)
714 30 return AVERROR_EOF;
715
716
5/6
✓ Branch 0 taken 388637 times.
✓ Branch 1 taken 3326 times.
✓ Branch 2 taken 97 times.
✓ Branch 3 taken 388540 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 97 times.
391963 if (avpkt && !avpkt->size && avpkt->data)
717 return AVERROR(EINVAL);
718
719
5/6
✓ Branch 0 taken 388637 times.
✓ Branch 1 taken 3326 times.
✓ Branch 2 taken 97 times.
✓ Branch 3 taken 388540 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 97 times.
391963 if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
720
2/4
✓ Branch 0 taken 388540 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 388540 times.
388540 if (!AVPACKET_IS_EMPTY(avci->buffer_pkt))
721 return AVERROR(EAGAIN);
722 388540 ret = av_packet_ref(avci->buffer_pkt, avpkt);
723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 388540 times.
388540 if (ret < 0)
724 return ret;
725 } else
726 3423 dc->draining_started = 1;
727
728
3/4
✓ Branch 0 taken 391963 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 388540 times.
✓ Branch 3 taken 3423 times.
391963 if (!avci->buffer_frame->buf[0] && !dc->draining_started) {
729 388540 ret = decode_receive_frame_internal(avctx, avci->buffer_frame);
730
5/6
✓ Branch 0 taken 11680 times.
✓ Branch 1 taken 376860 times.
✓ Branch 2 taken 659 times.
✓ Branch 3 taken 11021 times.
✓ Branch 4 taken 659 times.
✗ Branch 5 not taken.
388540 if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
731 659 return ret;
732 }
733
734 391304 return 0;
735 }
736
737 145778 static int apply_cropping(AVCodecContext *avctx, AVFrame *frame)
738 {
739 /* make sure we are noisy about decoders returning invalid cropping data */
740
1/2
✓ Branch 0 taken 145778 times.
✗ Branch 1 not taken.
145778 if (frame->crop_left >= INT_MAX - frame->crop_right ||
741
1/2
✓ Branch 0 taken 145778 times.
✗ Branch 1 not taken.
145778 frame->crop_top >= INT_MAX - frame->crop_bottom ||
742
1/2
✓ Branch 0 taken 145778 times.
✗ Branch 1 not taken.
145778 (frame->crop_left + frame->crop_right) >= frame->width ||
743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 145778 times.
145778 (frame->crop_top + frame->crop_bottom) >= frame->height) {
744 av_log(avctx, AV_LOG_WARNING,
745 "Invalid cropping information set by a decoder: "
746 "%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER"/%"SIZE_SPECIFIER" "
747 "(frame size %dx%d). This is a bug, please report it\n",
748 frame->crop_left, frame->crop_right, frame->crop_top, frame->crop_bottom,
749 frame->width, frame->height);
750 frame->crop_left = 0;
751 frame->crop_right = 0;
752 frame->crop_top = 0;
753 frame->crop_bottom = 0;
754 return 0;
755 }
756
757
2/2
✓ Branch 0 taken 138471 times.
✓ Branch 1 taken 7307 times.
145778 if (!avctx->apply_cropping)
758 138471 return 0;
759
760 7307 return av_frame_apply_cropping(frame, avctx->flags & AV_CODEC_FLAG_UNALIGNED ?
761 AV_FRAME_CROP_UNALIGNED : 0);
762 }
763
764 // make sure frames returned to the caller are valid
765 406724 static int frame_validate(AVCodecContext *avctx, AVFrame *frame)
766 {
767
2/4
✓ Branch 0 taken 406724 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 406724 times.
406724 if (!frame->buf[0] || frame->format < 0)
768 goto fail;
769
770
2/3
✓ Branch 0 taken 145778 times.
✓ Branch 1 taken 260946 times.
✗ Branch 2 not taken.
406724 switch (avctx->codec_type) {
771 145778 case AVMEDIA_TYPE_VIDEO:
772
2/4
✓ Branch 0 taken 145778 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 145778 times.
145778 if (frame->width <= 0 || frame->height <= 0)
773 goto fail;
774 145778 break;
775 260946 case AVMEDIA_TYPE_AUDIO:
776
1/2
✓ Branch 1 taken 260946 times.
✗ Branch 2 not taken.
260946 if (!av_channel_layout_check(&frame->ch_layout) ||
777
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 260946 times.
260946 frame->sample_rate <= 0)
778 goto fail;
779
780 260946 break;
781 default: av_assert0(0);
782 }
783
784 406724 return 0;
785 fail:
786 av_log(avctx, AV_LOG_ERROR, "An invalid frame was output by a decoder. "
787 "This is a bug, please report it.\n");
788 return AVERROR_BUG;
789 }
790
791 784697 int ff_decode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
792 {
793 784697 AVCodecInternal *avci = avctx->internal;
794 int ret;
795
796
2/2
✓ Branch 0 taken 376860 times.
✓ Branch 1 taken 407837 times.
784697 if (avci->buffer_frame->buf[0]) {
797 376860 av_frame_move_ref(frame, avci->buffer_frame);
798 } else {
799 407837 ret = decode_receive_frame_internal(avctx, frame);
800
2/2
✓ Branch 0 taken 377973 times.
✓ Branch 1 taken 29864 times.
407837 if (ret < 0)
801 377973 return ret;
802 }
803
804 406724 ret = frame_validate(avctx, frame);
805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 406724 times.
406724 if (ret < 0)
806 goto fail;
807
808
2/2
✓ Branch 0 taken 145778 times.
✓ Branch 1 taken 260946 times.
406724 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
809 145778 ret = apply_cropping(avctx, frame);
810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 145778 times.
145778 if (ret < 0)
811 goto fail;
812 }
813
814 406724 avctx->frame_num++;
815
816 406724 return 0;
817 fail:
818 av_frame_unref(frame);
819 return ret;
820 }
821
822 1709 static void get_subtitle_defaults(AVSubtitle *sub)
823 {
824 1709 memset(sub, 0, sizeof(*sub));
825 1709 sub->pts = AV_NOPTS_VALUE;
826 1709 }
827
828 #define UTF8_MAX_BYTES 4 /* 5 and 6 bytes sequences should not be used */
829 1675 static int recode_subtitle(AVCodecContext *avctx, const AVPacket **outpkt,
830 const AVPacket *inpkt, AVPacket *buf_pkt)
831 {
832 #if CONFIG_ICONV
833 1675 iconv_t cd = (iconv_t)-1;
834 1675 int ret = 0;
835 char *inb, *outb;
836 size_t inl, outl;
837 #endif
838
839
3/4
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1582 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 93 times.
1675 if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_PRE_DECODER || inpkt->size == 0) {
840 1582 *outpkt = inpkt;
841 1582 return 0;
842 }
843
844 #if CONFIG_ICONV
845 93 inb = inpkt->data;
846 93 inl = inpkt->size;
847
848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
93 if (inl >= INT_MAX / UTF8_MAX_BYTES - AV_INPUT_BUFFER_PADDING_SIZE) {
849 av_log(avctx, AV_LOG_ERROR, "Subtitles packet is too big for recoding\n");
850 return AVERROR(ERANGE);
851 }
852
853 93 cd = iconv_open("UTF-8", avctx->sub_charenc);
854
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
93 av_assert0(cd != (iconv_t)-1);
855
856 93 ret = av_new_packet(buf_pkt, inl * UTF8_MAX_BYTES);
857
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
93 if (ret < 0)
858 goto end;
859 93 ret = av_packet_copy_props(buf_pkt, inpkt);
860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
93 if (ret < 0)
861 goto end;
862 93 outb = buf_pkt->data;
863 93 outl = buf_pkt->size;
864
865
2/4
✓ Branch 1 taken 93 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 93 times.
✗ Branch 4 not taken.
186 if (iconv(cd, &inb, &inl, &outb, &outl) == (size_t)-1 ||
866 93 iconv(cd, NULL, NULL, &outb, &outl) == (size_t)-1 ||
867
2/4
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 93 times.
93 outl >= buf_pkt->size || inl != 0) {
868 ret = FFMIN(AVERROR(errno), -1);
869 av_log(avctx, AV_LOG_ERROR, "Unable to recode subtitle event \"%s\" "
870 "from %s to UTF-8\n", inpkt->data, avctx->sub_charenc);
871 goto end;
872 }
873 93 buf_pkt->size -= outl;
874 93 memset(buf_pkt->data + buf_pkt->size, 0, outl);
875 93 *outpkt = buf_pkt;
876
877 93 ret = 0;
878 93 end:
879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
93 if (ret < 0)
880 av_packet_unref(buf_pkt);
881
1/2
✓ Branch 0 taken 93 times.
✗ Branch 1 not taken.
93 if (cd != (iconv_t)-1)
882 93 iconv_close(cd);
883 93 return ret;
884 #else
885 av_log(avctx, AV_LOG_ERROR, "requesting subtitles recoding without iconv");
886 return AVERROR(EINVAL);
887 #endif
888 }
889
890 700 static int utf8_check(const uint8_t *str)
891 {
892 const uint8_t *byte;
893 uint32_t codepoint, min;
894
895
2/2
✓ Branch 0 taken 61070 times.
✓ Branch 1 taken 700 times.
61770 while (*str) {
896 61070 byte = str;
897
5/8
✓ Branch 0 taken 61070 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 61070 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2798 times.
✓ Branch 6 taken 2798 times.
✓ Branch 7 taken 61070 times.
63868 GET_UTF8(codepoint, *(byte++), return 0;);
898
4/4
✓ Branch 0 taken 2091 times.
✓ Branch 1 taken 58979 times.
✓ Branch 2 taken 707 times.
✓ Branch 3 taken 1384 times.
61777 min = byte - str == 1 ? 0 : byte - str == 2 ? 0x80 :
899 707 1 << (5 * (byte - str) - 4);
900
3/6
✓ Branch 0 taken 61070 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61070 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 61070 times.
✗ Branch 5 not taken.
61070 if (codepoint < min || codepoint >= 0x110000 ||
901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61070 times.
61070 codepoint == 0xFFFE /* BOM */ ||
902 codepoint >= 0xD800 && codepoint <= 0xDFFF /* surrogates */)
903 return 0;
904 61070 str = byte;
905 }
906 700 return 1;
907 }
908
909 1709 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
910 int *got_sub_ptr, const AVPacket *avpkt)
911 {
912 1709 int ret = 0;
913
914
3/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1669 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
1709 if (!avpkt->data && avpkt->size) {
915 av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
916 return AVERROR(EINVAL);
917 }
918
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1709 times.
1709 if (!avctx->codec)
919 return AVERROR(EINVAL);
920
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1709 times.
1709 if (ffcodec(avctx->codec)->cb_type != FF_CODEC_CB_TYPE_DECODE_SUB) {
921 av_log(avctx, AV_LOG_ERROR, "Codec not subtitle decoder\n");
922 return AVERROR(EINVAL);
923 }
924
925 1709 *got_sub_ptr = 0;
926 1709 get_subtitle_defaults(sub);
927
928
4/4
✓ Branch 0 taken 857 times.
✓ Branch 1 taken 852 times.
✓ Branch 2 taken 823 times.
✓ Branch 3 taken 34 times.
1709 if ((avctx->codec->capabilities & AV_CODEC_CAP_DELAY) || avpkt->size) {
929 1675 AVCodecInternal *avci = avctx->internal;
930 const AVPacket *pkt;
931
932 1675 ret = recode_subtitle(avctx, &pkt, avpkt, avci->buffer_pkt);
933
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1675 times.
1675 if (ret < 0)
934 79 return ret;
935
936
3/4
✓ Branch 0 taken 1675 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1665 times.
✓ Branch 3 taken 10 times.
1675 if (avctx->pkt_timebase.num && avpkt->pts != AV_NOPTS_VALUE)
937 1665 sub->pts = av_rescale_q(avpkt->pts,
938 1665 avctx->pkt_timebase, AV_TIME_BASE_Q);
939 1675 ret = ffcodec(avctx->codec)->cb.decode_sub(avctx, sub, got_sub_ptr, pkt);
940
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1582 times.
1675 if (pkt == avci->buffer_pkt) // did we recode?
941 93 av_packet_unref(avci->buffer_pkt);
942
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 1596 times.
1675 if (ret < 0) {
943 79 *got_sub_ptr = 0;
944 79 avsubtitle_free(sub);
945 79 return ret;
946 }
947 av_assert1(!sub->num_rects || *got_sub_ptr);
948
949
6/6
✓ Branch 0 taken 826 times.
✓ Branch 1 taken 770 times.
✓ Branch 2 taken 580 times.
✓ Branch 3 taken 246 times.
✓ Branch 4 taken 528 times.
✓ Branch 5 taken 52 times.
1596 if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
950
1/2
✓ Branch 0 taken 528 times.
✗ Branch 1 not taken.
528 avctx->pkt_timebase.num) {
951 528 AVRational ms = { 1, 1000 };
952 528 sub->end_display_time = av_rescale_q(avpkt->duration,
953 avctx->pkt_timebase, ms);
954 }
955
956
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 1440 times.
1596 if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
957 156 sub->format = 0;
958
1/2
✓ Branch 0 taken 1440 times.
✗ Branch 1 not taken.
1440 else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
959 1440 sub->format = 1;
960
961
2/2
✓ Branch 0 taken 859 times.
✓ Branch 1 taken 1596 times.
2455 for (unsigned i = 0; i < sub->num_rects; i++) {
962
1/2
✓ Branch 0 taken 859 times.
✗ Branch 1 not taken.
859 if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE &&
963
3/4
✓ Branch 0 taken 700 times.
✓ Branch 1 taken 159 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 700 times.
859 sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
964 av_log(avctx, AV_LOG_ERROR,
965 "Invalid UTF-8 in decoded subtitles text; "
966 "maybe missing -sub_charenc option\n");
967 avsubtitle_free(sub);
968 *got_sub_ptr = 0;
969 return AVERROR_INVALIDDATA;
970 }
971 }
972
973
2/2
✓ Branch 0 taken 835 times.
✓ Branch 1 taken 761 times.
1596 if (*got_sub_ptr)
974 835 avctx->frame_num++;
975 }
976
977 1630 return ret;
978 }
979
980 1578 enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *avctx,
981 const enum AVPixelFormat *fmt)
982 {
983 const AVPixFmtDescriptor *desc;
984 const AVCodecHWConfig *config;
985 int i, n;
986
987 // If a device was supplied when the codec was opened, assume that the
988 // user wants to use it.
989
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1578 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1578 if (avctx->hw_device_ctx && ffcodec(avctx->codec)->hw_configs) {
990 AVHWDeviceContext *device_ctx =
991 (AVHWDeviceContext*)avctx->hw_device_ctx->data;
992 for (i = 0;; i++) {
993 config = &ffcodec(avctx->codec)->hw_configs[i]->public;
994 if (!config)
995 break;
996 if (!(config->methods &
997 AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX))
998 continue;
999 if (device_ctx->type != config->device_type)
1000 continue;
1001 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1002 if (config->pix_fmt == fmt[n])
1003 return fmt[n];
1004 }
1005 }
1006 }
1007 // No device or other setup, so we have to choose from things which
1008 // don't any other external information.
1009
1010 // If the last element of the list is a software format, choose it
1011 // (this should be best software format if any exist).
1012
2/2
✓ Branch 0 taken 4051 times.
✓ Branch 1 taken 1578 times.
5629 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1013 1578 desc = av_pix_fmt_desc_get(fmt[n - 1]);
1014
1/2
✓ Branch 0 taken 1578 times.
✗ Branch 1 not taken.
1578 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
1015 1578 return fmt[n - 1];
1016
1017 // Finally, traverse the list in order and choose the first entry
1018 // with no external dependencies (if there is no hardware configuration
1019 // information available then this just picks the first entry).
1020 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++) {
1021 for (i = 0;; i++) {
1022 config = avcodec_get_hw_config(avctx->codec, i);
1023 if (!config)
1024 break;
1025 if (config->pix_fmt == fmt[n])
1026 break;
1027 }
1028 if (!config) {
1029 // No specific config available, so the decoder must be able
1030 // to handle this format without any additional setup.
1031 return fmt[n];
1032 }
1033 if (config->methods & AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1034 // Usable with only internal setup.
1035 return fmt[n];
1036 }
1037 }
1038
1039 // Nothing is usable, give up.
1040 return AV_PIX_FMT_NONE;
1041 }
1042
1043 int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx,
1044 enum AVHWDeviceType dev_type)
1045 {
1046 AVHWDeviceContext *device_ctx;
1047 AVHWFramesContext *frames_ctx;
1048 int ret;
1049
1050 if (!avctx->hwaccel)
1051 return AVERROR(ENOSYS);
1052
1053 if (avctx->hw_frames_ctx)
1054 return 0;
1055 if (!avctx->hw_device_ctx) {
1056 av_log(avctx, AV_LOG_ERROR, "A hardware frames or device context is "
1057 "required for hardware accelerated decoding.\n");
1058 return AVERROR(EINVAL);
1059 }
1060
1061 device_ctx = (AVHWDeviceContext *)avctx->hw_device_ctx->data;
1062 if (device_ctx->type != dev_type) {
1063 av_log(avctx, AV_LOG_ERROR, "Device type %s expected for hardware "
1064 "decoding, but got %s.\n", av_hwdevice_get_type_name(dev_type),
1065 av_hwdevice_get_type_name(device_ctx->type));
1066 return AVERROR(EINVAL);
1067 }
1068
1069 ret = avcodec_get_hw_frames_parameters(avctx,
1070 avctx->hw_device_ctx,
1071 avctx->hwaccel->pix_fmt,
1072 &avctx->hw_frames_ctx);
1073 if (ret < 0)
1074 return ret;
1075
1076 frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1077
1078
1079 if (frames_ctx->initial_pool_size) {
1080 // We guarantee 4 base work surfaces. The function above guarantees 1
1081 // (the absolute minimum), so add the missing count.
1082 frames_ctx->initial_pool_size += 3;
1083 }
1084
1085 ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
1086 if (ret < 0) {
1087 av_buffer_unref(&avctx->hw_frames_ctx);
1088 return ret;
1089 }
1090
1091 return 0;
1092 }
1093
1094 int avcodec_get_hw_frames_parameters(AVCodecContext *avctx,
1095 AVBufferRef *device_ref,
1096 enum AVPixelFormat hw_pix_fmt,
1097 AVBufferRef **out_frames_ref)
1098 {
1099 AVBufferRef *frames_ref = NULL;
1100 const AVCodecHWConfigInternal *hw_config;
1101 const FFHWAccel *hwa;
1102 int i, ret;
1103 bool clean_priv_data = false;
1104
1105 for (i = 0;; i++) {
1106 hw_config = ffcodec(avctx->codec)->hw_configs[i];
1107 if (!hw_config)
1108 return AVERROR(ENOENT);
1109 if (hw_config->public.pix_fmt == hw_pix_fmt)
1110 break;
1111 }
1112
1113 hwa = hw_config->hwaccel;
1114 if (!hwa || !hwa->frame_params)
1115 return AVERROR(ENOENT);
1116
1117 frames_ref = av_hwframe_ctx_alloc(device_ref);
1118 if (!frames_ref)
1119 return AVERROR(ENOMEM);
1120
1121 if (!avctx->internal->hwaccel_priv_data) {
1122 avctx->internal->hwaccel_priv_data =
1123 av_mallocz(hwa->priv_data_size);
1124 if (!avctx->internal->hwaccel_priv_data) {
1125 av_buffer_unref(&frames_ref);
1126 return AVERROR(ENOMEM);
1127 }
1128 clean_priv_data = true;
1129 }
1130
1131 ret = hwa->frame_params(avctx, frames_ref);
1132 if (ret >= 0) {
1133 AVHWFramesContext *frames_ctx = (AVHWFramesContext*)frames_ref->data;
1134
1135 if (frames_ctx->initial_pool_size) {
1136 // If the user has requested that extra output surfaces be
1137 // available then add them here.
1138 if (avctx->extra_hw_frames > 0)
1139 frames_ctx->initial_pool_size += avctx->extra_hw_frames;
1140
1141 // If frame threading is enabled then an extra surface per thread
1142 // is also required.
1143 if (avctx->active_thread_type & FF_THREAD_FRAME)
1144 frames_ctx->initial_pool_size += avctx->thread_count;
1145 }
1146
1147 *out_frames_ref = frames_ref;
1148 } else {
1149 if (clean_priv_data)
1150 av_freep(&avctx->internal->hwaccel_priv_data);
1151 av_buffer_unref(&frames_ref);
1152 }
1153 return ret;
1154 }
1155
1156 static int hwaccel_init(AVCodecContext *avctx,
1157 const FFHWAccel *hwaccel)
1158 {
1159 int err;
1160
1161 if (hwaccel->p.capabilities & AV_HWACCEL_CODEC_CAP_EXPERIMENTAL &&
1162 avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
1163 av_log(avctx, AV_LOG_WARNING, "Ignoring experimental hwaccel: %s\n",
1164 hwaccel->p.name);
1165 return AVERROR_PATCHWELCOME;
1166 }
1167
1168 if (!avctx->internal->hwaccel_priv_data && hwaccel->priv_data_size) {
1169 avctx->internal->hwaccel_priv_data =
1170 av_mallocz(hwaccel->priv_data_size);
1171 if (!avctx->internal->hwaccel_priv_data)
1172 return AVERROR(ENOMEM);
1173 }
1174
1175 avctx->hwaccel = &hwaccel->p;
1176 if (hwaccel->init) {
1177 err = hwaccel->init(avctx);
1178 if (err < 0) {
1179 av_log(avctx, AV_LOG_ERROR, "Failed setup for format %s: "
1180 "hwaccel initialisation returned error.\n",
1181 av_get_pix_fmt_name(hwaccel->p.pix_fmt));
1182 av_freep(&avctx->internal->hwaccel_priv_data);
1183 avctx->hwaccel = NULL;
1184 return err;
1185 }
1186 }
1187
1188 return 0;
1189 }
1190
1191 39350 void ff_hwaccel_uninit(AVCodecContext *avctx)
1192 {
1193
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39350 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
39350 if (FF_HW_HAS_CB(avctx, uninit))
1194 FF_HW_SIMPLE_CALL(avctx, uninit);
1195
1196 39350 av_freep(&avctx->internal->hwaccel_priv_data);
1197
1198 39350 avctx->hwaccel = NULL;
1199
1200 39350 av_buffer_unref(&avctx->hw_frames_ctx);
1201 39350 }
1202
1203 2588 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
1204 {
1205 const AVPixFmtDescriptor *desc;
1206 enum AVPixelFormat *choices;
1207 enum AVPixelFormat ret, user_choice;
1208 const AVCodecHWConfigInternal *hw_config;
1209 const AVCodecHWConfig *config;
1210 int i, n, err;
1211
1212 // Find end of list.
1213
2/2
✓ Branch 0 taken 6781 times.
✓ Branch 1 taken 2588 times.
9369 for (n = 0; fmt[n] != AV_PIX_FMT_NONE; n++);
1214 // Must contain at least one entry.
1215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2588 times.
2588 av_assert0(n >= 1);
1216 // If a software format is available, it must be the last entry.
1217 2588 desc = av_pix_fmt_desc_get(fmt[n - 1]);
1218
1/2
✓ Branch 0 taken 2588 times.
✗ Branch 1 not taken.
2588 if (desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
1219 // No software format is available.
1220 } else {
1221 2588 avctx->sw_pix_fmt = fmt[n - 1];
1222 }
1223
1224 2588 choices = av_memdup(fmt, (n + 1) * sizeof(*choices));
1225
1/2
✓ Branch 0 taken 2588 times.
✗ Branch 1 not taken.
2588 if (!choices)
1226 return AV_PIX_FMT_NONE;
1227
1228 for (;;) {
1229 // Remove the previous hwaccel, if there was one.
1230 2588 ff_hwaccel_uninit(avctx);
1231
1232 2588 user_choice = avctx->get_format(avctx, choices);
1233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2588 times.
2588 if (user_choice == AV_PIX_FMT_NONE) {
1234 // Explicitly chose nothing, give up.
1235 ret = AV_PIX_FMT_NONE;
1236 break;
1237 }
1238
1239 2588 desc = av_pix_fmt_desc_get(user_choice);
1240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2588 times.
2588 if (!desc) {
1241 av_log(avctx, AV_LOG_ERROR, "Invalid format returned by "
1242 "get_format() callback.\n");
1243 ret = AV_PIX_FMT_NONE;
1244 break;
1245 }
1246 2588 av_log(avctx, AV_LOG_DEBUG, "Format %s chosen by get_format().\n",
1247 2588 desc->name);
1248
1249
1/2
✓ Branch 0 taken 6780 times.
✗ Branch 1 not taken.
6780 for (i = 0; i < n; i++) {
1250
2/2
✓ Branch 0 taken 2588 times.
✓ Branch 1 taken 4192 times.
6780 if (choices[i] == user_choice)
1251 2588 break;
1252 }
1253
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2588 times.
2588 if (i == n) {
1254 av_log(avctx, AV_LOG_ERROR, "Invalid return from get_format(): "
1255 "%s not in possible list.\n", desc->name);
1256 ret = AV_PIX_FMT_NONE;
1257 break;
1258 }
1259
1260
2/2
✓ Branch 1 taken 2541 times.
✓ Branch 2 taken 47 times.
2588 if (ffcodec(avctx->codec)->hw_configs) {
1261 2541 for (i = 0;; i++) {
1262 6932 hw_config = ffcodec(avctx->codec)->hw_configs[i];
1263
2/2
✓ Branch 0 taken 2541 times.
✓ Branch 1 taken 4391 times.
6932 if (!hw_config)
1264 2541 break;
1265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4391 times.
4391 if (hw_config->public.pix_fmt == user_choice)
1266 break;
1267 }
1268 } else {
1269 47 hw_config = NULL;
1270 }
1271
1272
1/2
✓ Branch 0 taken 2588 times.
✗ Branch 1 not taken.
2588 if (!hw_config) {
1273 // No config available, so no extra setup required.
1274 2588 ret = user_choice;
1275 2588 break;
1276 }
1277 config = &hw_config->public;
1278
1279 if (config->methods &
1280 AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX &&
1281 avctx->hw_frames_ctx) {
1282 const AVHWFramesContext *frames_ctx =
1283 (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1284 if (frames_ctx->format != user_choice) {
1285 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1286 "does not match the format of the provided frames "
1287 "context.\n", desc->name);
1288 goto try_again;
1289 }
1290 } else if (config->methods &
1291 AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
1292 avctx->hw_device_ctx) {
1293 const AVHWDeviceContext *device_ctx =
1294 (AVHWDeviceContext*)avctx->hw_device_ctx->data;
1295 if (device_ctx->type != config->device_type) {
1296 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1297 "does not match the type of the provided device "
1298 "context.\n", desc->name);
1299 goto try_again;
1300 }
1301 } else if (config->methods &
1302 AV_CODEC_HW_CONFIG_METHOD_INTERNAL) {
1303 // Internal-only setup, no additional configuration.
1304 } else if (config->methods &
1305 AV_CODEC_HW_CONFIG_METHOD_AD_HOC) {
1306 // Some ad-hoc configuration we can't see and can't check.
1307 } else {
1308 av_log(avctx, AV_LOG_ERROR, "Invalid setup for format %s: "
1309 "missing configuration.\n", desc->name);
1310 goto try_again;
1311 }
1312 if (hw_config->hwaccel) {
1313 av_log(avctx, AV_LOG_DEBUG, "Format %s requires hwaccel %s "
1314 "initialisation.\n", desc->name, hw_config->hwaccel->p.name);
1315 err = hwaccel_init(avctx, hw_config->hwaccel);
1316 if (err < 0)
1317 goto try_again;
1318 }
1319 ret = user_choice;
1320 break;
1321
1322 try_again:
1323 av_log(avctx, AV_LOG_DEBUG, "Format %s not usable, retrying "
1324 "get_format() without it.\n", desc->name);
1325 for (i = 0; i < n; i++) {
1326 if (choices[i] == user_choice)
1327 break;
1328 }
1329 for (; i + 1 < n; i++)
1330 choices[i] = choices[i + 1];
1331 --n;
1332 }
1333
1334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2588 times.
2588 if (ret < 0)
1335 ff_hwaccel_uninit(avctx);
1336
1337 2588 av_freep(&choices);
1338 2588 return ret;
1339 }
1340
1341 static const AVPacketSideData*
1342 9820756 packet_side_data_get(const AVPacketSideData *sd, int nb_sd,
1343 enum AVPacketSideDataType type)
1344 {
1345
2/2
✓ Branch 0 taken 135192 times.
✓ Branch 1 taken 9818221 times.
9953413 for (int i = 0; i < nb_sd; i++)
1346
2/2
✓ Branch 0 taken 2535 times.
✓ Branch 1 taken 132657 times.
135192 if (sd[i].type == type)
1347 2535 return &sd[i];
1348
1349 9818221 return NULL;
1350 }
1351
1352 508 const AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx,
1353 enum AVPacketSideDataType type)
1354 {
1355 508 return packet_side_data_get(avctx->coded_side_data, avctx->nb_coded_side_data, type);
1356 }
1357
1358 22 static int side_data_stereo3d_merge(AVFrameSideData *sd_frame,
1359 const AVPacketSideData *sd_pkt)
1360 {
1361 const AVStereo3D *src;
1362 AVStereo3D *dst;
1363 int ret;
1364
1365 22 ret = av_buffer_make_writable(&sd_frame->buf);
1366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0)
1367 return ret;
1368 22 sd_frame->data = sd_frame->buf->data;
1369
1370 22 dst = ( AVStereo3D*)sd_frame->data;
1371 22 src = (const AVStereo3D*)sd_pkt->data;
1372
1373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (dst->type == AV_STEREO3D_UNSPEC)
1374 dst->type = src->type;
1375
1376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (dst->view == AV_STEREO3D_VIEW_UNSPEC)
1377 dst->view = src->view;
1378
1379
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (dst->primary_eye == AV_PRIMARY_EYE_NONE)
1380 22 dst->primary_eye = src->primary_eye;
1381
1382
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (!dst->baseline)
1383 22 dst->baseline = src->baseline;
1384
1385
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (!dst->horizontal_disparity_adjustment.num)
1386 22 dst->horizontal_disparity_adjustment = src->horizontal_disparity_adjustment;
1387
1388
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (!dst->horizontal_field_of_view.num)
1389 22 dst->horizontal_field_of_view = src->horizontal_field_of_view;
1390
1391 22 return 0;
1392 }
1393
1394 1227531 static int side_data_map(AVFrame *dst,
1395 const AVPacketSideData *sd_src, int nb_sd_src,
1396 const SideDataMap *map)
1397
1398 {
1399
2/2
✓ Branch 0 taken 9820248 times.
✓ Branch 1 taken 1227531 times.
11047779 for (int i = 0; map[i].packet < AV_PKT_DATA_NB; i++) {
1400 9820248 const enum AVPacketSideDataType type_pkt = map[i].packet;
1401 9820248 const enum AVFrameSideDataType type_frame = map[i].frame;
1402 const AVPacketSideData *sd_pkt;
1403 AVFrameSideData *sd_frame;
1404
1405 9820248 sd_pkt = packet_side_data_get(sd_src, nb_sd_src, type_pkt);
1406
2/2
✓ Branch 0 taken 9817724 times.
✓ Branch 1 taken 2524 times.
9820248 if (!sd_pkt)
1407 9817724 continue;
1408
1409 2524 sd_frame = av_frame_get_side_data(dst, type_frame);
1410
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2502 times.
2524 if (sd_frame) {
1411
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (type_frame == AV_FRAME_DATA_STEREO3D) {
1412 22 int ret = side_data_stereo3d_merge(sd_frame, sd_pkt);
1413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (ret < 0)
1414 return ret;
1415 }
1416
1417 22 continue;
1418 }
1419
1420 2502 sd_frame = av_frame_new_side_data(dst, type_frame, sd_pkt->size);
1421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2502 times.
2502 if (!sd_frame)
1422 return AVERROR(ENOMEM);
1423
1424 2502 memcpy(sd_frame->data, sd_pkt->data, sd_pkt->size);
1425 }
1426
1427 1227531 return 0;
1428 }
1429
1430 409177 static int add_metadata_from_side_data(const AVPacket *avpkt, AVFrame *frame)
1431 {
1432 size_t size;
1433 const uint8_t *side_metadata;
1434
1435 409177 AVDictionary **frame_md = &frame->metadata;
1436
1437 409177 side_metadata = av_packet_get_side_data(avpkt,
1438 AV_PKT_DATA_STRINGS_METADATA, &size);
1439 409177 return av_packet_unpack_dictionary(side_metadata, size, frame_md);
1440 }
1441
1442 409177 int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
1443 AVFrame *frame, const AVPacket *pkt)
1444 {
1445 static const SideDataMap sd[] = {
1446 { AV_PKT_DATA_A53_CC, AV_FRAME_DATA_A53_CC },
1447 { AV_PKT_DATA_AFD, AV_FRAME_DATA_AFD },
1448 { AV_PKT_DATA_DYNAMIC_HDR10_PLUS, AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
1449 { AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE },
1450 { AV_PKT_DATA_SKIP_SAMPLES, AV_FRAME_DATA_SKIP_SAMPLES },
1451 { AV_PKT_DATA_LCEVC, AV_FRAME_DATA_LCEVC },
1452 { AV_PKT_DATA_NB }
1453 };
1454
1455 409177 int ret = 0;
1456
1457 409177 frame->pts = pkt->pts;
1458 409177 frame->duration = pkt->duration;
1459
1460 409177 ret = side_data_map(frame, pkt->side_data, pkt->side_data_elems, ff_sd_global_map);
1461
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 409177 times.
409177 if (ret < 0)
1462 return ret;
1463
1464 409177 ret = side_data_map(frame, pkt->side_data, pkt->side_data_elems, sd);
1465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 409177 times.
409177 if (ret < 0)
1466 return ret;
1467
1468 409177 add_metadata_from_side_data(pkt, frame);
1469
1470
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 408968 times.
409177 if (pkt->flags & AV_PKT_FLAG_DISCARD) {
1471 209 frame->flags |= AV_FRAME_FLAG_DISCARD;
1472 }
1473
1474
2/2
✓ Branch 0 taken 397606 times.
✓ Branch 1 taken 11571 times.
409177 if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
1475 397606 int ret = av_buffer_replace(&frame->opaque_ref, pkt->opaque_ref);
1476
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 397606 times.
397606 if (ret < 0)
1477 return ret;
1478 397606 frame->opaque = pkt->opaque;
1479 }
1480
1481 409177 return 0;
1482 }
1483
1484 409177 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
1485 {
1486 int ret;
1487
1488 409177 ret = side_data_map(frame, avctx->coded_side_data, avctx->nb_coded_side_data,
1489 ff_sd_global_map);
1490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 409177 times.
409177 if (ret < 0)
1491 return ret;
1492
1493
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 409177 times.
409249 for (int i = 0; i < avctx->nb_decoded_side_data; i++) {
1494 72 const AVFrameSideData *src = avctx->decoded_side_data[i];
1495
2/2
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 52 times.
72 if (av_frame_get_side_data(frame, src->type))
1496 20 continue;
1497 52 ret = av_frame_side_data_clone(&frame->side_data, &frame->nb_side_data, src, 0);
1498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 if (ret < 0)
1499 return ret;
1500 }
1501
1502
1/2
✓ Branch 1 taken 409177 times.
✗ Branch 2 not taken.
409177 if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
1503 409177 const AVPacket *pkt = avctx->internal->last_pkt_props;
1504
1505 409177 ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt);
1506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 409177 times.
409177 if (ret < 0)
1507 return ret;
1508 }
1509
1510 409177 ret = fill_frame_props(avctx, frame);
1511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 409177 times.
409177 if (ret < 0)
1512 return ret;
1513
1514
2/2
✓ Branch 0 taken 147989 times.
✓ Branch 1 taken 261188 times.
409177 switch (avctx->codec->type) {
1515 147989 case AVMEDIA_TYPE_VIDEO:
1516
4/6
✓ Branch 0 taken 122527 times.
✓ Branch 1 taken 25462 times.
✓ Branch 2 taken 122527 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 122527 times.
270516 if (frame->width && frame->height &&
1517 122527 av_image_check_sar(frame->width, frame->height,
1518 frame->sample_aspect_ratio) < 0) {
1519 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
1520 frame->sample_aspect_ratio.num,
1521 frame->sample_aspect_ratio.den);
1522 frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1523 }
1524 147989 break;
1525 }
1526 409177 return 0;
1527 }
1528
1529 382136 static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame)
1530 {
1531
2/2
✓ Branch 0 taken 120948 times.
✓ Branch 1 taken 261188 times.
382136 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1532 int i;
1533 120948 int num_planes = av_pix_fmt_count_planes(frame->format);
1534 120948 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
1535
1/2
✓ Branch 0 taken 120948 times.
✗ Branch 1 not taken.
120948 int flags = desc ? desc->flags : 0;
1536
4/4
✓ Branch 0 taken 13645 times.
✓ Branch 1 taken 107303 times.
✓ Branch 2 taken 4217 times.
✓ Branch 3 taken 9428 times.
120948 if (num_planes == 1 && (flags & AV_PIX_FMT_FLAG_PAL))
1537 4217 num_planes = 2;
1538
2/2
✓ Branch 0 taken 340561 times.
✓ Branch 1 taken 120948 times.
461509 for (i = 0; i < num_planes; i++) {
1539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 340561 times.
340561 av_assert0(frame->data[i]);
1540 }
1541 // For formats without data like hwaccel allow unused pointers to be non-NULL.
1542
3/4
✓ Branch 0 taken 747971 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 627023 times.
✓ Branch 3 taken 120948 times.
747971 for (i = num_planes; num_planes > 0 && i < FF_ARRAY_ELEMS(frame->data); i++) {
1543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 627023 times.
627023 if (frame->data[i])
1544 av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n");
1545 627023 frame->data[i] = NULL;
1546 }
1547 }
1548 382136 }
1549
1550 382136 static void decode_data_free(AVRefStructOpaque unused, void *obj)
1551 {
1552 382136 FrameDecodeData *fdd = obj;
1553
1554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (fdd->post_process_opaque_free)
1555 fdd->post_process_opaque_free(fdd->post_process_opaque);
1556
1557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (fdd->hwaccel_priv_free)
1558 fdd->hwaccel_priv_free(fdd->hwaccel_priv);
1559 382136 }
1560
1561 382136 int ff_attach_decode_data(AVFrame *frame)
1562 {
1563 FrameDecodeData *fdd;
1564
1565 av_assert1(!frame->private_ref);
1566 382136 av_refstruct_unref(&frame->private_ref);
1567
1568 382136 fdd = av_refstruct_alloc_ext(sizeof(*fdd), 0, NULL, decode_data_free);
1569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (!fdd)
1570 return AVERROR(ENOMEM);
1571
1572 382136 frame->private_ref = fdd;
1573
1574 382136 return 0;
1575 }
1576
1577 382136 static void update_frame_props(AVCodecContext *avctx, AVFrame *frame)
1578 {
1579 382136 AVCodecInternal *avci = avctx->internal;
1580 382136 DecodeContext *dc = decode_ctx(avci);
1581
1582
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
382136 dc->lcevc_frame = dc->lcevc && avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
1583 av_frame_get_side_data(frame, AV_FRAME_DATA_LCEVC);
1584
1585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (dc->lcevc_frame) {
1586 dc->width = frame->width;
1587 dc->height = frame->height;
1588 frame->width = frame->width * 2 / FFMAX(frame->sample_aspect_ratio.den, 1);
1589 frame->height = frame->height * 2 / FFMAX(frame->sample_aspect_ratio.num, 1);
1590 }
1591 382136 }
1592
1593 382136 static int attach_post_process_data(AVCodecContext *avctx, AVFrame *frame)
1594 {
1595 382136 AVCodecInternal *avci = avctx->internal;
1596 382136 DecodeContext *dc = decode_ctx(avci);
1597
1598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (dc->lcevc_frame) {
1599 FrameDecodeData *fdd = frame->private_ref;
1600 FFLCEVCFrame *frame_ctx;
1601 int ret;
1602
1603 frame_ctx = av_mallocz(sizeof(*frame_ctx));
1604 if (!frame_ctx)
1605 return AVERROR(ENOMEM);
1606
1607 frame_ctx->frame = av_frame_alloc();
1608 if (!frame_ctx->frame) {
1609 av_free(frame_ctx);
1610 return AVERROR(ENOMEM);
1611 }
1612
1613 frame_ctx->lcevc = av_refstruct_ref(dc->lcevc);
1614 frame_ctx->frame->width = frame->width;
1615 frame_ctx->frame->height = frame->height;
1616 frame_ctx->frame->format = frame->format;
1617
1618 frame->width = dc->width;
1619 frame->height = dc->height;
1620
1621 ret = avctx->get_buffer2(avctx, frame_ctx->frame, 0);
1622 if (ret < 0) {
1623 ff_lcevc_unref(frame_ctx);
1624 return ret;
1625 }
1626
1627 validate_avframe_allocation(avctx, frame_ctx->frame);
1628
1629 fdd->post_process_opaque = frame_ctx;
1630 fdd->post_process_opaque_free = ff_lcevc_unref;
1631 fdd->post_process = ff_lcevc_process;
1632 }
1633 382136 dc->lcevc_frame = 0;
1634
1635 382136 return 0;
1636 }
1637
1638 382136 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
1639 {
1640 382136 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
1641 382136 int override_dimensions = 1;
1642 int ret;
1643
1644
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 382136 times.
382136 av_assert0(ff_codec_is_decoder(avctx->codec));
1645
1646
2/2
✓ Branch 0 taken 120948 times.
✓ Branch 1 taken 261188 times.
382136 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
1647
2/4
✓ Branch 0 taken 120948 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120948 times.
✗ Branch 3 not taken.
241896 if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
1648
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 120948 times.
241896 (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || avctx->pix_fmt<0) {
1649 av_log(avctx, AV_LOG_ERROR, "video_get_buffer: image parameters invalid\n");
1650 ret = AVERROR(EINVAL);
1651 goto fail;
1652 }
1653
1654
3/4
✓ Branch 0 taken 731 times.
✓ Branch 1 taken 120217 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 731 times.
120948 if (frame->width <= 0 || frame->height <= 0) {
1655 120217 frame->width = FFMAX(avctx->width, AV_CEIL_RSHIFT(avctx->coded_width, avctx->lowres));
1656 120217 frame->height = FFMAX(avctx->height, AV_CEIL_RSHIFT(avctx->coded_height, avctx->lowres));
1657 120217 override_dimensions = 0;
1658 }
1659
1660
4/8
✓ Branch 0 taken 120948 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120948 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 120948 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 120948 times.
120948 if (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3]) {
1661 av_log(avctx, AV_LOG_ERROR, "pic->data[*]!=NULL in get_buffer_internal\n");
1662 ret = AVERROR(EINVAL);
1663 goto fail;
1664 }
1665
1/2
✓ Branch 0 taken 261188 times.
✗ Branch 1 not taken.
261188 } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
1666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 261188 times.
261188 if (frame->nb_samples * (int64_t)avctx->ch_layout.nb_channels > avctx->max_samples) {
1667 av_log(avctx, AV_LOG_ERROR, "samples per frame %d, exceeds max_samples %"PRId64"\n", frame->nb_samples, avctx->max_samples);
1668 ret = AVERROR(EINVAL);
1669 goto fail;
1670 }
1671 }
1672 382136 ret = ff_decode_frame_props(avctx, frame);
1673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (ret < 0)
1674 goto fail;
1675
1676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (hwaccel) {
1677 if (hwaccel->alloc_frame) {
1678 ret = hwaccel->alloc_frame(avctx, frame);
1679 goto end;
1680 }
1681 } else {
1682 382136 avctx->sw_pix_fmt = avctx->pix_fmt;
1683 382136 update_frame_props(avctx, frame);
1684 }
1685
1686 382136 ret = avctx->get_buffer2(avctx, frame, flags);
1687
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (ret < 0)
1688 goto fail;
1689
1690 382136 validate_avframe_allocation(avctx, frame);
1691
1692 382136 ret = ff_attach_decode_data(frame);
1693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (ret < 0)
1694 goto fail;
1695
1696 382136 ret = attach_post_process_data(avctx, frame);
1697
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (ret < 0)
1698 goto fail;
1699
1700 382136 end:
1701
4/4
✓ Branch 0 taken 261188 times.
✓ Branch 1 taken 120948 times.
✓ Branch 2 taken 731 times.
✓ Branch 3 taken 120217 times.
382136 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions &&
1702
2/2
✓ Branch 1 taken 37024 times.
✓ Branch 2 taken 83193 times.
120217 !(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_EXPORTS_CROPPING)) {
1703 83193 frame->width = avctx->width;
1704 83193 frame->height = avctx->height;
1705 }
1706
1707 298943 fail:
1708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 382136 times.
382136 if (ret < 0) {
1709 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1710 av_frame_unref(frame);
1711 }
1712
1713 382136 return ret;
1714 }
1715
1716 7763 static int reget_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags)
1717 {
1718 AVFrame *tmp;
1719 int ret;
1720
1721
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7763 times.
7763 av_assert0(avctx->codec_type == AVMEDIA_TYPE_VIDEO);
1722
1723 // make sure the discard flag does not persist
1724 7763 frame->flags &= ~AV_FRAME_FLAG_DISCARD;
1725
1726
5/8
✓ Branch 0 taken 7614 times.
✓ Branch 1 taken 149 times.
✓ Branch 2 taken 7614 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 7614 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 7614 times.
7763 if (frame->data[0] && (frame->width != avctx->width || frame->height != avctx->height || frame->format != avctx->pix_fmt)) {
1727 av_log(avctx, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
1728 frame->width, frame->height, av_get_pix_fmt_name(frame->format), avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
1729 av_frame_unref(frame);
1730 }
1731
1732
2/2
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 7614 times.
7763 if (!frame->data[0])
1733 149 return ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1734
1735 7614 av_frame_side_data_free(&frame->side_data, &frame->nb_side_data);
1736
1737
4/4
✓ Branch 0 taken 7613 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 750 times.
✓ Branch 4 taken 6863 times.
7614 if ((flags & FF_REGET_BUFFER_FLAG_READONLY) || av_frame_is_writable(frame))
1738 751 return ff_decode_frame_props(avctx, frame);
1739
1740 6863 tmp = av_frame_alloc();
1741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6863 times.
6863 if (!tmp)
1742 return AVERROR(ENOMEM);
1743
1744 6863 av_frame_move_ref(tmp, frame);
1745
1746 6863 ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF);
1747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6863 times.
6863 if (ret < 0) {
1748 av_frame_free(&tmp);
1749 return ret;
1750 }
1751
1752 6863 av_frame_copy(frame, tmp);
1753 6863 av_frame_free(&tmp);
1754
1755 6863 return 0;
1756 }
1757
1758 7763 int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
1759 {
1760 7763 int ret = reget_buffer_internal(avctx, frame, flags);
1761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7763 times.
7763 if (ret < 0)
1762 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
1763 7763 return ret;
1764 }
1765
1766 typedef struct ProgressInternal {
1767 ThreadProgress progress;
1768 struct AVFrame *f;
1769 } ProgressInternal;
1770
1771 441792 static void check_progress_consistency(const ProgressFrame *f)
1772 {
1773 av_assert1(!!f->f == !!f->progress);
1774 av_assert1(!f->progress || f->progress->f == f->f);
1775 441792 }
1776
1777 16767 int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
1778 {
1779 16767 AVRefStructPool *pool = avctx->internal->progress_frame_pool;
1780
1781 av_assert1(!f->f && !f->progress);
1782
1783 16767 f->progress = av_refstruct_pool_get(pool);
1784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16767 times.
16767 if (!f->progress)
1785 return AVERROR(ENOMEM);
1786
1787 16767 f->f = f->progress->f;
1788 16767 return 0;
1789 }
1790
1791 6426 int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
1792 {
1793 6426 int ret = ff_progress_frame_alloc(avctx, f);
1794
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6426 times.
6426 if (ret < 0)
1795 return ret;
1796
1797 6426 ret = ff_thread_get_buffer(avctx, f->progress->f, flags);
1798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6426 times.
6426 if (ret < 0) {
1799 f->f = NULL;
1800 av_refstruct_unref(&f->progress);
1801 return ret;
1802 }
1803 6426 return 0;
1804 }
1805
1806 38994 void ff_progress_frame_ref(ProgressFrame *dst, const ProgressFrame *src)
1807 {
1808 av_assert1(src->progress && src->f && src->f == src->progress->f);
1809 av_assert1(!dst->f && !dst->progress);
1810 38994 dst->f = src->f;
1811 38994 dst->progress = av_refstruct_ref(src->progress);
1812 38994 }
1813
1814 401584 void ff_progress_frame_unref(ProgressFrame *f)
1815 {
1816 401584 check_progress_consistency(f);
1817 401584 f->f = NULL;
1818 401584 av_refstruct_unref(&f->progress);
1819 401584 }
1820
1821 40208 void ff_progress_frame_replace(ProgressFrame *dst, const ProgressFrame *src)
1822 {
1823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40208 times.
40208 if (dst == src)
1824 return;
1825 40208 ff_progress_frame_unref(dst);
1826 40208 check_progress_consistency(src);
1827
2/2
✓ Branch 0 taken 38927 times.
✓ Branch 1 taken 1281 times.
40208 if (src->f)
1828 38927 ff_progress_frame_ref(dst, src);
1829 }
1830
1831 19587 void ff_progress_frame_report(ProgressFrame *f, int n)
1832 {
1833 19587 ff_thread_progress_report(&f->progress->progress, n);
1834 19587 }
1835
1836 2598246 void ff_progress_frame_await(const ProgressFrame *f, int n)
1837 {
1838 2598246 ff_thread_progress_await(&f->progress->progress, n);
1839 2598246 }
1840
1841 #if !HAVE_THREADS
1842 enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
1843 {
1844 return FF_THREAD_NO_FRAME_THREADING;
1845 }
1846 #endif /* !HAVE_THREADS */
1847
1848 2544 static av_cold int progress_frame_pool_init_cb(AVRefStructOpaque opaque, void *obj)
1849 {
1850 2544 const AVCodecContext *avctx = opaque.nc;
1851 2544 ProgressInternal *progress = obj;
1852 int ret;
1853
1854 2544 ret = ff_thread_progress_init(&progress->progress, avctx->active_thread_type & FF_THREAD_FRAME);
1855
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544 times.
2544 if (ret < 0)
1856 return ret;
1857
1858 2544 progress->f = av_frame_alloc();
1859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544 times.
2544 if (!progress->f)
1860 return AVERROR(ENOMEM);
1861
1862 2544 return 0;
1863 }
1864
1865 16767 static void progress_frame_pool_reset_cb(AVRefStructOpaque unused, void *obj)
1866 {
1867 16767 ProgressInternal *progress = obj;
1868
1869 16767 ff_thread_progress_reset(&progress->progress);
1870 16767 av_frame_unref(progress->f);
1871 16767 }
1872
1873 2544 static av_cold void progress_frame_pool_free_entry_cb(AVRefStructOpaque opaque, void *obj)
1874 {
1875 2544 ProgressInternal *progress = obj;
1876
1877 2544 ff_thread_progress_destroy(&progress->progress);
1878 2544 av_frame_free(&progress->f);
1879 2544 }
1880
1881 15470 int ff_decode_preinit(AVCodecContext *avctx)
1882 {
1883 15470 AVCodecInternal *avci = avctx->internal;
1884 15470 DecodeContext *dc = decode_ctx(avci);
1885 15470 int ret = 0;
1886
1887 15470 dc->initial_pict_type = AV_PICTURE_TYPE_NONE;
1888
2/2
✓ Branch 0 taken 11781 times.
✓ Branch 1 taken 3689 times.
15470 if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
1889 11781 dc->intra_only_flag = AV_FRAME_FLAG_KEY;
1890
2/2
✓ Branch 0 taken 8749 times.
✓ Branch 1 taken 3032 times.
11781 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
1891 8749 dc->initial_pict_type = AV_PICTURE_TYPE_I;
1892 }
1893
1894 /* if the decoder init function was already called previously,
1895 * free the already allocated subtitle_header before overwriting it */
1896 15470 av_freep(&avctx->subtitle_header);
1897
1898
2/4
✓ Branch 0 taken 15470 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15470 times.
15470 if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
1899 av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
1900 avctx->codec->max_lowres);
1901 avctx->lowres = avctx->codec->max_lowres;
1902 }
1903
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 15464 times.
15470 if (avctx->sub_charenc) {
1904
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1905 av_log(avctx, AV_LOG_ERROR, "Character encoding is only "
1906 "supported with subtitles codecs\n");
1907 return AVERROR(EINVAL);
1908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) {
1909 av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, "
1910 "subtitles character encoding will be ignored\n",
1911 avctx->codec_descriptor->name);
1912 avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_DO_NOTHING;
1913 } else {
1914 /* input character encoding is set for a text based subtitle
1915 * codec at this point */
1916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_AUTOMATIC)
1917 6 avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_PRE_DECODER;
1918
1919
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_PRE_DECODER) {
1920 #if CONFIG_ICONV
1921 6 iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc);
1922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (cd == (iconv_t)-1) {
1923 ret = AVERROR(errno);
1924 av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context "
1925 "with input character encoding \"%s\"\n", avctx->sub_charenc);
1926 return ret;
1927 }
1928 6 iconv_close(cd);
1929 #else
1930 av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles "
1931 "conversion needs a libavcodec built with iconv support "
1932 "for this codec\n");
1933 return AVERROR(ENOSYS);
1934 #endif
1935 }
1936 }
1937 }
1938
1939 15470 dc->pts_correction_num_faulty_pts =
1940 15470 dc->pts_correction_num_faulty_dts = 0;
1941 15470 dc->pts_correction_last_pts =
1942 15470 dc->pts_correction_last_dts = INT64_MIN;
1943
1944
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if ( !CONFIG_GRAY && avctx->flags & AV_CODEC_FLAG_GRAY
1945 && avctx->codec_descriptor->type == AVMEDIA_TYPE_VIDEO)
1946 av_log(avctx, AV_LOG_WARNING,
1947 "gray decoding requested but not enabled at configuration time\n");
1948
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15465 times.
15470 if (avctx->flags2 & AV_CODEC_FLAG2_EXPORT_MVS) {
1949 5 avctx->export_side_data |= AV_CODEC_EXPORT_DATA_MVS;
1950 }
1951
1952
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if (avctx->nb_side_data_prefer_packet == 1 &&
1953 avctx->side_data_prefer_packet[0] == -1)
1954 dc->side_data_pref_mask = ~0ULL;
1955 else {
1956
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 15470 times.
15474 for (unsigned i = 0; i < avctx->nb_side_data_prefer_packet; i++) {
1957 4 int val = avctx->side_data_prefer_packet[i];
1958
1959
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (val < 0 || val >= AV_PKT_DATA_NB) {
1960 av_log(avctx, AV_LOG_ERROR, "Invalid side data type: %d\n", val);
1961 return AVERROR(EINVAL);
1962 }
1963
1964
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 4 times.
40 for (unsigned j = 0; ff_sd_global_map[j].packet < AV_PKT_DATA_NB; j++) {
1965
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 32 times.
36 if (ff_sd_global_map[j].packet == val) {
1966 4 val = ff_sd_global_map[j].frame;
1967
1968 // this code will need to be changed when we have more than
1969 // 64 frame side data types
1970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (val >= 64) {
1971 av_log(avctx, AV_LOG_ERROR, "Side data type too big\n");
1972 return AVERROR_BUG;
1973 }
1974
1975 4 dc->side_data_pref_mask |= 1ULL << val;
1976 }
1977 }
1978 }
1979 }
1980
1981 15470 avci->in_pkt = av_packet_alloc();
1982 15470 avci->last_pkt_props = av_packet_alloc();
1983
2/4
✓ Branch 0 taken 15470 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15470 times.
15470 if (!avci->in_pkt || !avci->last_pkt_props)
1984 return AVERROR(ENOMEM);
1985
1986
2/2
✓ Branch 1 taken 1351 times.
✓ Branch 2 taken 14119 times.
15470 if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_USES_PROGRESSFRAMES) {
1987 1351 avci->progress_frame_pool =
1988 1351 av_refstruct_pool_alloc_ext(sizeof(ProgressInternal),
1989 AV_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR,
1990 avctx, progress_frame_pool_init_cb,
1991 progress_frame_pool_reset_cb,
1992 progress_frame_pool_free_entry_cb, NULL);
1993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1351 times.
1351 if (!avci->progress_frame_pool)
1994 return AVERROR(ENOMEM);
1995 }
1996 15470 ret = decode_bsfs_init(avctx);
1997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
15470 if (ret < 0)
1998 return ret;
1999
2000
1/2
✓ Branch 0 taken 15470 times.
✗ Branch 1 not taken.
15470 if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_ENHANCEMENTS)) {
2001 15470 ret = ff_lcevc_alloc(&dc->lcevc);
2002
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15470 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15470 if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
2003 return ret;
2004 }
2005
2006 15470 return 0;
2007 }
2008
2009 /**
2010 * Check side data preference and clear existing side data from frame
2011 * if needed.
2012 *
2013 * @retval 0 side data of this type can be added to frame
2014 * @retval 1 side data of this type should not be added to frame
2015 */
2016 5600 static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd,
2017 int *nb_sd, enum AVFrameSideDataType type)
2018 {
2019 5600 DecodeContext *dc = decode_ctx(avctx->internal);
2020
2021 // Note: could be skipped for `type` without corresponding packet sd
2022
2/2
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 5578 times.
5600 if (av_frame_side_data_get(*sd, *nb_sd, type)) {
2023
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12 times.
22 if (dc->side_data_pref_mask & (1ULL << type))
2024 10 return 1;
2025 12 av_frame_side_data_remove(sd, nb_sd, type);
2026 }
2027
2028 5590 return 0;
2029 }
2030
2031
2032 4795 int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame,
2033 enum AVFrameSideDataType type, size_t size,
2034 AVFrameSideData **psd)
2035 {
2036 AVFrameSideData *sd;
2037
2038
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4795 times.
4795 if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data, type)) {
2039 if (psd)
2040 *psd = NULL;
2041 return 0;
2042 }
2043
2044 4795 sd = av_frame_new_side_data(frame, type, size);
2045
1/2
✓ Branch 0 taken 4795 times.
✗ Branch 1 not taken.
4795 if (psd)
2046 4795 *psd = sd;
2047
2048
1/2
✓ Branch 0 taken 4795 times.
✗ Branch 1 not taken.
4795 return sd ? 0 : AVERROR(ENOMEM);
2049 }
2050
2051 758 int ff_frame_new_side_data_from_buf_ext(const AVCodecContext *avctx,
2052 AVFrameSideData ***sd, int *nb_sd,
2053 enum AVFrameSideDataType type,
2054 AVBufferRef **buf)
2055 {
2056 758 int ret = 0;
2057
2058
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 758 times.
758 if (side_data_pref(avctx, sd, nb_sd, type))
2059 goto finish;
2060
2061
1/2
✓ Branch 1 taken 758 times.
✗ Branch 2 not taken.
758 if (!av_frame_side_data_add(sd, nb_sd, type, buf, 0))
2062 ret = AVERROR(ENOMEM);
2063
2064 758 finish:
2065 758 av_buffer_unref(buf);
2066
2067 758 return ret;
2068 }
2069
2070 748 int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
2071 AVFrame *frame, enum AVFrameSideDataType type,
2072 AVBufferRef **buf)
2073 {
2074 748 return ff_frame_new_side_data_from_buf_ext(avctx,
2075 &frame->side_data, &frame->nb_side_data,
2076 type, buf);
2077 }
2078
2079 35 int ff_decode_mastering_display_new_ext(const AVCodecContext *avctx,
2080 AVFrameSideData ***sd, int *nb_sd,
2081 struct AVMasteringDisplayMetadata **mdm)
2082 {
2083 AVBufferRef *buf;
2084 size_t size;
2085
2086
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 25 times.
35 if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) {
2087 10 *mdm = NULL;
2088 10 return 0;
2089 }
2090
2091 25 *mdm = av_mastering_display_metadata_alloc_size(&size);
2092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (!*mdm)
2093 return AVERROR(ENOMEM);
2094
2095 25 buf = av_buffer_create((uint8_t *)*mdm, size, NULL, NULL, 0);
2096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if (!buf) {
2097 av_freep(mdm);
2098 return AVERROR(ENOMEM);
2099 }
2100
2101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
25 if (!av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
2102 &buf, 0)) {
2103 *mdm = NULL;
2104 av_buffer_unref(&buf);
2105 return AVERROR(ENOMEM);
2106 }
2107
2108 25 return 0;
2109 }
2110
2111 2 int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame,
2112 AVMasteringDisplayMetadata **mdm)
2113 {
2114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2115 AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) {
2116 *mdm = NULL;
2117 return 0;
2118 }
2119
2120 2 *mdm = av_mastering_display_metadata_create_side_data(frame);
2121
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 return *mdm ? 0 : AVERROR(ENOMEM);
2122 }
2123
2124 8 int ff_decode_content_light_new_ext(const AVCodecContext *avctx,
2125 AVFrameSideData ***sd, int *nb_sd,
2126 AVContentLightMetadata **clm)
2127 {
2128 AVBufferRef *buf;
2129 size_t size;
2130
2131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (side_data_pref(avctx, sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) {
2132 *clm = NULL;
2133 return 0;
2134 }
2135
2136 8 *clm = av_content_light_metadata_alloc(&size);
2137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!*clm)
2138 return AVERROR(ENOMEM);
2139
2140 8 buf = av_buffer_create((uint8_t *)*clm, size, NULL, NULL, 0);
2141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (!buf) {
2142 av_freep(clm);
2143 return AVERROR(ENOMEM);
2144 }
2145
2146
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 if (!av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL,
2147 &buf, 0)) {
2148 *clm = NULL;
2149 av_buffer_unref(&buf);
2150 return AVERROR(ENOMEM);
2151 }
2152
2153 8 return 0;
2154 }
2155
2156 2 int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame,
2157 AVContentLightMetadata **clm)
2158 {
2159
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if (side_data_pref(avctx, &frame->side_data, &frame->nb_side_data,
2160 AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) {
2161 *clm = NULL;
2162 return 0;
2163 }
2164
2165 2 *clm = av_content_light_metadata_create_side_data(frame);
2166
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 return *clm ? 0 : AVERROR(ENOMEM);
2167 }
2168
2169 1673 int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
2170 {
2171 size_t size;
2172 1673 const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size);
2173
2174
3/4
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1641 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
1673 if (pal && size == AVPALETTE_SIZE) {
2175 32 memcpy(dst, pal, AVPALETTE_SIZE);
2176 32 return 1;
2177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1641 times.
1641 } else if (pal) {
2178 av_log(logctx, AV_LOG_ERROR,
2179 "Palette size %"SIZE_SPECIFIER" is wrong\n", size);
2180 }
2181 1641 return 0;
2182 }
2183
2184 53767 int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private)
2185 {
2186 53767 const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
2187
2188
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 53767 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
53767 if (!hwaccel || !hwaccel->frame_priv_data_size)
2189 53767 return 0;
2190
2191 av_assert0(!*hwaccel_picture_private);
2192
2193 if (hwaccel->free_frame_priv) {
2194 AVHWFramesContext *frames_ctx;
2195
2196 if (!avctx->hw_frames_ctx)
2197 return AVERROR(EINVAL);
2198
2199 frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data;
2200 *hwaccel_picture_private = av_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0,
2201 frames_ctx->device_ctx,
2202 hwaccel->free_frame_priv);
2203 } else {
2204 *hwaccel_picture_private = av_refstruct_allocz(hwaccel->frame_priv_data_size);
2205 }
2206
2207 if (!*hwaccel_picture_private)
2208 return AVERROR(ENOMEM);
2209
2210 return 0;
2211 }
2212
2213 104 void ff_decode_flush_buffers(AVCodecContext *avctx)
2214 {
2215 104 AVCodecInternal *avci = avctx->internal;
2216 104 DecodeContext *dc = decode_ctx(avci);
2217
2218 104 av_packet_unref(avci->last_pkt_props);
2219 104 av_packet_unref(avci->in_pkt);
2220
2221 104 dc->pts_correction_last_pts =
2222 104 dc->pts_correction_last_dts = INT64_MIN;
2223
2224
1/2
✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
104 if (avci->bsf)
2225 104 av_bsf_flush(avci->bsf);
2226
2227 104 dc->nb_draining_errors = 0;
2228 104 dc->draining_started = 0;
2229 104 }
2230
2231 15546 AVCodecInternal *ff_decode_internal_alloc(void)
2232 {
2233 15546 return av_mallocz(sizeof(DecodeContext));
2234 }
2235
2236 740 void ff_decode_internal_sync(AVCodecContext *dst, const AVCodecContext *src)
2237 {
2238 740 const DecodeContext *src_dc = decode_ctx(src->internal);
2239 740 DecodeContext *dst_dc = decode_ctx(dst->internal);
2240
2241 740 av_refstruct_replace(&dst_dc->lcevc, src_dc->lcevc);
2242 740 }
2243
2244 15546 void ff_decode_internal_uninit(AVCodecContext *avctx)
2245 {
2246 15546 AVCodecInternal *avci = avctx->internal;
2247 15546 DecodeContext *dc = decode_ctx(avci);
2248
2249 15546 av_refstruct_unref(&dc->lcevc);
2250 15546 }
2251