[pulseaudio-discuss] [PATCH RFC 08/17] packet: Introduce pa_packet_new_data() to copy data into a newly created packet

Peter Meerwald pmeerw at pmeerw.net
Fri Oct 24 14:21:32 PDT 2014


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

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/packet.c       | 9 +++++++++
 src/pulsecore/packet.h       | 4 ++++
 src/pulsecore/pstream-util.c | 2 +-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/pulsecore/packet.c b/src/pulsecore/packet.c
index 091cfb3..2f8eacf 100644
--- a/src/pulsecore/packet.c
+++ b/src/pulsecore/packet.c
@@ -62,6 +62,15 @@ pa_packet* pa_packet_new(size_t length) {
     return p;
 }
 
+pa_packet* pa_packet_new_data(const void* data, size_t length) {
+    pa_packet *p = pa_packet_new(length);
+
+    if (p && data)
+        memcpy(p->data, data, length);
+
+    return p;
+}
+
 pa_packet* pa_packet_new_dynamic(void* data, size_t length) {
     pa_packet *p;
 
diff --git a/src/pulsecore/packet.h b/src/pulsecore/packet.h
index 33c66f2..f36eb11 100644
--- a/src/pulsecore/packet.h
+++ b/src/pulsecore/packet.h
@@ -31,6 +31,10 @@ typedef struct pa_packet pa_packet;
  * on length) */
 pa_packet* pa_packet_new(size_t length);
 
+/* create packet (either of type appended or dynamic depending on length)
+ * and copy data */
+pa_packet* pa_packet_new_data(const void* data, size_t length);
+
 /* data must have been malloc()ed; the packet takes ownership of the memory,
  * i.e. memory is free()d with the packet */
 pa_packet* pa_packet_new_dynamic(void* data, size_t length);
diff --git a/src/pulsecore/pstream-util.c b/src/pulsecore/pstream-util.c
index b029482..8312cc5 100644
--- a/src/pulsecore/pstream-util.c
+++ b/src/pulsecore/pstream-util.c
@@ -38,7 +38,7 @@ static void pa_pstream_send_tagstruct_with_ancil(pa_pstream *p, pa_tagstruct *t,
     pa_assert(t);
 
     pa_assert_se(data = pa_tagstruct_data(t, &length));
-    pa_assert_se(packet = pa_packet_new_dynamic(pa_xmemdup(data, length), length));
+    pa_assert_se(packet = pa_packet_new_data(data, length));
     pa_tagstruct_free(t);
 
     pa_pstream_send_packet(p, packet, ancil);
-- 
1.9.1



More information about the pulseaudio-discuss mailing list