[FFmpeg-cvslog] avcodec/motionpixels: Only create VLC iff it is going to be used

Andreas Rheinhardt git at videolan.org
Tue Nov 24 12:48:31 EET 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Thu Oct 29 09:46:34 2020 +0100| [e246ea2535da863be83d94c2da3248367f5c0684] | committer: Andreas Rheinhardt

avcodec/motionpixels: Only create VLC iff it is going to be used

If the Huffman tree consists of only one entry (which has length zero),
no tree is used at all for parsing as the VLC API currently can't handle
this. So it makes no sense to create a VLC in this case.

Commit 41b7389cade702383e59343561776f83bb26e17f added a check for
whether creating the VLC should be skipped, but it also skipped decoding
the packet and it used the wrong check: It checked max_codes_bits,
the maximum length of a code; but this value is only updated iff there is
more than one Huffman entry. So if there is only one Huffman entry, and
there was a previous frame with more than one entry, then a VLC was
created unnecessarily; yet if there was no previous frame with more than
one entry, then this frame will be skipped which is probably
spec-incompliant. I have no sample for the latter.

This commit improves the check to create a VLC iff it is going to be
used.

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

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

 libavcodec/motionpixels.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/motionpixels.c b/libavcodec/motionpixels.c
index b48200b017..0bf153f883 100644
--- a/libavcodec/motionpixels.c
+++ b/libavcodec/motionpixels.c
@@ -324,8 +324,7 @@ static int mp_decode_frame(AVCodecContext *avctx,
     if (sz == 0)
         goto end;
 
-    if (mp->max_codes_bits <= 0)
-        goto end;
+    if (mp->codes_count > 1)
     if (init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0))
         goto end;
     mp_decode_frame_helper(mp, &gb);



More information about the ffmpeg-cvslog mailing list