[vlc-commits] avcodec: revector, no functional changes

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun 19 20:09:53 2017 +0300| [025fde2a54776c4959d5293678dc0ccb7de9fd0c] | committer: Rémi Denis-Courmont

avcodec: revector, no functional changes

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

 modules/codec/avcodec/audio.c    | 30 ++++++++++++++++++++++--------
 modules/codec/avcodec/avcodec.c  | 26 ++++----------------------
 modules/codec/avcodec/avcodec.h  |  7 ++++---
 modules/codec/avcodec/subtitle.c | 15 ++++++++++++---
 modules/codec/avcodec/video.c    | 22 ++++++++++++++++++----
 5 files changed, 60 insertions(+), 40 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index a7a5a42869..67698c5e3d 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -210,28 +210,35 @@ void EndAudioDec( decoder_t *p_dec )
  *****************************************************************************
  * The avcodec codec will be opened, some memory allocated.
  *****************************************************************************/
-int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
-                  const AVCodec *p_codec )
+int InitAudioDec( decoder_t *p_dec )
 {
-    decoder_sys_t *p_sys;
+    const AVCodec *codec;
+    AVCodecContext *avctx = ffmpeg_AllocContext( p_dec, &codec );
+    if( avctx == NULL )
+        return VLC_EGENERIC;
+
+    avctx->refcounted_frames = true;
 
     /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_dec->p_sys = p_sys = malloc(sizeof(*p_sys)) ) == NULL )
+    decoder_sys_t *p_sys = malloc(sizeof(*p_sys));
+    if( unlikely(p_sys == NULL) )
     {
+        avcodec_free_context( &avctx );
         return VLC_ENOMEM;
     }
 
-    p_context->refcounted_frames = true;
-    p_sys->p_context = p_context;
-    p_sys->p_codec = p_codec;
+    p_dec->p_sys = p_sys;
+    p_sys->p_context = avctx;
+    p_sys->p_codec = codec;
 
     // Initialize decoder extradata
-    InitDecoderConfig( p_dec, p_context);
+    InitDecoderConfig( p_dec, avctx );
 
     /* ***** Open the codec ***** */
     if( OpenAudioCodec( p_dec ) < 0 )
     {
         free( p_sys );
+        avcodec_free_context( &avctx );
         return VLC_EGENERIC;
     }
 
@@ -253,6 +260,13 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
 
     p_dec->pf_decode = DecodeAudio;
     p_dec->pf_flush  = Flush;
+
+    /* XXX: Writing input format makes little sense. */
+    if( avctx->profile != FF_PROFILE_UNKNOWN )
+        p_dec->fmt_in.i_profile = avctx->profile;
+    if( avctx->level != FF_LEVEL_UNKNOWN )
+        p_dec->fmt_in.i_level = avctx->level;
+
     return VLC_SUCCESS;
 }
 
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index 09204febb5..c44e9f1d97 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -236,7 +236,6 @@ vlc_module_begin ()
 #endif
 vlc_module_end ()
 
-static
 AVCodecContext *ffmpeg_AllocContext( decoder_t *p_dec,
                                      const AVCodec **restrict codecp )
 {
@@ -295,41 +294,24 @@ AVCodecContext *ffmpeg_AllocContext( decoder_t *p_dec,
 static int OpenDecoder( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t *)p_this;
-    const AVCodec *p_codec;
-
-    AVCodecContext *avctx = ffmpeg_AllocContext( p_dec, &p_codec );
-    if( unlikely(avctx == NULL) )
-        return VLC_EGENERIC;
-
     int ret;
 
     switch( p_dec->fmt_in.i_cat )
     {
         case VIDEO_ES:
-            ret = InitVideoDec( p_dec, avctx, p_codec );
+            ret = InitVideoDec( p_dec );
             break;
         case AUDIO_ES:
-            ret = InitAudioDec( p_dec, avctx, p_codec );
+            ret = InitAudioDec( p_dec );
             break;
         case SPU_ES:
-            ret = InitSubtitleDec( p_dec, avctx, p_codec );
+            ret = InitSubtitleDec( p_dec );
             break;
         default:
             vlc_assert_unreachable();
     }
 
-    if( ret != VLC_SUCCESS )
-    {
-        avcodec_free_context( &avctx );
-        return ret;
-    }
-
-    if( avctx->profile != FF_PROFILE_UNKNOWN)
-        p_dec->fmt_in.i_profile = avctx->profile;
-    if( avctx->level != FF_LEVEL_UNKNOWN)
-        p_dec->fmt_in.i_level = avctx->level;
-
-    return VLC_SUCCESS;
+    return ret;
 }
 
 /*****************************************************************************
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index ce7d2c8e31..2cf121a054 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -35,18 +35,19 @@ int  OpenEncoder ( vlc_object_t * );
 void CloseEncoder( vlc_object_t * );
 
 /* Video Decoder */
-int InitVideoDec( decoder_t *, AVCodecContext *, const AVCodec * );
+int InitVideoDec( decoder_t * );
 void EndVideoDec( decoder_t *p_dec );
 
 /* Audio Decoder */
-int InitAudioDec( decoder_t *, AVCodecContext *, const AVCodec * );
+int InitAudioDec( decoder_t * );
 void EndAudioDec( decoder_t *p_dec );
 
 /* Subtitle Decoder */
-int InitSubtitleDec( decoder_t *, AVCodecContext *, const AVCodec * );
+int InitSubtitleDec( decoder_t * );
 void EndSubtitleDec( decoder_t * );
 
 /* Initialize decoder */
+AVCodecContext *ffmpeg_AllocContext( decoder_t *, const AVCodec ** );
 int ffmpeg_OpenCodec( decoder_t *p_dec, AVCodecContext *, const AVCodec * );
 
 /*****************************************************************************
diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c
index 1c30b511cb..63eb76a47e 100644
--- a/modules/codec/avcodec/subtitle.c
+++ b/modules/codec/avcodec/subtitle.c
@@ -52,9 +52,13 @@ static void Flush(decoder_t *);
 /**
  * Initialize subtitle decoder
  */
-int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
-                    const AVCodec *codec)
+int InitSubtitleDec(decoder_t *dec)
 {
+    const AVCodec *codec;
+    AVCodecContext *context = ffmpeg_AllocContext(dec, &codec);
+    if (context == NULL)
+        return VLC_EGENERIC;
+
     decoder_sys_t *sys;
 
     /* */
@@ -65,13 +69,17 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
         break;
     default:
         msg_Warn(dec, "refusing to decode non validated subtitle codec");
+        avcodec_free_context(&context);
         return VLC_EGENERIC;
     }
 
     /* */
     dec->p_sys = sys = malloc(sizeof(*sys));
-    if (!sys)
+    if (unlikely(sys == NULL))
+    {
+        avcodec_free_context(&context);
         return VLC_ENOMEM;
+    }
 
     sys->p_context = context;
     sys->p_codec = codec;
@@ -107,6 +115,7 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
     if (ret < 0) {
         msg_Err(dec, "cannot open codec (%s)", codec->name);
         free(sys);
+        avcodec_free_context(&context);
         return VLC_EGENERIC;
     }
 
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 4b612d6b9e..1afd8fe36e 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -434,16 +434,24 @@ static int OpenVideoCodec( decoder_t *p_dec )
  * the ffmpeg codec will be opened, some memory allocated. The vout is not yet
  * opened (done after the first decoded frame).
  *****************************************************************************/
-int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
-                  const AVCodec *p_codec )
+int InitVideoDec( decoder_t *p_dec )
 {
-    decoder_sys_t *p_sys;
+    const AVCodec *p_codec;
+    AVCodecContext *p_context = ffmpeg_AllocContext( p_dec, &p_codec );
+    if( p_context == NULL )
+        return VLC_EGENERIC;
+
     int i_val;
 
     /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ) ) == NULL )
+    decoder_sys_t *p_sys = calloc( 1, sizeof(*p_sys) );
+    if( unlikely(p_sys == NULL) )
+    {
+        avcodec_free_context( &p_context );
         return VLC_ENOMEM;
+    }
 
+    p_dec->p_sys = p_sys;
     p_sys->p_context = p_context;
     p_sys->p_codec = p_codec;
     p_sys->p_va = NULL;
@@ -590,12 +598,18 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
     {
         vlc_sem_destroy( &p_sys->sem_mt );
         free( p_sys );
+        avcodec_free_context( &p_context );
         return VLC_EGENERIC;
     }
 
     p_dec->pf_decode = DecodeVideo;
     p_dec->pf_flush  = Flush;
 
+    /* XXX: Writing input format makes little sense. */
+    if( p_context->profile != FF_PROFILE_UNKNOWN )
+        p_dec->fmt_in.i_profile = p_context->profile;
+    if( p_context->level != FF_LEVEL_UNKNOWN )
+        p_dec->fmt_in.i_level = p_context->level;
     return VLC_SUCCESS;
 }
 



More information about the vlc-commits mailing list