mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-08 13:29:59 -05:00
format: Allow format->sample spec conversion for compressed formats
This allows clients to get a "fake" sample space for compressed formats that we can support. This should make size/time conversion for things like calculating buffer attributes simpler.
This commit is contained in:
parent
8baf8e90c2
commit
a0706e7c84
6 changed files with 38 additions and 43 deletions
|
|
@ -218,6 +218,28 @@ pa_format_info* pa_format_info_from_sample_spec(pa_sample_spec *ss, pa_channel_m
|
|||
return f;
|
||||
}
|
||||
|
||||
/* For compressed streams */
|
||||
static int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
|
||||
int rate;
|
||||
|
||||
pa_assert(f);
|
||||
pa_assert(ss);
|
||||
|
||||
/* Note: When we add support for non-IEC61937 encapsulated compressed
|
||||
* formats, this function should return a non-zero values for these. */
|
||||
|
||||
ss->format = PA_SAMPLE_S16LE;
|
||||
ss->channels = 2;
|
||||
|
||||
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;
|
||||
|
||||
if (f->encoding == PA_ENCODING_EAC3_IEC61937)
|
||||
ss->rate *= 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
|
@ -226,7 +248,9 @@ int pa_format_info_to_sample_spec(pa_format_info *f, pa_sample_spec *ss, pa_chan
|
|||
|
||||
pa_assert(f);
|
||||
pa_assert(ss);
|
||||
pa_return_val_if_fail(f->encoding == PA_ENCODING_PCM, FALSE);
|
||||
|
||||
if (!pa_format_info_is_pcm(f))
|
||||
return pa_format_info_to_sample_spec_fake(f, ss);
|
||||
|
||||
if (pa_format_info_get_prop_string(f, PA_PROP_FORMAT_SAMPLE_FORMAT, &sf))
|
||||
goto out;
|
||||
|
|
@ -260,26 +284,6 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* For compressed streams */
|
||||
int pa_format_info_to_sample_spec_fake(pa_format_info *f, pa_sample_spec *ss) {
|
||||
int rate;
|
||||
|
||||
pa_assert(f);
|
||||
pa_assert(ss);
|
||||
pa_return_val_if_fail(f->encoding != PA_ENCODING_PCM, -PA_ERR_INVALID);
|
||||
|
||||
ss->format = PA_SAMPLE_S16LE;
|
||||
ss->channels = 2;
|
||||
|
||||
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;
|
||||
|
||||
if (f->encoding == PA_ENCODING_EAC3_IEC61937)
|
||||
ss->rate *= 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pa_prop_type_t pa_format_info_get_prop_type(pa_format_info *f, const char *key) {
|
||||
const char *str;
|
||||
json_object *o, *o1;
|
||||
|
|
|
|||
|
|
@ -118,8 +118,11 @@ 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 */
|
||||
/** Utility function to generate a \a pa_sample_spec and \a pa_channel_map corresponding to a given \a pa_format_info. The
|
||||
* conversion for PCM formats is straight-forward. For non-PCM formats, if there is a fixed size-time conversion (i.e. all
|
||||
* IEC61937-encapsulated formats), a "fake" sample spec whose size-time conversion corresponds to this format is provided and
|
||||
* the channel map argument is ignored. For formats with variable size-time conversion, this function will fail. 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);
|
||||
|
||||
/** Represents the type of value type of a property on a \ref pa_format_info. \since 2.0 */
|
||||
|
|
|
|||
|
|
@ -304,7 +304,6 @@ 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_format_info_free2(pa_format_info *f, void *userdata);
|
||||
int 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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue