bluez5: make codec loading compatible with old conf files

Change codec factory names to api.codec.bluez5.*, so that they won't
conflict with old config file lib name rules for api.bluez5.*

Specify the fallback library name when loading the codecs, so that it
works without the rules in config files.
This commit is contained in:
Pauli Virtanen 2021-09-06 17:25:58 +03:00
parent 435de99428
commit b5ad37c7ac
5 changed files with 29 additions and 23 deletions

View file

@ -115,7 +115,9 @@ 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_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_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_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 codec factory names */
#define SPA_NAME_API_CODEC_BLUEZ5_A2DP "api.codec.bluez5.a2dp" /**< Bluez5 A2DP codec plugin */
/** keys for v4l2 factory names */ /** keys for v4l2 factory names */
#define SPA_NAME_API_V4L2_ENUM_UDEV "api.v4l2.enum.udev" /**< a v4l2 udev Device interface */ #define SPA_NAME_API_V4L2_ENUM_UDEV "api.v4l2.enum.udev" /**< a v4l2 udev Device interface */

View file

@ -50,7 +50,7 @@ struct spa_bluez5_codec_a2dp {
const struct a2dp_codec * const *codecs; /**< NULL terminated array */ const struct a2dp_codec * const *codecs; /**< NULL terminated array */
}; };
#define A2DP_CODEC_FACTORY_NAME(basename) (SPA_NAME_API_BLUEZ5_CODEC_A2DP "." basename) #define A2DP_CODEC_FACTORY_NAME(basename) (SPA_NAME_API_CODEC_BLUEZ5_A2DP "." basename)
#ifdef CODEC_PLUGIN #ifdef CODEC_PLUGIN
#define A2DP_CODEC_EXPORT_DEF(basename,...) \ #define A2DP_CODEC_EXPORT_DEF(basename,...) \

View file

@ -31,6 +31,8 @@
#include "defs.h" #include "defs.h"
#include "codec-loader.h" #include "codec-loader.h"
#define A2DP_CODEC_LIB_BASE "bluez5/libspa-codec-bluez5-"
/* AVDTP allows 0x3E endpoints, can't have more codecs than that */ /* AVDTP allows 0x3E endpoints, can't have more codecs than that */
#define MAX_CODECS 0x3E #define MAX_CODECS 0x3E
#define MAX_HANDLES MAX_CODECS #define MAX_HANDLES MAX_CODECS
@ -77,7 +79,7 @@ static int codec_order_cmp(const void *a, const void *b)
return (ia == ib) ? (*ca < *cb ? -1 : 1) : ia - ib; return (ia == ib) ? (*ca < *cb ? -1 : 1) : ia - ib;
} }
static int load_a2dp_codecs_from(struct impl *impl, const char *factory_name) static int load_a2dp_codecs_from(struct impl *impl, const char *factory_name, const char *libname)
{ {
struct spa_handle *handle = NULL; struct spa_handle *handle = NULL;
void *iface; void *iface;
@ -85,8 +87,12 @@ static int load_a2dp_codecs_from(struct impl *impl, const char *factory_name)
int n_codecs = 0; int n_codecs = 0;
int res; int res;
size_t i; size_t i;
struct spa_dict_item info_items[] = {
{ SPA_KEY_LIBRARY_NAME, libname },
};
struct spa_dict info = SPA_DICT_INIT_ARRAY(info_items);
handle = spa_plugin_loader_load(impl->loader, factory_name, NULL); handle = spa_plugin_loader_load(impl->loader, factory_name, &info);
if (handle == NULL) { if (handle == NULL) {
spa_log_info(impl->log, NAME ": Bluetooth codec plugin %s not available", factory_name); spa_log_info(impl->log, NAME ": Bluetooth codec plugin %s not available", factory_name);
return -ENOENT; return -ENOENT;
@ -152,15 +158,18 @@ fail:
const struct a2dp_codec * const *load_a2dp_codecs(struct spa_plugin_loader *loader, struct spa_log *log) const struct a2dp_codec * const *load_a2dp_codecs(struct spa_plugin_loader *loader, struct spa_log *log)
{ {
struct impl *impl; 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; bool has_sbc;
size_t i; size_t i;
const struct { const char *factory; const char *lib; } plugins[] = {
#define A2DP_CODEC_FACTORY_LIB(basename) \
{ A2DP_CODEC_FACTORY_NAME(basename), A2DP_CODEC_LIB_BASE basename }
A2DP_CODEC_FACTORY_LIB("aac"),
A2DP_CODEC_FACTORY_LIB("aptx"),
A2DP_CODEC_FACTORY_LIB("faststream"),
A2DP_CODEC_FACTORY_LIB("ldac"),
A2DP_CODEC_FACTORY_LIB("sbc")
#undef A2DP_CODEC_FACTORY_LIB
};
impl = calloc(sizeof(struct impl), 1); impl = calloc(sizeof(struct impl), 1);
if (impl == NULL) if (impl == NULL)
@ -169,8 +178,8 @@ const struct a2dp_codec * const *load_a2dp_codecs(struct spa_plugin_loader *load
impl->loader = loader; impl->loader = loader;
impl->log = log; impl->log = log;
for (i = 0; i < SPA_N_ELEMENTS(codec_plugins); ++i) for (i = 0; i < SPA_N_ELEMENTS(plugins); ++i)
load_a2dp_codecs_from(impl, codec_plugins[i]); load_a2dp_codecs_from(impl, plugins[i].factory, plugins[i].lib);
has_sbc = false; has_sbc = false;
for (i = 0; i < impl->n_codecs; ++i) for (i = 0; i < impl->n_codecs; ++i)

View file

@ -56,7 +56,7 @@ bluez5lib = shared_library('spa-bluez5',
codec_args = [ '-DCODEC_PLUGIN' ] codec_args = [ '-DCODEC_PLUGIN' ]
bluez_codec_sbc = shared_library('spa-bluez5-codec-sbc', bluez_codec_sbc = shared_library('spa-codec-bluez5-sbc',
[ 'a2dp-codec-sbc.c', 'a2dp-codecs.c' ], [ 'a2dp-codec-sbc.c', 'a2dp-codecs.c' ],
include_directories : [ spa_inc, configinc ], include_directories : [ spa_inc, configinc ],
c_args : codec_args, c_args : codec_args,
@ -64,7 +64,7 @@ bluez_codec_sbc = shared_library('spa-bluez5-codec-sbc',
install : true, install : true,
install_dir : spa_plugindir / 'bluez5') install_dir : spa_plugindir / 'bluez5')
bluez_codec_faststream = shared_library('spa-bluez5-codec-faststream', bluez_codec_faststream = shared_library('spa-codec-bluez5-faststream',
[ 'a2dp-codec-faststream.c', 'a2dp-codecs.c' ], [ 'a2dp-codec-faststream.c', 'a2dp-codecs.c' ],
include_directories : [ spa_inc, configinc ], include_directories : [ spa_inc, configinc ],
c_args : codec_args, c_args : codec_args,
@ -73,7 +73,7 @@ bluez_codec_faststream = shared_library('spa-bluez5-codec-faststream',
install_dir : spa_plugindir / 'bluez5') install_dir : spa_plugindir / 'bluez5')
if fdk_aac_dep.found() if fdk_aac_dep.found()
bluez_codec_aac = shared_library('spa-bluez5-codec-aac', bluez_codec_aac = shared_library('spa-codec-bluez5-aac',
[ 'a2dp-codec-aac.c', 'a2dp-codecs.c' ], [ 'a2dp-codec-aac.c', 'a2dp-codecs.c' ],
include_directories : [ spa_inc, configinc ], include_directories : [ spa_inc, configinc ],
c_args : codec_args, c_args : codec_args,
@ -83,7 +83,7 @@ if fdk_aac_dep.found()
endif endif
if aptx_dep.found() if aptx_dep.found()
bluez_codec_aac = shared_library('spa-bluez5-codec-aptx', bluez_codec_aac = shared_library('spa-codec-bluez5-aptx',
[ 'a2dp-codec-aptx.c', 'a2dp-codecs.c' ], [ 'a2dp-codec-aptx.c', 'a2dp-codecs.c' ],
include_directories : [ spa_inc, configinc ], include_directories : [ spa_inc, configinc ],
c_args : codec_args, c_args : codec_args,
@ -99,7 +99,7 @@ if ldac_dep.found()
ldac_args += [ '-DENABLE_LDAC_ABR' ] ldac_args += [ '-DENABLE_LDAC_ABR' ]
ldac_dep += ldac_abr_dep ldac_dep += ldac_abr_dep
endif endif
bluez_codec_ldac = shared_library('spa-bluez5-codec-ldac', bluez_codec_ldac = shared_library('spa-codec-bluez5-ldac',
[ 'a2dp-codec-ldac.c', 'a2dp-codecs.c' ], [ 'a2dp-codec-ldac.c', 'a2dp-codecs.c' ],
include_directories : [ spa_inc, configinc ], include_directories : [ spa_inc, configinc ],
c_args : ldac_args, c_args : ldac_args,

View file

@ -16,11 +16,6 @@ context.properties = {
context.spa-libs = { context.spa-libs = {
# Mapping from factory name to library. # 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.bluez5.* = bluez5/libspa-bluez5
api.alsa.* = alsa/libspa-alsa api.alsa.* = alsa/libspa-alsa
api.v4l2.* = v4l2/libspa-v4l2 api.v4l2.* = v4l2/libspa-v4l2