mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-31 22:25:33 -04:00
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:
parent
13229fb39e
commit
e418e49ecb
4 changed files with 12 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue