spa: improve object properties

This commit is contained in:
Wim Taymans 2019-10-01 10:04:22 +02:00
parent dc83c10c9a
commit 82ee139f65
4 changed files with 37 additions and 12 deletions

View file

@ -81,6 +81,11 @@ extern "C" {
#define SPA_KEY_API_V4L2_CAP_DRIVER "api.v4l2.cap.driver" /**< driver from capbility */ #define SPA_KEY_API_V4L2_CAP_DRIVER "api.v4l2.cap.driver" /**< driver from capbility */
#define SPA_KEY_API_V4L2_CAP_CARD "api.v4l2.cap.card" /**< caps from capability */ #define SPA_KEY_API_V4L2_CAP_CARD "api.v4l2.cap.card" /**< caps from capability */
#define SPA_KEY_API_V4L2_CAP_BUS_INFO "api.v4l2.cap.bus_info" /**< bus_info from capability */ #define SPA_KEY_API_V4L2_CAP_BUS_INFO "api.v4l2.cap.bus_info" /**< bus_info from capability */
#define SPA_KEY_API_V4L2_CAP_VERSION "api.v4l2.cap.version" /**< version from capability as %u.%u.%u */
#define SPA_KEY_API_V4L2_CAP_CAPABILITIES \
"api.v4l2.cap.capabilities" /**< capabilities from capability */
#define SPA_KEY_API_V4L2_CAP_DEVICE_CAPS \
"api.v4l2.cap.device-caps" /**< device_caps from capability */
/** keys for bluez5 api */ /** keys for bluez5 api */

View file

@ -116,17 +116,21 @@ static const char *get_subclass(snd_pcm_info_t *pcminfo)
static int emit_node(struct impl *this, snd_pcm_info_t *pcminfo, uint32_t id) static int emit_node(struct impl *this, snd_pcm_info_t *pcminfo, uint32_t id)
{ {
struct spa_dict_item items[12]; struct spa_dict_item items[12];
char device_name[128], path[160]; char device_name[128], path[180];
char sync_name[128], dev[16], subdev[16], card[16]; char sync_name[128], dev[16], subdev[16], card[16];
struct spa_device_object_info info; struct spa_device_object_info info;
snd_pcm_sync_id_t sync_id; snd_pcm_sync_id_t sync_id;
const char *stream;
info = SPA_DEVICE_OBJECT_INFO_INIT(); info = SPA_DEVICE_OBJECT_INFO_INIT();
info.type = SPA_TYPE_INTERFACE_Node; info.type = SPA_TYPE_INTERFACE_Node;
if (snd_pcm_info_get_stream(pcminfo) == SND_PCM_STREAM_PLAYBACK) if (snd_pcm_info_get_stream(pcminfo) == SND_PCM_STREAM_PLAYBACK) {
info.factory_name = SPA_NAME_API_ALSA_PCM_SINK; info.factory_name = SPA_NAME_API_ALSA_PCM_SINK;
else stream = "playback";
} else {
info.factory_name = SPA_NAME_API_ALSA_PCM_SOURCE; info.factory_name = SPA_NAME_API_ALSA_PCM_SOURCE;
stream = "capture";
}
info.change_mask = SPA_DEVICE_OBJECT_CHANGE_MASK_PROPS; info.change_mask = SPA_DEVICE_OBJECT_CHANGE_MASK_PROPS;
@ -134,7 +138,7 @@ static int emit_node(struct impl *this, snd_pcm_info_t *pcminfo, uint32_t id)
snprintf(dev, sizeof(dev), "%d", snd_pcm_info_get_device(pcminfo)); snprintf(dev, sizeof(dev), "%d", snd_pcm_info_get_device(pcminfo));
snprintf(subdev, sizeof(subdev), "%d", snd_pcm_info_get_subdevice(pcminfo)); snprintf(subdev, sizeof(subdev), "%d", snd_pcm_info_get_subdevice(pcminfo));
snprintf(device_name, sizeof(device_name), "%s,%s", this->props.device, dev); snprintf(device_name, sizeof(device_name), "%s,%s", this->props.device, dev);
snprintf(path, sizeof(path), "alsa:pcm:%s", device_name); snprintf(path, sizeof(path), "alsa:pcm:%s:%s", device_name, stream);
items[0] = SPA_DICT_ITEM_INIT(SPA_KEY_OBJECT_PATH, path); items[0] = SPA_DICT_ITEM_INIT(SPA_KEY_OBJECT_PATH, path);
items[1] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PATH, device_name); items[1] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PATH, device_name);
items[2] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PCM_CARD, card); items[2] = SPA_DICT_ITEM_INIT(SPA_KEY_API_ALSA_PCM_CARD, card);

View file

@ -71,10 +71,11 @@ struct impl {
static int emit_info(struct impl *this, bool full) static int emit_info(struct impl *this, bool full)
{ {
int res; int res;
struct spa_dict_item items[6]; struct spa_dict_item items[10];
uint32_t n_items = 0; uint32_t n_items = 0;
struct spa_device_info info; struct spa_device_info info;
struct spa_param_info params[2]; struct spa_param_info params[2];
char path[128], version[16], capabilities[16], device_caps[16];
if ((res = spa_v4l2_open(&this->dev, this->props.device)) < 0) if ((res = spa_v4l2_open(&this->dev, this->props.device)) < 0)
return res; return res;
@ -82,12 +83,26 @@ static int emit_info(struct impl *this, bool full)
info = SPA_DEVICE_INFO_INIT(); info = SPA_DEVICE_INFO_INIT();
info.change_mask = SPA_DEVICE_CHANGE_MASK_PROPS; info.change_mask = SPA_DEVICE_CHANGE_MASK_PROPS;
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MEDIA_CLASS, "Video/Device");
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_API, "v4l2"); #define ADD_ITEM(key, value) items[n_items++] = SPA_DICT_ITEM_INIT(key, value)
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_PATH, (char *)this->props.device); snprintf(path, sizeof(path), "v4l2:%s", this->props.device);
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_DRIVER, (char *)this->dev.cap.driver); ADD_ITEM(SPA_KEY_OBJECT_PATH, path);
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_CARD, (char *)this->dev.cap.card); ADD_ITEM(SPA_KEY_DEVICE_API, "v4l2");
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_BUS_INFO, (char *)this->dev.cap.bus_info); ADD_ITEM(SPA_KEY_MEDIA_CLASS, "Video/Device");
ADD_ITEM(SPA_KEY_API_V4L2_PATH, (char *)this->props.device);
ADD_ITEM(SPA_KEY_API_V4L2_CAP_DRIVER, (char *)this->dev.cap.driver);
ADD_ITEM(SPA_KEY_API_V4L2_CAP_CARD, (char *)this->dev.cap.card);
ADD_ITEM(SPA_KEY_API_V4L2_CAP_BUS_INFO, (char *)this->dev.cap.bus_info);
snprintf(version, sizeof(version), "%u.%u.%u",
(this->dev.cap.version >> 16) & 0xFF,
(this->dev.cap.version >> 8) & 0xFF,
(this->dev.cap.version) & 0xFF);
ADD_ITEM(SPA_KEY_API_V4L2_CAP_VERSION, version);
snprintf(capabilities, sizeof(capabilities), "%08x", this->dev.cap.capabilities);
ADD_ITEM(SPA_KEY_API_V4L2_CAP_CAPABILITIES, capabilities);
snprintf(device_caps, sizeof(device_caps), "%08x", this->dev.cap.device_caps);
ADD_ITEM(SPA_KEY_API_V4L2_CAP_DEVICE_CAPS, device_caps);
#undef ADD_ITEM
info.props = &SPA_DICT_INIT(items, n_items); info.props = &SPA_DICT_INIT(items, n_items);
info.change_mask |= SPA_DEVICE_CHANGE_MASK_PARAMS; info.change_mask |= SPA_DEVICE_CHANGE_MASK_PARAMS;

View file

@ -460,6 +460,7 @@ static struct alsa_object *alsa_create_object(struct monitor *monitor, uint32_t
} }
} }
/* no device reservation, activate device right now */
if (obj->reserve == NULL) if (obj->reserve == NULL)
set_profile(obj, 1); set_profile(obj, 1);