| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | /* Spa ALSA Source
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-05 17:48:52 +01:00
										 |  |  |  * Copyright © 2018 Wim Taymans | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-05 17:48:52 +01:00
										 |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a | 
					
						
							|  |  |  |  * copy of this software and associated documentation files (the "Software"), | 
					
						
							|  |  |  |  * to deal in the Software without restriction, including without limitation | 
					
						
							|  |  |  |  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
					
						
							|  |  |  |  * and/or sell copies of the Software, and to permit persons to whom the | 
					
						
							|  |  |  |  * Software is furnished to do so, subject to the following conditions: | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-05 17:48:52 +01:00
										 |  |  |  * The above copyright notice and this permission notice (including the next | 
					
						
							|  |  |  |  * paragraph) shall be included in all copies or substantial portions of the | 
					
						
							|  |  |  |  * Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | 
					
						
							|  |  |  |  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
					
						
							|  |  |  |  * DEALINGS IN THE SOFTWARE. | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-23 09:25:51 +02:00
										 |  |  | #include <alsa/asoundlib.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-10 13:36:14 +01:00
										 |  |  | #include <spa/node/node.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | #include <spa/node/utils.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-18 10:10:58 +01:00
										 |  |  | #include <spa/node/keys.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-03 16:48:01 +02:00
										 |  |  | #include <spa/utils/keys.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-21 13:31:34 +02:00
										 |  |  | #include <spa/utils/names.h>
 | 
					
						
							| 
									
										
										
										
											2017-11-10 13:36:14 +01:00
										 |  |  | #include <spa/utils/list.h>
 | 
					
						
							| 
									
										
										
										
											2021-05-18 11:36:13 +10:00
										 |  |  | #include <spa/utils/string.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-03 16:48:01 +02:00
										 |  |  | #include <spa/monitor/device.h>
 | 
					
						
							| 
									
										
										
										
											2017-11-10 13:36:14 +01:00
										 |  |  | #include <spa/param/audio/format.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-13 17:17:23 +02:00
										 |  |  | #include <spa/pod/filter.h>
 | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 14:25:32 +10:00
										 |  |  | #include "alsa.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-23 20:51:34 +02:00
										 |  |  | #include "alsa-pcm.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | #define CHECK_PORT(this,d,p)    ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | static const char default_device[] = "hw:0"; | 
					
						
							| 
									
										
										
										
											2019-10-24 12:35:00 +02:00
										 |  |  | static const uint32_t default_min_latency = MIN_LATENCY; | 
					
						
							|  |  |  | static const uint32_t default_max_latency = MAX_LATENCY; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | static void reset_props(struct props *props) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	strncpy(props->device, default_device, 64); | 
					
						
							|  |  |  | 	props->min_latency = default_min_latency; | 
					
						
							| 
									
										
										
										
											2018-04-30 09:27:20 +02:00
										 |  |  | 	props->max_latency = default_max_latency; | 
					
						
							| 
									
										
										
										
											2020-09-14 20:15:48 +02:00
										 |  |  | 	props->use_chmap = DEFAULT_USE_CHMAP; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | static void emit_node_info(struct state *this, bool full) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	uint64_t old = full ? this->info.change_mask : 0; | 
					
						
							|  |  |  | 	if (full) | 
					
						
							|  |  |  | 		this->info.change_mask = this->info_all; | 
					
						
							|  |  |  | 	if (this->info.change_mask) { | 
					
						
							|  |  |  | 		struct spa_dict_item items[4]; | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 		uint32_t i, n_items = 0; | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 		char latency[64]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_API, "alsa"); | 
					
						
							|  |  |  | 		items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MEDIA_CLASS, "Audio/Source"); | 
					
						
							|  |  |  | 		items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_DRIVER, "true"); | 
					
						
							|  |  |  | 		if (this->have_format) { | 
					
						
							|  |  |  | 			snprintf(latency, sizeof(latency), "%lu/%d", this->buffer_frames / 4, this->rate); | 
					
						
							|  |  |  | 			items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_NODE_MAX_LATENCY, latency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this->info.props = &SPA_DICT_INIT(items, n_items); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 		if (this->info.change_mask & SPA_NODE_CHANGE_MASK_PARAMS) { | 
					
						
							|  |  |  | 			for (i = 0; i < this->info.n_params; i++) { | 
					
						
							|  |  |  | 				if (this->params[i].user > 0) { | 
					
						
							|  |  |  | 					this->params[i].flags ^= SPA_PARAM_INFO_SERIAL; | 
					
						
							|  |  |  | 					this->params[i].user = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 		spa_node_emit_info(&this->hooks, &this->info); | 
					
						
							|  |  |  | 		this->info.change_mask = old; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void emit_port_info(struct state *this, bool full) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	uint64_t old = full ? this->port_info.change_mask : 0; | 
					
						
							|  |  |  | 	if (full) | 
					
						
							|  |  |  | 		this->port_info.change_mask = this->port_info_all; | 
					
						
							|  |  |  | 	if (this->port_info.change_mask) { | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 		uint32_t i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (this->port_info.change_mask & SPA_PORT_CHANGE_MASK_PARAMS) { | 
					
						
							|  |  |  | 			for (i = 0; i < this->port_info.n_params; i++) { | 
					
						
							|  |  |  | 				if (this->port_params[i].user > 0) { | 
					
						
							|  |  |  | 					this->port_params[i].flags ^= SPA_PARAM_INFO_SERIAL; | 
					
						
							|  |  |  | 					this->port_params[i].user = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 		spa_node_emit_port_info(&this->hooks, | 
					
						
							|  |  |  | 				SPA_DIRECTION_OUTPUT, 0, &this->port_info); | 
					
						
							|  |  |  | 		this->port_info.change_mask = old; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_enum_params(void *object, int seq, | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 				 uint32_t id, uint32_t start, uint32_t num, | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 				 const struct spa_pod *filter) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 	struct spa_pod *param; | 
					
						
							| 
									
										
										
										
											2017-11-14 10:17:45 +01:00
										 |  |  | 	uint8_t buffer[1024]; | 
					
						
							|  |  |  | 	struct spa_pod_builder b = { 0 }; | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 	struct props *p; | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 	struct spa_result_node_params result; | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	uint32_t count = 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	spa_return_val_if_fail(num != 0, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 	p = &this->props; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 	result.id = id; | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	result.next = start; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  |       next: | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 	result.index = result.next++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 10:17:45 +01:00
										 |  |  | 	spa_pod_builder_init(&b, buffer, sizeof(buffer)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	switch (id) { | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_PropInfo: | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 		switch (result.index) { | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		case 0: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_device), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_name, SPA_POD_String("The ALSA device"), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_type, SPA_POD_Stringn(p->device, sizeof(p->device))); | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_deviceName), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_name, SPA_POD_String("The ALSA device name"), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_type, SPA_POD_Stringn(p->device_name, sizeof(p->device_name))); | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_cardName), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_name, SPA_POD_String("The ALSA card name"), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_type, SPA_POD_Stringn(p->card_name, sizeof(p->card_name))); | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case 3: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_minLatency), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_name, SPA_POD_String("The minimum latency"), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(p->min_latency, 1, INT32_MAX)); | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-04-30 09:27:20 +02:00
										 |  |  | 		case 4: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_maxLatency), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_name, SPA_POD_String("The maximum latency"), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Int(p->max_latency, 1, INT32_MAX)); | 
					
						
							| 
									
										
										
										
											2018-04-30 09:27:20 +02:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-09-14 20:15:48 +02:00
										 |  |  | 		case 5: | 
					
						
							|  |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							|  |  |  | 				SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_START_CUSTOM), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_name, SPA_POD_String("Use the driver channelmap"), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_type, SPA_POD_Bool(p->use_chmap)); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 		case 6: | 
					
						
							|  |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_PropInfo, id, | 
					
						
							|  |  |  | 				SPA_PROP_INFO_id,   SPA_POD_Id(SPA_PROP_latencyOffsetNsec), | 
					
						
							|  |  |  | 				SPA_PROP_INFO_name, SPA_POD_String("Latency offset (ns)"), | 
					
						
							| 
									
										
										
										
											2021-09-02 15:17:36 +02:00
										 |  |  | 				SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Long(0LL, 0LL, INT64_MAX)); | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_Props: | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 		switch (result.index) { | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		case 0: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_Props, id, | 
					
						
							| 
									
										
										
										
											2020-09-14 20:15:48 +02:00
										 |  |  | 				SPA_PROP_device,       SPA_POD_Stringn(p->device, sizeof(p->device)), | 
					
						
							|  |  |  | 				SPA_PROP_deviceName,   SPA_POD_Stringn(p->device_name, sizeof(p->device_name)), | 
					
						
							|  |  |  | 				SPA_PROP_cardName,     SPA_POD_Stringn(p->card_name, sizeof(p->card_name)), | 
					
						
							|  |  |  | 				SPA_PROP_minLatency,   SPA_POD_Int(p->min_latency), | 
					
						
							|  |  |  | 				SPA_PROP_maxLatency,   SPA_POD_Int(p->max_latency), | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 				SPA_PROP_START_CUSTOM, SPA_POD_Bool(p->use_chmap), | 
					
						
							|  |  |  | 				SPA_PROP_latencyOffsetNsec,   SPA_POD_Long(this->process_latency.ns)); | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-21 13:05:52 +02:00
										 |  |  | 	case SPA_PARAM_IO: | 
					
						
							|  |  |  | 		switch (result.index) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							|  |  |  | 				SPA_PARAM_IO_id,   SPA_POD_Id(SPA_IO_Clock), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_clock))); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							|  |  |  | 				SPA_PARAM_IO_id,   SPA_POD_Id(SPA_IO_Position), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_position))); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 	case SPA_PARAM_ProcessLatency: | 
					
						
							|  |  |  | 		switch (result.index) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			param = spa_process_latency_build(&b, id, &this->process_latency); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	if (spa_pod_filter(&b, &result.param, param, filter) < 0) | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 13:59:48 +02:00
										 |  |  | 	spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result); | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (++count != num) | 
					
						
							|  |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) | 
					
						
							| 
									
										
										
										
											2018-10-23 12:31:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2018-10-24 10:27:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2018-10-24 10:27:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch (id) { | 
					
						
							|  |  |  | 	case SPA_IO_Clock: | 
					
						
							| 
									
										
										
										
											2019-10-23 16:04:03 +02:00
										 |  |  | 		if (size > 0 && size < sizeof(struct spa_io_clock)) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2018-10-24 10:27:57 +02:00
										 |  |  | 		this->clock = data; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SPA_IO_Position: | 
					
						
							|  |  |  | 		this->position = data; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return -ENOENT; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-21 10:47:32 +01:00
										 |  |  | 	spa_alsa_reassign_follower(this); | 
					
						
							| 
									
										
										
										
											2018-10-24 10:27:57 +02:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2018-10-23 12:31:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | static void handle_process_latency(struct state *this, | 
					
						
							|  |  |  | 		const struct spa_process_latency_info *info) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bool ns_changed = this->process_latency.ns != info->ns; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (this->process_latency.quantum == info->quantum && | 
					
						
							|  |  |  | 	    this->process_latency.rate == info->rate && | 
					
						
							|  |  |  | 	    !ns_changed) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this->process_latency = *info; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this->info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS; | 
					
						
							|  |  |  | 	if (ns_changed) | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 		this->params[NODE_Props].user++; | 
					
						
							|  |  |  | 	this->params[NODE_ProcessLatency].user++; | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	this->port_info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS; | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 	this->port_params[PORT_Latency].user++; | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_set_param(void *object, uint32_t id, uint32_t flags, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 			       const struct spa_pod *param) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	switch (id) { | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_Props: | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 		struct props *p = &this->props; | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 		struct spa_process_latency_info info; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (param == NULL) { | 
					
						
							|  |  |  | 			reset_props(p); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		info = this->process_latency; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 		spa_pod_parse_object(param, | 
					
						
							|  |  |  | 			SPA_TYPE_OBJECT_Props, NULL, | 
					
						
							| 
									
										
										
										
											2020-09-14 20:15:48 +02:00
										 |  |  | 			SPA_PROP_device,       SPA_POD_OPT_Stringn(p->device, sizeof(p->device)), | 
					
						
							|  |  |  | 			SPA_PROP_minLatency,   SPA_POD_OPT_Int(&p->min_latency), | 
					
						
							|  |  |  | 			SPA_PROP_maxLatency,   SPA_POD_OPT_Int(&p->max_latency), | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 			SPA_PROP_latencyOffsetNsec,   SPA_POD_OPT_Long(&info.ns), | 
					
						
							| 
									
										
										
										
											2020-09-14 20:15:48 +02:00
										 |  |  | 			SPA_PROP_START_CUSTOM, SPA_POD_OPT_Bool(&p->use_chmap)); | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		handle_process_latency(this, &info); | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		emit_node_info(this, false); | 
					
						
							|  |  |  | 		emit_port_info(this, false); | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 	case SPA_PARAM_ProcessLatency: | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		struct spa_process_latency_info info; | 
					
						
							|  |  |  | 		if ((res = spa_process_latency_parse(param, &info)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-17 11:57:12 +02:00
										 |  |  | 		handle_process_latency(this, &info); | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		emit_node_info(this, false); | 
					
						
							|  |  |  | 		emit_port_info(this, false); | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_send_command(void *object, const struct spa_command *command) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2018-01-18 11:57:23 +01:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(command != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-24 10:53:09 +02:00
										 |  |  | 	switch (SPA_NODE_COMMAND_ID(command)) { | 
					
						
							| 
									
										
										
										
											2020-12-09 17:10:52 +01:00
										 |  |  | 	case SPA_NODE_COMMAND_ParamBegin: | 
					
						
							| 
									
										
										
										
											2021-09-14 12:42:03 +02:00
										 |  |  | 		if ((res = spa_alsa_open(this, NULL)) < 0) | 
					
						
							| 
									
										
										
										
											2020-12-09 17:10:52 +01:00
										 |  |  | 			return res; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SPA_NODE_COMMAND_ParamEnd: | 
					
						
							|  |  |  | 		if (this->have_format) | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		if ((res = spa_alsa_close(this)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-24 10:53:09 +02:00
										 |  |  | 	case SPA_NODE_COMMAND_Start: | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		if (!this->have_format) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EIO; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		if (this->n_buffers == 0) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EIO; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 		if ((res = spa_alsa_start(this)) < 0) | 
					
						
							| 
									
										
										
										
											2018-01-18 11:57:23 +01:00
										 |  |  | 			return res; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-24 10:53:09 +02:00
										 |  |  | 	case SPA_NODE_COMMAND_Pause: | 
					
						
							| 
									
										
										
										
											2019-10-22 12:20:29 +02:00
										 |  |  | 	case SPA_NODE_COMMAND_Suspend: | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 		if ((res = spa_alsa_pause(this)) < 0) | 
					
						
							| 
									
										
										
										
											2018-01-18 11:57:23 +01:00
										 |  |  | 			return res; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | impl_node_add_listener(void *object, | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 		struct spa_hook *listener, | 
					
						
							|  |  |  | 		const struct spa_node_events *events, | 
					
						
							|  |  |  | 		void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	struct spa_hook_list save; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spa_hook_list_isolate(&this->hooks, &save, listener, events, data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	emit_node_info(this, true); | 
					
						
							|  |  |  | 	emit_port_info(this, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_hook_list_join(&this->hooks, &save); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | impl_node_set_callbacks(void *object, | 
					
						
							| 
									
										
										
										
											2017-06-18 19:48:31 +02:00
										 |  |  | 			const struct spa_node_callbacks *callbacks, | 
					
						
							| 
									
										
										
										
											2017-08-06 06:42:26 +02:00
										 |  |  | 			void *data) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-15 12:17:52 +02:00
										 |  |  | 	this->callbacks = SPA_CALLBACKS_INIT(callbacks, data); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 14:01:18 +02:00
										 |  |  | static int impl_node_sync(void *object, int seq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct state *this = object; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_node_emit_result(&this->hooks, seq, 0, 0, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id, | 
					
						
							| 
									
										
										
										
											2019-02-18 13:22:46 +01:00
										 |  |  | 		const struct spa_dict *props) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | impl_node_port_enum_params(void *object, int seq, | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 			   enum spa_direction direction, uint32_t port_id, | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 			   uint32_t id, uint32_t start, uint32_t num, | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 			   const struct spa_pod *filter) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 	struct spa_pod *param; | 
					
						
							| 
									
										
										
										
											2017-11-14 10:17:45 +01:00
										 |  |  | 	struct spa_pod_builder b = { 0 }; | 
					
						
							|  |  |  | 	uint8_t buffer[1024]; | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 	struct spa_result_node_params result; | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	uint32_t count = 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	spa_return_val_if_fail(num != 0, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 	result.id = id; | 
					
						
							|  |  |  | 	result.next = start; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  |       next: | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 	result.index = result.next++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 10:17:45 +01:00
										 |  |  | 	spa_pod_builder_init(&b, buffer, sizeof(buffer)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	switch (id) { | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_EnumFormat: | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 		return spa_alsa_enum_format(this, seq, start, num, filter); | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_Format: | 
					
						
							| 
									
										
										
										
											2018-08-29 14:50:58 +02:00
										 |  |  | 		if (!this->have_format) | 
					
						
							|  |  |  | 			return -EIO; | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 		if (result.index > 0) | 
					
						
							| 
									
										
										
										
											2018-08-29 14:50:58 +02:00
										 |  |  | 			return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw); | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_Buffers: | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 		if (!this->have_format) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EIO; | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 		if (result.index > 0) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-11-07 20:28:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 		param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 			SPA_TYPE_OBJECT_ParamBuffers, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(2, 1, MAX_BUFFERS), | 
					
						
							| 
									
										
										
										
											2020-07-01 11:42:10 +02:00
										 |  |  | 			SPA_PARAM_BUFFERS_blocks,  SPA_POD_Int(this->blocks), | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			SPA_PARAM_BUFFERS_size,    SPA_POD_CHOICE_RANGE_Int( | 
					
						
							| 
									
										
										
										
											2018-09-05 16:41:07 +02:00
										 |  |  | 							this->props.max_latency * this->frame_size, | 
					
						
							|  |  |  | 							this->props.min_latency * this->frame_size, | 
					
						
							|  |  |  | 							INT32_MAX), | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			SPA_PARAM_BUFFERS_stride,  SPA_POD_Int(this->frame_size), | 
					
						
							|  |  |  | 			SPA_PARAM_BUFFERS_align,   SPA_POD_Int(16)); | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_Meta: | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 		switch (result.index) { | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		case 0: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_ParamMeta, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header), | 
					
						
							|  |  |  | 				SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))); | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_IO: | 
					
						
							| 
									
										
										
										
											2019-02-25 12:29:57 +01:00
										 |  |  | 		switch (result.index) { | 
					
						
							| 
									
										
										
										
											2018-07-17 17:37:55 +02:00
										 |  |  | 		case 0: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PARAM_IO_id,   SPA_POD_Id(SPA_IO_Buffers), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_buffers))); | 
					
						
							| 
									
										
										
										
											2018-07-17 17:37:55 +02:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		case 1: | 
					
						
							| 
									
										
										
										
											2019-07-09 16:56:05 +02:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							|  |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							|  |  |  | 				SPA_PARAM_IO_id,   SPA_POD_Id(SPA_IO_RateMatch), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_rate_match))); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-07-17 17:37:55 +02:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-21 10:01:37 +02:00
										 |  |  | 	case SPA_PARAM_Latency: | 
					
						
							|  |  |  | 		switch (result.index) { | 
					
						
							| 
									
										
										
										
											2021-06-24 10:01:56 +02:00
										 |  |  | 		case 0: case 1: | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			struct spa_latency_info latency = this->latency[result.index]; | 
					
						
							|  |  |  | 			if (latency.direction == SPA_DIRECTION_OUTPUT) | 
					
						
							|  |  |  | 				spa_process_latency_info_add(&this->process_latency, &latency); | 
					
						
							|  |  |  | 			param = spa_latency_build(&b, id, &latency); | 
					
						
							| 
									
										
										
										
											2021-05-21 10:01:37 +02:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-21 10:01:37 +02:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	if (spa_pod_filter(&b, &result.param, param, filter) < 0) | 
					
						
							|  |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 13:59:48 +02:00
										 |  |  | 	spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result); | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	if (++count != num) | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-20 17:51:05 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int clear_buffers(struct state *this) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (this->n_buffers > 0) { | 
					
						
							|  |  |  | 		spa_list_init(&this->free); | 
					
						
							|  |  |  | 		spa_list_init(&this->ready); | 
					
						
							|  |  |  | 		this->n_buffers = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int port_set_format(void *object, | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 			   enum spa_direction direction, uint32_t port_id, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 			   uint32_t flags, const struct spa_pod *format) | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (format == NULL) { | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 		if (!this->have_format) | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 11:28:41 +01:00
										 |  |  | 		spa_log_debug(this->log, "clear format"); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		spa_alsa_close(this); | 
					
						
							| 
									
										
										
										
											2021-11-23 12:20:27 +01:00
										 |  |  | 		clear_buffers(this); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		struct spa_audio_info info = { 0 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 14:50:58 +02:00
										 |  |  | 		if ((err = spa_format_parse(format, &info.media_type, &info.media_subtype)) < 0) | 
					
						
							|  |  |  | 			return err; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		if (info.media_type != SPA_MEDIA_TYPE_audio || | 
					
						
							|  |  |  | 		    info.media_subtype != SPA_MEDIA_SUBTYPE_raw) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-03-17 11:58:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		if (spa_format_audio_raw_parse(format, &info.info.raw) < 0) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-03-17 11:58:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 15:13:33 +02:00
										 |  |  | 		if ((err = spa_alsa_set_format(this, &info, flags)) < 0) | 
					
						
							|  |  |  | 			return err; | 
					
						
							| 
									
										
										
										
											2017-03-17 11:58:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		this->current_format = info; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-02 10:34:41 +01:00
										 |  |  | 	this->info.change_mask |= SPA_NODE_CHANGE_MASK_PROPS; | 
					
						
							|  |  |  | 	emit_node_info(this, false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	this->port_info.change_mask |= SPA_PORT_CHANGE_MASK_RATE; | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	this->port_info.rate = SPA_FRACTION(1, this->rate); | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	this->port_info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (this->have_format) { | 
					
						
							| 
									
										
										
										
											2021-06-24 10:01:56 +02:00
										 |  |  | 		this->port_params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE); | 
					
						
							|  |  |  | 		this->port_params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ); | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 		this->port_params[PORT_Latency].user++; | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-06-24 10:01:56 +02:00
										 |  |  | 		this->port_params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE); | 
					
						
							|  |  |  | 		this->port_params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	emit_port_info(this, false); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | impl_node_port_set_param(void *object, | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 			 enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 			 uint32_t id, uint32_t flags, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 			 const struct spa_pod *param) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-05-22 13:06:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-05-22 13:06:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	switch (id) { | 
					
						
							|  |  |  | 	case SPA_PARAM_Format: | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 		res = port_set_format(this, direction, port_id, flags, param); | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2021-06-05 02:21:10 +08:00
										 |  |  | 	case SPA_PARAM_Latency: | 
					
						
							| 
									
										
										
										
											2021-06-24 09:43:58 +02:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		struct spa_latency_info info; | 
					
						
							|  |  |  | 		if ((res = spa_latency_parse(param, &info)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 		if (direction == info.direction) | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this->latency[info.direction] = info; | 
					
						
							|  |  |  | 		this->port_info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS; | 
					
						
							| 
									
										
										
										
											2021-09-01 13:08:03 +02:00
										 |  |  | 		this->port_params[PORT_Latency].user++; | 
					
						
							| 
									
										
										
										
											2021-06-24 09:43:58 +02:00
										 |  |  | 		emit_port_info(this, false); | 
					
						
							| 
									
										
										
										
											2021-06-05 02:21:10 +08:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2021-06-24 09:43:58 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		res = -ENOENT; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | impl_node_port_use_buffers(void *object, | 
					
						
							| 
									
										
										
										
											2019-07-25 13:19:39 +02:00
										 |  |  | 		enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 		uint32_t flags, | 
					
						
							|  |  |  | 		struct spa_buffer **buffers, uint32_t n_buffers) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2019-01-07 15:52:42 +01:00
										 |  |  | 	uint32_t i; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 19:52:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-04-04 09:00:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (!this->have_format) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -EIO; | 
					
						
							| 
									
										
										
										
											2016-09-20 19:52:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 08:05:40 +02:00
										 |  |  | 	spa_log_debug(this->log, "%p: use %d buffers", this, n_buffers); | 
					
						
							| 
									
										
										
										
											2019-10-18 21:54:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (this->n_buffers > 0) { | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 		spa_alsa_pause(this); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		if ((res = clear_buffers(this)) < 0) | 
					
						
							|  |  |  | 			return res; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for (i = 0; i < n_buffers; i++) { | 
					
						
							|  |  |  | 		struct buffer *b = &this->buffers[i]; | 
					
						
							|  |  |  | 		struct spa_data *d = buffers[i]->datas; | 
					
						
							| 
									
										
										
										
											2017-04-26 18:42:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-11 09:56:46 +02:00
										 |  |  | 		b->buf = buffers[i]; | 
					
						
							| 
									
										
										
										
											2019-01-07 17:57:03 +01:00
										 |  |  | 		b->id = i; | 
					
						
							| 
									
										
										
										
											2018-03-08 11:02:21 +01:00
										 |  |  | 		b->flags = 0; | 
					
						
							| 
									
										
										
										
											2016-10-04 19:37:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		b->h = spa_buffer_find_meta_data(b->buf, SPA_META_Header, sizeof(*b->h)); | 
					
						
							| 
									
										
										
										
											2017-04-26 18:42:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 12:23:42 +02:00
										 |  |  | 		if (d[0].data == NULL) { | 
					
						
							| 
									
										
										
										
											2021-10-03 08:05:40 +02:00
										 |  |  | 			spa_log_error(this->log, "%p: need mapped memory", this); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-24 12:58:10 +02:00
										 |  |  | 		spa_list_append(&this->free, &b->link); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	this->n_buffers = n_buffers; | 
					
						
							| 
									
										
										
										
											2016-09-20 19:52:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | impl_node_port_set_io(void *object, | 
					
						
							| 
									
										
										
										
											2017-11-21 19:34:37 +01:00
										 |  |  | 		      enum spa_direction direction, | 
					
						
							|  |  |  | 		      uint32_t port_id, | 
					
						
							|  |  |  | 		      uint32_t id, | 
					
						
							| 
									
										
										
										
											2017-11-22 14:30:04 +01:00
										 |  |  | 		      void *data, size_t size) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 08:05:40 +02:00
										 |  |  | 	spa_log_debug(this->log, "%p: io %d %p %zd", this, id, data, size); | 
					
						
							| 
									
										
										
										
											2019-07-08 18:23:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	switch (id) { | 
					
						
							|  |  |  | 	case SPA_IO_Buffers: | 
					
						
							| 
									
										
										
										
											2017-11-22 14:30:04 +01:00
										 |  |  | 		this->io = data; | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2019-07-09 16:56:05 +02:00
										 |  |  | 	case SPA_IO_RateMatch: | 
					
						
							|  |  |  | 		this->rate_match = data; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2017-11-21 19:34:37 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id) | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(port_id == 0, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (this->n_buffers == 0) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -EIO; | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (buffer_id >= this->n_buffers) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 13:12:49 +01:00
										 |  |  | 	spa_alsa_recycle_buffer(this, buffer_id); | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static int impl_node_process(void *object) | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	struct state *this = object; | 
					
						
							| 
									
										
										
										
											2017-11-21 19:34:37 +01:00
										 |  |  | 	struct spa_io_buffers *io; | 
					
						
							| 
									
										
										
										
											2018-04-26 17:22:17 +02:00
										 |  |  | 	struct buffer *b; | 
					
						
							| 
									
										
										
										
											2017-04-03 14:56:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	spa_return_val_if_fail(this != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-04-03 14:56:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	io = this->io; | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(io != NULL, -EIO); | 
					
						
							| 
									
										
										
										
											2017-04-03 14:56:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 08:05:40 +02:00
										 |  |  | 	spa_log_trace_fp(this->log, "%p; status %d", this, io->status); | 
					
						
							| 
									
										
										
										
											2020-09-25 17:01:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-16 12:55:23 +02:00
										 |  |  | 	if (io->status == SPA_STATUS_HAVE_DATA) | 
					
						
							|  |  |  | 		return SPA_STATUS_HAVE_DATA; | 
					
						
							| 
									
										
										
										
											2017-04-28 17:22:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-27 09:16:03 +02:00
										 |  |  | 	if (io->buffer_id < this->n_buffers) { | 
					
						
							| 
									
										
										
										
											2020-03-19 13:12:49 +01:00
										 |  |  | 		spa_alsa_recycle_buffer(this, io->buffer_id); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		io->buffer_id = SPA_ID_INVALID; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-11 16:44:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 11:51:22 +02:00
										 |  |  | 	if (spa_list_is_empty(&this->ready) && this->following) { | 
					
						
							|  |  |  | 		if (this->freewheel) | 
					
						
							|  |  |  | 			spa_alsa_skip(this); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			spa_alsa_read(this); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-02-21 10:47:32 +01:00
										 |  |  | 	if (spa_list_is_empty(&this->ready) || !this->following) | 
					
						
							| 
									
										
										
										
											2019-02-12 17:42:33 +01:00
										 |  |  | 		return SPA_STATUS_OK; | 
					
						
							| 
									
										
										
										
											2018-04-26 17:22:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	b = spa_list_first(&this->ready, struct buffer, link); | 
					
						
							|  |  |  | 	spa_list_remove(&b->link); | 
					
						
							| 
									
										
										
										
											2020-03-19 13:12:49 +01:00
										 |  |  | 	SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT); | 
					
						
							| 
									
										
										
										
											2018-04-26 17:22:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 08:05:40 +02:00
										 |  |  | 	spa_log_trace_fp(this->log, "%p: dequeue buffer %d", this, b->id); | 
					
						
							| 
									
										
										
										
											2018-04-26 17:22:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-07 17:57:03 +01:00
										 |  |  | 	io->buffer_id = b->id; | 
					
						
							| 
									
										
										
										
											2019-09-16 12:55:23 +02:00
										 |  |  | 	io->status = SPA_STATUS_HAVE_DATA; | 
					
						
							| 
									
										
										
										
											2018-04-26 17:22:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-16 12:55:23 +02:00
										 |  |  | 	return SPA_STATUS_HAVE_DATA; | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | static const struct spa_node_methods impl_node = { | 
					
						
							|  |  |  | 	SPA_VERSION_NODE_METHODS, | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	.add_listener = impl_node_add_listener, | 
					
						
							|  |  |  | 	.set_callbacks = impl_node_set_callbacks, | 
					
						
							| 
									
										
										
										
											2019-05-28 14:01:18 +02:00
										 |  |  | 	.sync = impl_node_sync, | 
					
						
							| 
									
										
										
										
											2019-02-14 17:08:46 +01:00
										 |  |  | 	.enum_params = impl_node_enum_params, | 
					
						
							|  |  |  | 	.set_param = impl_node_set_param, | 
					
						
							|  |  |  | 	.set_io = impl_node_set_io, | 
					
						
							|  |  |  | 	.send_command = impl_node_send_command, | 
					
						
							|  |  |  | 	.add_port = impl_node_add_port, | 
					
						
							|  |  |  | 	.remove_port = impl_node_remove_port, | 
					
						
							|  |  |  | 	.port_enum_params = impl_node_port_enum_params, | 
					
						
							|  |  |  | 	.port_set_param = impl_node_port_set_param, | 
					
						
							|  |  |  | 	.port_use_buffers = impl_node_port_use_buffers, | 
					
						
							|  |  |  | 	.port_set_io = impl_node_port_set_io, | 
					
						
							|  |  |  | 	.port_reuse_buffer = impl_node_port_reuse_buffer, | 
					
						
							|  |  |  | 	.process = impl_node_process, | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-19 13:15:10 +01:00
										 |  |  | static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(handle != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(interface != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = (struct state *) handle; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 11:36:13 +10:00
										 |  |  | 	if (spa_streq(type, SPA_TYPE_INTERFACE_Node)) | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		*interface = &this->node; | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2016-10-07 13:14:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | static int impl_clear(struct spa_handle *handle) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-09 15:01:07 +01:00
										 |  |  | 	struct state *this; | 
					
						
							|  |  |  | 	spa_return_val_if_fail(handle != NULL, -EINVAL); | 
					
						
							|  |  |  | 	this = (struct state *) handle; | 
					
						
							|  |  |  | 	spa_alsa_close(this); | 
					
						
							| 
									
										
										
										
											2021-06-02 13:23:08 +02:00
										 |  |  | 	spa_alsa_clear(this); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 10:06:17 +02:00
										 |  |  | static size_t | 
					
						
							|  |  |  | impl_get_size(const struct spa_handle_factory *factory, | 
					
						
							|  |  |  | 	      const struct spa_dict *params) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return sizeof(struct state); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | impl_init(const struct spa_handle_factory *factory, | 
					
						
							|  |  |  | 	  struct spa_handle *handle, | 
					
						
							|  |  |  | 	  const struct spa_dict *info, | 
					
						
							|  |  |  | 	  const struct spa_support *support, | 
					
						
							|  |  |  | 	  uint32_t n_support) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct state *this; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(factory != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(handle != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	handle->get_interface = impl_get_interface; | 
					
						
							|  |  |  | 	handle->clear = impl_clear; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = (struct state *) handle; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-19 13:15:10 +01:00
										 |  |  | 	this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log); | 
					
						
							| 
									
										
										
										
											2021-09-23 14:25:32 +10:00
										 |  |  | 	alsa_log_topic_init(this->log); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-19 13:15:10 +01:00
										 |  |  | 	this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem); | 
					
						
							|  |  |  | 	this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (this->data_loop == NULL) { | 
					
						
							| 
									
										
										
										
											2021-10-03 08:05:40 +02:00
										 |  |  | 		spa_log_error(this->log, "%p: a data loop is needed", this); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-06-06 15:20:43 +02:00
										 |  |  | 	if (this->data_system == NULL) { | 
					
						
							| 
									
										
										
										
											2021-10-03 08:05:40 +02:00
										 |  |  | 		spa_log_error(this->log, "%p: a data system is needed", this); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-20 16:11:23 +02:00
										 |  |  | 	this->node.iface = SPA_INTERFACE_INIT(SPA_TYPE_INTERFACE_Node, SPA_VERSION_NODE, &impl_node, this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	spa_hook_list_init(&this->hooks); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this->stream = SND_PCM_STREAM_CAPTURE; | 
					
						
							| 
									
										
										
										
											2021-06-24 09:43:58 +02:00
										 |  |  | 	this->port_direction = SPA_DIRECTION_OUTPUT; | 
					
						
							|  |  |  | 	this->latency[this->port_direction] = SPA_LATENCY_INFO( | 
					
						
							|  |  |  | 			this->port_direction, | 
					
						
							|  |  |  | 			.min_quantum = 1.0f, | 
					
						
							|  |  |  | 			.max_quantum = 1.0f); | 
					
						
							|  |  |  | 	this->latency[SPA_DIRECTION_INPUT] = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT); | 
					
						
							| 
									
										
										
										
											2021-05-21 10:01:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	this->info_all = SPA_NODE_CHANGE_MASK_FLAGS | | 
					
						
							|  |  |  | 			SPA_NODE_CHANGE_MASK_PROPS | | 
					
						
							|  |  |  | 			SPA_NODE_CHANGE_MASK_PARAMS; | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	this->info.max_output_ports = 1; | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	this->info.flags = SPA_NODE_FLAG_RT; | 
					
						
							| 
									
										
										
										
											2021-06-24 10:01:56 +02:00
										 |  |  | 	this->params[NODE_PropInfo] = SPA_PARAM_INFO(SPA_PARAM_PropInfo, SPA_PARAM_INFO_READ); | 
					
						
							|  |  |  | 	this->params[NODE_Props] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE); | 
					
						
							|  |  |  | 	this->params[NODE_IO] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ); | 
					
						
							| 
									
										
										
										
											2021-08-17 09:14:40 +02:00
										 |  |  | 	this->params[NODE_ProcessLatency] = SPA_PARAM_INFO(SPA_PARAM_ProcessLatency, SPA_PARAM_INFO_READWRITE); | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	this->info.params = this->params; | 
					
						
							| 
									
										
										
										
											2021-05-21 11:08:52 +02:00
										 |  |  | 	this->info.n_params = N_NODE_PARAMS; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	reset_props(&this->props); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-01 12:00:42 +01:00
										 |  |  | 	this->port_info_all = SPA_PORT_CHANGE_MASK_FLAGS | | 
					
						
							|  |  |  | 			SPA_PORT_CHANGE_MASK_PARAMS; | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	this->port_info = SPA_PORT_INFO_INIT(); | 
					
						
							| 
									
										
										
										
											2019-07-25 13:19:39 +02:00
										 |  |  | 	this->port_info.flags = SPA_PORT_FLAG_LIVE | | 
					
						
							| 
									
										
										
										
											2019-02-14 17:40:01 +01:00
										 |  |  | 			   SPA_PORT_FLAG_PHYSICAL | | 
					
						
							|  |  |  | 			   SPA_PORT_FLAG_TERMINAL; | 
					
						
							| 
									
										
										
										
											2021-06-24 10:01:56 +02:00
										 |  |  | 	this->port_params[PORT_EnumFormat] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ); | 
					
						
							|  |  |  | 	this->port_params[PORT_Meta] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ); | 
					
						
							|  |  |  | 	this->port_params[PORT_IO] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ); | 
					
						
							|  |  |  | 	this->port_params[PORT_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE); | 
					
						
							|  |  |  | 	this->port_params[PORT_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0); | 
					
						
							|  |  |  | 	this->port_params[PORT_Latency] = SPA_PARAM_INFO(SPA_PARAM_Latency, SPA_PARAM_INFO_READWRITE); | 
					
						
							| 
									
										
										
										
											2019-02-27 16:43:01 +01:00
										 |  |  | 	this->port_info.params = this->port_params; | 
					
						
							| 
									
										
										
										
											2021-05-21 11:08:52 +02:00
										 |  |  | 	this->port_info.n_params = N_PORT_PARAMS; | 
					
						
							| 
									
										
										
										
											2017-11-30 16:36:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	spa_list_init(&this->free); | 
					
						
							|  |  |  | 	spa_list_init(&this->ready); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 12:27:36 +01:00
										 |  |  | 	return spa_alsa_init(this, info); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct spa_interface_info impl_interfaces[] = { | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 	{SPA_TYPE_INTERFACE_Node,}, | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | impl_enum_interface_info(const struct spa_handle_factory *factory, | 
					
						
							|  |  |  | 			 const struct spa_interface_info **info, | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			 uint32_t *index) | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(factory != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(info != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(index != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	if (*index >= SPA_N_ELEMENTS(impl_interfaces)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	*info = &impl_interfaces[(*index)++]; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 19:55:22 +02:00
										 |  |  | static const struct spa_dict_item info_items[] = { | 
					
						
							| 
									
										
										
										
											2019-06-03 16:48:01 +02:00
										 |  |  | 	{ SPA_KEY_FACTORY_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, | 
					
						
							|  |  |  | 	{ SPA_KEY_FACTORY_DESCRIPTION, "Record audio with the alsa API" }, | 
					
						
							|  |  |  | 	{ SPA_KEY_FACTORY_USAGE, "["SPA_KEY_API_ALSA_PATH"=<device>]" }, | 
					
						
							| 
									
										
										
										
											2017-09-07 19:55:22 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-08 12:01:50 +01:00
										 |  |  | static const struct spa_dict info = SPA_DICT_INIT_ARRAY(info_items); | 
					
						
							| 
									
										
										
										
											2017-09-07 19:55:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-14 18:32:39 +02:00
										 |  |  | const struct spa_handle_factory spa_alsa_source_factory = { | 
					
						
							|  |  |  | 	SPA_VERSION_HANDLE_FACTORY, | 
					
						
							| 
									
										
										
										
											2019-06-21 13:31:34 +02:00
										 |  |  | 	SPA_NAME_API_ALSA_PCM_SOURCE, | 
					
						
							| 
									
										
										
										
											2017-09-07 19:55:22 +02:00
										 |  |  | 	&info, | 
					
						
							| 
									
										
										
										
											2018-04-09 10:06:17 +02:00
										 |  |  | 	impl_get_size, | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	impl_init, | 
					
						
							|  |  |  | 	impl_enum_interface_info, | 
					
						
							| 
									
										
										
										
											2016-09-20 11:20:43 +02:00
										 |  |  | }; |