]> code.delx.au - pulseaudio/commitdiff
format: Avoid some code duplication
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 2 Mar 2011 06:01:51 +0000 (11:31 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 2 May 2011 06:24:48 +0000 (11:54 +0530)
We frequently need to free an idxset containing pa_format_infos, so
define an internal free function that can be used directly with this
(instead of defining it once-per-file).

src/pulse/format.c
src/pulse/internal.h
src/pulsecore/protocol-native.c
src/pulsecore/sink-input.c

index af24eb2e08074845b7f66802ad5379ac36487b64..9bb76732d8ae37636e4516bac346afa47fa6e537 100644 (file)
@@ -66,6 +66,10 @@ void pa_format_info_free(pa_format_info *f) {
     pa_xfree(f);
 }
 
+void pa_format_info_free2(pa_format_info *f, void *userdata) {
+    pa_format_info_free(f);
+}
+
 int pa_format_info_valid(pa_format_info *f) {
     return (f->encoding >= 0 && f->encoding < PA_ENCODING_MAX && f->plist != NULL);
 }
index 228e8dc493cf82585caca4a11c69ab4ae9feba83..351aeec92d40ca7b8c974c7821b3406f3b655d15 100644 (file)
@@ -296,6 +296,7 @@ pa_tagstruct *pa_tagstruct_command(pa_context *c, uint32_t command, uint32_t *ta
 void pa_ext_device_manager_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
 void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
 
+void pa_format_info_free2(pa_format_info *f, void *userdata);
 pa_bool_t pa_format_info_is_compatible(pa_format_info *first, pa_format_info *second);
 pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
 pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);
index 833217904398c1b7d4024e7f3da14fdffc8a4ad0..ee2bc4f506576ffe2e4b24b63950a2be8ae3cd91 100644 (file)
@@ -35,6 +35,7 @@
 #include <pulse/utf8.h>
 #include <pulse/util.h>
 #include <pulse/xmalloc.h>
+#include <pulse/internal.h>
 
 #include <pulsecore/native-common.h>
 #include <pulsecore/packet.h>
@@ -1849,10 +1850,6 @@ static pa_tagstruct *reply_new(uint32_t tag) {
     return reply;
 }
 
-static void free_format_info(pa_format_info *f, void *userdata) {
-    pa_format_info_free(f);
-}
-
 static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) {
     pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
     playback_stream *s;
@@ -2110,7 +2107,7 @@ error:
     if (p)
         pa_proplist_free(p);
     if (formats)
-        pa_idxset_free(formats, (pa_free2_cb_t) free_format_info, NULL);
+        pa_idxset_free(formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
     return;
 }
 
index a465955895d17bdd7b28b967ebc48f374138ec98..0f34e65078c78eeb11eb83ed60750a1d35d43e9b 100644 (file)
@@ -130,10 +130,6 @@ void pa_sink_input_new_data_set_muted(pa_sink_input_new_data *data, pa_bool_t mu
     data->muted = !!mute;
 }
 
-static void free_format_info(pa_format_info *f, void *userdata) {
-    pa_format_info_free(f);
-}
-
 pa_bool_t pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink *s, pa_bool_t save) {
     pa_bool_t ret = TRUE;
     pa_idxset *formats = NULL;
@@ -154,12 +150,12 @@ pa_bool_t pa_sink_input_new_data_set_sink(pa_sink_input_new_data *data, pa_sink
             data->sink = s;
             data->save_sink = save;
             if (data->nego_formats)
-                pa_idxset_free(data->nego_formats, (pa_free2_cb_t) free_format_info, NULL);
+                pa_idxset_free(data->nego_formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
             data->nego_formats = formats;
         } else {
             /* Sink doesn't support any of the formats requested by the client */
             if (formats)
-                pa_idxset_free(formats, (pa_free2_cb_t) free_format_info, NULL);
+                pa_idxset_free(formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
             ret = FALSE;
         }
     }
@@ -172,7 +168,7 @@ pa_bool_t pa_sink_input_new_data_set_formats(pa_sink_input_new_data *data, pa_id
     pa_assert(formats);
 
     if (data->req_formats)
-        pa_idxset_free(formats, (pa_free2_cb_t) free_format_info, NULL);
+        pa_idxset_free(formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
 
     data->req_formats = formats;
 
@@ -188,10 +184,10 @@ void pa_sink_input_new_data_done(pa_sink_input_new_data *data) {
     pa_assert(data);
 
     if (data->req_formats)
-        pa_idxset_free(data->req_formats, (pa_free2_cb_t) free_format_info, NULL);
+        pa_idxset_free(data->req_formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
 
     if (data->nego_formats)
-        pa_idxset_free(data->nego_formats, (pa_free2_cb_t) free_format_info, NULL);
+        pa_idxset_free(data->nego_formats, (pa_free2_cb_t) pa_format_info_free2, NULL);
 
     if (data->format)
         pa_format_info_free(data->format);