mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
format: Expose pa_format_info<->pa_sample_spec conversion functions
These utility functions could be handy to clients. pa_format_info_to_sample_spec_fake() isn't made public, but the return value is changed to keep in sync with pa_format_info_to_sample_spec().
This commit is contained in:
parent
63429b67c7
commit
c60f698f1e
5 changed files with 19 additions and 14 deletions
|
|
@ -219,10 +219,10 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For PCM streams */
|
/* For PCM streams */
|
||||||
pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
|
int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
|
||||||
char *sf = NULL, *m = NULL;
|
char *sf = NULL, *m = NULL;
|
||||||
int rate, channels;
|
int rate, channels;
|
||||||
pa_bool_t ret = FALSE;
|
int ret = -PA_ERR_INVALID;
|
||||||
|
|
||||||
pa_assert(f);
|
pa_assert(f);
|
||||||
pa_assert(ss);
|
pa_assert(ss);
|
||||||
|
|
@ -249,7 +249,7 @@ pa_bool_t pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, p
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (sf)
|
if (sf)
|
||||||
|
|
@ -261,23 +261,23 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For compressed streams */
|
/* For compressed streams */
|
||||||
pa_bool_t pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
|
int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
|
||||||
int rate;
|
int rate;
|
||||||
|
|
||||||
pa_assert(f);
|
pa_assert(f);
|
||||||
pa_assert(ss);
|
pa_assert(ss);
|
||||||
pa_return_val_if_fail(f->encoding != PA_ENCODING_PCM, FALSE);
|
pa_return_val_if_fail(f->encoding != PA_ENCODING_PCM, -PA_ERR_INVALID);
|
||||||
|
|
||||||
ss->format = PA_SAMPLE_S16LE;
|
ss->format = PA_SAMPLE_S16LE;
|
||||||
ss->channels = 2;
|
ss->channels = 2;
|
||||||
|
|
||||||
pa_return_val_if_fail(pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate) == 0, FALSE);
|
pa_return_val_if_fail(pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate) == 0, -PA_ERR_INVALID);
|
||||||
ss->rate = (uint32_t) rate;
|
ss->rate = (uint32_t) rate;
|
||||||
|
|
||||||
if (f->encoding == PA_ENCODING_EAC3_IEC61937)
|
if (f->encoding == PA_ENCODING_EAC3_IEC61937)
|
||||||
ss->rate *= 4;
|
ss->rate *= 4;
|
||||||
|
|
||||||
return TRUE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_format_info_set_sample_format(pa_format_info *f, pa_sample_format_t sf) {
|
void pa_format_info_set_sample_format(pa_format_info *f, pa_sample_format_t sf) {
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,13 @@ char *pa_format_info_snprint(char *s, size_t l, const pa_format_info *f);
|
||||||
* \a pa_format_info_snprint() into a pa_format_info structure. \since 1.0 */
|
* \a pa_format_info_snprint() into a pa_format_info structure. \since 1.0 */
|
||||||
pa_format_info* pa_format_info_from_string(const char *str);
|
pa_format_info* pa_format_info_from_string(const char *str);
|
||||||
|
|
||||||
|
/** Utility function to take a \a pa_sample_spec and generate the corresponding \a pa_format_info. \since 2.0 */
|
||||||
|
pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
|
||||||
|
|
||||||
|
/** Utility function to generate a \a pa_sample_spec and \a pa_channel_map corresponding to a given \a pa_format_info. Returns
|
||||||
|
* a negative integer if conversion failed and 0 on success. \since 2.0 */
|
||||||
|
int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map);
|
||||||
|
|
||||||
/** Gets an integer property from the given format info. Returns 0 on success and a negative integer on failure. \since 2.0 */
|
/** Gets an integer property from the given format info. Returns 0 on success and a negative integer on failure. \since 2.0 */
|
||||||
int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v);
|
int pa_format_info_get_prop_int(pa_format_info *f, const char *key, int *v);
|
||||||
/** Gets a string property from the given format info. The caller must free the returned string using \ref pa_xfree. Returns
|
/** Gets a string property from the given format info. The caller must free the returned string using \ref pa_xfree. Returns
|
||||||
|
|
|
||||||
|
|
@ -304,9 +304,7 @@ void pa_ext_device_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_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t);
|
||||||
|
|
||||||
void pa_format_info_free2(pa_format_info *f, void *userdata);
|
void pa_format_info_free2(pa_format_info *f, void *userdata);
|
||||||
pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_map *map);
|
int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss);
|
||||||
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_fake(pa_format_info *f, pa_sample_spec *ss);
|
|
||||||
|
|
||||||
pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m);
|
pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -293,12 +293,12 @@ int pa_sink_input_new(
|
||||||
/* Now populate the sample spec and format according to the final
|
/* Now populate the sample spec and format according to the final
|
||||||
* format that we've negotiated */
|
* format that we've negotiated */
|
||||||
if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
|
if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
|
||||||
pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map), -PA_ERR_INVALID);
|
pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
|
||||||
pa_sink_input_new_data_set_sample_spec(data, &ss);
|
pa_sink_input_new_data_set_sample_spec(data, &ss);
|
||||||
if (pa_channel_map_valid(&map))
|
if (pa_channel_map_valid(&map))
|
||||||
pa_sink_input_new_data_set_channel_map(data, &map);
|
pa_sink_input_new_data_set_channel_map(data, &map);
|
||||||
} else {
|
} else {
|
||||||
pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss), -PA_ERR_INVALID);
|
pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss) == 0, -PA_ERR_INVALID);
|
||||||
pa_sink_input_new_data_set_sample_spec(data, &ss);
|
pa_sink_input_new_data_set_sample_spec(data, &ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -273,12 +273,12 @@ int pa_source_output_new(
|
||||||
/* Now populate the sample spec and format according to the final
|
/* Now populate the sample spec and format according to the final
|
||||||
* format that we've negotiated */
|
* format that we've negotiated */
|
||||||
if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
|
if (PA_LIKELY(data->format->encoding == PA_ENCODING_PCM)) {
|
||||||
pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map), -PA_ERR_INVALID);
|
pa_return_val_if_fail(pa_format_info_to_sample_spec(data->format, &ss, &map) == 0, -PA_ERR_INVALID);
|
||||||
pa_source_output_new_data_set_sample_spec(data, &ss);
|
pa_source_output_new_data_set_sample_spec(data, &ss);
|
||||||
if (pa_channel_map_valid(&map))
|
if (pa_channel_map_valid(&map))
|
||||||
pa_source_output_new_data_set_channel_map(data, &map);
|
pa_source_output_new_data_set_channel_map(data, &map);
|
||||||
} else {
|
} else {
|
||||||
pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss), -PA_ERR_INVALID);
|
pa_return_val_if_fail(pa_format_info_to_sample_spec_fake(data->format, &ss) == 0, -PA_ERR_INVALID);
|
||||||
pa_source_output_new_data_set_sample_spec(data, &ss);
|
pa_source_output_new_data_set_sample_spec(data, &ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue