FFmpeg coverage


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