[pulseaudio-discuss] [PATCH 2/2] tagstruct: Allow NULL proplist with pa_tagstruct_get_proplist().

Tanu Kaskinen tanu.kaskinen at digia.com
Fri Apr 13 04:40:32 PDT 2012


module-tunnel doesn't care about the proplist contents, so
pa_tagstruct_get_proplist() is only used for removing the
data from the tagstruct buffer. In that case it's more
convenient to just pass NULL as the proplist argument.
---
 src/modules/module-tunnel.c |   24 +++---------------------
 src/pulsecore/tagstruct.c   |    8 +++++---
 2 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c
index 0916717..4490d4e 100644
--- a/src/modules/module-tunnel.c
+++ b/src/modules/module-tunnel.c
@@ -1065,13 +1065,10 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
     pa_cvolume volume;
     pa_bool_t mute;
     pa_usec_t latency;
-    pa_proplist *pl;
 
     pa_assert(pd);
     pa_assert(u);
 
-    pl = pa_proplist_new();
-
     if (command != PA_COMMAND_REPLY) {
         if (command == PA_COMMAND_ERROR)
             pa_log("Failed to get info.");
@@ -1101,7 +1098,7 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
     if (u->version >= 13) {
         pa_usec_t configured_latency;
 
-        if (pa_tagstruct_get_proplist(t, pl) < 0 ||
+        if (pa_tagstruct_get_proplist(t, NULL) < 0 ||
             pa_tagstruct_get_usec(t, &configured_latency) < 0) {
 
             pa_log("Parse failure");
@@ -1134,8 +1131,6 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
         goto fail;
     }
 
-    pa_proplist_free(pl);
-
     if (!u->sink_name || strcmp(name, u->sink_name))
         return;
 
@@ -1148,7 +1143,6 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
 
 fail:
     pa_module_unload_request(u->module, TRUE);
-    pa_proplist_free(pl);
 }
 
 /* Called from main context */
@@ -1161,14 +1155,11 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
     pa_cvolume volume;
-    pa_proplist *pl;
     pa_bool_t b;
 
     pa_assert(pd);
     pa_assert(u);
 
-    pl = pa_proplist_new();
-
     if (command != PA_COMMAND_REPLY) {
         if (command == PA_COMMAND_ERROR)
             pa_log("Failed to get info.");
@@ -1203,7 +1194,7 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
     }
 
     if (u->version >= 13) {
-        if (pa_tagstruct_get_proplist(t, pl) < 0) {
+        if (pa_tagstruct_get_proplist(t, NULL) < 0) {
 
             pa_log("Parse failure");
             goto fail;
@@ -1243,8 +1234,6 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
         goto fail;
     }
 
-    pa_proplist_free(pl);
-
     if (idx != u->device_index)
         return;
 
@@ -1263,7 +1252,6 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag
 
 fail:
     pa_module_unload_request(u->module, TRUE);
-    pa_proplist_free(pl);
 }
 
 #else
@@ -1278,13 +1266,10 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
     pa_cvolume volume;
     pa_bool_t mute;
     pa_usec_t latency, configured_latency;
-    pa_proplist *pl;
 
     pa_assert(pd);
     pa_assert(u);
 
-    pl = pa_proplist_new();
-
     if (command != PA_COMMAND_REPLY) {
         if (command == PA_COMMAND_ERROR)
             pa_log("Failed to get info.");
@@ -1312,7 +1297,7 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
     }
 
     if (u->version >= 13) {
-        if (pa_tagstruct_get_proplist(t, pl) < 0 ||
+        if (pa_tagstruct_get_proplist(t, NULL) < 0 ||
             pa_tagstruct_get_usec(t, &configured_latency) < 0) {
 
             pa_log("Parse failure");
@@ -1345,8 +1330,6 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
         goto fail;
     }
 
-    pa_proplist_free(pl);
-
     if (!u->source_name || strcmp(name, u->source_name))
         return;
 
@@ -1359,7 +1342,6 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
 
 fail:
     pa_module_unload_request(u->module, TRUE);
-    pa_proplist_free(pl);
 }
 
 #endif
diff --git a/src/pulsecore/tagstruct.c b/src/pulsecore/tagstruct.c
index a0f1f10..762947a 100644
--- a/src/pulsecore/tagstruct.c
+++ b/src/pulsecore/tagstruct.c
@@ -602,7 +602,6 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
     size_t saved_rindex;
 
     pa_assert(t);
-    pa_assert(p);
 
     if (t->rindex+1 > t->length)
         return -1;
@@ -624,6 +623,9 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
         if (!k)
             break;
 
+        if (!pa_proplist_key_valid(k))
+            goto fail;
+
         if (pa_tagstruct_getu32(t, &length) < 0)
             goto fail;
 
@@ -633,8 +635,8 @@ int pa_tagstruct_get_proplist(pa_tagstruct *t, pa_proplist *p) {
         if (pa_tagstruct_get_arbitrary(t, &d, length) < 0)
             goto fail;
 
-        if (pa_proplist_set(p, k, d, length) < 0)
-            goto fail;
+        if (p)
+            pa_assert_se(pa_proplist_set(p, k, d, length) >= 0);
     }
 
     return 0;
-- 
1.7.10



More information about the pulseaudio-discuss mailing list