diff mbox series

[FFmpeg-devel,02/41] avcodec/mjpegenc: Remove nonsense assert

Message ID AM7PR03MB6660D83AC49DD05CB5CFF5F58F249@AM7PR03MB6660.eurprd03.prod.outlook.com
State Superseded
Headers show
Series [FFmpeg-devel,01/41] avcodec/mpegvideo_enc: Allow slices only for slice-thread-able codecs | expand

Commit Message

Andreas Rheinhardt Jan. 30, 2022, 6:27 a.m. UTC
Writing optimal huffman tables is incompatible with using slices
and hence commit 884506dfe2e29a5b2bd2905ca4f17e277e32acb1
that added writing optimal huffman tables also added an assert
that the slice context count is always 1.
Yet this was always wrong: a) The MJPEG-encoder has (and had)
the AV_CODEC_CAP_SLICE_THREADS capability, so asserting that
it always uses one slice context is incorrect.
b) This commit did not add any proper checks that ensured that
optimal huffman tables are never used together with multiple slices.
This only happened with 03eb0515c12637dbd20c2e3ca8503d7b47cf583a.
c) This assert is at the wrong place: ff_mjpeg_encode_init() is
called before the actual slice_context_count is set. This is
the reason why this assert was never triggered.

Therefore this commit removes this assert.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mjpegenc.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Michael Niedermayer Jan. 30, 2022, 1:15 p.m. UTC | #1
On Sun, Jan 30, 2022 at 07:27:10AM +0100, Andreas Rheinhardt wrote:
> Writing optimal huffman tables is incompatible with using slices

Fundamentally, this should not be i think

CCITT Rec. T.81 says

"If a table specification for a
given destination occurs more than once in the compressed image data, each specification shall replace the previous
specification. The quantization table specification shall not be altered between progressive DCT scans of a given
component."

This explicitly mentions quatization tables but not huffman tables so it
seems allowed that they can be changed 

[...]
Andreas Rheinhardt Jan. 30, 2022, 5:07 p.m. UTC | #2
Michael Niedermayer:
> On Sun, Jan 30, 2022 at 07:27:10AM +0100, Andreas Rheinhardt wrote:
>> Writing optimal huffman tables is incompatible with using slices
> 
> Fundamentally, this should not be i think
> 
> CCITT Rec. T.81 says
> 
> "If a table specification for a
> given destination occurs more than once in the compressed image data, each specification shall replace the previous
> specification. The quantization table specification shall not be altered between progressive DCT scans of a given
> component."
> 
> This explicitly mentions quatization tables but not huffman tables so it
> seems allowed that they can be changed 
> 

The intention of the quoted passage was to state a limitation of our
current code, not a limitation of the format.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index d15b9ece50..022f171c9e 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -293,8 +293,6 @@  av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
 
     s->mjpeg_ctx = m;
 
-    av_assert0(s->slice_context_count == 1);
-
     if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & FF_THREAD_SLICE))
         m->huffman = HUFFMAN_TABLE_DEFAULT;