format: Avoid some code duplication

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).
This commit is contained in:
Arun Raghavan 2011-03-02 11:31:51 +05:30
parent 13229fb39e
commit e418e49ecb
4 changed files with 12 additions and 14 deletions

View file

@ -66,6 +66,10 @@ void pa_format_info_free(pa_format_info *f) {
pa_xfree(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) { int pa_format_info_valid(pa_format_info *f) {
return (f->encoding >= 0 && f->encoding < PA_ENCODING_MAX && f->plist != NULL); return (f->encoding >= 0 && f->encoding < PA_ENCODING_MAX && f->plist != NULL);
} }

View 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_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_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_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_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); pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);

View file

@ -35,6 +35,7 @@
#include <pulse/utf8.h> #include <pulse/utf8.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/internal.h>
#include <pulsecore/native-common.h> #include <pulsecore/native-common.h>
#include <pulsecore/packet.h> #include <pulsecore/packet.h>
@ -1849,10 +1850,6 @@ static pa_tagstruct *reply_new(uint32_t tag) {
return reply; 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) { 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); pa_native_connection *c = PA_NATIVE_CONNECTION(userdata);
playback_stream *s; playback_stream *s;
@ -2110,7 +2107,7 @@ error:
if (p) if (p)
pa_proplist_free(p); pa_proplist_free(p);
if (formats) 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; return;
} }

View 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; 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 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_bool_t ret = TRUE;
pa_idxset *formats = NULL; 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->sink = s;
data->save_sink = save; data->save_sink = save;
if (data->nego_formats) 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; data->nego_formats = formats;
} else { } else {
/* Sink doesn't support any of the formats requested by the client */ /* Sink doesn't support any of the formats requested by the client */
if (formats) 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; 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); pa_assert(formats);
if (data->req_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; data->req_formats = formats;
@ -188,10 +184,10 @@ void pa_sink_input_new_data_done(pa_sink_input_new_data *data) {
pa_assert(data); pa_assert(data);
if (data->req_formats) 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) 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) if (data->format)
pa_format_info_free(data->format); pa_format_info_free(data->format);