mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
alsa: make it possible to fix format
This commit is contained in:
parent
7d73f0b8d0
commit
7768a87a0b
5 changed files with 22 additions and 2 deletions
|
|
@ -219,6 +219,8 @@ struct spa_audio_info_raw {
|
|||
|
||||
#define SPA_AUDIO_INFO_RAW_INIT(...) (struct spa_audio_info_raw) { __VA_ARGS__ }
|
||||
|
||||
#define SPA_KEY_AUDIO_FORMAT "audio.format" /**< an audio format as string,
|
||||
* Ex. "S16LE" */
|
||||
#define SPA_KEY_AUDIO_CHANNEL "audio.channel" /**< an audio channel as string,
|
||||
* Ex. "FL" */
|
||||
#define SPA_KEY_AUDIO_CHANNELS "audio.channels" /**< an audio channel count as int */
|
||||
|
|
|
|||
|
|
@ -781,6 +781,8 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->default_channels = atoi(info->items[i].value);
|
||||
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_RATE)) {
|
||||
this->default_rate = atoi(info->items[i].value);
|
||||
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_FORMAT)) {
|
||||
this->default_format = spa_alsa_format_from_name(info->items[i].value, 128);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -802,6 +802,8 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->default_channels = atoi(info->items[i].value);
|
||||
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_RATE)) {
|
||||
this->default_rate = atoi(info->items[i].value);
|
||||
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_FORMAT)) {
|
||||
this->default_format = spa_alsa_format_from_name(info->items[i].value, 128);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -325,13 +325,15 @@ spa_alsa_enum_format(struct state *state, int seq, uint32_t start, uint32_t num,
|
|||
const struct format_info *fi = &format_info[i];
|
||||
|
||||
if (snd_pcm_format_mask_test(fmask, fi->format)) {
|
||||
if (snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_INTERLEAVED)) {
|
||||
if (snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_INTERLEAVED) &&
|
||||
(state->default_format == 0 || state->default_format == fi->spa_format)) {
|
||||
if (j++ == 0)
|
||||
spa_pod_builder_id(&b, fi->spa_format);
|
||||
spa_pod_builder_id(&b, fi->spa_format);
|
||||
}
|
||||
if (snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_NONINTERLEAVED) &&
|
||||
fi->spa_pformat != SPA_AUDIO_FORMAT_UNKNOWN) {
|
||||
fi->spa_pformat != SPA_AUDIO_FORMAT_UNKNOWN &&
|
||||
(state->default_format == 0 || state->default_format == fi->spa_pformat)) {
|
||||
if (j++ == 0)
|
||||
spa_pod_builder_id(&b, fi->spa_pformat);
|
||||
spa_pod_builder_id(&b, fi->spa_pformat);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ extern "C" {
|
|||
#include <spa/node/node.h>
|
||||
#include <spa/node/utils.h>
|
||||
#include <spa/node/io.h>
|
||||
#include <spa/debug/types.h>
|
||||
#include <spa/param/param.h>
|
||||
#include <spa/param/audio/format-utils.h>
|
||||
|
||||
|
|
@ -105,6 +106,7 @@ struct state {
|
|||
bool have_format;
|
||||
struct spa_audio_info current_format;
|
||||
|
||||
uint32_t default_format;
|
||||
unsigned int default_channels;
|
||||
unsigned int default_rate;
|
||||
|
||||
|
|
@ -182,6 +184,16 @@ int spa_alsa_read(struct state *state, snd_pcm_uframes_t silence);
|
|||
|
||||
void spa_alsa_recycle_buffer(struct state *state, uint32_t buffer_id);
|
||||
|
||||
static inline uint32_t spa_alsa_format_from_name(const char *name, size_t len)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; spa_type_audio_format[i].name; i++) {
|
||||
if (strncmp(name, spa_debug_type_short_name(spa_type_audio_format[i].name), len) == 0)
|
||||
return spa_type_audio_format[i].type;
|
||||
}
|
||||
return SPA_AUDIO_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue