From 4e0d0c5f0befd3973b9ed22a7a45f2a9b3b7e449 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 7 Jun 2025 20:18:49 +0300 Subject: [PATCH] bluez5: replace codec->bap/asha flags with codec->kind enum Indicate codec type with enum instead of bool flags. This is in preparation of moving also HFP to media codecs. --- spa/plugins/bluez5/a2dp-codec-aac.c | 2 + spa/plugins/bluez5/a2dp-codec-aptx.c | 3 ++ spa/plugins/bluez5/a2dp-codec-faststream.c | 1 + spa/plugins/bluez5/a2dp-codec-lc3plus.c | 1 + spa/plugins/bluez5/a2dp-codec-ldac.c | 1 + spa/plugins/bluez5/a2dp-codec-opus-g.c | 1 + spa/plugins/bluez5/a2dp-codec-opus.c | 1 + spa/plugins/bluez5/a2dp-codec-sbc.c | 2 + spa/plugins/bluez5/asha-codec-g722.c | 2 +- spa/plugins/bluez5/bap-codec-lc3.c | 2 +- spa/plugins/bluez5/bluez5-dbus.c | 43 ++++++++++++---------- spa/plugins/bluez5/codec-loader.c | 11 ++++++ spa/plugins/bluez5/iso-io.c | 2 +- spa/plugins/bluez5/media-codecs.c | 2 +- spa/plugins/bluez5/media-codecs.h | 29 +++++++++++++-- spa/plugins/bluez5/media-sink.c | 30 ++++++++------- spa/plugins/bluez5/media-source.c | 10 ++--- 17 files changed, 97 insertions(+), 46 deletions(-) diff --git a/spa/plugins/bluez5/a2dp-codec-aac.c b/spa/plugins/bluez5/a2dp-codec-aac.c index 7522f3bb7..4e50cae45 100644 --- a/spa/plugins/bluez5/a2dp-codec-aac.c +++ b/spa/plugins/bluez5/a2dp-codec-aac.c @@ -683,6 +683,7 @@ static void codec_set_log(struct spa_log *global_log) const struct media_codec a2dp_codec_aac = { .id = SPA_BLUETOOTH_AUDIO_CODEC_AAC, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_MPEG24, .name = "aac", .description = "AAC", @@ -708,6 +709,7 @@ const struct media_codec a2dp_codec_aac = { const struct media_codec a2dp_codec_aac_eld = { .id = SPA_BLUETOOTH_AUDIO_CODEC_AAC_ELD, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_MPEG24, .name = "aac_eld", .description = "AAC-ELD", diff --git a/spa/plugins/bluez5/a2dp-codec-aptx.c b/spa/plugins/bluez5/a2dp-codec-aptx.c index e10691e78..d74238378 100644 --- a/spa/plugins/bluez5/a2dp-codec-aptx.c +++ b/spa/plugins/bluez5/a2dp-codec-aptx.c @@ -617,6 +617,7 @@ static int msbc_decode(void *data, const struct media_codec a2dp_codec_aptx = { .id = SPA_BLUETOOTH_AUDIO_CODEC_APTX, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_VENDOR, .vendor = { .vendor_id = APTX_VENDOR_ID, .codec_id = APTX_CODEC_ID }, @@ -641,6 +642,7 @@ const struct media_codec a2dp_codec_aptx = { const struct media_codec a2dp_codec_aptx_hd = { .id = SPA_BLUETOOTH_AUDIO_CODEC_APTX_HD, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_VENDOR, .vendor = { .vendor_id = APTX_HD_VENDOR_ID, .codec_id = APTX_HD_CODEC_ID }, @@ -663,6 +665,7 @@ const struct media_codec a2dp_codec_aptx_hd = { }; #define APTX_LL_COMMON_DEFS \ + .kind = MEDIA_CODEC_A2DP, \ .codec_id = A2DP_CODEC_VENDOR, \ .description = "aptX-LL", \ .fill_caps = codec_fill_caps, \ diff --git a/spa/plugins/bluez5/a2dp-codec-faststream.c b/spa/plugins/bluez5/a2dp-codec-faststream.c index bbf9e96ab..1f1875171 100644 --- a/spa/plugins/bluez5/a2dp-codec-faststream.c +++ b/spa/plugins/bluez5/a2dp-codec-faststream.c @@ -584,6 +584,7 @@ static const struct media_codec duplex_codec = { }; #define FASTSTREAM_COMMON_DEFS \ + .kind = MEDIA_CODEC_A2DP, \ .codec_id = A2DP_CODEC_VENDOR, \ .vendor = { .vendor_id = FASTSTREAM_VENDOR_ID, \ .codec_id = FASTSTREAM_CODEC_ID }, \ diff --git a/spa/plugins/bluez5/a2dp-codec-lc3plus.c b/spa/plugins/bluez5/a2dp-codec-lc3plus.c index 05a3aa209..808a6b721 100644 --- a/spa/plugins/bluez5/a2dp-codec-lc3plus.c +++ b/spa/plugins/bluez5/a2dp-codec-lc3plus.c @@ -740,6 +740,7 @@ static int codec_increase_bitpool(void *data) const struct media_codec a2dp_codec_lc3plus_hr = { .id = SPA_BLUETOOTH_AUDIO_CODEC_LC3PLUS_HR, + .kind = MEDIA_CODEC_A2DP, .name = "lc3plus_hr", .codec_id = A2DP_CODEC_VENDOR, .vendor = { .vendor_id = LC3PLUS_HR_VENDOR_ID, diff --git a/spa/plugins/bluez5/a2dp-codec-ldac.c b/spa/plugins/bluez5/a2dp-codec-ldac.c index 3abc8e36c..4ae86b571 100644 --- a/spa/plugins/bluez5/a2dp-codec-ldac.c +++ b/spa/plugins/bluez5/a2dp-codec-ldac.c @@ -748,6 +748,7 @@ static void codec_set_log(struct spa_log *global_log) const struct media_codec a2dp_codec_ldac = { .id = SPA_BLUETOOTH_AUDIO_CODEC_LDAC, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_VENDOR, .vendor = { .vendor_id = LDAC_VENDOR_ID, .codec_id = LDAC_CODEC_ID }, diff --git a/spa/plugins/bluez5/a2dp-codec-opus-g.c b/spa/plugins/bluez5/a2dp-codec-opus-g.c index 85a36bf8d..018a5a9ce 100644 --- a/spa/plugins/bluez5/a2dp-codec-opus-g.c +++ b/spa/plugins/bluez5/a2dp-codec-opus-g.c @@ -512,6 +512,7 @@ static void codec_set_log(struct spa_log *global_log) const struct media_codec a2dp_codec_opus_g = { .id = SPA_BLUETOOTH_AUDIO_CODEC_OPUS_G, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_VENDOR, .vendor = { .vendor_id = OPUS_G_VENDOR_ID, .codec_id = OPUS_G_CODEC_ID }, diff --git a/spa/plugins/bluez5/a2dp-codec-opus.c b/spa/plugins/bluez5/a2dp-codec-opus.c index e65b62fac..42cb1caba 100644 --- a/spa/plugins/bluez5/a2dp-codec-opus.c +++ b/spa/plugins/bluez5/a2dp-codec-opus.c @@ -1349,6 +1349,7 @@ static void codec_set_log(struct spa_log *global_log) } #define OPUS_05_COMMON_DEFS \ + .kind = MEDIA_CODEC_A2DP, \ .codec_id = A2DP_CODEC_VENDOR, \ .vendor = { .vendor_id = OPUS_05_VENDOR_ID, \ .codec_id = OPUS_05_CODEC_ID }, \ diff --git a/spa/plugins/bluez5/a2dp-codec-sbc.c b/spa/plugins/bluez5/a2dp-codec-sbc.c index fc55a031d..5c178c87b 100644 --- a/spa/plugins/bluez5/a2dp-codec-sbc.c +++ b/spa/plugins/bluez5/a2dp-codec-sbc.c @@ -634,6 +634,7 @@ static void codec_get_delay(void *data, uint32_t *encoder, uint32_t *decoder) const struct media_codec a2dp_codec_sbc = { .id = SPA_BLUETOOTH_AUDIO_CODEC_SBC, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_SBC, .name = "sbc", .description = "SBC", @@ -657,6 +658,7 @@ const struct media_codec a2dp_codec_sbc = { const struct media_codec a2dp_codec_sbc_xq = { .id = SPA_BLUETOOTH_AUDIO_CODEC_SBC_XQ, + .kind = MEDIA_CODEC_A2DP, .codec_id = A2DP_CODEC_SBC, .name = "sbc_xq", .description = "SBC-XQ", diff --git a/spa/plugins/bluez5/asha-codec-g722.c b/spa/plugins/bluez5/asha-codec-g722.c index 8faa920cb..3aaed84f2 100644 --- a/spa/plugins/bluez5/asha-codec-g722.c +++ b/spa/plugins/bluez5/asha-codec-g722.c @@ -155,9 +155,9 @@ static void codec_set_log(struct spa_log *global_log) const struct media_codec asha_codec_g722 = { .id = SPA_BLUETOOTH_AUDIO_CODEC_G722, + .kind = MEDIA_CODEC_ASHA, .codec_id = ASHA_CODEC_G722, .name = "g722", - .asha = true, .description = "G722", .fill_caps = NULL, .enum_config = codec_enum_config, diff --git a/spa/plugins/bluez5/bap-codec-lc3.c b/spa/plugins/bluez5/bap-codec-lc3.c index 2f1117ef8..80174dd3d 100644 --- a/spa/plugins/bluez5/bap-codec-lc3.c +++ b/spa/plugins/bluez5/bap-codec-lc3.c @@ -1401,9 +1401,9 @@ static int codec_get_bis_config(const struct media_codec *codec, uint8_t *caps, const struct media_codec bap_codec_lc3 = { .id = SPA_BLUETOOTH_AUDIO_CODEC_LC3, + .kind = MEDIA_CODEC_BAP, .name = "lc3", .codec_id = BAP_CODEC_LC3, - .bap = true, .description = "LC3", .fill_caps = codec_fill_caps, .select_config = codec_select_config, diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index 61491056f..ba2ac0bbc 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -458,9 +458,9 @@ static int media_codec_to_endpoint(const struct media_codec *codec, const char * endpoint; if (direction == SPA_BT_MEDIA_SOURCE) - endpoint = codec->bap ? BAP_SOURCE_ENDPOINT : A2DP_SOURCE_ENDPOINT; + endpoint = codec->kind == MEDIA_CODEC_BAP ? BAP_SOURCE_ENDPOINT : A2DP_SOURCE_ENDPOINT; else if (direction == SPA_BT_MEDIA_SINK) - endpoint = codec->bap ? BAP_SINK_ENDPOINT : A2DP_SINK_ENDPOINT; + endpoint = codec->kind == MEDIA_CODEC_BAP ? BAP_SINK_ENDPOINT : A2DP_SINK_ENDPOINT; else if (direction == SPA_BT_MEDIA_SOURCE_BROADCAST) endpoint = BAP_BROADCAST_SOURCE_ENDPOINT; else if (direction == SPA_BT_MEDIA_SINK_BROADCAST) @@ -568,11 +568,14 @@ static enum spa_bt_profile get_codec_profile(const struct media_codec *codec, { switch (direction) { case SPA_BT_MEDIA_SOURCE: - return codec->bap ? SPA_BT_PROFILE_BAP_SOURCE : SPA_BT_PROFILE_A2DP_SOURCE; + return codec->kind == MEDIA_CODEC_BAP ? SPA_BT_PROFILE_BAP_SOURCE : SPA_BT_PROFILE_A2DP_SOURCE; case SPA_BT_MEDIA_SINK: - if (codec->asha) + if (codec->kind == MEDIA_CODEC_ASHA) return SPA_BT_PROFILE_ASHA_SINK; - return codec->bap ? SPA_BT_PROFILE_BAP_SINK : SPA_BT_PROFILE_A2DP_SINK; + else if (codec->kind == MEDIA_CODEC_BAP) + return SPA_BT_PROFILE_BAP_SINK; + else + return SPA_BT_PROFILE_A2DP_SINK; case SPA_BT_MEDIA_SOURCE_BROADCAST: return SPA_BT_PROFILE_BAP_BROADCAST_SOURCE; case SPA_BT_MEDIA_SINK_BROADCAST: @@ -971,7 +974,7 @@ static DBusHandlerResult endpoint_select_properties(DBusConnection *conn, DBusMe */ codec = media_endpoint_to_codec(monitor, path, &sink, NULL); spa_log_debug(monitor->log, "%p: %s codec:%s", monitor, path, codec ? codec->name : ""); - if (!codec || !codec->bap || !codec->get_qos) { + if (!codec || codec->kind != MEDIA_CODEC_BAP || !codec->get_qos) { spa_log_error(monitor->log, "Unsupported codec"); err_msg = "Unsupported codec"; goto error; @@ -2537,7 +2540,7 @@ bool spa_bt_device_supports_media_codec(struct spa_bt_device *device, const stru { SPA_BLUETOOTH_AUDIO_CODEC_APTX_LL_DUPLEX, SPA_BT_FEATURE_A2DP_DUPLEX }, { SPA_BLUETOOTH_AUDIO_CODEC_FASTSTREAM_DUPLEX, SPA_BT_FEATURE_A2DP_DUPLEX }, }; - bool is_a2dp = !codec->bap && !codec->asha; + bool is_a2dp = codec->kind == MEDIA_CODEC_A2DP; size_t i; if (!is_media_codec_enabled(device->monitor, codec)) @@ -2548,7 +2551,7 @@ bool spa_bt_device_supports_media_codec(struct spa_bt_device *device, const stru return (codec->codec_id == A2DP_CODEC_SBC && spa_streq(codec->name, "sbc") && device->adapter->legacy_endpoints_registered); } - if (!device->adapter->bap_application_registered && codec->bap) + if (!device->adapter->bap_application_registered && codec->kind == MEDIA_CODEC_BAP) return false; /* Check codec quirks */ @@ -4178,7 +4181,7 @@ static int setup_asha_transport(struct spa_bt_remote_endpoint *remote_endpoint, for (int i = 0; media_codecs[i]; i++) { const struct media_codec *mcodec = media_codecs[i]; - if (!mcodec->asha) + if (mcodec->kind != MEDIA_CODEC_ASHA) continue; if (!spa_streq(mcodec->name, "g722")) continue; @@ -4577,7 +4580,7 @@ static int media_codec_switch_cmp(const void *a, const void *b) else if (ep2 == NULL) return -1; - if (codec->bap) + if (codec->kind == MEDIA_CODEC_BAP) flags = spa_streq(ep1->uuid, SPA_BT_UUID_BAP_SOURCE) ? MEDIA_CODEC_FLAG_SINK : 0; else flags = spa_streq(ep1->uuid, SPA_BT_UUID_A2DP_SOURCE) ? MEDIA_CODEC_FLAG_SINK : 0; @@ -5178,10 +5181,9 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage * uint8_t caps[A2DP_MAX_CAPS_SIZE]; int caps_size, ret; uint16_t codec_id = codec->codec_id; + enum media_codec_kind kind = is_bap ? MEDIA_CODEC_BAP : MEDIA_CODEC_A2DP; - if (codec->bap != is_bap) - continue; - if (codec->asha) + if (codec->kind != kind) continue; if (!is_media_codec_enabled(monitor, codec)) @@ -5197,7 +5199,7 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage * if (ret == 0) { spa_log_info(monitor->log, "register media sink codec %s: %s", media_codecs[i]->name, endpoint); append_media_object(monitor, &array, endpoint, - codec->bap ? SPA_BT_UUID_BAP_SINK : SPA_BT_UUID_A2DP_SINK, + is_bap ? SPA_BT_UUID_BAP_SINK : SPA_BT_UUID_A2DP_SINK, codec_id, caps, caps_size); } } @@ -5212,12 +5214,12 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage * if (ret == 0) { spa_log_info(monitor->log, "register media source codec %s: %s", media_codecs[i]->name, endpoint); append_media_object(monitor, &array, endpoint, - codec->bap ? SPA_BT_UUID_BAP_SOURCE : SPA_BT_UUID_A2DP_SOURCE, + is_bap ? SPA_BT_UUID_BAP_SOURCE : SPA_BT_UUID_A2DP_SOURCE, codec_id, caps, caps_size); } } - if (codec->bap && register_bcast) { + if (is_bap && register_bcast) { if (endpoint_should_be_registered(monitor, codec, SPA_BT_MEDIA_SOURCE_BROADCAST)) { caps_size = codec->fill_caps(codec, 0, &monitor->global_settings, caps); if (caps_size < 0) @@ -5375,7 +5377,7 @@ static int register_media_application(struct spa_bt_monitor * monitor) register_media_endpoint(monitor, codec, SPA_BT_MEDIA_SOURCE); register_media_endpoint(monitor, codec, SPA_BT_MEDIA_SINK); - if (codec->bap) { + if (codec->kind == MEDIA_CODEC_BAP) { register_media_endpoint(monitor, codec, SPA_BT_MEDIA_SOURCE_BROADCAST); register_media_endpoint(monitor, codec, SPA_BT_MEDIA_SINK_BROADCAST); } @@ -5411,7 +5413,7 @@ static void unregister_media_application(struct spa_bt_monitor * monitor) unregister_media_endpoint(monitor, codec, SPA_BT_MEDIA_SOURCE); unregister_media_endpoint(monitor, codec, SPA_BT_MEDIA_SINK); - if (codec->bap) { + if (codec->kind == MEDIA_CODEC_BAP) { unregister_media_endpoint(monitor, codec, SPA_BT_MEDIA_SOURCE_BROADCAST); unregister_media_endpoint(monitor, codec, SPA_BT_MEDIA_SINK_BROADCAST); } @@ -5428,8 +5430,9 @@ static bool have_codec_endpoints(struct spa_bt_monitor *monitor, bool bap) for (i = 0; media_codecs[i]; i++) { const struct media_codec *codec = media_codecs[i]; + enum media_codec_kind kind = bap ? MEDIA_CODEC_BAP : MEDIA_CODEC_A2DP; - if (codec->bap != bap) + if (codec->kind != kind) continue; if (endpoint_should_be_registered(monitor, codec, SPA_BT_MEDIA_SINK) || endpoint_should_be_registered(monitor, codec, SPA_BT_MEDIA_SOURCE) || @@ -5779,7 +5782,7 @@ static void interface_added(struct spa_bt_monitor *monitor, /* get local endpoint */ for (i = 0; monitor->media_codecs[i]; i++) { - if (!monitor->media_codecs[i]->bap) + if (monitor->media_codecs[i]->kind != MEDIA_CODEC_BAP) continue; if (!is_media_codec_enabled(monitor, monitor->media_codecs[i])) continue; diff --git a/spa/plugins/bluez5/codec-loader.c b/spa/plugins/bluez5/codec-loader.c index 6fd1d0430..ba2c1aa5e 100644 --- a/spa/plugins/bluez5/codec-loader.c +++ b/spa/plugins/bluez5/codec-loader.c @@ -120,6 +120,17 @@ static int load_media_codecs_from(struct impl *impl, const char *factory_name, c break; } + switch (c->kind) { + case MEDIA_CODEC_A2DP: + case MEDIA_CODEC_BAP: + case MEDIA_CODEC_ASHA: + break; + default: + spa_log_warn(impl->log, "codec plugin %s: unknown codec %s kind %d", + factory_name, c->name, c->kind); + continue; + } + /* Don't load duplicate endpoints */ for (j = 0; j < impl->n_codecs; ++j) { const struct media_codec *c2 = impl->codecs[j]; diff --git a/spa/plugins/bluez5/iso-io.c b/spa/plugins/bluez5/iso-io.c index cdfc6ec4f..8fc488eec 100644 --- a/spa/plugins/bluez5/iso-io.c +++ b/spa/plugins/bluez5/iso-io.c @@ -417,7 +417,7 @@ static struct stream *stream_create(struct spa_bt_transport *t, struct group *gr sink = false; } - if (!t->media_codec->bap || !t->media_codec->get_interval) { + if (t->media_codec->kind != MEDIA_CODEC_BAP || !t->media_codec->get_interval) { res = -EINVAL; goto fail; } diff --git a/spa/plugins/bluez5/media-codecs.c b/spa/plugins/bluez5/media-codecs.c index 718e54ea2..00a0bbf08 100644 --- a/spa/plugins/bluez5/media-codecs.c +++ b/spa/plugins/bluez5/media-codecs.c @@ -91,7 +91,7 @@ bool media_codec_check_caps(const struct media_codec *codec, unsigned int codec_ if (res < 0) return false; - if (codec->bap) + if (codec->kind == MEDIA_CODEC_BAP) return true; else return ((size_t)res == caps_size); diff --git a/spa/plugins/bluez5/media-codecs.h b/spa/plugins/bluez5/media-codecs.h index ed62cd131..0030ee615 100644 --- a/spa/plugins/bluez5/media-codecs.h +++ b/spa/plugins/bluez5/media-codecs.h @@ -26,7 +26,7 @@ #define SPA_TYPE_INTERFACE_Bluez5CodecMedia SPA_TYPE_INFO_INTERFACE_BASE "Bluez5:Codec:Media:Private" -#define SPA_VERSION_BLUEZ5_CODEC_MEDIA 13 +#define SPA_VERSION_BLUEZ5_CODEC_MEDIA 14 struct spa_bluez5_codec_a2dp { struct spa_interface iface; @@ -60,6 +60,13 @@ enum { NEED_FLUSH_FRAGMENT = 2, }; +enum media_codec_kind { + MEDIA_CODEC_A2DP, + MEDIA_CODEC_BAP, + MEDIA_CODEC_ASHA, + MEDIA_CODEC_HFP, +}; + struct media_codec_audio_info { uint32_t rate; uint32_t channels; @@ -67,12 +74,11 @@ struct media_codec_audio_info { struct media_codec { enum spa_bluetooth_audio_codec id; + enum media_codec_kind kind; + uint8_t codec_id; a2dp_vendor_codec_t vendor; - bool bap; - bool asha; - const char *name; const char *description; const char *endpoint_name; /**< Endpoint name. If NULL, same as name */ @@ -219,6 +225,21 @@ struct media_codec_config { unsigned int priority; }; +static inline const char *media_codec_kind_str(const struct media_codec *codec) +{ + switch (codec->kind) { + case MEDIA_CODEC_A2DP: + return "A2DP"; + case MEDIA_CODEC_BAP: + return "BAP"; + case MEDIA_CODEC_ASHA: + return "ASHA"; + case MEDIA_CODEC_HFP: + return "HFP"; + } + return "unknown"; +} + int media_codec_select_config(const struct media_codec_config configs[], size_t n, uint32_t cap, int preferred_value); diff --git a/spa/plugins/bluez5/media-sink.c b/spa/plugins/bluez5/media-sink.c index 374db005a..22dbad068 100644 --- a/spa/plugins/bluez5/media-sink.c +++ b/spa/plugins/bluez5/media-sink.c @@ -649,8 +649,12 @@ static int reset_buffer(struct impl *this) this->need_flush = 0; this->block_count = 0; this->fragment = false; - this->timestamp = (this->codec->bap || this->codec->asha) ? (get_reference_time(this, NULL) / SPA_NSEC_PER_USEC) - : this->sample_count; + + 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; + this->buffer_used = this->codec->start_encode(this->codec_data, this->buffer, sizeof(this->buffer), ++this->seqnum, this->timestamp); @@ -865,7 +869,7 @@ static void enable_flush_timer(struct impl *this, bool enabled) static int flush_data(struct impl *this, uint64_t now_time) { struct port *port = &this->port; - bool is_asha = this->codec->asha; + bool is_asha = this->codec->kind == MEDIA_CODEC_ASHA; uint32_t total_frames; int written; int unsent_buffer; @@ -1447,7 +1451,7 @@ static int transport_start(struct impl *this) conf = this->transport->configuration; size = this->transport->configuration_len; - is_asha = this->codec->asha; + is_asha = this->codec->kind == MEDIA_CODEC_ASHA; spa_log_debug(this->log, "Transport configuration:"); spa_debug_log_mem(this->log, SPA_LOG_LEVEL_DEBUG, 2, conf, (size_t)size); @@ -1478,7 +1482,7 @@ static int transport_start(struct impl *this) if (this->codec->get_delay) this->codec->get_delay(this->codec_data, &this->encoder_delay, NULL); - const char *codec_profile = this->codec->asha ? "ASHA" : (this->codec->bap ? "BAP" : "A2DP"); + const char *codec_profile = media_codec_kind_str(this->codec); spa_log_info(this->log, "%p: using %s codec %s, delay:%.2f ms, codec-delay:%.2f ms", this, codec_profile, this->codec->description, (double)spa_bt_transport_get_delay_nsec(this->transport) / SPA_NSEC_PER_MSEC, @@ -1653,7 +1657,7 @@ static int do_remove_transport_source(struct spa_loop *loop, if (this->flush_timer_source.loop) spa_loop_remove_source(this->data_loop, &this->flush_timer_source); - if (this->codec->asha) { + if (this->codec->kind == MEDIA_CODEC_ASHA) { if (this->asha->timer_source.loop) spa_loop_remove_source(this->data_loop, &this->asha->timer_source); if (this->asha->flush_source.loop) @@ -1761,7 +1765,7 @@ static void emit_node_info(struct impl *this, bool full) node_group = node_group_buf; } - const char *codec_profile = this->codec->asha ? "ASHA" : (this->codec->bap ? "BAP" : "A2DP"); + const char *codec_profile = media_codec_kind_str(this->codec); struct spa_dict_item node_info_items[] = { { SPA_KEY_DEVICE_API, "bluez5" }, { SPA_KEY_MEDIA_CLASS, this->is_internal ? "Audio/Sink/Internal" : @@ -1945,7 +1949,7 @@ impl_node_port_enum_params(void *object, int seq, SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_buffers))); break; case 1: - if (!this->codec->bap) + if (this->codec->kind != MEDIA_CODEC_BAP) return 0; param = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamIO, id, @@ -2158,7 +2162,7 @@ impl_node_port_set_io(void *object, port->io = data; break; case SPA_IO_RateMatch: - if (!this->codec->bap) + if (this->codec->kind != MEDIA_CODEC_BAP) return -ENOENT; port->rate_match = data; break; @@ -2244,7 +2248,7 @@ static int impl_node_process(void *object) setup_matching(this); - if (this->codec->asha && !this->asha->set_timer) { + if (this->codec->kind == MEDIA_CODEC_ASHA && !this->asha->set_timer) { struct impl *other = find_other_asha(this); if (other && other->asha->ref_t0 != 0) { this->asha->ref_t0 = other->asha->ref_t0; @@ -2390,7 +2394,7 @@ static int impl_clear(struct spa_handle *handle) spa_hook_remove(&this->transport_listener); spa_system_close(this->data_system, this->timerfd); spa_system_close(this->data_system, this->flush_timerfd); - if (this->codec->asha) { + if (this->codec->kind == MEDIA_CODEC_ASHA) { spa_system_close(this->data_system, this->asha->timerfd); free(this->asha); } @@ -2519,7 +2523,7 @@ impl_init(const struct spa_handle_factory *factory, this->is_duplex ? MEDIA_CODEC_FLAG_SINK : 0, this->transport->device->settings); - if (this->codec->bap) + if (this->codec->kind == MEDIA_CODEC_BAP) this->is_output = this->transport->bap_initiator; else this->is_output = true; @@ -2537,7 +2541,7 @@ impl_init(const struct spa_handle_factory *factory, this->flush_timerfd = spa_system_timerfd_create(this->data_system, CLOCK_MONOTONIC, SPA_FD_CLOEXEC | SPA_FD_NONBLOCK); - if (this->codec->asha) { + if (this->codec->kind == MEDIA_CODEC_ASHA) { this->asha = calloc(1, sizeof(struct spa_bt_asha)); if (this->asha == NULL) return -ENOMEM; diff --git a/spa/plugins/bluez5/media-source.c b/spa/plugins/bluez5/media-source.c index e8d77c1d3..c53ee9164 100644 --- a/spa/plugins/bluez5/media-source.c +++ b/spa/plugins/bluez5/media-source.c @@ -324,7 +324,7 @@ static void emit_node_info(struct impl *this, bool full); static void set_latency(struct impl *this, bool emit_latency) { - if (this->codec->bap && !this->is_input && this->transport && + if (this->codec->kind == MEDIA_CODEC_BAP && !this->is_input && this->transport && this->transport->delay_us != SPA_BT_UNKNOWN_DELAY) { struct port *port = &this->port; unsigned int node_latency = 2048; @@ -751,7 +751,7 @@ static int transport_start(struct impl *this) return -EIO; spa_log_info(this->log, "%p: using %s codec %s", this, - this->codec->bap ? "BAP" : "A2DP", this->codec->description); + media_codec_kind_str(this->codec), this->codec->description); /* * If the link is bidirectional, media-sink may also be polling the same FD, @@ -983,7 +983,7 @@ static void emit_node_info(struct impl *this, bool full) sizeof(media_name), "%s (codec %s)", ((this->transport && this->transport->device->name) ? - this->transport->device->name : this->codec->bap ? "BAP" : "A2DP"), + this->transport->device->name : media_codec_kind_str(this->codec)), this->codec->description ); @@ -1465,7 +1465,7 @@ static void update_target_latency(struct impl *this) if (this->transport == NULL || !port->have_format) return; - if (!this->codec->bap || this->is_input || + if (this->codec->kind != MEDIA_CODEC_BAP || this->is_input || this->transport->delay_us == SPA_BT_UNKNOWN_DELAY) return; @@ -1905,7 +1905,7 @@ impl_init(const struct spa_handle_factory *factory, this->is_input = true; } - if (this->codec->bap) + if (this->codec->kind == MEDIA_CODEC_BAP) this->is_input = this->transport->bap_initiator; if (this->codec->init_props != NULL)