+ *(response++) = maybe_swap_endian_32(c->swap_byte_order, rate);
+ *(response++) = maybe_swap_endian_32(c->swap_byte_order, format);
+ return 0;
+}
+
+static int esd_proto_all_info(struct connection *c, const void *data, size_t length) {
+ void *response;
+ size_t t, k, s;
+ struct connection *conn;
+ size_t index = IDXSET_INVALID;
+ assert(c && data && length == sizeof(int));
+
+ if (esd_proto_server_info(c, data, length) < 0)
+ return -1;
+
+ k = sizeof(int)*5+ESD_NAME_MAX;
+ s = sizeof(int)*6+ESD_NAME_MAX;
+ response = connection_write(c, (t = s+k*(c->protocol->n_player+1)));
+ assert(k);
+
+ for (conn = idxset_first(c->protocol->connections, &index); conn; conn = idxset_next(c->protocol->connections, &index)) {
+ int format = ESD_BITS16 | ESD_STEREO, rate = 44100, volume = 0xFF;
+
+ if (conn->state != ESD_STREAMING_DATA)
+ continue;
+
+ assert(t >= s+k+k);
+
+ if (conn->sink_input) {
+ rate = conn->sink_input->sample_spec.rate;
+ volume = (conn->sink_input->volume*0xFF)/0x100;
+ format = (conn->sink_input->sample_spec.format == PA_SAMPLE_U8) ? ESD_BITS8 : ESD_BITS16;
+ format |= (conn->sink_input->sample_spec.channels >= 2) ? ESD_STEREO : ESD_MONO;
+ }
+
+ /* id */
+ *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, (int) conn->index);
+ response += sizeof(int);
+
+ /* name */
+ assert(conn->client);
+ strncpy(response, conn->client->name, ESD_NAME_MAX);
+ response += ESD_NAME_MAX;
+
+ /* rate */
+ *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, rate);
+ response += sizeof(int);
+
+ /* left */
+ *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, volume);
+ response += sizeof(int);
+
+ /*right*/
+ *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, volume);
+ response += sizeof(int);
+
+ /*format*/
+ *((int*) response) = maybe_swap_endian_32(c->swap_byte_order, format);
+ response += sizeof(int);
+
+ t-= k;
+ }
+
+ assert(t == s+k);
+ memset(response, 0, t);
+ return 0;
+}
+
+static int esd_proto_stream_pan(struct connection *c, const void *data, size_t length) {
+ int *ok;
+ uint32_t index, volume;
+ struct connection *conn;
+ assert(c && data && length == sizeof(int)*3);
+
+ index = (uint32_t) maybe_swap_endian_32(c->swap_byte_order, *(int*)data);
+ volume = (uint32_t) maybe_swap_endian_32(c->swap_byte_order, *((int*)data + 1));
+ volume = (volume*0x100)/0xFF;
+
+ ok = connection_write(c, sizeof(int));
+ assert(ok);
+
+ if ((conn = idxset_get_by_index(c->protocol->connections, index))) {
+ assert(conn->sink_input);
+ conn->sink_input->volume = volume;
+ *ok = 1;
+ } else
+ *ok = 0;
+