Use v4l2 monitor

Use the v4l2 monitor to dynamically add and remove nodes.
Use the info from the monitor as parameter for the factory init and use
it to configure the new node.
Add info to the node.
Use info from the factory as properties on the PinosNode
This commit is contained in:
Wim Taymans 2016-09-15 17:51:34 +02:00
parent 9f53eda6cb
commit 6497c82a7d
23 changed files with 542 additions and 315 deletions

View file

@ -54,7 +54,6 @@ typedef struct {
const char *klass;
const SpaDict *info;
const SpaHandleFactory *factory;
const void *config;
} SpaMonitorItem;
/**

View file

@ -154,6 +154,12 @@ struct _SpaNode {
/* the total size of this node. This can be used to expand this
* structure in the future */
size_t size;
/**
* SpaNode::info
*
* Extra information about the node
*/
const SpaDict * info;
/**
* SpaNode::state:
*

View file

@ -102,8 +102,8 @@ struct _SpaHandleFactory {
* SpaHandleFactory::init
* @factory: a #SpaHandleFactory
* @handle: a pointer to memory
* @config: extra handle specific config information, usually obtained from
* a #SpaMonitor.
* @info: extra handle specific information, usually obtained
* from a #SpaMonitor. This can be used to configure the handle.
*
* Initialize an instance of this factory. The caller should allocate
* memory at least SpaHandleFactory::size bytes and pass this as @handle.
@ -114,7 +114,7 @@ struct _SpaHandleFactory {
*/
SpaResult (*init) (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config);
const SpaDict *info);
/**
* SpaHandle::enum_interface_info:

View file

@ -649,6 +649,7 @@ spa_alsa_sink_node_port_pull_output (SpaNode *node,
static const SpaNode alsasink_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_alsa_sink_node_get_props,
spa_alsa_sink_node_set_props,
@ -703,7 +704,7 @@ alsa_sink_clear (SpaHandle *handle)
static SpaResult
alsa_sink_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaALSASink *this;

View file

@ -726,6 +726,7 @@ spa_audiomixer_node_port_push_event (SpaNode *node,
static const SpaNode audiomixer_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_audiomixer_node_get_props,
spa_audiomixer_node_set_props,
@ -781,7 +782,7 @@ spa_audiomixer_clear (SpaHandle *handle)
static SpaResult
spa_audiomixer_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaAudioMixer *this;

View file

@ -787,6 +787,7 @@ spa_audiotestsrc_node_port_push_event (SpaNode *node,
static const SpaNode audiotestsrc_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_audiotestsrc_node_get_props,
spa_audiotestsrc_node_set_props,
@ -842,7 +843,7 @@ audiotestsrc_clear (SpaHandle *handle)
static SpaResult
audiotestsrc_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaAudioTestSrc *this;

View file

@ -503,6 +503,7 @@ spa_ffmpeg_dec_node_port_push_event (SpaNode *node,
static const SpaNode ffmpeg_dec_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_ffmpeg_dec_node_get_props,
spa_ffmpeg_dec_node_set_props,

View file

@ -506,6 +506,7 @@ spa_ffmpeg_enc_node_port_push_event (SpaNode *node,
static const SpaNode ffmpeg_enc_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_ffmpeg_enc_node_get_props,
spa_ffmpeg_enc_node_set_props,

View file

@ -31,7 +31,7 @@ SpaResult spa_ffmpeg_enc_init (SpaHandle *handle);
static SpaResult
ffmpeg_dec_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
@ -42,7 +42,7 @@ ffmpeg_dec_init (const SpaHandleFactory *factory,
static SpaResult
ffmpeg_enc_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;

View file

@ -1099,6 +1099,7 @@ proxy_on_fd_events (SpaPollNotifyData *data)
static const SpaNode proxy_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_proxy_node_get_props,
spa_proxy_node_set_props,
@ -1153,7 +1154,7 @@ proxy_clear (SpaHandle *handle)
static SpaResult
proxy_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaProxy *this;

View file

@ -31,6 +31,8 @@
#include <spa/memory.h>
#include <spa/debug.h>
extern const SpaHandleFactory spa_v4l2_source_factory;
typedef struct _SpaV4l2Monitor SpaV4l2Monitor;
typedef struct {
@ -81,16 +83,14 @@ fill_item (V4l2Item *item, struct udev_device *udevice)
if (udevice == NULL)
return;
item->item.id = udev_device_get_devnode (item->udevice);
item->item.id = udev_device_get_syspath (item->udevice);
item->item.flags = 0;
item->item.state = SPA_MONITOR_ITEM_STATE_AVAILABLE;
item->item.klass = "Video/Source";
item->item.info = &item->info;
item->item.factory = NULL;
item->item.config = NULL;
item->item.factory = &spa_v4l2_source_factory;
item->info.items = item->info_items;
i = 0;
item->info_items[i].key = "udev-probed";
item->info_items[i++].value = "1";
@ -351,7 +351,7 @@ v4l2_monitor_clear (SpaHandle *handle)
static SpaResult
v4l2_monitor_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaV4l2Monitor *this;

View file

@ -728,6 +728,7 @@ spa_v4l2_source_node_port_push_event (SpaNode *node,
static const SpaNode v4l2source_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_v4l2_source_node_get_props,
spa_v4l2_source_node_set_props,
@ -835,9 +836,10 @@ v4l2_source_clear (SpaHandle *handle)
static SpaResult
v4l2_source_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaV4l2Source *this;
unsigned int i;
if (factory == NULL || handle == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
@ -859,6 +861,13 @@ v4l2_source_init (const SpaHandleFactory *factory,
this->state[0].export_buf = true;
for (i = 0; info && i < info->n_items; i ++) {
if (!strcmp (info->items[i].key, "device.path")) {
strncpy (this->props[1].device, info->items[i].value, 63);
this->props[1].props.unset_mask &= ~1;
}
}
return SPA_RESULT_OK;
}

View file

@ -621,6 +621,7 @@ spa_volume_node_port_push_event (SpaNode *node,
static const SpaNode volume_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_volume_node_get_props,
spa_volume_node_set_props,
@ -677,7 +678,7 @@ volume_clear (SpaHandle *handle)
static SpaResult
volume_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaVolume *this;

View file

@ -501,6 +501,7 @@ spa_xv_sink_node_port_push_event (SpaNode *node,
static const SpaNode xvsink_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
spa_xv_sink_node_get_props,
spa_xv_sink_node_set_props,
@ -556,7 +557,7 @@ xv_sink_clear (SpaHandle *handle)
static SpaResult
xv_sink_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const void *config)
const SpaDict *info)
{
SpaXvSink *this;