[vlc-commits] transcode: initialize audio encoder properly when first packet arrives

Ilkka Ollakka git at videolan.org
Wed Dec 4 13:49:22 CET 2013


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Wed Dec  4 14:42:30 2013 +0200| [fbfe10b4df8106701184da66e0936e96fa3c202f] | committer: Ilkka Ollakka

transcode: initialize audio encoder properly when first packet arrives

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

 modules/stream_out/transcode/audio.c |   86 +++++++++++++++++++---------------
 1 file changed, 48 insertions(+), 38 deletions(-)

diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index b5dded6..46872c5 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -78,45 +78,9 @@ static int transcode_audio_initialize_filters( sout_stream_t *p_stream, sout_str
     return VLC_SUCCESS;
 }
 
-int transcode_audio_new( sout_stream_t *p_stream,
-                                sout_stream_id_t *id )
+static int transcode_audio_initialize_encoder( sout_stream_id_t *id, sout_stream_t *p_stream )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
-    audio_sample_format_t fmt_last;
-
-    /*
-     * Open decoder
-     */
-
-    /* Initialization of decoder structures */
-    id->p_decoder->fmt_out = id->p_decoder->fmt_in;
-    id->p_decoder->fmt_out.i_extra = 0;
-    id->p_decoder->fmt_out.p_extra = 0;
-    id->p_decoder->pf_decode_audio = NULL;
-    id->p_decoder->pf_aout_format_update = audio_update_format;
-    /* id->p_decoder->p_cfg = p_sys->p_audio_cfg; */
-
-    id->p_decoder->p_module =
-        module_need( id->p_decoder, "decoder", "$codec", false );
-    if( !id->p_decoder->p_module )
-    {
-        msg_Err( p_stream, "cannot find audio decoder" );
-        return VLC_EGENERIC;
-    }
-    /* decoders don't set audio.i_format, but audio filters use it */
-    id->p_decoder->fmt_out.audio.i_format = id->p_decoder->fmt_out.i_codec;
-    aout_FormatPrepare( &id->p_decoder->fmt_out.audio );
-    fmt_last = id->p_decoder->fmt_out.audio;
-    /* Fix AAC SBR changing number of channels and sampling rate */
-    if( !(id->p_decoder->fmt_in.i_codec == VLC_CODEC_MP4A &&
-        fmt_last.i_rate != id->p_encoder->fmt_in.audio.i_rate &&
-        fmt_last.i_channels != id->p_encoder->fmt_in.audio.i_channels) )
-        fmt_last.i_rate = id->p_decoder->fmt_in.audio.i_rate;
-
-    /*
-     * Open encoder
-     */
-
     /* Initialization of encoder format structures */
     es_format_Init( &id->p_encoder->fmt_in, id->p_decoder->fmt_in.i_cat,
                     id->p_decoder->fmt_out.i_codec );
@@ -154,6 +118,50 @@ int transcode_audio_new( sout_stream_t *p_stream,
     }
     aout_FormatPrepare( &id->p_encoder->fmt_in.audio );
 
+    return VLC_SUCCESS;
+}
+
+int transcode_audio_new( sout_stream_t *p_stream,
+                                sout_stream_id_t *id )
+{
+    sout_stream_sys_t *p_sys = p_stream->p_sys;
+    audio_sample_format_t fmt_last;
+
+    /*
+     * Open decoder
+     */
+
+    /* Initialization of decoder structures */
+    id->p_decoder->fmt_out = id->p_decoder->fmt_in;
+    id->p_decoder->fmt_out.i_extra = 0;
+    id->p_decoder->fmt_out.p_extra = 0;
+    id->p_decoder->pf_decode_audio = NULL;
+    id->p_decoder->pf_aout_format_update = audio_update_format;
+    /* id->p_decoder->p_cfg = p_sys->p_audio_cfg; */
+
+    id->p_decoder->p_module =
+        module_need( id->p_decoder, "decoder", "$codec", false );
+    if( !id->p_decoder->p_module )
+    {
+        msg_Err( p_stream, "cannot find audio decoder" );
+        return VLC_EGENERIC;
+    }
+    /* decoders don't set audio.i_format, but audio filters use it */
+    id->p_decoder->fmt_out.audio.i_format = id->p_decoder->fmt_out.i_codec;
+    aout_FormatPrepare( &id->p_decoder->fmt_out.audio );
+    fmt_last = id->p_decoder->fmt_out.audio;
+    /* Fix AAC SBR changing number of channels and sampling rate */
+    if( !(id->p_decoder->fmt_in.i_codec == VLC_CODEC_MP4A &&
+        fmt_last.i_rate != id->p_encoder->fmt_in.audio.i_rate &&
+        fmt_last.i_channels != id->p_encoder->fmt_in.audio.i_channels) )
+        fmt_last.i_rate = id->p_decoder->fmt_in.audio.i_rate;
+
+    /*
+     * Open encoder
+     */
+    if( transcode_audio_initialize_encoder( id, p_stream ) == VLC_EGENERIC )
+	return VLC_EGENERIC;
+
     if( unlikely( transcode_audio_initialize_filters( p_stream, id, p_sys, &fmt_last ) != VLC_SUCCESS ) )
         return VLC_EGENERIC;
 
@@ -222,11 +230,13 @@ int transcode_audio_process( sout_stream_t *p_stream,
                 id->p_decoder->fmt_in.audio.i_physical_channels;
             id->p_encoder->fmt_out.audio.i_physical_channels =
                 pi_channels_maps[id->p_encoder->fmt_out.audio.i_channels];
-            if( transcode_audio_new( p_stream, id ) )
+            if( transcode_audio_initialize_encoder( id, p_stream ) )
             {
                 msg_Err( p_stream, "cannot create audio chain" );
                 return VLC_EGENERIC;
             }
+            if( unlikely( transcode_audio_initialize_filters( p_stream, id, p_sys, &id->p_decoder->fmt_out.audio ) != VLC_SUCCESS ) )
+                return VLC_EGENERIC;
             date_Init( &id->interpolated_pts, id->p_decoder->fmt_out.audio.i_rate, 1 );
 
         }



More information about the vlc-commits mailing list