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

@ -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)
{
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];
struct spa_device_object_info info;
snd_pcm_sync_id_t sync_id;
const char *stream;
info = SPA_DEVICE_OBJECT_INFO_INIT();
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;
else
stream = "playback";
} else {
info.factory_name = SPA_NAME_API_ALSA_PCM_SOURCE;
stream = "capture";
}
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(subdev, sizeof(subdev), "%d", snd_pcm_info_get_subdevice(pcminfo));
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[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);

View file

@ -71,10 +71,11 @@ struct impl {
static int emit_info(struct impl *this, bool full)
{
int res;
struct spa_dict_item items[6];
struct spa_dict_item items[10];
uint32_t n_items = 0;
struct spa_device_info info;
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)
return res;
@ -82,12 +83,26 @@ static int emit_info(struct impl *this, bool full)
info = SPA_DEVICE_INFO_INIT();
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");
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_PATH, (char *)this->props.device);
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_DRIVER, (char *)this->dev.cap.driver);
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_CARD, (char *)this->dev.cap.card);
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_CAP_BUS_INFO, (char *)this->dev.cap.bus_info);
#define ADD_ITEM(key, value) items[n_items++] = SPA_DICT_ITEM_INIT(key, value)
snprintf(path, sizeof(path), "v4l2:%s", this->props.device);
ADD_ITEM(SPA_KEY_OBJECT_PATH, path);
ADD_ITEM(SPA_KEY_DEVICE_API, "v4l2");
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.change_mask |= SPA_DEVICE_CHANGE_MASK_PARAMS;