mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	media-session: add option to enable acp device
This commit is contained in:
		
							parent
							
								
									1612f5e4d2
								
							
						
					
					
						commit
						0bbc25e3e2
					
				
					 2 changed files with 36 additions and 13 deletions
				
			
		| 
						 | 
					@ -115,6 +115,8 @@ struct impl {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct spa_source *jack_timeout;
 | 
						struct spa_source *jack_timeout;
 | 
				
			||||||
	struct pw_proxy *jack_device;
 | 
						struct pw_proxy *jack_device;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned int use_acp:1;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#undef NAME
 | 
					#undef NAME
 | 
				
			||||||
| 
						 | 
					@ -455,9 +457,13 @@ static int update_device_props(struct device *device)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void set_profile(struct device *device, int index)
 | 
					static void set_profile(struct device *device, int index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct impl *impl = device->impl;
 | 
				
			||||||
	char buf[1024];
 | 
						char buf[1024];
 | 
				
			||||||
	struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
 | 
						struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (impl->use_acp)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_log_debug("%p: set profile %d id:%d", device, index, device->device_id);
 | 
						pw_log_debug("%p: set profile %d id:%d", device, index, device->device_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (device->device_id != 0) {
 | 
						if (device->device_id != 0) {
 | 
				
			||||||
| 
						 | 
					@ -670,7 +676,7 @@ static struct device *alsa_create_device(struct impl *impl, uint32_t id,
 | 
				
			||||||
	struct spa_handle *handle;
 | 
						struct spa_handle *handle;
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
	void *iface;
 | 
						void *iface;
 | 
				
			||||||
	const char *card;
 | 
						const char *card, *factory_name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_log_debug("new device %u", id);
 | 
						pw_log_debug("new device %u", id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -679,9 +685,13 @@ static struct device *alsa_create_device(struct impl *impl, uint32_t id,
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (impl->use_acp)
 | 
				
			||||||
 | 
							factory_name = SPA_NAME_API_ALSA_ACP_DEVICE;
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							factory_name = info->factory_name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	handle = pw_context_load_spa_handle(context,
 | 
						handle = pw_context_load_spa_handle(context,
 | 
				
			||||||
			info->factory_name,
 | 
								factory_name, info->props);
 | 
				
			||||||
			info->props);
 | 
					 | 
				
			||||||
	if (handle == NULL) {
 | 
						if (handle == NULL) {
 | 
				
			||||||
		res = -errno;
 | 
							res = -errno;
 | 
				
			||||||
		pw_log_error("can't make factory instance: %m");
 | 
							pw_log_error("can't make factory instance: %m");
 | 
				
			||||||
| 
						 | 
					@ -834,6 +844,7 @@ int sm_alsa_monitor_start(struct sm_media_session *session)
 | 
				
			||||||
	struct pw_context *context = session->context;
 | 
						struct pw_context *context = session->context;
 | 
				
			||||||
	struct impl *impl;
 | 
						struct impl *impl;
 | 
				
			||||||
	void *iface;
 | 
						void *iface;
 | 
				
			||||||
 | 
						const char *str;
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl = calloc(1, sizeof(struct impl));
 | 
						impl = calloc(1, sizeof(struct impl));
 | 
				
			||||||
| 
						 | 
					@ -842,6 +853,9 @@ int sm_alsa_monitor_start(struct sm_media_session *session)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl->session = session;
 | 
						impl->session = session;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ((str = pw_properties_get(session->props, "alsa.use-acp")) != NULL)
 | 
				
			||||||
 | 
							impl->use_acp = pw_properties_parse_bool(str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (session->dbus_connection)
 | 
						if (session->dbus_connection)
 | 
				
			||||||
		impl->conn = spa_dbus_connection_get(session->dbus_connection);
 | 
							impl->conn = spa_dbus_connection_get(session->dbus_connection);
 | 
				
			||||||
	if (impl->conn == NULL)
 | 
						if (impl->conn == NULL)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1735,16 +1735,18 @@ static const struct {
 | 
				
			||||||
	const char *name;
 | 
						const char *name;
 | 
				
			||||||
	const char *desc;
 | 
						const char *desc;
 | 
				
			||||||
	int (*start)(struct sm_media_session *sess);
 | 
						int (*start)(struct sm_media_session *sess);
 | 
				
			||||||
 | 
						const char *props;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} modules[] = {
 | 
					} modules[] = {
 | 
				
			||||||
	{ "alsa-seq", "alsa seq midi support", sm_alsa_midi_start },
 | 
						{ "alsa-seq", "alsa seq midi support", sm_alsa_midi_start, NULL },
 | 
				
			||||||
	{ "alsa-pcm", "alsa pcm udev detection", sm_alsa_monitor_start },
 | 
						{ "alsa-pcm", "alsa pcm udev detection", sm_alsa_monitor_start, NULL },
 | 
				
			||||||
	{ "v4l2", "video for linux udev detection", sm_v4l2_monitor_start },
 | 
						{ "alsa-acp", "alsa card profile udev detection", sm_alsa_monitor_start, "alsa.use-acp=true" },
 | 
				
			||||||
	{ "libcamera", "libcamera udev detection", sm_libcamera_monitor_start },
 | 
						{ "v4l2", "video for linux udev detection", sm_v4l2_monitor_start, NULL },
 | 
				
			||||||
	{ "bluez5", "bluetooth support", sm_bluez5_monitor_start },
 | 
						{ "libcamera", "libcamera udev detection", sm_libcamera_monitor_start, NULL },
 | 
				
			||||||
	{ "metadata", "export metadata API", sm_metadata_start },
 | 
						{ "bluez5", "bluetooth support", sm_bluez5_monitor_start, NULL },
 | 
				
			||||||
	{ "suspend-node", "suspend inactive nodes", sm_suspend_node_start },
 | 
						{ "metadata", "export metadata API", sm_metadata_start, NULL },
 | 
				
			||||||
	{ "policy-node", "configure and link nodes", sm_policy_node_start },
 | 
						{ "suspend-node", "suspend inactive nodes", sm_suspend_node_start, NULL },
 | 
				
			||||||
 | 
						{ "policy-node", "configure and link nodes", sm_policy_node_start, NULL },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int opt_contains(const char *opt, const char *val)
 | 
					static int opt_contains(const char *opt, const char *val)
 | 
				
			||||||
| 
						 | 
					@ -1833,9 +1835,8 @@ int main(int argc, char *argv[])
 | 
				
			||||||
	if (impl.this.props == NULL)
 | 
						if (impl.this.props == NULL)
 | 
				
			||||||
		return -1;
 | 
							return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_dict_for_each(item, &impl.this.props->dict) {
 | 
						spa_dict_for_each(item, &impl.this.props->dict)
 | 
				
			||||||
		pw_log_info("  '%s' = '%s'", item->key, item->value);
 | 
							pw_log_info("  '%s' = '%s'", item->key, item->value);
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	impl.loop = pw_main_loop_new(NULL);
 | 
						impl.loop = pw_main_loop_new(NULL);
 | 
				
			||||||
	if (impl.loop == NULL)
 | 
						if (impl.loop == NULL)
 | 
				
			||||||
| 
						 | 
					@ -1882,6 +1883,14 @@ int main(int argc, char *argv[])
 | 
				
			||||||
		const char *name = modules[i].name;
 | 
							const char *name = modules[i].name;
 | 
				
			||||||
		if (opt_contains(opt_enabled, name) &&
 | 
							if (opt_contains(opt_enabled, name) &&
 | 
				
			||||||
		    !opt_contains(opt_disabled, name)) {
 | 
							    !opt_contains(opt_disabled, name)) {
 | 
				
			||||||
 | 
								if (modules[i].props) {
 | 
				
			||||||
 | 
									struct pw_properties *props;
 | 
				
			||||||
 | 
									props = pw_properties_new_string(modules[i].props);
 | 
				
			||||||
 | 
									if (props) {
 | 
				
			||||||
 | 
										pw_properties_update(impl.this.props, &props->dict);
 | 
				
			||||||
 | 
										pw_properties_free(props);
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			pw_log_info("enable: %s", name);
 | 
								pw_log_info("enable: %s", name);
 | 
				
			||||||
			modules[i].start(&impl.this);
 | 
								modules[i].start(&impl.this);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue