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

Ilkka Ollakka git at videolan.org
Wed Dec 4 09:01:46 CET 2013


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Tue Dec  3 22:26:36 2013 +0200| [651ed87f2bc8f2299c823122406e524b30590d2f] | committer: Ilkka Ollakka

transcode: initialize audio encoder after first packet arrives

Similar approach as video encoding does, helps for example with faad
module that in some cases only gets proper audio properties on decoding.

Ref #9022,#6298

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

 modules/stream_out/transcode/audio.c |   37 ++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/modules/stream_out/transcode/audio.c b/modules/stream_out/transcode/audio.c
index 4a6f387..b5dded6 100644
--- a/modules/stream_out/transcode/audio.c
+++ b/modules/stream_out/transcode/audio.c
@@ -202,6 +202,34 @@ int transcode_audio_process( sout_stream_t *p_stream,
     while( (p_audio_buf = id->p_decoder->pf_decode_audio( id->p_decoder,
                                                           &in )) )
     {
+
+        if( unlikely( !id->p_encoder->p_module ) )
+        {
+            /* Complete destination format */
+            id->p_encoder->fmt_out.i_codec = p_sys->i_acodec;
+            id->p_encoder->fmt_out.audio.i_rate = p_sys->i_sample_rate > 0 ?
+                p_sys->i_sample_rate : id->p_decoder->fmt_out.audio.i_rate;
+            id->p_encoder->fmt_out.i_bitrate = p_sys->i_abitrate;
+            id->p_encoder->fmt_out.audio.i_bitspersample =
+                id->p_decoder->fmt_out.audio.i_bitspersample;
+            id->p_encoder->fmt_out.audio.i_channels = p_sys->i_channels > 0 ?
+                p_sys->i_channels : id->p_decoder->fmt_out.audio.i_channels;
+            /* Sanity check for audio channels */
+            id->p_encoder->fmt_out.audio.i_channels =
+                __MIN( id->p_encoder->fmt_out.audio.i_channels,
+                       id->p_decoder->fmt_out.audio.i_channels );
+            id->p_encoder->fmt_out.audio.i_original_channels =
+                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 ) )
+            {
+                msg_Err( p_stream, "cannot create audio chain" );
+                return VLC_EGENERIC;
+            }
+            date_Init( &id->interpolated_pts, id->p_decoder->fmt_out.audio.i_rate, 1 );
+
+        }
         /* Check if audio format has changed, and filters need reinit */
         if( unlikely( ( id->p_decoder->fmt_out.audio.i_rate != p_sys->fmt_audio.i_rate ) ||
                       ( id->p_decoder->fmt_out.audio.i_physical_channels != p_sys->fmt_audio.i_physical_channels ) ) )
@@ -308,6 +336,15 @@ bool transcode_audio_add( sout_stream_t *p_stream, es_format_t *p_fmt,
         return false;
     }
 
+    module_unneed( id->p_encoder, id->p_encoder->p_module );
+    if( id->p_encoder->fmt_out.p_extra )
+    {
+        free( id->p_encoder->fmt_out.p_extra );
+        id->p_encoder->fmt_out.p_extra = NULL;
+        id->p_encoder->fmt_out.i_extra = 0;
+    }
+    id->p_encoder->p_module = NULL;
+
     date_Init( &id->interpolated_pts, p_fmt->audio.i_rate, 1 );
 
     return true;



More information about the vlc-commits mailing list