Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function
@ 2023-07-12 22:07 James Almer
  2023-07-12 22:07 ` [FFmpeg-devel] [PATCH 2/4] avcodec/decode: simplify applying or exporting skip samples James Almer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: James Almer @ 2023-07-12 22:07 UTC (permalink / raw)
  To: ffmpeg-devel

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

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 239ad70b41..4478c8c4fe 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -289,6 +289,123 @@ static int64_t guess_correct_pts(AVCodecContext *ctx,
     return pts;
 }
 
+static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
+{
+    AVCodecInternal *avci = avctx->internal;
+    int ret = 0;
+    uint8_t *side;
+    size_t side_size;
+    uint32_t discard_padding = 0;
+    uint8_t skip_reason = 0;
+    uint8_t discard_reason = 0;
+
+    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);
+        avci->skip_samples = FFMAX(0, avci->skip_samples);
+        discard_padding = AV_RL32(side + 4);
+        av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
+               avci->skip_samples, (int)discard_padding);
+        skip_reason = AV_RL8(side + 8);
+        discard_reason = AV_RL8(side + 9);
+    }
+
+    if (!frame->buf[0])
+        return AVERROR(EAGAIN);
+
+    if (frame->format == AV_SAMPLE_FMT_NONE)
+        frame->format = avctx->sample_fmt;
+    if (!frame->ch_layout.nb_channels) {
+        int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
+        if (ret2 < 0) {
+            ret = ret2;
+        }
+    }
+#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;
+
+    if ((frame->flags & AV_FRAME_FLAG_DISCARD) &&
+        !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
+        avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
+        *discarded_samples += frame->nb_samples;
+        return AVERROR(EAGAIN);
+    }
+
+    if (avci->skip_samples > 0 &&
+        !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
+        if (frame->nb_samples <= avci->skip_samples){
+            *discarded_samples += frame->nb_samples;
+            avci->skip_samples -= frame->nb_samples;
+            av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
+                   avci->skip_samples);
+            return AVERROR(EAGAIN);
+        } else {
+            av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
+                            frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
+            if (avctx->pkt_timebase.num && avctx->sample_rate) {
+                int64_t diff_ts = av_rescale_q(avci->skip_samples,
+                                               (AVRational){1, avctx->sample_rate},
+                                               avctx->pkt_timebase);
+                if (frame->pts != AV_NOPTS_VALUE)
+                    frame->pts += diff_ts;
+                if (frame->pkt_dts != AV_NOPTS_VALUE)
+                    frame->pkt_dts += diff_ts;
+                if (frame->duration >= diff_ts)
+                    frame->duration -= diff_ts;
+            } else
+                av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
+
+            av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
+                   avci->skip_samples, frame->nb_samples);
+            *discarded_samples += avci->skip_samples;
+            frame->nb_samples -= avci->skip_samples;
+            avci->skip_samples = 0;
+        }
+    }
+
+    if (discard_padding > 0 && discard_padding <= frame->nb_samples &&
+        !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
+        if (discard_padding == frame->nb_samples) {
+            *discarded_samples += frame->nb_samples;
+            return AVERROR(EAGAIN);
+        } else {
+            if (avctx->pkt_timebase.num && avctx->sample_rate) {
+                int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
+                                               (AVRational){1, avctx->sample_rate},
+                                               avctx->pkt_timebase);
+                frame->duration = diff_ts;
+            } else
+                av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
+
+            av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
+                   (int)discard_padding, frame->nb_samples);
+            frame->nb_samples -= discard_padding;
+        }
+    }
+
+    if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
+        AVFrameSideData *fside = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10);
+        if (fside) {
+            AV_WL32(fside->data, avci->skip_samples);
+            AV_WL32(fside->data + 4, discard_padding);
+            AV_WL8(fside->data + 8, skip_reason);
+            AV_WL8(fside->data + 9, discard_reason);
+            avci->skip_samples = 0;
+        }
+    }
+
+    return ret;
+}
+
 /*
  * The core of the receive_frame_wrapper for the decoders implementing
  * the simple API. Certain decoders might consume partial packets without
@@ -300,7 +417,7 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
     AVCodecInternal   *avci = avctx->internal;
     AVPacket     *const pkt = avci->in_pkt;
     const FFCodec *const codec = ffcodec(avctx->codec);
-    int got_frame, actual_got_frame;
+    int got_frame, consumed;
     int ret;
 
     if (!pkt->data && !avci->draining) {
@@ -323,9 +440,9 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
     got_frame = 0;
 
     if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
-        ret = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
+        consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
     } else {
-        ret = codec->cb.decode(avctx, frame, &got_frame, pkt);
+        consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
 
         if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
             frame->pkt_dts = pkt->dts;
@@ -347,132 +464,33 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
     emms_c();
-    actual_got_frame = got_frame;
+
+    if (!got_frame)
+        av_frame_unref(frame);
 
     if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
-        if (frame->flags & AV_FRAME_FLAG_DISCARD)
-            got_frame = 0;
+        ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
+                          ? AVERROR(EAGAIN)
+                          : 0;
     } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
-        uint8_t *side;
-        size_t side_size;
-        uint32_t discard_padding = 0;
-        uint8_t skip_reason = 0;
-        uint8_t discard_reason = 0;
-
-        if (ret >= 0 && got_frame) {
-            if (frame->format == AV_SAMPLE_FMT_NONE)
-                frame->format = avctx->sample_fmt;
-            if (!frame->ch_layout.nb_channels) {
-                int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
-                if (ret2 < 0) {
-                    ret = ret2;
-                    got_frame = 0;
-                }
-            }
-#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);
-            avci->skip_samples = FFMAX(0, avci->skip_samples);
-            discard_padding = AV_RL32(side + 4);
-            av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
-                   avci->skip_samples, (int)discard_padding);
-            skip_reason = AV_RL8(side + 8);
-            discard_reason = AV_RL8(side + 9);
-        }
-
-        if ((frame->flags & AV_FRAME_FLAG_DISCARD) && got_frame &&
-            !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
-            avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
-            got_frame = 0;
-            *discarded_samples += frame->nb_samples;
-        }
-
-        if (avci->skip_samples > 0 && got_frame &&
-            !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
-            if(frame->nb_samples <= avci->skip_samples){
-                got_frame = 0;
-                *discarded_samples += frame->nb_samples;
-                avci->skip_samples -= frame->nb_samples;
-                av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n",
-                       avci->skip_samples);
-            } else {
-                av_samples_copy(frame->extended_data, frame->extended_data, 0, avci->skip_samples,
-                                frame->nb_samples - avci->skip_samples, avctx->ch_layout.nb_channels, frame->format);
-                if(avctx->pkt_timebase.num && avctx->sample_rate) {
-                    int64_t diff_ts = av_rescale_q(avci->skip_samples,
-                                                   (AVRational){1, avctx->sample_rate},
-                                                   avctx->pkt_timebase);
-                    if(frame->pts!=AV_NOPTS_VALUE)
-                        frame->pts += diff_ts;
-                    if(frame->pkt_dts!=AV_NOPTS_VALUE)
-                        frame->pkt_dts += diff_ts;
-                    if (frame->duration >= diff_ts)
-                        frame->duration -= diff_ts;
-                } else {
-                    av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n");
-                }
-                av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n",
-                       avci->skip_samples, frame->nb_samples);
-                *discarded_samples += avci->skip_samples;
-                frame->nb_samples -= avci->skip_samples;
-                avci->skip_samples = 0;
-            }
-        }
-
-        if (discard_padding > 0 && discard_padding <= frame->nb_samples && got_frame &&
-            !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
-            if (discard_padding == frame->nb_samples) {
-                *discarded_samples += frame->nb_samples;
-                got_frame = 0;
-            } else {
-                if(avctx->pkt_timebase.num && avctx->sample_rate) {
-                    int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding,
-                                                   (AVRational){1, avctx->sample_rate},
-                                                   avctx->pkt_timebase);
-                    frame->duration = diff_ts;
-                } else {
-                    av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n");
-                }
-                av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n",
-                       (int)discard_padding, frame->nb_samples);
-                frame->nb_samples -= discard_padding;
-            }
-        }
-
-        if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL) && got_frame) {
-            AVFrameSideData *fside = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10);
-            if (fside) {
-                AV_WL32(fside->data, avci->skip_samples);
-                AV_WL32(fside->data + 4, discard_padding);
-                AV_WL8(fside->data + 8, skip_reason);
-                AV_WL8(fside->data + 9, discard_reason);
-                avci->skip_samples = 0;
-            }
-        }
+        ret = discard_samples(avctx, frame, discarded_samples);
     }
 
-    if (!got_frame)
+    if (ret == AVERROR(EAGAIN))
         av_frame_unref(frame);
 
-    if (ret >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
-        ret = pkt->size;
+    if (consumed < 0)
+        ret = consumed;
+    if (consumed >= 0 && avctx->codec->type == AVMEDIA_TYPE_VIDEO)
+        consumed = pkt->size;
+
+    if (!ret)
+        av_assert0(frame->buf[0]);
+    if (ret == AVERROR(EAGAIN))
+        ret = 0;
 
-    /* do not stop draining when actual_got_frame != 0 or ret < 0 */
-    /* got_frame == 0 but actual_got_frame != 0 when frame is discarded */
-    if (avci->draining && !actual_got_frame) {
+    /* do not stop draining when got_frame != 0 or ret < 0 */
+    if (avci->draining && !got_frame) {
         if (ret < 0) {
             /* prevent infinite loop if a decoder wrongly always return error on draining */
             /* reasonable nb_errors_max = maximum b frames + thread count */
@@ -490,11 +508,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 
-    if (ret >= pkt->size || ret < 0) {
+    if (consumed >= pkt->size || ret < 0) {
         av_packet_unref(pkt);
     } else {
-        int consumed = ret;
-
         pkt->data                += consumed;
         pkt->size                -= consumed;
         pkt->pts                  = AV_NOPTS_VALUE;
@@ -509,10 +525,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 
-    if (got_frame)
-        av_assert0(frame->buf[0]);
-
-    return ret < 0 ? ret : 0;
+    return ret;
 }
 
 #if CONFIG_LCMS2
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH 2/4] avcodec/decode: simplify applying or exporting skip samples
  2023-07-12 22:07 [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer
@ 2023-07-12 22:07 ` James Almer
  2023-07-12 22:07 ` [FFmpeg-devel] [PATCH v4 3/4] avcodec/decode: fill missing frame fields for all decoders James Almer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2023-07-12 22:07 UTC (permalink / raw)
  To: ffmpeg-devel

Copy packet side data to the output frame in ff_decode_frame_props_from_pkt()
instead of in discard_samples(), having the latter only applying the skip if
required.
This will be useful for the following commit.

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

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 4478c8c4fe..57d38cbc54 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -293,26 +293,18 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca
 {
     AVCodecInternal *avci = avctx->internal;
     int ret = 0;
-    uint8_t *side;
-    size_t side_size;
+    AVFrameSideData *side;
     uint32_t discard_padding = 0;
-    uint8_t skip_reason = 0;
-    uint8_t discard_reason = 0;
 
-    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);
+    side = av_frame_get_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES);
+    if (side && side->size >= 10) {
+        avci->skip_samples = AV_RL32(side->data);
         avci->skip_samples = FFMAX(0, avci->skip_samples);
-        discard_padding = AV_RL32(side + 4);
+        discard_padding = AV_RL32(side->data + 4);
         av_log(avctx, AV_LOG_DEBUG, "skip %d / discard %d samples due to side data\n",
                avci->skip_samples, (int)discard_padding);
-        skip_reason = AV_RL8(side + 8);
-        discard_reason = AV_RL8(side + 9);
     }
 
-    if (!frame->buf[0])
-        return AVERROR(EAGAIN);
-
     if (frame->format == AV_SAMPLE_FMT_NONE)
         frame->format = avctx->sample_fmt;
     if (!frame->ch_layout.nb_channels) {
@@ -392,16 +384,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 
-    if ((avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
-        AVFrameSideData *fside = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10);
-        if (fside) {
-            AV_WL32(fside->data, avci->skip_samples);
-            AV_WL32(fside->data + 4, discard_padding);
-            AV_WL8(fside->data + 8, skip_reason);
-            AV_WL8(fside->data + 9, discard_reason);
-            avci->skip_samples = 0;
-        }
-    }
+    if (!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL))
+        av_frame_remove_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES);
 
     return ret;
 }
@@ -465,15 +449,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
     }
     emms_c();
 
-    if (!got_frame)
-        av_frame_unref(frame);
-
     if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
         ret = (!got_frame || frame->flags & AV_FRAME_FLAG_DISCARD)
                           ? AVERROR(EAGAIN)
                           : 0;
     } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
-        ret = discard_samples(avctx, frame, discarded_samples);
+        ret =  !got_frame ? AVERROR(EAGAIN)
+                          : discard_samples(avctx, frame, discarded_samples);
     }
 
     if (ret == AVERROR(EAGAIN))
@@ -1386,6 +1368,7 @@ int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
         { AV_PKT_DATA_ICC_PROFILE,                AV_FRAME_DATA_ICC_PROFILE },
         { AV_PKT_DATA_S12M_TIMECODE,              AV_FRAME_DATA_S12M_TIMECODE },
         { AV_PKT_DATA_DYNAMIC_HDR10_PLUS,         AV_FRAME_DATA_DYNAMIC_HDR_PLUS },
+        { AV_PKT_DATA_SKIP_SAMPLES,               AV_FRAME_DATA_SKIP_SAMPLES },
     };
 
     frame->pts          = pkt->pts;
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH v4 3/4] avcodec/decode: fill missing frame fields for all decoders
  2023-07-12 22:07 [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer
  2023-07-12 22:07 ` [FFmpeg-devel] [PATCH 2/4] avcodec/decode: simplify applying or exporting skip samples James Almer
@ 2023-07-12 22:07 ` James Almer
  2023-07-12 22:07 ` [FFmpeg-devel] [PATCH v3 4/4] avcodec/decode: check the output frame for discard samples with " James Almer
  2023-07-14 17:02 ` [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer
  3 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2023-07-12 22:07 UTC (permalink / raw)
  To: ffmpeg-devel

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

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

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 57d38cbc54..d1aa183b78 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -292,7 +292,6 @@ static int64_t guess_correct_pts(AVCodecContext *ctx,
 static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
 {
     AVCodecInternal *avci = avctx->internal;
-    int ret = 0;
     AVFrameSideData *side;
     uint32_t discard_padding = 0;
 
@@ -305,26 +304,6 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca
                avci->skip_samples, (int)discard_padding);
     }
 
-    if (frame->format == AV_SAMPLE_FMT_NONE)
-        frame->format = avctx->sample_fmt;
-    if (!frame->ch_layout.nb_channels) {
-        int ret2 = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
-        if (ret2 < 0) {
-            ret = ret2;
-        }
-    }
-#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;
-
     if ((frame->flags & AV_FRAME_FLAG_DISCARD) &&
         !(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL)) {
         avci->skip_samples = FFMAX(0, avci->skip_samples - frame->nb_samples);
@@ -387,7 +366,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     if (!(avctx->flags2 & AV_CODEC_FLAG2_SKIP_MANUAL))
         av_frame_remove_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES);
 
-    return ret;
+    return 0;
 }
 
 /*
@@ -437,14 +416,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();
@@ -599,8 +570,40 @@ 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) {
+            //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;
+            }
+        } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
+            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 (ret < 0) {
+                    av_frame_unref(frame);
+                    return ret;
+                }
+            }
+#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);
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [FFmpeg-devel] [PATCH v3 4/4] avcodec/decode: check the output frame for discard samples with all decoders
  2023-07-12 22:07 [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer
  2023-07-12 22:07 ` [FFmpeg-devel] [PATCH 2/4] avcodec/decode: simplify applying or exporting skip samples James Almer
  2023-07-12 22:07 ` [FFmpeg-devel] [PATCH v4 3/4] avcodec/decode: fill missing frame fields for all decoders James Almer
@ 2023-07-12 22:07 ` James Almer
  2023-07-14 17:02 ` [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer
  3 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2023-07-12 22:07 UTC (permalink / raw)
  To: ffmpeg-devel

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

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

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index d1aa183b78..b8c1862ad8 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -556,6 +556,14 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
     if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
         ret = codec->cb.receive_frame(avctx, frame);
         emms_c();
+        if (!ret) {
+            if (avctx->codec->type == AVMEDIA_TYPE_VIDEO)
+                ret = (frame->flags & AV_FRAME_FLAG_DISCARD) ? AVERROR(EAGAIN) : 0;
+            else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
+                int64_t discarded_samples = 0;
+                ret = discard_samples(avctx, frame, &discarded_samples);
+            }
+        }
     } else
         ret = decode_simple_receive_frame(avctx, frame);
 
-- 
2.41.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function
  2023-07-12 22:07 [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer
                   ` (2 preceding siblings ...)
  2023-07-12 22:07 ` [FFmpeg-devel] [PATCH v3 4/4] avcodec/decode: check the output frame for discard samples with " James Almer
@ 2023-07-14 17:02 ` James Almer
  3 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2023-07-14 17:02 UTC (permalink / raw)
  To: ffmpeg-devel

On 7/12/2023 7:07 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavcodec/decode.c | 269 +++++++++++++++++++++++---------------------
>   1 file changed, 141 insertions(+), 128 deletions(-)

Patchset applied.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-14 17:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-12 22:07 [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer
2023-07-12 22:07 ` [FFmpeg-devel] [PATCH 2/4] avcodec/decode: simplify applying or exporting skip samples James Almer
2023-07-12 22:07 ` [FFmpeg-devel] [PATCH v4 3/4] avcodec/decode: fill missing frame fields for all decoders James Almer
2023-07-12 22:07 ` [FFmpeg-devel] [PATCH v3 4/4] avcodec/decode: check the output frame for discard samples with " James Almer
2023-07-14 17:02 ` [FFmpeg-devel] [PATCH v4 1/4] avcodec/decode: move processing discard samples to its own function James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git