[vlc-devel] [PATCH 02/13] sout: provide the structure size to allocate for the encoder

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


This allows encoder "owners" to allocate more to store extra data with the
object and use them in callbacks (using container_of).
---
 include/vlc_sout.h                           | 4 ++--
 modules/stream_out/transcode/audio.c         | 2 +-
 modules/stream_out/transcode/encoder/audio.c | 2 +-
 modules/stream_out/transcode/encoder/video.c | 2 +-
 modules/stream_out/transcode/spu.c           | 2 +-
 modules/stream_out/transcode/video.c         | 2 +-
 src/misc/image.c                             | 2 +-
 src/missing.c                                | 2 +-
 src/stream_output/stream_output.c            | 5 +++--
 9 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/include/vlc_sout.h b/include/vlc_sout.h
index 484e91fff38..4bbf5b0ecd6 100644
--- a/include/vlc_sout.h
+++ b/include/vlc_sout.h
@@ -263,8 +263,8 @@ static inline int sout_StreamControl( sout_stream_t *s, int i_query, ... )
  * Encoder
  ****************************************************************************/
 
-VLC_API encoder_t * sout_EncoderCreate( vlc_object_t *obj );
-#define sout_EncoderCreate(o) sout_EncoderCreate(VLC_OBJECT(o))
+VLC_API encoder_t * sout_EncoderCreate( vlc_object_t *, size_t );
+#define sout_EncoderCreate(o,s) sout_EncoderCreate(VLC_OBJECT(o),s)
 
 /****************************************************************************
  * Announce handler
diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index 80794248d72..1a8c6ddf8c1 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( sout_EncoderCreate(p_stream), &encoder_tested_fmt_in );
+    id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream, sizeof(encoder_t)), &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/audio.c b/modules/stream_out/transcode/encoder/audio.c
index bb21e155880..5286ad5b21e 100644
--- a/modules/stream_out/transcode/encoder/audio.c
+++ b/modules/stream_out/transcode/encoder/audio.c
@@ -145,7 +145,7 @@ int transcode_encoder_audio_test( vlc_object_t *p_obj,
                                   vlc_fourcc_t i_codec_in,
                                   es_format_t *p_enc_wanted_in )
 {
-    encoder_t *p_encoder = sout_EncoderCreate( p_obj );
+    encoder_t *p_encoder = sout_EncoderCreate( p_obj, sizeof(encoder_t) );
     if( !p_encoder )
         return VLC_EGENERIC;
 
diff --git a/modules/stream_out/transcode/encoder/video.c b/modules/stream_out/transcode/encoder/video.c
index 670f5b819c6..c3f6b9ad7bb 100644
--- a/modules/stream_out/transcode/encoder/video.c
+++ b/modules/stream_out/transcode/encoder/video.c
@@ -289,7 +289,7 @@ int transcode_encoder_video_test( vlc_object_t *p_obj,
                                   vlc_fourcc_t i_codec_in,
                                   es_format_t *p_enc_wanted_in )
 {
-    encoder_t *p_encoder = sout_EncoderCreate( p_obj );
+    encoder_t *p_encoder = sout_EncoderCreate( p_obj, sizeof(encoder_t) );
     if( !p_encoder )
         return VLC_EGENERIC;
 
diff --git a/modules/stream_out/transcode/spu.c b/modules/stream_out/transcode/spu.c
index c06fa764e38..832600d2b93 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( sout_EncoderCreate(p_stream), &id->p_decoder->fmt_in );
+        id->encoder = transcode_encoder_new( sout_EncoderCreate(p_stream, sizeof(encoder_t)), &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 db90a90752e..8d47662c72d 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( sout_EncoderCreate(VLC_OBJECT(p_stream)), &encoder_tested_fmt_in );
+    id->encoder = transcode_encoder_new( sout_EncoderCreate(VLC_OBJECT(p_stream), sizeof(encoder_t)), &encoder_tested_fmt_in );
     if( !id->encoder )
     {
         module_unneed( id->p_decoder, id->p_decoder->p_module );
diff --git a/src/misc/image.c b/src/misc/image.c
index 15b2aeec04b..cc432f60d8f 100644
--- a/src/misc/image.c
+++ b/src/misc/image.c
@@ -705,7 +705,7 @@ static encoder_t *CreateEncoder( vlc_object_t *p_this, const video_format_t *fmt
 {
     encoder_t *p_enc;
 
-    p_enc = sout_EncoderCreate( p_this );
+    p_enc = sout_EncoderCreate( p_this, sizeof(encoder_t) );
     if( p_enc == NULL )
         return NULL;
 
diff --git a/src/missing.c b/src/missing.c
index 6769fa4ac38..edfd458cd16 100644
--- a/src/missing.c
+++ b/src/missing.c
@@ -118,7 +118,7 @@ noreturn void sout_AnnounceUnRegister(vlc_object_t *obj,
 }
 
 #undef sout_EncoderCreate
-encoder_t *sout_EncoderCreate( vlc_object_t *p_this )
+encoder_t *sout_EncoderCreate( vlc_object_t *p_this, size_t owner_size )
 {
     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 4c8bba8b5e5..80daa2ae0e4 100644
--- a/src/stream_output/stream_output.c
+++ b/src/stream_output/stream_output.c
@@ -1003,7 +1003,8 @@ rtp:
 }
 
 #undef sout_EncoderCreate
-encoder_t *sout_EncoderCreate( vlc_object_t *p_this )
+encoder_t *sout_EncoderCreate( vlc_object_t *p_this, size_t owner_size )
 {
-    return vlc_custom_create( p_this, sizeof( encoder_t ), "encoder" );
+    assert( owner_size >= sizeof(encoder_t) );
+    return vlc_custom_create( p_this, owner_size, "encoder" );
 }
-- 
2.17.1



More information about the vlc-devel mailing list