[vlc-commits] avcodec: split decoder in submodules per ES type
Rémi Denis-Courmont
git at videolan.org
Mon Jun 19 19:59:15 CEST 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jun 19 20:16:13 2017 +0300| [79eed1a3f3d90683c65fc27456e446dfea0972a2] | committer: Rémi Denis-Courmont
avcodec: split decoder in submodules per ES type
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=79eed1a3f3d90683c65fc27456e446dfea0972a2
---
modules/codec/avcodec/audio.c | 9 ++++--
modules/codec/avcodec/avcodec.c | 68 ++++++++--------------------------------
modules/codec/avcodec/avcodec.h | 12 +++----
modules/codec/avcodec/subtitle.c | 9 ++++--
modules/codec/avcodec/video.c | 9 ++++--
5 files changed, 40 insertions(+), 67 deletions(-)
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 67698c5e3d..e3b29bf589 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -196,8 +196,9 @@ static block_t *vlc_av_frame_Wrap(AVFrame *frame)
* This function is called when the thread ends after a successful
* initialization.
*****************************************************************************/
-void EndAudioDec( decoder_t *p_dec )
+void EndAudioDec( vlc_object_t *obj )
{
+ decoder_t *p_dec = (decoder_t *)obj;
decoder_sys_t *sys = p_dec->p_sys;
AVCodecContext *ctx = sys->p_context;
@@ -210,8 +211,12 @@ void EndAudioDec( decoder_t *p_dec )
*****************************************************************************
* The avcodec codec will be opened, some memory allocated.
*****************************************************************************/
-int InitAudioDec( decoder_t *p_dec )
+int InitAudioDec( vlc_object_t *obj )
{
+ decoder_t *p_dec = (decoder_t *)obj;
+ if( p_dec->fmt_in.i_cat != AUDIO_ES )
+ return VLC_EGENERIC;
+
const AVCodec *codec;
AVCodecContext *avctx = ffmpeg_AllocContext( p_dec, &codec );
if( avctx == NULL )
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index c44e9f1d97..f2c1a21d4e 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -45,9 +45,6 @@
/****************************************************************************
* Local prototypes
****************************************************************************/
-static int OpenDecoder( vlc_object_t * );
-static void CloseDecoder( vlc_object_t * );
-
static const int nloopf_list[] = { 0, 1, 2, 3, 4 };
static const char *const nloopf_list_text[] =
{ N_("None"), N_("Non-ref"), N_("Bidir"), N_("Non-key"), N_("All") };
@@ -73,16 +70,26 @@ static const char *const enc_hq_list_text[] = {
vlc_module_begin ()
set_shortname( "FFmpeg")
- add_shortcut( "ffmpeg" )
set_category( CAT_INPUT )
set_subcategory( SUBCAT_INPUT_VCODEC )
/* decoder main module */
set_description( N_("FFmpeg audio/video decoder") )
set_help( MODULE_DESCRIPTION )
- set_capability( "decoder", 70 )
set_section( N_("Decoding") , NULL )
- set_callbacks( OpenDecoder, CloseDecoder )
+ add_shortcut("ffmpeg")
+ set_capability("decoder", 70)
+ set_callbacks(InitVideoDec, EndVideoDec)
+
+ add_submodule()
+ add_shortcut("ffmpeg")
+ set_capability("decoder", 70)
+ set_callbacks(InitAudioDec, EndAudioDec)
+
+ add_submodule()
+ add_shortcut("ffmpeg")
+ set_capability("decoder", 70)
+ set_callbacks(InitSubtitleDec, EndSubtitleDec)
add_obsolete_bool( "ffmpeg-dr" ) /* removed since 2.1.0 */
add_bool( "avcodec-dr", true, DR_TEXT, DR_TEXT, true )
@@ -289,55 +296,6 @@ AVCodecContext *ffmpeg_AllocContext( decoder_t *p_dec,
}
/*****************************************************************************
- * OpenDecoder: probe the decoder and return score
- *****************************************************************************/
-static int OpenDecoder( vlc_object_t *p_this )
-{
- decoder_t *p_dec = (decoder_t *)p_this;
- int ret;
-
- switch( p_dec->fmt_in.i_cat )
- {
- case VIDEO_ES:
- ret = InitVideoDec( p_dec );
- break;
- case AUDIO_ES:
- ret = InitAudioDec( p_dec );
- break;
- case SPU_ES:
- ret = InitSubtitleDec( p_dec );
- break;
- default:
- vlc_assert_unreachable();
- }
-
- return ret;
-}
-
-/*****************************************************************************
- * CloseDecoder: decoder destruction
- *****************************************************************************/
-static void CloseDecoder( vlc_object_t *p_this )
-{
- decoder_t *p_dec = (decoder_t *)p_this;
-
- switch( p_dec->fmt_out.i_cat )
- {
- case VIDEO_ES:
- EndVideoDec( p_dec );
- break;
- case AUDIO_ES:
- EndAudioDec( p_dec );
- break;
- case SPU_ES:
- EndSubtitleDec( p_dec );
- break;
- default:
- vlc_assert_unreachable();
- }
-}
-
-/*****************************************************************************
* ffmpeg_OpenCodec:
*****************************************************************************/
int ffmpeg_OpenCodec( decoder_t *p_dec, AVCodecContext *ctx,
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index 2cf121a054..aec123dbef 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -35,16 +35,16 @@ int OpenEncoder ( vlc_object_t * );
void CloseEncoder( vlc_object_t * );
/* Video Decoder */
-int InitVideoDec( decoder_t * );
-void EndVideoDec( decoder_t *p_dec );
+int InitVideoDec( vlc_object_t * );
+void EndVideoDec( vlc_object_t * );
/* Audio Decoder */
-int InitAudioDec( decoder_t * );
-void EndAudioDec( decoder_t *p_dec );
+int InitAudioDec( vlc_object_t * );
+void EndAudioDec( vlc_object_t * );
/* Subtitle Decoder */
-int InitSubtitleDec( decoder_t * );
-void EndSubtitleDec( decoder_t * );
+int InitSubtitleDec( vlc_object_t * );
+void EndSubtitleDec( vlc_object_t * );
/* Initialize decoder */
AVCodecContext *ffmpeg_AllocContext( decoder_t *, const AVCodec ** );
diff --git a/modules/codec/avcodec/subtitle.c b/modules/codec/avcodec/subtitle.c
index 63eb76a47e..c29bbc4fbd 100644
--- a/modules/codec/avcodec/subtitle.c
+++ b/modules/codec/avcodec/subtitle.c
@@ -52,8 +52,12 @@ static void Flush(decoder_t *);
/**
* Initialize subtitle decoder
*/
-int InitSubtitleDec(decoder_t *dec)
+int InitSubtitleDec(vlc_object_t *obj)
{
+ decoder_t *dec = (decoder_t *)obj;
+ if (dec->fmt_in.i_cat != SPU_ES)
+ return VLC_EGENERIC;
+
const AVCodec *codec;
AVCodecContext *context = ffmpeg_AllocContext(dec, &codec);
if (context == NULL)
@@ -128,8 +132,9 @@ int InitSubtitleDec(decoder_t *dec)
return VLC_SUCCESS;
}
-void EndSubtitleDec(decoder_t *dec)
+void EndSubtitleDec(vlc_object_t *obj)
{
+ decoder_t *dec = (decoder_t *)obj;
decoder_sys_t *sys = dec->p_sys;
AVCodecContext *ctx = sys->p_context;
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 1afd8fe36e..d4b173658f 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -434,8 +434,12 @@ 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 )
+int InitVideoDec( vlc_object_t *obj )
{
+ decoder_t *p_dec = (decoder_t *)obj;
+ if( p_dec->fmt_in.i_cat != VIDEO_ES )
+ return VLC_EGENERIC;
+
const AVCodec *p_codec;
AVCodecContext *p_context = ffmpeg_AllocContext( p_dec, &p_codec );
if( p_context == NULL )
@@ -1219,8 +1223,9 @@ static int DecodeVideo( decoder_t *p_dec, block_t *p_block )
* This function is called when the thread ends after a successful
* initialization.
*****************************************************************************/
-void EndVideoDec( decoder_t *p_dec )
+void EndVideoDec( vlc_object_t *obj )
{
+ decoder_t *p_dec = (decoder_t *)obj;
decoder_sys_t *p_sys = p_dec->p_sys;
AVCodecContext *ctx = p_sys->p_context;
void *hwaccel_context;
More information about the vlc-commits
mailing list