[vlc-devel] [PATCH 17/26] sout:encoder: pass the input ES format to sout_EncoderCreate
Steve Lhomme
robux4 at ycbcr.xyz
Mon Jan 18 08:32:56 UTC 2021
So we can initialize common values on behalf of the caller. Then the format
values can be tweaked further before calling sout_EncoderOpen.
The format passed to transcode_encoder_new() is the one used to initialize the
fmt_in/fmt_out values.
For transcode_encoder_test() the fmt_in corresponds to the p_dec_fmtin parameter.
For the image encoder the input format corresponds to the one that was used to
initialize p_enc->fmt_in.
---
include/vlc_sout.h | 4 ++--
modules/stream_out/transcode/audio.c | 6 ++++--
modules/stream_out/transcode/encoder/encoder.c | 9 ---------
modules/stream_out/transcode/spu.c | 3 ++-
modules/stream_out/transcode/video.c | 6 ++++--
src/misc/image.c | 8 +++++---
src/missing.c | 3 ++-
src/stream_output/stream_output.c | 18 ++++++++++++++++--
8 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/include/vlc_sout.h b/include/vlc_sout.h
index b467e083796..2f5eb6a3a73 100644
--- a/include/vlc_sout.h
+++ b/include/vlc_sout.h
@@ -227,8 +227,8 @@ static inline bool sout_StreamIsSynchronous(sout_stream_t *s)
* Encoder
****************************************************************************/
-VLC_API encoder_t * sout_EncoderCreate( vlc_object_t *, size_t, enum es_format_category_e );
-#define sout_EncoderCreate(o,s,c) sout_EncoderCreate(VLC_OBJECT(o),s,c)
+VLC_API encoder_t * sout_EncoderCreate( vlc_object_t *, size_t, const es_format_t *fmt_in );
+#define sout_EncoderCreate(o,a,b) sout_EncoderCreate(VLC_OBJECT(o),a,b)
VLC_API int sout_EncoderOpen(encoder_t *, const char *name, bool strict);
VLC_API void sout_EncoderDelete(encoder_t *);
diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index 4cf538e330e..538869471b3 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -165,7 +165,8 @@ int transcode_audio_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
* This should be enough to initialize the encoder for the first time (it
* will be reloaded when all informations from the decoder are available).
* */
- if( transcode_encoder_test( sout_EncoderCreate(p_stream, sizeof(encoder_t), AUDIO_ES),
+ if( transcode_encoder_test( sout_EncoderCreate(p_stream, sizeof(encoder_t),
+ &id->decoder_out),
id->p_enccfg,
&id->decoder_out,
id->p_decoder->fmt_out.i_codec,
@@ -183,7 +184,8 @@ int transcode_audio_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
vlc_mutex_unlock(&id->fifo.lock);
- id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream, sizeof(encoder_t), AUDIO_ES),
+ id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream, sizeof(encoder_t),
+ &encoder_tested_fmt_in),
&encoder_tested_fmt_in );
if( !id->encoder )
{
diff --git a/modules/stream_out/transcode/encoder/encoder.c b/modules/stream_out/transcode/encoder/encoder.c
index 7ca60b8bacf..a88277f24c4 100644
--- a/modules/stream_out/transcode/encoder/encoder.c
+++ b/modules/stream_out/transcode/encoder/encoder.c
@@ -82,15 +82,6 @@ transcode_encoder_t * transcode_encoder_new( encoder_t *p_encoder,
p_enc->p_encoder = p_encoder;
p_enc->p_encoder->p_module = NULL;
- /* Create destination format */
- es_format_Init( &p_enc->p_encoder->fmt_in, p_fmt->i_cat, 0 );
- es_format_Copy( &p_enc->p_encoder->fmt_in, p_fmt );
- es_format_Init( &p_enc->p_encoder->fmt_out, p_fmt->i_cat, 0 );
- p_enc->p_encoder->fmt_out.i_id = p_fmt->i_id;
- p_enc->p_encoder->fmt_out.i_group = p_fmt->i_group;
- if( p_enc->p_encoder->fmt_in.psz_language )
- p_enc->p_encoder->fmt_out.psz_language = strdup( p_enc->p_encoder->fmt_in.psz_language );
-
switch( p_fmt->i_cat )
{
case VIDEO_ES:
diff --git a/modules/stream_out/transcode/spu.c b/modules/stream_out/transcode/spu.c
index 71ebb0bebe0..6c0c67c50e0 100644
--- a/modules/stream_out/transcode/spu.c
+++ b/modules/stream_out/transcode/spu.c
@@ -115,7 +115,8 @@ int transcode_spu_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
/* Open encoder */
/* Initialization of encoder format structures */
assert(!id->encoder);
- id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream, sizeof(encoder_t), SPU_ES),
+ id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream, sizeof(encoder_t),
+ &id->p_decoder->fmt_in),
&id->p_decoder->fmt_in );
if( !id->encoder )
{
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 44f75c42e93..ed84dfbb476 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -223,7 +223,8 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
es_format_Init( &encoder_tested_fmt_in, id->decoder_out.i_cat, 0 );
struct encoder_owner *p_enc_owner =
- (struct encoder_owner*)sout_EncoderCreate(p_stream, sizeof(struct encoder_owner), VIDEO_ES);
+ (struct encoder_owner*)sout_EncoderCreate(p_stream, sizeof(struct encoder_owner),
+ &id->p_decoder->fmt_in);
if ( unlikely(p_enc_owner == NULL))
goto error;
@@ -238,7 +239,8 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
goto error;
p_enc_owner =
- (struct encoder_owner *)sout_EncoderCreate(p_stream, sizeof(struct encoder_owner), VIDEO_ES);
+ (struct encoder_owner *)sout_EncoderCreate(p_stream, sizeof(struct encoder_owner),
+ &encoder_tested_fmt_in);
if ( unlikely(p_enc_owner == NULL))
goto error;
diff --git a/src/misc/image.c b/src/misc/image.c
index 5c393392626..2414778cbc0 100644
--- a/src/misc/image.c
+++ b/src/misc/image.c
@@ -710,12 +710,14 @@ static encoder_t *CreateEncoder( vlc_object_t *p_this, const video_format_t *fmt
{
encoder_t *p_enc;
- p_enc = sout_EncoderCreate( p_this, sizeof(encoder_t), VIDEO_ES );
+ es_format_t fmt;
+ es_format_InitFromVideo( &fmt, fmt_in );
+
+ p_enc = sout_EncoderCreate( p_this, sizeof(encoder_t), &fmt );
+ es_format_Clean( &fmt );
if( p_enc == NULL )
return NULL;
- es_format_InitFromVideo( &p_enc->fmt_in, fmt_in );
-
if( fmt_out->i_width > 0 && fmt_out->i_height > 0 )
{
p_enc->fmt_in.video.i_width = fmt_out->i_width;
diff --git a/src/missing.c b/src/missing.c
index ad33b6ac3d3..f1a6b243cf4 100644
--- a/src/missing.c
+++ b/src/missing.c
@@ -100,7 +100,8 @@ noreturn void sout_AnnounceUnRegister(vlc_object_t *obj,
}
#undef sout_EncoderCreate
-encoder_t *sout_EncoderCreate( vlc_object_t *p_this, size_t owner_size, enum es_format_category_e es )
+encoder_t *sout_EncoderCreate( vlc_object_t *p_this, size_t owner_size,
+ const es_format_t *fmt_in )
{
msg_Err (p_this, "Encoding support not compiled-in!");
return NULL;
diff --git a/src/stream_output/stream_output.c b/src/stream_output/stream_output.c
index 5f35ac2514e..19128cb0fa8 100644
--- a/src/stream_output/stream_output.c
+++ b/src/stream_output/stream_output.c
@@ -1005,10 +1005,24 @@ static const char encoder_caps[ES_CATEGORY_COUNT][16] = {
};
#undef sout_EncoderCreate
-encoder_t *sout_EncoderCreate( vlc_object_t *p_this, size_t owner_size, enum es_format_category_e i_cat )
+encoder_t *sout_EncoderCreate( vlc_object_t *p_this, size_t owner_size,
+ const es_format_t *p_fmt )
{
assert( owner_size >= sizeof(encoder_t) );
- return vlc_custom_create( p_this, owner_size, encoder_caps[i_cat] );
+ encoder_t *p_encoder =
+ vlc_custom_create( p_this, owner_size, encoder_caps[p_fmt->i_cat] );
+ if (likely(p_encoder != NULL))
+ {
+ /* Create destination format */
+ es_format_Init( &p_encoder->fmt_in, p_fmt->i_cat, 0 );
+ es_format_Copy( &p_encoder->fmt_in, p_fmt );
+ es_format_Init( &p_encoder->fmt_out, p_fmt->i_cat, 0 );
+ p_encoder->fmt_out.i_id = p_fmt->i_id;
+ p_encoder->fmt_out.i_group = p_fmt->i_group;
+ if( p_encoder->fmt_in.psz_language )
+ p_encoder->fmt_out.psz_language = strdup( p_fmt->psz_language );
+ }
+ return p_encoder;
}
static int encoder_start_video(void *func, bool forced, va_list ap)
--
2.29.2
More information about the vlc-devel
mailing list