[FFmpeg-cvslog] avcodec/mpegutils: Fix ff_draw_horiz_band()

Andreas Rheinhardt git at videolan.org
Thu Jun 20 20:00:16 EEST 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue Jun  4 12:14:10 2024 +0200| [c28e553cbfa70ba0ca635271f5154301889fb706] | committer: Andreas Rheinhardt

avcodec/mpegutils: Fix ff_draw_horiz_band()

Broken in 5ecf5b93dda9d0c69875b80d28929f0d97dd7d06.

More precisely, 3994623df2efd2749631c3492184dd8d4ffa9d1b changed
the precursor of ff_mpv_reconstruct_mb() to always decode
to the first row of macroblocks for B pictures when
a draw_horiz_band callback is set and to (they are exported to
the caller via said callback and each row overwrites the previously
decoded row; this was probably intended as a cache-optimization).
This first macroblock row was used as source for the draw_horiz_band
callback.

This of course means that the ordinary output B-frame was not
decoded correctly at all. Therefore the first aforementioned commit
removed this special handling of draw_horiz_band; yet it did not
remove the special handling for B-frames in ff_draw_horiz_band(),
which broke draw_horiz_band for B-frames. This commit fixes this.

(Actually, draw_horiz_band was already broken before
5ecf5b93dda9d0c69875b80d28929f0d97dd7d06 when using slice-threading:
All slice-threads would write to the first row of macroblocks
for B-frames, leading to data races. It seems no one has ever complained
about this, just as no one has ever complained about the breakage
caused by 5ecf5b93dda9d0c69875b80d28929f0d97dd7d06. Probably no one
uses draw_horiz_band.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c28e553cbfa70ba0ca635271f5154301889fb706
---

 libavcodec/mpegutils.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/libavcodec/mpegutils.c b/libavcodec/mpegutils.c
index a567165fd9..a53996852f 100644
--- a/libavcodec/mpegutils.c
+++ b/libavcodec/mpegutils.c
@@ -57,6 +57,7 @@ void ff_draw_horiz_band(AVCodecContext *avctx,
                         int first_field, int low_delay)
 {
     const int field_pic = picture_structure != PICT_FRAME;
+    const AVPixFmtDescriptor *desc;
     const AVFrame *src;
     int offset[AV_NUM_DATA_POINTERS];
 
@@ -82,21 +83,13 @@ void ff_draw_horiz_band(AVCodecContext *avctx,
     else
         return;
 
-    if (cur->pict_type == AV_PICTURE_TYPE_B &&
-        picture_structure == PICT_FRAME &&
-        avctx->codec_id != AV_CODEC_ID_SVQ3) {
-        for (int i = 0; i < AV_NUM_DATA_POINTERS; i++)
-            offset[i] = 0;
-    } else {
-        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
-        int vshift = desc->log2_chroma_h;
-
-        offset[0] = y * src->linesize[0];
-        offset[1] =
-        offset[2] = (y >> vshift) * src->linesize[1];
-        for (int i = 3; i < AV_NUM_DATA_POINTERS; i++)
-            offset[i] = 0;
-    }
+    desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+
+    offset[0] = y * src->linesize[0];
+    offset[1] =
+    offset[2] = (y >> desc->log2_chroma_h) * src->linesize[1];
+    for (int i = 3; i < AV_NUM_DATA_POINTERS; i++)
+        offset[i] = 0;
 
     emms_c();
 



More information about the ffmpeg-cvslog mailing list