Add monitor interface

Add an interface to monitor devices and helper program
Add v4l2 monitor
Add simple dictionary with key/value pairs
This commit is contained in:
Wim Taymans 2016-09-15 11:49:34 +02:00
parent 140f360cc0
commit 9f53eda6cb
29 changed files with 921 additions and 51 deletions

View file

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

View file

@ -29,12 +29,14 @@ extern "C" {
#include <spa/buffer.h>
#include <spa/props.h>
#include <spa/format.h>
#include <spa/dict.h>
SpaResult spa_debug_port_info (const SpaPortInfo *info);
SpaResult spa_debug_buffer (const SpaBuffer *buffer);
SpaResult spa_debug_props (const SpaProps *props, bool print_ranges);
SpaResult spa_debug_format (const SpaFormat *format);
SpaResult spa_debug_dump_mem (const void *data, size_t size);
SpaResult spa_debug_dict (const SpaDict *dict);
#ifdef __cplusplus
} /* extern "C" */

45
spa/include/spa/dict.h Normal file
View file

@ -0,0 +1,45 @@
/* Simple Plugin API
* 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.
*/
#ifndef __SPA_DICT_H__
#define __SPA_DICT_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaDict SpaDict;
#include <spa/defs.h>
typedef struct {
const char *key;
const char *value;
} SpaDictItem;
struct _SpaDict {
unsigned int n_items;
SpaDictItem *items;
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_DICT_H__ */

150
spa/include/spa/monitor.h Normal file
View file

@ -0,0 +1,150 @@
/* Simple Plugin API
* 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.
*/
#ifndef __SPA_MONITOR_H__
#define __SPA_MONITOR_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaMonitor SpaMonitor;
#include <spa/defs.h>
#include <spa/dict.h>
#include <spa/plugin.h>
typedef enum {
SPA_MONITOR_ITEM_FLAG_NONE = 0,
} SpaMonitorItemFlags;
/**
* SpaMonitorItemState:
* @SPA_MONITOR_ITEM_STATE_AVAILABLE: The item is available
* @SPA_MONITOR_ITEM_STATE_DISABLED: the item is disabled
* @SPA_MONITOR_ITEM_STATE_UNAVAILABLE: the item is unavailable
*/
typedef enum {
SPA_MONITOR_ITEM_STATE_AVAILABLE,
SPA_MONITOR_ITEM_STATE_DISABLED,
SPA_MONITOR_ITEM_STATE_UNAVAILABLE,
} SpaMonitorItemState;
typedef struct {
const char *id;
SpaMonitorItemFlags flags;
SpaMonitorItemState state;
const char *name;
const char *klass;
const SpaDict *info;
const SpaHandleFactory *factory;
const void *config;
} SpaMonitorItem;
/**
* SpaMonitorEventType:
* @SPA_MONITOR_EVENT_TYPE_INVALID: invalid event
* @SPA_MONITOR_EVENT_TYPE_ADDED: an item was added, data points to #SpaMonitorItem
* @SPA_MONITOR_EVENT_TYPE_REMOVED: an item was removed, data points to #SpaMonitorItem
* @SPA_MONITOR_EVENT_TYPE_CHANGED: an item was changed, data points to #SpaMonitorItem
* @SPA_MONITOR_EVENT_TYPE_ADD_POLL: add fd for polling, data points to #SpaPollItem
* @SPA_MONITOR_EVENT_TYPE_UPDATE_POLL: update fd for polling, data points to #SpaPollItem
* @SPA_MONITOR_EVENT_TYPE_REMOVE_POLL: remov fd for polling, data points to #SpaPollItem
*/
typedef enum {
SPA_MONITOR_EVENT_TYPE_INVALID = 0,
SPA_MONITOR_EVENT_TYPE_ADDED,
SPA_MONITOR_EVENT_TYPE_REMOVED,
SPA_MONITOR_EVENT_TYPE_CHANGED,
SPA_MONITOR_EVENT_TYPE_ADD_POLL,
SPA_MONITOR_EVENT_TYPE_UPDATE_POLL,
SPA_MONITOR_EVENT_TYPE_REMOVE_POLL,
} SpaMonitorEventType;
typedef struct {
SpaMonitorEventType type;
void *data;
size_t size;
} SpaMonitorEvent;
/**
* SpaMonitorCallback:
* @node: a #SpaMonitor emiting the event
* @event: the event that was emited
* @user_data: user data provided when registering the callback
*
* This will be called when a monitor event is notified
* on @monitor.
*/
typedef void (*SpaMonitorEventCallback) (SpaMonitor *monitor,
SpaMonitorEvent *event,
void *user_data);
#define SPA_INTERFACE_ID_MONITOR 2
#define SPA_INTERFACE_ID_MONITOR_NAME "Monitor interface"
#define SPA_INTERFACE_ID_MONITOR_DESCRIPTION "Device Monitor interface"
/**
* SpaMonitor:
*
* The device monitor interface.
*/
struct _SpaMonitor {
/* pointer to the handle owning this interface */
SpaHandle *handle;
/**
* SpaMonitor::info
*
* Extra information about the monitor
*/
const SpaDict * info;
/* the total size of this monitor. This can be used to expand this
* structure in the future */
size_t size;
/**
* SpaMonitor::set_event_callback:
* @monitor: a #SpaMonitor
* @callback: a #SpaMonitorEventCallback
* @user_data: extra user data
*
* Set an event callback to receive asynchronous notifications from
* the monitor.
*
* Returns: #SPA_RESULT_OK on success
*/
SpaResult (*set_event_callback) (SpaMonitor *monitor,
SpaMonitorEventCallback callback,
void *user_data);
SpaResult (*enum_items) (SpaMonitor *monitor,
SpaMonitorItem **item,
void **state);
};
#define spa_monitor_set_event_callback(m,...) (m)->set_event_callback((m),__VA_ARGS__)
#define spa_monitor_enum_items(m,...) (m)->enum_items((m),__VA_ARGS__)
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_MONITOR_H__ */

View file

@ -25,7 +25,7 @@ extern "C" {
#endif
#include <spa/defs.h>
#include <spa/props.h>
#include <spa/dict.h>
typedef struct _SpaHandle SpaHandle;
typedef struct _SpaHandleFactory SpaHandleFactory;
@ -90,7 +90,7 @@ struct _SpaHandleFactory {
*
* Extra information about the handles of this factory.
*/
const SpaProps * info;
const SpaDict * info;
/**
* SpaHandleFactory::size
*
@ -102,6 +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.
*
* Initialize an instance of this factory. The caller should allocate
* memory at least SpaHandleFactory::size bytes and pass this as @handle.
@ -111,7 +113,8 @@ struct _SpaHandleFactory {
* #SPA_RESULT_INVALID_ARGUMENTS when factory or handle are %NULL
*/
SpaResult (*init) (const SpaHandleFactory *factory,
SpaHandle *handle);
SpaHandle *handle,
const void *config);
/**
* SpaHandle::enum_interface_info:

View file

@ -158,7 +158,7 @@ typedef struct {
* properties. Can be %NULL when unspecified.
* @unset_mask: mask of unset properties. For each property in @prop_info there
* is a corresponding bit that specifies if the property is currently
* unset. When more that 32 properties are present, more uint32_t
* unset. When more than 32 properties are present, more uint32_t
* fields follow this one.
*
* Generic propertiers.