command: make commands dynamic

Ensure format object type.
This commit is contained in:
Wim Taymans 2017-03-22 10:04:24 +01:00
parent 4d9f2c5161
commit c44a7c9735
36 changed files with 549 additions and 604 deletions

58
spa/include/spa/command.h Normal file
View file

@ -0,0 +1,58 @@
/* 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_COMMAND_H__
#define __SPA_COMMAND_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaCommand SpaCommand;
#include <spa/defs.h>
#include <spa/pod.h>
#define SPA_COMMAND_URI "http://spaplug.in/ns/command"
#define SPA_COMMAND_PREFIX SPA_COMMAND_URI "#"
typedef struct {
SpaPODObjectBody body;
} SpaCommandBody;
struct _SpaCommand {
SpaPOD pod;
SpaCommandBody body;
};
#define SPA_COMMAND_TYPE(cmd) ((cmd)->body.body.type)
#define SPA_COMMAND_INIT(type) \
{ { sizeof (SpaCommandBody), SPA_POD_TYPE_OBJECT }, \
{ { 0, type } } } \
#define SPA_COMMAND_INIT_COMPLEX(size,type,...) \
{ { size, SPA_POD_TYPE_OBJECT }, \
{ { 0, type }, __VA_ARGS__ } } \
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_COMMAND_H__ */

View file

@ -27,9 +27,10 @@ extern "C" {
typedef struct _SpaEvent SpaEvent;
#include <spa/defs.h>
#include <spa/pod-utils.h>
#include <spa/pod.h>
#define SPA_EVENT_TYPE(ev) ((ev)->body.body.type)
#define SPA_EVENT_URI "http://spaplug.in/ns/event"
#define SPA_EVENT_PREFIX SPA_EVENT_URI "#"
typedef struct {
SpaPODObjectBody body;
@ -40,6 +41,8 @@ struct _SpaEvent {
SpaEventBody body;
};
#define SPA_EVENT_TYPE(ev) ((ev)->body.body.type)
#define SPA_EVENT_INIT(type) \
{ { sizeof (SpaEventBody), SPA_POD_TYPE_OBJECT }, \
{ { 0, type } } } \

View file

@ -32,21 +32,22 @@ extern "C" {
static inline uint32_t
spa_pod_builder_push_format (SpaPODBuilder *builder,
SpaPODFrame *frame,
uint32_t format_type,
uint32_t media_type,
uint32_t media_subtype)
{
const SpaFormat p = { { sizeof (SpaFormatBody), SPA_POD_TYPE_OBJECT },
{ { 0, 0 },
{ { 0, format_type },
{ { sizeof (uint32_t), SPA_POD_TYPE_URI }, media_type },
{ { sizeof (uint32_t), SPA_POD_TYPE_URI }, media_subtype } } };
return spa_pod_builder_push (builder, frame, &p.pod,
spa_pod_builder_raw (builder, &p, sizeof(p)));
}
#define spa_pod_builder_format(b,f,media_type,media_subtype,...) \
spa_pod_builder_object(b, f, 0, 0, \
SPA_POD_TYPE_URI,media_type, \
SPA_POD_TYPE_URI,media_subtype, \
#define spa_pod_builder_format(b,f,format_type,media_type,media_subtype,...) \
spa_pod_builder_object(b, f, 0, format_type, \
SPA_POD_TYPE_URI,media_type, \
SPA_POD_TYPE_URI,media_subtype, \
__VA_ARGS__)
SpaResult

View file

@ -27,6 +27,7 @@ extern "C" {
#include <stdarg.h>
#include <spa/format.h>
#include <spa/pod-utils.h>
#include <spa/id-map.h>
typedef struct {

View file

@ -30,7 +30,7 @@ extern "C" {
typedef struct _SpaFormat SpaFormat;
#include <spa/defs.h>
#include <spa/pod-utils.h>
#include <spa/pod.h>
#define SPA_MEDIA_TYPE_URI "http://spaplug.in/ns/media-type"
#define SPA_MEDIA_TYPE_PREFIX SPA_MEDIA_TYPE_URI "#"

View file

@ -2,6 +2,7 @@ spa_headers = [
'barrier.h',
'buffer.h',
'clock.h',
'command.h',
'defs.h',
'dict.h',
'event.h',

View file

@ -24,10 +24,8 @@
extern "C" {
#endif
typedef struct _SpaNodeCommand SpaNodeCommand;
#include <spa/defs.h>
#include <spa/clock.h>
#include <spa/id-map.h>
#include <spa/command.h>
#define SPA_NODE_COMMAND_URI "http://spaplug.in/ns/node-command"
#define SPA_NODE_COMMAND_PREFIX SPA_NODE_COMMAND_URI "#"
@ -39,34 +37,27 @@ typedef struct _SpaNodeCommand SpaNodeCommand;
#define SPA_NODE_COMMAND__Marker SPA_NODE_COMMAND_PREFIX "Marker"
#define SPA_NODE_COMMAND__ClockUpdate SPA_NODE_COMMAND_PREFIX "ClockUpdate"
typedef enum {
SPA_NODE_COMMAND_INVALID = 0,
SPA_NODE_COMMAND_PAUSE,
SPA_NODE_COMMAND_START,
SPA_NODE_COMMAND_FLUSH,
SPA_NODE_COMMAND_DRAIN,
SPA_NODE_COMMAND_MARKER,
SPA_NODE_COMMAND_CLOCK_UPDATE
} SpaNodeCommandType;
#define SPA_NODE_COMMAND_TYPE(cmd) ((cmd)->body.body.type)
typedef struct {
SpaPODObjectBody body;
} SpaNodeCommandBody;
uint32_t Pause;
uint32_t Start;
uint32_t Flush;
uint32_t Drain;
uint32_t Marker;
uint32_t ClockUpdate;
} SpaNodeCommands;
struct _SpaNodeCommand {
SpaPOD pod;
SpaNodeCommandBody body;
};
#define SPA_NODE_COMMAND_INIT(type) \
{ { sizeof (SpaNodeCommandBody), SPA_POD_TYPE_OBJECT }, \
{ { 0, type } } } \
#define SPA_NODE_COMMAND_INIT_COMPLEX(size,type,...) \
{ { size, SPA_POD_TYPE_OBJECT }, \
{ { 0, type }, __VA_ARGS__ } } \
static inline void
spa_node_commands_map (SpaIDMap *map, SpaNodeCommands *types)
{
if (types->Pause == 0) {
types->Pause = spa_id_map_get_id (map, SPA_NODE_COMMAND__Pause);
types->Start = spa_id_map_get_id (map, SPA_NODE_COMMAND__Start);
types->Flush = spa_id_map_get_id (map, SPA_NODE_COMMAND__Flush);
types->Drain = spa_id_map_get_id (map, SPA_NODE_COMMAND__Drain);
types->Marker = spa_id_map_get_id (map, SPA_NODE_COMMAND__Marker);
types->ClockUpdate = spa_id_map_get_id (map, SPA_NODE_COMMAND__ClockUpdate);
}
}
/**
* SpaNodeCommandClockUpdate:
@ -103,18 +94,17 @@ typedef struct {
SpaNodeCommandClockUpdateBody body;
} SpaNodeCommandClockUpdate;
#define SPA_NODE_COMMAND_CLOCK_UPDATE_INIT(change_mask,rate,ticks,monotonic_time,offset,scale,state,flags,latency) \
SPA_NODE_COMMAND_INIT_COMPLEX (sizeof (SpaNodeCommandClockUpdateBody), \
SPA_NODE_COMMAND_CLOCK_UPDATE, \
SPA_POD_INT_INIT (change_mask), \
SPA_POD_INT_INIT (rate), \
SPA_POD_LONG_INIT (ticks), \
SPA_POD_LONG_INIT (monotonic_time), \
SPA_POD_LONG_INIT (offset), \
SPA_POD_INT_INIT (scale), \
SPA_POD_INT_INIT (state), \
SPA_POD_INT_INIT (flags), \
SPA_POD_LONG_INIT (latency))
#define SPA_NODE_COMMAND_CLOCK_UPDATE_INIT(type,change_mask,rate,ticks,monotonic_time,offset,scale,state,flags,latency) \
SPA_COMMAND_INIT_COMPLEX (sizeof (SpaNodeCommandClockUpdateBody), type, \
SPA_POD_INT_INIT (change_mask), \
SPA_POD_INT_INIT (rate), \
SPA_POD_LONG_INIT (ticks), \
SPA_POD_LONG_INIT (monotonic_time), \
SPA_POD_LONG_INIT (offset), \
SPA_POD_INT_INIT (scale), \
SPA_POD_INT_INIT (state), \
SPA_POD_INT_INIT (flags), \
SPA_POD_LONG_INIT (latency))
#ifdef __cplusplus
} /* extern "C" */

View file

@ -202,7 +202,7 @@ struct _SpaNode {
/**
* SpaNode::send_command:
* @node: a #SpaNode
* @command: a #SpaNodeCommand
* @command: a #SpaCommand
*
* Send a command to @node.
*
@ -216,8 +216,8 @@ struct _SpaNode {
* #SPA_RESULT_INVALID_COMMAND @command is an invalid command
* #SPA_RESULT_ASYNC @command is executed asynchronously
*/
SpaResult (*send_command) (SpaNode *node,
SpaNodeCommand *command);
SpaResult (*send_command) (SpaNode *node,
SpaCommand *command);
/**
* SpaNode::set_event_callback:
* @node: a #SpaNode
@ -542,7 +542,7 @@ struct _SpaNode {
SpaResult (*port_send_command) (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaNodeCommand *command);
SpaCommand *command);
/**
* SpaNode::process_input:
* @node: a #SpaNode