]> code.delx.au - pulseaudio/blobdiff - polyp/protocol-esound.c
Merge Pierre's changes
[pulseaudio] / polyp / protocol-esound.c
index a32a9bd87ef4da69c503d45548213c78c4db22c8..18ecb0ac1f69c276d458c1b429c6af3ba5c683b8 100644 (file)
@@ -63,6 +63,8 @@
 
 #define SCACHE_PREFIX "esound."
 
+#define PA_TYPEID_ESOUND PA_TYPEID_MAKE('E', 'S', 'D', 'P')
+
 /* This is heavily based on esound's code */
 
 struct connection {
@@ -237,11 +239,14 @@ static void* connection_write(struct connection *c, size_t length) {
     return (uint8_t*) c->write_data+i;
 }
 
-static void format_esd2native(int format, struct pa_sample_spec *ss) {
+static void format_esd2native(int format, int swap_bytes, struct pa_sample_spec *ss) {
     assert(ss);
 
     ss->channels = ((format & ESD_MASK_CHAN) == ESD_STEREO) ? 2 : 1;
-    ss->format = ((format & ESD_MASK_BITS) == ESD_BITS16) ? PA_SAMPLE_S16NE : PA_SAMPLE_U8;
+    if ((format & ESD_MASK_BITS) == ESD_BITS16)
+        ss->format = swap_bytes ? PA_SAMPLE_S16RE : PA_SAMPLE_S16NE;
+    else
+        ss->format = PA_SAMPLE_U8;
 }
 
 static int format_native2esd(struct pa_sample_spec *ss) {
@@ -301,7 +306,7 @@ static int esd_proto_stream_play(struct connection *c, esd_proto_t request, cons
     rate = maybe_swap_endian_32(c->swap_byte_order, *((int*)data + 1));
 
     ss.rate = rate;
-    format_esd2native(format, &ss);
+    format_esd2native(format, c->swap_byte_order, &ss);
 
     if (!pa_sample_spec_valid(&ss)) {
         pa_log(__FILE__": invalid sample specification\n");
@@ -320,7 +325,7 @@ static int esd_proto_stream_play(struct connection *c, esd_proto_t request, cons
 
     assert(!c->sink_input && !c->input_memblockq);
 
-    if (!(c->sink_input = pa_sink_input_new(sink, name, &ss, 0, -1))) {
+    if (!(c->sink_input = pa_sink_input_new(sink, PA_TYPEID_ESOUND, name, &ss, 0, -1))) {
         pa_log(__FILE__": failed to create sink input.\n");
         return -1;
     }
@@ -357,7 +362,7 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
     rate = maybe_swap_endian_32(c->swap_byte_order, *((int*)data + 1));
 
     ss.rate = rate;
-    format_esd2native(format, &ss);
+    format_esd2native(format, c->swap_byte_order, &ss);
 
     if (!pa_sample_spec_valid(&ss)) {
         pa_log(__FILE__": invalid sample specification.\n");
@@ -392,7 +397,7 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
 
     assert(!c->output_memblockq && !c->source_output);
 
-    if (!(c->source_output = pa_source_output_new(source, name, &ss, -1))) {
+    if (!(c->source_output = pa_source_output_new(source, PA_TYPEID_ESOUND, name, &ss, -1))) {
         pa_log(__FILE__": failed to create source output\n");
         return -1;
     }
@@ -424,7 +429,6 @@ static int esd_proto_get_latency(struct connection *c, esd_proto_t request, cons
         latency = 0;
     else {
         double usec = pa_sink_get_latency(sink);
-        usec += PLAYBACK_BUFFER_SECONDS*1000000;          /* A better estimation would be a good idea! */
         latency = (int) ((usec*44100)/1000000);
     }
     
@@ -601,7 +605,7 @@ static int esd_proto_sample_cache(struct connection *c, esd_proto_t request, con
     rate = maybe_swap_endian_32(c->swap_byte_order, *((int*)data + 1));
     
     ss.rate = rate;
-    format_esd2native(format, &ss);
+    format_esd2native(format, c->swap_byte_order, &ss);
 
     sc_length = (size_t) maybe_swap_endian_32(c->swap_byte_order, (*((int*)data + 2)));
 
@@ -712,7 +716,8 @@ static int do_read(struct connection *c) {
         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) {
-            pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+            if (r != 0)
+                pa_log_warn(__FILE__": read() failed: %s\n", strerror(errno));
             return -1;
         }
 
@@ -761,7 +766,8 @@ static int do_read(struct connection *c) {
         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) {
-            pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+            if (r != 0)
+                pa_log_warn(__FILE__": read() failed: %s\n", strerror(errno));
             return -1;
         }
 
@@ -781,7 +787,8 @@ static int do_read(struct connection *c) {
         assert(c->scache.memchunk.memblock && c->scache.name && c->scache.memchunk.index < c->scache.memchunk.length);
         
         if ((r = pa_iochannel_read(c->io, (uint8_t*) c->scache.memchunk.memblock->data+c->scache.memchunk.index, c->scache.memchunk.length-c->scache.memchunk.index)) <= 0) {
-            pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+            if (r!= 0)
+                pa_log_warn(__FILE__": read() failed: %s\n", strerror(errno));
             return -1;
         }
 
@@ -838,7 +845,8 @@ static int do_read(struct connection *c) {
         }
 
         if ((r = pa_iochannel_read(c->io, (uint8_t*) c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
-            pa_log(__FILE__": read() failed: %s\n", r == 0 ? "EOF" : strerror(errno));
+            if (r != 0)
+                pa_log(__FILE__": read() failed: %s\n", strerror(errno));
             return -1;
         }
         
@@ -1058,7 +1066,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
 
     pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname));
     assert(p->core);
-    c->client = pa_client_new(p->core, "ESOUND", cname);
+    c->client = pa_client_new(p->core, PA_TYPEID_ESOUND, cname);
     assert(c->client);
     c->client->owner = p->module;
     c->client->kill = client_kill_cb;
@@ -1093,7 +1101,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
 
     if (!c->authorized) {
         struct timeval tv;
-        gettimeofday(&tv, NULL);
+        pa_gettimeofday(&tv);
         tv.tv_sec += AUTH_TIMEOUT;
         c->auth_timeout_event = p->core->mainloop->time_new(p->core->mainloop, &tv, auth_timeout, c);
     } else