[vlc-commits] transcode: create the actual encoder outside of transcode_encoder_new()

Steve Lhomme git at videolan.org
Wed Jan 8 12:47:21 CET 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Sep 24 14:17:00 2019 +0200| [088a1bc051f2c3109dd77f38f65c8907da778753] | committer: Steve Lhomme

transcode: create the actual encoder outside of transcode_encoder_new()

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.

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

 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 04bbbfb9f1..80794248d7 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 2cc0bf6e88..9d10dca3f1 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 fbefaaa82f..d3997395a9 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 83426d1d69..c06fa764e3 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 6a3d88abc9..db90a90752 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 );



More information about the vlc-commits mailing list