diff mbox series

[FFmpeg-devel,3/3] avcodec/decode: fill missing frame fields for all decoders

Message ID 20230708190038.24324-3-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/3] avcodec/decode: move processing discard samples to its own function | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer July 8, 2023, 7 p.m. UTC
And not just those with the old decode() API.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/decode.c | 52 +++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 25 deletions(-)

Comments

Anton Khirnov July 9, 2023, 9:49 a.m. UTC | #1
Quoting James Almer (2023-07-08 21:00:38)
> And not just those with the old decode() API.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/decode.c | 52 +++++++++++++++++++++++----------------------
>  1 file changed, 27 insertions(+), 25 deletions(-)

Is there a functional reason for this patch?

I've been wondering recently about dropping this code entirely, because
get_buffer() should always fill those fields.
James Almer July 9, 2023, 12:05 p.m. UTC | #2
On 7/9/2023 6:49 AM, Anton Khirnov wrote:
> Quoting James Almer (2023-07-08 21:00:38)
>> And not just those with the old decode() API.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavcodec/decode.c | 52 +++++++++++++++++++++++----------------------
>>   1 file changed, 27 insertions(+), 25 deletions(-)
> 
> Is there a functional reason for this patch?
> 
> I've been wondering recently about dropping this code entirely, because
> get_buffer() should always fill those fields.

Decoders that don't use get_buffer at all exist. If they don't fill all 
frame fields, this would.
Anton Khirnov July 9, 2023, 12:58 p.m. UTC | #3
Quoting James Almer (2023-07-09 14:05:45)
> On 7/9/2023 6:49 AM, Anton Khirnov wrote:
> > Quoting James Almer (2023-07-08 21:00:38)
> >> And not just those with the old decode() API.
> >>
> >> Signed-off-by: James Almer <jamrial@gmail.com>
> >> ---
> >>   libavcodec/decode.c | 52 +++++++++++++++++++++++----------------------
> >>   1 file changed, 27 insertions(+), 25 deletions(-)
> > 
> > Is there a functional reason for this patch?
> > 
> > I've been wondering recently about dropping this code entirely, because
> > get_buffer() should always fill those fields.
> 
> Decoders that don't use get_buffer at all exist. If they don't fill all 
> frame fields, this would.

Ah well, there's more of those than I thought.
No objections then.
diff mbox series

Patch

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 49c8b7e0f4..fe07e906c2 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -304,22 +304,6 @@  static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca
         uint8_t skip_reason = 0;
         uint8_t discard_reason = 0;
 
-            if (frame->format == AV_SAMPLE_FMT_NONE)
-                frame->format = avctx->sample_fmt;
-            if (!frame->ch_layout.nb_channels)
-                ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-            if (!frame->channel_layout)
-                frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
-                                        avctx->ch_layout.u.mask : 0;
-            if (!frame->channels)
-                frame->channels = avctx->ch_layout.nb_channels;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-            if (!frame->sample_rate)
-                frame->sample_rate = avctx->sample_rate;
-
         side= av_packet_get_side_data(avci->last_pkt_props, AV_PKT_DATA_SKIP_SAMPLES, &side_size);
         if(side && side_size>=10) {
             avci->skip_samples = AV_RL32(side);
@@ -452,14 +436,6 @@  FF_DISABLE_DEPRECATION_WARNINGS
                 frame->pkt_pos = pkt->pos;
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
-            //FIXME these should be under if(!avctx->has_b_frames)
-            /* get_buffer is supposed to set frame parameters */
-            if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
-                if (!frame->sample_aspect_ratio.num)  frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
-                if (!frame->width)                    frame->width               = avctx->width;
-                if (!frame->height)                   frame->height              = avctx->height;
-                if (frame->format == AV_PIX_FMT_NONE) frame->format              = avctx->pix_fmt;
-            }
         }
     }
     emms_c();
@@ -613,8 +589,34 @@  static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
     }
 
     if (!ret) {
-        if (avctx->codec_type != AVMEDIA_TYPE_VIDEO)
+        if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
+            /* get_buffer is supposed to set frame parameters */
+            if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
+                if (!frame->sample_aspect_ratio.num)  frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
+                if (!frame->width)                    frame->width               = avctx->width;
+                if (!frame->height)                   frame->height              = avctx->height;
+                if (frame->format == AV_PIX_FMT_NONE) frame->format              = avctx->pix_fmt;
+            }
+        } else {
+            if (frame->format == AV_SAMPLE_FMT_NONE)
+                frame->format = avctx->sample_fmt;
+            if (!frame->ch_layout.nb_channels)
+                ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+            if (!frame->channel_layout)
+                frame->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                        avctx->ch_layout.u.mask : 0;
+            if (!frame->channels)
+                frame->channels = avctx->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+            if (!frame->sample_rate)
+                frame->sample_rate = avctx->sample_rate;
+
             frame->flags |= AV_FRAME_FLAG_KEY;
+        }
+
 #if FF_API_FRAME_KEY
 FF_DISABLE_DEPRECATION_WARNINGS
         frame->key_frame = !!(frame->flags & AV_FRAME_FLAG_KEY);