#endif
#ifdef HAVE_BYTESWAP_H
-#define INT16_SWAP(x) ((int16_t) bswap_16((uint16_t) x))
-#define UINT16_SWAP(x) ((uint16_t) bswap_16((uint16_t) x))
-#define INT32_SWAP(x) ((int32_t) bswap_32((uint32_t) x))
-#define UINT32_SWAP(x) ((uint32_t) bswap_32((uint32_t) x))
+#define PA_INT16_SWAP(x) ((int16_t) bswap_16((uint16_t) x))
+#define PA_UINT16_SWAP(x) ((uint16_t) bswap_16((uint16_t) x))
+#define PA_INT32_SWAP(x) ((int32_t) bswap_32((uint32_t) x))
+#define PA_UINT32_SWAP(x) ((uint32_t) bswap_32((uint32_t) x))
#else
-#define INT16_SWAP(x) ( (int16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
-#define UINT16_SWAP(x) ( (uint16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
-#define INT32_SWAP(x) ( (int32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
-#define UINT32_SWAP(x) ( (uint32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
+#define PA_INT16_SWAP(x) ( (int16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
+#define PA_UINT16_SWAP(x) ( (uint16_t) ( ((uint16_t) x >> 8) | ((uint16_t) x << 8) ) )
+#define PA_INT32_SWAP(x) ( (int32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
+#define PA_UINT32_SWAP(x) ( (uint32_t) ( ((uint32_t) x >> 24) | ((uint32_t) x << 24) | (((uint32_t) x & 0xFF00) << 8) | ((((uint32_t) x) >> 8) & 0xFF00) ) )
#endif
-#define MAYBE_INT32_SWAP(c,x) ((c) ? INT32_SWAP(x) : x)
-#define MAYBE_UINT32_SWAP(c,x) ((c) ? UINT32_SWAP(x) : x)
+#define PA_MAYBE_INT16_SWAP(c,x) ((c) ? PA_INT32_SWAP(x) : x)
+#define PA_MAYBE_UINT16_SWAP(c,x) ((c) ? PA_UINT32_SWAP(x) : x)
+
+#define PA_MAYBE_INT32_SWAP(c,x) ((c) ? PA_INT32_SWAP(x) : x)
+#define PA_MAYBE_UINT32_SWAP(c,x) ((c) ? PA_UINT32_SWAP(x) : x)
#ifdef WORDS_BIGENDIAN
- #define INT16_FROM_LE(x) INT16_SWAP(x)
- #define INT16_FROM_BE(x) ((int16_t)(x))
+ #define PA_INT16_FROM_LE(x) PA_INT16_SWAP(x)
+ #define PA_INT16_FROM_BE(x) ((int16_t)(x))
- #define INT16_TO_LE(x) INT16_SWAP(x)
- #define INT16_TO_BE(x) ((int16_t)(x))
+ #define PA_INT16_TO_LE(x) PA_INT16_SWAP(x)
+ #define PA_INT16_TO_BE(x) ((int16_t)(x))
- #define UINT16_FROM_LE(x) UINT16_SWAP(x)
- #define UINT16_FROM_BE(x) ((uint16_t)(x))
+ #define PA_UINT16_FROM_LE(x) PA_UINT16_SWAP(x)
+ #define PA_UINT16_FROM_BE(x) ((uint16_t)(x))
- #define INT32_FROM_LE(x) INT32_SWAP(x)
- #define INT32_FROM_BE(x) ((int32_t)(x))
+ #define PA_INT32_FROM_LE(x) PA_INT32_SWAP(x)
+ #define PA_INT32_FROM_BE(x) ((int32_t)(x))
- #define UINT32_FROM_LE(x) UINT32_SWAP(x)
- #define UINT32_FROM_BE(x) ((uint32_t)(x))
+ #define PA_UINT32_FROM_LE(x) PA_UINT32_SWAP(x)
+ #define PA_UINT32_FROM_BE(x) ((uint32_t)(x))
- #define UINT32_TO_LE(x) UINT32_SWAP(x)
- #define UINT32_TO_BE(x) ((uint32_t)(x))
+ #define PA_UINT32_TO_LE(x) PA_UINT32_SWAP(x)
+ #define PA_UINT32_TO_BE(x) ((uint32_t)(x))
#else
- #define INT16_FROM_LE(x) ((int16_t)(x))
- #define INT16_FROM_BE(x) INT16_SWAP(x)
+ #define PA_INT16_FROM_LE(x) ((int16_t)(x))
+ #define PA_INT16_FROM_BE(x) PA_INT16_SWAP(x)
- #define INT16_TO_LE(x) ((int16_t)(x))
- #define INT16_TO_BE(x) INT16_SWAP(x)
+ #define PA_INT16_TO_LE(x) ((int16_t)(x))
+ #define PA_INT16_TO_BE(x) PA_INT16_SWAP(x)
- #define UINT16_FROM_LE(x) ((uint16_t)(x))
- #define UINT16_FROM_BE(x) UINT16_SWAP(x)
+ #define PA_UINT16_FROM_LE(x) ((uint16_t)(x))
+ #define PA_UINT16_FROM_BE(x) PA_UINT16_SWAP(x)
- #define INT32_FROM_LE(x) ((int32_t)(x))
- #define INT32_FROM_BE(x) INT32_SWAP(x)
+ #define PA_INT32_FROM_LE(x) ((int32_t)(x))
+ #define PA_INT32_FROM_BE(x) PA_INT32_SWAP(x)
- #define UINT32_FROM_LE(x) ((uint32_t)(x))
- #define UINT32_FROM_BE(x) UINT32_SWAP(x)
+ #define PA_UINT32_FROM_LE(x) ((uint32_t)(x))
+ #define PA_UINT32_FROM_BE(x) PA_UINT32_SWAP(x)
- #define UINT32_TO_LE(x) ((uint32_t)(x))
- #define UINT32_TO_BE(x) UINT32_SWAP(x)
+ #define PA_UINT32_TO_LE(x) ((uint32_t)(x))
+ #define PA_UINT32_TO_BE(x) PA_UINT32_SWAP(x)
#endif
#endif
typedef struct connection {
pa_msgobject parent;
-
+
uint32_t index;
int dead;
pa_protocol_esound *protocol;
int public;
pa_socket_server *server;
pa_idxset *connections;
-
+
char *sink_name, *source_name;
unsigned n_player;
uint8_t esd_key[ESD_KEY_LEN];
pa_client_free(c->client);
c->client = NULL;
}
-
+
if (c->state == ESD_STREAMING_DATA)
c->protocol->n_player--;
static void connection_free(pa_object *obj) {
connection *c = CONNECTION(obj);
pa_assert(c);
-
+
if (c->input_memblockq)
pa_memblockq_free(c->input_memblockq);
if (c->output_memblockq)
pa_assert(length == (sizeof(int32_t)*2+ESD_NAME_MAX));
memcpy(&format, data, sizeof(int32_t));
- format = MAYBE_INT32_SWAP(c->swap_byte_order, format);
+ format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format);
data = (const char*) data + sizeof(int32_t);
memcpy(&rate, data, sizeof(int32_t));
- rate = MAYBE_INT32_SWAP(c->swap_byte_order, rate);
+ rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, rate);
data = (const char*) data + sizeof(int32_t);
ss.rate = rate;
pa_atomic_store(&c->playback.missing, pa_memblockq_missing(c->input_memblockq));
pa_sink_input_put(c->sink_input);
-
+
return 0;
}
pa_assert(length == (sizeof(int32_t)*2+ESD_NAME_MAX));
memcpy(&format, data, sizeof(int32_t));
- format = MAYBE_INT32_SWAP(c->swap_byte_order, format);
+ format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format);
data = (const char*) data + sizeof(int32_t);
memcpy(&rate, data, sizeof(int32_t));
- rate = MAYBE_INT32_SWAP(c->swap_byte_order, rate);
+ rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, rate);
data = (const char*) data + sizeof(int32_t);
ss.rate = rate;
latency = (int) ((usec*44100)/1000000);
}
- latency = MAYBE_INT32_SWAP(c->swap_byte_order, latency);
+ latency = PA_MAYBE_INT32_SWAP(c->swap_byte_order, latency);
connection_write(c, &latency, sizeof(int32_t));
return 0;
}
response = 0;
connection_write(c, &response, sizeof(int32_t));
- rate = MAYBE_INT32_SWAP(c->swap_byte_order, rate);
+ rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, rate);
connection_write(c, &rate, sizeof(int32_t));
- format = MAYBE_INT32_SWAP(c->swap_byte_order, format);
+ format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format);
connection_write(c, &format, sizeof(int32_t));
return 0;
}
/* id */
- id = MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) (conn->index+1));
+ id = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int32_t) (conn->index+1));
connection_write(c, &id, sizeof(int32_t));
/* name */
connection_write(c, name, ESD_NAME_MAX);
/* rate */
- rate = MAYBE_INT32_SWAP(c->swap_byte_order, rate);
+ rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, rate);
connection_write(c, &rate, sizeof(int32_t));
/* left */
- lvolume = MAYBE_INT32_SWAP(c->swap_byte_order, lvolume);
+ lvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, lvolume);
connection_write(c, &lvolume, sizeof(int32_t));
/*right*/
- rvolume = MAYBE_INT32_SWAP(c->swap_byte_order, rvolume);
+ rvolume = PA_MAYBE_INT32_SWAP(c->swap_byte_order, rvolume);
connection_write(c, &rvolume, sizeof(int32_t));
/*format*/
- format = MAYBE_INT32_SWAP(c->swap_byte_order, format);
+ format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format);
connection_write(c, &format, sizeof(int32_t));
t -= k;
pa_assert(t >= s*2);
/* id */
- id = MAYBE_INT32_SWAP(c->swap_byte_order, (int) (ce->index+1));
+ id = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int) (ce->index+1));
connection_write(c, &id, sizeof(int32_t));
/* name */
connection_write(c, name, ESD_NAME_MAX);
/* rate */
- rate = MAYBE_UINT32_SWAP(c->swap_byte_order, ce->sample_spec.rate);
+ rate = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, ce->sample_spec.rate);
connection_write(c, &rate, sizeof(int32_t));
/* left */
- lvolume = MAYBE_UINT32_SWAP(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
+ lvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
connection_write(c, &lvolume, sizeof(int32_t));
/*right*/
- rvolume = MAYBE_UINT32_SWAP(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
+ rvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, (ce->volume.values[0]*ESD_VOLUME_BASE)/PA_VOLUME_NORM);
connection_write(c, &rvolume, sizeof(int32_t));
/*format*/
- format = MAYBE_INT32_SWAP(c->swap_byte_order, format_native2esd(&ce->sample_spec));
+ format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format_native2esd(&ce->sample_spec));
connection_write(c, &format, sizeof(int32_t));
/*length*/
- len = MAYBE_INT32_SWAP(c->swap_byte_order, (int) ce->memchunk.length);
+ len = PA_MAYBE_INT32_SWAP(c->swap_byte_order, (int) ce->memchunk.length);
connection_write(c, &len, sizeof(int32_t));
t -= s;
pa_assert(length == sizeof(int32_t)*3);
memcpy(&idx, data, sizeof(uint32_t));
- idx = MAYBE_UINT32_SWAP(c->swap_byte_order, idx) - 1;
+ 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 = MAYBE_UINT32_SWAP(c->swap_byte_order, lvolume);
+ lvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, lvolume);
data = (const char*)data + sizeof(uint32_t);
memcpy(&rvolume, data, sizeof(uint32_t));
- rvolume = MAYBE_UINT32_SWAP(c->swap_byte_order, rvolume);
+ rvolume = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, rvolume);
data = (const char*)data + sizeof(uint32_t);
if ((conn = pa_idxset_get_by_index(c->protocol->connections, idx)) && conn->sink_input) {
pa_assert(length == (ESD_NAME_MAX+3*sizeof(int32_t)));
memcpy(&format, data, sizeof(int32_t));
- format = MAYBE_INT32_SWAP(c->swap_byte_order, format);
+ format = PA_MAYBE_INT32_SWAP(c->swap_byte_order, format);
data = (const char*)data + sizeof(int32_t);
memcpy(&rate, data, sizeof(int32_t));
- rate = MAYBE_INT32_SWAP(c->swap_byte_order, rate);
+ rate = PA_MAYBE_INT32_SWAP(c->swap_byte_order, rate);
data = (const char*)data + sizeof(int32_t);
ss.rate = rate;
CHECK_VALIDITY(pa_sample_spec_valid(&ss), "Invalid sample specification.");
memcpy(&sc_length, data, sizeof(int32_t));
- sc_length = MAYBE_INT32_SWAP(c->swap_byte_order, sc_length);
+ sc_length = PA_MAYBE_INT32_SWAP(c->swap_byte_order, sc_length);
data = (const char*)data + sizeof(int32_t);
CHECK_VALIDITY(sc_length <= MAX_CACHE_SAMPLE_SIZE, "Sample too large (%d bytes).", (int)sc_length);
pa_assert(length == sizeof(int32_t));
memcpy(&idx, data, sizeof(uint32_t));
- idx = MAYBE_UINT32_SWAP(c->swap_byte_order, idx) - 1;
+ idx = PA_MAYBE_UINT32_SWAP(c->swap_byte_order, idx) - 1;
ok = 0;
static void client_kill_cb(pa_client *c) {
pa_assert(c);
-
+
connection_unlink(CONNECTION(c->userdata));
}
if ((c->read_data_length+= r) >= sizeof(c->request)) {
struct proto_handler *handler;
- c->request = MAYBE_INT32_SWAP(c->swap_byte_order, c->request);
+ c->request = PA_MAYBE_INT32_SWAP(c->swap_byte_order, c->request);
if (c->request < ESD_PROTO_CONNECT || c->request > ESD_PROTO_MAX) {
pa_log("recieved invalid request.");
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 (errno == EINTR || errno == EAGAIN)
return 0;
-
+
pa_log_debug("read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
return -1;
}
p = pa_memblock_acquire(c->scache.memchunk.memblock);
r = pa_iochannel_read(c->io, (uint8_t*) p+c->scache.memchunk.index, c->scache.memchunk.length-c->scache.memchunk.index);
pa_memblock_release(c->scache.memchunk.memblock);
-
+
if (r <= 0) {
if (errno == EINTR || errno == EAGAIN)
return 0;
-
+
pa_log_debug("read(): %s", r < 0 ? pa_cstrerror(errno) : "EOF");
return -1;
}
p = pa_memblock_acquire(c->playback.current_memblock);
r = pa_iochannel_read(c->io, (uint8_t*) p+c->playback.memblock_index, l);
pa_memblock_release(c->playback.current_memblock);
-
+
if (r <= 0) {
-
+
if (errno == EINTR || errno == EAGAIN)
return 0;
if (errno == EINTR || errno == EAGAIN)
return 0;
-
+
pa_log("write(): %s", pa_cstrerror(errno));
return -1;
}
pa_memblock_release(chunk.memblock);
pa_memblock_unref(chunk.memblock);
-
+
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
return 0;
-
+
pa_log("write(): %s", pa_cstrerror(errno));
return -1;
}
case CONNECTION_MESSAGE_REQUEST_DATA:
do_work(c);
break;
-
+
case CONNECTION_MESSAGE_POST_DATA:
/* pa_log("got data %u", chunk->length); */
pa_memblockq_push_align(c->output_memblockq, chunk);
pa_memblockq_push_align(c->input_memblockq, chunk);
/* pa_log("got data, %u", pa_memblockq_get_length(c->input_memblockq)); */
-
+
return 0;
}
static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
connection*c;
int r;
-
+
pa_assert(i);
c = CONNECTION(i->userdata);
connection_assert_ref(c);
static void auth_timeout(pa_mainloop_api*m, pa_time_event *e, const struct timeval *tv, void *userdata) {
connection *c = CONNECTION(userdata);
-
+
pa_assert(m);
pa_assert(tv);
connection_assert_ref(c);
connection *c;
pa_protocol_esound *p = userdata;
char cname[256], pname[128];
-
+
pa_assert(s);
pa_assert(io);
pa_assert(p);