mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
buffer: make data and meta types dynamic
Use dynamic types for the data and meta types. Move the meta into a separate header. Remove port state, we can keep track of that ourselves. Add size to MetaDataEnable params
This commit is contained in:
parent
ed273ec465
commit
b51d3e4862
36 changed files with 543 additions and 553 deletions
|
|
@ -87,6 +87,7 @@ spa_type_alloc_param_buffers_map (SpaTypeMap *map, SpaTypeAllocParamBuffers *typ
|
|||
#define SPA_TYPE_ALLOC_PARAM__MetaEnable SPA_TYPE_ALLOC_PARAM_BASE "MetaEnable"
|
||||
#define SPA_TYPE_ALLOC_PARAM_META_ENABLE_BASE SPA_TYPE_ALLOC_PARAM__MetaEnable ":"
|
||||
#define SPA_TYPE_ALLOC_PARAM_META_ENABLE__type SPA_TYPE_ALLOC_PARAM_META_ENABLE_BASE "type"
|
||||
#define SPA_TYPE_ALLOC_PARAM_META_ENABLE__size SPA_TYPE_ALLOC_PARAM_META_ENABLE_BASE "size"
|
||||
|
||||
#define SPA_TYPE_ALLOC_PARAM_META_ENABLE__ringbufferSize SPA_TYPE_ALLOC_PARAM_META_ENABLE_BASE "ringbufferSize"
|
||||
#define SPA_TYPE_ALLOC_PARAM_META_ENABLE__ringbufferStride SPA_TYPE_ALLOC_PARAM_META_ENABLE_BASE "ringbufferStride"
|
||||
|
|
@ -96,6 +97,7 @@ spa_type_alloc_param_buffers_map (SpaTypeMap *map, SpaTypeAllocParamBuffers *typ
|
|||
typedef struct {
|
||||
uint32_t MetaEnable;
|
||||
uint32_t type;
|
||||
uint32_t size;
|
||||
uint32_t ringbufferSize;
|
||||
uint32_t ringbufferStride;
|
||||
uint32_t ringbufferBlocks;
|
||||
|
|
@ -108,6 +110,7 @@ spa_type_alloc_param_meta_enable_map (SpaTypeMap *map, SpaTypeAllocParamMetaEnab
|
|||
if (type->MetaEnable == 0) {
|
||||
type->MetaEnable = spa_type_map_get_id (map, SPA_TYPE_ALLOC_PARAM__MetaEnable);
|
||||
type->type = spa_type_map_get_id (map, SPA_TYPE_ALLOC_PARAM_META_ENABLE__type);
|
||||
type->size = spa_type_map_get_id (map, SPA_TYPE_ALLOC_PARAM_META_ENABLE__size);
|
||||
type->ringbufferSize = spa_type_map_get_id (map, SPA_TYPE_ALLOC_PARAM_META_ENABLE__ringbufferSize);
|
||||
type->ringbufferStride = spa_type_map_get_id (map, SPA_TYPE_ALLOC_PARAM_META_ENABLE__ringbufferStride);
|
||||
type->ringbufferBlocks = spa_type_map_get_id (map, SPA_TYPE_ALLOC_PARAM_META_ENABLE__ringbufferBlocks);
|
||||
|
|
|
|||
|
|
@ -26,126 +26,37 @@ extern "C" {
|
|||
|
||||
typedef struct _SpaBuffer SpaBuffer;
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/meta.h>
|
||||
|
||||
#define SPA_TYPE__Buffer SPA_TYPE_POINTER_BASE "Buffer"
|
||||
#define SPA_TYPE_BUFFER_BASE SPA_TYPE__Buffer ":"
|
||||
|
||||
/**
|
||||
* SpaMetaType:
|
||||
* @SPA_META_TYPE_INVALID: invalid metadata, should be ignored
|
||||
* @SPA_META_TYPE_HEADER: header metadata
|
||||
* @SPA_META_TYPE_POINTER: a generic pointer
|
||||
* @SPA_META_TYPE_VIDEO_CROP: video cropping region
|
||||
* @SPA_META_TYPE_RINGBUFFER: a ringbuffer
|
||||
* @SPA_META_TYPE_SHARED: buffer data and metadata memory can be shared
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_META_TYPE_INVALID = 0,
|
||||
SPA_META_TYPE_HEADER,
|
||||
SPA_META_TYPE_POINTER,
|
||||
SPA_META_TYPE_VIDEO_CROP,
|
||||
SPA_META_TYPE_RINGBUFFER,
|
||||
SPA_META_TYPE_SHARED,
|
||||
} SpaMetaType;
|
||||
#define SPA_TYPE__Data SPA_TYPE_ENUM_BASE "DataType"
|
||||
#define SPA_TYPE_DATA_BASE SPA_TYPE__Data ":"
|
||||
|
||||
/**
|
||||
* SpaDataType:
|
||||
* @SPA_DATA_TYPE_INVALID: invalid data, should be ignored
|
||||
* @SPA_DATA_TYPE_MEMPTR: data points to CPU accessible memory
|
||||
* @SPA_DATA_TYPE_MEMFD: fd is memfd, data can be mmapped
|
||||
* @SPA_DATA_TYPE_DMABUF: fd is dmabuf, data can be mmapped
|
||||
* @SPA_DATA_TYPE_ID: data is an id use SPA_PTR_TO_INT32. The definition of
|
||||
* the ID is conveyed in some other way
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_DATA_TYPE_INVALID = 0,
|
||||
SPA_DATA_TYPE_MEMPTR,
|
||||
SPA_DATA_TYPE_MEMFD,
|
||||
SPA_DATA_TYPE_DMABUF,
|
||||
SPA_DATA_TYPE_ID,
|
||||
} SpaDataType;
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/ringbuffer.h>
|
||||
|
||||
/**
|
||||
* SpaBufferFlags:
|
||||
* @SPA_BUFFER_FLAG_NONE: no flag
|
||||
* @SPA_BUFFER_FLAG_DISCONT: the buffer marks a data discontinuity
|
||||
* @SPA_BUFFER_FLAG_CORRUPTED: the buffer data might be corrupted
|
||||
* @SPA_BUFFER_FLAG_MARKER: the buffer contains a media specific marker
|
||||
* @SPA_BUFFER_FLAG_HEADER: the buffer contains a header
|
||||
* @SPA_BUFFER_FLAG_GAP: the buffer has been constructed to fill a gap
|
||||
* and contains media neutral data
|
||||
* @SPA_BUFFER_FLAG_DELTA_UNIT: the media cannot be decoded independently
|
||||
*/
|
||||
typedef enum {
|
||||
SPA_BUFFER_FLAG_NONE = 0,
|
||||
SPA_BUFFER_FLAG_DISCONT = (1 << 0),
|
||||
SPA_BUFFER_FLAG_CORRUPTED = (1 << 1),
|
||||
SPA_BUFFER_FLAG_MARKER = (1 << 2),
|
||||
SPA_BUFFER_FLAG_HEADER = (1 << 3),
|
||||
SPA_BUFFER_FLAG_GAP = (1 << 4),
|
||||
SPA_BUFFER_FLAG_DELTA_UNIT = (1 << 5),
|
||||
} SpaBufferFlags;
|
||||
#define SPA_TYPE_DATA__MemPtr SPA_TYPE_DATA_BASE "MemPtr"
|
||||
#define SPA_TYPE_DATA__MemFd SPA_TYPE_DATA_BASE "MemFd"
|
||||
#define SPA_TYPE_DATA__DmaBuf SPA_TYPE_DATA_BASE "DmaBuf"
|
||||
#define SPA_TYPE_DATA__Id SPA_TYPE_DATA_BASE "Id"
|
||||
|
||||
typedef struct {
|
||||
SpaBufferFlags flags;
|
||||
uint32_t seq;
|
||||
int64_t pts;
|
||||
int64_t dts_offset;
|
||||
} SpaMetaHeader;
|
||||
uint32_t MemPtr;
|
||||
uint32_t MemFd;
|
||||
uint32_t DmaBuf;
|
||||
uint32_t Id;
|
||||
} SpaTypeData;
|
||||
|
||||
typedef struct {
|
||||
const char *ptr_type;
|
||||
void *ptr;
|
||||
} SpaMetaPointer;
|
||||
|
||||
/**
|
||||
* SpaMetaVideoCrop:
|
||||
* @x:
|
||||
* @y:
|
||||
* @width:
|
||||
* @height
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t x, y;
|
||||
int32_t width, height;
|
||||
} SpaMetaVideoCrop;
|
||||
|
||||
/**
|
||||
* SpaMetaRingbuffer:
|
||||
* @ringbuffer:
|
||||
*/
|
||||
typedef struct {
|
||||
SpaRingbuffer ringbuffer;
|
||||
} SpaMetaRingbuffer;
|
||||
|
||||
/**
|
||||
* SpaMetaShared:
|
||||
* @type:
|
||||
* @flags:
|
||||
* @fd:
|
||||
* @size:
|
||||
*/
|
||||
typedef struct {
|
||||
SpaDataType type;
|
||||
int32_t flags;
|
||||
int fd;
|
||||
int32_t offset;
|
||||
uint32_t size;
|
||||
} SpaMetaShared;
|
||||
|
||||
/**
|
||||
* SpaMeta:
|
||||
* @type: metadata type
|
||||
* @data: pointer to metadata
|
||||
* @size: size of metadata
|
||||
*/
|
||||
typedef struct {
|
||||
SpaMetaType type;
|
||||
void *data;
|
||||
uint32_t size;
|
||||
} SpaMeta;
|
||||
static inline void
|
||||
spa_type_data_map (SpaTypeMap *map, SpaTypeData *type)
|
||||
{
|
||||
if (type->MemPtr == 0) {
|
||||
type->MemPtr = spa_type_map_get_id (map, SPA_TYPE_DATA__MemPtr);
|
||||
type->MemFd = spa_type_map_get_id (map, SPA_TYPE_DATA__MemFd);
|
||||
type->DmaBuf = spa_type_map_get_id (map, SPA_TYPE_DATA__DmaBuf);
|
||||
type->Id = spa_type_map_get_id (map, SPA_TYPE_DATA__Id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SpaChunk:
|
||||
|
|
@ -164,13 +75,13 @@ typedef struct {
|
|||
* @type: memory type
|
||||
* @flags: memory flags
|
||||
* @fd: file descriptor
|
||||
* @offset: start offset when mapping @fd
|
||||
* @mapoffset: start offset when mapping @fd
|
||||
* @maxsize: maximum size of the memory
|
||||
* @data: pointer to memory
|
||||
* @chunk: pointer to chunk with valid offset
|
||||
*/
|
||||
typedef struct {
|
||||
SpaDataType type;
|
||||
uint32_t type;
|
||||
uint32_t flags;
|
||||
int fd;
|
||||
uint32_t mapoffset;
|
||||
|
|
@ -195,32 +106,16 @@ struct _SpaBuffer {
|
|||
SpaData *datas;
|
||||
};
|
||||
|
||||
|
||||
static inline void *
|
||||
spa_buffer_find_meta (SpaBuffer *b, SpaMetaType type)
|
||||
spa_buffer_find_meta (SpaBuffer *b, uint32_t type)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < b->n_metas; i++)
|
||||
if (b->metas[i].type == type)
|
||||
return b->metas[i].data;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
spa_meta_type_get_size (SpaMetaType type)
|
||||
{
|
||||
static const uint32_t header_sizes[] = {
|
||||
0,
|
||||
sizeof (SpaMetaHeader),
|
||||
sizeof (SpaMetaPointer),
|
||||
sizeof (SpaMetaVideoCrop),
|
||||
sizeof (SpaMetaRingbuffer),
|
||||
sizeof (SpaMetaShared),
|
||||
};
|
||||
if (type <= 0 || type >= SPA_N_ELEMENTS (header_sizes))
|
||||
return 0;
|
||||
return header_sizes[type];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
135
spa/include/spa/meta.h
Normal file
135
spa/include/spa/meta.h
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2017 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_META_H__
|
||||
#define __SPA_META_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/defs.h>
|
||||
#include <spa/ringbuffer.h>
|
||||
|
||||
#define SPA_TYPE__Meta SPA_TYPE_POINTER_BASE "Meta"
|
||||
#define SPA_TYPE_META_BASE SPA_TYPE__Meta ":"
|
||||
|
||||
#define SPA_TYPE_META__Header SPA_TYPE_META_BASE "Header"
|
||||
#define SPA_TYPE_META__Pointer SPA_TYPE_META_BASE "Pointer"
|
||||
#define SPA_TYPE_META__VideoCrop SPA_TYPE_META_BASE "VideoCrop"
|
||||
#define SPA_TYPE_META__Ringbuffer SPA_TYPE_META_BASE "Ringbuffer"
|
||||
#define SPA_TYPE_META__Shared SPA_TYPE_META_BASE "Shared"
|
||||
|
||||
typedef struct {
|
||||
uint32_t Header;
|
||||
uint32_t Pointer;
|
||||
uint32_t VideoCrop;
|
||||
uint32_t Ringbuffer;
|
||||
uint32_t Shared;
|
||||
} SpaTypeMeta;
|
||||
|
||||
static inline void
|
||||
spa_type_meta_map (SpaTypeMap *map, SpaTypeMeta *type)
|
||||
{
|
||||
if (type->Header == 0) {
|
||||
type->Header = spa_type_map_get_id (map, SPA_TYPE_META__Header);
|
||||
type->Pointer = spa_type_map_get_id (map, SPA_TYPE_META__Pointer);
|
||||
type->VideoCrop = spa_type_map_get_id (map, SPA_TYPE_META__VideoCrop);
|
||||
type->Ringbuffer = spa_type_map_get_id (map, SPA_TYPE_META__Ringbuffer);
|
||||
type->Shared = spa_type_map_get_id (map, SPA_TYPE_META__Shared);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SpaMetaHeader:
|
||||
* @flags: extra flags
|
||||
* @seq: sequence number. This monotonically increments and with the rate,
|
||||
* it can be used to derive a media time.
|
||||
* @pts: The MONOTONIC time for @seq.
|
||||
* @dts_offset: offset relative to @pts to start decoding this buffer.
|
||||
*/
|
||||
typedef struct {
|
||||
#define SPA_META_HEADER_FLAG_DISCONT (1 << 0) /* data is not continous with previous buffer */
|
||||
#define SPA_META_HEADER_FLAG_CORRUPTED (1 << 1) /* data might be corrupted */
|
||||
#define SPA_META_HEADER_FLAG_MARKER (1 << 2) /* media specific marker */
|
||||
#define SPA_META_HEADER_FLAG_HEADER (1 << 3) /* data contains a codec specific header */
|
||||
#define SPA_META_HEADER_FLAG_GAP (1 << 4) /* data contains media neutral data */
|
||||
#define SPA_META_HEADER_FLAG_DELTA_UNIT (1 << 5) /* cannot be decoded independently */
|
||||
uint32_t flags;
|
||||
uint32_t seq;
|
||||
int64_t pts;
|
||||
int64_t dts_offset;
|
||||
} SpaMetaHeader;
|
||||
|
||||
typedef struct {
|
||||
uint32_t type;
|
||||
void *ptr;
|
||||
} SpaMetaPointer;
|
||||
|
||||
/**
|
||||
* SpaMetaVideoCrop:
|
||||
* @x:
|
||||
* @y:
|
||||
* @width:
|
||||
* @height
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t x, y;
|
||||
int32_t width, height;
|
||||
} SpaMetaVideoCrop;
|
||||
|
||||
/**
|
||||
* SpaMetaRingbuffer:
|
||||
* @ringbuffer:
|
||||
*/
|
||||
typedef struct {
|
||||
SpaRingbuffer ringbuffer;
|
||||
} SpaMetaRingbuffer;
|
||||
|
||||
/**
|
||||
* SpaMetaShared:
|
||||
* @flags: flags
|
||||
* @fd: the fd of the memory
|
||||
* @offset: start offset of memory
|
||||
* @size: size of the memory
|
||||
*/
|
||||
typedef struct {
|
||||
int32_t flags;
|
||||
int fd;
|
||||
int32_t offset;
|
||||
uint32_t size;
|
||||
} SpaMetaShared;
|
||||
|
||||
/**
|
||||
* SpaMeta:
|
||||
* @type: metadata type
|
||||
* @data: pointer to metadata
|
||||
* @size: size of metadata
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t type;
|
||||
void *data;
|
||||
uint32_t size;
|
||||
} SpaMeta;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_META_H__ */
|
||||
|
|
@ -102,23 +102,17 @@ typedef enum {
|
|||
/**
|
||||
* SpaPortInfo
|
||||
* @flags: extra port flags
|
||||
* @rate: rate of sequence number increment per second of media data
|
||||
* @n_params: number of elements in @params;
|
||||
* @params: extra allocation parameters
|
||||
* @maxbuffering: the maximum amount of bytes that the element will keep
|
||||
* around internally
|
||||
* @latency: latency on this port in nanoseconds
|
||||
* @extra: a dictionary of extra port info
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
#define SPA_PORT_STATE_ERROR -1
|
||||
#define SPA_PORT_STATE_INIT 0
|
||||
#define SPA_PORT_STATE_CONFIGURE 1
|
||||
#define SPA_PORT_STATE_READY 2
|
||||
#define SPA_PORT_STATE_PAUSED 3
|
||||
#define SPA_PORT_STATE_STREAMING 4
|
||||
uint32_t state;
|
||||
SpaPortInfoFlags flags;
|
||||
uint32_t rate;
|
||||
uint32_t n_params;
|
||||
SpaAllocParam **params;
|
||||
uint64_t maxbuffering;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ typedef uint32_t SpaType;
|
|||
#define SPA_TYPE__Enum SPA_TYPE_BASE "Enum"
|
||||
#define SPA_TYPE_ENUM_BASE SPA_TYPE__Enum ":"
|
||||
|
||||
#define SPA_TYPE__Pointer SPA_TYPE_BASE "Pointer"
|
||||
#define SPA_TYPE_POINTER_BASE SPA_TYPE__Pointer ":"
|
||||
|
||||
#define SPA_TYPE__Interface SPA_TYPE_BASE "Interface"
|
||||
#define SPA_TYPE_INTERFACE_BASE SPA_TYPE__Interface ":"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue