[vlc-devel] [PATCH 01/13] transcode: create the actual encoder outside of transcode_encoder_new()

Steve Lhomme robux4 at ycbcr.xyz
Mon Dec 23 16:49:25 CET 2019


This allows adding extra values not known to the encoder itself.

If the creation fails, the transcode encoder is not created.

If the transcode encoder fails to be setup, the created encoder is deleted.
---
 modules/stream_out/transcode/audio.c           |  2 +-
 modules/stream_out/transcode/encoder/encoder.c | 13 +++++++------
 modules/stream_out/transcode/encoder/encoder.h |  2 +-
 modules/stream_out/transcode/spu.c             |  2 +-
 modules/stream_out/transcode/video.c           |  2 +-
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index 04bbbfb9f10..80794248d72 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -183,7 +183,7 @@ 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( VLC_OBJECT(p_stream), &encoder_tested_fmt_in );
+    id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream), &encoder_tested_fmt_in );
     if( !id->encoder )
     {
         module_unneed( id->p_decoder, id->p_decoder->p_module );
diff --git a/modules/stream_out/transcode/encoder/encoder.c b/modules/stream_out/transcode/encoder/encoder.c
index 2cc0bf6e888..9d10dca3f14 100644
--- a/modules/stream_out/transcode/encoder/encoder.c
+++ b/modules/stream_out/transcode/encoder/encoder.c
@@ -59,9 +59,12 @@ void transcode_encoder_delete( transcode_encoder_t *p_enc )
     free( p_enc );
 }
 
-transcode_encoder_t * transcode_encoder_new( vlc_object_t *p_obj,
+transcode_encoder_t * transcode_encoder_new( encoder_t *p_encoder,
                                              const es_format_t *p_fmt )
 {
+    if( !p_encoder )
+        return NULL;
+
     switch( p_fmt->i_cat )
     {
         case VIDEO_ES:
@@ -74,14 +77,12 @@ transcode_encoder_t * transcode_encoder_new( vlc_object_t *p_obj,
 
     transcode_encoder_t *p_enc = calloc( 1, sizeof(*p_enc) );
     if( !p_enc )
-        return NULL;
-
-    p_enc->p_encoder = sout_EncoderCreate( p_obj );
-    if( !p_enc->p_encoder )
     {
-        free( p_enc );
+        vlc_object_delete(p_encoder);
         return NULL;
     }
+
+    p_enc->p_encoder = p_encoder;
     p_enc->p_encoder->p_module = NULL;
 
     /* Create destination format */
diff --git a/modules/stream_out/transcode/encoder/encoder.h b/modules/stream_out/transcode/encoder/encoder.h
index fbefaaa82f6..d3997395a9a 100644
--- a/modules/stream_out/transcode/encoder/encoder.h
+++ b/modules/stream_out/transcode/encoder/encoder.h
@@ -71,7 +71,7 @@ void transcode_encoder_update_format_out( transcode_encoder_t *, const es_format
 block_t * transcode_encoder_encode( transcode_encoder_t *, void * );
 block_t * transcode_encoder_get_output_async( transcode_encoder_t * );
 void transcode_encoder_delete( transcode_encoder_t * );
-transcode_encoder_t * transcode_encoder_new( vlc_object_t *, const es_format_t * );
+transcode_encoder_t * transcode_encoder_new( encoder_t *, const es_format_t * );
 void transcode_encoder_close( transcode_encoder_t * );
 
 bool transcode_encoder_opened( const transcode_encoder_t * );
diff --git a/modules/stream_out/transcode/spu.c b/modules/stream_out/transcode/spu.c
index 83426d1d69a..c06fa764e38 100644
--- a/modules/stream_out/transcode/spu.c
+++ b/modules/stream_out/transcode/spu.c
@@ -115,7 +115,7 @@ 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( VLC_OBJECT(p_stream), &id->p_decoder->fmt_in );
+        id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream), &id->p_decoder->fmt_in );
         if( !id->encoder )
         {
             module_unneed( id->p_decoder, id->p_decoder->p_module );
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 6a3d88abc99..db90a90752e 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -234,7 +234,7 @@ int transcode_video_init( sout_stream_t *p_stream, const es_format_t *p_fmt,
         return VLC_EGENERIC;
     }
 
-    id->encoder = transcode_encoder_new( VLC_OBJECT(p_stream), &encoder_tested_fmt_in );
+    id->encoder = transcode_encoder_new( sout_EncoderCreate(VLC_OBJECT(p_stream)), &encoder_tested_fmt_in );
     if( !id->encoder )
     {
         module_unneed( id->p_decoder, id->p_decoder->p_module );
-- 
2.17.1



More information about the vlc-devel mailing list