[vlc-devel] [PATCH 09/26] sout:encoder: set callbacks of video encoders with set_callback_video_encoder
Steve Lhomme
robux4 at ycbcr.xyz
Mon Jan 18 08:32:48 UTC 2021
For now it's only using the proper encoder_t type and less casts.
---
modules/codec/aom.c | 35 ++++++++++++++----------------
modules/codec/avcodec/avcodec.c | 5 ++---
modules/codec/avcodec/avcodec.h | 5 +++--
modules/codec/avcodec/encoder.c | 35 ++++++++++++++++++------------
modules/codec/daala.c | 15 ++++++-------
modules/codec/dmo/dmo.c | 38 +++++++++++++++++++--------------
modules/codec/edummy.c | 9 +++-----
modules/codec/jpeg.c | 16 ++++++--------
modules/codec/omxil/omxil.c | 16 ++++++++------
modules/codec/png.c | 13 +++++------
modules/codec/qsv.c | 20 +++++++----------
modules/codec/rav1e.c | 9 +++-----
modules/codec/rtpvideo.c | 8 +++----
modules/codec/schroedinger.c | 17 ++++++---------
modules/codec/theora.c | 13 +++++------
modules/codec/vpx.c | 19 +++++++----------
modules/codec/x264.c | 25 ++++++++++------------
modules/codec/x265.c | 17 ++++++---------
modules/misc/stats.c | 9 +++-----
19 files changed, 149 insertions(+), 175 deletions(-)
diff --git a/modules/codec/aom.c b/modules/codec/aom.c
index db17d017dca..949919a4472 100644
--- a/modules/codec/aom.c
+++ b/modules/codec/aom.c
@@ -50,8 +50,8 @@
static int OpenDecoder(vlc_object_t *);
static void CloseDecoder(vlc_object_t *);
#ifdef ENABLE_SOUT
-static int OpenEncoder(vlc_object_t *);
-static void CloseEncoder(vlc_object_t *);
+static int OpenEncoder(encoder_t *);
+static void CloseEncoder(encoder_t *);
static block_t *Encode(encoder_t *p_enc, picture_t *p_pict);
static const int pi_enc_bitdepth_values_list[] =
@@ -74,9 +74,8 @@ vlc_module_begin ()
#ifdef ENABLE_SOUT
add_submodule()
set_shortname("aom")
- set_capability("video encoder", 101)
set_description(N_("AOM video encoder"))
- set_callbacks(OpenEncoder, CloseEncoder)
+ set_callback_video_encoder(OpenEncoder, CloseEncoder, 101)
add_integer( SOUT_CFG_PREFIX "profile", 0, "Profile", NULL, true )
change_integer_range( 0, 3 )
add_integer( SOUT_CFG_PREFIX "bitdepth", 8, "Bit Depth", NULL, true )
@@ -418,9 +417,8 @@ typedef struct
/*****************************************************************************
* OpenEncoder: probe the encoder
*****************************************************************************/
-static int OpenEncoder(vlc_object_t *p_this)
+static int OpenEncoder(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
if (p_enc->fmt_out.i_codec != VLC_CODEC_AV1)
@@ -499,13 +497,13 @@ static int OpenEncoder(vlc_object_t *p_this)
return VLC_EGENERIC;
}
- msg_Dbg(p_this, "AV1: using libaom version %s (build options %s)",
+ msg_Dbg(p_enc, "AV1: using libaom version %s (build options %s)",
aom_codec_version_str(), aom_codec_build_config());
struct aom_codec_ctx *ctx = &p_sys->ctx;
if (aom_codec_enc_init(ctx, iface, &enccfg, enc_flags) != AOM_CODEC_OK)
{
- AOM_ERR(p_this, ctx, "Failed to initialize encoder");
+ AOM_ERR(p_enc, ctx, "Failed to initialize encoder");
free(p_sys);
return VLC_EGENERIC;
}
@@ -513,8 +511,8 @@ static int OpenEncoder(vlc_object_t *p_this)
if (i_tile_rows >= 0 &&
aom_codec_control(ctx, AV1E_SET_TILE_ROWS, i_tile_rows))
{
- AOM_ERR(p_this, ctx, "Failed to set tile rows");
- destroy_context(p_this, ctx);
+ AOM_ERR(p_enc, ctx, "Failed to set tile rows");
+ destroy_context(VLC_OBJECT(p_enc), ctx);
free(p_sys);
return VLC_EGENERIC;
}
@@ -522,8 +520,8 @@ static int OpenEncoder(vlc_object_t *p_this)
if (i_tile_columns >= 0 &&
aom_codec_control(ctx, AV1E_SET_TILE_COLUMNS, i_tile_columns))
{
- AOM_ERR(p_this, ctx, "Failed to set tile columns");
- destroy_context(p_this, ctx);
+ AOM_ERR(p_enc, ctx, "Failed to set tile columns");
+ destroy_context(VLC_OBJECT(p_enc), ctx);
free(p_sys);
return VLC_EGENERIC;
}
@@ -532,8 +530,8 @@ static int OpenEncoder(vlc_object_t *p_this)
if (b_row_mt &&
aom_codec_control(ctx, AV1E_SET_ROW_MT, b_row_mt))
{
- AOM_ERR(p_this, ctx, "Failed to set row-multithreading");
- destroy_context(p_this, ctx);
+ AOM_ERR(p_enc, ctx, "Failed to set row-multithreading");
+ destroy_context(VLC_OBJECT(p_enc), ctx);
free(p_sys);
return VLC_EGENERIC;
}
@@ -542,8 +540,8 @@ static int OpenEncoder(vlc_object_t *p_this)
int i_cpu_used = var_InheritInteger( p_enc, SOUT_CFG_PREFIX "cpu-used" );
if (aom_codec_control(ctx, AOME_SET_CPUUSED, i_cpu_used))
{
- AOM_ERR(p_this, ctx, "Failed to set cpu-used");
- destroy_context(p_this, ctx);
+ AOM_ERR(p_enc, ctx, "Failed to set cpu-used");
+ destroy_context(VLC_OBJECT(p_enc), ctx);
free(p_sys);
return VLC_EGENERIC;
}
@@ -619,11 +617,10 @@ static block_t *Encode(encoder_t *p_enc, picture_t *p_pict)
/*****************************************************************************
* CloseEncoder: encoder destruction
*****************************************************************************/
-static void CloseEncoder(vlc_object_t *p_this)
+static void CloseEncoder(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
- destroy_context(p_this, &p_sys->ctx);
+ destroy_context(VLC_OBJECT(p_enc), &p_sys->ctx);
free(p_sys);
}
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index a0e0f52f1f1..295f4fbc3c7 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -144,12 +144,11 @@ vlc_module_begin ()
add_shortcut( "ffmpeg" )
set_section( N_("Encoding") , NULL )
set_description( N_("FFmpeg audio/video encoder") )
- set_capability( "video encoder", 100 )
- set_callbacks( InitVideoEnc, EndVideoEnc )
+ set_callback_video_encoder( InitVideoEnc, EndVideoEnc, 100 )
add_submodule()
set_capability( "audio encoder", 100 )
add_shortcut( "ffmpeg" )
- set_callbacks( InitAudioEnc, EndVideoEnc )
+ set_callbacks( InitAudioEnc, EndAudioEnc )
/* removed in 2.1.0 */
add_obsolete_string( "sout-ffmpeg-codec" )
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index 3aeace5d639..00e0512f9db 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -30,8 +30,8 @@ vlc_fourcc_t GetVlcFourcc( unsigned i_ffmpeg_codec );
vlc_fourcc_t GetVlcAudioFormat( int i_sample_fmt );
/* Video encoder module */
-int InitVideoEnc ( vlc_object_t * );
-void EndVideoEnc( vlc_object_t * );
+int InitVideoEnc ( encoder_t * );
+void EndVideoEnc( encoder_t * );
/* Video Decoder */
int InitVideoDec( vlc_object_t * );
@@ -43,6 +43,7 @@ void EndAudioDec( vlc_object_t * );
/* Audio encoder module */
int InitAudioEnc ( vlc_object_t * );
+void EndAudioEnc( vlc_object_t * );
/* Subtitle Decoder */
int InitSubtitleDec( vlc_object_t * );
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 2034e1df0dd..8aad59c9081 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -288,9 +288,8 @@ static void add_av_option_float( encoder_t *p_enc, AVDictionary** pp_dict, const
msg_Warn( p_enc, "Failed to set encoder option %s", psz_name );
}
-static int InitEncoder( vlc_object_t *p_this )
+static int InitEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
AVCodecContext *p_context;
AVCodec *p_codec = NULL;
@@ -299,10 +298,10 @@ static int InitEncoder( vlc_object_t *p_this )
float f_val;
char *psz_val;
- msg_Dbg( p_this, "using %s %s", AVPROVIDER(LIBAVCODEC), LIBAVCODEC_IDENT );
+ msg_Dbg( p_enc, "using %s %s", AVPROVIDER(LIBAVCODEC), LIBAVCODEC_IDENT );
/* Initialization must be done before avcodec_find_encoder() */
- vlc_init_avcodec(p_this);
+ vlc_init_avcodec(VLC_OBJECT(p_enc));
config_ChainParse( p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg );
@@ -336,19 +335,19 @@ static int InitEncoder( vlc_object_t *p_this )
return VLC_EGENERIC;
}
- char *psz_encoder = var_GetString( p_this, ENC_CFG_PREFIX "codec" );
+ char *psz_encoder = var_GetString( p_enc, ENC_CFG_PREFIX "codec" );
if( psz_encoder && *psz_encoder )
{
p_codec = avcodec_find_encoder_by_name( psz_encoder );
if( !p_codec )
{
- msg_Err( p_this, "Encoder `%s' not found", psz_encoder );
+ msg_Err( p_enc, "Encoder `%s' not found", psz_encoder );
free( psz_encoder );
return VLC_EGENERIC;
}
else if( p_codec->id != i_codec_id )
{
- msg_Err( p_this, "Encoder `%s' can't handle %4.4s",
+ msg_Err( p_enc, "Encoder `%s' can't handle %4.4s",
psz_encoder, (char*)&p_enc->fmt_out.i_codec );
free( psz_encoder );
return VLC_EGENERIC;
@@ -404,7 +403,7 @@ static int InitEncoder( vlc_object_t *p_this )
p_sys->p_context->codec_id = p_sys->p_codec->id;
p_context->thread_type = 0;
p_context->debug = var_InheritInteger( p_enc, "avcodec-debug" );
- p_context->opaque = (void *)p_this;
+ p_context->opaque = (void *)p_enc;
p_sys->i_key_int = var_GetInteger( p_enc, ENC_CFG_PREFIX "keyint" );
p_sys->i_b_frames = var_GetInteger( p_enc, ENC_CFG_PREFIX "bframes" );
@@ -1056,10 +1055,9 @@ error:
return VLC_ENOMEM;
}
-int InitVideoEnc( vlc_object_t *p_this )
+int InitVideoEnc( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
- int res = InitEncoder( p_this );
+ int res = InitEncoder( p_enc );
if (res == VLC_SUCCESS)
p_enc->pf_encode_video = EncodeVideo;
return res;
@@ -1068,7 +1066,7 @@ int InitVideoEnc( vlc_object_t *p_this )
int InitAudioEnc( vlc_object_t *p_this )
{
encoder_t *p_enc = (encoder_t *)p_this;
- int res = InitEncoder( p_this );
+ int res = InitEncoder( p_enc );
if (res == VLC_SUCCESS)
p_enc->pf_encode_audio = EncodeAudio;
return res;
@@ -1471,9 +1469,8 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
/*****************************************************************************
* EndVideoEnc: libavcodec encoder destruction
*****************************************************************************/
-void EndVideoEnc( vlc_object_t *p_this )
+static void EndEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
av_frame_free( &p_sys->frame );
@@ -1489,3 +1486,13 @@ void EndVideoEnc( vlc_object_t *p_this )
free( p_sys );
}
+
+void EndVideoEnc( encoder_t *p_enc )
+{
+ EndEncoder( p_enc );
+}
+
+void EndAudioEnc( vlc_object_t *p_this )
+{
+ EndEncoder( (encoder_t*)p_this );
+}
diff --git a/modules/codec/daala.c b/modules/codec/daala.c
index 88f988043db..1d5f8305e5d 100644
--- a/modules/codec/daala.c
+++ b/modules/codec/daala.c
@@ -91,8 +91,8 @@ static void ParseDaalaComments( decoder_t * );
static void daala_CopyPicture( picture_t *, daala_image * );
#ifdef ENABLE_SOUT
-static int OpenEncoder( vlc_object_t *p_this );
-static void CloseEncoder( vlc_object_t *p_this );
+static int OpenEncoder( encoder_t * );
+static void CloseEncoder( encoder_t * );
static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
static const char *const enc_chromafmt_list[] = {
@@ -130,8 +130,7 @@ vlc_module_begin ()
#ifdef ENABLE_SOUT
add_submodule ()
set_description( N_("Daala video encoder") )
- set_capability( "video encoder", 150 )
- set_callbacks( OpenEncoder, CloseEncoder )
+ set_callback_video_encoder( OpenEncoder, CloseEncoder, 150 )
add_shortcut( "daala" )
# define ENC_CFG_PREFIX "sout-daala-"
@@ -588,9 +587,8 @@ typedef struct
daala_enc_ctx *dcx; /* daala context */
} encoder_sys_t;
-static int OpenEncoder( vlc_object_t *p_this )
+static int OpenEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
daala_packet header;
int status;
@@ -704,7 +702,7 @@ static int OpenEncoder( vlc_object_t *p_this )
{
if ( status < 0 )
{
- CloseEncoder( p_this );
+ CloseEncoder( p_enc );
return VLC_EGENERIC;
}
if( xiph_AppendHeaders( &p_enc->fmt_out.i_extra,
@@ -776,9 +774,8 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
return p_block;
}
-static void CloseEncoder( vlc_object_t *p_this )
+static void CloseEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
daala_info_clear(&p_sys->di);
diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
index 7af404b6e9e..8593e510dcb 100644
--- a/modules/codec/dmo/dmo.c
+++ b/modules/codec/dmo/dmo.c
@@ -57,11 +57,12 @@ static void DecoderClose ( vlc_object_t * );
static int DecodeBlock ( decoder_t *, block_t * );
static void *DecoderThread( void * );
static int EncoderAudioOpen ( vlc_object_t * );
-static int EncoderVideoOpen ( vlc_object_t * );
-static void EncoderClose ( vlc_object_t * );
+static int EncoderVideoOpen ( encoder_t * );
+static void EncoderAudioClose ( vlc_object_t * );
+static void EncoderVideoClose ( encoder_t * );
static block_t *EncodeBlock( encoder_t *, block_t *, vlc_tick_t );
-static int EncOpen ( vlc_object_t * );
+static int EncOpen ( encoder_t * );
static int LoadDMO( vlc_object_t *, HINSTANCE *, IMediaObject **,
es_format_t *, bool );
@@ -84,10 +85,9 @@ vlc_module_begin ()
set_description( N_("DirectMedia Object encoder") )
add_shortcut( "dmo" )
set_capability( "audio encoder", 10 )
- set_callbacks( EncoderAudioOpen, EncoderClose )
+ set_callbacks( EncoderAudioOpen, EncoderAudioClose )
add_submodule()
- set_capability( "video encoder", 100 )
- set_callbacks( EncoderVideoOpen, EncoderClose )
+ set_callback_video_encoder( EncoderVideoOpen, EncoderVideoClose, 100 )
vlc_module_end ()
@@ -1087,7 +1087,7 @@ static int EncoderAudioOpen( vlc_object_t *p_this )
{
encoder_t *p_enc = (encoder_t*)p_this;
- int i_ret = EncOpen( p_this );
+ int i_ret = EncOpen( p_enc );
if( i_ret != VLC_SUCCESS ) return i_ret;
/* Set callbacks */
@@ -1095,11 +1095,9 @@ static int EncoderAudioOpen( vlc_object_t *p_this )
return VLC_SUCCESS;
}
-static int EncoderVideoOpen( vlc_object_t *p_this )
+static int EncoderVideoOpen( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t*)p_this;
-
- int i_ret = EncOpen( p_this );
+ int i_ret = EncOpen( p_enc );
if( i_ret != VLC_SUCCESS ) return i_ret;
/* Set callbacks */
@@ -1407,9 +1405,8 @@ static int EncoderSetAudioType( encoder_t *p_enc, IMediaObject *p_dmo )
/*****************************************************************************
* EncOpen: open dmo codec
*****************************************************************************/
-static int EncOpen( vlc_object_t *p_this )
+static int EncOpen( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t*)p_this;
encoder_sys_t *p_sys = NULL;
IMediaObject *p_dmo = NULL;
HINSTANCE hmsdmo_dll = NULL;
@@ -1418,7 +1415,7 @@ static int EncOpen( vlc_object_t *p_this )
if( FAILED(CoInitializeEx( NULL, COINIT_MULTITHREADED )) )
vlc_assert_unreachable();
- if( LoadDMO( p_this, &hmsdmo_dll, &p_dmo, &p_enc->fmt_out, true )
+ if( LoadDMO( VLC_OBJECT(p_enc), &hmsdmo_dll, &p_dmo, &p_enc->fmt_out, true )
!= VLC_SUCCESS )
{
hmsdmo_dll = 0;
@@ -1610,9 +1607,8 @@ static block_t *EncodeBlock( encoder_t *p_enc, block_t *p_block_in, vlc_tick_t i
/*****************************************************************************
* EncoderClose: close codec
*****************************************************************************/
-void EncoderClose( vlc_object_t *p_this )
+static void EncoderClose( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t*)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
if( !p_sys ) return;
@@ -1625,3 +1621,13 @@ void EncoderClose( vlc_object_t *p_this )
free( p_sys );
}
+
+static void EncoderAudioClose ( vlc_object_t *p_this )
+{
+ EncoderClose( (encoder_t*)p_this );
+}
+
+static void EncoderVideoClose ( encoder_t *p_enc )
+{
+ EncoderClose( p_enc );
+}
diff --git a/modules/codec/edummy.c b/modules/codec/edummy.c
index bd78fb3e8a8..98daa9e3791 100644
--- a/modules/codec/edummy.c
+++ b/modules/codec/edummy.c
@@ -32,7 +32,7 @@
#include <vlc_codec.h>
static int OpenAudioEncoder( vlc_object_t * );
-static int OpenVideoEncoder( vlc_object_t * );
+static int OpenVideoEncoder( encoder_t * );
vlc_module_begin ()
set_shortname( N_("Dummy") )
@@ -41,9 +41,8 @@ vlc_module_begin ()
set_callbacks( OpenAudioEncoder, NULL )
add_shortcut( "dummy" )
add_submodule ()
- set_capability( "video encoder", 0 )
+ set_callback_video_encoder( OpenVideoEncoder, NULL, 0 )
add_shortcut( "dummy" )
- set_callbacks( OpenVideoEncoder, NULL )
vlc_module_end ()
@@ -76,10 +75,8 @@ static int OpenAudioEncoder( vlc_object_t *p_this )
return VLC_SUCCESS;
}
-static int OpenVideoEncoder( vlc_object_t *p_this )
+static int OpenVideoEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
-
p_enc->pf_encode_video = EncodeVideo;
return VLC_SUCCESS;
diff --git a/modules/codec/jpeg.c b/modules/codec/jpeg.c
index e16a3b649ea..da501f1fb91 100644
--- a/modules/codec/jpeg.c
+++ b/modules/codec/jpeg.c
@@ -97,8 +97,8 @@ static const char * const ppsz_enc_options[] = {
NULL
};
-static int OpenEncoder(vlc_object_t *);
-static void CloseEncoder(vlc_object_t *);
+static int OpenEncoder(encoder_t *);
+static void CloseEncoder(encoder_t *);
static block_t *EncodeBlock(encoder_t *, picture_t *);
@@ -119,8 +119,7 @@ vlc_module_begin()
add_shortcut("jpeg")
set_section(N_("Encoding"), NULL)
set_description(N_("JPEG image encoder"))
- set_capability("video encoder", 1000)
- set_callbacks(OpenEncoder, CloseEncoder)
+ set_callback_video_encoder(OpenEncoder, CloseEncoder, 1000)
add_integer_with_range(ENC_CFG_PREFIX "quality", 95, 0, 100,
ENC_QUALITY_TEXT, ENC_QUALITY_LONGTEXT, true)
vlc_module_end()
@@ -605,10 +604,8 @@ static void CloseDecoder(vlc_object_t *p_this)
/*
* Probe the encoder and return score
*/
-static int OpenEncoder(vlc_object_t *p_this)
+static int OpenEncoder(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
-
config_ChainParse(p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg);
if (p_enc->fmt_out.i_codec != VLC_CODEC_JPEG)
@@ -625,7 +622,7 @@ static int OpenEncoder(vlc_object_t *p_this)
p_enc->p_sys = p_sys;
- p_sys->p_obj = p_this;
+ p_sys->p_obj = VLC_OBJECT(p_enc);
p_sys->p_jpeg.err = jpeg_std_error(&p_sys->err);
p_sys->err.error_exit = user_error_exit;
@@ -746,9 +743,8 @@ error:
/*
* jpeg encoder destruction
*/
-static void CloseEncoder(vlc_object_t *p_this)
+static void CloseEncoder(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
free(p_sys);
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 9c0a8fefed1..08b78a9f81b 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -61,7 +61,8 @@
* Local prototypes
*****************************************************************************/
static int OpenDecoder( vlc_object_t * );
-static int OpenEncoder( vlc_object_t * );
+static int OpenEncoder( encoder_t * );
+static void CloseEncoder( encoder_t * );
static int OpenGeneric( vlc_object_t *, bool b_encode );
static void CloseGeneric( vlc_object_t * );
@@ -101,8 +102,7 @@ vlc_module_begin ()
add_submodule ()
set_section( N_("Encoding") , NULL )
set_description( N_("Video encoder (using OpenMAX IL)") )
- set_capability( "video encoder", 0 )
- set_callbacks( OpenEncoder, CloseGeneric )
+ set_callback_video_encoder( OpenEncoder, CloseEncoder, 0 )
vlc_module_end ()
/*****************************************************************************
@@ -902,15 +902,14 @@ static int OpenDecoder( vlc_object_t *p_this )
/*****************************************************************************
* OpenEncoder: Create the encoder instance
*****************************************************************************/
-static int OpenEncoder( vlc_object_t *p_this )
+static int OpenEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t*)p_this;
int status;
if( !GetOmxRole(p_enc->fmt_out.i_codec, p_enc->fmt_in.i_cat, true) )
return VLC_EGENERIC;
- status = OpenGeneric( p_this, true );
+ status = OpenGeneric( VLC_OBJECT(p_enc), true );
if(status != VLC_SUCCESS) return status;
p_enc->pf_encode_video = EncodeVideo;
@@ -1707,6 +1706,11 @@ static void CloseGeneric( vlc_object_t *p_this )
free( p_sys );
}
+static void CloseEncoder( encoder_t *p_enc )
+{
+ CloseGeneric(VLC_OBJECT(p_enc));
+}
+
/*****************************************************************************
* OmxEventHandler:
*****************************************************************************/
diff --git a/modules/codec/png.c b/modules/codec/png.c
index ef855c2bcec..98583f53d04 100644
--- a/modules/codec/png.c
+++ b/modules/codec/png.c
@@ -75,7 +75,7 @@ typedef struct
int i_blocksize;
} encoder_sys_t;
-static int OpenEncoder(vlc_object_t *);
+static int OpenEncoder(encoder_t *);
static block_t *EncodeBlock(encoder_t *, picture_t *);
@@ -95,8 +95,7 @@ vlc_module_begin ()
add_shortcut("png")
set_section(N_("Encoding"), NULL)
set_description(N_("PNG video encoder"))
- set_capability("video encoder", 1000)
- set_callback(OpenEncoder)
+ set_callback_video_encoder(OpenEncoder, NULL, 1000)
vlc_module_end ()
/*****************************************************************************
@@ -319,20 +318,18 @@ static int DecodeBlock( decoder_t *p_dec, block_t *p_block )
return VLCDEC_SUCCESS;
}
-static int OpenEncoder(vlc_object_t *p_this)
+static int OpenEncoder(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *) p_this;
-
if( p_enc->fmt_out.i_codec != VLC_CODEC_PNG )
return VLC_EGENERIC;
/* Allocate the memory needed to store the encoder's structure */
- encoder_sys_t *p_sys = vlc_obj_malloc(p_this, sizeof(encoder_sys_t));
+ encoder_sys_t *p_sys = vlc_obj_malloc(VLC_OBJECT(p_enc), sizeof(encoder_sys_t));
if( p_sys == NULL )
return VLC_ENOMEM;
p_enc->p_sys = p_sys;
- p_sys->p_obj = p_this;
+ p_sys->p_obj = VLC_OBJECT(p_enc);
p_sys->i_blocksize = 3 * p_enc->fmt_in.video.i_visible_width *
p_enc->fmt_in.video.i_visible_height;
diff --git a/modules/codec/qsv.c b/modules/codec/qsv.c
index ef0745e11ed..1c7505f9ab8 100644
--- a/modules/codec/qsv.c
+++ b/modules/codec/qsv.c
@@ -52,8 +52,8 @@
/*****************************************************************************
* Modules descriptor
*****************************************************************************/
-static int Open(vlc_object_t *);
-static void Close(vlc_object_t *);
+static int Open(encoder_t *);
+static void Close(encoder_t *);
#define SW_IMPL_TEXT N_("Enable software mode")
#define SW_IMPL_LONGTEXT N_("Allow the use of the Intel Media SDK software " \
@@ -198,8 +198,7 @@ vlc_module_begin ()
set_subcategory(SUBCAT_INPUT_VCODEC)
set_description(N_("Intel QuickSync Video encoder for MPEG4-Part10/MPEG2 (aka H.264/H.262)"))
set_shortname("qsv")
- set_capability("video encoder", 0)
- set_callbacks(Open, Close)
+ set_callback_video_encoder(Open, Close, 0)
add_bool(SOUT_CFG_PREFIX "software", false, SW_IMPL_TEXT, SW_IMPL_LONGTEXT, true)
@@ -366,9 +365,8 @@ static uint64_t qsv_params_get_value(const char *const *text,
return list[result];
}
-static int Open(vlc_object_t *this)
+static int Open(encoder_t *enc)
{
- encoder_t *enc = (encoder_t *)this;
encoder_sys_t *sys = NULL;
mfxStatus sts = MFX_ERR_NONE;
@@ -626,18 +624,17 @@ static int Open(vlc_object_t *this)
return VLC_SUCCESS;
error:
- Close(this);
+ Close(enc);
enc->p_sys = NULL;
return VLC_EGENERIC;
nomem:
- Close(this);
+ Close(enc);
enc->p_sys = NULL;
return VLC_ENOMEM;
}
-static void Close(vlc_object_t *this)
+static void Close(encoder_t *enc)
{
- encoder_t *enc = (encoder_t *)this;
encoder_sys_t *sys = enc->p_sys;
MFXVideoENCODE_Close(sys->session);
@@ -851,9 +848,8 @@ done:
* - Main encoding phase : synchronizing the oldest task each call.
* - Empty : pic = 0, we empty the decoder. Synchronizing the remaining tasks.
*/
-static block_t *Encode(encoder_t *this, picture_t *pic)
+static block_t *Encode(encoder_t *enc, picture_t *pic)
{
- encoder_t *enc = (encoder_t *)this;
encoder_sys_t *sys = enc->p_sys;
async_task_t *task;
block_t *block = NULL;
diff --git a/modules/codec/rav1e.c b/modules/codec/rav1e.c
index d2819f70417..3f0b5d99b36 100644
--- a/modules/codec/rav1e.c
+++ b/modules/codec/rav1e.c
@@ -127,9 +127,8 @@ error:
return NULL;
}
-static int OpenEncoder(vlc_object_t *this)
+static int OpenEncoder(encoder_t *enc)
{
- encoder_t *enc = (encoder_t *) this;
encoder_sys_t *sys;
if (enc->fmt_out.i_codec != VLC_CODEC_AV1)
@@ -279,9 +278,8 @@ error:
return err;
}
-static void CloseEncoder(vlc_object_t* this)
+static void CloseEncoder(encoder_t* enc)
{
- encoder_t *enc = (encoder_t *) this;
encoder_sys_t *sys = enc->p_sys;
rav1e_context_unref(sys->ra_context);
free(sys);
@@ -293,8 +291,7 @@ static const char *bitdepth_values_name_list[] = {N_("8 bpp"), N_("10 bpp")};
vlc_module_begin()
set_shortname("rav1e")
set_description(N_("rav1e video encoder"))
- set_capability("video encoder", 105)
- set_callbacks(OpenEncoder, CloseEncoder)
+ set_callback_video_encoder(OpenEncoder, CloseEncoder, 105)
set_category(CAT_INPUT)
set_subcategory(SUBCAT_INPUT_VCODEC)
add_integer(SOUT_CFG_PREFIX "profile", 0, "Profile", NULL, true)
diff --git a/modules/codec/rtpvideo.c b/modules/codec/rtpvideo.c
index e1c27b1d3ce..96c644f81c6 100644
--- a/modules/codec/rtpvideo.c
+++ b/modules/codec/rtpvideo.c
@@ -34,7 +34,7 @@
/****************************************************************************
* Local prototypes
****************************************************************************/
-static int OpenEncoder( vlc_object_t * );
+static int OpenEncoder( encoder_t * );
static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
/*****************************************************************************
@@ -42,16 +42,14 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
*****************************************************************************/
vlc_module_begin ()
set_description( N_("Raw video encoder for RTP") )
- set_capability( "video encoder", 50 )
+ set_callback_video_encoder( OpenEncoder, NULL, 50 )
set_category( CAT_INPUT )
set_subcategory( SUBCAT_INPUT_VCODEC )
- set_callback( OpenEncoder )
add_shortcut( "rtpvideo" )
vlc_module_end ()
-static int OpenEncoder( vlc_object_t *p_this )
+static int OpenEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
if( p_enc->fmt_out.i_codec != VLC_CODEC_R420 && !p_enc->obj.force )
return VLC_EGENERIC;
diff --git a/modules/codec/schroedinger.c b/modules/codec/schroedinger.c
index 606583fad3c..021bcd224a4 100644
--- a/modules/codec/schroedinger.c
+++ b/modules/codec/schroedinger.c
@@ -46,8 +46,8 @@
*****************************************************************************/
static int OpenDecoder ( vlc_object_t * );
static void CloseDecoder ( vlc_object_t * );
-static int OpenEncoder ( vlc_object_t * );
-static void CloseEncoder ( vlc_object_t * );
+static int OpenEncoder ( encoder_t * );
+static void CloseEncoder ( encoder_t * );
#define ENC_CFG_PREFIX "sout-schro-"
@@ -370,8 +370,7 @@ vlc_module_begin ()
add_submodule()
set_section( N_("Encoding") , NULL )
set_description( N_("Dirac video encoder using libschroedinger") )
- set_capability( "video encoder", 110 )
- set_callbacks( OpenEncoder, CloseEncoder )
+ set_callback_video_encoder( OpenEncoder, CloseEncoder, 110 )
add_shortcut( "schroedinger", "schro" )
add_string( ENC_CFG_PREFIX ENC_RATE_CONTROL, NULL,
@@ -1067,9 +1066,8 @@ static bool SetEncChromaFormat( encoder_t *p_enc, uint32_t i_codec )
/*****************************************************************************
* OpenEncoder: probe the encoder and return score
*****************************************************************************/
-static int OpenEncoder( vlc_object_t *p_this )
+static int OpenEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
int i_tmp;
float f_tmp;
@@ -1099,7 +1097,7 @@ static int OpenEncoder( vlc_object_t *p_this )
if( ( p_sys->p_dts_fifo = timestamp_FifoNew(32) ) == NULL )
{
- CloseEncoder( p_this );
+ CloseEncoder( p_enc );
return VLC_ENOMEM;
}
@@ -1303,7 +1301,7 @@ static int OpenEncoder( vlc_object_t *p_this )
return VLC_SUCCESS;
error:
- CloseEncoder( p_this );
+ CloseEncoder( p_enc );
return VLC_EGENERIC;
}
@@ -1584,9 +1582,8 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pic )
/*****************************************************************************
* CloseEncoder: Schro encoder destruction
*****************************************************************************/
-static void CloseEncoder( vlc_object_t *p_this )
+static void CloseEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
/* Free the encoder resources */
diff --git a/modules/codec/theora.c b/modules/codec/theora.c
index 05b4b640504..16c84a3f209 100644
--- a/modules/codec/theora.c
+++ b/modules/codec/theora.c
@@ -93,8 +93,8 @@ static void ParseTheoraComments( decoder_t * );
static void theora_CopyPicture( picture_t *, th_ycbcr_buffer );
#ifdef ENABLE_SOUT
-static int OpenEncoder( vlc_object_t *p_this );
-static void CloseEncoder( vlc_object_t *p_this );
+static int OpenEncoder( encoder_t * );
+static void CloseEncoder( encoder_t * );
static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
#endif
@@ -128,8 +128,7 @@ vlc_module_begin ()
#ifdef ENABLE_SOUT
add_submodule ()
set_description( N_("Theora video encoder") )
- set_capability( "video encoder", 150 )
- set_callbacks( OpenEncoder, CloseEncoder )
+ set_callback_video_encoder( OpenEncoder, CloseEncoder, 150 )
add_shortcut( "theora" )
# define ENC_CFG_PREFIX "sout-theora-"
@@ -668,9 +667,8 @@ typedef struct
/*****************************************************************************
* OpenEncoder: probe the encoder and return score
*****************************************************************************/
-static int OpenEncoder( vlc_object_t *p_this )
+static int OpenEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
int i_quality;
int t_flags;
@@ -905,9 +903,8 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
/*****************************************************************************
* CloseEncoder: theora encoder destruction
*****************************************************************************/
-static void CloseEncoder( vlc_object_t *p_this )
+static void CloseEncoder( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
th_info_clear(&p_sys->ti);
diff --git a/modules/codec/vpx.c b/modules/codec/vpx.c
index eced20c1758..ef291f62e28 100644
--- a/modules/codec/vpx.c
+++ b/modules/codec/vpx.c
@@ -47,8 +47,8 @@ static int OpenDecoder(vlc_object_t *);
static void CloseDecoder(vlc_object_t *);
#ifdef ENABLE_SOUT
static const char *const ppsz_sout_options[] = { "quality-mode", NULL };
-static int OpenEncoder(vlc_object_t *);
-static void CloseEncoder(vlc_object_t *);
+static int OpenEncoder(encoder_t *);
+static void CloseEncoder(encoder_t *);
static block_t *Encode(encoder_t *p_enc, picture_t *p_pict);
#define QUALITY_MODE_TEXT N_("Quality mode")
@@ -72,9 +72,8 @@ vlc_module_begin ()
#ifdef ENABLE_SOUT
add_submodule()
set_shortname("vpx")
- set_capability("video encoder", 60)
+ set_callback_video_encoder(OpenEncoder, CloseEncoder, 60)
set_description(N_("WebM video encoder"))
- set_callbacks(OpenEncoder, CloseEncoder)
# define ENC_CFG_PREFIX "sout-vpx-"
add_integer( ENC_CFG_PREFIX "quality-mode", VPX_DL_GOOD_QUALITY, QUALITY_MODE_TEXT,
QUALITY_MODE_LONGTEXT, true )
@@ -386,9 +385,8 @@ typedef struct
/*****************************************************************************
* OpenEncoder: probe the encoder
*****************************************************************************/
-static int OpenEncoder(vlc_object_t *p_this)
+static int OpenEncoder(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
/* Allocate the memory needed to store the encoder's structure */
@@ -425,12 +423,12 @@ static int OpenEncoder(vlc_object_t *p_this)
enccfg.g_w = p_enc->fmt_in.video.i_visible_width;
enccfg.g_h = p_enc->fmt_in.video.i_visible_height;
- msg_Dbg(p_this, "VP%d: using libvpx version %s (build options %s)",
+ msg_Dbg(p_enc, "VP%d: using libvpx version %s (build options %s)",
vp_version, vpx_codec_version_str(), vpx_codec_build_config());
struct vpx_codec_ctx *ctx = &p_sys->ctx;
if (vpx_codec_enc_init(ctx, iface, &enccfg, 0) != VPX_CODEC_OK) {
- VPX_ERR(p_this, ctx, "Failed to initialize encoder");
+ VPX_ERR(p_enc, ctx, "Failed to initialize encoder");
free(p_sys);
return VLC_EGENERIC;
}
@@ -521,12 +519,11 @@ static block_t *Encode(encoder_t *p_enc, picture_t *p_pict)
/*****************************************************************************
* CloseEncoder: encoder destruction
*****************************************************************************/
-static void CloseEncoder(vlc_object_t *p_this)
+static void CloseEncoder(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
if (vpx_codec_destroy(&p_sys->ctx))
- VPX_ERR(p_this, &p_sys->ctx, "Failed to destroy codec");
+ VPX_ERR(p_enc, &p_sys->ctx, "Failed to destroy codec");
free(p_sys);
}
diff --git a/modules/codec/x264.c b/modules/codec/x264.c
index a509ffa672a..c72288cefb0 100644
--- a/modules/codec/x264.c
+++ b/modules/codec/x264.c
@@ -61,8 +61,8 @@
/*****************************************************************************
* Module descriptor
*****************************************************************************/
-static int Open ( vlc_object_t * );
-static void Close( vlc_object_t * );
+static int Open ( encoder_t * );
+static void Close( encoder_t * );
static void x264_log( void *, int i_level, const char *psz, va_list );
/* Frame-type options */
@@ -440,17 +440,16 @@ static const char *const framepacking_list_text[] =
vlc_module_begin ()
#ifdef MODULE_NAME_IS_x26410b
set_description( N_("H.264/MPEG-4 Part 10/AVC encoder (x264 10-bit)"))
- set_capability( "video encoder", 0 )
+ set_callback_video_encoder( Open, Close, 0 )
#endif
#ifdef MODULE_NAME_IS_x262
set_description( N_("H.262/MPEG-2 encoder (x262)"))
- set_capability( "video encoder", 0 )
+ set_callback_video_encoder( Open, Close, 0 )
#endif
#ifdef MODULE_NAME_IS_x264
set_description( N_("H.264/MPEG-4 Part 10/AVC encoder (x264)"))
- set_capability( "video encoder", 200 )
+ set_callback_video_encoder( Open, Close, 200 )
#endif
- set_callbacks( Open, Close )
set_category( CAT_INPUT )
set_subcategory( SUBCAT_INPUT_VCODEC )
@@ -775,9 +774,8 @@ static int pthread_win32_count = 0;
/*****************************************************************************
* Open: probe the encoder
*****************************************************************************/
-static int Open ( vlc_object_t *p_this )
+static int Open ( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
int i_val;
char *psz_val;
@@ -810,7 +808,7 @@ static int Open ( vlc_object_t *p_this )
#else
p_enc->fmt_out.i_codec = VLC_CODEC_H264;
#endif
- p_enc->p_sys = p_sys = vlc_obj_malloc( p_this, sizeof( encoder_sys_t ) );
+ p_enc->p_sys = p_sys = vlc_obj_malloc( VLC_OBJECT(p_enc), sizeof( encoder_sys_t ) );
if( !p_sys )
return VLC_ENOMEM;
@@ -1407,7 +1405,7 @@ static int Open ( vlc_object_t *p_this )
if( p_sys->h == NULL )
{
msg_Err( p_enc, "cannot open x264 encoder" );
- Close( VLC_OBJECT(p_enc) );
+ Close( p_enc );
return VLC_EGENERIC;
}
@@ -1416,7 +1414,7 @@ static int Open ( vlc_object_t *p_this )
uint8_t *p_extra = p_enc->fmt_out.p_extra = malloc( i_extra );
if( !p_extra )
{
- Close( VLC_OBJECT(p_enc) );
+ Close( p_enc );
return VLC_ENOMEM;
}
@@ -1441,7 +1439,7 @@ static int Open ( vlc_object_t *p_this )
if( !p_sys->p_sei )
{
free( p_extra );
- Close( VLC_OBJECT(p_enc) );
+ Close( p_enc );
return VLC_ENOMEM;
}
memcpy( p_sys->p_sei, nal[i].p_payload, nal[i].i_payload );
@@ -1559,9 +1557,8 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
/*****************************************************************************
* CloseEncoder: x264 encoder destruction
*****************************************************************************/
-static void Close( vlc_object_t *p_this )
+static void Close( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
free( p_sys->psz_stat_name );
diff --git a/modules/codec/x265.c b/modules/codec/x265.c
index 83854e0e6e3..a7835208dff 100644
--- a/modules/codec/x265.c
+++ b/modules/codec/x265.c
@@ -39,13 +39,12 @@
/*****************************************************************************
* Module descriptor
*****************************************************************************/
-static int Open (vlc_object_t *);
-static void Close(vlc_object_t *);
+static int Open (encoder_t *);
+static void Close(encoder_t *);
vlc_module_begin ()
set_description(N_("H.265/HEVC encoder (x265)"))
- set_capability("video encoder", 200)
- set_callbacks(Open, Close)
+ set_callback_video_encoder(Open, Close, 200)
set_category(CAT_INPUT)
set_subcategory(SUBCAT_INPUT_VCODEC)
vlc_module_end ()
@@ -134,9 +133,8 @@ static block_t *Encode(encoder_t *p_enc, picture_t *p_pict)
return p_block;
}
-static int Open (vlc_object_t *p_this)
+static int Open (encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys;
if (p_enc->fmt_out.i_codec != VLC_CODEC_HEVC && !p_enc->obj.force)
@@ -203,7 +201,7 @@ static int Open (vlc_object_t *p_this)
uint32_t i_nal;
if (x265_encoder_headers(p_sys->h, &nal, &i_nal) < 0) {
msg_Err(p_enc, "cannot get x265 headers");
- Close(VLC_OBJECT(p_enc));
+ Close(p_enc);
return VLC_EGENERIC;
}
@@ -215,7 +213,7 @@ static int Open (vlc_object_t *p_this)
uint8_t *p_extra = p_enc->fmt_out.p_extra = malloc(i_extra);
if (!p_extra) {
- Close(VLC_OBJECT(p_enc));
+ Close(p_enc);
return VLC_ENOMEM;
}
@@ -232,9 +230,8 @@ static int Open (vlc_object_t *p_this)
return VLC_SUCCESS;
}
-static void Close(vlc_object_t *p_this)
+static void Close(encoder_t *p_enc)
{
- encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
x265_encoder_close(p_sys->h);
diff --git a/modules/misc/stats.c b/modules/misc/stats.c
index fb47b89b560..7b33946bc8f 100644
--- a/modules/misc/stats.c
+++ b/modules/misc/stats.c
@@ -130,11 +130,9 @@ static int OpenAudioEncoder ( vlc_object_t *p_this )
return VLC_SUCCESS;
}
-static int OpenVideoEncoder ( vlc_object_t *p_this )
+static int OpenVideoEncoder ( encoder_t *p_enc )
{
- encoder_t *p_enc = (encoder_t *)p_this;
-
- msg_Dbg( p_this, "opening stats encoder" );
+ msg_Dbg( p_enc, "opening stats encoder" );
p_enc->pf_encode_video = EncodeVideo;
@@ -223,9 +221,8 @@ vlc_module_begin ()
set_shortname( N_("Stats"))
#ifdef ENABLE_SOUT
set_description( N_("Stats encoder function") )
- set_capability( "video encoder", 0 )
+ set_callback_video_encoder( OpenVideoEncoder, NULL, 0 )
add_shortcut( "stats" )
- set_callback( OpenVideoEncoder )
add_submodule ()
set_capability( "audio encoder", 0 )
add_shortcut( "stats" )
--
2.29.2
More information about the vlc-devel
mailing list