Commit 9f27fbd9 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

PulseAudio: implement and fix changing device while not playing

parent 9c4c35d1
...@@ -75,6 +75,7 @@ struct aout_sys_t ...@@ -75,6 +75,7 @@ struct aout_sys_t
mtime_t first_pts; /**< Play time of buffer start */ mtime_t first_pts; /**< Play time of buffer start */
mtime_t paused; /**< Time when (last) paused */ mtime_t paused; /**< Time when (last) paused */
char *sink_force; /**< Forced sink name (stream must be NULL) */
struct sink *sinks; /**< Locally-cached list of sinks */ struct sink *sinks; /**< Locally-cached list of sinks */
}; };
...@@ -681,6 +682,15 @@ static int SinksList(audio_output_t *aout, char ***namesp, char ***descsp) ...@@ -681,6 +682,15 @@ static int SinksList(audio_output_t *aout, char ***namesp, char ***descsp)
static int StreamMove(audio_output_t *aout, const char *name) static int StreamMove(audio_output_t *aout, const char *name)
{ {
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
if (sys->stream == NULL)
{
msg_Dbg(aout, "will connect to sink %s", name);
free(sys->sink_force);
sys->sink_force = strdup(name);
return 0;
}
pa_operation *op; pa_operation *op;
uint32_t idx = pa_stream_get_index(sys->stream); uint32_t idx = pa_stream_get_index(sys->stream);
...@@ -694,7 +704,7 @@ static int StreamMove(audio_output_t *aout, const char *name) ...@@ -694,7 +704,7 @@ static int StreamMove(audio_output_t *aout, const char *name)
vlc_pa_error(aout, "cannot move sink input", sys->context); vlc_pa_error(aout, "cannot move sink input", sys->context);
pa_threaded_mainloop_unlock(sys->mainloop); pa_threaded_mainloop_unlock(sys->mainloop);
return (op != NULL) ? VLC_SUCCESS : VLC_EGENERIC; return (op != NULL) ? 0 : -1;
} }
static void Stop(audio_output_t *); static void Stop(audio_output_t *);
...@@ -896,11 +906,14 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt) ...@@ -896,11 +906,14 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
pa_stream_set_suspended_callback(s, stream_suspended_cb, aout); pa_stream_set_suspended_callback(s, stream_suspended_cb, aout);
pa_stream_set_underflow_callback(s, stream_underflow_cb, aout); pa_stream_set_underflow_callback(s, stream_underflow_cb, aout);
if (pa_stream_connect_playback(s, NULL, &attr, flags, NULL, NULL) < 0 if (pa_stream_connect_playback(s, sys->sink_force, &attr, flags, NULL,
NULL) < 0
|| stream_wait(s, sys->mainloop)) { || stream_wait(s, sys->mainloop)) {
vlc_pa_error(aout, "stream connection failure", sys->context); vlc_pa_error(aout, "stream connection failure", sys->context);
goto fail; goto fail;
} }
free(sys->sink_force);
sys->sink_force = NULL;
const struct pa_sample_spec *spec = pa_stream_get_sample_spec(s); const struct pa_sample_spec *spec = pa_stream_get_sample_spec(s);
#if PA_CHECK_VERSION(1,0,0) #if PA_CHECK_VERSION(1,0,0)
...@@ -983,6 +996,7 @@ static int Open(vlc_object_t *obj) ...@@ -983,6 +996,7 @@ static int Open(vlc_object_t *obj)
} }
sys->stream = NULL; sys->stream = NULL;
sys->context = ctx; sys->context = ctx;
sys->sink_force = NULL;
sys->sinks = NULL; sys->sinks = NULL;
aout->sys = sys; aout->sys = sys;
...@@ -1032,5 +1046,6 @@ static void Close(vlc_object_t *obj) ...@@ -1032,5 +1046,6 @@ static void Close(vlc_object_t *obj)
free(sink->description); free(sink->description);
free(sink); free(sink);
} }
free(sys->sink_force);
free(sys); free(sys);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment