audio/pipewire: Add bps to pw format helper

This commit is contained in:
Martin Piatka
2023-05-30 15:34:08 +02:00
parent c28a770bfb
commit e064f0e40b
2 changed files with 13 additions and 18 deletions

View File

@@ -130,6 +130,18 @@ bool initialize_pw_common(pipewire_state_common& s);
std::vector<Pipewire_device> get_pw_device_list();
void print_devices(std::string_view media_class);
inline spa_audio_format get_pw_format_from_bps(unsigned bps){
spa_audio_format format_map[] = {
SPA_AUDIO_FORMAT_UNKNOWN,
SPA_AUDIO_FORMAT_S8,
SPA_AUDIO_FORMAT_S16,
SPA_AUDIO_FORMAT_S24,
SPA_AUDIO_FORMAT_S32,
};
return bps < std::size(format_map) ? format_map[bps] : SPA_AUDIO_FORMAT_UNKNOWN;
}
#if !PW_CHECK_VERSION(0, 3, 64)
# define STREAM_TARGET_PROPERTY_KEY PW_KEY_NODE_TARGET
#else

View File

@@ -237,24 +237,7 @@ static int audio_play_pw_reconfigure(void *state, struct audio_desc desc){
unsigned rate = desc.sample_rate;
unsigned quant = 128;
spa_audio_format format = SPA_AUDIO_FORMAT_UNKNOWN;
switch(desc.bps){
case 1:
format = SPA_AUDIO_FORMAT_S8;
break;
case 2:
format = SPA_AUDIO_FORMAT_S16;
break;
case 3:
format = SPA_AUDIO_FORMAT_S24;
break;
case 4:
format = SPA_AUDIO_FORMAT_S32;
break;
default:
break;
}
spa_audio_format format = get_pw_format_from_bps(desc.bps);
auto props = pw_properties_new(
PW_KEY_MEDIA_TYPE, "Audio",