diff options
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/client.c | 7 | ||||
-rw-r--r-- | src/pulsecore/namereg.c | 6 | ||||
-rw-r--r-- | src/pulsecore/protocol-esound.c | 154 | ||||
-rw-r--r-- | src/pulsecore/sink-input.c | 4 | ||||
-rw-r--r-- | src/pulsecore/source-output.c | 4 |
5 files changed, 136 insertions, 39 deletions
diff --git a/src/pulsecore/client.c b/src/pulsecore/client.c index 7ca7b97c..e6e8b528 100644 --- a/src/pulsecore/client.c +++ b/src/pulsecore/client.c @@ -132,15 +132,14 @@ void pa_client_set_name(pa_client *c, const char *name) { pa_log_info("Client %u changed name from \"%s\" to \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)), name); pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name); - pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c); - pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index); + pa_client_update_proplist(c, 0, NULL); } void pa_client_update_proplist(pa_client *c, pa_update_mode_t mode, pa_proplist *p) { pa_assert(c); - pa_assert(p); - pa_proplist_update(c->proplist, mode, p); + if (p) + pa_proplist_update(c->proplist, mode, p); pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c); pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index); diff --git a/src/pulsecore/namereg.c b/src/pulsecore/namereg.c index 86bcef74..5ab3036e 100644 --- a/src/pulsecore/namereg.c +++ b/src/pulsecore/namereg.c @@ -194,7 +194,11 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type) { } - if (!name || *name == '@' || !pa_namereg_is_valid_name(name)) + if (!name) + return NULL; + + if ((type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE || type == PA_NAMEREG_CARD) && + !pa_namereg_is_valid_name(name)) return NULL; if ((e = pa_hashmap_get(c->namereg, name))) diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c index 840f4581..2d4e62fa 100644 --- a/src/pulsecore/protocol-esound.c +++ b/src/pulsecore/protocol-esound.c @@ -34,6 +34,7 @@ #include <pulse/timeval.h> #include <pulse/utf8.h> #include <pulse/xmalloc.h> +#include <pulse/proplist.h> #include <pulsecore/esound.h> #include <pulsecore/memblock.h> @@ -164,10 +165,12 @@ static int esd_proto_get_latency(connection *c, esd_proto_t request, const void static int esd_proto_server_info(connection *c, esd_proto_t request, const void *data, size_t length); static int esd_proto_all_info(connection *c, esd_proto_t request, const void *data, size_t length); static int esd_proto_stream_pan(connection *c, esd_proto_t request, const void *data, size_t length); +static int esd_proto_sample_pan(connection *c, esd_proto_t request, const void *data, size_t length); static int esd_proto_sample_cache(connection *c, esd_proto_t request, const void *data, size_t length); static int esd_proto_sample_free_or_play(connection *c, esd_proto_t request, const void *data, size_t length); static int esd_proto_sample_get_id(connection *c, esd_proto_t request, const void *data, size_t length); static int esd_proto_standby_or_resume(connection *c, esd_proto_t request, const void *data, size_t length); +static int esd_proto_standby_mode(connection *c, esd_proto_t request, const void *data, size_t length); /* the big map of protocol handler info */ static struct proto_handler proto_map[ESD_PROTO_MAX] = { @@ -186,8 +189,8 @@ static struct proto_handler proto_map[ESD_PROTO_MAX] = { { sizeof(int), NULL, "sample stop" }, { (size_t) -1, NULL, "TODO: sample kill" }, - { ESD_KEY_LEN + sizeof(int), esd_proto_standby_or_resume, "standby" }, /* NOOP! */ - { ESD_KEY_LEN + sizeof(int), esd_proto_standby_or_resume, "resume" }, /* NOOP! */ /* 13 */ + { ESD_KEY_LEN + sizeof(int), esd_proto_standby_or_resume, "standby" }, + { ESD_KEY_LEN + sizeof(int), esd_proto_standby_or_resume, "resume" }, /* 13 */ { ESD_NAME_MAX, esd_proto_sample_get_id, "sample getid" }, /* 14 */ { ESD_NAME_MAX + 2 * sizeof(int), NULL, "stream filter" }, @@ -198,9 +201,9 @@ static struct proto_handler proto_map[ESD_PROTO_MAX] = { { (size_t) -1, NULL, "TODO: unsubscribe" }, { 3 * sizeof(int), esd_proto_stream_pan, "stream pan"}, - { 3 * sizeof(int), NULL, "sample pan" }, + { 3 * sizeof(int), esd_proto_sample_pan, "sample pan" }, - { sizeof(int), NULL, "standby mode" }, + { sizeof(int), esd_proto_standby_mode, "standby mode" }, { 0, esd_proto_get_latency, "get latency" } }; @@ -372,6 +375,8 @@ static int esd_proto_connect(connection *c, esd_proto_t request, const void *dat return -1; } + pa_proplist_sets(c->client->proplist, "esound.byte_order", c->swap_byte_order ? "reverse" : "native"); + ok = 1; connection_write(c, &ok, sizeof(int)); return 0; @@ -404,7 +409,7 @@ static int esd_proto_stream_play(connection *c, esd_proto_t request, const void if (c->options->default_sink) { sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK); - CHECK_VALIDITY(sink, "No such sink: %s", c->options->default_sink); + CHECK_VALIDITY(sink, "No such sink: %s", pa_strnull(c->options->default_sink)); } pa_strlcpy(name, data, sizeof(name)); @@ -489,23 +494,17 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi if (request == ESD_PROTO_STREAM_MON) { pa_sink* sink; - if (!(sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK))) { - pa_log("no such sink."); - return -1; - } + sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK); + CHECK_VALIDITY(sink, "No such sink: %s", pa_strnull(c->options->default_sink)); - if (!(source = sink->monitor_source)) { - pa_log("no such monitor source."); - return -1; - } + source = sink->monitor_source; + CHECK_VALIDITY(source, "No such source."); } else { pa_assert(request == ESD_PROTO_STREAM_REC); if (c->options->default_source) { - if (!(source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE))) { - pa_log("no such source."); - return -1; - } + source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE); + CHECK_VALIDITY(source, "No such source: %s", pa_strnull(c->options->default_source)); } } @@ -570,7 +569,7 @@ static int esd_proto_get_latency(connection *c, esd_proto_t request, const void if (!(sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK))) latency = 0; else { - double usec = (double) pa_sink_get_latency(sink); + double usec = (double) pa_sink_get_requested_latency(sink); latency = (int) ((usec*44100)/1000000); } @@ -621,7 +620,7 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da k = sizeof(int32_t)*5+ESD_NAME_MAX; s = sizeof(int32_t)*6+ESD_NAME_MAX; - nsamples = c->protocol->core->scache ? pa_idxset_size(c->protocol->core->scache) : 0; + nsamples = pa_idxset_size(c->protocol->core->scache); t = s*(nsamples+1) + k*(c->protocol->n_player+1); connection_write_prepare(c, t); @@ -641,7 +640,7 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da pa_cvolume volume = *pa_sink_input_get_volume(conn->sink_input); rate = (int32_t) conn->sink_input->sample_spec.rate; lvolume = (int32_t) ((volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM); - rvolume = (int32_t) ((volume.values[1]*ESD_VOLUME_BASE)/PA_VOLUME_NORM); + rvolume = (int32_t) ((volume.values[volume.channels == 2 ? 1 : 0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM); format = format_native2esd(&conn->sink_input->sample_spec); } @@ -688,9 +687,26 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da for (ce = pa_idxset_first(c->protocol->core->scache, &idx); ce; ce = pa_idxset_next(c->protocol->core->scache, &idx)) { int32_t id, rate, lvolume, rvolume, format, len; char name[ESD_NAME_MAX]; + pa_channel_map stereo = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } }; + pa_cvolume volume; + pa_sample_spec ss; pa_assert(t >= s*2); + if (ce->volume_is_set) { + volume = ce->volume; + pa_cvolume_remap(&volume, &ce->channel_map, &stereo); + } else + pa_cvolume_reset(&volume, 2); + + if (ce->memchunk.memblock) + ss = ce->sample_spec; + else { + ss.format = PA_SAMPLE_S16NE; + ss.rate = 44100; + ss.channels = 2; + } + /* id */ id = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int) (ce->index+1)); connection_write(c, &id, sizeof(int32_t)); @@ -704,19 +720,19 @@ static int esd_proto_all_info(connection *c, esd_proto_t request, const void *da connection_write(c, name, ESD_NAME_MAX); /* rate */ - rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ce->sample_spec.rate); + rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ss.rate); connection_write(c, &rate, sizeof(int32_t)); /* left */ - lvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM)); + lvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM)); connection_write(c, &lvolume, sizeof(int32_t)); /*right*/ - rvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM)); + rvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) ((volume.values[1]*ESD_VOLUME_BASE)/PA_VOLUME_NORM)); connection_write(c, &rvolume, sizeof(int32_t)); /*format*/ - format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format_native2esd(&ce->sample_spec)); + format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format_native2esd(&ss)); connection_write(c, &format, sizeof(int32_t)); /*length*/ @@ -759,7 +775,8 @@ static int esd_proto_stream_pan(connection *c, esd_proto_t request, const void * pa_cvolume volume; volume.values[0] = (lvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE; volume.values[1] = (rvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE; - volume.channels = 2; + volume.channels = conn->sink_input->sample_spec.channels; + pa_sink_input_set_volume(conn->sink_input, &volume, TRUE); ok = 1; } else @@ -770,6 +787,46 @@ static int esd_proto_stream_pan(connection *c, esd_proto_t request, const void * return 0; } +static int esd_proto_sample_pan(connection *c, esd_proto_t request, const void *data, size_t length) { + int32_t ok = 0; + uint32_t idx, lvolume, rvolume; + pa_cvolume volume; + pa_scache_entry *ce; + + connection_assert_ref(c); + pa_assert(data); + pa_assert(length == sizeof(int32_t)*3); + + memcpy(&idx, data, sizeof(uint32_t)); + idx = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, idx) - 1; + data = (const char*)data + sizeof(uint32_t); + + memcpy(&lvolume, data, sizeof(uint32_t)); + lvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, lvolume); + data = (const char*)data + sizeof(uint32_t); + + memcpy(&rvolume, data, sizeof(uint32_t)); + rvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, rvolume); + data = (const char*)data + sizeof(uint32_t); + + volume.values[0] = (lvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE; + volume.values[1] = (rvolume*PA_VOLUME_NORM)/ESD_VOLUME_BASE; + volume.channels = 2; + + if ((ce = pa_idxset_get_by_index(c->protocol->core->scache, idx))) { + pa_channel_map stereo = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } }; + + pa_cvolume_remap(&volume, &stereo, &ce->channel_map); + ce->volume = volume; + ce->volume_is_set = TRUE; + ok = 1; + } + + connection_write(c, &ok, sizeof(int32_t)); + + return 0; +} + static int esd_proto_sample_cache(connection *c, esd_proto_t request, const void *data, size_t length) { pa_sample_spec ss; int32_t format, rate, sc_length; @@ -880,19 +937,47 @@ static int esd_proto_sample_free_or_play(connection *c, esd_proto_t request, con } static int esd_proto_standby_or_resume(connection *c, esd_proto_t request, const void *data, size_t length) { - int32_t ok; + int32_t ok = 1; connection_assert_ref(c); connection_write_prepare(c, sizeof(int32_t) * 2); - - ok = 1; connection_write(c, &ok, sizeof(int32_t)); + + if (request == ESD_PROTO_STANDBY) + ok = pa_sink_suspend_all(c->protocol->core, TRUE) >= 0; + else { + pa_assert(request == ESD_PROTO_RESUME); + ok = pa_sink_suspend_all(c->protocol->core, FALSE) >= 0; + } + connection_write(c, &ok, sizeof(int32_t)); return 0; } +static int esd_proto_standby_mode(connection *c, esd_proto_t request, const void *data, size_t length) { + int32_t mode; + pa_sink *sink, *source; + + connection_assert_ref(c); + + mode = ESM_RUNNING; + + if ((sink = pa_namereg_get(c->protocol->core, c->options->default_sink, PA_NAMEREG_SINK))) + if (pa_sink_get_state(sink) == PA_SINK_SUSPENDED) + mode = ESM_ON_STANDBY; + + if ((source = pa_namereg_get(c->protocol->core, c->options->default_source, PA_NAMEREG_SOURCE))) + if (pa_source_get_state(source) == PA_SOURCE_SUSPENDED) + mode = ESM_ON_STANDBY; + + mode = PA_MAYBE_INT32_SWAP(c->swap_byte_order, mode); + + connection_write(c, &mode, sizeof(mode)); + return 0; +} + /*** client callbacks ***/ static void client_kill_cb(pa_client *c) { @@ -912,7 +997,13 @@ static int do_read(connection *c) { ssize_t r; pa_assert(c->read_data_length < sizeof(c->request)); - if ((r = pa_iochannel_read(c->io, ((uint8_t*) &c->request) + c->read_data_length, sizeof(c->request) - c->read_data_length)) <= 0) { + if ((r = pa_iochannel_read(c->io, + ((uint8_t*) &c->request) + c->read_data_length, + sizeof(c->request) - c->read_data_length)) <= 0) { + + if (r < 0 && (errno == EINTR || errno == EAGAIN)) + return 0; + pa_log_debug("read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF"); return -1; } @@ -962,7 +1053,10 @@ static int do_read(connection *c) { pa_assert(c->read_data && c->read_data_length < handler->data_length); - if ((r = pa_iochannel_read(c->io, (uint8_t*) c->read_data + c->read_data_length, handler->data_length - c->read_data_length)) <= 0) { + if ((r = pa_iochannel_read(c->io, + (uint8_t*) c->read_data + c->read_data_length, + handler->data_length - c->read_data_length)) <= 0) { + if (r < 0 && (errno == EINTR || errno == EAGAIN)) return 0; diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index 22419ee5..34217c86 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -943,9 +943,9 @@ pa_bool_t pa_sink_input_get_mute(pa_sink_input *i) { /* Called from main thread */ void pa_sink_input_update_proplist(pa_sink_input *i, pa_update_mode_t mode, pa_proplist *p) { pa_sink_input_assert_ref(i); - pa_assert(p); - pa_proplist_update(i->proplist, mode, p); + if (p) + pa_proplist_update(i->proplist, mode, p); if (PA_SINK_IS_LINKED(i->state)) { pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_PROPLIST_CHANGED], i); diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c index 382fb88c..d63aca15 100644 --- a/src/pulsecore/source-output.c +++ b/src/pulsecore/source-output.c @@ -618,9 +618,9 @@ void pa_source_output_set_name(pa_source_output *o, const char *name) { /* Called from main thread */ void pa_source_output_update_proplist(pa_source_output *o, pa_update_mode_t mode, pa_proplist *p) { pa_source_output_assert_ref(o); - pa_assert(p); - pa_proplist_update(o->proplist, mode, p); + if (p) + pa_proplist_update(o->proplist, mode, p); if (PA_SINK_IS_LINKED(o->state)) { pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PROPLIST_CHANGED], o); |