[vlc-commits] transcode: spu: refactor config

Francois Cartegnie git at videolan.org
Mon Jul 9 16:15:50 CEST 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Jul  2 17:13:29 2018 +0200| [61c62f7608b05bc18610c8ae505ce2cc1603ac5d] | committer: Francois Cartegnie

transcode: spu: refactor config

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

 modules/stream_out/transcode/spu.c       | 26 ++++--------
 modules/stream_out/transcode/transcode.c | 71 ++++++++++++++++----------------
 modules/stream_out/transcode/transcode.h | 16 +++----
 modules/stream_out/transcode/video.c     |  4 +-
 4 files changed, 54 insertions(+), 63 deletions(-)

diff --git a/modules/stream_out/transcode/spu.c b/modules/stream_out/transcode/spu.c
index 29d42159e8..fb1f1396aa 100644
--- a/modules/stream_out/transcode/spu.c
+++ b/modules/stream_out/transcode/spu.c
@@ -84,10 +84,10 @@ static int transcode_spu_encoder_open( sout_stream_t *p_stream, sout_stream_id_s
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
 
-    id->p_encoder->p_cfg = p_sys->p_spu_cfg;
+    id->p_encoder->p_cfg = p_sys->senc_cfg.p_config_chain;
 
     id->p_encoder->p_module = module_need( id->p_encoder, "encoder",
-                                           p_sys->psz_senc, true );
+                                           p_sys->senc_cfg.psz_name, true );
 
     return ( id->p_encoder->p_module ) ? VLC_SUCCESS: VLC_EGENERIC;
 }
@@ -134,20 +134,16 @@ static int transcode_spu_new( sout_stream_t *p_stream, sout_stream_id_sys_t *id
             es_format_Clean( &id->p_encoder->fmt_in );
             module_unneed( id->p_decoder, id->p_decoder->p_module );
             id->p_decoder->p_module = NULL;
-            msg_Err( p_stream, "cannot find spu encoder (%s)", p_sys->psz_senc );
+            msg_Err( p_stream, "cannot find spu encoder (%s)", p_sys->senc_cfg.psz_name );
             return VLC_EGENERIC;
         }
     }
 
-    if( !p_sys->p_spu )
-        p_sys->p_spu = spu_Create( p_stream, NULL );
-
     return VLC_SUCCESS;
 }
 
 void transcode_spu_close( sout_stream_t *p_stream, sout_stream_id_sys_t *id)
 {
-    sout_stream_sys_t *p_sys = p_stream->p_sys;
     /* Close decoder */
     if( id->p_decoder->p_module )
         module_unneed( id->p_decoder, id->p_decoder->p_module );
@@ -156,12 +152,6 @@ void transcode_spu_close( sout_stream_t *p_stream, sout_stream_id_sys_t *id)
 
     /* Close encoder */
     transcode_spu_encoder_close( p_stream, id );
-
-    if( p_sys->p_spu )
-    {
-        spu_Destroy( p_sys->p_spu );
-        p_sys->p_spu = NULL;
-    }
 }
 
 int transcode_spu_process( sout_stream_t *p_stream,
@@ -209,11 +199,11 @@ int transcode_spu_process( sout_stream_t *p_stream,
 
             fmt.video.i_sar_num =
             fmt.video.i_visible_width =
-            fmt.video.i_width = p_sys->i_spu_width;
+            fmt.video.i_width = p_sys->senc_cfg.spu.i_width;
 
             fmt.video.i_sar_den =
             fmt.video.i_visible_height =
-            fmt.video.i_height = p_sys->i_spu_height;
+            fmt.video.i_height =p_sys->senc_cfg.spu.i_height;
 
             subpicture_Update( p_subpic, &fmt.video, &fmt.video, p_subpic->i_start );
             es_format_Clean( &fmt );
@@ -238,14 +228,14 @@ bool transcode_spu_add( sout_stream_t *p_stream, const es_format_t *p_fmt,
     id->fifo.spu.first = NULL;
     id->fifo.spu.last = &id->fifo.spu.first;
 
-    if( p_sys->i_scodec )
+    if( p_sys->senc_cfg.i_codec )
     {
         msg_Dbg( p_stream, "creating subtitle transcoding from fcc=`%4.4s' "
                  "to fcc=`%4.4s'", (char*)&p_fmt->i_codec,
-                 (char*)&p_sys->i_scodec );
+                 (char*)&p_sys->senc_cfg.i_codec );
 
         /* Complete destination format */
-        id->p_encoder->fmt_out.i_codec = p_sys->i_scodec;
+        id->p_encoder->fmt_out.i_codec = p_sys->senc_cfg.i_codec;
 
         /* build decoder -> filter -> encoder */
         if( transcode_spu_new( p_stream, id ) )
diff --git a/modules/stream_out/transcode/transcode.c b/modules/stream_out/transcode/transcode.c
index 6e42a3db90..c0db88fae3 100644
--- a/modules/stream_out/transcode/transcode.c
+++ b/modules/stream_out/transcode/transcode.c
@@ -333,6 +333,30 @@ static void SetVideoEncoderConfig( sout_stream_t *p_stream, sout_encoder_config_
         p_cfg->video.threads.i_priority = VLC_THREAD_PRIORITY_VIDEO;
 }
 
+static void SetSPUEncoderConfig( sout_stream_t *p_stream, sout_encoder_config_t *p_cfg )
+{
+    char *psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "senc" );
+    if( psz_string && *psz_string )
+    {
+        char *psz_next;
+        psz_next = config_ChainCreate( &p_cfg->psz_name, &p_cfg->p_config_chain,
+                                       psz_string );
+        free( psz_next );
+    }
+    free( psz_string );
+
+    psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "scodec" );
+    if( psz_string && *psz_string )
+    {
+        char fcc[5] = "    \0";
+        memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
+        p_cfg->i_codec = vlc_fourcc_GetCodecFromString( SPU_ES, fcc );
+        msg_Dbg( p_stream, "Checking spu codec mapping for %s got %4.4s ", fcc, (char*)&p_cfg->i_codec);
+    }
+    free( psz_string );
+
+}
+
 /*****************************************************************************
  * Open:
  *****************************************************************************/
@@ -401,46 +425,24 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* Subpictures transcoding parameters */
-    p_sys->p_spu = NULL;
-    p_sys->psz_senc = NULL;
-    p_sys->p_spu_cfg = NULL;
-    p_sys->i_scodec = 0;
+    sout_encoder_config_init( &p_sys->senc_cfg );
 
-    psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "senc" );
-    if( psz_string && *psz_string )
-    {
-        char *psz_next;
-        psz_next = config_ChainCreate( &p_sys->psz_senc, &p_sys->p_spu_cfg,
-                                   psz_string );
-        free( psz_next );
-    }
-    free( psz_string );
-
-    psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "scodec" );
-    if( psz_string && *psz_string )
-    {
-        char fcc[5] = "    \0";
-        memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
-        p_sys->i_scodec = vlc_fourcc_GetCodecFromString( SPU_ES, fcc );
-        msg_Dbg( p_stream, "Checking spu codec mapping for %s got %4.4s ", fcc, (char*)&p_sys->i_scodec);
-    }
-    free( psz_string );
-
-    if( p_sys->i_scodec )
-    {
-        msg_Dbg( p_stream, "codec spu=%4.4s", (char *)&p_sys->i_scodec );
-    }
+    SetSPUEncoderConfig( p_stream, &p_sys->senc_cfg );
+    if( p_sys->senc_cfg.i_codec )
+        msg_Dbg( p_stream, "codec spu=%4.4s", (char *)&p_sys->senc_cfg.i_codec );
 
     p_sys->b_soverlay = var_GetBool( p_stream, SOUT_CFG_PREFIX "soverlay" );
     /* Set default size for TEXT spu non overlay conversion / updater */
-    p_sys->i_spu_width = (p_sys->venc_cfg.video.i_width) ? p_sys->venc_cfg.video.i_width : 1280;
-    p_sys->i_spu_height = (p_sys->venc_cfg.video.i_height) ? p_sys->venc_cfg.video.i_height : 720;
+    p_sys->senc_cfg.spu.i_width = (p_sys->venc_cfg.video.i_width) ? p_sys->venc_cfg.video.i_width : 1280;
+    p_sys->senc_cfg.spu.i_height = (p_sys->venc_cfg.video.i_height) ? p_sys->venc_cfg.video.i_height : 720;
+    if( p_sys->b_soverlay )
+        p_sys->p_spu = spu_Create( p_stream, NULL );
 
+    /* Subpictures SOURCES parameters (not releated to SPU stream) */
     psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "sfilter" );
     if( psz_string && *psz_string )
     {
-        p_sys->p_spu = spu_Create( p_stream, NULL );
-        if( p_sys->p_spu )
+        if( !p_sys->p_spu || (p_sys->p_spu = spu_Create( p_stream, NULL )) )
             spu_ChangeSources( p_sys->p_spu, psz_string );
     }
     free( psz_string );
@@ -467,8 +469,7 @@ static void Close( vlc_object_t * p_this )
     sout_encoder_config_clean( &p_sys->aenc_cfg );
     sout_filters_config_clean( &p_sys->afilters_cfg );
 
-    config_ChainDestroy( p_sys->p_spu_cfg );
-    free( p_sys->psz_senc );
+    sout_encoder_config_clean( &p_sys->senc_cfg );
 
     if( p_sys->p_spu ) spu_Destroy( p_sys->p_spu );
 
@@ -548,7 +549,7 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
     else if( p_fmt->i_cat == VIDEO_ES && p_sys->venc_cfg.i_codec )
         success = transcode_video_add(p_stream, p_fmt, id);
     else if( ( p_fmt->i_cat == SPU_ES ) &&
-             ( p_sys->i_scodec || p_sys->b_soverlay ) )
+             ( p_sys->senc_cfg.i_codec || p_sys->b_soverlay ) )
         success = transcode_spu_add(p_stream, p_fmt, id);
     else
     {
diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h
index ca7d026fca..8b9254f225 100644
--- a/modules/stream_out/transcode/transcode.h
+++ b/modules/stream_out/transcode/transcode.h
@@ -67,6 +67,11 @@ typedef struct
             uint32_t        i_sample_rate;
             uint32_t        i_channels;
         } audio;
+        struct
+        {
+            unsigned int    i_width; /* render width */
+            unsigned int    i_height;
+        } spu;
     };
 } sout_encoder_config_t;
 
@@ -87,6 +92,8 @@ void sout_encoder_config_clean( sout_encoder_config_t *p_cfg )
 typedef struct
 {
     sout_stream_id_sys_t *id_video;
+    spu_t                *p_spu;
+    bool                  b_soverlay;
 
     /* Audio */
     sout_encoder_config_t aenc_cfg;
@@ -97,13 +104,7 @@ typedef struct
     sout_filters_config_t vfilters_cfg;
 
     /* SPU */
-    vlc_fourcc_t    i_scodec;   /* codec spu (0 if not transcode) */
-    char            *psz_senc;
-    bool            b_soverlay;
-    config_chain_t  *p_spu_cfg;
-    spu_t           *p_spu;
-    unsigned int     i_spu_width; /* render width */
-    unsigned int     i_spu_height;
+    sout_encoder_config_t senc_cfg;
 
     /* Sync */
     bool            b_master_sync;
@@ -160,7 +161,6 @@ struct sout_stream_id_sys_t
              audio_format_t  fmt_input_audio;
              audio_format_t  audio_dec_out; /* only rw from pf_aout_format_update() */
          };
-
     };
 
     /* Encoder */
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 8922581596..a07a7f9209 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -848,8 +848,8 @@ int transcode_video_process( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
             if( conversion_video_filter_append( id, p_pic ) != VLC_SUCCESS )
                 goto error;
 
-            p_sys->i_spu_width = p_pic->format.i_visible_width;
-            p_sys->i_spu_height = p_pic->format.i_visible_height;
+            p_sys->senc_cfg.spu.i_width = p_pic->format.i_visible_width;
+            p_sys->senc_cfg.spu.i_height = p_pic->format.i_visible_height;
 
             /* Start missing encoder */
             if( id->p_encoder->p_module == NULL &&



More information about the vlc-commits mailing list