mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
Add bluez5 plugins
This commit is contained in:
parent
4a57f88345
commit
7d5f302f93
12 changed files with 3809 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ avcodec_dep = dependency('libavcodec', required : false)
|
||||||
avformat_dep = dependency('libavformat', required : false)
|
avformat_dep = dependency('libavformat', required : false)
|
||||||
avfilter_dep = dependency('libavfilter', required : false)
|
avfilter_dep = dependency('libavfilter', required : false)
|
||||||
libva_dep = dependency('libva', required : false)
|
libva_dep = dependency('libva', required : false)
|
||||||
|
sbc_dep = dependency('sbc')
|
||||||
libudev_dep = dependency('libudev')
|
libudev_dep = dependency('libudev')
|
||||||
threads_dep = dependency('threads')
|
threads_dep = dependency('threads')
|
||||||
|
|
||||||
|
|
|
||||||
123
spa/plugins/bluez5/a2dp-codecs.c
Normal file
123
spa/plugins/bluez5/a2dp-codecs.c
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* BlueALSA - bluez-a2dp.c
|
||||||
|
* Copyright (c) 2016-2017 Arkadiusz Bokowy
|
||||||
|
*
|
||||||
|
* This file is a part of bluez-alsa.
|
||||||
|
*
|
||||||
|
* This project is licensed under the terms of the MIT license.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "a2dp-codecs.h"
|
||||||
|
|
||||||
|
const a2dp_sbc_t bluez_a2dp_sbc = {
|
||||||
|
.frequency =
|
||||||
|
SBC_SAMPLING_FREQ_16000 |
|
||||||
|
SBC_SAMPLING_FREQ_32000 |
|
||||||
|
SBC_SAMPLING_FREQ_44100 |
|
||||||
|
SBC_SAMPLING_FREQ_48000,
|
||||||
|
.channel_mode =
|
||||||
|
SBC_CHANNEL_MODE_MONO |
|
||||||
|
SBC_CHANNEL_MODE_DUAL_CHANNEL |
|
||||||
|
SBC_CHANNEL_MODE_STEREO |
|
||||||
|
SBC_CHANNEL_MODE_JOINT_STEREO,
|
||||||
|
.block_length =
|
||||||
|
SBC_BLOCK_LENGTH_4 |
|
||||||
|
SBC_BLOCK_LENGTH_8 |
|
||||||
|
SBC_BLOCK_LENGTH_12 |
|
||||||
|
SBC_BLOCK_LENGTH_16,
|
||||||
|
.subbands =
|
||||||
|
SBC_SUBBANDS_4 |
|
||||||
|
SBC_SUBBANDS_8,
|
||||||
|
.allocation_method =
|
||||||
|
SBC_ALLOCATION_SNR |
|
||||||
|
SBC_ALLOCATION_LOUDNESS,
|
||||||
|
.min_bitpool = MIN_BITPOOL,
|
||||||
|
.max_bitpool = MAX_BITPOOL,
|
||||||
|
};
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
#if ENABLE_AAC
|
||||||
|
const a2dp_aac_t bluez_a2dp_aac = {
|
||||||
|
.object_type =
|
||||||
|
/* NOTE: AAC Long Term Prediction and AAC Scalable are
|
||||||
|
* not supported by the FDK-AAC library. */
|
||||||
|
AAC_OBJECT_TYPE_MPEG2_AAC_LC |
|
||||||
|
AAC_OBJECT_TYPE_MPEG4_AAC_LC,
|
||||||
|
AAC_INIT_FREQUENCY(
|
||||||
|
AAC_SAMPLING_FREQ_8000 |
|
||||||
|
AAC_SAMPLING_FREQ_11025 |
|
||||||
|
AAC_SAMPLING_FREQ_12000 |
|
||||||
|
AAC_SAMPLING_FREQ_16000 |
|
||||||
|
AAC_SAMPLING_FREQ_22050 |
|
||||||
|
AAC_SAMPLING_FREQ_24000 |
|
||||||
|
AAC_SAMPLING_FREQ_32000 |
|
||||||
|
AAC_SAMPLING_FREQ_44100 |
|
||||||
|
AAC_SAMPLING_FREQ_48000 |
|
||||||
|
AAC_SAMPLING_FREQ_64000 |
|
||||||
|
AAC_SAMPLING_FREQ_88200 |
|
||||||
|
AAC_SAMPLING_FREQ_96000)
|
||||||
|
.channels =
|
||||||
|
AAC_CHANNELS_1 |
|
||||||
|
AAC_CHANNELS_2,
|
||||||
|
.vbr = 1,
|
||||||
|
AAC_INIT_BITRATE(0xFFFF)
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_APTX
|
||||||
|
const a2dp_aptx_t bluez_a2dp_aptx = {
|
||||||
|
.info.vendor_id = APTX_VENDOR_ID,
|
||||||
|
.info.codec_id = APTX_CODEC_ID,
|
||||||
|
.channel_mode =
|
||||||
|
/* NOTE: Used apt-X library does not support
|
||||||
|
* single channel (mono) mode. */
|
||||||
|
APTX_CHANNEL_MODE_DUAL_CHANNEL |
|
||||||
|
APTX_CHANNEL_MODE_STEREO |
|
||||||
|
APTX_CHANNEL_MODE_JOINT_STEREO,
|
||||||
|
.frequency =
|
||||||
|
APTX_SAMPLING_FREQ_16000 |
|
||||||
|
APTX_SAMPLING_FREQ_32000 |
|
||||||
|
APTX_SAMPLING_FREQ_44100 |
|
||||||
|
APTX_SAMPLING_FREQ_48000,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
298
spa/plugins/bluez5/a2dp-codecs.h
Normal file
298
spa/plugins/bluez5/a2dp-codecs.h
Normal file
|
|
@ -0,0 +1,298 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* BlueZ - Bluetooth protocol stack for Linux
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2010 Nokia Corporation
|
||||||
|
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 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 BLUEALSA_A2DPCODECS_H_
|
||||||
|
#define BLUEALSA_A2DPCODECS_H_
|
||||||
|
|
||||||
|
#include <stdint.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
|
||||||
|
|
||||||
|
/* 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 MIN_BITPOOL 2
|
||||||
|
#define 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 0x08
|
||||||
|
#define APTX_CHANNEL_MODE_DUAL_CHANNEL 0x04
|
||||||
|
#define APTX_CHANNEL_MODE_STEREO 0x02
|
||||||
|
#define APTX_CHANNEL_MODE_JOINT_STEREO 0x01
|
||||||
|
|
||||||
|
#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 LDAC_VENDOR_ID 0x0000012d
|
||||||
|
#define LDAC_CODEC_ID 0x00aa
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t vendor_id;
|
||||||
|
uint16_t codec_id;
|
||||||
|
} __attribute__ ((packed)) a2dp_vendor_codec_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;
|
||||||
|
|
||||||
|
static inline int a2dp_sbc_get_channels(a2dp_sbc_t *config)
|
||||||
|
{
|
||||||
|
switch (config->channel_mode) {
|
||||||
|
case SBC_CHANNEL_MODE_MONO:
|
||||||
|
return 1;
|
||||||
|
case SBC_CHANNEL_MODE_DUAL_CHANNEL:
|
||||||
|
case SBC_CHANNEL_MODE_STEREO:
|
||||||
|
case SBC_CHANNEL_MODE_JOINT_STEREO:
|
||||||
|
return 2;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int a2dp_sbc_get_frequency(a2dp_sbc_t *config)
|
||||||
|
{
|
||||||
|
switch (config->frequency) {
|
||||||
|
case SBC_SAMPLING_FREQ_16000:
|
||||||
|
return 16000;
|
||||||
|
case SBC_SAMPLING_FREQ_32000:
|
||||||
|
return 32000;
|
||||||
|
case SBC_SAMPLING_FREQ_44100:
|
||||||
|
return 44100;
|
||||||
|
case SBC_SAMPLING_FREQ_48000:
|
||||||
|
return 48000;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 unknown[2];
|
||||||
|
} __attribute__ ((packed)) a2dp_ldac_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 unknown[2];
|
||||||
|
} __attribute__ ((packed)) a2dp_ldac_t;
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Unknown byte order"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const a2dp_sbc_t bluez_a2dp_sbc;
|
||||||
|
#if ENABLE_MP3
|
||||||
|
const a2dp_mpeg_t bluez_a2dp_mpeg;
|
||||||
|
#endif
|
||||||
|
#if ENABLE_AAC
|
||||||
|
const a2dp_aac_t bluez_a2dp_aac;
|
||||||
|
#endif
|
||||||
|
#if ENABLE_APTX
|
||||||
|
const a2dp_aptx_t bluez_a2dp_aptx;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
1474
spa/plugins/bluez5/a2dp-sink.c
Normal file
1474
spa/plugins/bluez5/a2dp-sink.c
Normal file
File diff suppressed because it is too large
Load diff
1272
spa/plugins/bluez5/bluez5-monitor.c
Normal file
1272
spa/plugins/bluez5/bluez5-monitor.c
Normal file
File diff suppressed because it is too large
Load diff
174
spa/plugins/bluez5/defs.h
Normal file
174
spa/plugins/bluez5/defs.h
Normal file
|
|
@ -0,0 +1,174 @@
|
||||||
|
/* Spa Bluez5 Monitor
|
||||||
|
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library 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_DEFS_H__
|
||||||
|
#define __SPA_BLUEZ5_DEFS_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BLUEZ_SERVICE "org.bluez"
|
||||||
|
#define BLUEZ_ADAPTER_INTERFACE BLUEZ_SERVICE ".Adapter1"
|
||||||
|
#define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device1"
|
||||||
|
#define BLUEZ_MEDIA_INTERFACE BLUEZ_SERVICE ".Media1"
|
||||||
|
#define BLUEZ_MEDIA_ENDPOINT_INTERFACE BLUEZ_SERVICE ".MediaEndpoint1"
|
||||||
|
#define BLUEZ_MEDIA_TRANSPORT_INTERFACE BLUEZ_SERVICE ".MediaTransport1"
|
||||||
|
|
||||||
|
#define ENDPOINT_INTROSPECT_XML \
|
||||||
|
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
|
||||||
|
"<node>" \
|
||||||
|
" <interface name=\"" BLUEZ_MEDIA_ENDPOINT_INTERFACE "\">" \
|
||||||
|
" <method name=\"SetConfiguration\">" \
|
||||||
|
" <arg name=\"transport\" direction=\"in\" type=\"o\"/>" \
|
||||||
|
" <arg name=\"properties\" direction=\"in\" type=\"ay\"/>" \
|
||||||
|
" </method>" \
|
||||||
|
" <method name=\"SelectConfiguration\">" \
|
||||||
|
" <arg name=\"capabilities\" direction=\"in\" type=\"ay\"/>" \
|
||||||
|
" <arg name=\"configuration\" direction=\"out\" type=\"ay\"/>" \
|
||||||
|
" </method>" \
|
||||||
|
" <method name=\"ClearConfiguration\">" \
|
||||||
|
" <arg name=\"transport\" direction=\"in\" type=\"o\"/>" \
|
||||||
|
" </method>" \
|
||||||
|
" <method name=\"Release\">" \
|
||||||
|
" </method>" \
|
||||||
|
" </interface>" \
|
||||||
|
" <interface name=\"org.freedesktop.DBus.Introspectable\">" \
|
||||||
|
" <method name=\"Introspect\">" \
|
||||||
|
" <arg name=\"data\" type=\"s\" direction=\"out\"/>" \
|
||||||
|
" </method>" \
|
||||||
|
" </interface>" \
|
||||||
|
"</node>"
|
||||||
|
|
||||||
|
|
||||||
|
#define BLUEZ_ERROR_NOT_SUPPORTED "org.bluez.Error.NotSupported"
|
||||||
|
|
||||||
|
#define SPA_BT_UUID_A2DP_SOURCE "0000110A-0000-1000-8000-00805F9B34FB"
|
||||||
|
#define SPA_BT_UUID_A2DP_SINK "0000110B-0000-1000-8000-00805F9B34FB"
|
||||||
|
#define SPA_BT_UUID_HSP_HS "00001108-0000-1000-8000-00805F9B34FB"
|
||||||
|
#define SPA_BT_UUID_HSP_AG "00001112-0000-1000-8000-00805F9B34FB"
|
||||||
|
#define SPA_BT_UUID_HFP_HF "0000111E-0000-1000-8000-00805F9B34FB"
|
||||||
|
#define SPA_BT_UUID_HFP_AG "0000111F-0000-1000-8000-00805F9B34FB"
|
||||||
|
|
||||||
|
enum spa_bt_profile {
|
||||||
|
SPA_BT_PROFILE_NULL = 0,
|
||||||
|
SPA_BT_PROFILE_A2DP_SOURCE = (1 << 0),
|
||||||
|
SPA_BT_PROFILE_A2DP_SINK = (1 << 1),
|
||||||
|
SPA_BT_PROFILE_HSP_HS = (1 << 2),
|
||||||
|
SPA_BT_PROFILE_HSP_AG = (1 << 3),
|
||||||
|
SPA_BT_PROFILE_HFP_HF = (1 << 4),
|
||||||
|
SPA_BT_PROFILE_HFP_AG = (1 << 5),
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline enum spa_bt_profile spa_bt_profile_from_uuid(const char *uuid)
|
||||||
|
{
|
||||||
|
if (strcasecmp(uuid, SPA_BT_UUID_A2DP_SOURCE) == 0)
|
||||||
|
return SPA_BT_PROFILE_A2DP_SOURCE;
|
||||||
|
else if (strcasecmp(uuid, SPA_BT_UUID_A2DP_SINK) == 0)
|
||||||
|
return SPA_BT_PROFILE_A2DP_SINK;
|
||||||
|
else if (strcasecmp(uuid, SPA_BT_UUID_HSP_HS) == 0)
|
||||||
|
return SPA_BT_PROFILE_HSP_HS;
|
||||||
|
else if (strcasecmp(uuid, SPA_BT_UUID_HSP_AG) == 0)
|
||||||
|
return SPA_BT_PROFILE_HSP_AG;
|
||||||
|
else if (strcasecmp(uuid, SPA_BT_UUID_HFP_HF) == 0)
|
||||||
|
return SPA_BT_PROFILE_HFP_HF;
|
||||||
|
else if (strcasecmp(uuid, SPA_BT_UUID_HFP_AG) == 0)
|
||||||
|
return SPA_BT_PROFILE_HFP_AG;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct spa_bt_monitor;
|
||||||
|
|
||||||
|
struct spa_bt_adapter {
|
||||||
|
struct spa_list link;
|
||||||
|
struct spa_bt_monitor *monitor;
|
||||||
|
char *path;
|
||||||
|
char *alias;
|
||||||
|
char *address;
|
||||||
|
char *name;
|
||||||
|
uint32_t bluetooth_class;
|
||||||
|
uint32_t profiles;
|
||||||
|
int powered;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct spa_bt_device {
|
||||||
|
struct spa_list link;
|
||||||
|
struct spa_bt_monitor *monitor;
|
||||||
|
char *path;
|
||||||
|
char *alias;
|
||||||
|
char *address;
|
||||||
|
char *adapter_path;
|
||||||
|
char *name;
|
||||||
|
char *icon;
|
||||||
|
uint32_t bluetooth_class;
|
||||||
|
uint16_t appearance;
|
||||||
|
uint16_t RSSI;
|
||||||
|
int paired;
|
||||||
|
int trusted;
|
||||||
|
int connected;
|
||||||
|
int blocked;
|
||||||
|
uint32_t profiles;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum spa_bt_transport_state {
|
||||||
|
SPA_BT_TRANSPORT_STATE_IDLE,
|
||||||
|
SPA_BT_TRANSPORT_STATE_PENDING,
|
||||||
|
SPA_BT_TRANSPORT_STATE_ACTIVE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct spa_bt_transport {
|
||||||
|
struct spa_list link;
|
||||||
|
struct spa_bt_monitor *monitor;
|
||||||
|
char *path;
|
||||||
|
struct spa_bt_device *device;
|
||||||
|
enum spa_bt_profile profile;
|
||||||
|
enum spa_bt_transport_state state;
|
||||||
|
int codec;
|
||||||
|
void *configuration;
|
||||||
|
int configuration_len;
|
||||||
|
|
||||||
|
bool acquired;
|
||||||
|
int fd;
|
||||||
|
uint16_t read_mtu;
|
||||||
|
uint16_t write_mtu;
|
||||||
|
|
||||||
|
int (*acquire) (struct spa_bt_transport *trans, bool optional);
|
||||||
|
|
||||||
|
int (*release) (struct spa_bt_transport *trans);
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline enum spa_bt_transport_state spa_bt_transport_state_from_string(const char *value)
|
||||||
|
{
|
||||||
|
if (strcasecmp("idle", value) == 0)
|
||||||
|
return SPA_BT_TRANSPORT_STATE_IDLE;
|
||||||
|
else if (strcasecmp("pending", value) == 0)
|
||||||
|
return SPA_BT_TRANSPORT_STATE_PENDING;
|
||||||
|
else if (strcasecmp("active", value) == 0)
|
||||||
|
return SPA_BT_TRANSPORT_STATE_ACTIVE;
|
||||||
|
else
|
||||||
|
return SPA_BT_TRANSPORT_STATE_IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __SPA_BLUEZ5_DEFS_H__ */
|
||||||
12
spa/plugins/bluez5/meson.build
Normal file
12
spa/plugins/bluez5/meson.build
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
bluez5_sources = ['plugin.c',
|
||||||
|
'a2dp-sink.c',
|
||||||
|
'bluez5-monitor.c']
|
||||||
|
|
||||||
|
bluez5lib = shared_library('spa-bluez5',
|
||||||
|
bluez5_sources,
|
||||||
|
include_directories : [ spa_inc, spa_libinc ],
|
||||||
|
dependencies : [ dbus_dep, sbc_dep ],
|
||||||
|
link_with : spalib,
|
||||||
|
install : true,
|
||||||
|
install_dir : '@0@/spa/bluez5'.format(get_option('libdir')))
|
||||||
53
spa/plugins/bluez5/plugin.c
Normal file
53
spa/plugins/bluez5/plugin.c
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* Spa Volume plugin
|
||||||
|
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <spa/support/plugin.h>
|
||||||
|
|
||||||
|
#define MAX_FACTORIES 16
|
||||||
|
|
||||||
|
static const struct spa_handle_factory *factories[MAX_FACTORIES];
|
||||||
|
static int n_factories;
|
||||||
|
|
||||||
|
int spa_handle_factory_register(const struct spa_handle_factory *factory)
|
||||||
|
{
|
||||||
|
if (n_factories >= MAX_FACTORIES) {
|
||||||
|
fprintf(stderr, "too many factories\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
factories[n_factories++] = factory;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (*index >= n_factories)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*factory = factories[(*index)++];
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
74
spa/plugins/bluez5/rtp.h
Normal file
74
spa/plugins/bluez5/rtp.h
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* BlueZ - Bluetooth protocol stack for Linux
|
||||||
|
*
|
||||||
|
* Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 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, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
|
||||||
|
struct rtp_header {
|
||||||
|
unsigned cc:4;
|
||||||
|
unsigned x:1;
|
||||||
|
unsigned p:1;
|
||||||
|
unsigned v:2;
|
||||||
|
|
||||||
|
unsigned pt:7;
|
||||||
|
unsigned m:1;
|
||||||
|
|
||||||
|
uint16_t sequence_number;
|
||||||
|
uint32_t timestamp;
|
||||||
|
uint32_t ssrc;
|
||||||
|
uint32_t csrc[0];
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
struct rtp_payload {
|
||||||
|
unsigned frame_count:4;
|
||||||
|
unsigned rfa0:1;
|
||||||
|
unsigned is_last_fragment:1;
|
||||||
|
unsigned is_first_fragment:1;
|
||||||
|
unsigned is_fragmented:1;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
|
||||||
|
struct rtp_header {
|
||||||
|
unsigned v:2;
|
||||||
|
unsigned p:1;
|
||||||
|
unsigned x:1;
|
||||||
|
unsigned cc:4;
|
||||||
|
|
||||||
|
unsigned m:1;
|
||||||
|
unsigned pt:7;
|
||||||
|
|
||||||
|
uint16_t sequence_number;
|
||||||
|
uint32_t timestamp;
|
||||||
|
uint32_t ssrc;
|
||||||
|
uint32_t csrc[0];
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
struct rtp_payload {
|
||||||
|
unsigned is_fragmented:1;
|
||||||
|
unsigned is_first_fragment:1;
|
||||||
|
unsigned is_last_fragment:1;
|
||||||
|
unsigned rfa0:1;
|
||||||
|
unsigned frame_count:4;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Unknown byte order"
|
||||||
|
#endif
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
subdir('alsa')
|
subdir('alsa')
|
||||||
subdir('audiomixer')
|
subdir('audiomixer')
|
||||||
subdir('audiotestsrc')
|
subdir('audiotestsrc')
|
||||||
|
subdir('bluez5')
|
||||||
if avcodec_dep.found()
|
if avcodec_dep.found()
|
||||||
subdir('ffmpeg')
|
subdir('ffmpeg')
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@ executable('test-mixer', 'test-mixer.c',
|
||||||
dependencies : [dl_lib, pthread_lib, libm],
|
dependencies : [dl_lib, pthread_lib, libm],
|
||||||
link_with : spalib,
|
link_with : spalib,
|
||||||
install : false)
|
install : false)
|
||||||
|
executable('test-bluez5', 'test-bluez5.c',
|
||||||
|
include_directories : [spa_inc, spa_libinc ],
|
||||||
|
dependencies : [dl_lib, pthread_lib, libm, dbus_dep],
|
||||||
|
link_with : spalib,
|
||||||
|
install : false)
|
||||||
executable('test-ringbuffer', 'test-ringbuffer.c',
|
executable('test-ringbuffer', 'test-ringbuffer.c',
|
||||||
include_directories : [spa_inc, spa_libinc ],
|
include_directories : [spa_inc, spa_libinc ],
|
||||||
dependencies : [dl_lib, pthread_lib],
|
dependencies : [dl_lib, pthread_lib],
|
||||||
|
|
|
||||||
322
spa/tests/test-bluez5.c
Normal file
322
spa/tests/test-bluez5.c
Normal file
|
|
@ -0,0 +1,322 @@
|
||||||
|
/* Spa
|
||||||
|
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 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
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <error.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
|
#include <spa/support/loop.h>
|
||||||
|
#include <spa/support/log.h>
|
||||||
|
#include <spa/support/type-map.h>
|
||||||
|
#include <spa/support/dbus.h>
|
||||||
|
#include <spa/monitor/monitor.h>
|
||||||
|
#include <spa/node/node.h>
|
||||||
|
#include <spa/node/io.h>
|
||||||
|
#include <spa/param/param.h>
|
||||||
|
#include <spa/param/props.h>
|
||||||
|
#include <spa/param/audio/format-utils.h>
|
||||||
|
#include <spa/param/format-utils.h>
|
||||||
|
#include <spa/param/io.h>
|
||||||
|
|
||||||
|
#define M_PI_M2 ( M_PI + M_PI )
|
||||||
|
|
||||||
|
static struct spa_log *logger;
|
||||||
|
|
||||||
|
#define spa_debug(f,...) spa_log_trace(logger, f, __VA_ARGS__)
|
||||||
|
|
||||||
|
#include <spa/graph/graph.h>
|
||||||
|
#include <spa/graph/graph-scheduler6.h>
|
||||||
|
|
||||||
|
#include <lib/debug.h>
|
||||||
|
|
||||||
|
struct type {
|
||||||
|
uint32_t log;
|
||||||
|
uint32_t node;
|
||||||
|
uint32_t props;
|
||||||
|
uint32_t format;
|
||||||
|
struct spa_type_monitor monitor;
|
||||||
|
struct spa_type_io io;
|
||||||
|
struct spa_type_param param;
|
||||||
|
struct spa_type_meta meta;
|
||||||
|
struct spa_type_data data;
|
||||||
|
struct spa_type_media_type media_type;
|
||||||
|
struct spa_type_media_subtype media_subtype;
|
||||||
|
struct spa_type_format_audio format_audio;
|
||||||
|
struct spa_type_audio_format audio_format;
|
||||||
|
struct spa_type_event_node event_node;
|
||||||
|
struct spa_type_command_node command_node;
|
||||||
|
struct spa_type_param_io param_io;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void init_type(struct type *type, struct spa_type_map *map)
|
||||||
|
{
|
||||||
|
type->log = spa_type_map_get_id(map, SPA_TYPE__Log);
|
||||||
|
type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
|
||||||
|
type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
|
||||||
|
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
|
||||||
|
spa_type_monitor_map(map, &type->monitor);
|
||||||
|
spa_type_io_map(map, &type->io);
|
||||||
|
spa_type_param_map(map, &type->param);
|
||||||
|
spa_type_meta_map(map, &type->meta);
|
||||||
|
spa_type_data_map(map, &type->data);
|
||||||
|
spa_type_media_type_map(map, &type->media_type);
|
||||||
|
spa_type_media_subtype_map(map, &type->media_subtype);
|
||||||
|
spa_type_format_audio_map(map, &type->format_audio);
|
||||||
|
spa_type_audio_format_map(map, &type->audio_format);
|
||||||
|
spa_type_event_node_map(map, &type->event_node);
|
||||||
|
spa_type_command_node_map(map, &type->command_node);
|
||||||
|
spa_type_param_io_map(map, &type->param_io);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct buffer {
|
||||||
|
struct spa_buffer buffer;
|
||||||
|
struct spa_meta metas[1];
|
||||||
|
struct spa_meta_header header;
|
||||||
|
struct spa_data datas[1];
|
||||||
|
struct spa_chunk chunks[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct data {
|
||||||
|
struct type type;
|
||||||
|
struct spa_type_map *map;
|
||||||
|
struct spa_log *log;
|
||||||
|
|
||||||
|
struct spa_loop *loop;
|
||||||
|
struct spa_loop_control *loop_control;
|
||||||
|
struct spa_loop_utils *loop_utils;
|
||||||
|
bool running;
|
||||||
|
|
||||||
|
struct spa_dbus *dbus;
|
||||||
|
|
||||||
|
struct spa_support support[7];
|
||||||
|
uint32_t n_support;
|
||||||
|
|
||||||
|
struct spa_monitor *monitor;
|
||||||
|
|
||||||
|
struct spa_graph graph;
|
||||||
|
struct spa_graph_data graph_data;
|
||||||
|
struct spa_graph_node source_node;
|
||||||
|
struct spa_graph_port source_out;
|
||||||
|
struct spa_graph_port sink_in;
|
||||||
|
struct spa_graph_node sink_node;
|
||||||
|
|
||||||
|
struct spa_node *sink;
|
||||||
|
struct spa_node *source;
|
||||||
|
|
||||||
|
struct spa_io_buffers source_sink_io[1];
|
||||||
|
struct spa_buffer *source_buffers[1];
|
||||||
|
struct buffer source_buffer[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
static void inspect_item(struct data *data, struct spa_pod *item)
|
||||||
|
{
|
||||||
|
spa_debug_pod(item, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void monitor_event(void *_data, struct spa_event *event)
|
||||||
|
{
|
||||||
|
struct data *data = _data;
|
||||||
|
|
||||||
|
if (SPA_EVENT_TYPE(event) == data->type.monitor.Added) {
|
||||||
|
fprintf(stderr, "added:\n");
|
||||||
|
inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event));
|
||||||
|
} else if (SPA_EVENT_TYPE(event) == data->type.monitor.Removed) {
|
||||||
|
fprintf(stderr, "removed:\n");
|
||||||
|
inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event));
|
||||||
|
} else if (SPA_EVENT_TYPE(event) == data->type.monitor.Changed) {
|
||||||
|
fprintf(stderr, "changed:\n");
|
||||||
|
inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct spa_monitor_callbacks monitor_callbacks = {
|
||||||
|
SPA_VERSION_MONITOR_CALLBACKS,
|
||||||
|
monitor_event,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int get_handle(struct data *data,
|
||||||
|
struct spa_handle **handle,
|
||||||
|
const char *lib,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
void *hnd;
|
||||||
|
spa_handle_factory_enum_func_t enum_func;
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
|
||||||
|
printf("can't load %s: %s\n", lib, dlerror());
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
|
||||||
|
printf("can't find enum function\n");
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0;;) {
|
||||||
|
const struct spa_handle_factory *factory;
|
||||||
|
|
||||||
|
if ((res = enum_func(&factory, &i)) <= 0) {
|
||||||
|
if (res != 0)
|
||||||
|
printf("can't enumerate factories: %s\n", spa_strerror(res));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (strcmp(factory->name, name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
*handle = calloc(1, factory->size);
|
||||||
|
if ((res = spa_handle_factory_init(factory, *handle, NULL,
|
||||||
|
data->support,
|
||||||
|
data->n_support)) < 0) {
|
||||||
|
printf("can't make factory instance: %d\n", res);
|
||||||
|
free(*handle);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
struct data data;
|
||||||
|
int res;
|
||||||
|
const char *str;
|
||||||
|
struct spa_handle *handle;
|
||||||
|
void *iface;
|
||||||
|
|
||||||
|
spa_zero(data);
|
||||||
|
if ((res = get_handle(&data, &handle,
|
||||||
|
"build/spa/plugins/support/libspa-support.so",
|
||||||
|
"mapper")) < 0) {
|
||||||
|
error(-1, res, "can't create mapper");
|
||||||
|
}
|
||||||
|
if ((res = spa_handle_get_interface(handle, 0, &iface)) < 0)
|
||||||
|
error(-1, res, "can't get mapper interface");
|
||||||
|
|
||||||
|
data.map = iface;
|
||||||
|
data.support[0].type = SPA_TYPE__TypeMap;
|
||||||
|
data.support[0].data = data.map;
|
||||||
|
data.n_support = 1;
|
||||||
|
init_type(&data.type, data.map);
|
||||||
|
spa_debug_set_type_map(data.map);
|
||||||
|
|
||||||
|
if ((res = get_handle(&data, &handle,
|
||||||
|
"build/spa/plugins/support/libspa-support.so",
|
||||||
|
"logger")) < 0) {
|
||||||
|
error(-1, res, "can't create logger");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = spa_handle_get_interface(handle,
|
||||||
|
spa_type_map_get_id(data.map, SPA_TYPE__Log),
|
||||||
|
&iface)) < 0)
|
||||||
|
error(-1, res, "can't get log interface");
|
||||||
|
|
||||||
|
data.log = iface;
|
||||||
|
data.support[1].type = SPA_TYPE__Log;
|
||||||
|
data.support[1].data = data.log;
|
||||||
|
data.n_support = 2;
|
||||||
|
|
||||||
|
if ((str = getenv("SPA_DEBUG")))
|
||||||
|
data.log->level = atoi(str);
|
||||||
|
|
||||||
|
if ((res = get_handle(&data, &handle,
|
||||||
|
"build/spa/plugins/support/libspa-support.so",
|
||||||
|
"loop")) < 0) {
|
||||||
|
error(-1, res, "can't create loop");
|
||||||
|
}
|
||||||
|
if ((res = spa_handle_get_interface(handle,
|
||||||
|
spa_type_map_get_id(data.map, SPA_TYPE__Loop),
|
||||||
|
&iface)) < 0)
|
||||||
|
error(-1, res, "can't get loop interface");
|
||||||
|
data.loop = iface;
|
||||||
|
|
||||||
|
if ((res = spa_handle_get_interface(handle,
|
||||||
|
spa_type_map_get_id(data.map, SPA_TYPE__LoopControl),
|
||||||
|
&iface)) < 0)
|
||||||
|
error(-1, res, "can't get loopcontrol interface");
|
||||||
|
data.loop_control = iface;
|
||||||
|
|
||||||
|
if ((res = spa_handle_get_interface(handle,
|
||||||
|
spa_type_map_get_id(data.map, SPA_TYPE__LoopUtils),
|
||||||
|
&iface)) < 0)
|
||||||
|
error(-1, res, "can't get looputils interface");
|
||||||
|
data.loop_utils = iface;
|
||||||
|
|
||||||
|
data.support[2].type = SPA_TYPE_LOOP__DataLoop;
|
||||||
|
data.support[2].data = data.loop;
|
||||||
|
data.support[3].type = SPA_TYPE_LOOP__MainLoop;
|
||||||
|
data.support[3].data = data.loop;
|
||||||
|
data.support[4].type = SPA_TYPE__LoopControl;
|
||||||
|
data.support[4].data = data.loop_control;
|
||||||
|
data.support[5].type = SPA_TYPE__LoopUtils;
|
||||||
|
data.support[5].data = data.loop_utils;
|
||||||
|
data.n_support = 6;
|
||||||
|
|
||||||
|
if ((res = get_handle(&data, &handle,
|
||||||
|
"build/spa/plugins/support/libspa-dbus.so",
|
||||||
|
"dbus")) < 0) {
|
||||||
|
error(-1, res, "can't create dbus");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = spa_handle_get_interface(handle,
|
||||||
|
spa_type_map_get_id(data.map, SPA_TYPE__DBus),
|
||||||
|
&iface)) < 0)
|
||||||
|
error(-1, res, "can't get dbus interface");
|
||||||
|
|
||||||
|
data.dbus = iface;
|
||||||
|
data.support[6].type = SPA_TYPE__DBus;
|
||||||
|
data.support[6].data = data.dbus;
|
||||||
|
data.n_support = 7;
|
||||||
|
|
||||||
|
if ((res = get_handle(&data, &handle,
|
||||||
|
"build/spa/plugins/bluez5/libspa-bluez5.so",
|
||||||
|
"bluez5-monitor")) < 0) {
|
||||||
|
error(-1, res, "can't create bluez5-monitor");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((res = spa_handle_get_interface(handle,
|
||||||
|
spa_type_map_get_id(data.map, SPA_TYPE__Monitor),
|
||||||
|
&iface)) < 0)
|
||||||
|
error(-1, res, "can't get monitor interface");
|
||||||
|
|
||||||
|
data.monitor = iface;
|
||||||
|
|
||||||
|
spa_graph_init(&data.graph);
|
||||||
|
spa_graph_data_init(&data.graph_data, &data.graph);
|
||||||
|
spa_graph_set_callbacks(&data.graph, &spa_graph_impl_default, &data.graph_data);
|
||||||
|
|
||||||
|
spa_monitor_set_callbacks(data.monitor, &monitor_callbacks, &data);
|
||||||
|
|
||||||
|
data.running = true;
|
||||||
|
spa_loop_control_enter(data.loop_control);
|
||||||
|
while (data.running) {
|
||||||
|
spa_loop_control_iterate(data.loop_control, -1);
|
||||||
|
}
|
||||||
|
spa_loop_control_leave(data.loop_control);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue