[vlc-commits] trascode: reinit audio filters if audio format changes in midstream

Ilkka Ollakka git at videolan.org
Sat Apr 19 10:32:08 CEST 2014


vlc/vlc-2.1 | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Sep 22 12:24:52 2013 +0300| [28bd6670a26bf88c2523b7302e2c22f8ca210bb7] | committer: Rafaël Carré

trascode: reinit audio filters if audio format changes in midstream

(cherry picked from commit a3a150b91f09620dc0d81c22db591a20faf4b2a5)
Signed-off-by: Rafaël Carré <funman at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.1.git/?a=commit;h=28bd6670a26bf88c2523b7302e2c22f8ca210bb7
---

 modules/stream_out/transcode/audio.c     |   55 ++++++++++++++++++++----------
 modules/stream_out/transcode/transcode.h |    1 +
 2 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index 8d3ee57..f3fc3b6 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -72,6 +72,31 @@ static block_t *audio_new_buffer( decoder_t *p_dec, int i_samples )
     return p_block;
 }
 
+static int transcode_audio_initialize_filters( sout_stream_t *p_stream, sout_stream_id_t *id, sout_stream_sys_t *p_sys, audio_sample_format_t *fmt_last )
+{
+    /* Load user specified audio filters */
+    /* XXX: These variable names come kinda out of nowhere... */
+    var_Create( p_stream, "audio-time-stretch", VLC_VAR_BOOL );
+    var_Create( p_stream, "audio-filter", VLC_VAR_STRING );
+    if( p_sys->psz_af )
+        var_SetString( p_stream, "audio-filter", p_sys->psz_af );
+    id->p_af_chain = aout_FiltersNew( p_stream, fmt_last,
+                                      &id->p_encoder->fmt_in.audio, NULL );
+    var_Destroy( p_stream, "audio-filter" );
+    var_Destroy( p_stream, "audio-time-stretch" );
+    if( id->p_af_chain == NULL )
+    {
+        msg_Err( p_stream, "Unable to initialize audio filters" );
+        module_unneed( id->p_encoder, id->p_encoder->p_module );
+        id->p_encoder->p_module = NULL;
+        module_unneed( id->p_decoder, id->p_decoder->p_module );
+        id->p_decoder->p_module = NULL;
+        return VLC_EGENERIC;
+    }
+    memcpy( fmt_last, &p_sys->fmt_audio, sizeof( audio_sample_format_t ) );
+    return VLC_SUCCESS;
+}
+
 int transcode_audio_new( sout_stream_t *p_stream,
                                 sout_stream_id_t *id )
 {
@@ -148,25 +173,8 @@ int transcode_audio_new( sout_stream_t *p_stream,
     }
     aout_FormatPrepare( &id->p_encoder->fmt_in.audio );
 
-    /* Load user specified audio filters */
-    /* XXX: These variable names come kinda out of nowhere... */
-    var_Create( p_stream, "audio-time-stretch", VLC_VAR_BOOL );
-    var_Create( p_stream, "audio-filter", VLC_VAR_STRING );
-    if( p_sys->psz_af )
-        var_SetString( p_stream, "audio-filter", p_sys->psz_af );
-    id->p_af_chain = aout_FiltersNew( p_stream, &fmt_last,
-                                      &id->p_encoder->fmt_in.audio, NULL );
-    var_Destroy( p_stream, "audio-filter" );
-    var_Destroy( p_stream, "audio-time-stretch" );
-    if( id->p_af_chain == NULL )
-    {
-        msg_Err( p_stream, "cannot connect audio filters chain" );
-        module_unneed( id->p_encoder, id->p_encoder->p_module );
-        id->p_encoder->p_module = NULL;
-        module_unneed( id->p_decoder, id->p_decoder->p_module );
-        id->p_decoder->p_module = NULL;
+    if( unlikely( transcode_audio_initialize_filters( p_stream, id, p_sys, &fmt_last ) != VLC_SUCCESS ) )
         return VLC_EGENERIC;
-    }
 
     return VLC_SUCCESS;
 }
@@ -238,6 +246,17 @@ int transcode_audio_process( sout_stream_t *p_stream,
 
         p_audio_buf->i_dts = p_audio_buf->i_pts;
 
+        /* Check if audio format has changed, and filters need reinit */
+        if( unlikely( AOUT_FMTS_IDENTICAL( &id->p_decoder->fmt_out.audio, &p_sys->fmt_audio ) ) )
+        {
+            msg_Dbg( p_stream, "Audio changed, trying to reinitialize filters" );
+            if( id->p_af_chain != NULL )
+                aout_FiltersDelete( (vlc_object_t *)NULL, id->p_af_chain );
+            if( transcode_audio_initialize_filters( p_stream, id, p_sys, &id->p_decoder->fmt_out.audio ) != VLC_SUCCESS )
+                return VLC_EGENERIC;
+
+        }
+
         /* Run filter chain */
         p_audio_buf = aout_FiltersPlay( id->p_af_chain, p_audio_buf,
                                         INPUT_RATE_DEFAULT );
diff --git a/modules/stream_out/transcode/transcode.h b/modules/stream_out/transcode/transcode.h
index 85651c9..00e7a6d 100644
--- a/modules/stream_out/transcode/transcode.h
+++ b/modules/stream_out/transcode/transcode.h
@@ -25,6 +25,7 @@ struct sout_stream_sys_t
 
     /* Audio */
     vlc_fourcc_t    i_acodec;   /* codec audio (0 if not transcode) */
+    audio_sample_format_t   fmt_audio;
     char            *psz_aenc;
     char            *psz_alang;
     config_chain_t  *p_audio_cfg;



More information about the vlc-commits mailing list