[vlc-devel] [PATCH] libvlc_media_player: create the aout when first setting audio options

Thomas Guillem thomas at gllm.fr
Thu Jun 25 10:59:48 CEST 2015


If not setting any audio options, the aout will be created by the decoder
thread.

This avoids to create an audio output that will be destroyed if you change it
with libvlc_audio_output_set.
---
 lib/audio.c        | 17 +++++++++++------
 lib/media_player.c |  4 ----
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/audio.c b/lib/audio.c
index 7901c64..262c8d9 100644
--- a/lib/audio.c
+++ b/lib/audio.c
@@ -51,7 +51,17 @@ static audio_output_t *GetAOut( libvlc_media_player_t *mp )
 
     audio_output_t *p_aout = input_resource_HoldAout( mp->input.p_resource );
     if( p_aout == NULL )
-        libvlc_printerr( "No active audio output" );
+    {
+        p_aout = input_resource_GetAout( mp->input.p_resource );
+        if( p_aout != NULL )
+        {
+            input_resource_PutAout( mp->input.p_resource, p_aout );
+            p_aout = input_resource_HoldAout( mp->input.p_resource );
+        }
+        else
+            libvlc_printerr( "No active audio output" );
+    }
+
     return p_aout;
 }
 
@@ -133,11 +143,6 @@ int libvlc_audio_output_set( libvlc_media_player_t *mp, const char *psz_name )
     /* Forget the existing audio output */
     input_resource_ResetAout(mp->input.p_resource);
 
-    /* Create a new audio output */
-    audio_output_t *aout = input_resource_GetAout(mp->input.p_resource);
-    if( aout != NULL )
-        input_resource_PutAout(mp->input.p_resource, aout);
-
     return 0;
 }
 
diff --git a/lib/media_player.c b/lib/media_player.c
index b57acc0..14fcf8a 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -599,10 +599,6 @@ libvlc_media_player_new( libvlc_instance_t *instance )
         vlc_object_release(mp);
         return NULL;
     }
-    audio_output_t *aout = input_resource_GetAout(mp->input.p_resource);
-    if( aout != NULL )
-        input_resource_PutAout(mp->input.p_resource, aout);
-
     vlc_mutex_init (&mp->input.lock);
     mp->i_refcount = 1;
     mp->p_event_manager = libvlc_event_manager_new(mp, instance);
-- 
2.1.4




More information about the vlc-devel mailing list