Rework transport protocol

Remove the old PinosBuffer object and replace it with SpaControl, this
communication protocol is designed to make it possible to implement
remote nodes and so it is moved to Spa.
Move SpaBuffer into to API
Work on easier API to make formats, implement enumeration and support
for all formats in v4l2.
Improve format output in -inspect
This commit is contained in:
Wim Taymans 2016-07-28 21:19:20 +02:00
parent b795fb851f
commit 4cb90f3b86
37 changed files with 2658 additions and 1032 deletions

View file

@ -101,10 +101,11 @@ typedef struct {
/**
* SpaDataType:
* @SPA_DATA_TYPE_INVALID: invalid data type, is ignored
* @SPA_DATA_TYPE_MEMPTR: data and size point to memory accassible by the
* @SPA_DATA_TYPE_MEMPTR: data and size point to memory accessible by the
* CPU.
* @SPA_DATA_TYPE_FD: data points to an int file descriptor that can be
* mmapped.
* @SPA_DATA_TYPE_MEMID: data points to the id of the memory block to use
* @SPA_DATA_TYPE_POINTER: data points to some other datastructure, the
* type can be found in ptr_type
*/
@ -112,6 +113,7 @@ typedef enum {
SPA_DATA_TYPE_INVALID = 0,
SPA_DATA_TYPE_MEMPTR,
SPA_DATA_TYPE_FD,
SPA_DATA_TYPE_MEMID,
SPA_DATA_TYPE_POINTER,
} SpaDataType;
@ -138,6 +140,7 @@ typedef struct {
* SpaBuffer:
* @refcount: reference counter
* @notify: called when the refcount reaches 0
* @id: buffer id
* @size: total size of the buffer data
* @n_metas: number of metadata
* @metas: array of @n_metas metadata
@ -147,6 +150,7 @@ typedef struct {
struct _SpaBuffer {
volatile int refcount;
SpaNotify notify;
uint32_t id;
size_t size;
unsigned int n_metas;
SpaMeta *metas;

273
spa/include/spa/control.h Normal file
View file

@ -0,0 +1,273 @@
/* 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_CONTROL_H__
#define __SPA_CONTROL_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _SpaControl SpaControl;
typedef struct _SpaControlIter SpaControlIter;
typedef struct _SpaControlBuilder SpaControlBuilder;
#define SPA_CONTROL_VERSION 0
#include <spa/defs.h>
#include <spa/props.h>
#include <spa/format.h>
#include <spa/port.h>
struct _SpaControl {
size_t x[16];
};
SpaResult spa_control_init_data (SpaControl *control,
void *data,
size_t size,
int *fds,
unsigned int n_fds);
SpaResult spa_control_clear (SpaControl *control);
uint32_t spa_control_get_version (SpaControl *control);
int spa_control_get_fd (SpaControl *control,
unsigned int index,
bool close);
typedef enum {
SPA_CONTROL_CMD_INVALID = 0,
/* client to server */
SPA_CONTROL_CMD_NODE_UPDATE = 1,
SPA_CONTROL_CMD_PORT_UPDATE = 2,
SPA_CONTROL_CMD_PORT_REMOVED = 3,
SPA_CONTROL_CMD_START_CONFIGURE = 4,
SPA_CONTROL_CMD_PORT_STATUS_CHANGE = 5,
SPA_CONTROL_CMD_START_ALLOC = 6,
SPA_CONTROL_CMD_NEED_INPUT = 7,
SPA_CONTROL_CMD_HAVE_OUTPUT = 8,
/* server to client */
SPA_CONTROL_CMD_ADD_PORT = 32,
SPA_CONTROL_CMD_REMOVE_PORT = 33,
SPA_CONTROL_CMD_SET_FORMAT = 34,
SPA_CONTROL_CMD_SET_PROPERTY = 35,
SPA_CONTROL_CMD_END_CONFIGURE = 36,
SPA_CONTROL_CMD_PAUSE = 37,
SPA_CONTROL_CMD_START = 38,
SPA_CONTROL_CMD_STOP = 39,
/* both */
SPA_CONTROL_CMD_ADD_MEM = 64,
SPA_CONTROL_CMD_REMOVE_MEM = 65,
SPA_CONTROL_CMD_ADD_BUFFER = 66,
SPA_CONTROL_CMD_REMOVE_BUFFER = 67,
SPA_CONTROL_CMD_PROCESS_BUFFER = 68,
SPA_CONTROL_CMD_REUSE_BUFFER = 69,
} SpaControlCmd;
/* SPA_CONTROL_CMD_NODE_UPDATE */
typedef struct {
uint32_t change_mask;
uint32_t max_input_ports;
uint32_t max_output_ports;
const SpaProps *props;
} SpaControlCmdNodeUpdate;
/* SPA_CONTROL_CMD_PORT_UPDATE */
typedef struct {
uint32_t port;
uint32_t change_mask;
uint32_t direction;
uint32_t n_possible_formats;
const SpaFormat **possible_formats;
const SpaProps *props;
const SpaPortInfo *info;
} SpaControlCmdPortUpdate;
/* SPA_CONTROL_CMD_PORT_REMOVED */
typedef struct {
uint32_t port;
} SpaControlCmdPortRemoved;
/* SPA_CONTROL_CMD_START_CONFIGURE */
/* SPA_CONTROL_CMD_PORT_STATUS_CHANGE */
/* SPA_CONTROL_CMD_START_ALLOC */
/* SPA_CONTROL_CMD_NEED_INPUT */
typedef struct {
uint32_t port;
} SpaControlCmdNeedInput;
/* SPA_CONTROL_CMD_HAVE_OUTPUT */
typedef struct {
uint32_t port;
} SpaControlCmdHaveOutput;
/* SPA_CONTROL_CMD_ADD_PORT */
typedef struct {
uint32_t port;
uint32_t direction;
} SpaControlCmdAddPort;
/* SPA_CONTROL_CMD_REMOVE_PORT */
typedef struct {
uint32_t port;
} SpaControlCmdRemovePort;
/* SPA_CONTROL_CMD_SET_FORMAT */
typedef struct {
uint32_t port;
const SpaFormat *format;
const char *str;
} SpaControlCmdSetFormat;
/* SPA_CONTROL_CMD_SET_PROPERTY */
typedef struct {
uint32_t port;
uint32_t id;
uint32_t size;
void *value;
} SpaControlCmdSetProperty;
/* SPA_CONTROL_CMD_END_CONFIGURE */
/* SPA_CONTROL_CMD_PAUSE */
/* SPA_CONTROL_CMD_START */
/* SPA_CONTROL_CMD_STOP */
/* SPA_CONTROL_CMD_ADD_MEM */
typedef struct {
uint32_t port;
uint32_t id;
uint32_t type;
uint32_t fd_index;
uint64_t offset;
uint64_t size;
} SpaControlCmdAddMem;
/* SPA_CONTROL_CMD_REMOVE_MEM */
typedef struct {
uint32_t port;
uint32_t id;
} SpaControlCmdRemoveMem;
/* SPA_CONTROL_CMD_ADD_BUFFER */
typedef struct {
uint32_t port;
SpaBuffer *buffer;
} SpaControlCmdAddBuffer;
/* SPA_CONTROL_CMD_REMOVE_BUFFER */
typedef struct {
uint32_t port;
uint32_t id;
} SpaControlCmdRemoveBuffer;
/* SPA_CONTROL_CMD_PROCESS_BUFFER */
typedef struct {
uint32_t port;
uint32_t id;
} SpaControlCmdProcessBuffer;
/* SPA_CONTROL_CMD_REUSE_BUFFER */
typedef struct {
uint32_t port;
uint32_t id;
} SpaControlCmdReuseBuffer;
struct _SpaControlIter {
/*< private >*/
size_t x[16];
};
SpaResult spa_control_iter_init_full (SpaControlIter *iter,
SpaControl *control,
uint32_t version);
#define spa_control_iter_init(i,b) spa_control_iter_init_full(i,b, SPA_CONTROL_VERSION);
SpaResult spa_control_iter_next (SpaControlIter *iter);
SpaResult spa_control_iter_end (SpaControlIter *iter);
SpaControlCmd spa_control_iter_get_cmd (SpaControlIter *iter);
void * spa_control_iter_get_data (SpaControlIter *iter, size_t *size);
SpaResult spa_control_iter_parse_cmd (SpaControlIter *iter,
void *command);
/**
* SpaControlBuilder:
*/
struct _SpaControlBuilder {
/*< private >*/
size_t x[16];
};
SpaResult spa_control_builder_init_full (SpaControlBuilder *builder,
uint32_t version,
void *data,
size_t max_data,
int *fds,
unsigned int max_fds);
#define spa_control_builder_init_into(b,d,md,f,mf) spa_control_builder_init_full(b, SPA_CONTROL_VERSION,d,md,f,mf);
#define spa_control_builder_init(b) spa_control_builder_init_into(b, NULL, 0, NULL, 0);
SpaResult spa_control_builder_clear (SpaControlBuilder *builder);
SpaResult spa_control_builder_end (SpaControlBuilder *builder,
SpaControl *control);
int spa_control_builder_add_fd (SpaControlBuilder *builder,
int fd,
bool close);
SpaResult spa_control_builder_add_cmd (SpaControlBuilder *builder,
SpaControlCmd cmd,
void *command);
/* IO */
SpaResult spa_control_read (SpaControl *control,
int fd,
void *data,
size_t max_data,
int *fds,
unsigned int max_fds);
SpaResult spa_control_write (SpaControl *control,
int fd);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_CONTROL_H__ */

38
spa/include/spa/debug.h Normal file
View file

@ -0,0 +1,38 @@
/* 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_DEBUG_H__
#define __SPA_DEBUG_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/defs.h>
#include <spa/port.h>
SpaResult spa_debug_port_info (const SpaPortInfo *info);
SpaResult spa_debug_dump_mem (void *data, size_t size);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_DEBUG_H__ */

View file

@ -45,6 +45,7 @@ typedef struct _SpaEvent SpaEvent;
* @SPA_EVENT_TYPE_MARKER: emited when MARK command completed
* @SPA_EVENT_TYPE_ERROR: emited when error occured
* @SPA_EVENT_TYPE_BUFFERING: emited when buffering is in progress
* @SPA_EVENT_TYPE_REQUEST_REFRESH: emited when a keyframe refresh is needed
*/
typedef enum {
SPA_EVENT_TYPE_INVALID = 0,
@ -60,6 +61,7 @@ typedef enum {
SPA_EVENT_TYPE_MARKER,
SPA_EVENT_TYPE_ERROR,
SPA_EVENT_TYPE_BUFFERING,
SPA_EVENT_TYPE_REQUEST_REFRESH,
} SpaEventType;
struct _SpaEvent {

View file

@ -33,11 +33,26 @@ typedef enum {
SPA_MEDIA_TYPE_INVALID = 0,
SPA_MEDIA_TYPE_AUDIO = 1,
SPA_MEDIA_TYPE_VIDEO = 2,
SPA_MEDIA_TYPE_IMAGE = 3,
} SpaMediaType;
typedef enum {
SPA_MEDIA_SUBTYPE_INVALID = 0,
SPA_MEDIA_SUBTYPE_RAW = 1,
SPA_MEDIA_SUBTYPE_H264 = 2,
SPA_MEDIA_SUBTYPE_MJPG = 3,
SPA_MEDIA_SUBTYPE_DV = 4,
SPA_MEDIA_SUBTYPE_MPEGTS = 5,
SPA_MEDIA_SUBTYPE_H263 = 6,
SPA_MEDIA_SUBTYPE_MPEG1 = 7,
SPA_MEDIA_SUBTYPE_MPEG2 = 8,
SPA_MEDIA_SUBTYPE_MPEG4 = 9,
SPA_MEDIA_SUBTYPE_XVID = 10,
SPA_MEDIA_SUBTYPE_VC1 = 11,
SPA_MEDIA_SUBTYPE_VP8 = 12,
SPA_MEDIA_SUBTYPE_VP9 = 13,
SPA_MEDIA_SUBTYPE_JPEG = 14,
SPA_MEDIA_SUBTYPE_BAYER = 15,
} SpaMediaSubType;
struct _SpaFormat {

View file

@ -244,7 +244,6 @@ SpaResult spa_props_copy (const SpaProps *src,
SpaProps *dest);
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -57,6 +57,10 @@ SpaResult spa_video_raw_format_init (SpaVideoRawFormat *format);
SpaResult spa_video_raw_format_parse (const SpaFormat *format,
SpaVideoRawFormat *rawformat);
SpaResult spa_video_raw_fill_default_info (SpaVideoRawInfo *info);
SpaResult spa_video_raw_fill_prop_info (SpaPropInfo *info,
SpaPropIdVideo id,
size_t offset);
#ifdef __cplusplus
} /* extern "C" */