mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	Parse format param and store in node
This commit is contained in:
		
							parent
							
								
									0d6bbaa7e1
								
							
						
					
					
						commit
						18b4aee677
					
				
					 4 changed files with 187 additions and 165 deletions
				
			
		| 
						 | 
					@ -806,24 +806,21 @@ static void node_event_info(void *object, const struct pw_node_info *info)
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		g->node_info.profile_device_id = SPA_ID_INVALID;
 | 
							g->node_info.profile_device_id = SPA_ID_INVALID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (info->change_mask & PW_NODE_CHANGE_MASK_PARAMS && !g->subscribed) {
 | 
						if (info->change_mask & PW_NODE_CHANGE_MASK_PARAMS) {
 | 
				
			||||||
		uint32_t subscribed[32], n_subscribed = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		for (i = 0; i < info->n_params; i++) {
 | 
							for (i = 0; i < info->n_params; i++) {
 | 
				
			||||||
 | 
								if (!(info->params[i].flags & SPA_PARAM_INFO_READ))
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			switch (info->params[i].id) {
 | 
								switch (info->params[i].id) {
 | 
				
			||||||
			case SPA_PARAM_EnumFormat:
 | 
					 | 
				
			||||||
			case SPA_PARAM_Props:
 | 
								case SPA_PARAM_Props:
 | 
				
			||||||
				subscribed[n_subscribed++] = info->params[i].id;
 | 
								case SPA_PARAM_Format:
 | 
				
			||||||
 | 
									pw_device_enum_params((struct pw_device*)g->proxy,
 | 
				
			||||||
 | 
										0, info->params[i].id, 0, -1, NULL);
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (n_subscribed > 0) {
 | 
					 | 
				
			||||||
			pw_node_subscribe_params((struct pw_node*)g->proxy,
 | 
					 | 
				
			||||||
					subscribed, n_subscribed);
 | 
					 | 
				
			||||||
			g->subscribed = true;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	global_sync(g);
 | 
						global_sync(g);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -840,6 +837,9 @@ static void node_event_param(void *object, int seq,
 | 
				
			||||||
		if (!SPA_FLAG_IS_SET(g->node_info.flags, NODE_FLAG_DEVICE_VOLUME | NODE_FLAG_DEVICE_MUTE))
 | 
							if (!SPA_FLAG_IS_SET(g->node_info.flags, NODE_FLAG_DEVICE_VOLUME | NODE_FLAG_DEVICE_MUTE))
 | 
				
			||||||
			parse_props(g, param, false);
 | 
								parse_props(g, param, false);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case SPA_PARAM_Format:
 | 
				
			||||||
 | 
							pa_format_parse_param(param, &g->node_info.sample_spec, &g->node_info.channel_map);
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
	default:
 | 
						default:
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,118 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "internal.h"
 | 
					#include "internal.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const uint32_t audio_formats[] = {
 | 
				
			||||||
 | 
						[PA_SAMPLE_U8] = SPA_AUDIO_FORMAT_U8,
 | 
				
			||||||
 | 
						[PA_SAMPLE_ALAW] = SPA_AUDIO_FORMAT_UNKNOWN,
 | 
				
			||||||
 | 
						[PA_SAMPLE_ULAW] = SPA_AUDIO_FORMAT_UNKNOWN,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S16NE] = SPA_AUDIO_FORMAT_S16,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S16RE] = SPA_AUDIO_FORMAT_S16_OE,
 | 
				
			||||||
 | 
						[PA_SAMPLE_FLOAT32NE] = SPA_AUDIO_FORMAT_F32,
 | 
				
			||||||
 | 
						[PA_SAMPLE_FLOAT32RE] = SPA_AUDIO_FORMAT_F32_OE,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S32NE] = SPA_AUDIO_FORMAT_S32,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S32RE] = SPA_AUDIO_FORMAT_S32_OE,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S24NE] = SPA_AUDIO_FORMAT_S24,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S24RE] = SPA_AUDIO_FORMAT_S24_OE,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S24_32NE] = SPA_AUDIO_FORMAT_S24_32,
 | 
				
			||||||
 | 
						[PA_SAMPLE_S24_32RE] = SPA_AUDIO_FORMAT_S24_32_OE,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline uint32_t format_pa2id(pa_sample_format_t format)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (format < 0 || (size_t)format >= SPA_N_ELEMENTS(audio_formats))
 | 
				
			||||||
 | 
							return SPA_AUDIO_FORMAT_UNKNOWN;
 | 
				
			||||||
 | 
						return audio_formats[format];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline pa_sample_format_t format_id2pa(uint32_t id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						size_t i;
 | 
				
			||||||
 | 
						for (i = 0; i < SPA_N_ELEMENTS(audio_formats); i++) {
 | 
				
			||||||
 | 
							if (id == audio_formats[i])
 | 
				
			||||||
 | 
								return i;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return PA_SAMPLE_INVALID;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const uint32_t audio_channels[] = {
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_MONO] = SPA_AUDIO_CHANNEL_MONO,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_FRONT_LEFT] = SPA_AUDIO_CHANNEL_FL,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_FRONT_RIGHT] = SPA_AUDIO_CHANNEL_FR,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_FRONT_CENTER] = SPA_AUDIO_CHANNEL_FC,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_REAR_CENTER] = SPA_AUDIO_CHANNEL_RC,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_REAR_LEFT] = SPA_AUDIO_CHANNEL_RL,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_REAR_RIGHT] = SPA_AUDIO_CHANNEL_RR,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_LFE] = SPA_AUDIO_CHANNEL_LFE,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = SPA_AUDIO_CHANNEL_FLC,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = SPA_AUDIO_CHANNEL_FRC,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_SIDE_LEFT] = SPA_AUDIO_CHANNEL_SL,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_SIDE_RIGHT] = SPA_AUDIO_CHANNEL_SR,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX0] = SPA_AUDIO_CHANNEL_CUSTOM_START + 1,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX1] = SPA_AUDIO_CHANNEL_CUSTOM_START + 2,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX2] = SPA_AUDIO_CHANNEL_CUSTOM_START + 3,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX3] = SPA_AUDIO_CHANNEL_CUSTOM_START + 4,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX4] = SPA_AUDIO_CHANNEL_CUSTOM_START + 5,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX5] = SPA_AUDIO_CHANNEL_CUSTOM_START + 6,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX6] = SPA_AUDIO_CHANNEL_CUSTOM_START + 7,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX7] = SPA_AUDIO_CHANNEL_CUSTOM_START + 8,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX8] = SPA_AUDIO_CHANNEL_CUSTOM_START + 9,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX9] = SPA_AUDIO_CHANNEL_CUSTOM_START + 10,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX10] = SPA_AUDIO_CHANNEL_CUSTOM_START + 11,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX11] = SPA_AUDIO_CHANNEL_CUSTOM_START + 12,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX12] = SPA_AUDIO_CHANNEL_CUSTOM_START + 13,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX13] = SPA_AUDIO_CHANNEL_CUSTOM_START + 14,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX14] = SPA_AUDIO_CHANNEL_CUSTOM_START + 15,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX15] = SPA_AUDIO_CHANNEL_CUSTOM_START + 16,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX16] = SPA_AUDIO_CHANNEL_CUSTOM_START + 17,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX17] = SPA_AUDIO_CHANNEL_CUSTOM_START + 18,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX18] = SPA_AUDIO_CHANNEL_CUSTOM_START + 19,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX19] = SPA_AUDIO_CHANNEL_CUSTOM_START + 20,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX20] = SPA_AUDIO_CHANNEL_CUSTOM_START + 21,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX21] = SPA_AUDIO_CHANNEL_CUSTOM_START + 22,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX22] = SPA_AUDIO_CHANNEL_CUSTOM_START + 23,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX23] = SPA_AUDIO_CHANNEL_CUSTOM_START + 24,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX24] = SPA_AUDIO_CHANNEL_CUSTOM_START + 25,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX25] = SPA_AUDIO_CHANNEL_CUSTOM_START + 26,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX26] = SPA_AUDIO_CHANNEL_CUSTOM_START + 27,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX27] = SPA_AUDIO_CHANNEL_CUSTOM_START + 28,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX28] = SPA_AUDIO_CHANNEL_CUSTOM_START + 29,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX29] = SPA_AUDIO_CHANNEL_CUSTOM_START + 30,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX30] = SPA_AUDIO_CHANNEL_CUSTOM_START + 31,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_AUX31] = SPA_AUDIO_CHANNEL_CUSTOM_START + 32,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_TOP_CENTER] = SPA_AUDIO_CHANNEL_TC,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = SPA_AUDIO_CHANNEL_TFL,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = SPA_AUDIO_CHANNEL_TFR,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = SPA_AUDIO_CHANNEL_TFC,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_TOP_REAR_LEFT] = SPA_AUDIO_CHANNEL_TRL,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = SPA_AUDIO_CHANNEL_TRR,
 | 
				
			||||||
 | 
						[PA_CHANNEL_POSITION_TOP_REAR_CENTER] = SPA_AUDIO_CHANNEL_TRC,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline uint32_t channel_pa2id(pa_channel_position_t channel)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (channel < 0 || (size_t)channel >= SPA_N_ELEMENTS(audio_channels))
 | 
				
			||||||
 | 
							return SPA_AUDIO_CHANNEL_UNKNOWN;
 | 
				
			||||||
 | 
						return audio_channels[channel];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline pa_channel_position_t channel_id2pa(uint32_t id)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						size_t i;
 | 
				
			||||||
 | 
						for (i = 0; i < SPA_N_ELEMENTS(audio_channels); i++) {
 | 
				
			||||||
 | 
							if (id == audio_channels[i])
 | 
				
			||||||
 | 
								return i;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return PA_CHANNEL_POSITION_INVALID;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SPA_EXPORT
 | 
					SPA_EXPORT
 | 
				
			||||||
int pa_format_info_get_sample_format(const pa_format_info *f, pa_sample_format_t *sf) {
 | 
					int pa_format_info_get_sample_format(const pa_format_info *f, pa_sample_format_t *sf) {
 | 
				
			||||||
    int r;
 | 
					    int r;
 | 
				
			||||||
| 
						 | 
					@ -246,3 +358,54 @@ int pa_format_info_to_sample_spec_fake(const pa_format_info *f, pa_sample_spec *
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int pa_format_parse_param(const struct spa_pod *param, pa_sample_spec *spec, pa_channel_map *map)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct spa_audio_info info = { 0 };
 | 
				
			||||||
 | 
						uint32_t i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (param == NULL)
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spa_format_parse(param, &info.media_type, &info.media_subtype);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (info.media_type != SPA_MEDIA_TYPE_audio ||
 | 
				
			||||||
 | 
						    info.media_subtype != SPA_MEDIA_SUBTYPE_raw ||
 | 
				
			||||||
 | 
						    spa_format_audio_raw_parse(param, &info.info.raw) < 0 ||
 | 
				
			||||||
 | 
						    !SPA_AUDIO_FORMAT_IS_INTERLEAVED(info.info.raw.format)) {
 | 
				
			||||||
 | 
							return -ENOTSUP;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spec->format = format_id2pa(info.info.raw.format);
 | 
				
			||||||
 | 
						if (spec->format == PA_SAMPLE_INVALID)
 | 
				
			||||||
 | 
							return -ENOTSUP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spec->rate = info.info.raw.rate;
 | 
				
			||||||
 | 
						spec->channels = info.info.raw.channels;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pa_channel_map_init(map);
 | 
				
			||||||
 | 
						map->channels = info.info.raw.channels;
 | 
				
			||||||
 | 
						for (i = 0; i < info.info.raw.channels; i++)
 | 
				
			||||||
 | 
							map->map[i] = channel_id2pa(info.info.raw.position[i]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!pa_channel_map_valid(map))
 | 
				
			||||||
 | 
							pa_channel_map_init_auto(map, info.info.raw.channels, PA_CHANNEL_MAP_DEFAULT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const struct spa_pod *pa_format_build_param(struct spa_pod_builder *b,
 | 
				
			||||||
 | 
							uint32_t id, pa_sample_spec *spec, pa_channel_map *map)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct spa_audio_info_raw info;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						info = SPA_AUDIO_INFO_RAW_INIT( .format = format_pa2id(spec->format),
 | 
				
			||||||
 | 
							                .channels = spec->channels,
 | 
				
			||||||
 | 
							                .rate = spec->rate);
 | 
				
			||||||
 | 
						if (map) {
 | 
				
			||||||
 | 
							int i;
 | 
				
			||||||
 | 
							for (i = 0; i < map->channels; i++)
 | 
				
			||||||
 | 
								info.position[i] = channel_pa2id(map->map[i]);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return spa_format_audio_raw_build(b, id, &info);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -254,7 +254,6 @@ struct global {
 | 
				
			||||||
	int priority_master;
 | 
						int priority_master;
 | 
				
			||||||
	int pending_seq;
 | 
						int pending_seq;
 | 
				
			||||||
	int init:1;
 | 
						int init:1;
 | 
				
			||||||
	int subscribed:1;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void *info;
 | 
						void *info;
 | 
				
			||||||
	struct global_info *ginfo;
 | 
						struct global_info *ginfo;
 | 
				
			||||||
| 
						 | 
					@ -280,6 +279,8 @@ struct global {
 | 
				
			||||||
			uint32_t flags;
 | 
								uint32_t flags;
 | 
				
			||||||
			float volume;
 | 
								float volume;
 | 
				
			||||||
			bool mute;
 | 
								bool mute;
 | 
				
			||||||
 | 
								pa_sample_spec sample_spec;
 | 
				
			||||||
 | 
								pa_channel_map channel_map;
 | 
				
			||||||
			uint32_t n_channel_volumes;
 | 
								uint32_t n_channel_volumes;
 | 
				
			||||||
			float channel_volumes[SPA_AUDIO_MAX_CHANNELS];
 | 
								float channel_volumes[SPA_AUDIO_MAX_CHANNELS];
 | 
				
			||||||
			uint32_t device_id;		/* id of device (card) */
 | 
								uint32_t device_id;		/* id of device (card) */
 | 
				
			||||||
| 
						 | 
					@ -490,6 +491,11 @@ int pa_metadata_update(struct global *global, uint32_t subject, const char *key,
 | 
				
			||||||
int pa_metadata_get(struct global *global, uint32_t subject, const char *key,
 | 
					int pa_metadata_get(struct global *global, uint32_t subject, const char *key,
 | 
				
			||||||
                        const char **type, const char **value);
 | 
					                        const char **type, const char **value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int pa_format_parse_param(const struct spa_pod *param,
 | 
				
			||||||
 | 
							pa_sample_spec *spec, pa_channel_map *map);
 | 
				
			||||||
 | 
					const struct spa_pod *pa_format_build_param(struct spa_pod_builder *b,
 | 
				
			||||||
 | 
							uint32_t id, pa_sample_spec *spec, pa_channel_map *map);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,117 +38,6 @@
 | 
				
			||||||
#define MAX_SIZE	(4*1024*1024)
 | 
					#define MAX_SIZE	(4*1024*1024)
 | 
				
			||||||
#define BLOCK_SIZE	(64*1024)
 | 
					#define BLOCK_SIZE	(64*1024)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const uint32_t audio_formats[] = {
 | 
					 | 
				
			||||||
	[PA_SAMPLE_U8] = SPA_AUDIO_FORMAT_U8,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_ALAW] = SPA_AUDIO_FORMAT_UNKNOWN,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_ULAW] = SPA_AUDIO_FORMAT_UNKNOWN,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S16NE] = SPA_AUDIO_FORMAT_S16,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S16RE] = SPA_AUDIO_FORMAT_S16_OE,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_FLOAT32NE] = SPA_AUDIO_FORMAT_F32,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_FLOAT32RE] = SPA_AUDIO_FORMAT_F32_OE,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S32NE] = SPA_AUDIO_FORMAT_S32,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S32RE] = SPA_AUDIO_FORMAT_S32_OE,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S24NE] = SPA_AUDIO_FORMAT_S24,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S24RE] = SPA_AUDIO_FORMAT_S24_OE,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S24_32NE] = SPA_AUDIO_FORMAT_S24_32,
 | 
					 | 
				
			||||||
	[PA_SAMPLE_S24_32RE] = SPA_AUDIO_FORMAT_S24_32_OE,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static inline uint32_t format_pa2id(pa_stream *s, pa_sample_format_t format)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if (format < 0 || (size_t)format >= SPA_N_ELEMENTS(audio_formats))
 | 
					 | 
				
			||||||
		return SPA_AUDIO_FORMAT_UNKNOWN;
 | 
					 | 
				
			||||||
	return audio_formats[format];
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static inline pa_sample_format_t format_id2pa(pa_stream *s, uint32_t id)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	size_t i;
 | 
					 | 
				
			||||||
	for (i = 0; i < SPA_N_ELEMENTS(audio_formats); i++) {
 | 
					 | 
				
			||||||
		if (id == audio_formats[i])
 | 
					 | 
				
			||||||
			return i;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return PA_SAMPLE_INVALID;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static const uint32_t audio_channels[] = {
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_MONO] = SPA_AUDIO_CHANNEL_MONO,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_FRONT_LEFT] = SPA_AUDIO_CHANNEL_FL,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_FRONT_RIGHT] = SPA_AUDIO_CHANNEL_FR,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_FRONT_CENTER] = SPA_AUDIO_CHANNEL_FC,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_REAR_CENTER] = SPA_AUDIO_CHANNEL_RC,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_REAR_LEFT] = SPA_AUDIO_CHANNEL_RL,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_REAR_RIGHT] = SPA_AUDIO_CHANNEL_RR,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_LFE] = SPA_AUDIO_CHANNEL_LFE,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER] = SPA_AUDIO_CHANNEL_FLC,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER] = SPA_AUDIO_CHANNEL_FRC,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_SIDE_LEFT] = SPA_AUDIO_CHANNEL_SL,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_SIDE_RIGHT] = SPA_AUDIO_CHANNEL_SR,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX0] = SPA_AUDIO_CHANNEL_CUSTOM_START + 1,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX1] = SPA_AUDIO_CHANNEL_CUSTOM_START + 2,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX2] = SPA_AUDIO_CHANNEL_CUSTOM_START + 3,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX3] = SPA_AUDIO_CHANNEL_CUSTOM_START + 4,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX4] = SPA_AUDIO_CHANNEL_CUSTOM_START + 5,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX5] = SPA_AUDIO_CHANNEL_CUSTOM_START + 6,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX6] = SPA_AUDIO_CHANNEL_CUSTOM_START + 7,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX7] = SPA_AUDIO_CHANNEL_CUSTOM_START + 8,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX8] = SPA_AUDIO_CHANNEL_CUSTOM_START + 9,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX9] = SPA_AUDIO_CHANNEL_CUSTOM_START + 10,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX10] = SPA_AUDIO_CHANNEL_CUSTOM_START + 11,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX11] = SPA_AUDIO_CHANNEL_CUSTOM_START + 12,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX12] = SPA_AUDIO_CHANNEL_CUSTOM_START + 13,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX13] = SPA_AUDIO_CHANNEL_CUSTOM_START + 14,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX14] = SPA_AUDIO_CHANNEL_CUSTOM_START + 15,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX15] = SPA_AUDIO_CHANNEL_CUSTOM_START + 16,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX16] = SPA_AUDIO_CHANNEL_CUSTOM_START + 17,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX17] = SPA_AUDIO_CHANNEL_CUSTOM_START + 18,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX18] = SPA_AUDIO_CHANNEL_CUSTOM_START + 19,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX19] = SPA_AUDIO_CHANNEL_CUSTOM_START + 20,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX20] = SPA_AUDIO_CHANNEL_CUSTOM_START + 21,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX21] = SPA_AUDIO_CHANNEL_CUSTOM_START + 22,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX22] = SPA_AUDIO_CHANNEL_CUSTOM_START + 23,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX23] = SPA_AUDIO_CHANNEL_CUSTOM_START + 24,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX24] = SPA_AUDIO_CHANNEL_CUSTOM_START + 25,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX25] = SPA_AUDIO_CHANNEL_CUSTOM_START + 26,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX26] = SPA_AUDIO_CHANNEL_CUSTOM_START + 27,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX27] = SPA_AUDIO_CHANNEL_CUSTOM_START + 28,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX28] = SPA_AUDIO_CHANNEL_CUSTOM_START + 29,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX29] = SPA_AUDIO_CHANNEL_CUSTOM_START + 30,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX30] = SPA_AUDIO_CHANNEL_CUSTOM_START + 31,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_AUX31] = SPA_AUDIO_CHANNEL_CUSTOM_START + 32,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_TOP_CENTER] = SPA_AUDIO_CHANNEL_TC,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_TOP_FRONT_LEFT] = SPA_AUDIO_CHANNEL_TFL,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_TOP_FRONT_RIGHT] = SPA_AUDIO_CHANNEL_TFR,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_TOP_FRONT_CENTER] = SPA_AUDIO_CHANNEL_TFC,
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_TOP_REAR_LEFT] = SPA_AUDIO_CHANNEL_TRL,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_TOP_REAR_RIGHT] = SPA_AUDIO_CHANNEL_TRR,
 | 
					 | 
				
			||||||
	[PA_CHANNEL_POSITION_TOP_REAR_CENTER] = SPA_AUDIO_CHANNEL_TRC,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static inline uint32_t channel_pa2id(pa_stream *s, pa_channel_position_t channel)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if (channel < 0 || (size_t)channel >= SPA_N_ELEMENTS(audio_channels))
 | 
					 | 
				
			||||||
		return SPA_AUDIO_CHANNEL_UNKNOWN;
 | 
					 | 
				
			||||||
	return audio_channels[channel];
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static inline pa_channel_position_t channel_id2pa(pa_stream *s, uint32_t id)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	size_t i;
 | 
					 | 
				
			||||||
	for (i = 0; i < SPA_N_ELEMENTS(audio_channels); i++) {
 | 
					 | 
				
			||||||
		if (id == audio_channels[i])
 | 
					 | 
				
			||||||
			return i;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return PA_CHANNEL_POSITION_INVALID;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void dump_buffer_attr(pa_stream *s, pa_buffer_attr *attr)
 | 
					static void dump_buffer_attr(pa_stream *s, pa_buffer_attr *attr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -347,38 +236,16 @@ static void stream_param_changed(void *data, uint32_t id, const struct spa_pod *
 | 
				
			||||||
	uint32_t n_params = 0;
 | 
						uint32_t n_params = 0;
 | 
				
			||||||
        uint8_t buffer[4096];
 | 
					        uint8_t buffer[4096];
 | 
				
			||||||
        struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
 | 
					        struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
 | 
				
			||||||
	struct spa_audio_info info = { 0 };
 | 
						int res;
 | 
				
			||||||
	unsigned int i;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (param == NULL || id != SPA_PARAM_Format)
 | 
						if (param == NULL || id != SPA_PARAM_Format)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_format_parse(param, &info.media_type, &info.media_subtype);
 | 
						if ((res = pa_format_parse_param(param, &s->sample_spec, &s->channel_map)) < 0) {
 | 
				
			||||||
 | 
							pw_stream_set_error(s->stream, res, "unhandled format");
 | 
				
			||||||
	if (info.media_type != SPA_MEDIA_TYPE_audio ||
 | 
					 | 
				
			||||||
	    info.media_subtype != SPA_MEDIA_SUBTYPE_raw ||
 | 
					 | 
				
			||||||
	    spa_format_audio_raw_parse(param, &info.info.raw) < 0 ||
 | 
					 | 
				
			||||||
	    !SPA_AUDIO_FORMAT_IS_INTERLEAVED(info.info.raw.format)) {
 | 
					 | 
				
			||||||
		pw_stream_set_error(s->stream, -EINVAL, "unhandled format");
 | 
					 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	s->sample_spec.format = format_id2pa(s, info.info.raw.format);
 | 
					 | 
				
			||||||
	if (s->sample_spec.format == PA_SAMPLE_INVALID) {
 | 
					 | 
				
			||||||
		pw_stream_set_error(s->stream, -EINVAL, "invalid format");
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	s->sample_spec.rate = info.info.raw.rate;
 | 
					 | 
				
			||||||
	s->sample_spec.channels = info.info.raw.channels;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pa_channel_map_init(&s->channel_map);
 | 
					 | 
				
			||||||
	s->channel_map.channels = info.info.raw.channels;
 | 
					 | 
				
			||||||
	for (i = 0; i < info.info.raw.channels; i++)
 | 
					 | 
				
			||||||
		s->channel_map.map[i] = channel_id2pa(s, info.info.raw.position[i]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!pa_channel_map_valid(&s->channel_map))
 | 
					 | 
				
			||||||
		pa_channel_map_init_auto(&s->channel_map, info.info.raw.channels, PA_CHANNEL_MAP_DEFAULT);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (s->format)
 | 
						if (s->format)
 | 
				
			||||||
		pa_format_info_free(s->format);
 | 
							pa_format_info_free(s->format);
 | 
				
			||||||
	s->format = pa_format_info_from_sample_spec(&s->sample_spec, &s->channel_map);
 | 
						s->format = pa_format_info_from_sample_spec(&s->sample_spec, &s->channel_map);
 | 
				
			||||||
| 
						 | 
					@ -894,22 +761,6 @@ int pa_stream_is_corked(PA_CONST pa_stream *s)
 | 
				
			||||||
	return s->corked;
 | 
						return s->corked;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct spa_pod *get_param(pa_stream *s, pa_sample_spec *ss, pa_channel_map *map,
 | 
					 | 
				
			||||||
		struct spa_pod_builder *b)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct spa_audio_info_raw info;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	info = SPA_AUDIO_INFO_RAW_INIT( .format = format_pa2id(s, ss->format),
 | 
					 | 
				
			||||||
		                .channels = ss->channels,
 | 
					 | 
				
			||||||
		                .rate = ss->rate);
 | 
					 | 
				
			||||||
	if (map) {
 | 
					 | 
				
			||||||
		int i;
 | 
					 | 
				
			||||||
		for (i = 0; i < map->channels; i++)
 | 
					 | 
				
			||||||
			info.position[i] = channel_pa2id(s, map->map[i]);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return spa_format_audio_raw_build(b, SPA_PARAM_EnumFormat, &info);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static int create_stream(pa_stream_direction_t direction,
 | 
					static int create_stream(pa_stream_direction_t direction,
 | 
				
			||||||
        pa_stream *s,
 | 
					        pa_stream *s,
 | 
				
			||||||
        const char *dev,
 | 
					        const char *dev,
 | 
				
			||||||
| 
						 | 
					@ -1006,7 +857,8 @@ static int create_stream(pa_stream_direction_t direction,
 | 
				
			||||||
	no_remix = (flags & PA_STREAM_NO_REMIX_CHANNELS);
 | 
						no_remix = (flags & PA_STREAM_NO_REMIX_CHANNELS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pa_sample_spec_valid(&s->sample_spec)) {
 | 
						if (pa_sample_spec_valid(&s->sample_spec)) {
 | 
				
			||||||
		params[n_params++] = get_param(s, &s->sample_spec, &s->channel_map, &b);
 | 
							params[n_params++] = pa_format_build_param(&b, SPA_PARAM_EnumFormat,
 | 
				
			||||||
 | 
									&s->sample_spec, &s->channel_map);
 | 
				
			||||||
		sample_rate = s->sample_spec.rate;
 | 
							sample_rate = s->sample_spec.rate;
 | 
				
			||||||
		stride = pa_frame_size(&s->sample_spec);
 | 
							stride = pa_frame_size(&s->sample_spec);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -1025,7 +877,8 @@ static int create_stream(pa_stream_direction_t direction,
 | 
				
			||||||
			if (pa_format_info_get_channel_map(s->req_formats[i], &chmap) < 0)
 | 
								if (pa_format_info_get_channel_map(s->req_formats[i], &chmap) < 0)
 | 
				
			||||||
				pa_channel_map_init_auto(&chmap, ss.channels, PA_CHANNEL_MAP_DEFAULT);
 | 
									pa_channel_map_init_auto(&chmap, ss.channels, PA_CHANNEL_MAP_DEFAULT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			params[n_params++] = get_param(s, &ss, &chmap, &b);
 | 
								params[n_params++] = pa_format_build_param(&b, SPA_PARAM_EnumFormat,
 | 
				
			||||||
 | 
										&ss, &chmap);
 | 
				
			||||||
			if (ss.rate > sample_rate) {
 | 
								if (ss.rate > sample_rate) {
 | 
				
			||||||
				sample_rate = ss.rate;
 | 
									sample_rate = ss.rate;
 | 
				
			||||||
				stride = pa_frame_size(&ss);
 | 
									stride = pa_frame_size(&ss);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue