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