[vlc-commits] avcodec: use avcodec_is_open() instead of custom flag

Rémi Denis-Courmont git at videolan.org
Mon Jun 19 19:58:44 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun 19 18:32:06 2017 +0300| [b2a5f8ed1f67600ecf9fdaf47775b9c858d31701] | committer: Rémi Denis-Courmont

avcodec: use avcodec_is_open() instead of custom flag

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

 modules/codec/avcodec/audio.c    | 6 +++---
 modules/codec/avcodec/avcodec.c  | 3 +--
 modules/codec/avcodec/avcodec.h  | 3 +--
 modules/codec/avcodec/subtitle.c | 1 -
 modules/codec/avcodec/video.c    | 5 ++---
 5 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index d61385fabc..35ed792e03 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -219,7 +219,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
     p_context->refcounted_frames = true;
     p_sys->p_context = p_context;
     p_sys->p_codec = p_codec;
-    p_sys->b_delayed_open = true;
 
     // Initialize decoder extradata
     InitDecoderConfig( p_dec, p_context);
@@ -280,13 +279,14 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     block_t *p_block = NULL;
     bool b_error = false;
 
-    if( !ctx->extradata_size && p_dec->fmt_in.i_extra && p_sys->b_delayed_open)
+    if( !ctx->extradata_size && p_dec->fmt_in.i_extra
+     && !avcodec_is_open( ctx ) )
     {
         InitDecoderConfig( p_dec, ctx );
         OpenAudioCodec( p_dec );
     }
 
-    if( p_sys->b_delayed_open )
+    if( !avcodec_is_open( ctx ) )
     {
         if( pp_block )
             p_block = *pp_block;
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index a7d9ed768d..0da4690ffd 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -388,7 +388,6 @@ int ffmpeg_OpenCodec( decoder_t *p_dec )
     }
 
     msg_Dbg( p_dec, "codec (%s) started", p_sys->p_codec->name );
-    p_sys->b_delayed_open = false;
     return VLC_SUCCESS;
 }
 
@@ -396,7 +395,7 @@ void ffmpeg_CloseCodec( decoder_t *p_dec )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    if( p_sys->b_delayed_open )
+    if( !avcodec_is_open( p_sys->p_context ) )
         return;
 
     vlc_avcodec_lock();
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index 530894bfd6..0d049174f3 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -235,8 +235,7 @@ void ffmpeg_CloseCodec( decoder_t *p_dec );
 
 #define AVCODEC_COMMON_MEMBERS   \
     AVCodecContext *p_context;  \
-    const AVCodec  *p_codec;    \
-    bool b_delayed_open;
+    const AVCodec  *p_codec;
 
 #ifndef AV_VERSION_INT
 #   define AV_VERSION_INT(a, b, c) ((a)<<16 | (b)<<8 | (c))
diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c
index ddb1dd9252..61adb97fe1 100644
--- a/modules/codec/avcodec/subtitle.c
+++ b/modules/codec/avcodec/subtitle.c
@@ -74,7 +74,6 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
 
     sys->p_context = context;
     sys->p_codec = codec;
-    sys->b_delayed_open = false;
     sys->b_need_ephemer = codec->id == AV_CODEC_ID_HDMV_PGS_SUBTITLE;
 
     /* */
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 61d065aaa5..6b40c65792 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -443,7 +443,6 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
 
     p_sys->p_context = p_context;
     p_sys->p_codec = p_codec;
-    p_sys->b_delayed_open = true;
     p_sys->p_va = NULL;
     vlc_sem_init( &p_sys->sem_mt, 0 );
 
@@ -868,7 +867,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block, bool *error
     if( !p_context->extradata_size && p_dec->fmt_in.i_extra )
     {
         ffmpeg_InitCodec( p_dec );
-        if( p_sys->b_delayed_open )
+        if( !avcodec_is_open( p_context ) )
             OpenVideoCodec( p_dec );
     }
 
@@ -876,7 +875,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block, bool *error
     if(!p_block && !(p_sys->p_codec->capabilities & AV_CODEC_CAP_DELAY) )
         return NULL;
 
-    if( p_sys->b_delayed_open )
+    if( !avcodec_is_open( p_context ) )
     {
         if( p_block )
             block_Release( p_block );



More information about the vlc-commits mailing list