[pulseaudio-discuss] [PATCH RFCv3 19/51] pstream: Add helper functions reset_descriptor(), shm_descriptor()

Peter Meerwald pmeerw at pmeerw.net
Tue Nov 4 15:26:14 PST 2014


From: Peter Meerwald <p.meerwald at bct-electronic.com>

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/pstream.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c
index a53a074..7bd7760 100644
--- a/src/pulsecore/pstream.c
+++ b/src/pulsecore/pstream.c
@@ -512,6 +512,22 @@ static void memexport_revoke_cb(pa_memexport *e, uint32_t block_id, void *userda
         pa_pstream_send_revoke(p, block_id);
 }
 
+static void reset_descriptor(void *d, uint32_t l) {
+    uint32_t *descriptor = d;
+
+    descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl(l);
+    descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL] = htonl((uint32_t) -1);
+    descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI] = 0;
+    descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_LO] = 0;
+    descriptor[PA_PSTREAM_DESCRIPTOR_FLAGS] = 0;
+}
+
+static void shm_descriptor(void *d, uint32_t flags, uint32_t block_id) {
+    uint32_t *descriptor = d;
+    descriptor[PA_PSTREAM_DESCRIPTOR_FLAGS] = htonl(flags);
+    descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI] = htonl(block_id);
+}
+
 static void prepare_next_write_item(pa_pstream *p) {
     pa_assert(p);
     pa_assert(PA_REFCNT_VALUE(p) > 0);
@@ -525,11 +541,7 @@ static void prepare_next_write_item(pa_pstream *p) {
     p->write.minibuf_validsize = 0;
     pa_memchunk_reset(&p->write.memchunk);
 
-    p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = 0;
-    p->write.descriptor[PA_PSTREAM_DESCRIPTOR_CHANNEL] = htonl((uint32_t) -1);
-    p->write.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI] = 0;
-    p->write.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_LO] = 0;
-    p->write.descriptor[PA_PSTREAM_DESCRIPTOR_FLAGS] = 0;
+    reset_descriptor(p->write.descriptor, 0);
 
     if (p->write.current->type == PA_PSTREAM_ITEM_PACKET) {
         size_t plen;
@@ -559,13 +571,11 @@ static void prepare_next_write_item(pa_pstream *p) {
 
     } else if (p->write.current->type == PA_PSTREAM_ITEM_SHMRELEASE) {
 
-        p->write.descriptor[PA_PSTREAM_DESCRIPTOR_FLAGS] = htonl(PA_FLAG_SHMRELEASE);
-        p->write.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI] = htonl(p->write.current->per_type.block_id);
+        shm_descriptor(p->write.descriptor, PA_FLAG_SHMRELEASE, p->write.current->per_type.block_id);
 
     } else if (p->write.current->type == PA_PSTREAM_ITEM_SHMREVOKE) {
 
-        p->write.descriptor[PA_PSTREAM_DESCRIPTOR_FLAGS] = htonl(PA_FLAG_SHMREVOKE);
-        p->write.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI] = htonl(p->write.current->per_type.block_id);
+        shm_descriptor(p->write.descriptor, PA_FLAG_SHMREVOKE, p->write.current->per_type.block_id);
 
     } else {
         uint32_t flags;
-- 
1.9.1



More information about the pulseaudio-discuss mailing list