2023-02-08 18:12:00 +01:00
|
|
|
/* Spa Media Sink */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2018-01-11 10:23:37 +01:00
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
2019-10-25 15:01:02 +02:00
|
|
|
#include <spa/support/plugin.h>
|
2018-01-11 10:23:37 +01:00
|
|
|
#include <spa/support/loop.h>
|
|
|
|
|
#include <spa/support/log.h>
|
2019-06-06 15:21:40 +02:00
|
|
|
#include <spa/support/system.h>
|
2018-01-11 10:23:37 +01:00
|
|
|
#include <spa/utils/list.h>
|
2019-06-03 16:48:01 +02:00
|
|
|
#include <spa/utils/keys.h>
|
2019-06-21 13:31:34 +02:00
|
|
|
#include <spa/utils/names.h>
|
2019-10-25 15:01:02 +02:00
|
|
|
#include <spa/utils/result.h>
|
2021-05-18 11:36:13 +10:00
|
|
|
#include <spa/utils/string.h>
|
2019-06-03 16:48:01 +02:00
|
|
|
#include <spa/monitor/device.h>
|
2018-01-11 10:23:37 +01:00
|
|
|
|
|
|
|
|
#include <spa/node/node.h>
|
2019-05-20 10:14:00 +02:00
|
|
|
#include <spa/node/utils.h>
|
2018-01-11 10:23:37 +01:00
|
|
|
#include <spa/node/io.h>
|
2019-11-18 10:10:58 +01:00
|
|
|
#include <spa/node/keys.h>
|
2018-08-25 12:08:29 +02:00
|
|
|
#include <spa/param/param.h>
|
2021-05-28 19:02:06 +08:00
|
|
|
#include <spa/param/latency-utils.h>
|
2018-01-11 10:23:37 +01:00
|
|
|
#include <spa/param/audio/format.h>
|
|
|
|
|
#include <spa/param/audio/format-utils.h>
|
2018-08-13 17:17:23 +02:00
|
|
|
#include <spa/pod/filter.h>
|
2023-01-18 17:41:16 +01:00
|
|
|
#include <spa/debug/mem.h>
|
|
|
|
|
#include <spa/debug/log.h>
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-19 14:14:27 +02:00
|
|
|
#include <bluetooth/bluetooth.h>
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
#include <sbc/sbc.h>
|
|
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
#include "rtp.h"
|
2022-06-15 17:24:41 +02:00
|
|
|
#include "media-codecs.h"
|
2023-03-03 23:56:58 +02:00
|
|
|
#include "rate-control.h"
|
2023-03-25 18:01:43 +02:00
|
|
|
#include "iso-io.h"
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-12-23 21:07:45 +02:00
|
|
|
SPA_LOG_TOPIC_DEFINE_STATIC(log_topic, "spa.bluez5.sink.media");
|
2021-10-01 19:03:49 +03:00
|
|
|
#undef SPA_LOG_TOPIC_DEFAULT
|
|
|
|
|
#define SPA_LOG_TOPIC_DEFAULT &log_topic
|
2020-10-19 09:33:49 +02:00
|
|
|
|
2024-02-20 23:01:07 +02:00
|
|
|
#include "bt-latency.h"
|
|
|
|
|
|
2021-12-10 12:31:44 +01:00
|
|
|
#define DEFAULT_CLOCK_NAME "clock.system.monotonic"
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
struct props {
|
2021-02-13 22:59:04 +02:00
|
|
|
int64_t latency_offset;
|
2021-12-10 12:31:44 +01:00
|
|
|
char clock_name[64];
|
2018-01-11 10:23:37 +01:00
|
|
|
};
|
|
|
|
|
|
2022-07-10 16:35:07 +03:00
|
|
|
#define FILL_FRAMES 4
|
2023-12-04 21:32:05 +02:00
|
|
|
#define MIN_BUFFERS 3
|
2018-01-11 10:23:37 +01:00
|
|
|
#define MAX_BUFFERS 32
|
2022-07-09 18:06:36 +03:00
|
|
|
#define BUFFER_SIZE (8192*8)
|
2025-07-11 17:13:31 +03:00
|
|
|
#define RATE_CTL_DIFF_MAX 0.01
|
2024-02-20 23:01:07 +02:00
|
|
|
#define LATENCY_PERIOD (200 * SPA_NSEC_PER_MSEC)
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-04-09 19:53:42 +03:00
|
|
|
/* Wait for two cycles before trying to sync ISO. On start/driver reassign,
|
|
|
|
|
* first cycle may have strange number of samples. */
|
|
|
|
|
#define RESYNC_CYCLES 2
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
struct buffer {
|
2019-01-07 17:57:03 +01:00
|
|
|
uint32_t id;
|
2020-09-02 17:04:19 +02:00
|
|
|
#define BUFFER_FLAG_OUT (1<<0)
|
|
|
|
|
uint32_t flags;
|
2018-05-17 17:26:09 +02:00
|
|
|
struct spa_buffer *buf;
|
2018-01-11 10:23:37 +01:00
|
|
|
struct spa_meta_header *h;
|
|
|
|
|
struct spa_list link;
|
|
|
|
|
};
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port {
|
|
|
|
|
struct spa_audio_info current_format;
|
2020-12-05 08:30:14 +01:00
|
|
|
uint32_t frame_size;
|
2019-05-15 10:20:28 +02:00
|
|
|
unsigned int have_format:1;
|
2019-02-27 16:43:01 +01:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
uint64_t info_all;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_port_info info;
|
|
|
|
|
struct spa_io_buffers *io;
|
2023-03-03 23:56:58 +02:00
|
|
|
struct spa_io_rate_match *rate_match;
|
2021-05-28 19:02:06 +08:00
|
|
|
struct spa_latency_info latency;
|
2021-05-28 16:42:22 +08:00
|
|
|
#define IDX_EnumFormat 0
|
|
|
|
|
#define IDX_Meta 1
|
|
|
|
|
#define IDX_IO 2
|
|
|
|
|
#define IDX_Format 3
|
|
|
|
|
#define IDX_Buffers 4
|
2021-05-28 19:02:06 +08:00
|
|
|
#define IDX_Latency 5
|
|
|
|
|
#define N_PORT_PARAMS 6
|
2021-05-28 16:42:22 +08:00
|
|
|
struct spa_param_info params[N_PORT_PARAMS];
|
2019-02-27 16:43:01 +01:00
|
|
|
|
|
|
|
|
struct buffer buffers[MAX_BUFFERS];
|
2019-05-15 10:20:28 +02:00
|
|
|
uint32_t n_buffers;
|
2019-02-27 16:43:01 +01:00
|
|
|
|
|
|
|
|
struct spa_list free;
|
|
|
|
|
struct spa_list ready;
|
|
|
|
|
|
|
|
|
|
size_t ready_offset;
|
2023-03-03 23:56:58 +02:00
|
|
|
|
|
|
|
|
struct spa_bt_rate_control ratectl;
|
2019-02-27 16:43:01 +01:00
|
|
|
};
|
|
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
#define ASHA_ENCODED_PKT_SZ 161 /* 160 bytes encoded + 1 byte sequence number */
|
2025-04-21 06:08:47 -04:00
|
|
|
#define ASHA_CONN_INTERVAL (20 * SPA_NSEC_PER_MSEC)
|
2025-02-10 22:16:44 +05:30
|
|
|
|
|
|
|
|
struct spa_bt_asha {
|
|
|
|
|
struct spa_source flush_source;
|
|
|
|
|
struct spa_source timer_source;
|
|
|
|
|
int timerfd;
|
|
|
|
|
|
|
|
|
|
uint8_t buf[512];
|
|
|
|
|
|
2025-04-21 06:08:47 -04:00
|
|
|
uint64_t ref_t0;
|
2025-02-10 22:16:44 +05:30
|
|
|
uint64_t next_time;
|
|
|
|
|
|
|
|
|
|
unsigned int flush_pending:1;
|
|
|
|
|
unsigned int set_timer:1;
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
struct impl {
|
|
|
|
|
struct spa_handle handle;
|
|
|
|
|
struct spa_node node;
|
|
|
|
|
|
|
|
|
|
struct spa_log *log;
|
|
|
|
|
struct spa_loop *data_loop;
|
2019-06-06 15:21:40 +02:00
|
|
|
struct spa_system *data_system;
|
2024-03-01 22:17:58 +02:00
|
|
|
struct spa_loop_utils *loop_utils;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook_list hooks;
|
2019-05-15 12:17:52 +02:00
|
|
|
struct spa_callbacks callbacks;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
uint32_t quantum_limit;
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
uint64_t info_all;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_node_info info;
|
2021-05-28 16:42:22 +08:00
|
|
|
#define IDX_PropInfo 0
|
|
|
|
|
#define IDX_Props 1
|
|
|
|
|
#define N_NODE_PARAMS 2
|
|
|
|
|
struct spa_param_info params[N_NODE_PARAMS];
|
2018-01-11 10:23:37 +01:00
|
|
|
struct props props;
|
|
|
|
|
|
|
|
|
|
struct spa_bt_transport *transport;
|
2019-05-14 18:10:18 +02:00
|
|
|
struct spa_hook transport_listener;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port port;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-04-24 12:41:16 +02:00
|
|
|
unsigned int started:1;
|
2023-03-06 22:40:33 +02:00
|
|
|
unsigned int start_ready:1;
|
|
|
|
|
unsigned int transport_started:1;
|
2020-02-21 10:47:32 +01:00
|
|
|
unsigned int following:1;
|
2022-07-22 11:01:18 +02:00
|
|
|
unsigned int is_output:1;
|
2022-07-09 18:06:36 +03:00
|
|
|
unsigned int flush_pending:1;
|
2023-04-09 19:53:42 +03:00
|
|
|
unsigned int iso_pending:1;
|
2023-04-09 21:28:40 +03:00
|
|
|
unsigned int own_codec_data:1;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-05-22 19:08:56 +03:00
|
|
|
unsigned int is_duplex:1;
|
2023-03-13 19:17:34 +02:00
|
|
|
unsigned int is_internal:1;
|
2022-05-22 19:08:56 +03:00
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
struct spa_source source;
|
|
|
|
|
int timerfd;
|
|
|
|
|
struct spa_source flush_source;
|
2021-11-06 12:54:02 +02:00
|
|
|
struct spa_source flush_timer_source;
|
|
|
|
|
int flush_timerfd;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-04-24 12:41:16 +02:00
|
|
|
struct spa_io_clock *clock;
|
|
|
|
|
struct spa_io_position *position;
|
|
|
|
|
|
2020-10-16 13:13:04 +02:00
|
|
|
uint64_t current_time;
|
|
|
|
|
uint64_t next_time;
|
|
|
|
|
uint64_t last_error;
|
2022-07-09 18:06:36 +03:00
|
|
|
uint64_t process_time;
|
2023-03-25 18:01:43 +02:00
|
|
|
uint64_t process_duration;
|
|
|
|
|
uint64_t process_rate;
|
2025-07-11 15:54:08 +03:00
|
|
|
double process_rate_diff;
|
2022-07-09 18:06:36 +03:00
|
|
|
|
|
|
|
|
uint64_t prev_flush_time;
|
|
|
|
|
uint64_t next_flush_time;
|
2020-10-16 13:13:04 +02:00
|
|
|
|
2024-01-26 21:00:35 +02:00
|
|
|
uint64_t packet_delay_ns;
|
2024-03-01 22:17:58 +02:00
|
|
|
struct spa_source *update_delay_event;
|
2024-01-26 21:00:35 +02:00
|
|
|
|
2024-02-23 21:04:47 +02:00
|
|
|
uint32_t encoder_delay;
|
|
|
|
|
|
2022-06-15 17:24:41 +02:00
|
|
|
const struct media_codec *codec;
|
2021-03-20 14:53:18 +08:00
|
|
|
bool codec_props_changed;
|
|
|
|
|
void *codec_props;
|
2020-10-19 09:33:49 +02:00
|
|
|
void *codec_data;
|
2020-10-19 10:38:22 +02:00
|
|
|
struct spa_audio_info codec_format;
|
2020-10-19 09:33:49 +02:00
|
|
|
|
2021-03-31 17:50:15 +08:00
|
|
|
int need_flush;
|
2022-04-30 20:54:32 +03:00
|
|
|
bool fragment;
|
2023-04-09 19:53:42 +03:00
|
|
|
uint32_t resync;
|
2020-12-05 08:30:14 +01:00
|
|
|
uint32_t block_size;
|
2021-11-06 12:54:02 +02:00
|
|
|
uint8_t buffer[BUFFER_SIZE];
|
2020-12-05 08:30:14 +01:00
|
|
|
uint32_t buffer_used;
|
2021-03-31 17:50:15 +08:00
|
|
|
uint32_t header_size;
|
2022-07-09 18:06:36 +03:00
|
|
|
uint32_t block_count;
|
2018-01-11 10:23:37 +01:00
|
|
|
uint16_t seqnum;
|
2025-02-10 22:16:44 +05:30
|
|
|
uint64_t last_seqnum;
|
2018-01-11 10:23:37 +01:00
|
|
|
uint32_t timestamp;
|
2020-10-16 13:13:04 +02:00
|
|
|
uint64_t sample_count;
|
2021-11-06 12:54:02 +02:00
|
|
|
uint8_t tmp_buffer[BUFFER_SIZE];
|
2020-12-05 08:30:14 +01:00
|
|
|
uint32_t tmp_buffer_used;
|
2020-12-19 08:21:40 +08:00
|
|
|
uint32_t fd_buffer_size;
|
2025-10-11 18:38:38 +03:00
|
|
|
uint32_t silence_frames;
|
2025-02-10 22:16:44 +05:30
|
|
|
|
|
|
|
|
struct spa_bt_asha *asha;
|
|
|
|
|
struct spa_list asha_link;
|
2024-03-02 19:28:22 +02:00
|
|
|
|
|
|
|
|
struct spa_bt_latency tx_latency;
|
2020-10-19 09:33:49 +02:00
|
|
|
};
|
|
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) == 0)
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2025-04-28 11:42:42 +05:30
|
|
|
static struct spa_list asha_sinks = SPA_LIST_INIT(&asha_sinks);
|
2025-02-10 22:16:44 +05:30
|
|
|
|
2025-04-28 11:42:42 +05:30
|
|
|
static void drop_frames(struct impl *this, uint32_t req);
|
2025-04-22 16:41:30 -04:00
|
|
|
static uint64_t get_reference_time(struct impl *this, uint64_t *duration_ns_ret);
|
|
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
static struct impl *find_other_asha(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
struct impl *other;
|
|
|
|
|
|
|
|
|
|
spa_list_for_each(other, &asha_sinks, asha_link) {
|
|
|
|
|
if (this == other)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (this->transport->hisyncid == other->transport->hisyncid) {
|
|
|
|
|
return other;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-15 22:45:47 +03:00
|
|
|
static void reset_props(struct impl *this, struct props *props)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2021-02-13 22:59:04 +02:00
|
|
|
props->latency_offset = 0;
|
2021-12-10 12:31:44 +01:00
|
|
|
strncpy(props->clock_name, DEFAULT_CLOCK_NAME, sizeof(props->clock_name));
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_enum_params(void *object, int seq,
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t id, uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_pod *filter)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2018-01-11 10:23:37 +01:00
|
|
|
struct spa_pod *param;
|
|
|
|
|
struct spa_pod_builder b = { 0 };
|
|
|
|
|
uint8_t buffer[1024];
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params result;
|
2021-03-20 14:53:18 +08:00
|
|
|
uint32_t count = 0, index_offset = 0;
|
|
|
|
|
bool enum_codec = false;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_return_val_if_fail(num != 0, -EINVAL);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
result.id = id;
|
2019-02-20 17:51:05 +01:00
|
|
|
result.next = start;
|
2018-01-11 10:23:37 +01:00
|
|
|
next:
|
2019-02-25 12:29:57 +01:00
|
|
|
result.index = result.next++;
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
switch (id) {
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_PropInfo:
|
2018-08-23 17:47:57 +02:00
|
|
|
{
|
2019-02-25 12:29:57 +01:00
|
|
|
switch (result.index) {
|
2018-01-11 10:23:37 +01:00
|
|
|
case 0:
|
2021-02-13 22:59:04 +02:00
|
|
|
param = spa_pod_builder_add_object(&b,
|
|
|
|
|
SPA_TYPE_OBJECT_PropInfo, id,
|
|
|
|
|
SPA_PROP_INFO_id, SPA_POD_Id(SPA_PROP_latencyOffsetNsec),
|
2022-03-30 17:09:08 +02:00
|
|
|
SPA_PROP_INFO_description, SPA_POD_String("Latency offset (ns)"),
|
2021-09-02 15:17:36 +02:00
|
|
|
SPA_PROP_INFO_type, SPA_POD_CHOICE_RANGE_Long(0LL, INT64_MIN, INT64_MAX));
|
2021-02-13 22:59:04 +02:00
|
|
|
break;
|
2018-01-11 10:23:37 +01:00
|
|
|
default:
|
2021-03-20 14:53:18 +08:00
|
|
|
enum_codec = true;
|
2022-07-09 18:06:36 +03:00
|
|
|
index_offset = 1;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_Props:
|
2018-08-23 17:47:57 +02:00
|
|
|
{
|
2018-01-11 10:23:37 +01:00
|
|
|
struct props *p = &this->props;
|
|
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
switch (result.index) {
|
2018-01-11 10:23:37 +01:00
|
|
|
case 0:
|
2019-01-16 11:05:12 +01:00
|
|
|
param = spa_pod_builder_add_object(&b,
|
2018-08-27 15:03:11 +02:00
|
|
|
SPA_TYPE_OBJECT_Props, id,
|
2021-02-13 22:59:04 +02:00
|
|
|
SPA_PROP_latencyOffsetNsec, SPA_POD_Long(p->latency_offset));
|
2018-01-11 10:23:37 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2021-03-20 14:53:18 +08:00
|
|
|
enum_codec = true;
|
|
|
|
|
index_offset = 1;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2018-08-23 17:47:57 +02:00
|
|
|
default:
|
2018-01-11 10:23:37 +01:00
|
|
|
return -ENOENT;
|
2018-08-23 17:47:57 +02:00
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2021-03-20 14:53:18 +08:00
|
|
|
if (enum_codec) {
|
|
|
|
|
int res;
|
2021-10-11 11:22:36 +02:00
|
|
|
if (this->codec->enum_props == NULL || this->codec_props == NULL ||
|
|
|
|
|
this->transport == NULL)
|
2021-03-20 14:53:18 +08:00
|
|
|
return 0;
|
|
|
|
|
else if ((res = this->codec->enum_props(this->codec_props,
|
|
|
|
|
this->transport->device->settings,
|
|
|
|
|
id, result.index - index_offset, &b, ¶m)) != 1)
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
|
|
|
|
goto next;
|
|
|
|
|
|
2019-05-28 13:59:48 +02:00
|
|
|
spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
if (++count != num)
|
2018-01-11 10:23:37 +01:00
|
|
|
goto next;
|
|
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-16 13:13:04 +02:00
|
|
|
static int set_timeout(struct impl *this, uint64_t time)
|
2019-04-24 12:41:16 +02:00
|
|
|
{
|
|
|
|
|
struct itimerspec ts;
|
2020-10-16 13:13:04 +02:00
|
|
|
ts.it_value.tv_sec = time / SPA_NSEC_PER_SEC;
|
|
|
|
|
ts.it_value.tv_nsec = time % SPA_NSEC_PER_SEC;
|
2019-04-24 12:41:16 +02:00
|
|
|
ts.it_interval.tv_sec = 0;
|
|
|
|
|
ts.it_interval.tv_nsec = 0;
|
2020-10-16 13:13:04 +02:00
|
|
|
return spa_system_timerfd_settime(this->data_system,
|
|
|
|
|
this->timerfd, SPA_FD_TIMER_ABSTIME, &ts, NULL);
|
|
|
|
|
}
|
2019-04-24 12:41:16 +02:00
|
|
|
|
2020-10-16 13:13:04 +02:00
|
|
|
static int set_timers(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
struct timespec now;
|
|
|
|
|
|
|
|
|
|
spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &now);
|
|
|
|
|
this->next_time = SPA_TIMESPEC_TO_NSEC(&now);
|
|
|
|
|
|
|
|
|
|
return set_timeout(this, this->following ? 0 : this->next_time);
|
2019-04-24 12:41:16 +02:00
|
|
|
}
|
|
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
static int set_asha_timeout(struct impl *this, uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
struct itimerspec ts;
|
|
|
|
|
|
|
|
|
|
ts.it_value.tv_sec = time / SPA_NSEC_PER_SEC;
|
|
|
|
|
ts.it_value.tv_nsec = time % SPA_NSEC_PER_SEC;
|
|
|
|
|
ts.it_interval.tv_sec = 0;
|
|
|
|
|
ts.it_interval.tv_nsec = 0;
|
|
|
|
|
|
|
|
|
|
return spa_system_timerfd_settime(this->data_system,
|
|
|
|
|
this->asha->timerfd, SPA_FD_TIMER_ABSTIME, &ts, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-22 16:41:30 -04:00
|
|
|
static int set_asha_timer(struct impl *this, struct impl *other)
|
2025-02-10 22:16:44 +05:30
|
|
|
{
|
2025-04-22 16:41:30 -04:00
|
|
|
uint64_t time;
|
|
|
|
|
|
|
|
|
|
if (other) {
|
|
|
|
|
/* Try to line up our timer with the other side, and drop samples so we're sending
|
|
|
|
|
* the same sample position on both sides */
|
|
|
|
|
uint64_t other_samples = (get_reference_time(other, NULL) - other->asha->ref_t0) *
|
|
|
|
|
this->port.current_format.info.raw.rate / SPA_NSEC_PER_SEC;
|
|
|
|
|
|
|
|
|
|
if (other->asha->next_time < this->process_time) {
|
|
|
|
|
/* Other side has not yet been scheduled in this graph cycle, we expect
|
|
|
|
|
* there might be one packet left from the previous cycle at most */
|
|
|
|
|
time = other->asha->next_time + ASHA_CONN_INTERVAL;
|
|
|
|
|
other_samples += ASHA_CONN_INTERVAL *
|
|
|
|
|
this->port.current_format.info.raw.rate / SPA_NSEC_PER_SEC;
|
|
|
|
|
} else {
|
|
|
|
|
/* Other side has set up its next cycle, catch up */
|
|
|
|
|
time = other->asha->next_time;
|
|
|
|
|
}
|
2025-04-21 06:49:42 -04:00
|
|
|
|
2025-04-22 16:41:30 -04:00
|
|
|
/* Since the quantum and packet size aren't correlated, drop any samples from this
|
|
|
|
|
* cycle that might have been used to send a packet starting in the previous cycle */
|
2025-04-28 11:42:42 +05:30
|
|
|
drop_frames(this, other_samples % this->process_duration);
|
2025-04-21 06:49:42 -04:00
|
|
|
} else {
|
2025-04-22 16:41:30 -04:00
|
|
|
time = this->process_time;
|
2025-04-21 06:49:42 -04:00
|
|
|
}
|
|
|
|
|
|
2025-04-22 16:41:30 -04:00
|
|
|
this->asha->next_time = time;
|
2025-02-10 22:16:44 +05:30
|
|
|
|
|
|
|
|
return set_asha_timeout(this, this->asha->next_time);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
static inline bool is_following(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
return this->position && this->clock && this->position->clock.id != this->clock->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct reassign_io_info {
|
|
|
|
|
struct impl *this;
|
|
|
|
|
struct spa_io_position *position;
|
|
|
|
|
struct spa_io_clock *clock;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int do_reassign_io(struct spa_loop *loop,
|
2019-04-24 12:41:16 +02:00
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
const void *data,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
2023-03-25 18:01:43 +02:00
|
|
|
struct reassign_io_info *info = user_data;
|
|
|
|
|
struct impl *this = info->this;
|
|
|
|
|
bool following;
|
2019-04-24 12:41:16 +02:00
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
if (this->position != info->position || this->clock != info->clock)
|
2023-04-09 19:53:42 +03:00
|
|
|
this->resync = RESYNC_CYCLES;
|
2023-03-25 18:01:43 +02:00
|
|
|
|
|
|
|
|
this->position = info->position;
|
|
|
|
|
this->clock = info->clock;
|
|
|
|
|
|
|
|
|
|
following = is_following(this);
|
|
|
|
|
|
|
|
|
|
if (following != this->following) {
|
|
|
|
|
spa_log_debug(this->log, "%p: reassign follower %d->%d", this, this->following, following);
|
|
|
|
|
this->following = following;
|
|
|
|
|
set_timers(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2019-05-15 10:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
|
2018-10-23 12:31:41 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2023-03-25 18:01:43 +02:00
|
|
|
struct reassign_io_info info = { .this = this, .position = this->position, .clock = this->clock };
|
2019-04-24 12:41:16 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-04-24 12:41:16 +02:00
|
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
|
case SPA_IO_Clock:
|
2023-03-25 18:01:43 +02:00
|
|
|
info.clock = data;
|
|
|
|
|
if (info.clock != NULL) {
|
|
|
|
|
spa_scnprintf(info.clock->name,
|
|
|
|
|
sizeof(info.clock->name),
|
2021-12-10 12:31:44 +01:00
|
|
|
"%s", this->props.clock_name);
|
|
|
|
|
}
|
2019-04-24 12:41:16 +02:00
|
|
|
break;
|
|
|
|
|
case SPA_IO_Position:
|
2023-03-25 18:01:43 +02:00
|
|
|
info.position = data;
|
2019-04-24 12:41:16 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
if (this->started) {
|
2025-05-30 11:59:35 +02:00
|
|
|
spa_loop_locked(this->data_loop, do_reassign_io, 0, NULL, 0, &info);
|
2023-03-25 18:01:43 +02:00
|
|
|
} else {
|
|
|
|
|
this->clock = info.clock;
|
|
|
|
|
this->position = info.position;
|
2019-04-24 12:41:16 +02:00
|
|
|
}
|
2023-03-25 18:01:43 +02:00
|
|
|
|
2018-10-30 16:29:39 +00:00
|
|
|
return 0;
|
2018-10-23 12:31:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 19:55:04 +02:00
|
|
|
static void emit_node_info(struct impl *this, bool full);
|
|
|
|
|
|
2021-05-28 19:02:06 +08:00
|
|
|
static void emit_port_info(struct impl *this, struct port *port, bool full);
|
|
|
|
|
|
|
|
|
|
static void set_latency(struct impl *this, bool emit_latency)
|
|
|
|
|
{
|
|
|
|
|
struct port *port = &this->port;
|
|
|
|
|
int64_t delay;
|
|
|
|
|
|
2024-03-01 22:17:58 +02:00
|
|
|
/* in main loop */
|
2024-01-26 21:00:35 +02:00
|
|
|
|
2024-02-23 21:04:47 +02:00
|
|
|
if (this->transport == NULL || !port->have_format)
|
2021-05-28 19:02:06 +08:00
|
|
|
return;
|
|
|
|
|
|
2024-01-26 21:00:35 +02:00
|
|
|
/*
|
|
|
|
|
* We start flushing data immediately, so the delay is:
|
|
|
|
|
*
|
|
|
|
|
* (packet delay) + (codec internal delay) + (transport delay) + (latency offset)
|
|
|
|
|
*
|
2024-02-23 21:04:47 +02:00
|
|
|
* and doesn't depend on the quantum. Kernel knows the latency due to
|
|
|
|
|
* socket/controller queue, but doesn't tell us, so not included but
|
|
|
|
|
* hopefully in < 10 ms range.
|
2024-01-26 21:00:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
delay = __atomic_load_n(&this->packet_delay_ns, __ATOMIC_RELAXED);
|
2024-02-23 21:04:47 +02:00
|
|
|
delay += (int64_t)this->encoder_delay * SPA_NSEC_PER_SEC / port->current_format.info.raw.rate;
|
2024-01-26 21:00:35 +02:00
|
|
|
delay += spa_bt_transport_get_delay_nsec(this->transport);
|
2021-05-28 19:02:06 +08:00
|
|
|
delay += SPA_CLAMP(this->props.latency_offset, -delay, INT64_MAX / 2);
|
2024-01-26 21:00:35 +02:00
|
|
|
delay = SPA_MAX(delay, 0);
|
|
|
|
|
|
2021-05-28 19:02:06 +08:00
|
|
|
port->latency.min_ns = port->latency.max_ns = delay;
|
2024-01-26 21:00:35 +02:00
|
|
|
port->latency.min_rate = port->latency.max_rate = 0;
|
2025-03-08 11:35:35 +02:00
|
|
|
|
2025-07-11 18:36:07 +03:00
|
|
|
if (this->codec->kind == MEDIA_CODEC_BAP) {
|
2025-03-08 11:35:35 +02:00
|
|
|
/* ISO has different delay */
|
|
|
|
|
port->latency.min_quantum = port->latency.max_quantum = 1.0f;
|
|
|
|
|
} else {
|
|
|
|
|
port->latency.min_quantum = port->latency.max_quantum = 0.0f;
|
|
|
|
|
}
|
2024-01-26 21:00:35 +02:00
|
|
|
|
|
|
|
|
spa_log_info(this->log, "%p: total latency:%d ms", this, (int)(delay / SPA_NSEC_PER_MSEC));
|
2021-05-28 19:02:06 +08:00
|
|
|
|
|
|
|
|
if (emit_latency) {
|
|
|
|
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
|
|
|
|
port->params[IDX_Latency].flags ^= SPA_PARAM_INFO_SERIAL;
|
|
|
|
|
emit_port_info(this, port, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 22:17:58 +02:00
|
|
|
static void update_delay_event(void *data, uint64_t count)
|
2024-01-26 21:00:35 +02:00
|
|
|
{
|
2024-03-01 22:17:58 +02:00
|
|
|
struct impl *this = data;
|
2024-01-26 21:00:35 +02:00
|
|
|
|
2024-03-01 22:17:58 +02:00
|
|
|
/* in main loop */
|
2024-01-26 21:00:35 +02:00
|
|
|
set_latency(this, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void update_packet_delay(struct impl *this, uint64_t delay)
|
|
|
|
|
{
|
|
|
|
|
uint64_t old_delay = this->packet_delay_ns;
|
|
|
|
|
|
|
|
|
|
/* in data thread */
|
|
|
|
|
|
|
|
|
|
delay = SPA_MAX(delay, old_delay);
|
|
|
|
|
if (delay == old_delay)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__atomic_store_n(&this->packet_delay_ns, delay, __ATOMIC_RELAXED);
|
2024-03-01 22:17:58 +02:00
|
|
|
if (this->update_delay_event)
|
|
|
|
|
spa_loop_utils_signal_event(this->loop_utils, this->update_delay_event);
|
2024-01-26 21:00:35 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-25 19:55:04 +02:00
|
|
|
static int apply_props(struct impl *this, const struct spa_pod *param)
|
|
|
|
|
{
|
|
|
|
|
struct props new_props = this->props;
|
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
|
|
if (param == NULL) {
|
2021-08-15 22:45:47 +03:00
|
|
|
reset_props(this, &new_props);
|
2021-02-25 19:55:04 +02:00
|
|
|
} else {
|
|
|
|
|
spa_pod_parse_object(param,
|
|
|
|
|
SPA_TYPE_OBJECT_Props, NULL,
|
|
|
|
|
SPA_PROP_latencyOffsetNsec, SPA_POD_OPT_Long(&new_props.latency_offset));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changed = (memcmp(&new_props, &this->props, sizeof(struct props)) != 0);
|
|
|
|
|
this->props = new_props;
|
2021-05-28 19:02:06 +08:00
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
|
set_latency(this, true);
|
|
|
|
|
|
2021-02-25 19:55:04 +02:00
|
|
|
return changed;
|
|
|
|
|
}
|
2021-02-13 22:59:04 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
2018-01-11 10:23:37 +01:00
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
switch (id) {
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_Props:
|
2018-08-23 17:47:57 +02:00
|
|
|
{
|
2021-03-20 14:53:18 +08:00
|
|
|
int res, codec_res = 0;
|
|
|
|
|
res = apply_props(this, param);
|
|
|
|
|
if (this->codec_props && this->codec->set_props) {
|
|
|
|
|
codec_res = this->codec->set_props(this->codec_props, param);
|
|
|
|
|
if (codec_res > 0)
|
|
|
|
|
this->codec_props_changed = true;
|
|
|
|
|
}
|
|
|
|
|
if (res > 0 || codec_res > 0) {
|
2021-02-25 19:55:04 +02:00
|
|
|
this->info.change_mask |= SPA_NODE_CHANGE_MASK_PARAMS;
|
2021-05-28 16:42:22 +08:00
|
|
|
this->params[IDX_Props].flags ^= SPA_PARAM_INFO_SERIAL;
|
2021-02-25 19:55:04 +02:00
|
|
|
emit_node_info(this, false);
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2018-08-23 17:47:57 +02:00
|
|
|
default:
|
2018-01-11 10:23:37 +01:00
|
|
|
return -ENOENT;
|
2018-08-23 17:47:57 +02:00
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-19 14:14:27 +02:00
|
|
|
static uint32_t get_queued_frames(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
struct port *port = &this->port;
|
|
|
|
|
uint32_t bytes = 0;
|
|
|
|
|
struct buffer *b;
|
|
|
|
|
|
|
|
|
|
spa_list_for_each(b, &port->ready, link) {
|
|
|
|
|
struct spa_data *d = b->buf->datas;
|
|
|
|
|
|
|
|
|
|
bytes += d[0].chunk->size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bytes > port->ready_offset)
|
|
|
|
|
bytes -= port->ready_offset;
|
|
|
|
|
else
|
|
|
|
|
bytes = 0;
|
|
|
|
|
|
2025-10-11 18:38:38 +03:00
|
|
|
bytes += this->silence_frames * this->block_size;
|
|
|
|
|
|
2023-03-19 14:14:27 +02:00
|
|
|
/* Count (partially) encoded packet */
|
|
|
|
|
bytes += this->tmp_buffer_used;
|
|
|
|
|
bytes += this->block_count * this->block_size;
|
|
|
|
|
|
|
|
|
|
return bytes / port->frame_size;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
static uint64_t get_reference_time(struct impl *this, uint64_t *duration_ns_ret)
|
2023-03-19 14:14:27 +02:00
|
|
|
{
|
|
|
|
|
struct port *port = &this->port;
|
2025-07-11 15:54:08 +03:00
|
|
|
uint64_t duration_ns;
|
|
|
|
|
int64_t t;
|
2023-04-10 18:21:19 +03:00
|
|
|
bool resampling;
|
2023-03-19 14:14:27 +02:00
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
if (!this->process_rate || !this->process_duration) {
|
|
|
|
|
if (this->position) {
|
|
|
|
|
this->process_duration = this->position->clock.duration;
|
|
|
|
|
this->process_rate = this->position->clock.rate.denom;
|
2025-07-11 15:54:08 +03:00
|
|
|
this->process_rate_diff = this->position->clock.rate_diff;
|
2023-03-25 18:01:43 +02:00
|
|
|
} else {
|
|
|
|
|
this->process_duration = 1024;
|
|
|
|
|
this->process_rate = 48000;
|
2025-07-11 15:54:08 +03:00
|
|
|
this->process_rate_diff = 1.0;
|
2023-03-25 18:01:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-19 14:14:27 +02:00
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
duration_ns = ((uint64_t)this->process_duration * SPA_NSEC_PER_SEC / this->process_rate);
|
|
|
|
|
if (duration_ns_ret)
|
|
|
|
|
*duration_ns_ret = duration_ns;
|
2023-03-19 14:14:27 +02:00
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
/* Time at the first sample in the current packet. */
|
2025-07-11 15:54:08 +03:00
|
|
|
t = duration_ns;
|
2023-03-25 18:01:43 +02:00
|
|
|
t -= ((uint64_t)get_queued_frames(this) * SPA_NSEC_PER_SEC
|
|
|
|
|
/ port->current_format.info.raw.rate);
|
2023-03-19 14:14:27 +02:00
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
/* Account for resampling delay */
|
2023-04-10 18:21:19 +03:00
|
|
|
resampling = (port->current_format.info.raw.rate != this->process_rate) || this->following;
|
2024-01-27 18:04:07 +02:00
|
|
|
if (port->rate_match && this->position && resampling) {
|
2025-01-18 11:50:16 +02:00
|
|
|
t -= (port->rate_match->delay * SPA_NSEC_PER_SEC + port->rate_match->delay_frac)
|
|
|
|
|
/ port->current_format.info.raw.rate;
|
2023-04-10 18:21:19 +03:00
|
|
|
}
|
2023-03-19 14:14:27 +02:00
|
|
|
|
2025-07-11 17:56:44 +03:00
|
|
|
if (this->process_rate_diff > 0)
|
2025-07-11 15:54:08 +03:00
|
|
|
t = (int64_t)(t / this->process_rate_diff);
|
|
|
|
|
|
2025-10-11 18:53:31 +03:00
|
|
|
if (this->transport && this->transport->iso_io && this->transport->iso_io->size)
|
|
|
|
|
t -= this->transport->iso_io->duration;
|
|
|
|
|
|
2025-07-11 15:54:08 +03:00
|
|
|
return this->process_time + t;
|
2023-03-19 14:14:27 +02:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int reset_buffer(struct impl *this)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2021-03-20 14:53:18 +08:00
|
|
|
if (this->codec_props_changed && this->codec_props
|
|
|
|
|
&& this->codec->update_props) {
|
|
|
|
|
this->codec->update_props(this->codec_data, this->codec_props);
|
|
|
|
|
this->codec_props_changed = false;
|
|
|
|
|
}
|
2021-03-31 17:50:15 +08:00
|
|
|
this->need_flush = 0;
|
2022-07-09 18:06:36 +03:00
|
|
|
this->block_count = 0;
|
2022-04-30 20:54:32 +03:00
|
|
|
this->fragment = false;
|
2025-06-07 20:18:49 +03:00
|
|
|
|
|
|
|
|
if (this->codec->kind == MEDIA_CODEC_BAP || this->codec->kind == MEDIA_CODEC_ASHA)
|
|
|
|
|
this->timestamp = get_reference_time(this, NULL) / SPA_NSEC_PER_USEC;
|
|
|
|
|
else
|
|
|
|
|
this->timestamp = this->sample_count;
|
|
|
|
|
|
2020-10-19 09:33:49 +02:00
|
|
|
this->buffer_used = this->codec->start_encode(this->codec_data,
|
|
|
|
|
this->buffer, sizeof(this->buffer),
|
2023-03-19 14:14:27 +02:00
|
|
|
++this->seqnum, this->timestamp);
|
2021-03-31 17:50:15 +08:00
|
|
|
this->header_size = this->buffer_used;
|
2018-01-18 11:57:23 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-03 23:56:58 +02:00
|
|
|
static int setup_matching(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
struct port *port = &this->port;
|
|
|
|
|
|
|
|
|
|
if (!this->transport_started)
|
|
|
|
|
port->ratectl.corr = 1.0;
|
|
|
|
|
|
|
|
|
|
if (port->rate_match) {
|
|
|
|
|
port->rate_match->rate = 1 / port->ratectl.corr;
|
|
|
|
|
|
2025-07-11 15:11:38 +03:00
|
|
|
/* We rate match in the system clock domain. If driver ticks at a
|
|
|
|
|
* different rate, we as follower must compensate.
|
|
|
|
|
*/
|
|
|
|
|
if (this->following && SPA_LIKELY(this->position &&
|
2025-07-11 17:56:44 +03:00
|
|
|
this->position->clock.rate_diff > 0))
|
2025-07-11 15:11:38 +03:00
|
|
|
port->rate_match->rate /= this->position->clock.rate_diff;
|
|
|
|
|
|
2023-03-03 23:56:58 +02:00
|
|
|
SPA_FLAG_UPDATE(port->rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE, this->following);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 19:28:22 +02:00
|
|
|
static int get_transport_unsent_size(struct impl *this)
|
2020-12-19 08:21:40 +08:00
|
|
|
{
|
|
|
|
|
int res, value;
|
2024-03-02 19:28:22 +02:00
|
|
|
|
|
|
|
|
if (this->tx_latency.enabled) {
|
|
|
|
|
res = 0;
|
|
|
|
|
value = this->tx_latency.unsent;
|
2025-06-08 13:19:05 +03:00
|
|
|
} else if (this->codec->kind == MEDIA_CODEC_HFP) {
|
|
|
|
|
value = 0;
|
2024-03-02 19:28:22 +02:00
|
|
|
} else {
|
|
|
|
|
res = ioctl(this->flush_source.fd, TIOCOUTQ, &value);
|
|
|
|
|
if (res < 0) {
|
|
|
|
|
spa_log_error(this->log, "%p: ioctl fail: %m", this);
|
|
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
if ((unsigned int)value > this->fd_buffer_size)
|
|
|
|
|
return -EIO;
|
|
|
|
|
value = this->fd_buffer_size - value;
|
2020-12-19 08:21:40 +08:00
|
|
|
}
|
2024-03-02 19:28:22 +02:00
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: fd unsent size:%d/%d", this, value, this->fd_buffer_size);
|
2020-12-19 08:21:40 +08:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int send_buffer(struct impl *this)
|
|
|
|
|
{
|
2020-12-19 08:21:40 +08:00
|
|
|
int written, unsent;
|
2024-03-02 19:28:22 +02:00
|
|
|
struct timespec ts_pre;
|
2022-07-09 18:06:36 +03:00
|
|
|
|
2025-06-08 13:19:05 +03:00
|
|
|
if (this->codec->abr_process) {
|
|
|
|
|
unsent = get_transport_unsent_size(this);
|
|
|
|
|
if (unsent >= 0)
|
|
|
|
|
this->codec->abr_process(this->codec_data, unsent);
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2024-03-02 19:28:22 +02:00
|
|
|
spa_system_clock_gettime(this->data_system, CLOCK_REALTIME, &ts_pre);
|
|
|
|
|
|
2025-06-08 13:19:05 +03:00
|
|
|
if (this->codec->kind == MEDIA_CODEC_HFP) {
|
|
|
|
|
written = spa_bt_sco_io_write(this->transport->sco_io, this->buffer, this->buffer_used);
|
|
|
|
|
} else {
|
|
|
|
|
written = spa_bt_send(this->flush_source.fd, this->buffer, this->buffer_used,
|
|
|
|
|
&this->tx_latency, SPA_TIMESPEC_TO_NSEC(&ts_pre));
|
|
|
|
|
}
|
2020-10-19 09:33:49 +02:00
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
if (SPA_UNLIKELY(spa_log_level_topic_enabled(this->log, SPA_LOG_TOPIC_DEFAULT, SPA_LOG_LEVEL_TRACE))) {
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
uint64_t now;
|
|
|
|
|
uint64_t dt;
|
|
|
|
|
|
|
|
|
|
spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &ts);
|
|
|
|
|
now = SPA_TIMESPEC_TO_NSEC(&ts);
|
|
|
|
|
dt = now - this->prev_flush_time;
|
|
|
|
|
this->prev_flush_time = now;
|
|
|
|
|
|
|
|
|
|
spa_log_trace(this->log,
|
|
|
|
|
"%p: send blocks:%d block:%u seq:%u ts:%u size:%u "
|
|
|
|
|
"wrote:%d dt:%"PRIu64,
|
|
|
|
|
this, this->block_count, this->block_size, this->seqnum,
|
|
|
|
|
this->timestamp, this->buffer_used, written, dt);
|
|
|
|
|
}
|
2021-02-08 10:24:50 +01:00
|
|
|
|
2020-12-17 02:29:04 +08:00
|
|
|
if (written < 0) {
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_debug(this->log, "%p: %m", this);
|
2018-01-18 11:57:23 +01:00
|
|
|
return -errno;
|
2020-12-17 02:29:04 +08:00
|
|
|
}
|
2018-01-18 11:57:23 +01:00
|
|
|
|
|
|
|
|
return written;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-05 08:30:14 +01:00
|
|
|
static int encode_buffer(struct impl *this, const void *data, uint32_t size)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2018-01-18 11:57:23 +01:00
|
|
|
int processed;
|
2020-11-02 09:16:59 +01:00
|
|
|
size_t out_encoded;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port = &this->port;
|
2020-06-18 20:05:25 +02:00
|
|
|
const void *from_data = data;
|
|
|
|
|
int from_size = size;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_trace(this->log, "%p: encode %d used %d, %d %d %d",
|
2020-10-19 09:33:49 +02:00
|
|
|
this, size, this->buffer_used, port->frame_size, this->block_size,
|
2022-07-09 18:06:36 +03:00
|
|
|
this->block_count);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2021-03-31 17:50:15 +08:00
|
|
|
if (this->need_flush)
|
2020-12-06 15:55:38 +01:00
|
|
|
return 0;
|
|
|
|
|
|
2020-12-05 08:30:14 +01:00
|
|
|
if (this->buffer_used >= sizeof(this->buffer))
|
2018-01-18 11:57:23 +01:00
|
|
|
return -ENOSPC;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-10-19 09:33:49 +02:00
|
|
|
if (size < this->block_size - this->tmp_buffer_used) {
|
2020-06-18 20:05:25 +02:00
|
|
|
memcpy(this->tmp_buffer + this->tmp_buffer_used, data, size);
|
|
|
|
|
this->tmp_buffer_used += size;
|
|
|
|
|
return size;
|
|
|
|
|
} else if (this->tmp_buffer_used > 0) {
|
2020-10-19 09:33:49 +02:00
|
|
|
memcpy(this->tmp_buffer + this->tmp_buffer_used, data, this->block_size - this->tmp_buffer_used);
|
2020-06-18 20:05:25 +02:00
|
|
|
from_data = this->tmp_buffer;
|
2020-10-19 09:33:49 +02:00
|
|
|
from_size = this->block_size;
|
|
|
|
|
this->tmp_buffer_used = this->block_size - this->tmp_buffer_used;
|
2020-06-18 20:05:25 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-19 09:33:49 +02:00
|
|
|
processed = this->codec->encode(this->codec_data,
|
|
|
|
|
from_data, from_size,
|
|
|
|
|
this->buffer + this->buffer_used,
|
|
|
|
|
sizeof(this->buffer) - this->buffer_used,
|
2021-03-31 17:50:15 +08:00
|
|
|
&out_encoded, &this->need_flush);
|
2018-01-18 11:57:23 +01:00
|
|
|
if (processed < 0)
|
|
|
|
|
return processed;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
this->sample_count += processed / port->frame_size;
|
2022-07-09 18:06:36 +03:00
|
|
|
this->block_count += processed / this->block_size;
|
2018-01-18 11:57:23 +01:00
|
|
|
this->buffer_used += out_encoded;
|
|
|
|
|
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_trace(this->log, "%p: processed %d %zd used %d",
|
2018-01-18 11:57:23 +01:00
|
|
|
this, processed, out_encoded, this->buffer_used);
|
|
|
|
|
|
2020-06-18 20:05:25 +02:00
|
|
|
if (this->tmp_buffer_used) {
|
|
|
|
|
processed = this->tmp_buffer_used;
|
|
|
|
|
this->tmp_buffer_used = 0;
|
|
|
|
|
}
|
2018-01-18 11:57:23 +01:00
|
|
|
return processed;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 20:54:32 +03:00
|
|
|
static int encode_fragment(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
size_t out_encoded;
|
|
|
|
|
struct port *port = &this->port;
|
|
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: encode fragment used %d, %d %d %d",
|
|
|
|
|
this, this->buffer_used, port->frame_size, this->block_size,
|
2022-07-09 18:06:36 +03:00
|
|
|
this->block_count);
|
2022-04-30 20:54:32 +03:00
|
|
|
|
|
|
|
|
if (this->need_flush)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
res = this->codec->encode(this->codec_data,
|
|
|
|
|
NULL, 0,
|
|
|
|
|
this->buffer + this->buffer_used,
|
|
|
|
|
sizeof(this->buffer) - this->buffer_used,
|
|
|
|
|
&out_encoded, &this->need_flush);
|
|
|
|
|
if (res < 0)
|
|
|
|
|
return res;
|
|
|
|
|
if (res != 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
this->buffer_used += out_encoded;
|
|
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: processed fragment %zd used %d",
|
|
|
|
|
this, out_encoded, this->buffer_used);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-08 10:24:50 +01:00
|
|
|
static int flush_buffer(struct impl *this)
|
2018-01-18 11:57:23 +01:00
|
|
|
{
|
2024-12-19 10:39:44 +05:30
|
|
|
spa_log_trace(this->log, "%p: used:%d block_size:%d need_flush:%d", this,
|
|
|
|
|
this->buffer_used, this->block_size, this->need_flush);
|
2018-01-18 11:57:23 +01:00
|
|
|
|
2021-11-06 12:54:02 +02:00
|
|
|
if (this->need_flush)
|
2018-01-18 11:57:23 +01:00
|
|
|
return send_buffer(this);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 08:30:14 +01:00
|
|
|
static int add_data(struct impl *this, const void *data, uint32_t size)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2018-01-18 11:57:23 +01:00
|
|
|
int processed, total = 0;
|
|
|
|
|
|
|
|
|
|
while (size > 0) {
|
|
|
|
|
processed = encode_buffer(this, data, size);
|
|
|
|
|
|
2020-01-10 09:55:02 +01:00
|
|
|
if (processed <= 0)
|
|
|
|
|
return total > 0 ? total : processed;
|
2018-01-18 11:57:23 +01:00
|
|
|
|
2021-05-06 13:41:44 +10:00
|
|
|
data = SPA_PTROFF(data, processed, void);
|
2018-01-18 11:57:23 +01:00
|
|
|
size -= processed;
|
|
|
|
|
total += processed;
|
|
|
|
|
}
|
|
|
|
|
return total;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
static void enable_flush_timer(struct impl *this, bool enabled)
|
2020-10-16 13:13:04 +02:00
|
|
|
{
|
2021-11-06 12:54:02 +02:00
|
|
|
struct itimerspec ts;
|
|
|
|
|
|
|
|
|
|
if (!enabled)
|
2022-07-09 18:06:36 +03:00
|
|
|
this->next_flush_time = 0;
|
2021-11-06 12:54:02 +02:00
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
ts.it_value.tv_sec = this->next_flush_time / SPA_NSEC_PER_SEC;
|
|
|
|
|
ts.it_value.tv_nsec = this->next_flush_time % SPA_NSEC_PER_SEC;
|
2021-11-06 12:54:02 +02:00
|
|
|
ts.it_interval.tv_sec = 0;
|
|
|
|
|
ts.it_interval.tv_nsec = 0;
|
|
|
|
|
spa_system_timerfd_settime(this->data_system,
|
2022-07-09 18:06:36 +03:00
|
|
|
this->flush_timerfd, SPA_FD_TIMER_ABSTIME, &ts, NULL);
|
|
|
|
|
|
|
|
|
|
this->flush_pending = enabled;
|
2020-10-16 13:13:04 +02:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int flush_data(struct impl *this, uint64_t now_time)
|
|
|
|
|
{
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port = &this->port;
|
2025-06-07 20:18:49 +03:00
|
|
|
bool is_asha = this->codec->kind == MEDIA_CODEC_ASHA;
|
2025-06-08 13:19:05 +03:00
|
|
|
bool is_sco = this->codec->kind == MEDIA_CODEC_HFP;
|
2025-02-10 22:16:44 +05:30
|
|
|
uint32_t total_frames;
|
|
|
|
|
int written;
|
2024-03-02 19:28:22 +02:00
|
|
|
int unsent_buffer;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
spa_assert(this->transport_started);
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
/* I/O in error state? */
|
2025-06-08 13:19:05 +03:00
|
|
|
if (this->transport == NULL || (!this->flush_source.loop && !is_asha && !is_sco))
|
2023-03-25 18:01:43 +02:00
|
|
|
return -EIO;
|
2025-02-10 22:16:44 +05:30
|
|
|
if (!this->flush_timer_source.loop && !this->transport->iso_io && !is_asha)
|
2022-03-06 16:47:25 +02:00
|
|
|
return -EIO;
|
2025-06-08 13:19:05 +03:00
|
|
|
if (!this->transport->sco_io && is_sco)
|
|
|
|
|
return -EIO;
|
2022-03-06 16:47:25 +02:00
|
|
|
|
2023-04-09 19:53:42 +03:00
|
|
|
if (this->transport->iso_io && !this->iso_pending)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
total_frames = 0;
|
2020-09-02 17:51:33 +02:00
|
|
|
again:
|
2021-04-10 04:45:05 +08:00
|
|
|
written = 0;
|
2022-04-30 20:54:32 +03:00
|
|
|
if (this->fragment && !this->need_flush) {
|
|
|
|
|
int res;
|
|
|
|
|
this->fragment = false;
|
|
|
|
|
if ((res = encode_fragment(this)) < 0) {
|
|
|
|
|
/* Error */
|
|
|
|
|
reset_buffer(this);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-10 22:16:44 +05:30
|
|
|
|
2025-10-11 18:38:38 +03:00
|
|
|
while (this->silence_frames && !this->need_flush) {
|
|
|
|
|
static const uint8_t empty[1024] = {};
|
|
|
|
|
uint32_t avail = SPA_MIN(this->silence_frames, sizeof(empty) / port->frame_size)
|
|
|
|
|
* port->frame_size;
|
|
|
|
|
|
|
|
|
|
written = add_data(this, empty, avail);
|
|
|
|
|
if (written <= 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
this->silence_frames -= written / port->frame_size;
|
|
|
|
|
spa_log_trace(this->log, "%p: written %d silence frames", this,
|
|
|
|
|
written / port->frame_size);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-10 04:45:05 +08:00
|
|
|
while (!spa_list_is_empty(&port->ready) && !this->need_flush) {
|
2018-01-18 11:57:23 +01:00
|
|
|
uint8_t *src;
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t n_bytes, n_frames;
|
2018-01-18 11:57:23 +01:00
|
|
|
struct buffer *b;
|
|
|
|
|
struct spa_data *d;
|
|
|
|
|
uint32_t index, offs, avail, l0, l1;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
b = spa_list_first(&port->ready, struct buffer, link);
|
2018-05-17 17:26:09 +02:00
|
|
|
d = b->buf->datas;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
src = d[0].data;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
index = d[0].chunk->offset + port->ready_offset;
|
|
|
|
|
avail = d[0].chunk->size - port->ready_offset;
|
|
|
|
|
avail /= port->frame_size;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
offs = index % d[0].maxsize;
|
|
|
|
|
n_frames = avail;
|
2019-02-27 16:43:01 +01:00
|
|
|
n_bytes = n_frames * port->frame_size;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
l0 = SPA_MIN(n_bytes, d[0].maxsize - offs);
|
|
|
|
|
l1 = n_bytes - l0;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-01-10 09:55:02 +01:00
|
|
|
written = add_data(this, src + offs, l0);
|
|
|
|
|
if (written > 0 && l1 > 0)
|
|
|
|
|
written += add_data(this, src, l1);
|
|
|
|
|
if (written <= 0) {
|
|
|
|
|
if (written < 0 && written != -ENOSPC) {
|
|
|
|
|
spa_list_remove(&b->link);
|
2020-09-02 17:04:19 +02:00
|
|
|
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
|
|
|
|
|
this->port.io->buffer_id = b->id;
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_warn(this->log, "%p: error %s, reuse buffer %u",
|
2020-01-10 09:55:02 +01:00
|
|
|
this, spa_strerror(written), b->id);
|
|
|
|
|
spa_node_call_reuse_buffer(&this->callbacks, 0, b->id);
|
|
|
|
|
port->ready_offset = 0;
|
|
|
|
|
}
|
2018-01-18 11:57:23 +01:00
|
|
|
break;
|
2019-07-12 09:55:55 +02:00
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-01-10 09:55:02 +01:00
|
|
|
n_frames = written / port->frame_size;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-01-10 09:55:02 +01:00
|
|
|
port->ready_offset += written;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
if (port->ready_offset >= d[0].chunk->size) {
|
2018-01-18 11:57:23 +01:00
|
|
|
spa_list_remove(&b->link);
|
2020-09-02 17:04:19 +02:00
|
|
|
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_trace(this->log, "%p: reuse buffer %u", this, b->id);
|
2020-09-02 17:04:19 +02:00
|
|
|
this->port.io->buffer_id = b->id;
|
2019-05-15 11:19:23 +02:00
|
|
|
|
|
|
|
|
spa_node_call_reuse_buffer(&this->callbacks, 0, b->id);
|
2019-02-27 16:43:01 +01:00
|
|
|
port->ready_offset = 0;
|
2018-01-18 11:57:23 +01:00
|
|
|
}
|
|
|
|
|
total_frames += n_frames;
|
|
|
|
|
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_trace(this->log, "%p: written %u frames", this, total_frames);
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
if (this->transport->iso_io) {
|
|
|
|
|
struct spa_bt_iso_io *iso_io = this->transport->iso_io;
|
|
|
|
|
|
2023-04-09 19:53:42 +03:00
|
|
|
if (this->need_flush) {
|
2023-03-25 18:01:43 +02:00
|
|
|
size_t avail = SPA_MIN(this->buffer_used, sizeof(iso_io->buf));
|
2025-03-08 11:35:35 +02:00
|
|
|
uint64_t delay = 0;
|
2023-03-25 18:01:43 +02:00
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: ISO put fd:%d size:%u sn:%u ts:%u now:%"PRIu64,
|
|
|
|
|
this, this->transport->fd, (unsigned)avail,
|
|
|
|
|
(unsigned)this->seqnum, (unsigned)this->timestamp,
|
|
|
|
|
iso_io->now);
|
|
|
|
|
|
|
|
|
|
memcpy(iso_io->buf, this->buffer, avail);
|
|
|
|
|
iso_io->size = avail;
|
|
|
|
|
iso_io->timestamp = this->timestamp;
|
2023-04-09 19:53:42 +03:00
|
|
|
this->iso_pending = false;
|
2023-03-25 18:01:43 +02:00
|
|
|
|
|
|
|
|
reset_buffer(this);
|
2024-01-26 21:00:35 +02:00
|
|
|
|
2025-03-08 11:35:35 +02:00
|
|
|
if (this->process_rate) {
|
|
|
|
|
/* Match target delay in media_iso_pull() */
|
|
|
|
|
delay = this->process_duration * SPA_NSEC_PER_SEC / this->process_rate;
|
|
|
|
|
if (delay < iso_io->duration*3/2)
|
|
|
|
|
delay = iso_io->duration*3/2 - delay;
|
|
|
|
|
else
|
|
|
|
|
delay = 0;
|
|
|
|
|
}
|
|
|
|
|
update_packet_delay(this, delay);
|
2023-03-25 18:01:43 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
if (is_asha) {
|
|
|
|
|
struct spa_bt_asha *asha = this->asha;
|
|
|
|
|
|
|
|
|
|
if (this->need_flush && !asha->flush_pending) {
|
|
|
|
|
/*
|
|
|
|
|
* For ASHA, we cannot send more than one encoded
|
|
|
|
|
* packet at a time and can only send them spaced
|
|
|
|
|
* 20 ms apart which is the ASHA connection interval.
|
|
|
|
|
* All encoded packets will be 160 bytes + 1 byte
|
|
|
|
|
* sequence number.
|
|
|
|
|
*
|
|
|
|
|
* Unlike the A2DP flow below, we cannot delay the
|
|
|
|
|
* output by 1 packet. While that might work for the
|
|
|
|
|
* mono case, for stereo that make the two sides be
|
|
|
|
|
* out of sync with each other and if the two sides
|
|
|
|
|
* differ by more than 3 credits, we would have to
|
|
|
|
|
* drop packets or the devices themselves might drop
|
|
|
|
|
* the connection.
|
|
|
|
|
*/
|
|
|
|
|
memcpy(asha->buf, this->buffer, this->buffer_used);
|
|
|
|
|
asha->flush_pending = true;
|
|
|
|
|
reset_buffer(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
if (this->flush_pending) {
|
|
|
|
|
spa_log_trace(this->log, "%p: wait for flush timer", this);
|
2020-12-17 02:29:04 +08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-07 20:15:29 +02:00
|
|
|
/*
|
2024-03-02 19:28:22 +02:00
|
|
|
* Get packet queue size before writing to it. This should be zero to increase
|
|
|
|
|
* bitpool. Bitpool shouldn't be increased when there is unsent data.
|
2022-11-07 20:15:29 +02:00
|
|
|
*/
|
2024-03-02 19:28:22 +02:00
|
|
|
unsent_buffer = get_transport_unsent_size(this);
|
2022-11-07 20:15:29 +02:00
|
|
|
|
2021-02-08 10:24:50 +01:00
|
|
|
written = flush_buffer(this);
|
2022-02-15 11:40:36 +02:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
if (written == -EAGAIN) {
|
2022-02-15 11:40:36 +02:00
|
|
|
spa_log_trace(this->log, "%p: fail flush", this);
|
2020-10-16 13:13:04 +02:00
|
|
|
if (now_time - this->last_error > SPA_NSEC_PER_SEC / 2) {
|
2025-06-08 13:19:05 +03:00
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
|
|
if (this->codec->reduce_bitpool)
|
|
|
|
|
res = this->codec->reduce_bitpool(this->codec_data);
|
2022-11-07 20:15:29 +02:00
|
|
|
|
|
|
|
|
spa_log_debug(this->log, "%p: reduce bitpool: %i", this, res);
|
2020-10-16 13:13:04 +02:00
|
|
|
this->last_error = now_time;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2022-02-15 11:40:36 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The socket buffer is full, and the device is not processing data
|
|
|
|
|
* fast enough, so should just skip this packet. There will be a sound
|
|
|
|
|
* glitch in any case.
|
|
|
|
|
*/
|
|
|
|
|
written = this->buffer_used;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2022-02-15 11:40:36 +02:00
|
|
|
|
|
|
|
|
if (written < 0) {
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_trace(this->log, "%p: error flushing %s", this,
|
2019-05-31 15:06:44 +02:00
|
|
|
spa_strerror(written));
|
2021-04-10 04:45:05 +08:00
|
|
|
reset_buffer(this);
|
2022-07-09 18:06:36 +03:00
|
|
|
enable_flush_timer(this, false);
|
2018-01-18 11:57:23 +01:00
|
|
|
return written;
|
|
|
|
|
}
|
|
|
|
|
else if (written > 0) {
|
2022-07-09 18:06:36 +03:00
|
|
|
/*
|
|
|
|
|
* We cannot write all data we have at once, since this can exceed device
|
|
|
|
|
* buffers (esp. for the A2DP low-latency codecs) and socket buffers, so
|
|
|
|
|
* flush needs to be delayed.
|
|
|
|
|
*/
|
|
|
|
|
uint32_t packet_samples = this->block_count * this->block_size
|
|
|
|
|
/ port->frame_size;
|
|
|
|
|
uint64_t packet_time = (uint64_t)packet_samples * SPA_NSEC_PER_SEC
|
|
|
|
|
/ port->current_format.info.raw.rate;
|
|
|
|
|
|
|
|
|
|
if (SPA_LIKELY(this->position)) {
|
|
|
|
|
uint64_t duration_ns;
|
2022-04-30 20:54:32 +03:00
|
|
|
|
2022-07-22 18:18:54 +02:00
|
|
|
/*
|
2022-07-09 18:06:36 +03:00
|
|
|
* Flush at the time position of the next buffered sample.
|
|
|
|
|
*/
|
2023-03-19 14:14:27 +02:00
|
|
|
this->next_flush_time = get_reference_time(this, &duration_ns)
|
|
|
|
|
+ packet_time;
|
2022-07-09 18:06:36 +03:00
|
|
|
|
|
|
|
|
/*
|
2023-02-23 22:01:53 +02:00
|
|
|
* We can delay the output by one packet to avoid waiting
|
2022-07-09 18:06:36 +03:00
|
|
|
* for the next buffer and so make send intervals exactly regular.
|
|
|
|
|
* However, this is not needed for A2DP or BAP. The controller
|
|
|
|
|
* will do the scheduling for us, and there's also the socket buffer
|
|
|
|
|
* in between.
|
2023-02-23 22:01:53 +02:00
|
|
|
*
|
|
|
|
|
* Although in principle this should not be needed, we
|
|
|
|
|
* do it regardless in case it helps.
|
2022-07-09 18:06:36 +03:00
|
|
|
*/
|
2023-02-23 22:01:53 +02:00
|
|
|
#if 1
|
2022-07-09 18:06:36 +03:00
|
|
|
this->next_flush_time += SPA_MIN(packet_time,
|
2023-12-04 21:32:05 +02:00
|
|
|
duration_ns * (SPA_MAX(port->n_buffers, 2u) - 2));
|
2022-07-09 18:06:36 +03:00
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
if (this->next_flush_time == 0)
|
|
|
|
|
this->next_flush_time = this->process_time;
|
|
|
|
|
this->next_flush_time += packet_time;
|
|
|
|
|
}
|
2022-07-22 18:18:54 +02:00
|
|
|
|
2024-01-26 21:00:35 +02:00
|
|
|
update_packet_delay(this, packet_time);
|
|
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
if (this->need_flush == NEED_FLUSH_FRAGMENT) {
|
2022-07-22 18:18:54 +02:00
|
|
|
reset_buffer(this);
|
2022-07-09 18:06:36 +03:00
|
|
|
this->fragment = true;
|
|
|
|
|
goto again;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (now_time - this->last_error > SPA_NSEC_PER_SEC) {
|
2024-03-02 19:28:22 +02:00
|
|
|
if (unsent_buffer == 0) {
|
2025-06-08 13:19:05 +03:00
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
|
|
if (this->codec->increase_bitpool)
|
|
|
|
|
res = this->codec->increase_bitpool(this->codec_data);
|
2022-11-07 20:15:29 +02:00
|
|
|
|
|
|
|
|
spa_log_debug(this->log, "%p: increase bitpool: %i", this, res);
|
2022-07-22 18:18:54 +02:00
|
|
|
}
|
2022-07-09 18:06:36 +03:00
|
|
|
this->last_error = now_time;
|
2021-11-06 12:54:02 +02:00
|
|
|
}
|
2022-07-09 18:06:36 +03:00
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: flush at:%"PRIu64" process:%"PRIu64, this,
|
|
|
|
|
this->next_flush_time, this->process_time);
|
|
|
|
|
reset_buffer(this);
|
|
|
|
|
enable_flush_timer(this, true);
|
2023-01-21 17:37:44 +02:00
|
|
|
|
|
|
|
|
/* Encode next packet already now; it will be flushed later on timer */
|
|
|
|
|
goto again;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2021-08-13 23:20:47 +03:00
|
|
|
else {
|
|
|
|
|
/* Don't want to flush yet, or failed to write anything */
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_trace(this->log, "%p: skip flush", this);
|
2022-07-09 18:06:36 +03:00
|
|
|
enable_flush_timer(this, false);
|
2021-08-13 23:20:47 +03:00
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
static void drop_frames(struct impl *this, uint32_t req)
|
|
|
|
|
{
|
|
|
|
|
struct port *port = &this->port;
|
|
|
|
|
|
2025-10-11 18:38:38 +03:00
|
|
|
if (this->silence_frames > req) {
|
|
|
|
|
this->silence_frames -= req;
|
|
|
|
|
req = 0;
|
|
|
|
|
} else {
|
|
|
|
|
req -= this->silence_frames;
|
|
|
|
|
this->silence_frames = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
while (req > 0 && !spa_list_is_empty(&port->ready)) {
|
|
|
|
|
struct buffer *b;
|
|
|
|
|
struct spa_data *d;
|
|
|
|
|
uint32_t avail;
|
|
|
|
|
|
|
|
|
|
b = spa_list_first(&port->ready, struct buffer, link);
|
|
|
|
|
d = b->buf->datas;
|
|
|
|
|
|
|
|
|
|
avail = d[0].chunk->size - port->ready_offset;
|
|
|
|
|
avail /= port->frame_size;
|
|
|
|
|
|
|
|
|
|
avail = SPA_MIN(avail, req);
|
|
|
|
|
port->ready_offset += avail * port->frame_size;
|
|
|
|
|
req -= avail;
|
|
|
|
|
|
|
|
|
|
if (port->ready_offset >= d[0].chunk->size) {
|
|
|
|
|
spa_list_remove(&b->link);
|
|
|
|
|
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
|
|
|
|
|
spa_log_trace(this->log, "%p: reuse buffer %u", this, b->id);
|
|
|
|
|
this->port.io->buffer_id = b->id;
|
|
|
|
|
|
|
|
|
|
spa_node_call_reuse_buffer(&this->callbacks, 0, b->id);
|
|
|
|
|
port->ready_offset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: skipped %u frames", this, avail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 16:12:32 +03:00
|
|
|
static void media_iso_rate_match(struct impl *this)
|
2023-03-25 18:01:43 +02:00
|
|
|
{
|
2025-07-11 16:12:32 +03:00
|
|
|
struct spa_bt_iso_io *iso_io = this->transport ? this->transport->iso_io : NULL;
|
2023-03-25 18:01:43 +02:00
|
|
|
struct port *port = &this->port;
|
2025-07-11 17:13:31 +03:00
|
|
|
const double period = 0.05 * SPA_NSEC_PER_SEC;
|
2025-07-11 16:12:32 +03:00
|
|
|
uint64_t ref_time;
|
2023-03-25 18:01:43 +02:00
|
|
|
uint64_t duration_ns;
|
2023-04-09 19:53:42 +03:00
|
|
|
double value, target, err, max_err;
|
2023-03-25 18:01:43 +02:00
|
|
|
|
2025-07-11 16:12:32 +03:00
|
|
|
if (!iso_io || !this->transport_started)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
if (this->resync || !this->position) {
|
|
|
|
|
spa_bt_rate_control_init(&port->ratectl, 0);
|
2025-10-11 18:53:31 +03:00
|
|
|
setup_matching(this);
|
2025-07-11 16:12:32 +03:00
|
|
|
return;
|
2023-03-25 18:01:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2025-03-08 11:35:35 +02:00
|
|
|
* Rate match sample position so that the graph is max(ISO interval*3/2, quantum)
|
2023-03-25 18:01:43 +02:00
|
|
|
* ahead of the time instant we have to send data.
|
|
|
|
|
*
|
2025-03-08 11:35:35 +02:00
|
|
|
* Being 1 ISO interval ahead is unavoidable otherwise we underrun, and the
|
|
|
|
|
* rest is safety margin for the graph to deliver data in time.
|
2023-03-25 18:01:43 +02:00
|
|
|
*
|
|
|
|
|
* This is then the part of the TX latency on PipeWire side. There is
|
|
|
|
|
* another part of TX latency on kernel/controller side before the
|
|
|
|
|
* controller starts processing the packet.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-11 16:12:32 +03:00
|
|
|
ref_time = get_reference_time(this, &duration_ns);
|
|
|
|
|
|
|
|
|
|
value = (int64_t)iso_io->now - (int64_t)ref_time;
|
2025-03-08 11:35:35 +02:00
|
|
|
if (this->process_rate)
|
|
|
|
|
target = this->process_duration * SPA_NSEC_PER_SEC / this->process_rate;
|
|
|
|
|
else
|
|
|
|
|
target = 0;
|
|
|
|
|
target = SPA_MAX(target, iso_io->duration*3/2);
|
2023-03-25 18:01:43 +02:00
|
|
|
err = value - target;
|
2025-07-11 16:12:32 +03:00
|
|
|
max_err = SPA_MAX(40 * SPA_NSEC_PER_MSEC, target);
|
2023-03-25 18:01:43 +02:00
|
|
|
|
2023-04-09 21:28:40 +03:00
|
|
|
if (iso_io->resync && err >= 0) {
|
2024-06-18 12:17:56 +02:00
|
|
|
unsigned int req = (unsigned int)(err * port->current_format.info.raw.rate / SPA_NSEC_PER_SEC);
|
2023-03-25 18:01:43 +02:00
|
|
|
|
2023-04-09 19:53:42 +03:00
|
|
|
if (req > 0) {
|
|
|
|
|
spa_bt_rate_control_init(&port->ratectl, 0);
|
|
|
|
|
drop_frames(this, req);
|
|
|
|
|
}
|
2023-04-09 21:28:40 +03:00
|
|
|
spa_log_debug(this->log, "%p: ISO sync skip frames:%u", this, req);
|
|
|
|
|
} else if (iso_io->resync && -err >= 0) {
|
2024-06-18 12:17:56 +02:00
|
|
|
unsigned int req = (unsigned int)(-err * port->current_format.info.raw.rate / SPA_NSEC_PER_SEC);
|
2023-04-09 19:53:42 +03:00
|
|
|
|
|
|
|
|
if (req > 0) {
|
|
|
|
|
spa_bt_rate_control_init(&port->ratectl, 0);
|
2025-10-11 18:38:38 +03:00
|
|
|
this->silence_frames += req;
|
2023-04-09 19:53:42 +03:00
|
|
|
}
|
2023-04-09 21:28:40 +03:00
|
|
|
spa_log_debug(this->log, "%p: ISO sync pad frames:%u", this, req);
|
|
|
|
|
} else if (err > max_err || -err > max_err) {
|
|
|
|
|
iso_io->need_resync = true;
|
|
|
|
|
spa_log_debug(this->log, "%p: ISO sync need resync err:%+.3f",
|
|
|
|
|
this, err / SPA_NSEC_PER_MSEC);
|
2023-03-25 18:01:43 +02:00
|
|
|
} else {
|
|
|
|
|
spa_bt_rate_control_update(&port->ratectl, err, 0,
|
2025-07-11 16:12:32 +03:00
|
|
|
duration_ns, period, RATE_CTL_DIFF_MAX);
|
2025-01-18 11:50:16 +02:00
|
|
|
spa_log_trace(this->log, "%p: ISO sync err:%+.3g value:%.6f target:%.6f (ms) corr:%g",
|
2023-03-25 18:01:43 +02:00
|
|
|
this,
|
|
|
|
|
port->ratectl.avg / SPA_NSEC_PER_MSEC,
|
|
|
|
|
value / SPA_NSEC_PER_MSEC,
|
|
|
|
|
target / SPA_NSEC_PER_MSEC,
|
|
|
|
|
port->ratectl.corr);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 19:53:42 +03:00
|
|
|
iso_io->resync = false;
|
2025-07-11 16:12:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void media_iso_pull(struct spa_bt_iso_io *iso_io)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = iso_io->user_data;
|
2023-04-09 19:53:42 +03:00
|
|
|
|
|
|
|
|
this->iso_pending = true;
|
2023-03-25 18:01:43 +02:00
|
|
|
flush_data(this, this->current_time);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
static void media_on_flush_error(struct spa_source *source)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2018-01-18 11:57:23 +01:00
|
|
|
struct impl *this = source->data;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2024-02-20 23:01:07 +02:00
|
|
|
if (source->rmask & SPA_IO_ERR) {
|
|
|
|
|
/* TX timestamp info? */
|
2024-03-02 19:28:22 +02:00
|
|
|
if (this->transport && this->transport->iso_io) {
|
2024-02-20 23:01:07 +02:00
|
|
|
if (spa_bt_iso_io_recv_errqueue(this->transport->iso_io) == 0)
|
|
|
|
|
return;
|
2024-03-02 19:28:22 +02:00
|
|
|
} else {
|
|
|
|
|
if (spa_bt_latency_recv_errqueue(&this->tx_latency, this->flush_source.fd, this->log) == 0)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-20 23:01:07 +02:00
|
|
|
|
|
|
|
|
/* Otherwise: actual error */
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
spa_log_trace(this->log, "%p: flush event", this);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2024-02-20 23:01:07 +02:00
|
|
|
if (source->rmask & (SPA_IO_HUP | SPA_IO_ERR)) {
|
2025-10-02 01:25:56 +03:00
|
|
|
spa_log_warn(this->log, "%p: connection (%s) terminated unexpectedly",
|
|
|
|
|
this, this->transport ? this->transport->path : "");
|
2024-03-02 19:28:22 +02:00
|
|
|
if (this->flush_source.loop) {
|
|
|
|
|
spa_bt_latency_flush(&this->tx_latency, this->flush_source.fd, this->log);
|
2018-04-24 17:21:23 +02:00
|
|
|
spa_loop_remove_source(this->data_loop, &this->flush_source);
|
2024-03-02 19:28:22 +02:00
|
|
|
}
|
2023-03-10 18:57:12 +02:00
|
|
|
enable_flush_timer(this, false);
|
|
|
|
|
if (this->flush_timer_source.loop)
|
|
|
|
|
spa_loop_remove_source(this->data_loop, &this->flush_timer_source);
|
2023-03-25 18:01:43 +02:00
|
|
|
if (this->transport && this->transport->iso_io)
|
|
|
|
|
spa_bt_iso_io_set_cb(this->transport->iso_io, NULL, NULL);
|
2018-01-18 11:57:23 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-11-06 12:54:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-15 17:24:41 +02:00
|
|
|
static void media_on_flush_timeout(struct spa_source *source)
|
2021-11-06 12:54:02 +02:00
|
|
|
{
|
|
|
|
|
struct impl *this = source->data;
|
|
|
|
|
uint64_t exp;
|
2022-12-09 17:30:31 +01:00
|
|
|
int res;
|
2021-11-06 12:54:02 +02:00
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: flush on timeout", this);
|
|
|
|
|
|
2022-12-09 17:30:31 +01:00
|
|
|
if ((res = spa_system_timerfd_read(this->data_system, this->flush_timerfd, &exp)) < 0) {
|
|
|
|
|
if (res != -EAGAIN)
|
|
|
|
|
spa_log_warn(this->log, "error reading timerfd: %s", spa_strerror(res));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-11-06 12:54:02 +02:00
|
|
|
|
|
|
|
|
if (this->transport == NULL) {
|
2022-07-09 18:06:36 +03:00
|
|
|
enable_flush_timer(this, false);
|
2021-11-06 12:54:02 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
while (exp-- > 0) {
|
|
|
|
|
this->flush_pending = false;
|
|
|
|
|
flush_data(this, this->current_time);
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-15 17:24:41 +02:00
|
|
|
static void media_on_timeout(struct spa_source *source)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2018-01-18 11:57:23 +01:00
|
|
|
struct impl *this = source->data;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port = &this->port;
|
2020-10-16 13:13:04 +02:00
|
|
|
uint64_t exp, duration;
|
|
|
|
|
uint32_t rate;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_io_buffers *io = port->io;
|
2020-10-16 13:13:04 +02:00
|
|
|
uint64_t prev_time, now_time;
|
2023-12-04 20:22:47 +02:00
|
|
|
int status, res;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-12-09 17:30:31 +01:00
|
|
|
if (this->started) {
|
|
|
|
|
if ((res = spa_system_timerfd_read(this->data_system, this->timerfd, &exp)) < 0) {
|
|
|
|
|
if (res != -EAGAIN)
|
|
|
|
|
spa_log_warn(this->log, "error reading timerfd: %s",
|
|
|
|
|
spa_strerror(res));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-10-16 13:13:04 +02:00
|
|
|
prev_time = this->current_time;
|
|
|
|
|
now_time = this->current_time = this->next_time;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-06-18 14:37:11 +03:00
|
|
|
spa_log_debug(this->log, "%p: timer %"PRIu64" %"PRIu64"", this,
|
2021-04-28 17:03:59 +02:00
|
|
|
now_time, now_time - prev_time);
|
|
|
|
|
|
2020-10-16 13:13:04 +02:00
|
|
|
if (SPA_LIKELY(this->position)) {
|
2023-03-24 11:20:01 +01:00
|
|
|
duration = this->position->clock.target_duration;
|
|
|
|
|
rate = this->position->clock.target_rate.denom;
|
2020-10-16 13:13:04 +02:00
|
|
|
} else {
|
|
|
|
|
duration = 1024;
|
|
|
|
|
rate = 48000;
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-03 23:56:58 +02:00
|
|
|
setup_matching(this);
|
|
|
|
|
|
2024-06-18 12:17:56 +02:00
|
|
|
this->next_time = (uint64_t)(now_time + duration * SPA_NSEC_PER_SEC / rate * port->ratectl.corr);
|
2020-10-16 13:13:04 +02:00
|
|
|
|
|
|
|
|
if (SPA_LIKELY(this->clock)) {
|
|
|
|
|
this->clock->nsec = now_time;
|
2023-03-24 11:20:01 +01:00
|
|
|
this->clock->rate = this->clock->target_rate;
|
|
|
|
|
this->clock->position += this->clock->duration;
|
2020-10-19 15:35:45 +02:00
|
|
|
this->clock->duration = duration;
|
2023-03-03 23:56:58 +02:00
|
|
|
this->clock->rate_diff = 1 / port->ratectl.corr;
|
2020-10-16 13:13:04 +02:00
|
|
|
this->clock->next_nsec = this->next_time;
|
2024-01-26 21:00:35 +02:00
|
|
|
this->clock->delay = 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-04 20:22:47 +02:00
|
|
|
status = this->transport_started ? SPA_STATUS_NEED_DATA : SPA_STATUS_HAVE_DATA;
|
2018-10-05 11:10:36 +02:00
|
|
|
|
2023-12-04 20:22:47 +02:00
|
|
|
spa_log_trace(this->log, "%p: %d -> %d", this, io->status, status);
|
|
|
|
|
io->status = status;
|
|
|
|
|
io->buffer_id = SPA_ID_INVALID;
|
|
|
|
|
spa_node_call_ready(&this->callbacks, status);
|
2019-05-16 16:42:49 +02:00
|
|
|
|
2020-10-16 13:13:04 +02:00
|
|
|
set_timeout(this, this->next_time);
|
2018-01-18 11:57:23 +01:00
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2025-04-21 06:08:47 -04:00
|
|
|
static uint64_t asha_seqnum(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
uint64_t tn = get_reference_time(this, NULL);
|
2025-04-28 11:42:42 +05:30
|
|
|
uint64_t dt = tn - this->asha->ref_t0;
|
|
|
|
|
uint64_t num_packets = (dt + ASHA_CONN_INTERVAL / 2) / ASHA_CONN_INTERVAL;
|
2025-04-21 06:08:47 -04:00
|
|
|
|
2025-05-07 09:38:24 +02:00
|
|
|
spa_log_trace(this->log, "%" PRIu64 " - %" PRIu64 " / 20ms = %"PRIu64,
|
2025-04-21 06:08:47 -04:00
|
|
|
tn, this->asha->ref_t0, num_packets);
|
|
|
|
|
|
|
|
|
|
if (this->asha->ref_t0 > tn)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2025-04-28 11:42:42 +05:30
|
|
|
return num_packets % 256;
|
2025-04-21 06:08:47 -04:00
|
|
|
}
|
|
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
static void media_asha_flush_timeout(struct spa_source *source)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = source->data;
|
|
|
|
|
struct port *port = &this->port;
|
|
|
|
|
struct spa_bt_asha *asha = this->asha;
|
|
|
|
|
const char *address = this->transport->device->address;
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
int res, written;
|
|
|
|
|
uint64_t exp, now;
|
|
|
|
|
|
|
|
|
|
if (this->started) {
|
|
|
|
|
if ((res = spa_system_timerfd_read(this->data_system, asha->timerfd, &exp)) < 0) {
|
|
|
|
|
if (res != -EAGAIN)
|
|
|
|
|
spa_log_warn(this->log, "error reading ASHA timerfd: %s",
|
|
|
|
|
spa_strerror(res));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &ts);
|
|
|
|
|
now = SPA_TIMESPEC_TO_NSEC(&ts);
|
|
|
|
|
|
2025-04-25 13:03:52 +05:30
|
|
|
asha->next_time += (uint64_t)(ASHA_CONN_INTERVAL * port->ratectl.corr);
|
2025-02-10 22:16:44 +05:30
|
|
|
|
|
|
|
|
if (asha->flush_pending) {
|
2025-05-06 16:11:19 +05:30
|
|
|
asha->buf[0] = this->seqnum;
|
2025-02-10 22:16:44 +05:30
|
|
|
written = send(asha->flush_source.fd, asha->buf,
|
|
|
|
|
ASHA_ENCODED_PKT_SZ, MSG_DONTWAIT | MSG_NOSIGNAL);
|
|
|
|
|
/*
|
|
|
|
|
* For ASHA, when we are out of LE credits and cannot write to
|
|
|
|
|
* the socket, return value of `send` will be -EAGAIN.
|
|
|
|
|
*/
|
|
|
|
|
if (written < 0) {
|
|
|
|
|
asha->flush_pending = false;
|
|
|
|
|
spa_log_warn(this->log, "%p: ASHA failed to flush %d seqnum on timer for %s, written:%d",
|
2025-05-06 16:11:19 +05:30
|
|
|
this, this->seqnum, address, -errno);
|
2025-02-10 22:16:44 +05:30
|
|
|
goto skip_flush;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (written > 0) {
|
|
|
|
|
asha->flush_pending = false;
|
|
|
|
|
spa_log_trace(this->log, "%p: ASHA flush %d seqnum for %s, ts:%u",
|
2025-05-06 16:11:19 +05:30
|
|
|
this, this->seqnum, address, this->timestamp);
|
2025-02-10 22:16:44 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-21 06:08:47 -04:00
|
|
|
this->seqnum = asha_seqnum(this);
|
2025-02-10 22:16:44 +05:30
|
|
|
flush_data(this, now);
|
|
|
|
|
|
|
|
|
|
skip_flush:
|
|
|
|
|
set_asha_timeout(this, asha->next_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void media_asha_cb(struct spa_source *source)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = source->data;
|
|
|
|
|
struct spa_bt_asha *asha = this->asha;
|
|
|
|
|
const char *address = this->transport->device->address;
|
|
|
|
|
|
|
|
|
|
if (source->rmask & (SPA_IO_HUP | SPA_IO_ERR)) {
|
|
|
|
|
spa_log_error(this->log, "%p: ASHA source error %d on %s", this, source->rmask, address);
|
|
|
|
|
|
|
|
|
|
if (asha->flush_source.loop)
|
|
|
|
|
spa_loop_remove_source(this->data_loop, &asha->flush_source);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-11 16:12:32 +03:00
|
|
|
static int do_start_transport(struct spa_loop *loop, bool async, uint32_t seq,
|
2023-03-25 18:01:43 +02:00
|
|
|
const void *data, size_t size, void *user_data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = user_data;
|
|
|
|
|
|
2025-07-11 16:12:32 +03:00
|
|
|
this->transport_started = true;
|
|
|
|
|
if (this->transport->iso_io)
|
|
|
|
|
spa_bt_iso_io_set_cb(this->transport->iso_io, media_iso_pull, this);
|
2023-03-25 18:01:43 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
static int transport_start(struct impl *this)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2023-03-06 22:40:33 +02:00
|
|
|
int val, size;
|
2020-12-03 18:05:57 +01:00
|
|
|
struct port *port;
|
2018-01-18 11:57:23 +01:00
|
|
|
socklen_t len;
|
2020-12-06 09:32:12 +01:00
|
|
|
uint8_t *conf;
|
2022-08-12 15:35:22 +02:00
|
|
|
uint32_t flags;
|
2025-02-10 22:16:44 +05:30
|
|
|
bool is_asha;
|
2025-06-08 13:19:05 +03:00
|
|
|
bool is_sco;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
if (this->transport_started)
|
2018-01-18 11:57:23 +01:00
|
|
|
return 0;
|
2023-03-06 22:40:33 +02:00
|
|
|
if (!this->start_ready)
|
|
|
|
|
return -EIO;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-03-23 13:49:30 +01:00
|
|
|
spa_return_val_if_fail(this->transport, -EIO);
|
|
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
spa_log_debug(this->log, "%p: start transport", this);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-12-03 18:05:57 +01:00
|
|
|
port = &this->port;
|
|
|
|
|
|
2020-12-06 09:32:12 +01:00
|
|
|
conf = this->transport->configuration;
|
|
|
|
|
size = this->transport->configuration_len;
|
2025-06-07 20:18:49 +03:00
|
|
|
is_asha = this->codec->kind == MEDIA_CODEC_ASHA;
|
2025-06-08 13:19:05 +03:00
|
|
|
is_sco = this->codec->kind == MEDIA_CODEC_HFP;
|
2020-12-06 09:32:12 +01:00
|
|
|
|
2022-07-18 11:26:59 +02:00
|
|
|
spa_log_debug(this->log, "Transport configuration:");
|
2023-01-18 17:41:16 +01:00
|
|
|
spa_debug_log_mem(this->log, SPA_LOG_LEVEL_DEBUG, 2, conf, (size_t)size);
|
2020-12-06 09:32:12 +01:00
|
|
|
|
2022-10-23 16:50:03 +03:00
|
|
|
flags = this->is_duplex ? MEDIA_CODEC_FLAG_SINK : 0;
|
2022-08-12 15:35:22 +02:00
|
|
|
|
2023-04-09 21:28:40 +03:00
|
|
|
if (!this->transport->iso_io) {
|
|
|
|
|
this->own_codec_data = true;
|
|
|
|
|
this->codec_data = this->codec->init(this->codec,
|
|
|
|
|
flags,
|
|
|
|
|
this->transport->configuration,
|
|
|
|
|
this->transport->configuration_len,
|
|
|
|
|
&port->current_format,
|
|
|
|
|
this->codec_props,
|
|
|
|
|
this->transport->write_mtu);
|
2024-01-28 22:15:00 +02:00
|
|
|
if (this->codec_data == NULL) {
|
|
|
|
|
spa_log_error(this->log, "%p: codec %s initialization failed", this,
|
|
|
|
|
this->codec->description);
|
2023-04-09 21:28:40 +03:00
|
|
|
return -EIO;
|
2024-01-28 22:15:00 +02:00
|
|
|
}
|
2023-04-09 21:28:40 +03:00
|
|
|
} else {
|
|
|
|
|
this->own_codec_data = false;
|
|
|
|
|
this->codec_data = this->transport->iso_io->codec_data;
|
|
|
|
|
this->codec_props_changed = true;
|
|
|
|
|
}
|
2020-12-03 18:05:57 +01:00
|
|
|
|
2024-02-23 21:04:47 +02:00
|
|
|
this->encoder_delay = 0;
|
|
|
|
|
if (this->codec->get_delay)
|
|
|
|
|
this->codec->get_delay(this->codec_data, &this->encoder_delay, NULL);
|
|
|
|
|
|
2025-06-07 20:18:49 +03:00
|
|
|
const char *codec_profile = media_codec_kind_str(this->codec);
|
2024-02-23 21:04:47 +02:00
|
|
|
spa_log_info(this->log, "%p: using %s codec %s, delay:%.2f ms, codec-delay:%.2f ms", this,
|
2025-01-16 16:28:26 +05:30
|
|
|
codec_profile, this->codec->description,
|
2024-02-23 21:04:47 +02:00
|
|
|
(double)spa_bt_transport_get_delay_nsec(this->transport) / SPA_NSEC_PER_MSEC,
|
|
|
|
|
(double)this->encoder_delay * SPA_MSEC_PER_SEC / port->current_format.info.raw.rate);
|
2020-12-04 11:34:38 +01:00
|
|
|
|
2023-03-19 14:14:27 +02:00
|
|
|
this->seqnum = UINT16_MAX;
|
2020-10-19 09:33:49 +02:00
|
|
|
|
|
|
|
|
this->block_size = this->codec->get_block_size(this->codec_data);
|
2020-12-11 19:23:30 +01:00
|
|
|
if (this->block_size > sizeof(this->tmp_buffer)) {
|
|
|
|
|
spa_log_error(this->log, "block-size %d > %zu",
|
|
|
|
|
this->block_size, sizeof(this->tmp_buffer));
|
2025-06-08 13:19:05 +03:00
|
|
|
goto fail;
|
2020-12-11 19:23:30 +01:00
|
|
|
}
|
2020-10-19 09:33:49 +02:00
|
|
|
|
2022-06-15 17:24:41 +02:00
|
|
|
spa_log_debug(this->log, "%p: block_size %d", this, this->block_size);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2021-02-08 10:24:27 +01:00
|
|
|
val = this->codec->send_buf_size > 0
|
2021-01-31 09:01:40 +08:00
|
|
|
/* The kernel doubles the SO_SNDBUF option value set by setsockopt(). */
|
|
|
|
|
? this->codec->send_buf_size / 2 + this->codec->send_buf_size % 2
|
|
|
|
|
: FILL_FRAMES * this->transport->write_mtu;
|
2018-01-18 11:57:23 +01:00
|
|
|
if (setsockopt(this->transport->fd, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)) < 0)
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_warn(this->log, "%p: SO_SNDBUF %m", this);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
len = sizeof(val);
|
|
|
|
|
if (getsockopt(this->transport->fd, SOL_SOCKET, SO_SNDBUF, &val, &len) < 0) {
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_warn(this->log, "%p: SO_SNDBUF %m", this);
|
2018-01-18 11:57:23 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_debug(this->log, "%p: SO_SNDBUF: %d", this, val);
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2020-12-19 08:21:40 +08:00
|
|
|
this->fd_buffer_size = val;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
val = 6;
|
|
|
|
|
if (setsockopt(this->transport->fd, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)) < 0)
|
|
|
|
|
spa_log_warn(this->log, "SO_PRIORITY failed: %m");
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
reset_buffer(this);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-03 23:56:58 +02:00
|
|
|
spa_bt_rate_control_init(&port->ratectl, 0);
|
|
|
|
|
|
2024-03-01 22:17:58 +02:00
|
|
|
this->update_delay_event = spa_loop_utils_add_event(this->loop_utils, update_delay_event, this);
|
|
|
|
|
|
2025-06-08 13:19:05 +03:00
|
|
|
spa_zero(this->tx_latency);
|
|
|
|
|
|
|
|
|
|
if (is_sco) {
|
|
|
|
|
int res;
|
|
|
|
|
if ((res = spa_bt_transport_ensure_sco_io(this->transport, this->data_loop, this->data_system)) < 0)
|
|
|
|
|
goto fail;
|
2025-06-21 16:13:57 +03:00
|
|
|
spa_bt_sco_io_write_start(this->transport->sco_io);
|
2025-06-08 13:19:05 +03:00
|
|
|
}
|
|
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
if (!this->transport->iso_io && !is_asha) {
|
2023-03-25 18:01:43 +02:00
|
|
|
this->flush_timer_source.data = this;
|
|
|
|
|
this->flush_timer_source.fd = this->flush_timerfd;
|
|
|
|
|
this->flush_timer_source.func = media_on_flush_timeout;
|
|
|
|
|
this->flush_timer_source.mask = SPA_IO_IN;
|
|
|
|
|
this->flush_timer_source.rmask = 0;
|
|
|
|
|
spa_loop_add_source(this->data_loop, &this->flush_timer_source);
|
2024-03-02 19:28:22 +02:00
|
|
|
|
2025-06-08 13:19:05 +03:00
|
|
|
if (!is_sco)
|
|
|
|
|
spa_bt_latency_init(&this->tx_latency, this->transport, LATENCY_PERIOD, this->log);
|
2023-03-25 18:01:43 +02:00
|
|
|
}
|
2021-11-06 12:54:02 +02:00
|
|
|
|
2025-06-08 13:19:05 +03:00
|
|
|
if (!is_asha && !is_sco) {
|
2025-02-10 22:16:44 +05:30
|
|
|
this->flush_source.data = this;
|
|
|
|
|
this->flush_source.fd = this->transport->fd;
|
|
|
|
|
this->flush_source.func = media_on_flush_error;
|
|
|
|
|
this->flush_source.mask = SPA_IO_ERR | SPA_IO_HUP;
|
|
|
|
|
this->flush_source.rmask = 0;
|
|
|
|
|
spa_loop_add_source(this->data_loop, &this->flush_source);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-11 18:53:31 +03:00
|
|
|
this->resync = 0;
|
2025-05-17 09:16:24 -04:00
|
|
|
this->flush_pending = false;
|
|
|
|
|
this->iso_pending = false;
|
|
|
|
|
|
2025-07-11 16:12:32 +03:00
|
|
|
spa_loop_locked(this->data_loop, do_start_transport, 0, NULL, 0, this);
|
2025-05-17 09:16:24 -04:00
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
if (is_asha) {
|
|
|
|
|
struct spa_bt_asha *asha = this->asha;
|
|
|
|
|
|
|
|
|
|
asha->flush_pending = false;
|
|
|
|
|
asha->set_timer = false;
|
|
|
|
|
|
|
|
|
|
asha->timer_source.data = this;
|
|
|
|
|
asha->timer_source.fd = this->asha->timerfd;
|
|
|
|
|
asha->timer_source.func = media_asha_flush_timeout;
|
|
|
|
|
asha->timer_source.mask = SPA_IO_IN;
|
|
|
|
|
asha->timer_source.rmask = 0;
|
|
|
|
|
spa_loop_add_source(this->data_loop, &asha->timer_source);
|
|
|
|
|
|
|
|
|
|
asha->flush_source.data = this;
|
|
|
|
|
asha->flush_source.fd = this->transport->fd;
|
|
|
|
|
asha->flush_source.func = media_asha_cb;
|
2025-04-28 11:42:42 +05:30
|
|
|
asha->flush_source.mask = SPA_IO_ERR | SPA_IO_HUP;
|
2025-02-10 22:16:44 +05:30
|
|
|
asha->flush_source.rmask = 0;
|
|
|
|
|
spa_loop_add_source(this->data_loop, &asha->flush_source);
|
|
|
|
|
|
|
|
|
|
spa_list_append(&asha_sinks, &this->asha_link);
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2025-07-11 18:36:07 +03:00
|
|
|
set_latency(this, true);
|
2023-03-25 18:01:43 +02:00
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
return 0;
|
2025-06-08 13:19:05 +03:00
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
if (this->codec_data) {
|
|
|
|
|
if (this->own_codec_data)
|
|
|
|
|
this->codec->deinit(this->codec_data);
|
|
|
|
|
this->own_codec_data = false;
|
|
|
|
|
this->codec_data = NULL;
|
|
|
|
|
}
|
|
|
|
|
return -EIO;
|
2023-03-06 22:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int do_start(struct impl *this)
|
|
|
|
|
{
|
2025-10-11 18:53:31 +03:00
|
|
|
struct port *port = &this->port;
|
2023-03-06 22:40:33 +02:00
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
if (this->started)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail(this->transport, -EIO);
|
|
|
|
|
|
|
|
|
|
this->following = is_following(this);
|
|
|
|
|
|
|
|
|
|
spa_log_debug(this->log, "%p: start following:%d", this, this->following);
|
|
|
|
|
|
|
|
|
|
this->start_ready = true;
|
|
|
|
|
|
2025-06-08 13:19:05 +03:00
|
|
|
bool do_accept = this->transport->profile & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY;
|
|
|
|
|
if ((res = spa_bt_transport_acquire(this->transport, do_accept)) < 0) {
|
2023-03-06 22:40:33 +02:00
|
|
|
this->start_ready = false;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 21:00:35 +02:00
|
|
|
this->packet_delay_ns = 0;
|
|
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
this->source.data = this;
|
|
|
|
|
this->source.fd = this->timerfd;
|
|
|
|
|
this->source.func = media_on_timeout;
|
|
|
|
|
this->source.mask = SPA_IO_IN;
|
|
|
|
|
this->source.rmask = 0;
|
|
|
|
|
spa_loop_add_source(this->data_loop, &this->source);
|
|
|
|
|
|
2025-10-11 18:53:31 +03:00
|
|
|
spa_bt_rate_control_init(&port->ratectl, 0);
|
2023-03-03 23:56:58 +02:00
|
|
|
setup_matching(this);
|
|
|
|
|
|
2019-04-24 12:41:16 +02:00
|
|
|
set_timers(this);
|
2023-03-06 22:40:33 +02:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
this->started = true;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int do_remove_source(struct spa_loop *loop,
|
|
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
const void *data,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = user_data;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-04-24 17:21:23 +02:00
|
|
|
if (this->source.loop)
|
|
|
|
|
spa_loop_remove_source(this->data_loop, &this->source);
|
2023-03-24 17:55:15 +01:00
|
|
|
set_timeout(this, 0);
|
2024-03-01 22:17:58 +02:00
|
|
|
|
|
|
|
|
if (this->update_delay_event) {
|
|
|
|
|
spa_loop_utils_destroy_source(this->loop_utils, this->update_delay_event);
|
|
|
|
|
this->update_delay_event = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int do_remove_transport_source(struct spa_loop *loop,
|
|
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
const void *data,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = user_data;
|
|
|
|
|
|
|
|
|
|
this->transport_started = false;
|
|
|
|
|
|
2024-03-02 19:28:22 +02:00
|
|
|
if (this->flush_source.loop) {
|
|
|
|
|
spa_bt_latency_flush(&this->tx_latency, this->flush_source.fd, this->log);
|
2018-04-24 17:21:23 +02:00
|
|
|
spa_loop_remove_source(this->data_loop, &this->flush_source);
|
2024-03-02 19:28:22 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-06 12:54:02 +02:00
|
|
|
if (this->flush_timer_source.loop)
|
|
|
|
|
spa_loop_remove_source(this->data_loop, &this->flush_timer_source);
|
2025-06-07 20:18:49 +03:00
|
|
|
if (this->codec->kind == MEDIA_CODEC_ASHA) {
|
2025-02-10 22:16:44 +05:30
|
|
|
if (this->asha->timer_source.loop)
|
|
|
|
|
spa_loop_remove_source(this->data_loop, &this->asha->timer_source);
|
|
|
|
|
if (this->asha->flush_source.loop)
|
|
|
|
|
spa_loop_remove_source(this->data_loop, &this->asha->flush_source);
|
|
|
|
|
spa_list_remove(&this->asha_link);
|
|
|
|
|
}
|
2023-03-24 17:55:15 +01:00
|
|
|
enable_flush_timer(this, false);
|
2021-11-06 12:54:02 +02:00
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
if (this->transport->iso_io)
|
|
|
|
|
spa_bt_iso_io_set_cb(this->transport->iso_io, NULL, NULL);
|
|
|
|
|
|
2023-12-04 20:40:22 +02:00
|
|
|
/* Drop queued data */
|
|
|
|
|
drop_frames(this, UINT32_MAX);
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
static void transport_stop(struct impl *this)
|
|
|
|
|
{
|
|
|
|
|
if (!this->transport_started)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: stop transport", this);
|
|
|
|
|
|
2025-05-30 11:59:35 +02:00
|
|
|
spa_loop_locked(this->data_loop, do_remove_transport_source, 0, NULL, 0, this);
|
2023-03-06 22:40:33 +02:00
|
|
|
|
2023-04-09 21:28:40 +03:00
|
|
|
if (this->codec_data && this->own_codec_data)
|
2023-03-06 22:40:33 +02:00
|
|
|
this->codec->deinit(this->codec_data);
|
|
|
|
|
this->codec_data = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int do_stop(struct impl *this)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-07-31 18:30:19 +02:00
|
|
|
int res = 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
if (!this->started)
|
|
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
spa_log_debug(this->log, "%p: stop", this);
|
|
|
|
|
|
|
|
|
|
this->start_ready = false;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2025-05-30 11:59:35 +02:00
|
|
|
spa_loop_locked(this->data_loop, do_remove_source, 0, NULL, 0, this);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
transport_stop(this);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-07-31 18:30:19 +02:00
|
|
|
if (this->transport)
|
|
|
|
|
res = spa_bt_transport_release(this->transport);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
this->started = false;
|
2020-12-03 18:11:06 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
return res;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_send_command(void *object, const struct spa_command *command)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port;
|
2018-01-18 11:57:23 +01:00
|
|
|
int res;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-01-18 11:57:23 +01:00
|
|
|
spa_return_val_if_fail(command != NULL, -EINVAL);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
port = &this->port;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-08-24 10:53:09 +02:00
|
|
|
switch (SPA_NODE_COMMAND_ID(command)) {
|
|
|
|
|
case SPA_NODE_COMMAND_Start:
|
2019-02-27 16:43:01 +01:00
|
|
|
if (!port->have_format)
|
2018-01-18 11:57:23 +01:00
|
|
|
return -EIO;
|
2019-02-27 16:43:01 +01:00
|
|
|
if (port->n_buffers == 0)
|
2018-01-18 11:57:23 +01:00
|
|
|
return -EIO;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
if ((res = do_start(this)) < 0)
|
|
|
|
|
return res;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2020-01-10 13:25:40 +01:00
|
|
|
case SPA_NODE_COMMAND_Suspend:
|
2018-08-24 10:53:09 +02:00
|
|
|
case SPA_NODE_COMMAND_Pause:
|
2018-01-18 11:57:23 +01:00
|
|
|
if ((res = do_stop(this)) < 0)
|
|
|
|
|
return res;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2018-01-18 11:57:23 +01:00
|
|
|
return -ENOTSUP;
|
2018-08-23 17:47:57 +02:00
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
static void emit_node_info(struct impl *this, bool full)
|
2019-02-14 17:08:46 +01:00
|
|
|
{
|
2023-11-12 18:30:32 +02:00
|
|
|
char node_group_buf[256];
|
|
|
|
|
char *node_group = NULL;
|
2025-06-08 13:19:05 +03:00
|
|
|
const char *media_role = NULL;
|
|
|
|
|
const char *codec_profile = media_codec_kind_str(this->codec);
|
2023-11-12 18:30:32 +02:00
|
|
|
|
|
|
|
|
if (this->transport && (this->transport->profile & SPA_BT_PROFILE_BAP_SINK)) {
|
2024-06-21 13:20:02 +03:00
|
|
|
spa_scnprintf(node_group_buf, sizeof(node_group_buf), "[\"bluez-iso-%s-cig-%d\"]",
|
2023-11-12 18:30:32 +02:00
|
|
|
this->transport->device->adapter->address,
|
|
|
|
|
this->transport->bap_cig);
|
|
|
|
|
node_group = node_group_buf;
|
|
|
|
|
} else if (this->transport && (this->transport->profile & SPA_BT_PROFILE_BAP_BROADCAST_SINK)) {
|
2024-06-21 13:20:02 +03:00
|
|
|
spa_scnprintf(node_group_buf, sizeof(node_group_buf), "[\"bluez-iso-%s-big-%d\"]",
|
2023-11-12 18:30:32 +02:00
|
|
|
this->transport->device->adapter->address,
|
|
|
|
|
this->transport->bap_big);
|
|
|
|
|
node_group = node_group_buf;
|
2025-01-21 19:21:13 +05:30
|
|
|
} else if (this->transport && (this->transport->profile & SPA_BT_PROFILE_ASHA_SINK)) {
|
2025-04-28 11:42:42 +05:30
|
|
|
spa_scnprintf(node_group_buf, sizeof(node_group_buf), "[\"bluez-asha-%" PRIu64 "d\"]",
|
2025-01-21 19:21:13 +05:30
|
|
|
this->transport->hisyncid);
|
|
|
|
|
node_group = node_group_buf;
|
2023-11-12 18:30:32 +02:00
|
|
|
}
|
|
|
|
|
|
2025-06-08 13:19:05 +03:00
|
|
|
if (!this->is_output && this->transport &&
|
|
|
|
|
(this->transport->profile & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY))
|
|
|
|
|
media_role = "Communication";
|
|
|
|
|
|
2021-08-15 22:45:47 +03:00
|
|
|
struct spa_dict_item node_info_items[] = {
|
|
|
|
|
{ SPA_KEY_DEVICE_API, "bluez5" },
|
2023-03-13 19:17:34 +02:00
|
|
|
{ SPA_KEY_MEDIA_CLASS, this->is_internal ? "Audio/Sink/Internal" :
|
|
|
|
|
this->is_output ? "Audio/Sink" : "Stream/Input/Audio" },
|
2022-07-22 11:01:18 +02:00
|
|
|
{ "media.name", ((this->transport && this->transport->device->name) ?
|
2025-01-16 16:28:26 +05:30
|
|
|
this->transport->device->name : codec_profile ) },
|
2022-07-22 11:01:18 +02:00
|
|
|
{ SPA_KEY_NODE_DRIVER, this->is_output ? "true" : "false" },
|
2023-11-12 18:30:32 +02:00
|
|
|
{ "node.group", node_group },
|
2025-06-08 13:19:05 +03:00
|
|
|
{ SPA_KEY_MEDIA_ROLE, media_role },
|
2021-08-15 22:45:47 +03:00
|
|
|
};
|
2021-05-25 15:22:13 +02:00
|
|
|
uint64_t old = full ? this->info.change_mask : 0;
|
2019-03-01 12:00:42 +01:00
|
|
|
if (full)
|
|
|
|
|
this->info.change_mask = this->info_all;
|
|
|
|
|
if (this->info.change_mask) {
|
2019-02-27 16:43:01 +01:00
|
|
|
this->info.props = &SPA_DICT_INIT_ARRAY(node_info_items);
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_info(&this->hooks, &this->info);
|
2021-05-25 15:22:13 +02:00
|
|
|
this->info.change_mask = old;
|
2019-02-14 17:08:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
static void emit_port_info(struct impl *this, struct port *port, bool full)
|
2019-02-14 17:08:46 +01:00
|
|
|
{
|
2021-05-25 15:22:13 +02:00
|
|
|
uint64_t old = full ? port->info.change_mask : 0;
|
2019-03-01 12:00:42 +01:00
|
|
|
if (full)
|
|
|
|
|
port->info.change_mask = port->info_all;
|
|
|
|
|
if (port->info.change_mask) {
|
|
|
|
|
spa_node_emit_port_info(&this->hooks,
|
|
|
|
|
SPA_DIRECTION_INPUT, 0, &port->info);
|
2021-05-25 15:22:13 +02:00
|
|
|
port->info.change_mask = old;
|
2019-02-14 17:08:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_add_listener(void *object,
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook *listener,
|
|
|
|
|
const struct spa_node_events *events,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook_list save;
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-03-01 12:00:42 +01:00
|
|
|
|
|
|
|
|
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
|
|
|
|
|
|
|
|
|
emit_node_info(this, true);
|
|
|
|
|
emit_port_info(this, &this->port, true);
|
|
|
|
|
|
|
|
|
|
spa_hook_list_join(&this->hooks, &save);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_set_callbacks(void *object,
|
2018-01-18 11:57:23 +01:00
|
|
|
const struct spa_node_callbacks *callbacks,
|
|
|
|
|
void *data)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-15 12:17:52 +02:00
|
|
|
this->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
|
2018-01-18 11:57:23 +01:00
|
|
|
|
|
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 14:01:18 +02:00
|
|
|
static int impl_node_sync(void *object, int seq)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = object;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
spa_node_emit_result(&this->hooks, seq, 0, 0, NULL);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id,
|
2019-02-18 13:22:46 +01:00
|
|
|
const struct spa_dict *props)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2018-01-18 11:57:23 +01:00
|
|
|
return -ENOTSUP;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2018-01-18 11:57:23 +01:00
|
|
|
return -ENOTSUP;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_enum_params(void *object, int seq,
|
2019-02-20 17:51:05 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_pod *filter)
|
2018-01-18 11:57:23 +01:00
|
|
|
{
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port;
|
2018-01-18 11:57:23 +01:00
|
|
|
struct spa_pod *param;
|
|
|
|
|
struct spa_pod_builder b = { 0 };
|
|
|
|
|
uint8_t buffer[1024];
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params result;
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t count = 0;
|
2020-12-03 18:05:57 +01:00
|
|
|
int res;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_return_val_if_fail(num != 0, -EINVAL);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2019-02-27 16:43:01 +01:00
|
|
|
port = &this->port;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
result.id = id;
|
2019-02-20 17:51:05 +01:00
|
|
|
result.next = start;
|
2018-01-18 11:57:23 +01:00
|
|
|
next:
|
2019-02-25 12:29:57 +01:00
|
|
|
result.index = result.next++;
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
switch (id) {
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_EnumFormat:
|
2020-12-03 18:05:57 +01:00
|
|
|
if (this->codec == NULL)
|
2020-03-23 13:49:30 +01:00
|
|
|
return -EIO;
|
2020-12-30 16:31:55 +02:00
|
|
|
if (this->transport == NULL)
|
|
|
|
|
return -EIO;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-12-04 11:34:38 +01:00
|
|
|
if ((res = this->codec->enum_config(this->codec,
|
2022-06-15 17:24:41 +02:00
|
|
|
this->is_duplex ? MEDIA_CODEC_FLAG_SINK : 0,
|
2020-12-03 18:05:57 +01:00
|
|
|
this->transport->configuration,
|
|
|
|
|
this->transport->configuration_len,
|
|
|
|
|
id, result.index, &b, ¶m)) != 1)
|
|
|
|
|
return res;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
|
|
|
|
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_Format:
|
2019-02-27 16:43:01 +01:00
|
|
|
if (!port->have_format)
|
2018-01-18 11:57:23 +01:00
|
|
|
return -EIO;
|
2019-02-25 12:29:57 +01:00
|
|
|
if (result.index > 0)
|
2018-01-18 11:57:23 +01:00
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
param = spa_format_audio_raw_build(&b, id, &port->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:
|
2019-02-27 16:43:01 +01:00
|
|
|
if (!port->have_format)
|
2018-01-18 11:57:23 +01:00
|
|
|
return -EIO;
|
2019-02-25 12:29:57 +01:00
|
|
|
if (result.index > 0)
|
2018-01-18 11:57:23 +01:00
|
|
|
return 0;
|
2018-01-11 10:23:37 +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,
|
2022-07-09 18:06:36 +03:00
|
|
|
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(
|
|
|
|
|
MIN_BUFFERS,
|
|
|
|
|
MIN_BUFFERS,
|
|
|
|
|
MAX_BUFFERS),
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
|
2022-07-09 18:06:36 +03:00
|
|
|
SPA_PARAM_BUFFERS_size, SPA_POD_CHOICE_RANGE_Int(
|
|
|
|
|
this->quantum_limit * port->frame_size,
|
|
|
|
|
16 * port->frame_size,
|
2019-02-27 16:43:01 +01:00
|
|
|
INT32_MAX),
|
2022-01-03 12:32:26 +01:00
|
|
|
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->frame_size));
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
|
|
|
|
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_PARAM_Meta:
|
2019-02-25 12:29:57 +01:00
|
|
|
switch (result.index) {
|
2018-01-18 11:57:23 +01:00
|
|
|
case 0:
|
2019-01-16 11:05:12 +01:00
|
|
|
param = spa_pod_builder_add_object(&b,
|
2018-08-27 15:03:11 +02:00
|
|
|
SPA_TYPE_OBJECT_ParamMeta, id,
|
2019-01-16 11:05:12 +01:00
|
|
|
SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
|
|
|
|
|
SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header)));
|
2018-01-18 11:57:23 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
|
|
|
|
|
2020-12-17 12:25:12 +01:00
|
|
|
case SPA_PARAM_IO:
|
|
|
|
|
switch (result.index) {
|
|
|
|
|
case 0:
|
|
|
|
|
param = spa_pod_builder_add_object(&b,
|
|
|
|
|
SPA_TYPE_OBJECT_ParamIO, id,
|
|
|
|
|
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_Buffers),
|
|
|
|
|
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_buffers)));
|
|
|
|
|
break;
|
2023-03-03 23:56:58 +02:00
|
|
|
case 1:
|
2025-06-07 20:18:49 +03:00
|
|
|
if (this->codec->kind != MEDIA_CODEC_BAP)
|
2023-03-03 23:56:58 +02:00
|
|
|
return 0;
|
|
|
|
|
param = spa_pod_builder_add_object(&b,
|
|
|
|
|
SPA_TYPE_OBJECT_ParamIO, id,
|
|
|
|
|
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_RateMatch),
|
|
|
|
|
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_rate_match)));
|
|
|
|
|
break;
|
2020-12-17 12:25:12 +01:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2021-05-28 19:02:06 +08:00
|
|
|
case SPA_PARAM_Latency:
|
|
|
|
|
switch (result.index) {
|
|
|
|
|
case 0:
|
|
|
|
|
param = spa_latency_build(&b, id, &port->latency);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
default:
|
2018-01-18 11:57:23 +01:00
|
|
|
return -ENOENT;
|
2018-08-23 17:47:57 +02:00
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
2018-01-18 11:57:23 +01:00
|
|
|
goto next;
|
|
|
|
|
|
2019-05-28 13:59:48 +02:00
|
|
|
spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);
|
2019-02-20 17:51:05 +01:00
|
|
|
|
|
|
|
|
if (++count != num)
|
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
static int clear_buffers(struct impl *this, struct port *port)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2018-01-18 11:57:23 +01:00
|
|
|
do_stop(this);
|
2019-02-27 16:43:01 +01:00
|
|
|
if (port->n_buffers > 0) {
|
|
|
|
|
spa_list_init(&port->ready);
|
|
|
|
|
port->n_buffers = 0;
|
2018-01-18 11:57:23 +01:00
|
|
|
}
|
|
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
static int port_set_format(struct impl *this, struct port *port,
|
2018-01-18 11:57:23 +01:00
|
|
|
uint32_t flags,
|
|
|
|
|
const struct spa_pod *format)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
if (format == NULL) {
|
2020-04-22 12:47:18 +02:00
|
|
|
spa_log_debug(this->log, "clear format");
|
2019-02-27 16:43:01 +01:00
|
|
|
clear_buffers(this, port);
|
|
|
|
|
port->have_format = false;
|
2018-01-18 11:57:23 +01:00
|
|
|
} else {
|
|
|
|
|
struct spa_audio_info info = { 0 };
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-08-29 14:50:58 +02:00
|
|
|
if ((err = spa_format_parse(format, &info.media_type, &info.media_subtype)) < 0)
|
2018-01-18 11:57:23 +01:00
|
|
|
return err;
|
2018-01-11 10:23:37 +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)
|
2018-01-18 11:57:23 +01:00
|
|
|
return -EINVAL;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
2018-01-18 11:57:23 +01:00
|
|
|
return -EINVAL;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-11-03 13:10:32 +01:00
|
|
|
if (info.info.raw.rate == 0 ||
|
|
|
|
|
info.info.raw.channels == 0 ||
|
2025-10-20 15:33:17 +02:00
|
|
|
info.info.raw.channels > MAX_CHANNELS)
|
2022-11-03 13:10:32 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
2023-04-09 21:28:40 +03:00
|
|
|
if (this->transport && this->transport->iso_io) {
|
|
|
|
|
if (memcmp(&info.info.raw, &this->transport->iso_io->format.info.raw,
|
|
|
|
|
sizeof(info.info.raw))) {
|
|
|
|
|
spa_log_error(this->log, "unexpected incompatible "
|
|
|
|
|
"BAP audio format");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-04 11:34:38 +01:00
|
|
|
port->frame_size = info.info.raw.channels;
|
|
|
|
|
switch (info.info.raw.format) {
|
2025-06-08 13:19:05 +03:00
|
|
|
case SPA_AUDIO_FORMAT_S16_LE:
|
|
|
|
|
case SPA_AUDIO_FORMAT_S16_BE:
|
2020-12-04 11:34:38 +01:00
|
|
|
port->frame_size *= 2;
|
|
|
|
|
break;
|
|
|
|
|
case SPA_AUDIO_FORMAT_S24:
|
|
|
|
|
port->frame_size *= 3;
|
|
|
|
|
break;
|
|
|
|
|
case SPA_AUDIO_FORMAT_S24_32:
|
|
|
|
|
case SPA_AUDIO_FORMAT_S32:
|
|
|
|
|
case SPA_AUDIO_FORMAT_F32:
|
|
|
|
|
port->frame_size *= 4;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
port->current_format = info;
|
|
|
|
|
port->have_format = true;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-26 21:00:35 +02:00
|
|
|
set_latency(this, false);
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
2019-02-27 16:43:01 +01:00
|
|
|
if (port->have_format) {
|
|
|
|
|
port->info.change_mask |= SPA_PORT_CHANGE_MASK_RATE;
|
2019-03-01 12:00:42 +01:00
|
|
|
port->info.rate = SPA_FRACTION(1, port->current_format.info.raw.rate);
|
2021-05-28 16:42:22 +08:00
|
|
|
port->params[IDX_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
|
|
|
|
|
port->params[IDX_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
|
2021-05-28 19:02:06 +08:00
|
|
|
port->params[IDX_Latency].flags ^= SPA_PARAM_INFO_SERIAL;
|
2019-02-27 16:43:01 +01:00
|
|
|
} else {
|
2021-05-28 16:42:22 +08:00
|
|
|
port->params[IDX_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
|
|
|
|
port->params[IDX_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
2018-01-18 11:57:23 +01:00
|
|
|
}
|
2019-03-01 12:00:42 +01:00
|
|
|
emit_port_info(this, port, false);
|
2018-01-18 11:57:23 +01:00
|
|
|
|
|
|
|
|
return 0;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_set_param(void *object,
|
2018-01-18 11:57:23 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod *param)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port;
|
2019-05-15 10:20:28 +02:00
|
|
|
int res;
|
2019-02-27 16:43:01 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-08-23 17:47:57 +02:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL);
|
2019-02-27 16:43:01 +01:00
|
|
|
port = &this->port;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-15 10:20:28 +02:00
|
|
|
switch (id) {
|
|
|
|
|
case SPA_PARAM_Format:
|
|
|
|
|
res = port_set_format(this, port, flags, param);
|
|
|
|
|
break;
|
2021-06-05 02:21:10 +08:00
|
|
|
case SPA_PARAM_Latency:
|
|
|
|
|
res = 0;
|
|
|
|
|
break;
|
2019-05-15 10:20:28 +02:00
|
|
|
default:
|
|
|
|
|
res = -ENOENT;
|
|
|
|
|
break;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2019-05-15 10:20:28 +02:00
|
|
|
return res;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_use_buffers(void *object,
|
2019-07-25 13:19:39 +02:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t flags,
|
|
|
|
|
struct spa_buffer **buffers, uint32_t n_buffers)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port;
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t i;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-01-18 11:57:23 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2019-02-27 16:43:01 +01:00
|
|
|
port = &this->port;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-03-25 18:01:43 +02:00
|
|
|
spa_log_debug(this->log, "%p: use buffers %d", this, n_buffers);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
clear_buffers(this, port);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2023-01-10 12:30:25 +01:00
|
|
|
if (n_buffers > 0 && !port->have_format)
|
|
|
|
|
return -EIO;
|
|
|
|
|
if (n_buffers > MAX_BUFFERS)
|
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
2018-01-18 11:57:23 +01:00
|
|
|
for (i = 0; i < n_buffers; i++) {
|
2019-02-27 16:43:01 +01:00
|
|
|
struct buffer *b = &port->buffers[i];
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-05-17 17:26:09 +02:00
|
|
|
b->buf = buffers[i];
|
2019-01-07 17:57:03 +01:00
|
|
|
b->id = i;
|
2020-09-02 17:04:19 +02:00
|
|
|
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-10-16 12:23:42 +02:00
|
|
|
if (buffers[i]->datas[0].data == NULL) {
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_error(this->log, "%p: need mapped memory", this);
|
2018-01-18 11:57:23 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-27 16:43:01 +01:00
|
|
|
port->n_buffers = n_buffers;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_set_io(void *object,
|
2018-01-18 11:57:23 +01:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
void *data, size_t size)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
|
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2019-02-27 16:43:01 +01:00
|
|
|
port = &this->port;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
switch (id) {
|
2018-08-25 12:08:29 +02:00
|
|
|
case SPA_IO_Buffers:
|
2019-02-27 16:43:01 +01:00
|
|
|
port->io = data;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2023-03-03 23:56:58 +02:00
|
|
|
case SPA_IO_RateMatch:
|
2025-06-07 20:18:49 +03:00
|
|
|
if (this->codec->kind != MEDIA_CODEC_BAP)
|
2023-03-03 23:56:58 +02:00
|
|
|
return -ENOENT;
|
|
|
|
|
port->rate_match = data;
|
|
|
|
|
break;
|
2018-08-23 17:47:57 +02:00
|
|
|
default:
|
2018-01-18 11:57:23 +01:00
|
|
|
return -ENOENT;
|
2018-08-23 17:47:57 +02:00
|
|
|
}
|
2018-01-18 11:57:23 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id)
|
2018-01-18 11:57:23 +01:00
|
|
|
{
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_process(void *object)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct impl *this = object;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port;
|
|
|
|
|
struct spa_io_buffers *io;
|
2023-03-25 18:01:43 +02:00
|
|
|
int res;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
port = &this->port;
|
2022-09-01 15:31:14 +02:00
|
|
|
if ((io = port->io) == NULL)
|
|
|
|
|
return -EIO;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-05-30 09:54:22 +02:00
|
|
|
if (this->position && this->position->clock.flags & SPA_IO_CLOCK_FLAG_FREEWHEEL) {
|
|
|
|
|
io->status = SPA_STATUS_NEED_DATA;
|
|
|
|
|
return SPA_STATUS_HAVE_DATA;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-04 20:22:47 +02:00
|
|
|
if (!this->started || !this->transport_started) {
|
|
|
|
|
if (io->status != SPA_STATUS_HAVE_DATA) {
|
|
|
|
|
io->status = SPA_STATUS_HAVE_DATA;
|
|
|
|
|
io->buffer_id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
return SPA_STATUS_HAVE_DATA;
|
|
|
|
|
}
|
2023-03-06 22:40:33 +02:00
|
|
|
|
2019-09-16 12:55:23 +02:00
|
|
|
if (io->status == SPA_STATUS_HAVE_DATA && io->buffer_id < port->n_buffers) {
|
2019-02-27 16:43:01 +01:00
|
|
|
struct buffer *b = &port->buffers[io->buffer_id];
|
2023-04-03 21:19:12 +03:00
|
|
|
struct spa_data *d = b->buf->datas;
|
|
|
|
|
unsigned int frames;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2020-09-02 17:16:16 +02:00
|
|
|
if (!SPA_FLAG_IS_SET(b->flags, BUFFER_FLAG_OUT)) {
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_warn(this->log, "%p: buffer %u in use", this, io->buffer_id);
|
2019-02-27 16:43:01 +01:00
|
|
|
io->status = -EINVAL;
|
2018-01-11 10:23:37 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 21:19:12 +03:00
|
|
|
frames = d ? d[0].chunk->size / port->frame_size : 0;
|
|
|
|
|
spa_log_trace(this->log, "%p: queue buffer %u frames:%u", this, io->buffer_id, frames);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
spa_list_append(&port->ready, &b->link);
|
2020-09-02 17:04:19 +02:00
|
|
|
SPA_FLAG_CLEAR(b->flags, BUFFER_FLAG_OUT);
|
2018-04-24 17:02:19 +02:00
|
|
|
|
2020-10-16 13:13:04 +02:00
|
|
|
io->buffer_id = SPA_ID_INVALID;
|
2019-02-27 16:43:01 +01:00
|
|
|
io->status = SPA_STATUS_OK;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
2022-07-09 18:06:36 +03:00
|
|
|
|
|
|
|
|
if (this->following) {
|
|
|
|
|
if (this->position) {
|
|
|
|
|
this->current_time = this->position->clock.nsec;
|
|
|
|
|
} else {
|
|
|
|
|
struct timespec now;
|
|
|
|
|
spa_system_clock_gettime(this->data_system, CLOCK_MONOTONIC, &now);
|
|
|
|
|
this->current_time = SPA_TIMESPEC_TO_NSEC(&now);
|
2022-05-28 13:50:12 +03:00
|
|
|
}
|
2022-07-09 18:06:36 +03:00
|
|
|
}
|
|
|
|
|
|
2025-07-11 15:54:08 +03:00
|
|
|
/* Make copies of current position values, so that they can be used later at any
|
|
|
|
|
* time without shared memory races
|
|
|
|
|
*/
|
2023-03-25 18:01:43 +02:00
|
|
|
if (this->position) {
|
|
|
|
|
this->process_duration = this->position->clock.duration;
|
|
|
|
|
this->process_rate = this->position->clock.rate.denom;
|
2025-07-11 15:54:08 +03:00
|
|
|
this->process_rate_diff = this->position->clock.rate_diff;
|
2023-03-25 18:01:43 +02:00
|
|
|
} else {
|
|
|
|
|
this->process_duration = 1024;
|
|
|
|
|
this->process_rate = 48000;
|
2025-07-11 15:54:08 +03:00
|
|
|
this->process_rate_diff = 1.0;
|
2023-03-25 18:01:43 +02:00
|
|
|
}
|
2023-03-19 14:14:27 +02:00
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
this->process_time = this->current_time;
|
2023-04-09 19:53:42 +03:00
|
|
|
if (this->resync)
|
|
|
|
|
--this->resync;
|
2022-07-09 18:06:36 +03:00
|
|
|
|
2023-03-03 23:56:58 +02:00
|
|
|
setup_matching(this);
|
|
|
|
|
|
2025-07-11 16:12:32 +03:00
|
|
|
media_iso_rate_match(this);
|
|
|
|
|
|
2025-06-07 20:18:49 +03:00
|
|
|
if (this->codec->kind == MEDIA_CODEC_ASHA && !this->asha->set_timer) {
|
2025-04-21 06:08:47 -04:00
|
|
|
struct impl *other = find_other_asha(this);
|
|
|
|
|
if (other && other->asha->ref_t0 != 0) {
|
|
|
|
|
this->asha->ref_t0 = other->asha->ref_t0;
|
|
|
|
|
this->seqnum = asha_seqnum(this);
|
2025-04-22 16:41:30 -04:00
|
|
|
set_asha_timer(this, other);
|
2025-04-21 06:08:47 -04:00
|
|
|
} else {
|
|
|
|
|
this->asha->ref_t0 = get_reference_time(this, NULL);
|
|
|
|
|
this->seqnum = 0;
|
2025-04-22 16:41:30 -04:00
|
|
|
set_asha_timer(this, NULL);
|
2025-04-21 06:08:47 -04:00
|
|
|
}
|
|
|
|
|
|
2025-02-10 22:16:44 +05:30
|
|
|
this->asha->set_timer = true;
|
2025-04-21 06:49:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "%p: on process time:%"PRIu64, this, this->process_time);
|
|
|
|
|
if ((res = flush_data(this, this->current_time)) < 0) {
|
|
|
|
|
io->status = res;
|
|
|
|
|
return SPA_STATUS_STOPPED;
|
2025-02-10 22:16:44 +05:30
|
|
|
}
|
|
|
|
|
|
2019-09-16 12:55:23 +02:00
|
|
|
return SPA_STATUS_HAVE_DATA;
|
2018-01-11 10:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static const struct spa_node_methods impl_node = {
|
|
|
|
|
SPA_VERSION_NODE_METHODS,
|
2019-03-01 12:00:42 +01:00
|
|
|
.add_listener = impl_node_add_listener,
|
|
|
|
|
.set_callbacks = impl_node_set_callbacks,
|
2019-05-28 14:01:18 +02:00
|
|
|
.sync = impl_node_sync,
|
2019-02-14 17:08:46 +01:00
|
|
|
.enum_params = impl_node_enum_params,
|
|
|
|
|
.set_param = impl_node_set_param,
|
|
|
|
|
.set_io = impl_node_set_io,
|
|
|
|
|
.send_command = impl_node_send_command,
|
|
|
|
|
.add_port = impl_node_add_port,
|
|
|
|
|
.remove_port = impl_node_remove_port,
|
|
|
|
|
.port_enum_params = impl_node_port_enum_params,
|
|
|
|
|
.port_set_param = impl_node_port_set_param,
|
|
|
|
|
.port_use_buffers = impl_node_port_use_buffers,
|
|
|
|
|
.port_set_io = impl_node_port_set_io,
|
|
|
|
|
.port_reuse_buffer = impl_node_port_reuse_buffer,
|
|
|
|
|
.process = impl_node_process,
|
2018-01-11 10:23:37 +01:00
|
|
|
};
|
|
|
|
|
|
2021-05-28 19:02:06 +08:00
|
|
|
static void transport_delay_changed(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = data;
|
|
|
|
|
spa_log_debug(this->log, "transport %p delay changed", this->transport);
|
|
|
|
|
set_latency(this, true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 02:02:58 +02:00
|
|
|
static int do_transport_destroy(struct spa_loop *loop,
|
|
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
const void *data,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = user_data;
|
|
|
|
|
this->transport = NULL;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 18:10:18 +02:00
|
|
|
static void transport_destroy(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = data;
|
|
|
|
|
spa_log_debug(this->log, "transport %p destroy", this->transport);
|
2025-05-30 11:59:35 +02:00
|
|
|
spa_loop_locked(this->data_loop, do_transport_destroy, 0, NULL, 0, this);
|
2019-05-14 18:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-22 15:04:44 +03:00
|
|
|
static void transport_state_changed(void *data,
|
|
|
|
|
enum spa_bt_transport_state old,
|
|
|
|
|
enum spa_bt_transport_state state)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this = data;
|
2023-03-06 22:40:33 +02:00
|
|
|
bool was_started = this->transport_started;
|
2022-05-22 15:04:44 +03:00
|
|
|
|
|
|
|
|
spa_log_debug(this->log, "%p: transport %p state %d->%d", this, this->transport, old, state);
|
|
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
if (state == SPA_BT_TRANSPORT_STATE_ACTIVE)
|
|
|
|
|
transport_start(this);
|
|
|
|
|
else
|
|
|
|
|
transport_stop(this);
|
2022-05-22 15:04:44 +03:00
|
|
|
|
2023-04-18 22:26:18 +03:00
|
|
|
if (state < SPA_BT_TRANSPORT_STATE_ACTIVE && was_started && !this->is_duplex && this->is_output) {
|
2022-05-22 15:04:44 +03:00
|
|
|
/*
|
|
|
|
|
* If establishing connection fails due to remote end not activating
|
|
|
|
|
* the transport, we won't get a write error, but instead see a transport
|
|
|
|
|
* state change.
|
|
|
|
|
*
|
2023-03-18 14:48:16 +02:00
|
|
|
* Treat this as a transport error, so that upper levels don't try to
|
|
|
|
|
* retry too often.
|
2022-05-22 15:04:44 +03:00
|
|
|
*/
|
|
|
|
|
|
2023-03-06 22:40:33 +02:00
|
|
|
spa_log_debug(this->log, "%p: transport %p becomes inactive: stop and indicate error",
|
|
|
|
|
this, this->transport);
|
2023-03-18 14:48:16 +02:00
|
|
|
|
|
|
|
|
spa_bt_transport_set_state(this->transport, SPA_BT_TRANSPORT_STATE_ERROR);
|
|
|
|
|
return;
|
2023-03-06 22:40:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state == SPA_BT_TRANSPORT_STATE_ERROR) {
|
|
|
|
|
uint8_t buffer[1024];
|
|
|
|
|
struct spa_pod_builder b = { 0 };
|
2022-05-22 15:04:44 +03:00
|
|
|
|
|
|
|
|
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
|
|
|
|
spa_node_emit_event(&this->hooks,
|
|
|
|
|
spa_pod_builder_add_object(&b,
|
|
|
|
|
SPA_TYPE_EVENT_Node, SPA_NODE_EVENT_Error));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 18:10:18 +02:00
|
|
|
static const struct spa_bt_transport_events transport_events = {
|
|
|
|
|
SPA_VERSION_BT_TRANSPORT_EVENTS,
|
2021-05-28 19:02:06 +08:00
|
|
|
.delay_changed = transport_delay_changed,
|
2022-05-22 15:04:44 +03:00
|
|
|
.state_changed = transport_state_changed,
|
2021-05-28 19:02:06 +08:00
|
|
|
.destroy = transport_destroy,
|
2019-05-14 18:10:18 +02:00
|
|
|
};
|
|
|
|
|
|
2019-12-19 13:15:10 +01:00
|
|
|
static int impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
|
2018-01-11 10:23:37 +01:00
|
|
|
{
|
|
|
|
|
struct impl *this;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(interface != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
this = (struct impl *) handle;
|
|
|
|
|
|
2021-05-18 11:36:13 +10:00
|
|
|
if (spa_streq(type, SPA_TYPE_INTERFACE_Node))
|
2018-01-11 10:23:37 +01:00
|
|
|
*interface = &this->node;
|
|
|
|
|
else
|
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int impl_clear(struct spa_handle *handle)
|
|
|
|
|
{
|
2019-06-06 15:21:40 +02:00
|
|
|
struct impl *this = (struct impl *) handle;
|
2020-10-19 09:33:49 +02:00
|
|
|
|
2022-10-20 21:52:49 +02:00
|
|
|
do_stop(this);
|
2021-03-20 14:53:18 +08:00
|
|
|
if (this->codec_props && this->codec->clear_props)
|
|
|
|
|
this->codec->clear_props(this->codec_props);
|
2020-07-03 16:08:53 +02:00
|
|
|
if (this->transport)
|
|
|
|
|
spa_hook_remove(&this->transport_listener);
|
2019-06-06 15:21:40 +02:00
|
|
|
spa_system_close(this->data_system, this->timerfd);
|
2021-11-06 12:54:02 +02:00
|
|
|
spa_system_close(this->data_system, this->flush_timerfd);
|
2025-06-07 20:18:49 +03:00
|
|
|
if (this->codec->kind == MEDIA_CODEC_ASHA) {
|
2025-02-10 22:16:44 +05:30
|
|
|
spa_system_close(this->data_system, this->asha->timerfd);
|
|
|
|
|
free(this->asha);
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
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 impl);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
static int
|
|
|
|
|
impl_init(const struct spa_handle_factory *factory,
|
|
|
|
|
struct spa_handle *handle,
|
|
|
|
|
const struct spa_dict *info,
|
|
|
|
|
const struct spa_support *support,
|
|
|
|
|
uint32_t n_support)
|
|
|
|
|
{
|
|
|
|
|
struct impl *this;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct port *port;
|
2019-12-19 13:15:10 +01:00
|
|
|
const char *str;
|
2018-01-11 10:23:37 +01:00
|
|
|
|
|
|
|
|
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
handle->get_interface = impl_get_interface;
|
|
|
|
|
handle->clear = impl_clear;
|
|
|
|
|
|
|
|
|
|
this = (struct impl *) handle;
|
|
|
|
|
|
2019-12-19 13:15:10 +01:00
|
|
|
this->log = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Log);
|
|
|
|
|
this->data_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataLoop);
|
|
|
|
|
this->data_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DataSystem);
|
2024-03-01 22:17:58 +02:00
|
|
|
this->loop_utils = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_LoopUtils);
|
2019-12-19 13:15:10 +01:00
|
|
|
|
2021-10-01 19:03:49 +03:00
|
|
|
spa_log_topic_init(this->log, &log_topic);
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
if (this->data_loop == NULL) {
|
|
|
|
|
spa_log_error(this->log, "a data loop is needed");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2019-06-06 15:21:40 +02:00
|
|
|
if (this->data_system == NULL) {
|
|
|
|
|
spa_log_error(this->log, "a data system is needed");
|
2018-01-11 10:23:37 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2024-03-01 22:17:58 +02:00
|
|
|
if (this->loop_utils == NULL) {
|
|
|
|
|
spa_log_error(this->log, "loop utils are needed");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
this->node.iface = SPA_INTERFACE_INIT(
|
|
|
|
|
SPA_TYPE_INTERFACE_Node,
|
|
|
|
|
SPA_VERSION_NODE,
|
|
|
|
|
&impl_node, this);
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_hook_list_init(&this->hooks);
|
|
|
|
|
|
|
|
|
|
this->info_all = SPA_NODE_CHANGE_MASK_FLAGS |
|
2019-04-24 12:41:16 +02:00
|
|
|
SPA_NODE_CHANGE_MASK_PARAMS |
|
|
|
|
|
SPA_NODE_CHANGE_MASK_PROPS;
|
2019-02-27 16:43:01 +01:00
|
|
|
this->info = SPA_NODE_INFO_INIT();
|
2019-07-12 09:55:55 +02:00
|
|
|
this->info.max_input_ports = 1;
|
|
|
|
|
this->info.max_output_ports = 0;
|
2019-02-27 16:43:01 +01:00
|
|
|
this->info.flags = SPA_NODE_FLAG_RT;
|
2021-05-28 16:42:22 +08:00
|
|
|
this->params[IDX_PropInfo] = SPA_PARAM_INFO(SPA_PARAM_PropInfo, SPA_PARAM_INFO_READ);
|
|
|
|
|
this->params[IDX_Props] = SPA_PARAM_INFO(SPA_PARAM_Props, SPA_PARAM_INFO_READWRITE);
|
2019-02-27 16:43:01 +01:00
|
|
|
this->info.params = this->params;
|
2021-05-28 16:42:22 +08:00
|
|
|
this->info.n_params = N_NODE_PARAMS;
|
2019-02-27 16:43:01 +01:00
|
|
|
|
|
|
|
|
port = &this->port;
|
2019-03-01 12:00:42 +01:00
|
|
|
port->info_all = SPA_PORT_CHANGE_MASK_FLAGS |
|
|
|
|
|
SPA_PORT_CHANGE_MASK_PARAMS;
|
2019-02-27 16:43:01 +01:00
|
|
|
port->info = SPA_PORT_INFO_INIT();
|
2023-08-31 12:59:56 +02:00
|
|
|
port->info.flags = SPA_PORT_FLAG_LIVE |
|
|
|
|
|
SPA_PORT_FLAG_PHYSICAL |
|
|
|
|
|
SPA_PORT_FLAG_TERMINAL;
|
2021-05-28 16:42:22 +08:00
|
|
|
port->params[IDX_EnumFormat] = SPA_PARAM_INFO(SPA_PARAM_EnumFormat, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[IDX_Meta] = SPA_PARAM_INFO(SPA_PARAM_Meta, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[IDX_IO] = SPA_PARAM_INFO(SPA_PARAM_IO, SPA_PARAM_INFO_READ);
|
|
|
|
|
port->params[IDX_Format] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_WRITE);
|
|
|
|
|
port->params[IDX_Buffers] = SPA_PARAM_INFO(SPA_PARAM_Buffers, 0);
|
2021-05-28 19:02:06 +08:00
|
|
|
port->params[IDX_Latency] = SPA_PARAM_INFO(SPA_PARAM_Latency, SPA_PARAM_INFO_READWRITE);
|
2019-02-27 16:43:01 +01:00
|
|
|
port->info.params = port->params;
|
2021-05-28 16:42:22 +08:00
|
|
|
port->info.n_params = N_PORT_PARAMS;
|
2021-05-28 19:02:06 +08:00
|
|
|
|
|
|
|
|
port->latency = SPA_LATENCY_INFO(SPA_DIRECTION_INPUT);
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
spa_list_init(&port->ready);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-07-09 18:06:36 +03:00
|
|
|
this->quantum_limit = 8192;
|
|
|
|
|
|
|
|
|
|
if (info && (str = spa_dict_lookup(info, "clock.quantum-limit")))
|
|
|
|
|
spa_atou32(str, &this->quantum_limit, 0);
|
|
|
|
|
|
2022-05-22 19:08:56 +03:00
|
|
|
if (info && (str = spa_dict_lookup(info, "api.bluez5.a2dp-duplex")) != NULL)
|
|
|
|
|
this->is_duplex = spa_atob(str);
|
|
|
|
|
|
2023-03-13 19:17:34 +02:00
|
|
|
if (info && (str = spa_dict_lookup(info, "api.bluez5.internal")) != NULL)
|
|
|
|
|
this->is_internal = spa_atob(str);
|
|
|
|
|
|
2019-12-19 13:15:10 +01:00
|
|
|
if (info && (str = spa_dict_lookup(info, SPA_KEY_API_BLUEZ5_TRANSPORT)))
|
|
|
|
|
sscanf(str, "pointer:%p", &this->transport);
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
if (this->transport == NULL) {
|
|
|
|
|
spa_log_error(this->log, "a transport is needed");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2022-06-15 17:24:41 +02:00
|
|
|
if (this->transport->media_codec == NULL) {
|
2020-10-19 13:27:11 +02:00
|
|
|
spa_log_error(this->log, "a transport codec is needed");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2022-05-22 19:08:56 +03:00
|
|
|
|
2022-06-15 17:24:41 +02:00
|
|
|
this->codec = this->transport->media_codec;
|
2022-05-22 19:08:56 +03:00
|
|
|
|
|
|
|
|
if (this->is_duplex) {
|
|
|
|
|
if (!this->codec->duplex_codec) {
|
|
|
|
|
spa_log_error(this->log, "transport codec doesn't support duplex");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
this->codec = this->codec->duplex_codec;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-20 14:53:18 +08:00
|
|
|
if (this->codec->init_props != NULL)
|
|
|
|
|
this->codec_props = this->codec->init_props(this->codec,
|
2022-06-15 17:24:41 +02:00
|
|
|
this->is_duplex ? MEDIA_CODEC_FLAG_SINK : 0,
|
2021-03-20 14:53:18 +08:00
|
|
|
this->transport->device->settings);
|
2020-10-19 13:27:11 +02:00
|
|
|
|
2025-06-07 20:18:49 +03:00
|
|
|
if (this->codec->kind == MEDIA_CODEC_BAP)
|
2022-07-22 11:01:18 +02:00
|
|
|
this->is_output = this->transport->bap_initiator;
|
2025-06-08 13:19:05 +03:00
|
|
|
else if (this->transport->profile & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY)
|
|
|
|
|
this->is_output = false;
|
2022-09-15 19:46:23 +03:00
|
|
|
else
|
|
|
|
|
this->is_output = true;
|
2022-07-22 11:01:18 +02:00
|
|
|
|
2021-08-15 22:45:47 +03:00
|
|
|
reset_props(this, &this->props);
|
|
|
|
|
|
2022-12-21 16:40:28 +02:00
|
|
|
set_latency(this, false);
|
|
|
|
|
|
2019-05-14 18:10:18 +02:00
|
|
|
spa_bt_transport_add_listener(this->transport,
|
|
|
|
|
&this->transport_listener, &transport_events, this);
|
|
|
|
|
|
2019-06-06 15:21:40 +02:00
|
|
|
this->timerfd = spa_system_timerfd_create(this->data_system,
|
|
|
|
|
CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2021-11-06 12:54:02 +02:00
|
|
|
this->flush_timerfd = spa_system_timerfd_create(this->data_system,
|
|
|
|
|
CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
|
|
|
|
|
|
2025-06-07 20:18:49 +03:00
|
|
|
if (this->codec->kind == MEDIA_CODEC_ASHA) {
|
2025-02-10 22:16:44 +05:30
|
|
|
this->asha = calloc(1, sizeof(struct spa_bt_asha));
|
|
|
|
|
if (this->asha == NULL)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
this->asha->timerfd = spa_system_timerfd_create(this->data_system,
|
|
|
|
|
CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 10:23:37 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct spa_interface_info impl_interfaces[] = {
|
2018-08-27 15:03:11 +02:00
|
|
|
{SPA_TYPE_INTERFACE_Node,},
|
2018-01-11 10:23:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
impl_enum_interface_info(const struct spa_handle_factory *factory,
|
|
|
|
|
const struct spa_interface_info **info, uint32_t *index)
|
|
|
|
|
{
|
|
|
|
|
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(info != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(index != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
switch (*index) {
|
|
|
|
|
case 0:
|
|
|
|
|
*info = &impl_interfaces[*index];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
(*index)++;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct spa_dict_item info_items[] = {
|
2019-06-03 16:48:01 +02:00
|
|
|
{ SPA_KEY_FACTORY_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
|
2022-06-15 17:24:41 +02:00
|
|
|
{ SPA_KEY_FACTORY_DESCRIPTION, "Play audio with the media" },
|
2019-06-03 16:48:01 +02:00
|
|
|
{ SPA_KEY_FACTORY_USAGE, SPA_KEY_API_BLUEZ5_TRANSPORT"=<transport>" },
|
2018-01-11 10:23:37 +01:00
|
|
|
};
|
|
|
|
|
|
2019-02-08 12:01:50 +01:00
|
|
|
static const struct spa_dict info = SPA_DICT_INIT_ARRAY(info_items);
|
2018-01-11 10:23:37 +01:00
|
|
|
|
2022-06-15 17:24:41 +02:00
|
|
|
const struct spa_handle_factory spa_media_sink_factory = {
|
2018-01-11 10:23:37 +01:00
|
|
|
SPA_VERSION_HANDLE_FACTORY,
|
2022-06-15 17:24:41 +02:00
|
|
|
SPA_NAME_API_BLUEZ5_MEDIA_SINK,
|
2018-01-11 10:23:37 +01:00
|
|
|
&info,
|
2018-04-09 10:06:17 +02:00
|
|
|
impl_get_size,
|
2018-01-11 10:23:37 +01:00
|
|
|
impl_init,
|
|
|
|
|
impl_enum_interface_info,
|
|
|
|
|
};
|
2022-09-15 23:02:51 +03:00
|
|
|
|
|
|
|
|
/* Retained for backward compatibility: */
|
|
|
|
|
const struct spa_handle_factory spa_a2dp_sink_factory = {
|
|
|
|
|
SPA_VERSION_HANDLE_FACTORY,
|
|
|
|
|
SPA_NAME_API_BLUEZ5_A2DP_SINK,
|
|
|
|
|
&info,
|
|
|
|
|
impl_get_size,
|
|
|
|
|
impl_init,
|
|
|
|
|
impl_enum_interface_info,
|
|
|
|
|
};
|
2025-06-08 13:19:05 +03:00
|
|
|
|
|
|
|
|
/* Retained for backward compatibility: */
|
|
|
|
|
const struct spa_handle_factory spa_sco_sink_factory = {
|
|
|
|
|
SPA_VERSION_HANDLE_FACTORY,
|
|
|
|
|
SPA_NAME_API_BLUEZ5_SCO_SINK,
|
|
|
|
|
&info,
|
|
|
|
|
impl_get_size,
|
|
|
|
|
impl_init,
|
|
|
|
|
impl_enum_interface_info,
|
|
|
|
|
};
|