From ce0c65a2989ef19de6be2e1e96c3d8a5f892d5d3 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 7 Apr 2006 21:24:47 +0000 Subject: Update to new API. git-svn-id: file:///home/lennart/svn/public/xmms-pulse/trunk@35 ef929aba-56e2-0310-84e0-b7573d389508 --- src/plugin.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 60ddefc..95ed252 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include static pthread_cond_t request_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t request_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -57,7 +57,7 @@ struct request { int success, done; uint32_t value; pa_usec_t latency; - pa_volume_t volume; + pa_cvolume volume; }; static struct request* current_request = NULL; @@ -70,12 +70,12 @@ static struct pa_context *context = NULL; static struct pa_stream *stream = NULL; static struct pa_mainloop_api *mainloop_api = NULL; static int failed = 0; -static pa_volume_t volume = PA_VOLUME_NORM; +static pa_cvolume volume; static size_t written = 0; static int do_trigger = 0, triggered = 0; static struct pa_sample_spec sample_spec; static int locked_by_thread = 0; -static pa_volume_t saved_volume = PA_VOLUME_NORM; +static pa_cvolume saved_volume; /* This function is from xmms' core */ gint ctrlsocket_get_session_id(void); @@ -190,11 +190,11 @@ static void context_state_callback(struct pa_context *c, void *userdata) { pa_context_set_subscribe_callback(context, subscribe_callback, NULL); pa_operation_unref(pa_context_subscribe(context, PA_SUBSCRIPTION_MASK_SINK_INPUT, NULL, NULL)); - stream = pa_stream_new(c, get_song_name(), ¤t_request->ss); + stream = pa_stream_new(c, get_song_name(), ¤t_request->ss, NULL); assert(stream); pa_stream_set_state_callback(stream, stream_state_callback, NULL); - pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_LATENCY, current_request->volume); + pa_stream_connect_playback(stream, NULL, NULL, PA_STREAM_INTERPOLATE_LATENCY, ¤t_request->volume, NULL); break; default: @@ -253,6 +253,8 @@ static void request_func(struct pa_mainloop_api*api, struct pa_io_event *io, int struct pa_operation *o; assert(context); + if (stream) + pa_stream_disconnect(stream); if ((o = pa_context_drain(context, context_drain_callback, NULL))) pa_operation_unref(o); else { @@ -264,7 +266,7 @@ static void request_func(struct pa_mainloop_api*api, struct pa_io_event *io, int case MESSAGE_WRITE: assert(context && stream && current_request->data && current_request->length > 0); - pa_stream_write(stream, current_request->data, current_request->length, free, 0); + pa_stream_write(stream, current_request->data, current_request->length, free, 0, 0); current_request->data = NULL; finish_request(1); break; @@ -300,10 +302,10 @@ static void request_func(struct pa_mainloop_api*api, struct pa_io_event *io, int case MESSAGE_SETVOLUME: assert(context && stream); - if (current_request->volume == volume) + if (pa_cvolume_equal(¤t_request->volume, &volume)) finish_request(1); else - pa_operation_unref(pa_context_set_sink_input_volume(context, pa_stream_get_index(stream), current_request->volume, context_success_callback, NULL)); + pa_operation_unref(pa_context_set_sink_input_volume(context, pa_stream_get_index(stream), ¤t_request->volume, context_success_callback, NULL)); break; case MESSAGE_TRIGGER: @@ -422,8 +424,7 @@ static void execute_request(struct request *r) { static void polyp_get_volume(int *l, int *r) { struct request req; - pa_volume_t v; - int u; + pa_cvolume v; req.message = MESSAGE_GETVOLUME; execute_request(&req); @@ -433,15 +434,21 @@ static void polyp_get_volume(int *l, int *r) { else saved_volume = v = req.volume; - u = (int) (pa_volume_to_user(v)*100); - *r = *l = u > 100 ? 100 : u; + *l = (int) (pa_sw_volume_to_linear(v.values[0]) * 100); + if (sample_spec.channels > 1) + *r = (int) (pa_sw_volume_to_linear(v.values[1]) * 100); + else + *r = *l; } void polyp_set_volume(int l, int r) { struct request req; req.message = MESSAGE_SETVOLUME; - req.volume = pa_volume_from_user((double) (l>r?l:r)/100); + pa_cvolume_reset(&req.volume, sample_spec.channels); + req.volume.values[0] = pa_sw_volume_from_linear(l/100.0); + if (sample_spec.channels > 1) + req.volume.values[1] = pa_sw_volume_from_linear(r/100.0); execute_request(&req); saved_volume = req.volume; @@ -507,6 +514,8 @@ static void polyp_flush(int time) { r.message = MESSAGE_FLUSH; execute_request(&r); + triggered = 0; + written = (size_t) (((double)time*sample_spec.rate/1000)*pa_frame_size(&sample_spec)); } @@ -554,6 +563,9 @@ static int polyp_open(AFormat fmt, int rate, int nch) { return 0; sample_spec = r.ss; + + pa_cvolume_reset(&volume, nch); + pa_cvolume_reset(&saved_volume, nch); start_thread(); -- cgit