codec: avcodec: check open codec return value
authorZhao Zhili <quinkblack@foxmail.com>
Fri, 11 Jun 2021 10:02:34 +0000 (18:02 +0800)
committerSebastian Ramacher <sramacher@debian.org>
Tue, 21 Jan 2025 18:02:47 +0000 (19:02 +0100)
(cherry picked from commit 21ab6be22e7c1831cebf023fd53bd7ffbfad22f6) (edited)
edited:
- on 3.0 DecodeBlock returns a picture_t, not an error code

Gbp-Pq: Name 0088-codec-avcodec-check-open-codec-return-value.patch

modules/codec/avcodec/audio.c
modules/codec/avcodec/video.c

index a3f67f7bd93471f0311b4813242e3211c61da322..e8436754f4a54ae82838a12510185a5fdf69c71f 100644 (file)
@@ -309,7 +309,12 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
      && !avcodec_is_open( ctx ) )
     {
         InitDecoderConfig( p_dec, ctx );
-        OpenAudioCodec( p_dec );
+        if( OpenAudioCodec( p_dec ) < 0 )
+        {
+            if( pp_block != NULL && *pp_block != NULL )
+                block_Release( *pp_block );
+            return VLCDEC_ECRITICAL;
+        }
     }
 
     if( !avcodec_is_open( ctx ) )
index c306e916c7d68451cfcd3c6084c2b327e03b0fdf..096a0b7940e22224f777191be79908545edd09ad 100644 (file)
@@ -1114,17 +1114,20 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block, bool *error
     bool eos_spotted = false;
 
 
-    block_t *p_block;
+    block_t *p_block = pp_block ? *pp_block : NULL;
     vlc_tick_t current_time;
 
     if( !p_context->extradata_size && p_dec->fmt_in.i_extra )
     {
         ffmpeg_InitCodec( p_dec );
-        if( !avcodec_is_open( p_context ) )
-            OpenVideoCodec( p_dec );
+        if( !avcodec_is_open( p_context ) && OpenVideoCodec(p_dec) < 0 )
+        {
+            if( p_block != NULL )
+                block_Release( p_block );
+            return NULL;
+        }
     }
 
-    p_block = pp_block ? *pp_block : NULL;
     if(!p_block && !(p_sys->p_codec->capabilities & AV_CODEC_CAP_DELAY) )
         return NULL;