| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | /* Spa ALSA Sink
 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-11-05 17:48:52 +01:00
										 |  |  |  * Copyright © 2018 Wim Taymans | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +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-06-28 12:21:56 +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-06-28 12:21:56 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <asoundlib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-10 13:36:14 +01:00
										 |  |  | #include <spa/node/node.h>
 | 
					
						
							|  |  |  | #include <spa/param/audio/format.h>
 | 
					
						
							| 
									
										
										
										
											2018-08-13 17:17:23 +02:00
										 |  |  | #include <spa/pod/filter.h>
 | 
					
						
							| 
									
										
										
										
											2019-01-22 17:38:23 +01:00
										 |  |  | #include <spa/debug/pod.h>
 | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | #define NAME "alsa-sink"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-19 09:16:58 +02:00
										 |  |  | #include "alsa-utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | #define CHECK_PORT(this,d,p)    ((d) == SPA_DIRECTION_INPUT && (p) == 0)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-06 13:30:34 +02:00
										 |  |  | static const char default_device[] = "hw:0"; | 
					
						
							| 
									
										
										
										
											2018-05-14 13:07:01 +02:00
										 |  |  | static const uint32_t default_min_latency = 16; | 
					
						
							| 
									
										
										
										
											2017-10-31 15:59:08 +01:00
										 |  |  | static const uint32_t default_max_latency = 1024; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | static void reset_props(struct props *props) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	strncpy(props->device, default_device, 64); | 
					
						
							|  |  |  | 	props->min_latency = default_min_latency; | 
					
						
							| 
									
										
										
										
											2017-10-31 15:59:08 +01:00
										 |  |  | 	props->max_latency = default_max_latency; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | static int impl_node_enum_params(struct spa_node *node, | 
					
						
							|  |  |  | 				 uint32_t id, uint32_t *index, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 				 const struct spa_pod *filter, | 
					
						
							|  |  |  | 				 struct spa_pod **result, | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 				 struct spa_pod_builder *builder) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											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]; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(index != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(builder != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  |       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_List: | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 		uint32_t list[] = { SPA_PARAM_PropInfo, | 
					
						
							|  |  |  | 				    SPA_PARAM_Props }; | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (*index < SPA_N_ELEMENTS(list)) | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-09-05 16:41:07 +02:00
										 |  |  | 					SPA_TYPE_OBJECT_ParamList, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 					SPA_PARAM_LIST_id, SPA_POD_Id(list[*index])); | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_PropInfo: | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		struct props *p = &this->props; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  | 		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)); | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-15 16:30:56 +01:00
										 |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		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, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01: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)); | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											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-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 	(*index)++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 	if (spa_pod_filter(builder, result, param, filter) < 0) | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 12:31:41 +02:00
										 |  |  | static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-24 10:27:57 +02:00
										 |  |  | 	struct state *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (id) { | 
					
						
							|  |  |  | 	case SPA_IO_Clock: | 
					
						
							|  |  |  | 		this->clock = data; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case SPA_IO_Position: | 
					
						
							|  |  |  | 		this->position = data; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return -ENOENT; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2018-10-23 12:31:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 			       const struct spa_pod *param) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	if (id == SPA_PARAM_Props) { | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 		struct props *p = &this->props; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		if (param == NULL) { | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 			reset_props(p); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 		spa_pod_parse_object(param, | 
					
						
							|  |  |  | 			SPA_TYPE_OBJECT_Props, NULL, | 
					
						
							| 
									
										
										
										
											2019-01-16 12:55:50 +01: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)); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 19:52:31 +02:00
										 |  |  | static int impl_node_send_command(struct spa_node *node, const struct spa_command *command) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2018-01-18 11:57:23 +01:00
										 |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(command != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2016-07-30 20:35:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-24 10:53:09 +02:00
										 |  |  | 	switch (SPA_NODE_COMMAND_ID(command)) { | 
					
						
							|  |  |  | 	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-07-06 19:43:37 +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: | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-18 11:57:23 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 12:41:40 +01:00
										 |  |  | static const struct spa_dict_item node_info_items[] = { | 
					
						
							|  |  |  | 	{ "media.class", "Audio/Sink" }, | 
					
						
							|  |  |  | 	{ "node.driver", "true" }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 17:08:46 +01:00
										 |  |  | static void emit_node_info(struct state *this) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (this->callbacks && this->callbacks->info) { | 
					
						
							|  |  |  | 		struct spa_node_info info; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		info = SPA_NODE_INFO_INIT(); | 
					
						
							| 
									
										
										
										
											2019-02-14 17:40:01 +01:00
										 |  |  | 		info.max_input_ports = 1; | 
					
						
							| 
									
										
										
										
											2019-02-14 17:08:46 +01:00
										 |  |  | 		info.change_mask = SPA_NODE_CHANGE_MASK_PROPS; | 
					
						
							|  |  |  | 		info.props = &SPA_DICT_INIT_ARRAY(node_info_items); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this->callbacks->info(this->callbacks_data, &info); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void emit_port_info(struct state *this) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (this->callbacks && this->callbacks->port_info && this->info.change_mask) { | 
					
						
							|  |  |  | 		this->callbacks->port_info(this->callbacks_data, SPA_DIRECTION_INPUT, 0, &this->info); | 
					
						
							|  |  |  | 		this->info.change_mask = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 12:31:36 +01:00
										 |  |  | static int | 
					
						
							|  |  |  | impl_node_sync(struct spa_node *node, uint32_t seq) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct state *this; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spa_return_val_if_fail(this->callbacks && this->callbacks->done, -EIO); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this->callbacks->done(this->callbacks_data, seq); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | impl_node_set_callbacks(struct spa_node *node, | 
					
						
							| 
									
										
										
										
											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-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2016-07-30 20:35:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-14 18:32:39 +02:00
										 |  |  | 	this->callbacks = callbacks; | 
					
						
							| 
									
										
										
										
											2017-08-06 06:42:26 +02:00
										 |  |  | 	this->callbacks_data = data; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 17:08:46 +01:00
										 |  |  | 	emit_node_info(this); | 
					
						
							|  |  |  | 	emit_port_info(this); | 
					
						
							| 
									
										
										
										
											2018-11-26 12:41:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 13:22:46 +01:00
										 |  |  | static int impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 		const struct spa_dict *props) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | static int impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | impl_node_port_enum_params(struct spa_node *node, | 
					
						
							|  |  |  | 			   enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 			   uint32_t id, uint32_t *index, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 			   const struct spa_pod *filter, | 
					
						
							|  |  |  | 			   struct spa_pod **result, | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 			   struct spa_pod_builder *builder) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											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]; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(index != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(builder != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2016-07-30 20:35:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  |       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_List: | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 		uint32_t list[] = { SPA_PARAM_EnumFormat, | 
					
						
							|  |  |  | 				    SPA_PARAM_Format, | 
					
						
							|  |  |  | 				    SPA_PARAM_Buffers, | 
					
						
							|  |  |  | 				    SPA_PARAM_Meta, | 
					
						
							|  |  |  | 				    SPA_PARAM_IO, }; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (*index < SPA_N_ELEMENTS(list)) | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-09-05 16:41:07 +02:00
										 |  |  | 					SPA_TYPE_OBJECT_ParamList, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 					SPA_PARAM_LIST_id, SPA_POD_Id(list[*index])); | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_EnumFormat: | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 		return spa_alsa_enum_format(this, index, filter, result, builder); | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_PARAM_Format: | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 		if (!this->have_format) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EIO; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 		if (*index > 0) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 14:50:58 +02:00
										 |  |  | 		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; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		if (*index > 0) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +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(3, 1, MAX_BUFFERS), | 
					
						
							|  |  |  | 			SPA_PARAM_BUFFERS_blocks,  SPA_POD_Int(1), | 
					
						
							|  |  |  | 			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: | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 		if (!this->have_format) | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EIO; | 
					
						
							| 
									
										
										
										
											2017-11-08 11:22:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		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: | 
					
						
							| 
									
										
										
										
											2018-07-17 17:37:55 +02:00
										 |  |  | 		switch (*index) { | 
					
						
							|  |  |  | 		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-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_Clock), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_clock))); | 
					
						
							| 
									
										
										
										
											2018-07-17 17:37:55 +02:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 		case 2: | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 			param = spa_pod_builder_add_object(&b, | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 				SPA_TYPE_OBJECT_ParamIO, id, | 
					
						
							| 
									
										
										
										
											2019-01-16 11:05:12 +01:00
										 |  |  | 				SPA_PARAM_IO_id,   SPA_POD_Id(SPA_IO_Notify), | 
					
						
							|  |  |  | 				SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_sequence) + 1024)); | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2018-07-17 17:37:55 +02:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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
										 |  |  | 
 | 
					
						
							|  |  |  | 	(*index)++; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 	if (spa_pod_filter(builder, result, param, filter) < 0) | 
					
						
							| 
									
										
										
										
											2017-11-09 17:07:04 +01:00
										 |  |  | 		goto next; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int clear_buffers(struct state *this) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (this->n_buffers > 0) { | 
					
						
							|  |  |  | 		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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int port_set_format(struct spa_node *node, | 
					
						
							|  |  |  | 			   enum spa_direction direction, uint32_t port_id, | 
					
						
							|  |  |  | 			   uint32_t flags, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 			   const struct spa_pod *format) | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct state *this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (format == NULL) { | 
					
						
							| 
									
										
										
										
											2018-05-10 11:23:51 +02:00
										 |  |  | 		spa_log_debug(this->log, "clear format"); | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 		spa_alsa_pause(this); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		clear_buffers(this); | 
					
						
							|  |  |  | 		spa_alsa_close(this); | 
					
						
							|  |  |  | 		this->have_format = false; | 
					
						
							|  |  |  | 	} 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) | 
					
						
							| 
									
										
										
										
											2017-11-08 15:48:31 +01:00
										 |  |  | 			return err; | 
					
						
							| 
									
										
										
										
											2017-03-24 18:11:11 +01: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-24 18:11:11 +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-24 18:11:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-26 15:13:33 +02:00
										 |  |  | 		if ((err = spa_alsa_set_format(this, &info, flags)) < 0) | 
					
						
							|  |  |  | 			return err; | 
					
						
							| 
									
										
										
										
											2017-03-24 18:11:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		this->current_format = info; | 
					
						
							|  |  |  | 		this->have_format = true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (this->have_format) { | 
					
						
							| 
									
										
										
										
											2019-02-14 17:08:46 +01:00
										 |  |  | 		this->info.change_mask |= SPA_PORT_CHANGE_MASK_RATE; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		this->info.rate = this->rate; | 
					
						
							| 
									
										
										
										
											2019-02-14 17:08:46 +01:00
										 |  |  | 		emit_port_info(this); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | impl_node_port_set_param(struct spa_node *node, | 
					
						
							|  |  |  | 			 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-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	if (id == SPA_PARAM_Format) { | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 		return port_set_format(node, direction, port_id, flags, param); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-07 17:39:31 +01:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | impl_node_port_use_buffers(struct spa_node *node, | 
					
						
							|  |  |  | 			   enum spa_direction direction, | 
					
						
							|  |  |  | 			   uint32_t port_id, struct spa_buffer **buffers, uint32_t n_buffers) | 
					
						
							| 
									
										
										
										
											2016-07-08 20:12:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2019-01-07 15:52:42 +01:00
										 |  |  | 	uint32_t i; | 
					
						
							| 
									
										
										
										
											2016-10-28 16:56:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-10-28 16:56:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2016-10-28 16:56:33 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 11:23:51 +02:00
										 |  |  | 	spa_log_debug(this->log, "use buffers %d", n_buffers); | 
					
						
							| 
									
										
										
										
											2016-10-28 16:56:33 +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-10-28 16:56:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	if (n_buffers == 0) { | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 		spa_alsa_pause(this); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		clear_buffers(this); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-28 16:56:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	for (i = 0; i < n_buffers; i++) { | 
					
						
							|  |  |  | 		struct buffer *b = &this->buffers[i]; | 
					
						
							| 
									
										
										
										
											2018-04-30 09:27:20 +02:00
										 |  |  | 		struct spa_data *d = buffers[i]->datas; | 
					
						
							| 
									
										
										
										
											2017-09-07 19:55:22 +02:00
										 |  |  | 		uint32_t type; | 
					
						
							| 
									
										
										
										
											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 = BUFFER_FLAG_OUT; | 
					
						
							| 
									
										
										
										
											2016-10-28 16:56:33 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-30 09:27:20 +02:00
										 |  |  | 		type = d[0].type; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		if ((type == SPA_DATA_MemFd || | 
					
						
							|  |  |  | 		     type == SPA_DATA_DmaBuf || | 
					
						
							|  |  |  | 		     type == SPA_DATA_MemPtr) && d[0].data == NULL) { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 			spa_log_error(this->log, NAME " %p: need mapped memory", this); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-12-12 15:13:36 +01:00
										 |  |  | 		spa_log_debug(this->log, "alsa-sink %p: %d %p data:%p", this, i, b->buf, d[0].data); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	this->n_buffers = n_buffers; | 
					
						
							| 
									
										
										
										
											2016-10-28 16:56:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-07-08 20:12:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | impl_node_port_alloc_buffers(struct spa_node *node, | 
					
						
							|  |  |  | 			     enum spa_direction direction, | 
					
						
							|  |  |  | 			     uint32_t port_id, | 
					
						
							| 
									
										
										
										
											2017-11-13 17:57:38 +01:00
										 |  |  | 			     struct spa_pod **params, | 
					
						
							| 
									
										
										
										
											2017-05-26 18:19:51 +02:00
										 |  |  | 			     uint32_t n_params, | 
					
						
							|  |  |  | 			     struct spa_buffer **buffers, | 
					
						
							|  |  |  | 			     uint32_t *n_buffers) | 
					
						
							| 
									
										
										
										
											2016-07-08 20:12:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2016-08-24 16:26:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							|  |  |  | 	spa_return_val_if_fail(buffers != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-08-24 16:26:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2016-08-24 16:26:58 +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-08-24 16:26:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2016-07-08 20:12:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2017-11-21 19:34:37 +01:00
										 |  |  | impl_node_port_set_io(struct spa_node *node, | 
					
						
							|  |  |  | 		      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-08-02 16:34:44 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2016-08-02 16:34:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-08-02 16:34:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							| 
									
										
										
										
											2016-08-02 16:34:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-08-02 16:34:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	switch (id) { | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_IO_Buffers: | 
					
						
							| 
									
										
										
										
											2017-11-22 14:30:04 +01:00
										 |  |  | 		this->io = data; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-25 12:08:29 +02:00
										 |  |  | 	case SPA_IO_Clock: | 
					
						
							| 
									
										
										
										
											2018-07-17 09:50:51 +02:00
										 |  |  | 		this->clock = data; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-11-16 17:00:40 +01:00
										 |  |  | 	case SPA_IO_Notify: | 
					
						
							|  |  |  | 		this->notify = data; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2017-11-21 19:34:37 +01:00
										 |  |  | 		return -ENOENT; | 
					
						
							| 
									
										
										
										
											2018-08-23 17:47:57 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-07-30 20:35:34 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | static int impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id) | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return -ENOTSUP; | 
					
						
							| 
									
										
										
										
											2016-10-03 19:43:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 16:55:25 +01:00
										 |  |  | static int impl_node_process(struct spa_node *node) | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2017-11-21 19:34:37 +01:00
										 |  |  | 	struct spa_io_buffers *input; | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(node != NULL, -EINVAL); | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = SPA_CONTAINER_OF(node, struct state, node); | 
					
						
							|  |  |  | 	input = this->io; | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	spa_return_val_if_fail(input != NULL, -EIO); | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 05:10:55 +02:00
										 |  |  | 	spa_log_trace(this->log, NAME " %p: process %d %d/%d", this, input->status, | 
					
						
							|  |  |  | 			input->buffer_id, | 
					
						
							|  |  |  | 			this->n_buffers); | 
					
						
							| 
									
										
										
										
											2018-03-08 11:02:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-16 16:55:25 +01:00
										 |  |  | 	if (input->status == SPA_STATUS_HAVE_BUFFER && | 
					
						
							|  |  |  | 	    input->buffer_id < this->n_buffers) { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		struct buffer *b = &this->buffers[input->buffer_id]; | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-08 11:02:21 +01:00
										 |  |  | 		if (!SPA_FLAG_CHECK(b->flags, BUFFER_FLAG_OUT)) { | 
					
						
							| 
									
										
										
										
											2018-03-16 16:55:25 +01:00
										 |  |  | 			spa_log_warn(this->log, NAME " %p: buffer %u in use", | 
					
						
							|  |  |  | 					this, input->buffer_id); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			input->status = -EINVAL; | 
					
						
							|  |  |  | 			return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		spa_log_trace(this->log, NAME " %p: queue buffer %u", this, input->buffer_id); | 
					
						
							| 
									
										
										
										
											2017-10-24 12:58:10 +02:00
										 |  |  | 		spa_list_append(&this->ready, &b->link); | 
					
						
							| 
									
										
										
										
											2018-03-08 11:02:21 +01:00
										 |  |  | 		SPA_FLAG_UNSET(b->flags, BUFFER_FLAG_OUT); | 
					
						
							| 
									
										
										
										
											2018-11-12 09:56:45 +01:00
										 |  |  | 		input->buffer_id = SPA_ID_INVALID; | 
					
						
							| 
									
										
										
										
											2018-03-09 12:36:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-19 12:01:36 +01:00
										 |  |  | 		spa_alsa_write(this, 0, true); | 
					
						
							| 
									
										
										
										
											2018-04-19 22:00:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-09 12:36:23 +01:00
										 |  |  | 		input->status = SPA_STATUS_OK; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-21 15:30:55 +01:00
										 |  |  | 	return SPA_STATUS_HAVE_BUFFER; | 
					
						
							| 
									
										
										
										
											2016-11-07 18:23:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 13:28:15 +02:00
										 |  |  | static const struct spa_node impl_node = { | 
					
						
							| 
									
										
										
										
											2017-06-14 18:32:39 +02:00
										 |  |  | 	SPA_VERSION_NODE, | 
					
						
							| 
									
										
										
										
											2019-02-18 12:31:36 +01:00
										 |  |  | 	.set_callbacks = impl_node_set_callbacks, | 
					
						
							|  |  |  | 	.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_alloc_buffers = impl_node_port_alloc_buffers, | 
					
						
							|  |  |  | 	.port_set_io = impl_node_port_set_io, | 
					
						
							|  |  |  | 	.port_reuse_buffer = impl_node_port_reuse_buffer, | 
					
						
							|  |  |  | 	.process = impl_node_process, | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | static int impl_get_interface(struct spa_handle *handle, uint32_t type, void **interface) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							| 
									
										
										
										
											2016-07-30 20:35:34 +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-06-28 12:21:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	this = (struct state *) handle; | 
					
						
							| 
									
										
										
										
											2016-07-30 20:35:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 	if (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-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | static int impl_clear(struct spa_handle *handle) | 
					
						
							| 
									
										
										
										
											2016-09-01 10:04:25 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-09-01 10:04:25 +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) | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	struct state *this; | 
					
						
							|  |  |  | 	uint32_t i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	for (i = 0; i < n_support; i++) { | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 		if (support[i].type == SPA_TYPE_INTERFACE_Log) | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 			this->log = support[i].data; | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 		else if (support[i].type == SPA_TYPE_INTERFACE_DataLoop) | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 			this->data_loop = support[i].data; | 
					
						
							| 
									
										
										
										
											2018-08-27 15:03:11 +02:00
										 |  |  | 		else if (support[i].type == SPA_TYPE_INTERFACE_MainLoop) | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 			this->main_loop = support[i].data; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (this->data_loop == NULL) { | 
					
						
							|  |  |  | 		spa_log_error(this->log, "a data loop is needed"); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (this->main_loop == NULL) { | 
					
						
							|  |  |  | 		spa_log_error(this->log, "a main loop is needed"); | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return -EINVAL; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	this->node = impl_node; | 
					
						
							|  |  |  | 	this->stream = SND_PCM_STREAM_PLAYBACK; | 
					
						
							|  |  |  | 	reset_props(&this->props); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-14 17:08:46 +01:00
										 |  |  | 	this->info = SPA_PORT_INFO_INIT(); | 
					
						
							|  |  |  | 	this->info.change_mask |= SPA_PORT_CHANGE_MASK_FLAGS; | 
					
						
							| 
									
										
										
										
											2019-02-14 17:40:01 +01:00
										 |  |  | 	this->info.flags = SPA_PORT_FLAG_CAN_USE_BUFFERS | | 
					
						
							|  |  |  | 			   SPA_PORT_FLAG_LIVE | | 
					
						
							|  |  |  | 			   SPA_PORT_FLAG_PHYSICAL | | 
					
						
							|  |  |  | 			   SPA_PORT_FLAG_TERMINAL; | 
					
						
							| 
									
										
										
										
											2017-11-30 16:36:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	spa_list_init(&this->ready); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; info && i < info->n_items; i++) { | 
					
						
							| 
									
										
										
										
											2018-11-23 17:41:39 +01:00
										 |  |  | 		if (!strcmp(info->items[i].key, "alsa.device")) { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 			snprintf(this->props.device, 63, "%s", info->items[i].value); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2016-06-28 12:21:56 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-07-13 18:29:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-07-13 18:29:55 +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, | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 			 const struct spa_interface_info **info, uint32_t *index) | 
					
						
							| 
									
										
										
										
											2016-07-13 18:29:55 +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); | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	switch (*index) { | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	case 0: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		*info = &impl_interfaces[*index]; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-13 09:41:41 +01:00
										 |  |  | 	(*index)++; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2016-07-13 18:29:55 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 19:55:22 +02:00
										 |  |  | static const struct spa_dict_item info_items[] = { | 
					
						
							|  |  |  | 	{ "factory.author", "Wim Taymans <wim.taymans@gmail.com>" }, | 
					
						
							|  |  |  | 	{ "factory.description", "Play audio with the alsa API" }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-05-26 08:05:01 +02:00
										 |  |  | const struct spa_handle_factory spa_alsa_sink_factory = { | 
					
						
							| 
									
										
										
										
											2017-06-14 18:32:39 +02:00
										 |  |  | 	SPA_VERSION_HANDLE_FACTORY, | 
					
						
							| 
									
										
										
										
											2017-05-26 08:05:01 +02:00
										 |  |  | 	NAME, | 
					
						
							| 
									
										
										
										
											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-07-13 18:29:55 +02:00
										 |  |  | }; |