History

avcodec/decode: fill missing frame fields for all decoders

And not just those with the old decode() API.

James Almer committed 3 years ago

Commit dd7bdb41 parent 94ac6471 file · +48 −31Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/decode.c+48−31
@@ -292,7 +292,6 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, · 291 unmodified lines
292292 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
293293 {
294294 AVCodecInternal *avci = avctx->internal;
295− int ret = 0;
296295 AVFrameSideData *side;
297296 uint32_t discard_padding = 0;
298297 uint8_t skip_reason = 0;
@@ -309,26 +308,6 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca · 10 unmodified lines
309308 discard_reason = AV_RL8(side->data + 9);
310309 }
311310
312− if (frame->format == AV_SAMPLE_FMT_NONE)
313− frame->format = avctx->sample_fmt;
314− if (!frame->ch_layout.nb_channels) {
315− int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
316− if (ret2 < 0) {
317− ret = ret2;
318− }
319− }
320−#if FF_API_OLD_CHANNEL_LAYOUT
321−FF_DISABLE_DEPRECATION_WARNINGS
322− if (!frame->channel_layout)
323− frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
324− avctx->ch_layout.u.mask : 0;
325− if (!frame->channels)
326− frame->channels = avctx->ch_layout.nb_channels;
327−FF_ENABLE_DEPRECATION_WARNINGS
328−#endif
329− if (!frame->sample_rate)
330− frame->sample_rate = avctx->sample_rate;
331−
332311 if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
333312 if (!side && (avci->skip_samples || discard_padding))
334313 side = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10);
@@ -339,7 +318,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 4 unmodified lines
339318 AV_WL8(side->data + 9, discard_reason);
340319 avci->skip_samples = 0;
341320 }
342− return ret;
321+ return 0;
343322 }
344323 av_frame_remove_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES);
345324
@@ -399,7 +378,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 53 unmodified lines
399378 }
400379 }
401380
402− return ret;
381+ return 0;
403382 }
404383
405384 /*
@@ -449,14 +428,6 @@ FF_DISABLE_DEPRECATION_WARNINGS · 43 unmodified lines
449428 frame->pkt_pos = pkt->pos;
450429 FF_ENABLE_DEPRECATION_WARNINGS
451430 #endif
452− //FIXME these should be under if(!avctx->has_b_frames)
453− /* get_buffer is supposed to set frame parameters */
454− if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
455− if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
456− if (!frame->width) frame->width = avctx->width;
457− if (!frame->height) frame->height = avctx->height;
458− if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
459− }
460431 }
461432 }
462433 emms_c();
@@ -570,6 +541,45 @@ static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f) · 107 unmodified lines
570541 }
571542 #endif
572543
544+static int fill_frame_props(AVCodecContext *avctx, AVFrame *frame)
545+{
546+ int ret;
547+
548+ if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
549+ //FIXME these should be under if(!avctx->has_b_frames)
550+ /* get_buffer is supposed to set frame parameters */
551+ if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
552+ if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
553+ if (!frame->width) frame->width = avctx->width;
554+ if (!frame->height) frame->height = avctx->height;
555+ if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
556+ }
557+ } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
558+ if (frame->format == AV_SAMPLE_FMT_NONE)
559+ frame->format = avctx->sample_fmt;
560+ if (!frame->ch_layout.nb_channels) {
561+ ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
562+ if (ret < 0) {
563+ av_frame_unref(frame);
564+ return ret;
565+ }
566+ }
567+#if FF_API_OLD_CHANNEL_LAYOUT
568+FF_DISABLE_DEPRECATION_WARNINGS
569+ if (!frame->channel_layout)
570+ frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
571+ avctx->ch_layout.u.mask : 0;
572+ if (!frame->channels)
573+ frame->channels = avctx->ch_layout.nb_channels;
574+FF_ENABLE_DEPRECATION_WARNINGS
575+#endif
576+ if (!frame->sample_rate)
577+ frame->sample_rate = avctx->sample_rate;
578+ }
579+
580+ return 0;
581+}
582+
573583 static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame)
574584 {
575585 int ret;
@@ -621,6 +631,13 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 45 unmodified lines
621631 if (!ret) {
622632 if (avctx->codec_type != AVMEDIA_TYPE_VIDEO)
623633 frame->flags |= AV_FRAME_FLAG_KEY;
634+
635+ ret = fill_missing_fields(avctx, frame);
636+ if (ret < 0) {
637+ av_frame_unref(frame);
638+ return ret;
639+ }
640+
624641 #if FF_API_FRAME_KEY
625642 FF_DISABLE_DEPRECATION_WARNINGS
626643 frame->key_frame = !!(frame->flags & AV_FRAME_FLAG_KEY);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t