[vlc-devel] [PATCH] libvlc_media_player: create the audio output on first play
Thomas Guillem
thomas at gllm.fr
Wed Jun 24 18:30:49 CEST 2015
This avoids to create an audio output that will be destroyed if you change it
with libvlc_audio_output_set.
---
lib/audio.c | 7 +++----
lib/media_player.c | 15 +++++++++++----
lib/media_player_internal.h | 1 +
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/lib/audio.c b/lib/audio.c
index 7901c64..1fdbc56 100644
--- a/lib/audio.c
+++ b/lib/audio.c
@@ -130,13 +130,12 @@ int libvlc_audio_output_set( libvlc_media_player_t *mp, const char *psz_name )
var_SetString( mp, "aout", value );
free( value );
+ vlc_mutex_lock(&mp->object_lock);
/* 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);
+ mp->b_aout_init = false;
+ vlc_mutex_unlock(&mp->object_lock);
return 0;
}
diff --git a/lib/media_player.c b/lib/media_player.c
index b57acc0..d0f6d10 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -599,11 +599,8 @@ 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->b_aout_init = false;
mp->i_refcount = 1;
mp->p_event_manager = libvlc_event_manager_new(mp, instance);
if (unlikely(mp->p_event_manager == NULL))
@@ -843,6 +840,16 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
/* Ignore previous exception */
lock(p_mi);
+ if( !p_mi->b_aout_init )
+ {
+ /* Create a new audio output */
+ audio_output_t *aout = input_resource_GetAout(p_mi->input.p_resource);
+ if( aout != NULL )
+ input_resource_PutAout(p_mi->input.p_resource, aout);
+
+ p_mi->b_aout_init = true;
+ }
+
if( !p_mi->p_md )
{
unlock(p_mi);
diff --git a/lib/media_player_internal.h b/lib/media_player_internal.h
index 27fbf1f..3c073e4 100644
--- a/lib/media_player_internal.h
+++ b/lib/media_player_internal.h
@@ -54,6 +54,7 @@ struct libvlc_media_player_t
libvlc_media_t * p_md; /* current media descriptor */
libvlc_event_manager_t * p_event_manager;
libvlc_state_t state;
+ bool b_aout_init;
};
/* Media player - audio, video */
--
2.1.4
More information about the vlc-devel
mailing list