]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/transcode.c
subpicture_t now has a b_pausable attribute. When set to VLC_TRUE (default value...
[vlc] / modules / stream_out / transcode.c
index 6ddaf72c53daac93cc0d75d425e47ca8683437a1..89866cc3fe0c0b427f7189c50f7dbbc50f06aa0f 100644 (file)
@@ -514,8 +514,8 @@ static int Open( vlc_object_t *p_this )
 
     if( p_sys->i_acodec )
     {
-        if( (strncmp( (char *)&p_sys->i_acodec, "mp3", 3) == 0) &&
-                            (p_sys->i_channels > 2) )
+        if( p_sys->i_acodec == VLC_FOURCC('m','p','3',0) &&
+            p_sys->i_channels > 2 )
         {
             msg_Warn( p_stream, "%d channels invalid for mp3, forcing to 2",
                       p_sys->i_channels );
@@ -662,28 +662,20 @@ static int Open( vlc_object_t *p_this )
     p_sys->i_canvas_height = val.i_int;
 
     var_Get( p_stream, SOUT_CFG_PREFIX "canvas-aspect", &val );
-    if ( val.psz_string )
+    p_sys->i_canvas_aspect = 0;
+    if( val.psz_string && *val.psz_string )
     {
         char *psz_parser = strchr( val.psz_string, ':' );
-
         if( psz_parser )
         {
             *psz_parser++ = '\0';
-            p_sys->i_canvas_aspect = atoi( val.psz_string ) * VOUT_ASPECT_FACTOR
-                / atoi( psz_parser );
-        }
-        else
-        {
-            msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
-            p_sys->i_canvas_aspect = 0;
+            p_sys->i_canvas_aspect = atoi( val.psz_string ) *
+                VOUT_ASPECT_FACTOR / atoi( psz_parser );
         }
+        else msg_Warn( p_stream, "bad aspect ratio %s", val.psz_string );
 
-        free( val.psz_string );
-    }
-    else
-    {
-        p_sys->i_canvas_aspect = 0;
     }
+    if( val.psz_string ) free( val.psz_string );
 
     var_Get( p_stream, SOUT_CFG_PREFIX "threads", &val );
     p_sys->i_threads = val.i_int;
@@ -1094,6 +1086,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     {
         vlc_object_detach( id->p_decoder );
         vlc_object_destroy( id->p_decoder );
+        id->p_decoder = NULL;
     }
 
     if( id->p_encoder )
@@ -1101,6 +1094,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
         vlc_object_detach( id->p_encoder );
         es_format_Clean( &id->p_encoder->fmt_out );
         vlc_object_destroy( id->p_encoder );
+        id->p_encoder = NULL;
     }
 
     free( id );
@@ -1136,6 +1130,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
     {
         vlc_object_detach( id->p_decoder );
         vlc_object_destroy( id->p_decoder );
+        id->p_decoder = NULL;
     }
 
     if( id->p_encoder )
@@ -1143,8 +1138,8 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
         vlc_object_detach( id->p_encoder );
         es_format_Clean( &id->p_encoder->fmt_out );
         vlc_object_destroy( id->p_encoder );
+        id->p_encoder = NULL;
     }
-
     free( id );
 
     return VLC_SUCCESS;
@@ -1297,7 +1292,6 @@ static int transcode_audio_new( sout_stream_t *p_stream,
 
     id->p_decoder->p_module =
         module_Need( id->p_decoder, "decoder", "$codec", 0 );
-
     if( !id->p_decoder->p_module )
     {
         msg_Err( p_stream, "cannot find decoder" );
@@ -1319,8 +1313,9 @@ static int transcode_audio_new( sout_stream_t *p_stream,
     id->p_encoder->fmt_in.audio.i_format = id->p_decoder->fmt_out.i_codec;
 
     /* Initialization of encoder format structures */
-    es_format_Init( &id->p_encoder->fmt_in, AUDIO_ES, AOUT_FMT_S16_NE );
-    id->p_encoder->fmt_in.audio.i_format = AOUT_FMT_S16_NE;
+    es_format_Init( &id->p_encoder->fmt_in, AUDIO_ES, VLC_FOURCC('f','l','3','2') );
+    id->p_encoder->fmt_in.audio.i_format = VLC_FOURCC('f','l','3','2');
+
     id->p_encoder->fmt_in.audio.i_rate = id->p_encoder->fmt_out.audio.i_rate;
     id->p_encoder->fmt_in.audio.i_physical_channels =
         id->p_encoder->fmt_out.audio.i_physical_channels;
@@ -1332,14 +1327,13 @@ static int transcode_audio_new( sout_stream_t *p_stream,
         audio_BitsPerSample( id->p_encoder->fmt_in.i_codec );
 
     id->p_encoder->p_cfg = p_stream->p_sys->p_audio_cfg;
-
     id->p_encoder->p_module =
         module_Need( id->p_encoder, "encoder", p_sys->psz_aenc, VLC_TRUE );
     if( !id->p_encoder->p_module )
     {
         msg_Err( p_stream, "cannot find encoder (%s)", p_sys->psz_aenc );
         module_Unneed( id->p_decoder, id->p_decoder->p_module );
-        id->p_decoder->p_module = 0;
+        id->p_decoder->p_module = NULL;
         return VLC_EGENERIC;
     }
     id->p_encoder->fmt_in.audio.i_format = id->p_encoder->fmt_in.i_codec;
@@ -1405,11 +1399,11 @@ static int transcode_audio_new( sout_stream_t *p_stream,
 
     if( fmt_last.audio.i_channels != id->p_encoder->fmt_in.audio.i_channels )
     {
-        msg_Err( p_stream, "no audio filter found for mixing from"
-                 " %i to %i channels", fmt_last.audio.i_channels,
-                 id->p_encoder->fmt_in.audio.i_channels );
-#if 0
-        /* FIXME : this might work, but only if the encoder is restarted */
+#if 1
+        module_Unneed( id->p_encoder, id->p_encoder->p_module );
+        id->p_encoder->p_module = NULL;
+
+        /* This might work, but only if the encoder is restarted */
         id->p_encoder->fmt_in.audio.i_channels = fmt_last.audio.i_channels;
         id->p_encoder->fmt_out.audio.i_channels = fmt_last.audio.i_channels;
 
@@ -1419,7 +1413,30 @@ static int transcode_audio_new( sout_stream_t *p_stream,
         id->p_encoder->fmt_out.audio.i_physical_channels =
             id->p_encoder->fmt_out.audio.i_original_channels =
                 fmt_last.audio.i_physical_channels;
+
+        msg_Dbg( p_stream, "number of audio channels for mixing changed, "
+                 "trying to reopen the encoder for mixing %i to %i channels",
+                 fmt_last.audio.i_channels,
+                 id->p_encoder->fmt_in.audio.i_channels );
+
+        /* reload encoder */
+        id->p_encoder->p_cfg = p_stream->p_sys->p_audio_cfg;
+        id->p_encoder->p_module =
+            module_Need( id->p_encoder, "encoder", p_sys->psz_aenc, VLC_TRUE );
+        if( !id->p_encoder->p_module )
+        {
+            msg_Err( p_stream, "cannot find encoder (%s)", p_sys->psz_aenc );
+            transcode_audio_close( p_stream, id );
+            return VLC_EGENERIC;
+        }
+        id->p_encoder->fmt_in.audio.i_format = id->p_encoder->fmt_in.i_codec;
+        id->p_encoder->fmt_in.audio.i_bitspersample =
+            audio_BitsPerSample( id->p_encoder->fmt_in.i_codec );
 #else
+        msg_Err( p_stream, "no audio filter found for mixing from"
+                 " %i to %i channels", fmt_last.audio.i_channels,
+                 id->p_encoder->fmt_in.audio.i_channels );
+
         transcode_audio_close( p_stream, id );
         return VLC_EGENERIC;
 #endif
@@ -1455,12 +1472,12 @@ static void transcode_audio_close( sout_stream_t *p_stream,
     /* Close decoder */
     if( id->p_decoder->p_module )
         module_Unneed( id->p_decoder, id->p_decoder->p_module );
-    id->p_decoder->p_module = 0;
+    id->p_decoder->p_module = NULL;
 
     /* Close encoder */
     if( id->p_encoder->p_module )
         module_Unneed( id->p_encoder, id->p_encoder->p_module );
-    id->p_encoder->p_module = 0;
+    id->p_encoder->p_module = NULL;
 
     /* Close filters */
     for( i = 0; i < id->i_filter; i++ )
@@ -2284,6 +2301,7 @@ static int transcode_video_process( sout_stream_t *p_stream,
                     msg_Dbg( p_stream, "no video filter found" );
                     vlc_object_detach( id->pp_ufilter[id->i_ufilter] );
                     vlc_object_destroy( id->pp_ufilter[id->i_ufilter] );
+                    id->pp_ufilter[id->i_ufilter] = NULL;
                 }
             }
         }
@@ -2301,7 +2319,8 @@ static int transcode_video_process( sout_stream_t *p_stream,
         /* Check if we have a subpicture to overlay */
         if( p_sys->p_spu )
         {
-            p_subpic = spu_SortSubpictures( p_sys->p_spu, p_pic->date );
+            p_subpic = spu_SortSubpictures( p_sys->p_spu, p_pic->date,
+                       VLC_FALSE /* Fixme: check if stream is paused */ );
             /* TODO: get another pic */
         }
 
@@ -2866,7 +2885,7 @@ static int transcode_osd_process( sout_stream_t *p_stream,
     /* Check if we have a subpicture to send */
     if( p_sys->p_spu && in->i_dts > 0)
     {
-        p_subpic = spu_SortSubpictures( p_sys->p_spu, in->i_dts );
+        p_subpic = spu_SortSubpictures( p_sys->p_spu, in->i_dts, VLC_FALSE );
     }
     else
     {