mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
core-format: Add pa_format_info_get_sample_format()
This commit is contained in:
parent
d2c9b46aca
commit
eae16f41a4
3 changed files with 33 additions and 7 deletions
|
|
@ -218,7 +218,7 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m
|
|||
|
||||
/* For PCM streams */
|
||||
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 *m = NULL;
|
||||
int rate, channels;
|
||||
int ret = -PA_ERR_INVALID;
|
||||
|
||||
|
|
@ -228,16 +228,13 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
|
|||
if (!pa_format_info_is_pcm(f))
|
||||
return pa_format_info_to_sample_spec_fake(f, ss, map);
|
||||
|
||||
if (pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf))
|
||||
if (pa_format_info_get_sample_format(f, &ss->format) < 0)
|
||||
goto out;
|
||||
if (pa_format_info_get_prop_int(f, PA_PROP_FORMAT_RATE, &rate))
|
||||
goto out;
|
||||
if (pa_format_info_get_prop_int(f, PA_PROP_FORMAT_CHANNELS, &channels))
|
||||
goto out;
|
||||
|
||||
if ((ss->format = pa_parse_sample_format(sf)) == PA_SAMPLE_INVALID)
|
||||
goto out;
|
||||
|
||||
ss->rate = (uint32_t) rate;
|
||||
ss->channels = (uint8_t) channels;
|
||||
|
||||
|
|
@ -252,8 +249,6 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
|
|||
ret = 0;
|
||||
|
||||
out:
|
||||
if (sf)
|
||||
pa_xfree(sf);
|
||||
if (m)
|
||||
pa_xfree(m);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,35 @@
|
|||
#include "core-format.h"
|
||||
|
||||
#include <pulse/def.h>
|
||||
#include <pulse/xmalloc.h>
|
||||
|
||||
#include <pulsecore/macro.h>
|
||||
|
||||
int pa_format_info_get_sample_format(pa_format_info *f, pa_sample_format_t *sf) {
|
||||
int r;
|
||||
char *sf_str;
|
||||
pa_sample_format_t sf_local;
|
||||
|
||||
pa_assert(f);
|
||||
pa_assert(sf);
|
||||
|
||||
r = pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf_str);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
sf_local = pa_parse_sample_format(sf_str);
|
||||
pa_xfree(sf_str);
|
||||
|
||||
if (!pa_sample_format_valid(sf_local)) {
|
||||
pa_log_debug("Invalid sample format.");
|
||||
return -PA_ERR_INVALID;
|
||||
}
|
||||
|
||||
*sf = sf_local;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss, pa_channel_map *map) {
|
||||
int rate;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,11 @@
|
|||
|
||||
#include <pulse/format.h>
|
||||
|
||||
/* Gets the sample format stored in the format info. Returns a negative error
|
||||
* code on failure. If the sample format property is not set at all, returns
|
||||
* -PA_ERR_NOENTITY. */
|
||||
int pa_format_info_get_sample_format(pa_format_info *f, pa_sample_format_t *sf);
|
||||
|
||||
/* For compressed formats. Converts the format info into a sample spec and a
|
||||
* channel map that an ALSA device can use as its configuration parameters when
|
||||
* playing back the compressed data. That is, the returned sample spec doesn't
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue