[vlc-commits] sout: privatise sout_stream_t.p_module

Rémi Denis-Courmont git at videolan.org
Mon Oct 12 17:03:04 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 11 17:07:50 2020 +0300| [23f085eeb84a8edd6471a0541a6ab1505f863cc8] | committer: Rémi Denis-Courmont

sout: privatise sout_stream_t.p_module

This adds a private structure around sout_stream_t and moves the module
pointer therein.

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

 include/vlc_sout.h                |  1 -
 src/stream_output/stream_output.c | 24 ++++++++++++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/include/vlc_sout.h b/include/vlc_sout.h
index eb5ff0f83c..c76c8a6344 100644
--- a/include/vlc_sout.h
+++ b/include/vlc_sout.h
@@ -184,7 +184,6 @@ struct sout_stream_t
 {
     struct vlc_object_t obj;
 
-    module_t          *p_module;
     char              *psz_name;
     config_chain_t    *p_cfg;
     sout_stream_t     *p_next;
diff --git a/src/stream_output/stream_output.c b/src/stream_output/stream_output.c
index dc9f979927..1e0d554202 100644
--- a/src/stream_output/stream_output.c
+++ b/src/stream_output/stream_output.c
@@ -734,13 +734,23 @@ static void mrl_Clean( mrl_t *p_mrl )
  ****************************************************************************
  ****************************************************************************/
 
+struct sout_stream_private {
+    sout_stream_t stream;
+    module_t *module;
+};
+
+#define sout_stream_priv(s) \
+        container_of(s, struct sout_stream_private, stream)
+
 /* Destroy a "stream_out" module */
 static void sout_StreamDelete( sout_stream_t *p_stream )
 {
+    struct sout_stream_private *priv = sout_stream_priv(p_stream);
+
     msg_Dbg( p_stream, "destroying chain... (name=%s)", p_stream->psz_name );
 
-    if( p_stream->p_module != NULL )
-        module_unneed( p_stream, p_stream->p_module );
+    if (priv->module != NULL)
+        module_unneed(p_stream, priv->module);
 
     FREENULL( p_stream->psz_name );
 
@@ -776,14 +786,16 @@ static sout_stream_t *sout_StreamNew( vlc_object_t *parent, char *psz_name,
                                config_chain_t *p_cfg, sout_stream_t *p_next)
 {
     const char *cap = (p_next != NULL) ? "sout filter" : "sout output";
+    struct sout_stream_private *priv;
     sout_stream_t *p_stream;
 
     assert(psz_name);
 
-    p_stream = vlc_custom_create( parent, sizeof( *p_stream ), "stream out" );
-    if( !p_stream )
+    priv = vlc_custom_create(parent, sizeof (*priv), "stream out");
+    if (unlikely(priv == NULL))
         return NULL;
 
+    p_stream = &priv->stream;
     p_stream->psz_name = psz_name;
     p_stream->p_cfg    = p_cfg;
     p_stream->p_next   = p_next;
@@ -792,9 +804,9 @@ static sout_stream_t *sout_StreamNew( vlc_object_t *parent, char *psz_name,
 
     msg_Dbg( p_stream, "stream=`%s'", p_stream->psz_name );
 
-    p_stream->p_module = module_need( p_stream, cap, p_stream->psz_name, true );
+    priv->module = module_need(p_stream, cap, p_stream->psz_name, true);
 
-    if( !p_stream->p_module )
+    if (priv->module == NULL)
     {
         /* those must be freed by the caller if creation failed */
         p_stream->psz_name = NULL;



More information about the vlc-commits mailing list