mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
bluez5: split A2DP codecs to separate SPA plugins
Make easier to package A2DP codecs separately, by splitting each to a separate SPA plugin. Adjust the code to not use a global variable for the codec list. The A2DP SPA interface API is in the bluez5 private headers, and not exposed in installed SPA headers, as it's too close to the implementation.
This commit is contained in:
parent
3115775c02
commit
59d572de09
15 changed files with 911 additions and 469 deletions
|
|
@ -115,6 +115,7 @@ extern "C" {
|
|||
#define SPA_NAME_API_BLUEZ5_A2DP_SOURCE "api.bluez5.a2dp.source" /**< a capture Node interface for A2DP profiles */
|
||||
#define SPA_NAME_API_BLUEZ5_SCO_SINK "api.bluez5.sco.sink" /**< a playback Node interface for HSP/HFP profiles */
|
||||
#define SPA_NAME_API_BLUEZ5_SCO_SOURCE "api.bluez5.sco.source" /**< a capture Node interface for HSP/HFP profiles */
|
||||
#define SPA_NAME_API_BLUEZ5_CODEC_A2DP "api.bluez5.codec.a2dp" /**< Bluez5 A2DP codec plugin */
|
||||
|
||||
/** keys for v4l2 factory names */
|
||||
#define SPA_NAME_API_V4L2_ENUM_UDEV "api.v4l2.enum.udev" /**< a v4l2 udev Device interface */
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
#include <spa/param/audio/format.h>
|
||||
#include <spa/utils/dict.h>
|
||||
|
||||
#include <fdk-aac/aacenc_lib.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "rtp.h"
|
||||
#include "a2dp-codecs.h"
|
||||
|
||||
|
|
@ -506,3 +506,8 @@ const struct a2dp_codec a2dp_codec_aac = {
|
|||
.reduce_bitpool = codec_reduce_bitpool,
|
||||
.increase_bitpool = codec_increase_bitpool,
|
||||
};
|
||||
|
||||
A2DP_CODEC_EXPORT_DEF(
|
||||
"aac",
|
||||
&a2dp_codec_aac
|
||||
);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
|
||||
#include <freeaptx.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "rtp.h"
|
||||
#include "a2dp-codecs.h"
|
||||
|
||||
|
|
@ -42,6 +41,10 @@
|
|||
#define APTX_LL_LEVEL2(level) (((level) >> 0) & 0xFF)
|
||||
#define APTX_LL_LEVEL(level1, level2) ((((level1) & 0xFF) << 8) | (((level2) & 0xFF) << 0))
|
||||
|
||||
#define MSBC_DECODED_SIZE 240
|
||||
#define MSBC_ENCODED_SIZE 60
|
||||
#define MSBC_PAYLOAD_SIZE 57
|
||||
|
||||
/*
|
||||
* XXX: Bump requested device buffer levels up by 50% from defaults,
|
||||
* XXX: increasing latency similarly. This seems to be necessary for
|
||||
|
|
@ -723,3 +726,13 @@ const struct a2dp_codec a2dp_codec_aptx_ll_duplex_1 = {
|
|||
.endpoint_name = "aptx_ll_duplex_1",
|
||||
.duplex_codec = &aptx_ll_msbc,
|
||||
};
|
||||
|
||||
A2DP_CODEC_EXPORT_DEF(
|
||||
"aptx",
|
||||
&a2dp_codec_aptx_hd,
|
||||
&a2dp_codec_aptx,
|
||||
&a2dp_codec_aptx_ll_0,
|
||||
&a2dp_codec_aptx_ll_1,
|
||||
&a2dp_codec_aptx_ll_duplex_0,
|
||||
&a2dp_codec_aptx_ll_duplex_1
|
||||
);
|
||||
|
|
|
|||
355
spa/plugins/bluez5/a2dp-codec-caps.h
Normal file
355
spa/plugins/bluez5/a2dp-codec-caps.h
Normal file
|
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
*
|
||||
* BlueZ - Bluetooth protocol stack for Linux
|
||||
*
|
||||
* Copyright (C) 2006-2010 Nokia Corporation
|
||||
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||
* Copyright (C) 2018 Pali Rohár <pali.rohar@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SPA_BLUEZ5_A2DP_CODEC_CAPS_H_
|
||||
#define SPA_BLUEZ5_A2DP_CODEC_CAPS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define A2DP_CODEC_SBC 0x00
|
||||
#define A2DP_CODEC_MPEG12 0x01
|
||||
#define A2DP_CODEC_MPEG24 0x02
|
||||
#define A2DP_CODEC_ATRAC 0x03
|
||||
#define A2DP_CODEC_VENDOR 0xFF
|
||||
|
||||
#define A2DP_MAX_CAPS_SIZE 254
|
||||
|
||||
/* customized 16-bit vendor extension */
|
||||
#define A2DP_CODEC_VENDOR_APTX 0x4FFF
|
||||
#define A2DP_CODEC_VENDOR_LDAC 0x2DFF
|
||||
|
||||
#define SBC_SAMPLING_FREQ_48000 (1 << 0)
|
||||
#define SBC_SAMPLING_FREQ_44100 (1 << 1)
|
||||
#define SBC_SAMPLING_FREQ_32000 (1 << 2)
|
||||
#define SBC_SAMPLING_FREQ_16000 (1 << 3)
|
||||
|
||||
#define SBC_CHANNEL_MODE_JOINT_STEREO (1 << 0)
|
||||
#define SBC_CHANNEL_MODE_STEREO (1 << 1)
|
||||
#define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
|
||||
#define SBC_CHANNEL_MODE_MONO (1 << 3)
|
||||
|
||||
#define SBC_BLOCK_LENGTH_16 (1 << 0)
|
||||
#define SBC_BLOCK_LENGTH_12 (1 << 1)
|
||||
#define SBC_BLOCK_LENGTH_8 (1 << 2)
|
||||
#define SBC_BLOCK_LENGTH_4 (1 << 3)
|
||||
|
||||
#define SBC_SUBBANDS_8 (1 << 0)
|
||||
#define SBC_SUBBANDS_4 (1 << 1)
|
||||
|
||||
#define SBC_ALLOCATION_LOUDNESS (1 << 0)
|
||||
#define SBC_ALLOCATION_SNR (1 << 1)
|
||||
|
||||
#define SBC_MIN_BITPOOL 2
|
||||
#define SBC_MAX_BITPOOL 64
|
||||
|
||||
#define MPEG_CHANNEL_MODE_JOINT_STEREO (1 << 0)
|
||||
#define MPEG_CHANNEL_MODE_STEREO (1 << 1)
|
||||
#define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
|
||||
#define MPEG_CHANNEL_MODE_MONO (1 << 3)
|
||||
|
||||
#define MPEG_LAYER_MP3 (1 << 0)
|
||||
#define MPEG_LAYER_MP2 (1 << 1)
|
||||
#define MPEG_LAYER_MP1 (1 << 2)
|
||||
|
||||
#define MPEG_SAMPLING_FREQ_48000 (1 << 0)
|
||||
#define MPEG_SAMPLING_FREQ_44100 (1 << 1)
|
||||
#define MPEG_SAMPLING_FREQ_32000 (1 << 2)
|
||||
#define MPEG_SAMPLING_FREQ_24000 (1 << 3)
|
||||
#define MPEG_SAMPLING_FREQ_22050 (1 << 4)
|
||||
#define MPEG_SAMPLING_FREQ_16000 (1 << 5)
|
||||
|
||||
#define MPEG_BIT_RATE_VBR 0x8000
|
||||
#define MPEG_BIT_RATE_320000 0x4000
|
||||
#define MPEG_BIT_RATE_256000 0x2000
|
||||
#define MPEG_BIT_RATE_224000 0x1000
|
||||
#define MPEG_BIT_RATE_192000 0x0800
|
||||
#define MPEG_BIT_RATE_160000 0x0400
|
||||
#define MPEG_BIT_RATE_128000 0x0200
|
||||
#define MPEG_BIT_RATE_112000 0x0100
|
||||
#define MPEG_BIT_RATE_96000 0x0080
|
||||
#define MPEG_BIT_RATE_80000 0x0040
|
||||
#define MPEG_BIT_RATE_64000 0x0020
|
||||
#define MPEG_BIT_RATE_56000 0x0010
|
||||
#define MPEG_BIT_RATE_48000 0x0008
|
||||
#define MPEG_BIT_RATE_40000 0x0004
|
||||
#define MPEG_BIT_RATE_32000 0x0002
|
||||
#define MPEG_BIT_RATE_FREE 0x0001
|
||||
|
||||
#define AAC_OBJECT_TYPE_MPEG2_AAC_LC 0x80
|
||||
#define AAC_OBJECT_TYPE_MPEG4_AAC_LC 0x40
|
||||
#define AAC_OBJECT_TYPE_MPEG4_AAC_LTP 0x20
|
||||
#define AAC_OBJECT_TYPE_MPEG4_AAC_SCA 0x10
|
||||
|
||||
#define AAC_SAMPLING_FREQ_8000 0x0800
|
||||
#define AAC_SAMPLING_FREQ_11025 0x0400
|
||||
#define AAC_SAMPLING_FREQ_12000 0x0200
|
||||
#define AAC_SAMPLING_FREQ_16000 0x0100
|
||||
#define AAC_SAMPLING_FREQ_22050 0x0080
|
||||
#define AAC_SAMPLING_FREQ_24000 0x0040
|
||||
#define AAC_SAMPLING_FREQ_32000 0x0020
|
||||
#define AAC_SAMPLING_FREQ_44100 0x0010
|
||||
#define AAC_SAMPLING_FREQ_48000 0x0008
|
||||
#define AAC_SAMPLING_FREQ_64000 0x0004
|
||||
#define AAC_SAMPLING_FREQ_88200 0x0002
|
||||
#define AAC_SAMPLING_FREQ_96000 0x0001
|
||||
|
||||
#define AAC_CHANNELS_1 0x02
|
||||
#define AAC_CHANNELS_2 0x01
|
||||
|
||||
#define AAC_GET_BITRATE(a) ((a).bitrate1 << 16 | \
|
||||
(a).bitrate2 << 8 | (a).bitrate3)
|
||||
#define AAC_GET_FREQUENCY(a) ((a).frequency1 << 4 | (a).frequency2)
|
||||
|
||||
#define AAC_SET_BITRATE(a, b) \
|
||||
do { \
|
||||
(a).bitrate1 = ((b) >> 16) & 0x7f; \
|
||||
(a).bitrate2 = ((b) >> 8) & 0xff; \
|
||||
(a).bitrate3 = (b) & 0xff; \
|
||||
} while (0)
|
||||
#define AAC_SET_FREQUENCY(a, f) \
|
||||
do { \
|
||||
(a).frequency1 = ((f) >> 4) & 0xff; \
|
||||
(a).frequency2 = (f) & 0x0f; \
|
||||
} while (0)
|
||||
|
||||
#define AAC_INIT_BITRATE(b) \
|
||||
.bitrate1 = ((b) >> 16) & 0x7f, \
|
||||
.bitrate2 = ((b) >> 8) & 0xff, \
|
||||
.bitrate3 = (b) & 0xff,
|
||||
#define AAC_INIT_FREQUENCY(f) \
|
||||
.frequency1 = ((f) >> 4) & 0xff, \
|
||||
.frequency2 = (f) & 0x0f,
|
||||
|
||||
#define APTX_VENDOR_ID 0x0000004f
|
||||
#define APTX_CODEC_ID 0x0001
|
||||
|
||||
#define APTX_CHANNEL_MODE_MONO 0x01
|
||||
#define APTX_CHANNEL_MODE_STEREO 0x02
|
||||
|
||||
#define APTX_SAMPLING_FREQ_16000 0x08
|
||||
#define APTX_SAMPLING_FREQ_32000 0x04
|
||||
#define APTX_SAMPLING_FREQ_44100 0x02
|
||||
#define APTX_SAMPLING_FREQ_48000 0x01
|
||||
|
||||
#define APTX_HD_VENDOR_ID 0x000000D7
|
||||
#define APTX_HD_CODEC_ID 0x0024
|
||||
|
||||
#define APTX_HD_CHANNEL_MODE_MONO 0x1
|
||||
#define APTX_HD_CHANNEL_MODE_STEREO 0x2
|
||||
|
||||
#define APTX_HD_SAMPLING_FREQ_16000 0x8
|
||||
#define APTX_HD_SAMPLING_FREQ_32000 0x4
|
||||
#define APTX_HD_SAMPLING_FREQ_44100 0x2
|
||||
#define APTX_HD_SAMPLING_FREQ_48000 0x1
|
||||
|
||||
#define APTX_LL_VENDOR_ID 0x0000000a
|
||||
#define APTX_LL_VENDOR_ID2 0x000000d7
|
||||
#define APTX_LL_CODEC_ID 0x0002
|
||||
|
||||
/**
|
||||
* Default parameters for aptX LL (Sprint) encoder
|
||||
*/
|
||||
#define APTX_LL_TARGET_CODEC_LEVEL 180 /* target codec buffer level */
|
||||
#define APTX_LL_INITIAL_CODEC_LEVEL 360 /* initial codec buffer level */
|
||||
#define APTX_LL_SRA_MAX_RATE 50 /* x/10000 = 0.005 SRA rate */
|
||||
#define APTX_LL_SRA_AVG_TIME 1 /* SRA averaging time = 1s */
|
||||
#define APTX_LL_GOOD_WORKING_LEVEL 180 /* good working buffer level */
|
||||
|
||||
#define LDAC_VENDOR_ID 0x0000012d
|
||||
#define LDAC_CODEC_ID 0x00aa
|
||||
|
||||
#define LDAC_CHANNEL_MODE_MONO 0x04
|
||||
#define LDAC_CHANNEL_MODE_DUAL_CHANNEL 0x02
|
||||
#define LDAC_CHANNEL_MODE_STEREO 0x01
|
||||
|
||||
#define LDAC_SAMPLING_FREQ_44100 0x20
|
||||
#define LDAC_SAMPLING_FREQ_48000 0x10
|
||||
#define LDAC_SAMPLING_FREQ_88200 0x08
|
||||
#define LDAC_SAMPLING_FREQ_96000 0x04
|
||||
#define LDAC_SAMPLING_FREQ_176400 0x02
|
||||
#define LDAC_SAMPLING_FREQ_192000 0x01
|
||||
|
||||
#define FASTSTREAM_VENDOR_ID 0x0000000a
|
||||
#define FASTSTREAM_CODEC_ID 0x0001
|
||||
|
||||
#define FASTSTREAM_DIRECTION_SINK 0x1
|
||||
#define FASTSTREAM_DIRECTION_SOURCE 0x2
|
||||
|
||||
#define FASTSTREAM_SINK_SAMPLING_FREQ_44100 0x2
|
||||
#define FASTSTREAM_SINK_SAMPLING_FREQ_48000 0x1
|
||||
|
||||
#define FASTSTREAM_SOURCE_SAMPLING_FREQ_16000 0x2
|
||||
|
||||
typedef struct {
|
||||
uint32_t vendor_id;
|
||||
uint16_t codec_id;
|
||||
} __attribute__ ((packed)) a2dp_vendor_codec_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t frequency;
|
||||
uint8_t channel_mode;
|
||||
} __attribute__ ((packed)) a2dp_ldac_t;
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
||||
typedef struct {
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t frequency:4;
|
||||
uint8_t allocation_method:2;
|
||||
uint8_t subbands:2;
|
||||
uint8_t block_length:4;
|
||||
uint8_t min_bitpool;
|
||||
uint8_t max_bitpool;
|
||||
} __attribute__ ((packed)) a2dp_sbc_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t crc:1;
|
||||
uint8_t layer:3;
|
||||
uint8_t frequency:6;
|
||||
uint8_t mpf:1;
|
||||
uint8_t rfa:1;
|
||||
uint16_t bitrate;
|
||||
} __attribute__ ((packed)) a2dp_mpeg_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t object_type;
|
||||
uint8_t frequency1;
|
||||
uint8_t rfa:2;
|
||||
uint8_t channels:2;
|
||||
uint8_t frequency2:4;
|
||||
uint8_t bitrate1:7;
|
||||
uint8_t vbr:1;
|
||||
uint8_t bitrate2;
|
||||
uint8_t bitrate3;
|
||||
} __attribute__ ((packed)) a2dp_aac_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t frequency:4;
|
||||
} __attribute__ ((packed)) a2dp_aptx_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t frequency:4;
|
||||
uint32_t rfa;
|
||||
} __attribute__ ((packed)) a2dp_aptx_hd_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_aptx_t aptx;
|
||||
uint8_t bidirect_link:1;
|
||||
uint8_t has_new_caps:1;
|
||||
uint8_t reserved:6;
|
||||
} __attribute__ ((packed)) a2dp_aptx_ll_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t direction;
|
||||
uint8_t sink_frequency:4;
|
||||
uint8_t source_frequency:4;
|
||||
} __attribute__ ((packed)) a2dp_faststream_t;
|
||||
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
|
||||
typedef struct {
|
||||
uint8_t frequency:4;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t block_length:4;
|
||||
uint8_t subbands:2;
|
||||
uint8_t allocation_method:2;
|
||||
uint8_t min_bitpool;
|
||||
uint8_t max_bitpool;
|
||||
} __attribute__ ((packed)) a2dp_sbc_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t layer:3;
|
||||
uint8_t crc:1;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t rfa:1;
|
||||
uint8_t mpf:1;
|
||||
uint8_t frequency:6;
|
||||
uint16_t bitrate;
|
||||
} __attribute__ ((packed)) a2dp_mpeg_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t object_type;
|
||||
uint8_t frequency1;
|
||||
uint8_t frequency2:4;
|
||||
uint8_t channels:2;
|
||||
uint8_t rfa:2;
|
||||
uint8_t vbr:1;
|
||||
uint8_t bitrate1:7;
|
||||
uint8_t bitrate2;
|
||||
uint8_t bitrate3;
|
||||
} __attribute__ ((packed)) a2dp_aac_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t frequency:4;
|
||||
uint8_t channel_mode:4;
|
||||
} __attribute__ ((packed)) a2dp_aptx_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t frequency:4;
|
||||
uint8_t channel_mode:4;
|
||||
uint32_t rfa;
|
||||
} __attribute__ ((packed)) a2dp_aptx_hd_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_aptx_t aptx;
|
||||
uint8_t reserved:6;
|
||||
uint8_t has_new_caps:1;
|
||||
uint8_t bidirect_link:1;
|
||||
} __attribute__ ((packed)) a2dp_aptx_ll_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t direction;
|
||||
uint8_t source_frequency:4;
|
||||
uint8_t sink_frequency:4;
|
||||
} __attribute__ ((packed)) a2dp_faststream_t;
|
||||
|
||||
#else
|
||||
#error "Unknown byte order"
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
a2dp_aptx_ll_t base;
|
||||
uint8_t reserved;
|
||||
uint8_t target_level2;
|
||||
uint8_t target_level1;
|
||||
uint8_t initial_level2;
|
||||
uint8_t initial_level1;
|
||||
uint8_t sra_max_rate;
|
||||
uint8_t sra_avg_time;
|
||||
uint8_t good_working_level2;
|
||||
uint8_t good_working_level1;
|
||||
} __attribute__ ((packed)) a2dp_aptx_ll_ext_t;
|
||||
|
||||
#endif
|
||||
|
|
@ -36,7 +36,6 @@
|
|||
|
||||
#include <sbc/sbc.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "a2dp-codecs.h"
|
||||
|
||||
struct impl {
|
||||
|
|
@ -624,3 +623,9 @@ const struct a2dp_codec a2dp_codec_faststream_duplex = {
|
|||
.name = "faststream_duplex",
|
||||
.duplex_codec = &duplex_codec,
|
||||
};
|
||||
|
||||
A2DP_CODEC_EXPORT_DEF(
|
||||
"faststream",
|
||||
&a2dp_codec_faststream,
|
||||
&a2dp_codec_faststream_duplex
|
||||
);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
#include <spa/utils/string.h>
|
||||
#include <spa/utils/dict.h>
|
||||
#include <spa/pod/parser.h>
|
||||
#include <spa/param/props.h>
|
||||
#include <spa/param/audio/format.h>
|
||||
|
|
@ -38,7 +39,6 @@
|
|||
#include <ldacBT_abr.h>
|
||||
#endif
|
||||
|
||||
#include "defs.h"
|
||||
#include "rtp.h"
|
||||
#include "a2dp-codecs.h"
|
||||
|
||||
|
|
@ -597,3 +597,8 @@ const struct a2dp_codec a2dp_codec_ldac = {
|
|||
.reduce_bitpool = codec_reduce_bitpool,
|
||||
.increase_bitpool = codec_increase_bitpool,
|
||||
};
|
||||
|
||||
A2DP_CODEC_EXPORT_DEF(
|
||||
"ldac",
|
||||
&a2dp_codec_ldac
|
||||
);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#include <sbc/sbc.h>
|
||||
|
||||
#include "defs.h"
|
||||
#include "rtp.h"
|
||||
#include "a2dp-codecs.h"
|
||||
|
||||
|
|
@ -682,3 +681,9 @@ const struct a2dp_codec a2dp_codec_sbc_xq = {
|
|||
.reduce_bitpool = codec_reduce_bitpool,
|
||||
.increase_bitpool = codec_increase_bitpool,
|
||||
};
|
||||
|
||||
A2DP_CODEC_EXPORT_DEF(
|
||||
"sbc",
|
||||
&a2dp_codec_sbc,
|
||||
&a2dp_codec_sbc_xq
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <spa/utils/string.h>
|
||||
|
||||
#include "a2dp-codecs.h"
|
||||
|
||||
int a2dp_codec_select_config(const struct a2dp_codec_config configs[], size_t n,
|
||||
|
|
@ -78,93 +80,129 @@ bool a2dp_codec_check_caps(const struct a2dp_codec *codec, unsigned int codec_id
|
|||
return ((size_t)res == caps_size);
|
||||
}
|
||||
|
||||
#if ENABLE_MP3
|
||||
const a2dp_mpeg_t bluez_a2dp_mpeg = {
|
||||
.layer =
|
||||
MPEG_LAYER_MP1 |
|
||||
MPEG_LAYER_MP2 |
|
||||
MPEG_LAYER_MP3,
|
||||
.crc = 1,
|
||||
.channel_mode =
|
||||
MPEG_CHANNEL_MODE_MONO |
|
||||
MPEG_CHANNEL_MODE_DUAL_CHANNEL |
|
||||
MPEG_CHANNEL_MODE_STEREO |
|
||||
MPEG_CHANNEL_MODE_JOINT_STEREO,
|
||||
.mpf = 1,
|
||||
.frequency =
|
||||
MPEG_SAMPLING_FREQ_16000 |
|
||||
MPEG_SAMPLING_FREQ_22050 |
|
||||
MPEG_SAMPLING_FREQ_24000 |
|
||||
MPEG_SAMPLING_FREQ_32000 |
|
||||
MPEG_SAMPLING_FREQ_44100 |
|
||||
MPEG_SAMPLING_FREQ_48000,
|
||||
.bitrate =
|
||||
MPEG_BIT_RATE_VBR |
|
||||
MPEG_BIT_RATE_320000 |
|
||||
MPEG_BIT_RATE_256000 |
|
||||
MPEG_BIT_RATE_224000 |
|
||||
MPEG_BIT_RATE_192000 |
|
||||
MPEG_BIT_RATE_160000 |
|
||||
MPEG_BIT_RATE_128000 |
|
||||
MPEG_BIT_RATE_112000 |
|
||||
MPEG_BIT_RATE_96000 |
|
||||
MPEG_BIT_RATE_80000 |
|
||||
MPEG_BIT_RATE_64000 |
|
||||
MPEG_BIT_RATE_56000 |
|
||||
MPEG_BIT_RATE_48000 |
|
||||
MPEG_BIT_RATE_40000 |
|
||||
MPEG_BIT_RATE_32000 |
|
||||
MPEG_BIT_RATE_FREE,
|
||||
};
|
||||
#endif
|
||||
#ifdef CODEC_PLUGIN
|
||||
|
||||
extern struct a2dp_codec a2dp_codec_sbc;
|
||||
extern struct a2dp_codec a2dp_codec_sbc_xq;
|
||||
extern struct a2dp_codec a2dp_codec_faststream;
|
||||
extern struct a2dp_codec a2dp_codec_faststream_duplex;
|
||||
#if ENABLE_LDAC
|
||||
extern struct a2dp_codec a2dp_codec_ldac;
|
||||
#endif
|
||||
#if ENABLE_AAC
|
||||
extern struct a2dp_codec a2dp_codec_aac;
|
||||
#endif
|
||||
#if ENABLE_MP3
|
||||
extern struct a2dp_codec a2dp_codec_mpeg;
|
||||
#endif
|
||||
#if ENABLE_APTX
|
||||
extern struct a2dp_codec a2dp_codec_aptx;
|
||||
extern struct a2dp_codec a2dp_codec_aptx_hd;
|
||||
extern struct a2dp_codec a2dp_codec_aptx_ll_0;
|
||||
extern struct a2dp_codec a2dp_codec_aptx_ll_1;
|
||||
extern struct a2dp_codec a2dp_codec_aptx_ll_duplex_0;
|
||||
extern struct a2dp_codec a2dp_codec_aptx_ll_duplex_1;
|
||||
#endif
|
||||
|
||||
static const struct a2dp_codec * const a2dp_codec_list[] = {
|
||||
#if ENABLE_LDAC
|
||||
&a2dp_codec_ldac,
|
||||
#endif
|
||||
#if ENABLE_APTX
|
||||
&a2dp_codec_aptx_hd,
|
||||
&a2dp_codec_aptx,
|
||||
#endif
|
||||
#if ENABLE_AAC
|
||||
&a2dp_codec_aac,
|
||||
#endif
|
||||
#if ENABLE_MP3
|
||||
&a2dp_codec_mpeg,
|
||||
#endif
|
||||
&a2dp_codec_sbc,
|
||||
&a2dp_codec_sbc_xq,
|
||||
&a2dp_codec_faststream,
|
||||
&a2dp_codec_faststream_duplex,
|
||||
#if ENABLE_APTX
|
||||
&a2dp_codec_aptx_ll_0,
|
||||
&a2dp_codec_aptx_ll_1,
|
||||
&a2dp_codec_aptx_ll_duplex_0,
|
||||
&a2dp_codec_aptx_ll_duplex_1,
|
||||
#endif
|
||||
NULL
|
||||
struct impl {
|
||||
struct spa_handle handle;
|
||||
struct spa_bluez5_codec_a2dp bluez5_codec_a2dp;
|
||||
};
|
||||
|
||||
const struct a2dp_codec * const * const a2dp_codecs = a2dp_codec_list;
|
||||
static int
|
||||
impl_get_interface(struct spa_handle *handle, const char *type, void **interface)
|
||||
{
|
||||
struct impl *this;
|
||||
|
||||
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(interface != NULL, -EINVAL);
|
||||
|
||||
this = (struct impl *) handle;
|
||||
|
||||
if (spa_streq(type, SPA_TYPE_INTERFACE_Bluez5CodecA2DP))
|
||||
*interface = &this->bluez5_codec_a2dp;
|
||||
else
|
||||
return -ENOENT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
impl_clear(struct spa_handle *handle)
|
||||
{
|
||||
spa_return_val_if_fail(handle != NULL, -EINVAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t
|
||||
impl_get_size(const struct spa_handle_factory *factory, const struct spa_dict *params)
|
||||
{
|
||||
return sizeof(struct impl);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
this->bluez5_codec_a2dp.codecs = codec_plugin_a2dp_codecs;
|
||||
this->bluez5_codec_a2dp.iface = SPA_INTERFACE_INIT(
|
||||
SPA_TYPE_INTERFACE_Bluez5CodecA2DP,
|
||||
SPA_VERSION_BLUEZ5_CODEC_A2DP,
|
||||
NULL,
|
||||
this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
{SPA_TYPE_INTERFACE_Bluez5CodecA2DP,},
|
||||
};
|
||||
|
||||
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 handle_info_items[] = {
|
||||
{ SPA_KEY_FACTORY_DESCRIPTION, "Bluetooth codec plugin" },
|
||||
};
|
||||
|
||||
static const struct spa_dict handle_info = SPA_DICT_INIT_ARRAY(handle_info_items);
|
||||
|
||||
static struct spa_handle_factory handle_factory = {
|
||||
SPA_VERSION_HANDLE_FACTORY,
|
||||
NULL,
|
||||
&handle_info,
|
||||
impl_get_size,
|
||||
impl_init,
|
||||
impl_enum_interface_info,
|
||||
};
|
||||
|
||||
SPA_EXPORT
|
||||
int spa_handle_factory_enum(const struct spa_handle_factory **factory, uint32_t *index)
|
||||
{
|
||||
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(index != NULL, -EINVAL);
|
||||
|
||||
if (handle_factory.name == NULL)
|
||||
handle_factory.name = codec_plugin_factory_name;
|
||||
|
||||
switch (*index) {
|
||||
case 0:
|
||||
*factory = &handle_factory;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
(*index)++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,362 +1,67 @@
|
|||
/*
|
||||
/* Spa A2DP codec API
|
||||
*
|
||||
* BlueZ - Bluetooth protocol stack for Linux
|
||||
* Copyright © 2020 Wim Taymans
|
||||
*
|
||||
* Copyright (C) 2006-2010 Nokia Corporation
|
||||
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||
* Copyright (C) 2018 Pali Rohár <pali.rohar@gmail.com>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef BLUEALSA_A2DPCODECS_H_
|
||||
#define BLUEALSA_A2DPCODECS_H_
|
||||
#ifndef SPA_BLUEZ5_A2DP_CODECS_H_
|
||||
#define SPA_BLUEZ5_A2DP_CODECS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <spa/param/audio/format.h>
|
||||
#include <spa/param/bluetooth/audio.h>
|
||||
#include <spa/utils/names.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/pod/pod.h>
|
||||
#include <spa/pod/builder.h>
|
||||
|
||||
#define A2DP_CODEC_SBC 0x00
|
||||
#define A2DP_CODEC_MPEG12 0x01
|
||||
#define A2DP_CODEC_MPEG24 0x02
|
||||
#define A2DP_CODEC_ATRAC 0x03
|
||||
#define A2DP_CODEC_VENDOR 0xFF
|
||||
#include "a2dp-codec-caps.h"
|
||||
|
||||
#define A2DP_MAX_CAPS_SIZE 254
|
||||
|
||||
/* customized 16-bit vendor extension */
|
||||
#define A2DP_CODEC_VENDOR_APTX 0x4FFF
|
||||
#define A2DP_CODEC_VENDOR_LDAC 0x2DFF
|
||||
|
||||
#define SBC_SAMPLING_FREQ_48000 (1 << 0)
|
||||
#define SBC_SAMPLING_FREQ_44100 (1 << 1)
|
||||
#define SBC_SAMPLING_FREQ_32000 (1 << 2)
|
||||
#define SBC_SAMPLING_FREQ_16000 (1 << 3)
|
||||
|
||||
#define SBC_CHANNEL_MODE_JOINT_STEREO (1 << 0)
|
||||
#define SBC_CHANNEL_MODE_STEREO (1 << 1)
|
||||
#define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
|
||||
#define SBC_CHANNEL_MODE_MONO (1 << 3)
|
||||
|
||||
#define SBC_BLOCK_LENGTH_16 (1 << 0)
|
||||
#define SBC_BLOCK_LENGTH_12 (1 << 1)
|
||||
#define SBC_BLOCK_LENGTH_8 (1 << 2)
|
||||
#define SBC_BLOCK_LENGTH_4 (1 << 3)
|
||||
|
||||
#define SBC_SUBBANDS_8 (1 << 0)
|
||||
#define SBC_SUBBANDS_4 (1 << 1)
|
||||
|
||||
#define SBC_ALLOCATION_LOUDNESS (1 << 0)
|
||||
#define SBC_ALLOCATION_SNR (1 << 1)
|
||||
|
||||
#define SBC_MIN_BITPOOL 2
|
||||
#define SBC_MAX_BITPOOL 64
|
||||
|
||||
#define MPEG_CHANNEL_MODE_JOINT_STEREO (1 << 0)
|
||||
#define MPEG_CHANNEL_MODE_STEREO (1 << 1)
|
||||
#define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
|
||||
#define MPEG_CHANNEL_MODE_MONO (1 << 3)
|
||||
|
||||
#define MPEG_LAYER_MP3 (1 << 0)
|
||||
#define MPEG_LAYER_MP2 (1 << 1)
|
||||
#define MPEG_LAYER_MP1 (1 << 2)
|
||||
|
||||
#define MPEG_SAMPLING_FREQ_48000 (1 << 0)
|
||||
#define MPEG_SAMPLING_FREQ_44100 (1 << 1)
|
||||
#define MPEG_SAMPLING_FREQ_32000 (1 << 2)
|
||||
#define MPEG_SAMPLING_FREQ_24000 (1 << 3)
|
||||
#define MPEG_SAMPLING_FREQ_22050 (1 << 4)
|
||||
#define MPEG_SAMPLING_FREQ_16000 (1 << 5)
|
||||
|
||||
#define MPEG_BIT_RATE_VBR 0x8000
|
||||
#define MPEG_BIT_RATE_320000 0x4000
|
||||
#define MPEG_BIT_RATE_256000 0x2000
|
||||
#define MPEG_BIT_RATE_224000 0x1000
|
||||
#define MPEG_BIT_RATE_192000 0x0800
|
||||
#define MPEG_BIT_RATE_160000 0x0400
|
||||
#define MPEG_BIT_RATE_128000 0x0200
|
||||
#define MPEG_BIT_RATE_112000 0x0100
|
||||
#define MPEG_BIT_RATE_96000 0x0080
|
||||
#define MPEG_BIT_RATE_80000 0x0040
|
||||
#define MPEG_BIT_RATE_64000 0x0020
|
||||
#define MPEG_BIT_RATE_56000 0x0010
|
||||
#define MPEG_BIT_RATE_48000 0x0008
|
||||
#define MPEG_BIT_RATE_40000 0x0004
|
||||
#define MPEG_BIT_RATE_32000 0x0002
|
||||
#define MPEG_BIT_RATE_FREE 0x0001
|
||||
|
||||
#define AAC_OBJECT_TYPE_MPEG2_AAC_LC 0x80
|
||||
#define AAC_OBJECT_TYPE_MPEG4_AAC_LC 0x40
|
||||
#define AAC_OBJECT_TYPE_MPEG4_AAC_LTP 0x20
|
||||
#define AAC_OBJECT_TYPE_MPEG4_AAC_SCA 0x10
|
||||
|
||||
#define AAC_SAMPLING_FREQ_8000 0x0800
|
||||
#define AAC_SAMPLING_FREQ_11025 0x0400
|
||||
#define AAC_SAMPLING_FREQ_12000 0x0200
|
||||
#define AAC_SAMPLING_FREQ_16000 0x0100
|
||||
#define AAC_SAMPLING_FREQ_22050 0x0080
|
||||
#define AAC_SAMPLING_FREQ_24000 0x0040
|
||||
#define AAC_SAMPLING_FREQ_32000 0x0020
|
||||
#define AAC_SAMPLING_FREQ_44100 0x0010
|
||||
#define AAC_SAMPLING_FREQ_48000 0x0008
|
||||
#define AAC_SAMPLING_FREQ_64000 0x0004
|
||||
#define AAC_SAMPLING_FREQ_88200 0x0002
|
||||
#define AAC_SAMPLING_FREQ_96000 0x0001
|
||||
|
||||
#define AAC_CHANNELS_1 0x02
|
||||
#define AAC_CHANNELS_2 0x01
|
||||
|
||||
#define AAC_GET_BITRATE(a) ((a).bitrate1 << 16 | \
|
||||
(a).bitrate2 << 8 | (a).bitrate3)
|
||||
#define AAC_GET_FREQUENCY(a) ((a).frequency1 << 4 | (a).frequency2)
|
||||
|
||||
#define AAC_SET_BITRATE(a, b) \
|
||||
do { \
|
||||
(a).bitrate1 = ((b) >> 16) & 0x7f; \
|
||||
(a).bitrate2 = ((b) >> 8) & 0xff; \
|
||||
(a).bitrate3 = (b) & 0xff; \
|
||||
} while (0)
|
||||
#define AAC_SET_FREQUENCY(a, f) \
|
||||
do { \
|
||||
(a).frequency1 = ((f) >> 4) & 0xff; \
|
||||
(a).frequency2 = (f) & 0x0f; \
|
||||
} while (0)
|
||||
|
||||
#define AAC_INIT_BITRATE(b) \
|
||||
.bitrate1 = ((b) >> 16) & 0x7f, \
|
||||
.bitrate2 = ((b) >> 8) & 0xff, \
|
||||
.bitrate3 = (b) & 0xff,
|
||||
#define AAC_INIT_FREQUENCY(f) \
|
||||
.frequency1 = ((f) >> 4) & 0xff, \
|
||||
.frequency2 = (f) & 0x0f,
|
||||
|
||||
#define APTX_VENDOR_ID 0x0000004f
|
||||
#define APTX_CODEC_ID 0x0001
|
||||
|
||||
#define APTX_CHANNEL_MODE_MONO 0x01
|
||||
#define APTX_CHANNEL_MODE_STEREO 0x02
|
||||
|
||||
#define APTX_SAMPLING_FREQ_16000 0x08
|
||||
#define APTX_SAMPLING_FREQ_32000 0x04
|
||||
#define APTX_SAMPLING_FREQ_44100 0x02
|
||||
#define APTX_SAMPLING_FREQ_48000 0x01
|
||||
|
||||
#define APTX_HD_VENDOR_ID 0x000000D7
|
||||
#define APTX_HD_CODEC_ID 0x0024
|
||||
|
||||
#define APTX_HD_CHANNEL_MODE_MONO 0x1
|
||||
#define APTX_HD_CHANNEL_MODE_STEREO 0x2
|
||||
|
||||
#define APTX_HD_SAMPLING_FREQ_16000 0x8
|
||||
#define APTX_HD_SAMPLING_FREQ_32000 0x4
|
||||
#define APTX_HD_SAMPLING_FREQ_44100 0x2
|
||||
#define APTX_HD_SAMPLING_FREQ_48000 0x1
|
||||
|
||||
#define APTX_LL_VENDOR_ID 0x0000000a
|
||||
#define APTX_LL_VENDOR_ID2 0x000000d7
|
||||
#define APTX_LL_CODEC_ID 0x0002
|
||||
|
||||
/**
|
||||
* Default parameters for aptX LL (Sprint) encoder
|
||||
/*
|
||||
* The codec plugin SPA interface is private. The version should be incremented
|
||||
* when any of the structs or semantics change.
|
||||
*/
|
||||
#define APTX_LL_TARGET_CODEC_LEVEL 180 /* target codec buffer level */
|
||||
#define APTX_LL_INITIAL_CODEC_LEVEL 360 /* initial codec buffer level */
|
||||
#define APTX_LL_SRA_MAX_RATE 50 /* x/10000 = 0.005 SRA rate */
|
||||
#define APTX_LL_SRA_AVG_TIME 1 /* SRA averaging time = 1s */
|
||||
#define APTX_LL_GOOD_WORKING_LEVEL 180 /* good working buffer level */
|
||||
|
||||
#define LDAC_VENDOR_ID 0x0000012d
|
||||
#define LDAC_CODEC_ID 0x00aa
|
||||
#define SPA_TYPE_INTERFACE_Bluez5CodecA2DP SPA_TYPE_INFO_INTERFACE_BASE "Bluez5:Codec:A2DP:Private"
|
||||
|
||||
#define LDAC_CHANNEL_MODE_MONO 0x04
|
||||
#define LDAC_CHANNEL_MODE_DUAL_CHANNEL 0x02
|
||||
#define LDAC_CHANNEL_MODE_STEREO 0x01
|
||||
#define SPA_VERSION_BLUEZ5_CODEC_A2DP 0
|
||||
|
||||
#define LDAC_SAMPLING_FREQ_44100 0x20
|
||||
#define LDAC_SAMPLING_FREQ_48000 0x10
|
||||
#define LDAC_SAMPLING_FREQ_88200 0x08
|
||||
#define LDAC_SAMPLING_FREQ_96000 0x04
|
||||
#define LDAC_SAMPLING_FREQ_176400 0x02
|
||||
#define LDAC_SAMPLING_FREQ_192000 0x01
|
||||
struct spa_bluez5_codec_a2dp {
|
||||
struct spa_interface iface;
|
||||
const struct a2dp_codec * const *codecs; /**< NULL terminated array */
|
||||
};
|
||||
|
||||
#define FASTSTREAM_VENDOR_ID 0x0000000a
|
||||
#define FASTSTREAM_CODEC_ID 0x0001
|
||||
#define A2DP_CODEC_FACTORY_NAME(basename) (SPA_NAME_API_BLUEZ5_CODEC_A2DP "." basename)
|
||||
|
||||
#define FASTSTREAM_DIRECTION_SINK 0x1
|
||||
#define FASTSTREAM_DIRECTION_SOURCE 0x2
|
||||
#ifdef CODEC_PLUGIN
|
||||
#define A2DP_CODEC_EXPORT_DEF(basename,...) \
|
||||
const char *codec_plugin_factory_name = A2DP_CODEC_FACTORY_NAME(basename); \
|
||||
static const struct a2dp_codec * const codec_plugin_a2dp_codec_list[] = { __VA_ARGS__, NULL }; \
|
||||
const struct a2dp_codec * const * const codec_plugin_a2dp_codecs = codec_plugin_a2dp_codec_list;
|
||||
|
||||
#define FASTSTREAM_SINK_SAMPLING_FREQ_44100 0x2
|
||||
#define FASTSTREAM_SINK_SAMPLING_FREQ_48000 0x1
|
||||
|
||||
#define FASTSTREAM_SOURCE_SAMPLING_FREQ_16000 0x2
|
||||
|
||||
typedef struct {
|
||||
uint32_t vendor_id;
|
||||
uint16_t codec_id;
|
||||
} __attribute__ ((packed)) a2dp_vendor_codec_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t frequency;
|
||||
uint8_t channel_mode;
|
||||
} __attribute__ ((packed)) a2dp_ldac_t;
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
||||
typedef struct {
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t frequency:4;
|
||||
uint8_t allocation_method:2;
|
||||
uint8_t subbands:2;
|
||||
uint8_t block_length:4;
|
||||
uint8_t min_bitpool;
|
||||
uint8_t max_bitpool;
|
||||
} __attribute__ ((packed)) a2dp_sbc_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t crc:1;
|
||||
uint8_t layer:3;
|
||||
uint8_t frequency:6;
|
||||
uint8_t mpf:1;
|
||||
uint8_t rfa:1;
|
||||
uint16_t bitrate;
|
||||
} __attribute__ ((packed)) a2dp_mpeg_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t object_type;
|
||||
uint8_t frequency1;
|
||||
uint8_t rfa:2;
|
||||
uint8_t channels:2;
|
||||
uint8_t frequency2:4;
|
||||
uint8_t bitrate1:7;
|
||||
uint8_t vbr:1;
|
||||
uint8_t bitrate2;
|
||||
uint8_t bitrate3;
|
||||
} __attribute__ ((packed)) a2dp_aac_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t frequency:4;
|
||||
} __attribute__ ((packed)) a2dp_aptx_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t frequency:4;
|
||||
uint32_t rfa;
|
||||
} __attribute__ ((packed)) a2dp_aptx_hd_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_aptx_t aptx;
|
||||
uint8_t bidirect_link:1;
|
||||
uint8_t has_new_caps:1;
|
||||
uint8_t reserved:6;
|
||||
} __attribute__ ((packed)) a2dp_aptx_ll_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t direction;
|
||||
uint8_t sink_frequency:4;
|
||||
uint8_t source_frequency:4;
|
||||
} __attribute__ ((packed)) a2dp_faststream_t;
|
||||
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
|
||||
typedef struct {
|
||||
uint8_t frequency:4;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t block_length:4;
|
||||
uint8_t subbands:2;
|
||||
uint8_t allocation_method:2;
|
||||
uint8_t min_bitpool;
|
||||
uint8_t max_bitpool;
|
||||
} __attribute__ ((packed)) a2dp_sbc_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t layer:3;
|
||||
uint8_t crc:1;
|
||||
uint8_t channel_mode:4;
|
||||
uint8_t rfa:1;
|
||||
uint8_t mpf:1;
|
||||
uint8_t frequency:6;
|
||||
uint16_t bitrate;
|
||||
} __attribute__ ((packed)) a2dp_mpeg_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t object_type;
|
||||
uint8_t frequency1;
|
||||
uint8_t frequency2:4;
|
||||
uint8_t channels:2;
|
||||
uint8_t rfa:2;
|
||||
uint8_t vbr:1;
|
||||
uint8_t bitrate1:7;
|
||||
uint8_t bitrate2;
|
||||
uint8_t bitrate3;
|
||||
} __attribute__ ((packed)) a2dp_aac_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t frequency:4;
|
||||
uint8_t channel_mode:4;
|
||||
} __attribute__ ((packed)) a2dp_aptx_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t frequency:4;
|
||||
uint8_t channel_mode:4;
|
||||
uint32_t rfa;
|
||||
} __attribute__ ((packed)) a2dp_aptx_hd_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_aptx_t aptx;
|
||||
uint8_t reserved:6;
|
||||
uint8_t has_new_caps:1;
|
||||
uint8_t bidirect_link:1;
|
||||
} __attribute__ ((packed)) a2dp_aptx_ll_t;
|
||||
|
||||
typedef struct {
|
||||
a2dp_vendor_codec_t info;
|
||||
uint8_t direction;
|
||||
uint8_t source_frequency:4;
|
||||
uint8_t sink_frequency:4;
|
||||
} __attribute__ ((packed)) a2dp_faststream_t;
|
||||
|
||||
#else
|
||||
#error "Unknown byte order"
|
||||
extern const struct a2dp_codec * const * const codec_plugin_a2dp_codecs;
|
||||
extern const char *codec_plugin_factory_name;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
a2dp_aptx_ll_t base;
|
||||
uint8_t reserved;
|
||||
uint8_t target_level2;
|
||||
uint8_t target_level1;
|
||||
uint8_t initial_level2;
|
||||
uint8_t initial_level1;
|
||||
uint8_t sra_max_rate;
|
||||
uint8_t sra_avg_time;
|
||||
uint8_t good_working_level2;
|
||||
uint8_t good_working_level1;
|
||||
} __attribute__ ((packed)) a2dp_aptx_ll_ext_t;
|
||||
|
||||
|
||||
#define A2DP_CODEC_DEFAULT_RATE 48000
|
||||
#define A2DP_CODEC_DEFAULT_CHANNELS 2
|
||||
|
|
@ -366,8 +71,6 @@ struct a2dp_codec_audio_info {
|
|||
uint32_t channels;
|
||||
};
|
||||
|
||||
struct a2dp_codec_handle;
|
||||
|
||||
struct a2dp_codec {
|
||||
enum spa_bluetooth_audio_codec id;
|
||||
uint8_t codec_id;
|
||||
|
|
@ -437,8 +140,6 @@ struct a2dp_codec {
|
|||
int (*increase_bitpool) (void *data);
|
||||
};
|
||||
|
||||
extern const struct a2dp_codec * const * const a2dp_codecs;
|
||||
|
||||
struct a2dp_codec_config {
|
||||
uint32_t config;
|
||||
int value;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#include <spa/support/loop.h>
|
||||
#include <spa/support/dbus.h>
|
||||
#include <spa/support/plugin.h>
|
||||
#include <spa/support/plugin-loader.h>
|
||||
#include <spa/monitor/device.h>
|
||||
#include <spa/monitor/utils.h>
|
||||
#include <spa/utils/hook.h>
|
||||
|
|
@ -49,7 +50,7 @@
|
|||
#include <spa/utils/string.h>
|
||||
#include <spa/utils/json.h>
|
||||
|
||||
#include "a2dp-codecs.h"
|
||||
#include "codec-loader.h"
|
||||
#include "defs.h"
|
||||
|
||||
#define NAME "bluez5-monitor"
|
||||
|
|
@ -61,6 +62,7 @@ struct spa_bt_monitor {
|
|||
struct spa_log *log;
|
||||
struct spa_loop *main_loop;
|
||||
struct spa_system *main_system;
|
||||
struct spa_plugin_loader *plugin_loader;
|
||||
struct spa_dbus *dbus;
|
||||
struct spa_dbus_connection *dbus_connection;
|
||||
DBusConnection *conn;
|
||||
|
|
@ -69,6 +71,8 @@ struct spa_bt_monitor {
|
|||
|
||||
uint32_t id;
|
||||
|
||||
const struct a2dp_codec * const * a2dp_codecs;
|
||||
|
||||
/*
|
||||
* Lists of BlueZ objects, kept up-to-date by following DBus events
|
||||
* initiated by BlueZ. Object lifetime is also determined by that.
|
||||
|
|
@ -407,9 +411,10 @@ static int a2dp_codec_to_endpoint(const struct a2dp_codec *codec,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const struct a2dp_codec *a2dp_endpoint_to_codec(const char *endpoint)
|
||||
static const struct a2dp_codec *a2dp_endpoint_to_codec(struct spa_bt_monitor *monitor, const char *endpoint)
|
||||
{
|
||||
const char *ep_name;
|
||||
const struct a2dp_codec * const * const a2dp_codecs = monitor->a2dp_codecs;
|
||||
int i;
|
||||
|
||||
if (spa_strstartswith(endpoint, A2DP_SINK_ENDPOINT "/"))
|
||||
|
|
@ -470,7 +475,7 @@ static DBusHandlerResult endpoint_select_configuration(DBusConnection *conn, DBu
|
|||
for (i = 0; i < size; i++)
|
||||
spa_log_debug(monitor->log, " %d: %02x", i, cap[i]);
|
||||
|
||||
codec = a2dp_endpoint_to_codec(path);
|
||||
codec = a2dp_endpoint_to_codec(monitor, path);
|
||||
if (codec != NULL)
|
||||
/* FIXME: We can't determine which device the SelectConfiguration()
|
||||
* call is associated with, therefore device settings are not passed.
|
||||
|
|
@ -1425,6 +1430,8 @@ bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struc
|
|||
|
||||
const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_device *device, size_t *count)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = device->monitor;
|
||||
const struct a2dp_codec * const * const a2dp_codecs = monitor->a2dp_codecs;
|
||||
const struct a2dp_codec **supported_codecs;
|
||||
size_t i, j, size;
|
||||
|
||||
|
|
@ -2697,7 +2704,7 @@ static DBusHandlerResult endpoint_set_configuration(DBusConnection *conn,
|
|||
endpoint = dbus_message_get_path(m);
|
||||
|
||||
profile = a2dp_endpoint_to_profile(endpoint);
|
||||
codec = a2dp_endpoint_to_codec(endpoint);
|
||||
codec = a2dp_endpoint_to_codec(monitor, endpoint);
|
||||
if (codec == NULL) {
|
||||
spa_log_warn(monitor->log, "unknown SetConfiguration() codec");
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
|
|
@ -3016,6 +3023,7 @@ static int register_a2dp_endpoint(struct spa_bt_monitor *monitor,
|
|||
static int adapter_register_endpoints(struct spa_bt_adapter *a)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = a->monitor;
|
||||
const struct a2dp_codec * const * const a2dp_codecs = monitor->a2dp_codecs;
|
||||
int i;
|
||||
int err = 0;
|
||||
|
||||
|
|
@ -3108,6 +3116,7 @@ static void append_a2dp_object(DBusMessageIter *iter, const char *endpoint,
|
|||
static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage *m, void *user_data)
|
||||
{
|
||||
struct spa_bt_monitor *monitor = user_data;
|
||||
const struct a2dp_codec * const * const a2dp_codecs = monitor->a2dp_codecs;
|
||||
const char *path, *interface, *member;
|
||||
char *endpoint;
|
||||
DBusMessage *r;
|
||||
|
|
@ -3221,6 +3230,7 @@ finish:
|
|||
|
||||
static int register_media_application(struct spa_bt_monitor * monitor)
|
||||
{
|
||||
const struct a2dp_codec * const * const a2dp_codecs = monitor->a2dp_codecs;
|
||||
const DBusObjectPathVTable vtable_object_manager = {
|
||||
.message_function = object_manager_handler,
|
||||
};
|
||||
|
|
@ -3247,6 +3257,7 @@ static int register_media_application(struct spa_bt_monitor * monitor)
|
|||
|
||||
static void unregister_media_application(struct spa_bt_monitor * monitor)
|
||||
{
|
||||
const struct a2dp_codec * const * const a2dp_codecs = monitor->a2dp_codecs;
|
||||
int ret;
|
||||
char *object_path = NULL;
|
||||
|
||||
|
|
@ -3886,6 +3897,8 @@ static int impl_clear(struct spa_handle *handle)
|
|||
|
||||
spa_bt_quirks_destroy(monitor->quirks);
|
||||
|
||||
free_a2dp_codecs(monitor->a2dp_codecs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3928,6 +3941,7 @@ int spa_bt_profiles_from_json_array(const char *str)
|
|||
|
||||
static int parse_codec_array(struct spa_bt_monitor *this, const struct spa_dict *info)
|
||||
{
|
||||
const struct a2dp_codec * const * const a2dp_codecs = this->a2dp_codecs;
|
||||
const char *str;
|
||||
struct spa_dict_item *codecs;
|
||||
struct spa_json it, it_array;
|
||||
|
|
@ -4024,29 +4038,47 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->dbus = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_DBus);
|
||||
this->main_loop = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_Loop);
|
||||
this->main_system = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_System);
|
||||
this->plugin_loader = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_PluginLoader);
|
||||
|
||||
if (this->dbus == NULL) {
|
||||
spa_log_error(this->log, "a dbus is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (this->plugin_loader == NULL) {
|
||||
spa_log_error(this->log, "a plugin loader is needed");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
this->a2dp_codecs = NULL;
|
||||
this->quirks = NULL;
|
||||
this->dbus_connection = NULL;
|
||||
|
||||
this->a2dp_codecs = load_a2dp_codecs(this->plugin_loader, this->log);
|
||||
if (this->a2dp_codecs == NULL) {
|
||||
spa_log_error(this->log, NAME ": failed to load required A2DP codec plugins");
|
||||
res = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
this->quirks = spa_bt_quirks_create(info, this->log);
|
||||
if (this->quirks == NULL) {
|
||||
spa_log_error(this->log, NAME ": failed to parse quirk table");
|
||||
return -EINVAL;
|
||||
res = -EINVAL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
this->dbus_connection = spa_dbus_get_connection(this->dbus, SPA_DBUS_TYPE_SYSTEM);
|
||||
if (this->dbus_connection == NULL) {
|
||||
spa_log_error(this->log, "no dbus connection");
|
||||
return -EIO;
|
||||
res = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
this->conn = spa_dbus_connection_get(this->dbus_connection);
|
||||
if (this->conn == NULL) {
|
||||
spa_log_error(this->log, "failed to get dbus connection");
|
||||
spa_dbus_connection_destroy(this->dbus_connection);
|
||||
this->dbus_connection = NULL;
|
||||
return -EIO;
|
||||
res = -EIO;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* XXX: We should handle spa_dbus reconnecting, but we don't, so ref
|
||||
|
|
@ -4067,7 +4099,7 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
spa_list_init(&this->transport_list);
|
||||
|
||||
if ((res = parse_codec_array(this, info)) < 0)
|
||||
return res;
|
||||
goto fail;
|
||||
|
||||
this->default_audio_info.rate = A2DP_CODEC_DEFAULT_RATE;
|
||||
this->default_audio_info.channels = A2DP_CODEC_DEFAULT_CHANNELS;
|
||||
|
|
@ -4101,6 +4133,18 @@ impl_init(const struct spa_handle_factory *factory,
|
|||
this->backend_hsphfpd_registered = true;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (this->a2dp_codecs)
|
||||
free_a2dp_codecs(this->a2dp_codecs);
|
||||
if (this->quirks)
|
||||
spa_bt_quirks_destroy(this->quirks);
|
||||
if (this->dbus_connection)
|
||||
spa_dbus_connection_destroy(this->dbus_connection);
|
||||
this->a2dp_codecs = NULL;
|
||||
this->quirks = NULL;
|
||||
this->dbus_connection = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
static const struct spa_interface_info impl_interfaces[] = {
|
||||
|
|
|
|||
|
|
@ -164,13 +164,14 @@ static void init_node(struct impl *this, struct node *node, uint32_t id)
|
|||
}
|
||||
}
|
||||
|
||||
static void get_a2dp_codecs(enum spa_bluetooth_audio_codec id, const struct a2dp_codec **codecs, size_t size)
|
||||
static void get_a2dp_codecs(struct impl *this, enum spa_bluetooth_audio_codec id, const struct a2dp_codec **codecs, size_t size)
|
||||
{
|
||||
const struct a2dp_codec * const *c;
|
||||
|
||||
spa_assert(size > 0);
|
||||
spa_assert(this->supported_codecs);
|
||||
|
||||
for (c = a2dp_codecs; *c && size > 1; ++c) {
|
||||
for (c = this->supported_codecs; *c && size > 1; ++c) {
|
||||
if ((*c)->id == id || id == 0) {
|
||||
*codecs++ = *c;
|
||||
--size;
|
||||
|
|
@ -775,7 +776,7 @@ static int set_profile(struct impl *this, uint32_t profile, enum spa_bluetooth_a
|
|||
int ret;
|
||||
const struct a2dp_codec *codecs[64];
|
||||
|
||||
get_a2dp_codecs(codec, codecs, SPA_N_ELEMENTS(codecs));
|
||||
get_a2dp_codecs(this, codec, codecs, SPA_N_ELEMENTS(codecs));
|
||||
|
||||
this->switching_codec = true;
|
||||
|
||||
|
|
|
|||
195
spa/plugins/bluez5/codec-loader.c
Normal file
195
spa/plugins/bluez5/codec-loader.c
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
/* Spa A2DP codec API
|
||||
*
|
||||
* Copyright © 2020 Wim Taymans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <spa/utils/string.h>
|
||||
|
||||
#define NAME "bluez5-a2dp-codecs"
|
||||
|
||||
#include "defs.h"
|
||||
#include "codec-loader.h"
|
||||
|
||||
/* AVDTP allows 0x3E endpoints, can't have more codecs than that */
|
||||
#define MAX_CODECS 0x3E
|
||||
#define MAX_HANDLES MAX_CODECS
|
||||
|
||||
struct impl {
|
||||
const struct a2dp_codec *codecs[MAX_CODECS + 1];
|
||||
struct spa_handle *handles[MAX_HANDLES];
|
||||
size_t n_codecs;
|
||||
size_t n_handles;
|
||||
struct spa_plugin_loader *loader;
|
||||
struct spa_log *log;
|
||||
};
|
||||
|
||||
static int codec_order(const struct a2dp_codec *c)
|
||||
{
|
||||
static const enum spa_bluetooth_audio_codec order[] = {
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_LDAC,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_APTX_HD,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_APTX,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_AAC,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_MPEG,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_SBC,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_SBC_XQ,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_FASTSTREAM,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_FASTSTREAM_DUPLEX,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_APTX_LL,
|
||||
SPA_BLUETOOTH_AUDIO_CODEC_APTX_LL_DUPLEX,
|
||||
};
|
||||
size_t i;
|
||||
for (i = 0; i < SPA_N_ELEMENTS(order); ++i)
|
||||
if (c->id == order[i])
|
||||
return i;
|
||||
return SPA_N_ELEMENTS(order);
|
||||
}
|
||||
|
||||
static int codec_order_cmp(const void *a, const void *b)
|
||||
{
|
||||
const struct a2dp_codec * const *ca = a;
|
||||
const struct a2dp_codec * const *cb = b;
|
||||
int ia = codec_order(*ca);
|
||||
int ib = codec_order(*cb);
|
||||
if (*ca == *cb)
|
||||
return 0;
|
||||
return (ia == ib) ? (*ca < *cb ? -1 : 1) : ia - ib;
|
||||
}
|
||||
|
||||
static int load_a2dp_codecs_from(struct impl *impl, const char *factory_name)
|
||||
{
|
||||
struct spa_handle *handle;
|
||||
void *iface;
|
||||
const struct spa_bluez5_codec_a2dp *bluez5_codec_a2dp;
|
||||
int n_codecs = 0;
|
||||
int res;
|
||||
size_t i;
|
||||
|
||||
handle = spa_plugin_loader_load(impl->loader, factory_name, NULL);
|
||||
if (handle == NULL) {
|
||||
spa_log_info(impl->log, NAME ": Bluetooth codec plugin %s not available", factory_name);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
spa_log_debug(impl->log, NAME ": loading codecs from %s", factory_name);
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Bluez5CodecA2DP, &iface)) < 0) {
|
||||
spa_log_info(impl->log, NAME ": Bluetooth codec plugin %s has no codec interface",
|
||||
factory_name);
|
||||
return res;
|
||||
}
|
||||
|
||||
bluez5_codec_a2dp = iface;
|
||||
|
||||
if (bluez5_codec_a2dp->iface.version != SPA_VERSION_BLUEZ5_CODEC_A2DP) {
|
||||
spa_log_info(impl->log, NAME ": codec plugin %s has incompatible ABI version (%d != %d)",
|
||||
factory_name, bluez5_codec_a2dp->iface.version, SPA_VERSION_BLUEZ5_CODEC_A2DP);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
for (i = 0; bluez5_codec_a2dp->codecs[i]; ++i) {
|
||||
const struct a2dp_codec *c = bluez5_codec_a2dp->codecs[i];
|
||||
size_t j;
|
||||
|
||||
if (impl->n_codecs >= MAX_CODECS) {
|
||||
spa_log_error(impl->log, NAME ": too many A2DP codecs");
|
||||
break;
|
||||
}
|
||||
|
||||
/* Don't load duplicate endpoints */
|
||||
for (j = 0; j < impl->n_codecs; ++j) {
|
||||
const struct a2dp_codec *c2 = impl->codecs[j];
|
||||
const char *ep1 = c->endpoint_name ? c->endpoint_name : c->name;
|
||||
const char *ep2 = c2->endpoint_name ? c2->endpoint_name : c2->name;
|
||||
if (spa_streq(ep1, ep2))
|
||||
goto next_codec;
|
||||
}
|
||||
|
||||
spa_log_debug(impl->log, NAME ": loaded A2DP codec %s from %s", c->name, factory_name);
|
||||
|
||||
impl->codecs[impl->n_codecs++] = c;
|
||||
++n_codecs;
|
||||
|
||||
next_codec:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (n_codecs > 0)
|
||||
impl->handles[impl->n_handles++] = handle;
|
||||
else
|
||||
spa_plugin_loader_unload(impl->loader, handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct a2dp_codec * const *load_a2dp_codecs(struct spa_plugin_loader *loader, struct spa_log *log)
|
||||
{
|
||||
struct impl *impl;
|
||||
const char *codec_plugins[] = {
|
||||
A2DP_CODEC_FACTORY_NAME("aac"),
|
||||
A2DP_CODEC_FACTORY_NAME("aptx"),
|
||||
A2DP_CODEC_FACTORY_NAME("faststream"),
|
||||
A2DP_CODEC_FACTORY_NAME("ldac"),
|
||||
A2DP_CODEC_FACTORY_NAME("sbc")
|
||||
};
|
||||
bool has_sbc;
|
||||
size_t i;
|
||||
|
||||
impl = calloc(sizeof(struct impl), 1);
|
||||
if (impl == NULL)
|
||||
return NULL;
|
||||
|
||||
impl->loader = loader;
|
||||
impl->log = log;
|
||||
|
||||
for (i = 0; i < SPA_N_ELEMENTS(codec_plugins); ++i)
|
||||
load_a2dp_codecs_from(impl, codec_plugins[i]);
|
||||
|
||||
has_sbc = false;
|
||||
for (i = 0; i < impl->n_codecs; ++i)
|
||||
if (impl->codecs[i]->id == SPA_BLUETOOTH_AUDIO_CODEC_SBC)
|
||||
has_sbc = true;
|
||||
|
||||
if (!has_sbc) {
|
||||
spa_log_error(impl->log, NAME ": failed to load A2DP SBC codec from plugins");
|
||||
free_a2dp_codecs(impl->codecs);
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
qsort(impl->codecs, impl->n_codecs, sizeof(const struct a2dp_codec *), codec_order_cmp);
|
||||
|
||||
return impl->codecs;
|
||||
}
|
||||
|
||||
void free_a2dp_codecs(const struct a2dp_codec * const *a2dp_codecs)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(a2dp_codecs, struct impl, codecs);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < impl->n_handles; ++i)
|
||||
spa_plugin_loader_unload(impl->loader, impl->handles[i]);
|
||||
|
||||
free(impl);
|
||||
}
|
||||
39
spa/plugins/bluez5/codec-loader.h
Normal file
39
spa/plugins/bluez5/codec-loader.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* Spa A2DP codec API
|
||||
*
|
||||
* Copyright © 2020 Wim Taymans
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SPA_BLUEZ5_CODEC_LOADER_H_
|
||||
#define SPA_BLUEZ5_CODEC_LOADER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <spa/support/plugin-loader.h>
|
||||
|
||||
#include "a2dp-codec-caps.h"
|
||||
#include "a2dp-codecs.h"
|
||||
|
||||
const struct a2dp_codec * const *load_a2dp_codecs(struct spa_plugin_loader *loader, struct spa_log *log);
|
||||
void free_a2dp_codecs(const struct a2dp_codec * const *a2dp_codecs);
|
||||
|
||||
#endif
|
||||
|
|
@ -21,9 +21,8 @@ if not get_option('bluez5-backend-hsphfpd').disabled()
|
|||
endif
|
||||
|
||||
bluez5_sources = ['plugin.c',
|
||||
'codec-loader.c',
|
||||
'a2dp-codecs.c',
|
||||
'a2dp-codec-sbc.c',
|
||||
'a2dp-codec-faststream.c',
|
||||
'a2dp-sink.c',
|
||||
'a2dp-source.c',
|
||||
'sco-sink.c',
|
||||
|
|
@ -33,28 +32,6 @@ bluez5_sources = ['plugin.c',
|
|||
'bluez5-device.c',
|
||||
'bluez5-dbus.c']
|
||||
|
||||
bluez5_args = [ ]
|
||||
|
||||
if ldac_dep.found()
|
||||
bluez5_sources += [ 'a2dp-codec-ldac.c' ]
|
||||
bluez5_args += [ '-DENABLE_LDAC' ]
|
||||
bluez5_deps += ldac_dep
|
||||
if ldac_abr_dep.found()
|
||||
bluez5_args += [ '-DENABLE_LDAC_ABR' ]
|
||||
bluez5_deps += ldac_abr_dep
|
||||
endif
|
||||
endif
|
||||
if aptx_dep.found()
|
||||
bluez5_sources += [ 'a2dp-codec-aptx.c' ]
|
||||
bluez5_args += [ '-DENABLE_APTX' ]
|
||||
bluez5_deps += aptx_dep
|
||||
endif
|
||||
if fdk_aac_dep.found()
|
||||
bluez5_sources += [ 'a2dp-codec-aac.c' ]
|
||||
bluez5_args += [ '-DENABLE_AAC' ]
|
||||
bluez5_deps += fdk_aac_dep
|
||||
endif
|
||||
|
||||
if not get_option('bluez5-backend-hsp-native').disabled() or not get_option('bluez5-backend-hfp-native').disabled()
|
||||
if libusb_dep.found()
|
||||
bluez5_deps += libusb_dep
|
||||
|
|
@ -73,7 +50,60 @@ endif
|
|||
bluez5lib = shared_library('spa-bluez5',
|
||||
bluez5_sources,
|
||||
include_directories : [ spa_inc, configinc ],
|
||||
c_args : bluez5_args,
|
||||
dependencies : bluez5_deps,
|
||||
install : true,
|
||||
install_dir : spa_plugindir / 'bluez5')
|
||||
|
||||
codec_args = [ '-DCODEC_PLUGIN' ]
|
||||
|
||||
bluez_codec_sbc = shared_library('spa-bluez5-codec-sbc',
|
||||
[ 'a2dp-codec-sbc.c', 'a2dp-codecs.c' ],
|
||||
include_directories : [ spa_inc, configinc ],
|
||||
c_args : codec_args,
|
||||
dependencies : sbc_dep,
|
||||
install : true,
|
||||
install_dir : spa_plugindir / 'bluez5')
|
||||
|
||||
bluez_codec_faststream = shared_library('spa-bluez5-codec-faststream',
|
||||
[ 'a2dp-codec-faststream.c', 'a2dp-codecs.c' ],
|
||||
include_directories : [ spa_inc, configinc ],
|
||||
c_args : codec_args,
|
||||
dependencies : sbc_dep,
|
||||
install : true,
|
||||
install_dir : spa_plugindir / 'bluez5')
|
||||
|
||||
if fdk_aac_dep.found()
|
||||
bluez_codec_aac = shared_library('spa-bluez5-codec-aac',
|
||||
[ 'a2dp-codec-aac.c', 'a2dp-codecs.c' ],
|
||||
include_directories : [ spa_inc, configinc ],
|
||||
c_args : codec_args,
|
||||
dependencies : fdk_aac_dep,
|
||||
install : true,
|
||||
install_dir : spa_plugindir / 'bluez5')
|
||||
endif
|
||||
|
||||
if aptx_dep.found()
|
||||
bluez_codec_aac = shared_library('spa-bluez5-codec-aptx',
|
||||
[ 'a2dp-codec-aptx.c', 'a2dp-codecs.c' ],
|
||||
include_directories : [ spa_inc, configinc ],
|
||||
c_args : codec_args,
|
||||
dependencies : [ aptx_dep, sbc_dep ],
|
||||
install : true,
|
||||
install_dir : spa_plugindir / 'bluez5')
|
||||
endif
|
||||
|
||||
if ldac_dep.found()
|
||||
ldac_args = codec_args
|
||||
ldac_dep = [ ldac_dep ]
|
||||
if ldac_abr_dep.found()
|
||||
ldac_args += [ '-DENABLE_LDAC_ABR' ]
|
||||
ldac_dep += ldac_abr_dep
|
||||
endif
|
||||
bluez_codec_ldac = shared_library('spa-bluez5-codec-ldac',
|
||||
[ 'a2dp-codec-ldac.c', 'a2dp-codecs.c' ],
|
||||
include_directories : [ spa_inc, configinc ],
|
||||
c_args : ldac_args,
|
||||
dependencies : ldac_dep,
|
||||
install : true,
|
||||
install_dir : spa_plugindir / 'bluez5')
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ context.properties = {
|
|||
|
||||
context.spa-libs = {
|
||||
# Mapping from factory name to library.
|
||||
api.bluez5.codec.a2dp.aac = bluez5/libspa-bluez5-codec-aac
|
||||
api.bluez5.codec.a2dp.aptx = bluez5/libspa-bluez5-codec-aptx
|
||||
api.bluez5.codec.a2dp.faststream = bluez5/libspa-bluez5-codec-faststream
|
||||
api.bluez5.codec.a2dp.ldac = bluez5/libspa-bluez5-codec-ldac
|
||||
api.bluez5.codec.a2dp.sbc = bluez5/libspa-bluez5-codec-sbc
|
||||
api.bluez5.* = bluez5/libspa-bluez5
|
||||
api.alsa.* = alsa/libspa-alsa
|
||||
api.v4l2.* = v4l2/libspa-v4l2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue