summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Meerwald <p.meerwald@bct-electronic.com>2014-10-23 11:43:04 +0200
committerPeter Meerwald <pmeerw@pmeerw.net>2015-02-26 23:23:17 +0100
commit5a2c41e5bf13d16f01dce1e73de956ea9456b447 (patch)
treea67f0390dc133aec74b7d4028a18555f37bc82f0
parent9f97f08f400a371e93ee6f178b5307427c79295c (diff)
packet: Hide internals of pa_packet, introduce pa_packet_data()
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
-rw-r--r--src/pulsecore/packet.c18
-rw-r--r--src/pulsecore/packet.h11
-rw-r--r--src/pulsecore/pdispatch.c9
-rw-r--r--src/pulsecore/pstream.c15
-rw-r--r--src/tests/srbchannel-test.c21
5 files changed, 50 insertions, 24 deletions
diff --git a/src/pulsecore/packet.c b/src/pulsecore/packet.c
index 8fea4e20a..a819ee3d8 100644
--- a/src/pulsecore/packet.c
+++ b/src/pulsecore/packet.c
@@ -25,9 +25,17 @@
#include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
+#include <pulsecore/refcnt.h>
#include "packet.h"
+typedef struct pa_packet {
+ PA_REFCNT_DECLARE;
+ enum { PA_PACKET_APPENDED, PA_PACKET_DYNAMIC } type;
+ size_t length;
+ uint8_t *data;
+} pa_packet;
+
pa_packet* pa_packet_new(size_t length) {
pa_packet *p;
@@ -57,6 +65,16 @@ pa_packet* pa_packet_new_dynamic(void* data, size_t length) {
return p;
}
+const void* pa_packet_data(pa_packet *p, size_t *l) {
+ pa_assert(PA_REFCNT_VALUE(p) >= 1);
+ pa_assert(p->data);
+ pa_assert(l);
+
+ *l = p->length;
+
+ return p->data;
+}
+
pa_packet* pa_packet_ref(pa_packet *p) {
pa_assert(p);
pa_assert(PA_REFCNT_VALUE(p) >= 1);
diff --git a/src/pulsecore/packet.h b/src/pulsecore/packet.h
index c49ca06e4..83fa0b863 100644
--- a/src/pulsecore/packet.h
+++ b/src/pulsecore/packet.h
@@ -23,18 +23,13 @@
#include <sys/types.h>
#include <inttypes.h>
-#include <pulsecore/refcnt.h>
-
-typedef struct pa_packet {
- PA_REFCNT_DECLARE;
- enum { PA_PACKET_APPENDED, PA_PACKET_DYNAMIC } type;
- size_t length;
- uint8_t *data;
-} pa_packet;
+typedef struct pa_packet pa_packet;
pa_packet* pa_packet_new(size_t length);
pa_packet* pa_packet_new_dynamic(void* data, size_t length);
+const void* pa_packet_data(pa_packet *p, size_t *l);
+
pa_packet* pa_packet_ref(pa_packet *p);
void pa_packet_unref(pa_packet *p);
diff --git a/src/pulsecore/pdispatch.c b/src/pulsecore/pdispatch.c
index 7837ee309..f1368759f 100644
--- a/src/pulsecore/pdispatch.c
+++ b/src/pulsecore/pdispatch.c
@@ -293,19 +293,20 @@ int pa_pdispatch_run(pa_pdispatch *pd, pa_packet *packet, const pa_cmsg_ancil_da
uint32_t tag, command;
pa_tagstruct *ts = NULL;
int ret = -1;
+ const void *pdata;
+ size_t plen;
pa_assert(pd);
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
pa_assert(packet);
- pa_assert(PA_REFCNT_VALUE(packet) >= 1);
- pa_assert(packet->data);
pa_pdispatch_ref(pd);
- if (packet->length <= 8)
+ pdata = pa_packet_data(packet, &plen);
+ if (plen <= 8)
goto finish;
- ts = pa_tagstruct_new_fixed(packet->data, packet->length);
+ ts = pa_tagstruct_new_fixed(pdata, plen);
if (pa_tagstruct_getu32(ts, &command) < 0 ||
pa_tagstruct_getu32(ts, &tag) < 0)
diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c
index ad8eef1bc..b0ed5a70f 100644
--- a/src/pulsecore/pstream.c
+++ b/src/pulsecore/pstream.c
@@ -491,14 +491,16 @@ static void prepare_next_write_item(pa_pstream *p) {
p->write.descriptor[PA_PSTREAM_DESCRIPTOR_FLAGS] = 0;
if (p->write.current->type == PA_PSTREAM_ITEM_PACKET) {
+ size_t plen;
pa_assert(p->write.current->packet);
- p->write.data = p->write.current->packet->data;
- p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl((uint32_t) p->write.current->packet->length);
- if (p->write.current->packet->length <= MINIBUF_SIZE - PA_PSTREAM_DESCRIPTOR_SIZE) {
- memcpy(&p->write.minibuf[PA_PSTREAM_DESCRIPTOR_SIZE], p->write.data, p->write.current->packet->length);
- p->write.minibuf_validsize = PA_PSTREAM_DESCRIPTOR_SIZE + p->write.current->packet->length;
+ p->write.data = (void *) pa_packet_data(p->write.current->packet, &plen);
+ p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl((uint32_t) plen);
+
+ if (plen <= MINIBUF_SIZE - PA_PSTREAM_DESCRIPTOR_SIZE) {
+ memcpy(&p->write.minibuf[PA_PSTREAM_DESCRIPTOR_SIZE], p->write.data, plen);
+ p->write.minibuf_validsize = PA_PSTREAM_DESCRIPTOR_SIZE + plen;
}
} else if (p->write.current->type == PA_PSTREAM_ITEM_SHMRELEASE) {
@@ -787,6 +789,7 @@ static int do_read(pa_pstream *p, struct pstream_read *re) {
channel = ntohl(re->descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL]);
if (channel == (uint32_t) -1) {
+ size_t plen;
if (flags != 0) {
pa_log_warn("Received packet frame with invalid flags value.");
@@ -795,7 +798,7 @@ static int do_read(pa_pstream *p, struct pstream_read *re) {
/* Frame is a packet frame */
re->packet = pa_packet_new(length);
- re->data = re->packet->data;
+ re->data = (void *) pa_packet_data(re->packet, &plen);
} else {
diff --git a/src/tests/srbchannel-test.c b/src/tests/srbchannel-test.c
index ba7b8ef29..cd4d39790 100644
--- a/src/tests/srbchannel-test.c
+++ b/src/tests/srbchannel-test.c
@@ -35,26 +35,35 @@ static unsigned packets_checksum;
static size_t packets_length;
static void packet_received(pa_pstream *p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data, void *userdata) {
+ const uint8_t *pdata;
+ size_t plen;
unsigned i;
- fail_unless(packets_length == packet->length);
+
+ pdata = pa_packet_data(packet, &plen);
+ fail_unless(packets_length == plen);
+
packets_received++;
- for (i = 0; i < packet->length; i++)
- packets_checksum += packet->data[i];
+ for (i = 0; i < plen; i++)
+ packets_checksum += pdata[i];
}
static void packet_test(unsigned npackets, size_t plength, pa_mainloop *ml, pa_pstream *p1, pa_pstream *p2) {
pa_packet *packet = pa_packet_new(plength);
unsigned i;
unsigned psum = 0, totalsum = 0;
+ uint8_t *pdata;
+ size_t plen;
+
pa_log_info("Sending %d packets of length %zd", npackets, plength);
packets_received = 0;
packets_checksum = 0;
packets_length = plength;
pa_pstream_set_receive_packet_callback(p2, packet_received, NULL);
- for (i = 0; i < plength; i++) {
- packet->data[i] = i;
- psum += packet->data[i];
+ pdata = (uint8_t *) pa_packet_data(packet, &plen);
+ for (i = 0; i < plen; i++) {
+ pdata[i] = i;
+ psum += pdata[i];
}
for (i = 0; i < npackets; i++) {