Remove dynamic types

Do not use dynamic types anymore. The reason is that it's difficult:

- to maintain a shared type database over a network.
- the extra overhead when translating between processes and for
  maintaining the translation tables.
- race conditions in translating in RT-threads, this is a problem
  because we want to make event streams.

We now have simple enums with types and extension points for all
types. This is also nicer to use in general.
We don't need the mapper anymore or pass strings around as types.
There is a parallel type info system to get more info about ids and
enums and their hierarchy. It can also be used for debugging.
This commit is contained in:
Wim Taymans 2018-08-23 17:47:57 +02:00
parent e6977fa178
commit fca3e1d85d
162 changed files with 5200 additions and 7461 deletions

View file

@ -23,8 +23,6 @@
#include <math.h>
#include <sys/mman.h>
#include <spa/support/type-map.h>
#include <spa/param/format-utils.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/props.h>
@ -36,28 +34,10 @@
#define DEFAULT_CHANNELS 2
#define DEFAULT_VOLUME 0.7
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
}
struct data {
struct type type;
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote;
struct pw_stream *stream;
@ -131,17 +111,15 @@ int main(int argc, char *argv[])
&data);
data.remote = pw_stream_get_remote(data.stream);
data.t = pw_core_get_type(pw_remote_get_core(data.remote));
init_type(&data.type, data.t->map);
params[0] = spa_pod_builder_object(&b,
data.t->param.idEnumFormat, data.t->spa_format,
"I", data.type.media_type.audio,
"I", data.type.media_subtype.raw,
":", data.type.format_audio.format, "I", data.type.audio_format.F32,
":", data.type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED,
":", data.type.format_audio.channels, "i", DEFAULT_CHANNELS,
":", data.type.format_audio.rate, "i", DEFAULT_RATE);
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED,
":", SPA_FORMAT_AUDIO_channels, "i", DEFAULT_CHANNELS,
":", SPA_FORMAT_AUDIO_rate, "i", DEFAULT_RATE);
pw_stream_connect(data.stream,
PW_DIRECTION_OUTPUT,

View file

@ -21,10 +21,6 @@
#include <stdio.h>
#include <sys/mman.h>
#include <SDL2/SDL.h>
#include <spa/support/type-map.h>
#include <spa/param/format-utils.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/props.h>
#include <spa/node/io.h>
@ -34,29 +30,16 @@
#include <pipewire/module.h>
#include <pipewire/factory.h>
#define WIDTH 640
#define HEIGHT 480
#define BPP 3
#include "sdl.h"
#define M_PI_M2 ( M_PI + M_PI )
#define MAX_BUFFERS 16
struct type {
uint32_t prop_param;
uint32_t io_prop_param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_video_format video_format;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->prop_param = spa_type_map_get_id(map, SPA_TYPE_PROPS__contrast);
type->io_prop_param = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "contrast");
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video);
spa_type_video_format_map(map, &type->video_format);
}
#define DEFAULT_PARAM 0.1
struct props {
@ -68,12 +51,7 @@ static void reset_props(struct props *props)
props->param = DEFAULT_PARAM;
}
#define WIDTH 640
#define HEIGHT 480
#define BPP 3
struct data {
struct type type;
struct props props;
const char *path;
@ -85,7 +63,6 @@ struct data {
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote;
struct spa_hook remote_listener;
@ -124,76 +101,6 @@ static void handle_events(struct data *data)
}
}
static struct {
Uint32 format;
uint32_t id;
} video_formats[] = {
{ SDL_PIXELFORMAT_UNKNOWN, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_UNKNOWN, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1MSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX4LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX4MSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX8, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB332, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGR555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ARGB4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ABGR4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGRA4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ARGB1555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA5551, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ABGR1555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGRA5551, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB565, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGR565, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB24, offsetof(struct spa_type_video_format, RGB),},
{ SDL_PIXELFORMAT_RGB888, offsetof(struct spa_type_video_format, RGB),},
{ SDL_PIXELFORMAT_RGBX8888, offsetof(struct spa_type_video_format, RGBx),},
{ SDL_PIXELFORMAT_BGR24, offsetof(struct spa_type_video_format, BGR),},
{ SDL_PIXELFORMAT_BGR888, offsetof(struct spa_type_video_format, BGR),},
{ SDL_PIXELFORMAT_BGRX8888, offsetof(struct spa_type_video_format, BGRx),},
{ SDL_PIXELFORMAT_ARGB2101010, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA8888, offsetof(struct spa_type_video_format, RGBA),},
{ SDL_PIXELFORMAT_ARGB8888, offsetof(struct spa_type_video_format, ARGB),},
{ SDL_PIXELFORMAT_BGRA8888, offsetof(struct spa_type_video_format, BGRA),},
{ SDL_PIXELFORMAT_ABGR8888, offsetof(struct spa_type_video_format, ABGR),},
{ SDL_PIXELFORMAT_YV12, offsetof(struct spa_type_video_format, YV12),},
{ SDL_PIXELFORMAT_IYUV, offsetof(struct spa_type_video_format, I420),},
{ SDL_PIXELFORMAT_YUY2, offsetof(struct spa_type_video_format, YUY2),},
{ SDL_PIXELFORMAT_UYVY, offsetof(struct spa_type_video_format, UYVY),},
{ SDL_PIXELFORMAT_YVYU, offsetof(struct spa_type_video_format, YVYU),},
#if SDL_VERSION_ATLEAST(2,0,4)
{ SDL_PIXELFORMAT_NV12, offsetof(struct spa_type_video_format, NV12),},
{ SDL_PIXELFORMAT_NV21, offsetof(struct spa_type_video_format, NV21),},
#endif
};
static uint32_t sdl_format_to_id(struct data *data, Uint32 format)
{
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
if (video_formats[i].format == format)
return *SPA_MEMBER(&data->type.video_format, video_formats[i].id, uint32_t);
}
return data->type.video_format.UNKNOWN;
}
static Uint32 id_to_sdl_format(struct data *data, uint32_t id)
{
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
if (*SPA_MEMBER(&data->type.video_format, video_formats[i].id, uint32_t) == id)
return video_formats[i].format;
}
return SDL_PIXELFORMAT_UNKNOWN;
}
static void update_param(struct data *data)
{
if (data->ctrl_param == NULL)
@ -247,14 +154,16 @@ static int impl_port_set_io(struct spa_node *node,
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
if (id == d->t->io.Buffers)
if (id == SPA_ID_IO_Buffers)
d->io = data;
#if 0
else if (id == d->type.io_prop_param) {
if (data && size >= sizeof(struct spa_pod_double))
d->ctrl_param = data;
else
d->ctrl_param = NULL;
}
#endif
else
return -ENOENT;
@ -284,47 +193,12 @@ static int port_enum_formats(struct spa_node *node,
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
SDL_RendererInfo info;
uint32_t i, c;
if (*index != 0)
return 0;
SDL_GetRendererInfo(d->renderer, &info);
spa_pod_builder_push_object(builder,
d->t->param.idEnumFormat, d->t->spa_format);
spa_pod_builder_id(builder, d->type.media_type.video);
spa_pod_builder_id(builder, d->type.media_subtype.raw);
spa_pod_builder_push_prop(builder, d->type.format_video.format,
SPA_POD_PROP_FLAG_UNSET |
SPA_POD_PROP_RANGE_ENUM);
for (i = 0, c = 0; i < info.num_texture_formats; i++) {
uint32_t id = sdl_format_to_id(d, info.texture_formats[i]);
if (id == 0)
continue;
if (c++ == 0)
spa_pod_builder_id(builder, id);
spa_pod_builder_id(builder, id);
}
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
uint32_t id =
*SPA_MEMBER(&d->type.video_format, video_formats[i].id,
uint32_t);
if (id != d->type.video_format.UNKNOWN)
spa_pod_builder_id(builder, id);
}
spa_pod_builder_pop(builder);
spa_pod_builder_add(builder,
":", d->type.format_video.size, "Rru", &SPA_RECTANGLE(WIDTH, HEIGHT),
SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1,1),
&SPA_RECTANGLE(info.max_texture_width,
info.max_texture_height)),
":", d->type.format_video.framerate, "Fru", &SPA_FRACTION(25,1),
SPA_POD_PROP_MIN_MAX(&SPA_FRACTION(0,1),
&SPA_FRACTION(30,1)),
NULL);
*result = spa_pod_builder_pop(builder);
*result = sdl_build_formats(&info, builder);
(*index)++;
@ -344,12 +218,12 @@ static int port_get_format(struct spa_node *node,
return 0;
*result = spa_pod_builder_object(builder,
d->t->param.idFormat, d->t->spa_format,
"I", d->type.media_type.video,
"I", d->type.media_subtype.raw,
":", d->type.format_video.format, "I", d->format.format,
":", d->type.format_video.size, "R", &d->format.size,
":", d->type.format_video.framerate, "F", &d->format.framerate);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_video,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_VIDEO_format, "I", d->format.format,
":", SPA_FORMAT_VIDEO_size, "R", &d->format.size,
":", SPA_FORMAT_VIDEO_framerate, "F", &d->format.framerate);
(*index)++;
@ -364,59 +238,64 @@ static int impl_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct pw_type *t = d->t;
struct spa_pod *param;
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idPropsOut };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(builder,
id, t->param.List,
":", t->param.listId, "I", list[*index]);
id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
break;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
return port_enum_formats(node, direction, port_id, index, filter, result, builder);
}
else if (id == t->param.idFormat) {
case SPA_ID_PARAM_Format:
return port_get_format(node, direction, port_id, index, filter, result, builder);
}
else if (id == t->param.idBuffers) {
case SPA_ID_PARAM_Buffers:
if (*index != 0)
return 0;
param = spa_pod_builder_object(builder,
id, t->param_buffers.Buffers,
":", t->param_buffers.size, "i", d->stride * d->format.size.height,
":", t->param_buffers.stride, "i", d->stride,
":", t->param_buffers.buffers, "iru", 2,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 2,
SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS),
":", t->param_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
":", SPA_PARAM_BUFFERS_size, "i", d->stride * d->format.size.height,
":", SPA_PARAM_BUFFERS_stride, "i", d->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
case SPA_ID_PARAM_Meta:
switch (*index) {
case 0:
param = spa_pod_builder_object(builder,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
case 1:
param = spa_pod_builder_object(builder,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.VideoDamage,
":", t->param_meta.size, "i", sizeof(struct spa_meta_region));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_VideoDamage,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_region));
break;
default:
return 0;
}
}
break;
#if 0
else if (id == t->param_io.idPropsOut) {
struct props *p = &d->props;
@ -434,8 +313,10 @@ static int impl_port_enum_params(struct spa_node *node,
return 0;
}
}
else
#endif
default:
return -ENOENT;
}
(*index)++;
@ -455,11 +336,11 @@ static int port_set_format(struct spa_node *node,
if (format == NULL)
return 0;
spa_debug_format(0, d->t->map, format);
spa_debug_format(0, NULL, format);
spa_format_video_raw_parse(format, &d->format, &d->type.format_video);
spa_format_video_raw_parse(format, &d->format);
sdl_format = id_to_sdl_format(d, d->format.format);
sdl_format = id_to_sdl_format(d->format.format);
if (sdl_format == SDL_PIXELFORMAT_UNKNOWN)
return -EINVAL;
@ -479,10 +360,7 @@ static int impl_port_set_param(struct spa_node *node,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct pw_type *t = d->t;
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
}
else
@ -505,7 +383,6 @@ static int do_render(struct spa_loop *loop, bool async, uint32_t seq,
const void *_data, size_t size, void *user_data)
{
struct data *d = user_data;
struct pw_type *t = d->t;
const struct spa_buffer *buf = *(struct spa_buffer**)_data;
uint8_t *map;
void *sdata, *ddata;
@ -517,12 +394,12 @@ static int do_render(struct spa_loop *loop, bool async, uint32_t seq,
handle_events(d);
if (buf->datas[0].type == d->t->data.MemFd ||
buf->datas[0].type == d->t->data.DmaBuf) {
if (buf->datas[0].type == SPA_DATA_MemFd ||
buf->datas[0].type == SPA_DATA_DmaBuf) {
map = mmap(NULL, buf->datas[0].maxsize + buf->datas[0].mapoffset, PROT_READ,
MAP_PRIVATE, buf->datas[0].fd, 0);
sdata = SPA_MEMBER(map, buf->datas[0].mapoffset, uint8_t);
} else if (buf->datas[0].type == d->t->data.MemPtr) {
} else if (buf->datas[0].type == SPA_DATA_MemPtr) {
map = NULL;
sdata = buf->datas[0].data;
} else
@ -533,7 +410,7 @@ static int do_render(struct spa_loop *loop, bool async, uint32_t seq,
return -EIO;
}
if ((m = spa_buffer_find_meta(buf, t->meta.VideoDamage))) {
if ((m = spa_buffer_find_meta(buf, SPA_META_VideoDamage))) {
spa_meta_region_for_each(r, m) {
if (!spa_meta_region_is_valid(r))
break;
@ -676,11 +553,9 @@ int main(int argc, char *argv[])
data.loop = pw_main_loop_new(NULL);
data.core = pw_core_new(pw_main_loop_get_loop(data.loop), NULL);
data.t = pw_core_get_type(data.core);
data.remote = pw_remote_new(data.core, NULL, 0);
data.path = argc > 1 ? argv[1] : NULL;
init_type(&data.type, data.t->map);
reset_props(&data.props);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {

View file

@ -22,8 +22,6 @@
#include <math.h>
#include <sys/mman.h>
#include <spa/support/type-map.h>
#include <spa/param/format-utils.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/props.h>
#include <spa/node/io.h>
@ -35,25 +33,6 @@
#define BUFFER_SAMPLES 128
struct type {
uint32_t prop_volume;
uint32_t io_prop_volume;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume");
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
}
#define DEFAULT_VOLUME 1.0
struct props {
@ -73,8 +52,6 @@ struct buffer {
};
struct data {
struct type type;
struct props props;
const char *path;
@ -82,7 +59,6 @@ struct data {
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote;
struct spa_hook remote_listener;
@ -161,14 +137,16 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction,
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
if (id == d->t->io.Buffers)
if (id == SPA_ID_IO_Buffers)
d->io = data;
else if (id == d->type.io_prop_volume) {
#if 0
else if (id == type.io_prop_volume) {
if (data && size >= sizeof(struct spa_pod_double))
d->ctrl_volume = data;
else
d->ctrl_volume = NULL;
}
#endif
else
return -ENOENT;
@ -199,24 +177,22 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
if (*index != 0)
return 0;
*param = spa_pod_builder_object(builder,
d->t->param.idEnumFormat, d->t->spa_format,
"I", d->type.media_type.audio,
"I", d->type.media_subtype.raw,
":", d->type.format_audio.format, "Ieu", d->type.audio_format.S16,
SPA_POD_PROP_ENUM(2, d->type.audio_format.S16,
d->type.audio_format.F32),
":", d->type.format_audio.layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "Ieu", SPA_AUDIO_FORMAT_S16,
SPA_POD_PROP_ENUM(2, SPA_AUDIO_FORMAT_S16,
SPA_AUDIO_FORMAT_F32),
":", SPA_FORMAT_AUDIO_layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED,
SPA_AUDIO_LAYOUT_NON_INTERLEAVED),
":", d->type.format_audio.channels, "iru", 2,
":", SPA_FORMAT_AUDIO_channels, "iru", 2,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", d->type.format_audio.rate, "iru", 44100,
":", SPA_FORMAT_AUDIO_rate, "iru", 44100,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
(*index)++;
@ -240,13 +216,13 @@ static int port_get_format(struct spa_node *node,
return 0;
*param = spa_pod_builder_object(builder,
d->t->param.idFormat, d->t->spa_format,
"I", d->type.media_type.audio,
"I", d->type.media_subtype.raw,
":", d->type.format_audio.format, "I", d->format.format,
":", d->type.format_audio.layout, "i", d->format.layout,
":", d->type.format_audio.channels, "i", d->format.channels,
":", d->type.format_audio.rate, "i", d->format.rate);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", d->format.format,
":", SPA_FORMAT_AUDIO_layout, "i", d->format.layout,
":", SPA_FORMAT_AUDIO_channels, "i", d->format.channels,
":", SPA_FORMAT_AUDIO_rate, "i", d->format.rate);
(*index)++;
@ -260,68 +236,70 @@ static int impl_port_enum_params(struct spa_node *node,
struct spa_pod **result,
struct spa_pod_builder *builder)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct pw_type *t = d->t;
struct spa_pod *param;
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idBuffers,
t->param_io.idPropsOut };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(builder,
id, t->param.List,
":", t->param.listId, "I", list[*index]);
id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
break;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
return port_enum_formats(node, direction, port_id, index, filter, result, builder);
}
else if (id == t->param.idFormat) {
case SPA_ID_PARAM_Format:
return port_get_format(node, direction, port_id, index, filter, result, builder);
}
else if (id == t->param.idBuffers) {
case SPA_ID_PARAM_Buffers:
if (*index > 0)
return 0;
param = spa_pod_builder_object(builder,
id, t->param_buffers.Buffers,
":", t->param_buffers.size, "iru", BUFFER_SAMPLES * sizeof(float),
SPA_POD_PROP_MIN_MAX(32, 4096),
":", t->param_buffers.stride, "i", 0,
":", t->param_buffers.buffers, "iru", 1,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 1,
SPA_POD_PROP_MIN_MAX(1, 32),
":", t->param_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
":", SPA_PARAM_BUFFERS_size, "iru", BUFFER_SAMPLES * sizeof(float),
SPA_POD_PROP_MIN_MAX(32, 4096),
":", SPA_PARAM_BUFFERS_stride, "i", 0,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
case SPA_ID_PARAM_Meta:
switch (*index) {
case 0:
param = spa_pod_builder_object(builder,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return 0;
}
}
else if (id == t->param_io.idBuffers) {
break;
case SPA_ID_PARAM_IO:
switch (*index) {
case 0:
param = spa_pod_builder_object(builder,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
break;
#if 0
else if (id == t->param_io.idPropsOut) {
struct props *p = &d->props;
@ -339,8 +317,10 @@ static int impl_port_enum_params(struct spa_node *node,
return 0;
}
}
else
#endif
default:
return -ENOENT;
}
(*index)++;
*result = param;
@ -359,13 +339,13 @@ static int port_set_format(struct spa_node *node,
return 0;
}
spa_debug_format(0, d->t->map, format);
spa_debug_format(0, NULL, format);
if (spa_format_audio_raw_parse(format, &d->format, &d->type.format_audio) < 0)
if (spa_format_audio_raw_parse(format, &d->format) < 0)
return -EINVAL;
if (d->format.format != d->type.audio_format.S16 &&
d->format.format != d->type.audio_format.F32)
if (d->format.format != SPA_AUDIO_FORMAT_S16 &&
d->format.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
return 0;
@ -376,10 +356,7 @@ static int impl_port_set_param(struct spa_node *node,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct pw_type *t = d->t;
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
}
else
@ -399,8 +376,8 @@ static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direc
b->ptr = datas[0].data;
b->mapped = false;
}
else if (datas[0].type == d->t->data.MemFd ||
datas[0].type == d->t->data.DmaBuf) {
else if (datas[0].type == SPA_DATA_MemFd ||
datas[0].type == SPA_DATA_DmaBuf) {
b->ptr = mmap(NULL, datas[0].maxsize + datas[0].mapoffset, PROT_WRITE,
MAP_SHARED, datas[0].fd, 0);
if (b->ptr == MAP_FAILED) {
@ -509,9 +486,9 @@ static int impl_node_process(struct spa_node *node)
if (offset + avail > maxsize)
avail = maxsize - offset;
if (d->format.format == d->type.audio_format.S16)
if (d->format.format == SPA_AUDIO_FORMAT_S16)
fill_s16(d, SPA_MEMBER(b->ptr, offset, void), avail);
else if (d->format.format == d->type.audio_format.F32)
else if (d->format.format == SPA_AUDIO_FORMAT_F32)
fill_f32(d, SPA_MEMBER(b->ptr, offset, void), avail);
od[0].chunk->offset = 0;
@ -595,12 +572,10 @@ int main(int argc, char *argv[])
data.loop = pw_main_loop_new(NULL);
data.core = pw_core_new(pw_main_loop_get_loop(data.loop), NULL);
data.t = pw_core_get_type(data.core);
data.remote = pw_remote_new(data.core, NULL, 0);
data.path = argc > 1 ? argv[1] : NULL;
spa_list_init(&data.empty);
init_type(&data.type, data.t->map);
reset_props(&data.props);
pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);

View file

@ -21,8 +21,6 @@
#include <sys/mman.h>
#include <signal.h>
#include <spa/support/type-map.h>
#include <spa/param/format-utils.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/props.h>
@ -33,7 +31,6 @@ struct data {
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote;
struct spa_hook remote_listener;
@ -47,7 +44,6 @@ struct data {
static int make_node(struct data *data)
{
struct pw_factory *factory;
struct pw_type *t = data->t;
struct pw_properties *props;
factory = pw_core_find_factory(data->core, "spa-node-factory");
@ -64,7 +60,7 @@ static int make_node(struct data *data)
data->node = pw_factory_create_object(factory,
NULL,
t->node,
PW_ID_INTERFACE_Node,
PW_VERSION_NODE,
props, SPA_ID_INVALID);
@ -129,7 +125,6 @@ int main(int argc, char *argv[])
pw_loop_add_signal(l, SIGINT, do_quit, &data);
pw_loop_add_signal(l, SIGTERM, do_quit, &data);
data.core = pw_core_new(l, NULL);
data.t = pw_core_get_type(data.core);
data.remote = pw_remote_new(data.core, NULL, 0);
data.library = argv[1];
data.factory = argv[2];

View file

@ -22,8 +22,6 @@
#include <SDL2/SDL.h>
#include <spa/support/type-map.h>
#include <spa/param/format-utils.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/props.h>
#include <spa/node/io.h>
@ -33,28 +31,11 @@
#include <pipewire/module.h>
#include <pipewire/factory.h>
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_video_format video_format;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video);
spa_type_video_format_map(map, &type->video_format);
}
#define WIDTH 640
#define HEIGHT 480
#define BPP 3
struct data {
struct type type;
SDL_Renderer *renderer;
SDL_Window *window;
SDL_Texture *texture;
@ -63,7 +44,6 @@ struct data {
struct spa_source *timer;
struct pw_core *core;
struct pw_type *t;
struct pw_node *node;
struct spa_port_info port_info;
@ -100,47 +80,47 @@ static struct {
Uint32 format;
uint32_t id;
} video_formats[] = {
{ SDL_PIXELFORMAT_UNKNOWN, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_UNKNOWN, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1MSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX4LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX4MSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX8, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB332, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGR555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ARGB4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ABGR4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGRA4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ARGB1555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA5551, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ABGR1555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGRA5551, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB565, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGR565, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB24, offsetof(struct spa_type_video_format, RGB),},
{ SDL_PIXELFORMAT_RGB888, offsetof(struct spa_type_video_format, RGB),},
{ SDL_PIXELFORMAT_RGBX8888, offsetof(struct spa_type_video_format, RGBx),},
{ SDL_PIXELFORMAT_BGR24, offsetof(struct spa_type_video_format, BGR),},
{ SDL_PIXELFORMAT_BGR888, offsetof(struct spa_type_video_format, BGR),},
{ SDL_PIXELFORMAT_BGRX8888, offsetof(struct spa_type_video_format, BGRx),},
{ SDL_PIXELFORMAT_ARGB2101010, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA8888, offsetof(struct spa_type_video_format, RGBA),},
{ SDL_PIXELFORMAT_ARGB8888, offsetof(struct spa_type_video_format, ARGB),},
{ SDL_PIXELFORMAT_BGRA8888, offsetof(struct spa_type_video_format, BGRA),},
{ SDL_PIXELFORMAT_ABGR8888, offsetof(struct spa_type_video_format, ABGR),},
{ SDL_PIXELFORMAT_YV12, offsetof(struct spa_type_video_format, YV12),},
{ SDL_PIXELFORMAT_IYUV, offsetof(struct spa_type_video_format, I420),},
{ SDL_PIXELFORMAT_YUY2, offsetof(struct spa_type_video_format, YUY2),},
{ SDL_PIXELFORMAT_UYVY, offsetof(struct spa_type_video_format, UYVY),},
{ SDL_PIXELFORMAT_YVYU, offsetof(struct spa_type_video_format, YVYU),},
{ SDL_PIXELFORMAT_UNKNOWN, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_INDEX1LSB, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_UNKNOWN, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_INDEX1LSB, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_INDEX1MSB, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_INDEX4LSB, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_INDEX4MSB, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_INDEX8, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGB332, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGB444, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGB555, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_BGR555, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_ARGB4444, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGBA4444, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_ABGR4444, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_BGRA4444, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_ARGB1555, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGBA5551, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_ABGR1555, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_BGRA5551, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGB565, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_BGR565, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGB24, SPA_VIDEO_FORMAT_RGB,},
{ SDL_PIXELFORMAT_RGB888, SPA_VIDEO_FORMAT_RGB,},
{ SDL_PIXELFORMAT_RGBX8888, SPA_VIDEO_FORMAT_RGBx,},
{ SDL_PIXELFORMAT_BGR24, SPA_VIDEO_FORMAT_BGR,},
{ SDL_PIXELFORMAT_BGR888, SPA_VIDEO_FORMAT_BGR,},
{ SDL_PIXELFORMAT_BGRX8888, SPA_VIDEO_FORMAT_BGRx,},
{ SDL_PIXELFORMAT_ARGB2101010, SPA_VIDEO_FORMAT_UNKNOWN,},
{ SDL_PIXELFORMAT_RGBA8888, SPA_VIDEO_FORMAT_RGBA,},
{ SDL_PIXELFORMAT_ARGB8888, SPA_VIDEO_FORMAT_ARGB,},
{ SDL_PIXELFORMAT_BGRA8888, SPA_VIDEO_FORMAT_BGRA,},
{ SDL_PIXELFORMAT_ABGR8888, SPA_VIDEO_FORMAT_ABGR,},
{ SDL_PIXELFORMAT_YV12, SPA_VIDEO_FORMAT_YV12,},
{ SDL_PIXELFORMAT_IYUV, SPA_VIDEO_FORMAT_I420,},
{ SDL_PIXELFORMAT_YUY2, SPA_VIDEO_FORMAT_YUY2,},
{ SDL_PIXELFORMAT_UYVY, SPA_VIDEO_FORMAT_UYVY,},
{ SDL_PIXELFORMAT_YVYU, SPA_VIDEO_FORMAT_YVYU,},
#if SDL_VERSION_ATLEAST(2,0,4)
{ SDL_PIXELFORMAT_NV12, offsetof(struct spa_type_video_format, NV12),},
{ SDL_PIXELFORMAT_NV21, offsetof(struct spa_type_video_format, NV21),},
{ SDL_PIXELFORMAT_NV12, SPA_VIDEO_FORMAT_NV12,},
{ SDL_PIXELFORMAT_NV21, SPA_VIDEO_FORMAT_NV21,},
#endif
};
@ -150,9 +130,9 @@ static uint32_t sdl_format_to_id(struct data *data, Uint32 format)
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
if (video_formats[i].format == format)
return *SPA_MEMBER(&data->type.video_format, video_formats[i].id, uint32_t);
return video_formats[i].id;
}
return data->type.video_format.UNKNOWN;
return SPA_VIDEO_FORMAT_UNKNOWN;
}
static Uint32 id_to_sdl_format(struct data *data, uint32_t id)
@ -160,7 +140,7 @@ static Uint32 id_to_sdl_format(struct data *data, uint32_t id)
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
if (*SPA_MEMBER(&data->type.video_format, video_formats[i].id, uint32_t) == id)
if (video_formats[i].id == id)
return video_formats[i].format;
}
return SDL_PIXELFORMAT_UNKNOWN;
@ -207,7 +187,7 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction,
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
if (id == d->t->io.Buffers)
if (id == SPA_ID_IO_Buffers)
d->io = data;
else
return -ENOENT;
@ -245,12 +225,11 @@ static int port_enum_formats(struct spa_node *node,
SDL_GetRendererInfo(d->renderer, &info);
spa_pod_builder_push_object(builder,
d->t->param.idEnumFormat, d->t->spa_format);
spa_pod_builder_id(builder, d->type.media_type.video);
spa_pod_builder_id(builder, d->type.media_subtype.raw);
spa_pod_builder_push_object(builder, SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format);
spa_pod_builder_id(builder, SPA_MEDIA_TYPE_video);
spa_pod_builder_id(builder, SPA_MEDIA_SUBTYPE_raw);
spa_pod_builder_push_prop(builder, d->type.format_video.format,
spa_pod_builder_push_prop(builder, SPA_FORMAT_VIDEO_format,
SPA_POD_PROP_FLAG_UNSET |
SPA_POD_PROP_RANGE_ENUM);
for (i = 0, c = 0; i < info.num_texture_formats; i++) {
@ -262,20 +241,18 @@ static int port_enum_formats(struct spa_node *node,
spa_pod_builder_id(builder, id);
}
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
uint32_t id =
*SPA_MEMBER(&d->type.video_format, video_formats[i].id,
uint32_t);
if (id != d->type.video_format.UNKNOWN)
uint32_t id = video_formats[i].id;
if (id != SPA_VIDEO_FORMAT_UNKNOWN)
spa_pod_builder_id(builder, id);
}
spa_pod_builder_pop(builder);
spa_pod_builder_add(builder,
":", d->type.format_video.size, "Rru", &SPA_RECTANGLE(WIDTH, HEIGHT),
":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(WIDTH, HEIGHT),
SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1,1),
&SPA_RECTANGLE(info.max_texture_width,
info.max_texture_height)),
":", d->type.format_video.framerate, "Fru", &SPA_FRACTION(25,1),
":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1),
SPA_POD_PROP_MIN_MAX(&SPA_FRACTION(0,1),
&SPA_FRACTION(30,1)),
NULL);
@ -294,34 +271,38 @@ static int impl_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct pw_type *t = d->t;
if (id == t->param.idEnumFormat) {
switch (id) {
case SPA_ID_PARAM_EnumFormat:
return port_enum_formats(node, direction, port_id, index, filter, result, builder);
}
else if (id == t->param.idBuffers) {
case SPA_ID_PARAM_Buffers:
if (*index > 0)
return 0;
*result = spa_pod_builder_object(builder,
id, t->param_buffers.Buffers,
":", t->param_buffers.size, "i", d->stride * d->format.size.height,
":", t->param_buffers.stride, "i", d->stride,
":", t->param_buffers.buffers, "iru", 2,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 2,
SPA_POD_PROP_MIN_MAX(1, 32),
":", t->param_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
":", SPA_PARAM_BUFFERS_size, "i", d->stride * d->format.size.height,
":", SPA_PARAM_BUFFERS_stride, "i", d->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
case SPA_ID_PARAM_Meta:
if (*index > 0)
return 0;
*result = spa_pod_builder_object(builder,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
}
else
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return -ENOENT;
}
(*index)++;
return 1;
@ -337,19 +318,19 @@ static int port_set_format(struct spa_node *node, enum spa_direction direction,
if (format == NULL)
return 0;
spa_debug_format(0, d->t->map, format);
spa_debug_format(0, NULL, format);
spa_format_video_raw_parse(format, &d->format, &d->type.format_video);
spa_format_video_raw_parse(format, &d->format);
sdl_format = id_to_sdl_format(d, d->format.format);
if (sdl_format == SDL_PIXELFORMAT_UNKNOWN)
return -EINVAL;
d->texture = SDL_CreateTexture(d->renderer,
sdl_format,
SDL_TEXTUREACCESS_STREAMING,
d->format.size.width,
d->format.size.height);
sdl_format,
SDL_TEXTUREACCESS_STREAMING,
d->format.size.width,
d->format.size.height);
SDL_LockTexture(d->texture, NULL, &dest, &d->stride);
SDL_UnlockTexture(d->texture);
@ -361,10 +342,7 @@ static int impl_port_set_param(struct spa_node *node,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct pw_type *t = d->t;
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
}
else
@ -396,12 +374,12 @@ static int do_render(struct spa_loop *loop, bool async, uint32_t seq,
buf = d->buffers[d->io->buffer_id];
if (buf->datas[0].type == d->t->data.MemFd ||
buf->datas[0].type == d->t->data.DmaBuf) {
if (buf->datas[0].type == SPA_DATA_MemFd ||
buf->datas[0].type == SPA_DATA_DmaBuf) {
map = mmap(NULL, buf->datas[0].maxsize + buf->datas[0].mapoffset, PROT_READ,
MAP_PRIVATE, buf->datas[0].fd, 0);
sdata = SPA_MEMBER(map, buf->datas[0].mapoffset, uint8_t);
} else if (buf->datas[0].type == d->t->data.MemPtr) {
} else if (buf->datas[0].type == SPA_DATA_MemPtr) {
map = NULL;
sdata = buf->datas[0].data;
} else
@ -480,7 +458,7 @@ static void make_nodes(struct data *data)
"spa.factory.name", "v4l2-source", NULL);
data->v4l2 = pw_factory_create_object(factory,
NULL,
data->t->node,
PW_ID_INTERFACE_Node,
PW_VERSION_NODE,
props,
SPA_ID_INVALID);
@ -505,12 +483,9 @@ int main(int argc, char *argv[])
data.loop = pw_main_loop_new(NULL);
data.core = pw_core_new(pw_main_loop_get_loop(data.loop), NULL);
data.t = pw_core_get_type(data.core);
pw_module_load(data.core, "libpipewire-module-spa-node-factory", NULL, NULL, NULL, NULL);
init_type(&data.type, data.t->map);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("can't initialize SDL: %s\n", SDL_GetError());
return -1;

View file

@ -43,31 +43,11 @@
#define MIN_QUANTUM_SIZE 64
#define MAX_QUANTUM_SIZE 1024
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_media_subtype_audio media_subtype_audio;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_media_subtype_audio_map(map, &type->media_subtype_audio);
}
struct impl {
struct type type;
struct timespec now;
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote;
struct spa_hook remote_listener;
@ -289,14 +269,13 @@ registry_global(void *data,uint32_t id, uint32_t parent_id,
const struct spa_dict *props)
{
struct impl *impl = data;
struct pw_type *t = impl->t;
clock_gettime(CLOCK_MONOTONIC, &impl->now);
if (type == t->node) {
if (type == PW_ID_INTERFACE_Node) {
handle_node(impl, id, parent_id, type, props);
}
else if (type == t->port) {
else if (type == PW_ID_INTERFACE_Port) {
handle_port(impl, id, parent_id, type, props);
}
schedule_rescan(impl);
@ -316,7 +295,6 @@ static const struct pw_registry_proxy_events registry_events = {
static void rescan_session(struct impl *impl)
{
struct session *sess;
struct pw_type *t = impl->t;
pw_log_debug("rescan session");
@ -335,7 +313,7 @@ static void rescan_session(struct impl *impl)
sess->dsp = pw_core_proxy_create_object(impl->core_proxy,
"audio-dsp",
t->node,
PW_ID_INTERFACE_Node,
PW_VERSION_NODE,
&props->dict,
0);
@ -356,7 +334,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remo
case PW_REMOTE_STATE_CONNECTED:
impl->core_proxy = pw_remote_get_core_proxy(impl->remote);
impl->registry_proxy = pw_core_proxy_get_registry(impl->core_proxy,
impl->t->registry,
PW_ID_INTERFACE_Registry,
PW_VERSION_REGISTRY, 0);
pw_registry_proxy_add_listener(impl->registry_proxy,
&impl->registry_listener,
@ -395,10 +373,8 @@ int main(int argc, char *argv[])
impl.loop = pw_main_loop_new(NULL);
impl.core = pw_core_new(pw_main_loop_get_loop(impl.loop), NULL);
impl.t = pw_core_get_type(impl.core);
impl.remote = pw_remote_new(impl.core, NULL, 0);
init_type(&impl.type, impl.t->map);
spa_list_init(&impl.session_list);
clock_gettime(CLOCK_MONOTONIC, &impl.now);

View file

@ -21,38 +21,19 @@
#include <unistd.h>
#include <sys/mman.h>
#include <SDL2/SDL.h>
#include <spa/support/type-map.h>
#include <spa/param/format-utils.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/props.h>
#include <spa/debug/format.h>
#include <pipewire/pipewire.h>
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_video_format video_format;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video);
spa_type_video_format_map(map, &type->video_format);
}
#define WIDTH 640
#define HEIGHT 480
#define BPP 3
struct data {
struct type type;
#include "sdl.h"
struct data {
const char *path;
SDL_Renderer *renderer;
@ -62,7 +43,6 @@ struct data {
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote;
struct spa_hook remote_listener;
@ -153,82 +133,11 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old,
}
}
static struct {
Uint32 format;
uint32_t id;
} video_formats[] = {
{ SDL_PIXELFORMAT_UNKNOWN, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_UNKNOWN, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX1MSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX4LSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX4MSB, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_INDEX8, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB332, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGR555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ARGB4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ABGR4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGRA4444, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ARGB1555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA5551, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_ABGR1555, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGRA5551, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB565, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_BGR565, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGB24, offsetof(struct spa_type_video_format, RGB),},
{ SDL_PIXELFORMAT_RGB888, offsetof(struct spa_type_video_format, RGB),},
{ SDL_PIXELFORMAT_RGBX8888, offsetof(struct spa_type_video_format, RGBx),},
{ SDL_PIXELFORMAT_BGR24, offsetof(struct spa_type_video_format, BGR),},
{ SDL_PIXELFORMAT_BGR888, offsetof(struct spa_type_video_format, BGR),},
{ SDL_PIXELFORMAT_BGRX8888, offsetof(struct spa_type_video_format, BGRx),},
{ SDL_PIXELFORMAT_ARGB2101010, offsetof(struct spa_type_video_format, UNKNOWN),},
{ SDL_PIXELFORMAT_RGBA8888, offsetof(struct spa_type_video_format, RGBA),},
{ SDL_PIXELFORMAT_ARGB8888, offsetof(struct spa_type_video_format, ARGB),},
{ SDL_PIXELFORMAT_BGRA8888, offsetof(struct spa_type_video_format, BGRA),},
{ SDL_PIXELFORMAT_ABGR8888, offsetof(struct spa_type_video_format, ABGR),},
{ SDL_PIXELFORMAT_YV12, offsetof(struct spa_type_video_format, YV12),},
{ SDL_PIXELFORMAT_IYUV, offsetof(struct spa_type_video_format, I420),},
{ SDL_PIXELFORMAT_YUY2, offsetof(struct spa_type_video_format, YUY2),},
{ SDL_PIXELFORMAT_UYVY, offsetof(struct spa_type_video_format, UYVY),},
{ SDL_PIXELFORMAT_YVYU, offsetof(struct spa_type_video_format, YVYU),},
#if SDL_VERSION_ATLEAST(2,0,4)
{ SDL_PIXELFORMAT_NV12, offsetof(struct spa_type_video_format, NV12),},
{ SDL_PIXELFORMAT_NV21, offsetof(struct spa_type_video_format, NV21),},
#endif
};
static uint32_t sdl_format_to_id(struct data *data, Uint32 format)
{
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
if (video_formats[i].format == format)
return *SPA_MEMBER(&data->type.video_format, video_formats[i].id, uint32_t);
}
return data->type.video_format.UNKNOWN;
}
static Uint32 id_to_sdl_format(struct data *data, uint32_t id)
{
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
if (*SPA_MEMBER(&data->type.video_format, video_formats[i].id, uint32_t) == id)
return video_formats[i].format;
}
return SDL_PIXELFORMAT_UNKNOWN;
}
static void
on_stream_format_changed(void *_data, const struct spa_pod *format)
{
struct data *data = _data;
struct pw_stream *stream = data->stream;
struct pw_type *t = data->t;
uint8_t params_buffer[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
const struct spa_pod *params[2];
@ -241,11 +150,11 @@ on_stream_format_changed(void *_data, const struct spa_pod *format)
}
fprintf(stderr, "got format:\n");
spa_debug_format(2, data->t->map, format);
spa_debug_format(2, NULL, format);
spa_format_video_raw_parse(format, &data->format, &data->type.format_video);
spa_format_video_raw_parse(format, &data->format);
sdl_format = id_to_sdl_format(data, data->format.format);
sdl_format = id_to_sdl_format(data->format.format);
if (sdl_format == SDL_PIXELFORMAT_UNKNOWN) {
pw_stream_finish_format(stream, -EINVAL, NULL, 0);
return;
@ -260,17 +169,18 @@ on_stream_format_changed(void *_data, const struct spa_pod *format)
SDL_UnlockTexture(data->texture);
params[0] = spa_pod_builder_object(&b,
t->param.idBuffers, t->param_buffers.Buffers,
":", t->param_buffers.size, "i", data->stride * data->format.size.height,
":", t->param_buffers.stride, "i", data->stride,
":", t->param_buffers.buffers, "iru", 8,
SPA_ID_PARAM_Buffers, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 8,
SPA_POD_PROP_MIN_MAX(2, 16),
":", t->param_buffers.align, "i", 16);
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
":", SPA_PARAM_BUFFERS_size, "i", data->stride * data->format.size.height,
":", SPA_PARAM_BUFFERS_stride, "i", data->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
params[1] = spa_pod_builder_object(&b,
t->param.idMeta, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
SPA_ID_PARAM_Meta, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
pw_stream_finish_format(stream, 0, params, 2);
}
@ -284,48 +194,13 @@ static const struct pw_stream_events stream_events = {
static int build_format(struct data *data, struct spa_pod_builder *b, const struct spa_pod **params)
{
uint32_t i, c;
SDL_RendererInfo info;
SDL_GetRendererInfo(data->renderer, &info);
spa_pod_builder_push_object(b,
data->t->param.idEnumFormat, data->t->spa_format);
spa_pod_builder_id(b, data->type.media_type.video);
spa_pod_builder_id(b, data->type.media_subtype.raw);
spa_pod_builder_push_prop(b, data->type.format_video.format,
SPA_POD_PROP_FLAG_UNSET |
SPA_POD_PROP_RANGE_ENUM);
for (i = 0, c = 0; i < info.num_texture_formats; i++) {
uint32_t id = sdl_format_to_id(data, info.texture_formats[i]);
if (id == 0)
continue;
if (c++ == 0)
spa_pod_builder_id(b, id);
spa_pod_builder_id(b, id);
}
for (i = 0; i < SPA_N_ELEMENTS(video_formats); i++) {
uint32_t id =
*SPA_MEMBER(&data->type.video_format, video_formats[i].id,
uint32_t);
if (id != data->type.video_format.UNKNOWN)
spa_pod_builder_id(b, id);
}
spa_pod_builder_pop(b);
spa_pod_builder_add(b,
":", data->type.format_video.size, "Rru", &SPA_RECTANGLE(WIDTH, HEIGHT),
SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1,1),
&SPA_RECTANGLE(info.max_texture_width,
info.max_texture_height)),
":", data->type.format_video.framerate, "Fru", &SPA_FRACTION(25,1),
SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(0,1),
&SPA_RECTANGLE(30,1)),
NULL);
params[0] = spa_pod_builder_pop(b);
params[0] = sdl_build_formats(&info, b);
fprintf(stderr, "supported formats:\n");
spa_debug_format(2, data->t->map, params[0]);
spa_debug_format(2, NULL, params[0]);
return 0;
}
@ -354,11 +229,8 @@ int main(int argc, char *argv[])
data.remote = pw_stream_get_remote(data.stream);
data.core = pw_remote_get_core(data.remote);
data.t = pw_core_get_type(data.core);
data.path = argc > 1 ? argv[1] : NULL;
init_type(&data.type, data.t->map);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "can't initialize SDL: %s\n", SDL_GetError());
return -1;

View file

@ -22,38 +22,18 @@
#include <time.h>
#include <sys/mman.h>
#include <spa/support/type-map.h>
#include <spa/param/format-utils.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/props.h>
#include <pipewire/pipewire.h>
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_video format_video;
struct spa_type_video_format video_format;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video);
spa_type_video_format_map(map, &type->video_format);
}
#define BPP 3
struct data {
struct type type;
struct pw_main_loop *loop;
struct spa_source *timer;
struct pw_core *core;
struct pw_type *t;
struct pw_remote *remote;
struct spa_hook remote_listener;
@ -86,8 +66,8 @@ static void on_timeout(void *userdata, uint64_t expirations)
}
buf = b->buffer;
if (buf->datas[0].type == data->t->data.MemFd ||
buf->datas[0].type == data->t->data.DmaBuf) {
if (buf->datas[0].type == SPA_DATA_MemFd ||
buf->datas[0].type == SPA_DATA_DmaBuf) {
map =
mmap(NULL, buf->datas[0].maxsize + buf->datas[0].mapoffset,
PROT_READ | PROT_WRITE, MAP_SHARED, buf->datas[0].fd, 0);
@ -96,13 +76,13 @@ static void on_timeout(void *userdata, uint64_t expirations)
return;
}
p = SPA_MEMBER(map, buf->datas[0].mapoffset, uint8_t);
} else if (buf->datas[0].type == data->t->data.MemPtr) {
} else if (buf->datas[0].type == SPA_DATA_MemPtr) {
map = NULL;
p = buf->datas[0].data;
} else
return;
if ((h = spa_buffer_find_meta_data(buf, data->t->meta.Header, sizeof(*h)))) {
if ((h = spa_buffer_find_meta_data(buf, SPA_META_Header, sizeof(*h)))) {
#if 0
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
@ -114,7 +94,7 @@ static void on_timeout(void *userdata, uint64_t expirations)
h->seq = data->seq++;
h->dts_offset = 0;
}
if ((m = spa_buffer_find_meta(buf, data->t->meta.VideoDamage))) {
if ((m = spa_buffer_find_meta(buf, SPA_META_VideoDamage))) {
struct spa_meta_region *r = spa_meta_first(m);
if (spa_meta_check(r, m)) {
@ -175,7 +155,6 @@ on_stream_format_changed(void *_data, const struct spa_pod *format)
{
struct data *data = _data;
struct pw_stream *stream = data->stream;
struct pw_type *t = data->t;
uint8_t params_buffer[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
const struct spa_pod *params[3];
@ -184,27 +163,28 @@ on_stream_format_changed(void *_data, const struct spa_pod *format)
pw_stream_finish_format(stream, 0, NULL, 0);
return;
}
spa_format_video_raw_parse(format, &data->format, &data->type.format_video);
spa_format_video_raw_parse(format, &data->format);
data->stride = SPA_ROUND_UP_N(data->format.size.width * BPP, 4);
params[0] = spa_pod_builder_object(&b,
t->param.idBuffers, t->param_buffers.Buffers,
":", t->param_buffers.size, "i", data->stride * data->format.size.height,
":", t->param_buffers.stride, "i", data->stride,
":", t->param_buffers.buffers, "iru", 2,
SPA_ID_PARAM_Buffers, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 2,
SPA_POD_PROP_MIN_MAX(1, 32),
":", t->param_buffers.align, "i", 16);
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
":", SPA_PARAM_BUFFERS_size, "i", data->stride * data->format.size.height,
":", SPA_PARAM_BUFFERS_stride, "i", data->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
params[1] = spa_pod_builder_object(&b,
t->param.idMeta, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
SPA_ID_PARAM_Meta, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
params[2] = spa_pod_builder_object(&b,
t->param.idMeta, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.VideoDamage,
":", t->param_meta.size, "iru", sizeof(struct spa_meta_region) * 16,
SPA_ID_PARAM_Meta, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_VideoDamage,
":", SPA_PARAM_META_size, "iru", sizeof(struct spa_meta_region) * 16,
SPA_POD_PROP_MIN_MAX(sizeof(struct spa_meta_region) * 1,
sizeof(struct spa_meta_region) * 16));
@ -243,14 +223,14 @@ static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remo
NULL));
params[0] = spa_pod_builder_object(&b,
data->t->param.idEnumFormat, data->t->spa_format,
"I", data->type.media_type.video,
"I", data->type.media_subtype.raw,
":", data->type.format_video.format, "I", data->type.video_format.RGB,
":", data->type.format_video.size, "Rru", &SPA_RECTANGLE(320, 240),
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_video,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_VIDEO_format, "I", SPA_VIDEO_FORMAT_RGB,
":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320, 240),
SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1, 1),
&SPA_RECTANGLE(4096, 4096)),
":", data->type.format_video.framerate, "F", &SPA_FRACTION(25, 1));
":", SPA_FORMAT_VIDEO_framerate, "F", &SPA_FRACTION(25, 1));
pw_stream_add_listener(data->stream,
&data->stream_listener,
@ -282,11 +262,8 @@ int main(int argc, char *argv[])
data.loop = pw_main_loop_new(NULL);
data.core = pw_core_new(pw_main_loop_get_loop(data.loop), NULL);
data.t = pw_core_get_type(data.core);
data.remote = pw_remote_new(data.core, NULL, 0);
init_type(&data.type, data.t->map);
data.timer = pw_loop_add_timer(pw_main_loop_get_loop(data.loop), on_timeout, &data);
pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);

View file

@ -371,13 +371,12 @@ static void port_event_info(void *data, struct pw_port_info *info)
struct port_data *port_data = data;
struct node_data *node_data = port_data->node_data;
GstPipeWireDeviceProvider *self = node_data->self;
struct pw_type *t = node_data->self->type;
pw_log_debug("%p", port_data);
if (info->change_mask & PW_PORT_CHANGE_MASK_ENUM_PARAMS) {
pw_port_proxy_enum_params((struct pw_port_proxy*)port_data->proxy,
t->param.idEnumFormat, 0, 0, NULL);
SPA_ID_PARAM_EnumFormat, 0, 0, NULL);
add_pending(self, &port_data->pending_param, do_add_node, port_data);
}
}
@ -387,13 +386,11 @@ static void port_event_param(void *data, uint32_t id, uint32_t index, uint32_t n
{
struct port_data *port_data = data;
struct node_data *node_data = port_data->node_data;
GstPipeWireDeviceProvider *self = node_data->self;
struct pw_type *t = self->type;
GstCaps *c1;
pw_log_debug("%p", port_data);
c1 = gst_caps_from_format (param, t->map);
c1 = gst_caps_from_format (param);
if (c1 && node_data->caps)
gst_caps_append (node_data->caps, c1);
@ -467,11 +464,11 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, u
GstPipeWireDeviceProvider *self = rd->self;
struct node_data *nd;
if (type == self->type->node) {
if (type == PW_ID_INTERFACE_Node) {
struct pw_node_proxy *node;
node = pw_registry_proxy_bind(rd->registry,
id, self->type->node,
id, PW_ID_INTERFACE_Node,
PW_VERSION_NODE, sizeof(*nd));
if (node == NULL)
goto no_mem;
@ -487,7 +484,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, u
pw_proxy_add_listener((struct pw_proxy*)node, &nd->proxy_listener, &proxy_node_events, nd);
add_pending(self, &nd->pending, NULL, NULL);
}
else if (type == self->type->port) {
else if (type == PW_ID_INTERFACE_Port) {
struct pw_port_proxy *port;
struct port_data *pd;
@ -495,7 +492,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id, u
return;
port = pw_registry_proxy_bind(rd->registry,
id, self->type->port,
id, PW_ID_INTERFACE_Port,
PW_VERSION_PORT, sizeof(*pd));
if (port == NULL)
goto no_mem;
@ -540,7 +537,6 @@ gst_pipewire_device_provider_probe (GstDeviceProvider * provider)
GstPipeWireDeviceProvider *self = GST_PIPEWIRE_DEVICE_PROVIDER (provider);
struct pw_loop *l = NULL;
struct pw_core *c = NULL;
struct pw_type *t = NULL;
struct pw_remote *r = NULL;
struct remote_data *data;
struct spa_hook listener;
@ -553,8 +549,6 @@ gst_pipewire_device_provider_probe (GstDeviceProvider * provider)
if (!(c = pw_core_new (l, NULL)))
return NULL;
t = pw_core_get_type(c);
if (!(r = pw_remote_new (c, NULL, sizeof(*data))))
goto failed;
@ -595,7 +589,8 @@ gst_pipewire_device_provider_probe (GstDeviceProvider * provider)
self->devices = NULL;
self->core_proxy = pw_remote_get_core_proxy(r);
data->registry = pw_core_proxy_get_registry(self->core_proxy, t->registry, PW_VERSION_REGISTRY, 0);
data->registry = pw_core_proxy_get_registry(self->core_proxy,
PW_ID_INTERFACE_Registry, PW_VERSION_REGISTRY, 0);
pw_registry_proxy_add_listener(data->registry, &data->registry_listener, &registry_events, data);
pw_core_proxy_sync(self->core_proxy, ++self->seq);
@ -641,7 +636,6 @@ gst_pipewire_device_provider_start (GstDeviceProvider * provider)
GST_ERROR_OBJECT (self, "Could not create PipeWire core");
goto failed_core;
}
self->type = pw_core_get_type (self->core);
if (pw_thread_loop_start (self->main_loop) < 0) {
GST_ERROR_OBJECT (self, "Could not start PipeWire mainloop");
@ -682,8 +676,8 @@ gst_pipewire_device_provider_start (GstDeviceProvider * provider)
get_core_info (self->remote, self);
self->core_proxy = pw_remote_get_core_proxy(self->remote);
self->registry = pw_core_proxy_get_registry(self->core_proxy, self->type->registry,
PW_VERSION_REGISTRY, 0);
self->registry = pw_core_proxy_get_registry(self->core_proxy,
PW_ID_INTERFACE_Registry, PW_VERSION_REGISTRY, 0);
data->registry = self->registry;
@ -709,7 +703,6 @@ failed_remote:
failed_start:
pw_core_destroy (self->core);
self->core = NULL;
self->type = NULL;
failed_core:
pw_thread_loop_destroy (self->main_loop);
self->main_loop = NULL;
@ -734,7 +727,6 @@ gst_pipewire_device_provider_stop (GstDeviceProvider * provider)
if (self->core) {
pw_core_destroy (self->core);
self->core = NULL;
self->type = NULL;
}
if (self->main_loop) {
pw_thread_loop_destroy (self->main_loop);

View file

@ -85,7 +85,6 @@ struct _GstPipeWireDeviceProvider {
struct pw_thread_loop *main_loop;
struct pw_core *core;
struct pw_type *type;
struct pw_remote *remote;
struct spa_hook remote_listener;

View file

@ -24,6 +24,7 @@
#include <gst/video/video.h>
#include <gst/audio/audio.h>
#include <spa/utils/type.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/audio/format-utils.h>
#include <spa/pod/builder.h>
@ -32,141 +33,112 @@
struct media_type {
const char *name;
uint32_t *media_type;
uint32_t *media_subtype;
uint32_t media_type;
uint32_t media_subtype;
};
static struct {
struct spa_type_map *map;
uint32_t format;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_media_subtype_video media_subtype_video;
struct spa_type_media_subtype_audio media_subtype_audio;
struct spa_type_format_video format_video;
struct spa_type_format_audio format_audio;
struct spa_type_video_format video_format;
struct spa_type_audio_format audio_format;
} type = { NULL, };
static void
ensure_types (struct spa_type_map *map)
{
type.map = map;
type.format = spa_type_map_get_id (map, SPA_TYPE__Format);
spa_type_media_type_map (map, &type.media_type);
spa_type_media_subtype_map (map, &type.media_subtype);
spa_type_media_subtype_video_map (map, &type.media_subtype_video);
spa_type_media_subtype_audio_map (map, &type.media_subtype_audio);
spa_type_format_video_map (map, &type.format_video);
spa_type_format_audio_map (map, &type.format_audio);
spa_type_video_format_map (map, &type.video_format);
spa_type_audio_format_map (map, &type.audio_format);
}
static const struct media_type media_type_map[] = {
{ "video/x-raw", &type.media_type.video, &type.media_subtype.raw },
{ "audio/x-raw", &type.media_type.audio, &type.media_subtype.raw },
{ "image/jpeg", &type.media_type.video, &type.media_subtype_video.mjpg },
{ "video/x-h264", &type.media_type.video, &type.media_subtype_video.h264 },
{ "video/x-raw", SPA_MEDIA_TYPE_video, SPA_MEDIA_SUBTYPE_raw },
{ "audio/x-raw", SPA_MEDIA_TYPE_audio, SPA_MEDIA_SUBTYPE_raw },
{ "image/jpeg", SPA_MEDIA_TYPE_video, SPA_MEDIA_SUBTYPE_mjpg },
{ "video/x-h264", SPA_MEDIA_TYPE_video, SPA_MEDIA_SUBTYPE_h264 },
{ NULL, }
};
static const uint32_t *video_format_map[] = {
&type.video_format.UNKNOWN,
&type.video_format.ENCODED,
&type.video_format.I420,
&type.video_format.YV12,
&type.video_format.YUY2,
&type.video_format.UYVY,
&type.video_format.AYUV,
&type.video_format.RGBx,
&type.video_format.BGRx,
&type.video_format.xRGB,
&type.video_format.xBGR,
&type.video_format.RGBA,
&type.video_format.BGRA,
&type.video_format.ARGB,
&type.video_format.ABGR,
&type.video_format.RGB,
&type.video_format.BGR,
&type.video_format.Y41B,
&type.video_format.Y42B,
&type.video_format.YVYU,
&type.video_format.Y444,
&type.video_format.v210,
&type.video_format.v216,
&type.video_format.NV12,
&type.video_format.NV21,
&type.video_format.GRAY8,
&type.video_format.GRAY16_BE,
&type.video_format.GRAY16_LE,
&type.video_format.v308,
&type.video_format.RGB16,
&type.video_format.BGR16,
&type.video_format.RGB15,
&type.video_format.BGR15,
&type.video_format.UYVP,
&type.video_format.A420,
&type.video_format.RGB8P,
&type.video_format.YUV9,
&type.video_format.YVU9,
&type.video_format.IYU1,
&type.video_format.ARGB64,
&type.video_format.AYUV64,
&type.video_format.r210,
&type.video_format.I420_10BE,
&type.video_format.I420_10LE,
&type.video_format.I422_10BE,
&type.video_format.I422_10LE,
&type.video_format.Y444_10BE,
&type.video_format.Y444_10LE,
&type.video_format.GBR,
&type.video_format.GBR_10BE,
&type.video_format.GBR_10LE,
&type.video_format.NV16,
&type.video_format.NV24,
&type.video_format.NV12_64Z32,
&type.video_format.A420_10BE,
&type.video_format.A420_10LE,
&type.video_format.A422_10BE,
&type.video_format.A422_10LE,
&type.video_format.A444_10BE,
&type.video_format.A444_10LE,
&type.video_format.NV61,
&type.video_format.P010_10BE,
&type.video_format.P010_10LE,
&type.video_format.IYU2,
&type.video_format.VYUY,
&type.video_format.GBRA,
&type.video_format.GBRA_10BE,
&type.video_format.GBRA_10LE,
&type.video_format.GBR_12BE,
&type.video_format.GBR_12LE,
&type.video_format.GBRA_12BE,
&type.video_format.GBRA_12LE,
&type.video_format.I420_12BE,
&type.video_format.I420_12LE,
&type.video_format.I422_12BE,
&type.video_format.I422_12LE,
&type.video_format.Y444_12BE,
&type.video_format.Y444_12LE,
static const uint32_t video_format_map[] = {
SPA_VIDEO_FORMAT_UNKNOWN,
SPA_VIDEO_FORMAT_ENCODED,
SPA_VIDEO_FORMAT_I420,
SPA_VIDEO_FORMAT_YV12,
SPA_VIDEO_FORMAT_YUY2,
SPA_VIDEO_FORMAT_UYVY,
SPA_VIDEO_FORMAT_AYUV,
SPA_VIDEO_FORMAT_RGBx,
SPA_VIDEO_FORMAT_BGRx,
SPA_VIDEO_FORMAT_xRGB,
SPA_VIDEO_FORMAT_xBGR,
SPA_VIDEO_FORMAT_RGBA,
SPA_VIDEO_FORMAT_BGRA,
SPA_VIDEO_FORMAT_ARGB,
SPA_VIDEO_FORMAT_ABGR,
SPA_VIDEO_FORMAT_RGB,
SPA_VIDEO_FORMAT_BGR,
SPA_VIDEO_FORMAT_Y41B,
SPA_VIDEO_FORMAT_Y42B,
SPA_VIDEO_FORMAT_YVYU,
SPA_VIDEO_FORMAT_Y444,
SPA_VIDEO_FORMAT_v210,
SPA_VIDEO_FORMAT_v216,
SPA_VIDEO_FORMAT_NV12,
SPA_VIDEO_FORMAT_NV21,
SPA_VIDEO_FORMAT_GRAY8,
SPA_VIDEO_FORMAT_GRAY16_BE,
SPA_VIDEO_FORMAT_GRAY16_LE,
SPA_VIDEO_FORMAT_v308,
SPA_VIDEO_FORMAT_RGB16,
SPA_VIDEO_FORMAT_BGR16,
SPA_VIDEO_FORMAT_RGB15,
SPA_VIDEO_FORMAT_BGR15,
SPA_VIDEO_FORMAT_UYVP,
SPA_VIDEO_FORMAT_A420,
SPA_VIDEO_FORMAT_RGB8P,
SPA_VIDEO_FORMAT_YUV9,
SPA_VIDEO_FORMAT_YVU9,
SPA_VIDEO_FORMAT_IYU1,
SPA_VIDEO_FORMAT_ARGB64,
SPA_VIDEO_FORMAT_AYUV64,
SPA_VIDEO_FORMAT_r210,
SPA_VIDEO_FORMAT_I420_10BE,
SPA_VIDEO_FORMAT_I420_10LE,
SPA_VIDEO_FORMAT_I422_10BE,
SPA_VIDEO_FORMAT_I422_10LE,
SPA_VIDEO_FORMAT_Y444_10BE,
SPA_VIDEO_FORMAT_Y444_10LE,
SPA_VIDEO_FORMAT_GBR,
SPA_VIDEO_FORMAT_GBR_10BE,
SPA_VIDEO_FORMAT_GBR_10LE,
SPA_VIDEO_FORMAT_NV16,
SPA_VIDEO_FORMAT_NV24,
SPA_VIDEO_FORMAT_NV12_64Z32,
SPA_VIDEO_FORMAT_A420_10BE,
SPA_VIDEO_FORMAT_A420_10LE,
SPA_VIDEO_FORMAT_A422_10BE,
SPA_VIDEO_FORMAT_A422_10LE,
SPA_VIDEO_FORMAT_A444_10BE,
SPA_VIDEO_FORMAT_A444_10LE,
SPA_VIDEO_FORMAT_NV61,
SPA_VIDEO_FORMAT_P010_10BE,
SPA_VIDEO_FORMAT_P010_10LE,
SPA_VIDEO_FORMAT_IYU2,
SPA_VIDEO_FORMAT_VYUY,
SPA_VIDEO_FORMAT_GBRA,
SPA_VIDEO_FORMAT_GBRA_10BE,
SPA_VIDEO_FORMAT_GBRA_10LE,
SPA_VIDEO_FORMAT_GBR_12BE,
SPA_VIDEO_FORMAT_GBR_12LE,
SPA_VIDEO_FORMAT_GBRA_12BE,
SPA_VIDEO_FORMAT_GBRA_12LE,
SPA_VIDEO_FORMAT_I420_12BE,
SPA_VIDEO_FORMAT_I420_12LE,
SPA_VIDEO_FORMAT_I422_12BE,
SPA_VIDEO_FORMAT_I422_12LE,
SPA_VIDEO_FORMAT_Y444_12BE,
SPA_VIDEO_FORMAT_Y444_12LE,
};
#if __BYTE_ORDER == __BIG_ENDIAN
#define _FORMAT_LE(fmt) &type.audio_format. fmt ## _OE
#define _FORMAT_BE(fmt) &type.audio_format. fmt
#define _FORMAT_LE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## _OE
#define _FORMAT_BE(fmt) SPA_AUDIO_FORMAT_ ## fmt
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#define _FORMAT_LE(fmt) &type.audio_format. fmt
#define _FORMAT_BE(fmt) &type.audio_format. fmt ## _OE
#define _FORMAT_LE(fmt) SPA_AUDIO_FORMAT_ ## fmt
#define _FORMAT_BE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## _OE
#endif
static const uint32_t *audio_format_map[] = {
&type.audio_format.UNKNOWN,
&type.audio_format.ENCODED,
&type.audio_format.S8,
&type.audio_format.U8,
static const uint32_t audio_format_map[] = {
SPA_AUDIO_FORMAT_UNKNOWN,
SPA_AUDIO_FORMAT_ENCODED,
SPA_AUDIO_FORMAT_S8,
SPA_AUDIO_FORMAT_U8,
_FORMAT_LE (S16),
_FORMAT_BE (S16),
_FORMAT_LE (U16),
@ -217,6 +189,15 @@ find_media_types (const char *name)
return NULL;
}
static int find_index(const uint32_t *items, int n_items, uint32_t id)
{
int i;
for (i = 0; i < n_items; i++)
if (items[i] == id)
return i;
return -1;
}
static const char *
get_nth_string (const GValue *val, int idx)
{
@ -385,12 +366,12 @@ handle_video_fields (ConvertData *d)
for (i = 0; (v = get_nth_string (value, i)); i++) {
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_video.format,
SPA_FORMAT_VIDEO_format,
get_range_type (value));
idx = gst_video_format_from_string (v);
if (idx < SPA_N_ELEMENTS (video_format_map))
spa_pod_builder_id (&d->b, *video_format_map[idx]);
spa_pod_builder_id (&d->b, video_format_map[idx]);
}
prop = spa_pod_builder_pop(&d->b);
if (i > 1)
@ -403,7 +384,7 @@ handle_video_fields (ConvertData *d)
for (i = 0; get_nth_rectangle (value, value2, i, &v); i++) {
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_video.size,
SPA_FORMAT_VIDEO_size,
get_range_type2 (value, value2));
spa_pod_builder_rectangle (&d->b, v.width, v.height);
@ -419,7 +400,7 @@ handle_video_fields (ConvertData *d)
for (i = 0; get_nth_fraction (value, i, &v); i++) {
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_video.framerate,
SPA_FORMAT_VIDEO_framerate,
get_range_type (value));
spa_pod_builder_fraction (&d->b, v.num, v.denom);
@ -435,7 +416,7 @@ handle_video_fields (ConvertData *d)
for (i = 0; get_nth_fraction (value, i, &v); i++) {
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_video.max_framerate,
SPA_FORMAT_VIDEO_maxFramerate,
get_range_type (value));
spa_pod_builder_fraction (&d->b, v.num, v.denom);
@ -461,12 +442,12 @@ handle_audio_fields (ConvertData *d)
for (i = 0; (v = get_nth_string (value, i)); i++) {
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_audio.format,
SPA_FORMAT_AUDIO_format,
get_range_type (value));
idx = gst_audio_format_from_string (v);
if (idx < SPA_N_ELEMENTS (audio_format_map))
spa_pod_builder_id (&d->b, *audio_format_map[idx]);
spa_pod_builder_id (&d->b, audio_format_map[idx]);
}
prop = spa_pod_builder_pop(&d->b);
if (i > 1)
@ -488,7 +469,7 @@ handle_audio_fields (ConvertData *d)
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_audio.layout,
SPA_FORMAT_AUDIO_layout,
get_range_type (value));
spa_pod_builder_int (&d->b, layout);
@ -503,7 +484,7 @@ handle_audio_fields (ConvertData *d)
for (i = 0; get_nth_int (value, i, &v); i++) {
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_audio.rate,
SPA_FORMAT_AUDIO_rate,
get_range_type (value));
spa_pod_builder_int (&d->b, v);
@ -518,7 +499,7 @@ handle_audio_fields (ConvertData *d)
for (i = 0; get_nth_int (value, i, &v); i++) {
if (i == 0)
spa_pod_builder_push_prop (&d->b,
type.format_audio.channels,
SPA_FORMAT_AUDIO_channels,
get_range_type (value));
spa_pod_builder_int (&d->b, v);
@ -553,13 +534,13 @@ convert_1 (ConvertData *d)
d->b.write = write_pod;
spa_pod_builder_push_object (&d->b, d->id, type.format);
spa_pod_builder_id(&d->b, *d->type->media_type);
spa_pod_builder_id(&d->b, *d->type->media_subtype);
spa_pod_builder_push_object (&d->b, d->id, SPA_ID_OBJECT_Format);
spa_pod_builder_id(&d->b, d->type->media_type);
spa_pod_builder_id(&d->b, d->type->media_subtype);
if (*d->type->media_type == type.media_type.video)
if (d->type->media_type == SPA_MEDIA_TYPE_video)
handle_video_fields (d);
else if (*d->type->media_type == type.media_type.audio)
else if (d->type->media_type == SPA_MEDIA_TYPE_audio)
handle_audio_fields (d);
spa_pod_builder_pop (&d->b);
@ -568,7 +549,7 @@ convert_1 (ConvertData *d)
}
struct spa_pod *
gst_caps_to_format (GstCaps *caps, guint index, uint32_t id, struct spa_type_map *map)
gst_caps_to_format (GstCaps *caps, guint index, uint32_t id)
{
ConvertData d;
struct spa_pod *res;
@ -576,8 +557,6 @@ gst_caps_to_format (GstCaps *caps, guint index, uint32_t id, struct spa_type_map
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
ensure_types(map);
spa_zero (d);
d.cf = gst_caps_get_features (caps, index);
d.cs = gst_caps_get_structure (caps, index);
@ -607,12 +586,10 @@ foreach_func (GstCapsFeatures *features,
GPtrArray *
gst_caps_to_format_all (GstCaps *caps, uint32_t id, struct spa_type_map *map)
gst_caps_to_format_all (GstCaps *caps, uint32_t id)
{
ConvertData d;
ensure_types(map);
spa_zero (d);
d.id = id;
d.array = g_ptr_array_new_full (gst_caps_get_size (caps), (GDestroyNotify)g_free);
@ -622,8 +599,26 @@ gst_caps_to_format_all (GstCaps *caps, uint32_t id, struct spa_type_map *map)
return d.array;
}
typedef const char *(*id_to_string_func)(uint32_t id);
static const char *video_id_to_string(uint32_t id)
{
int idx;
if ((idx = find_index(video_format_map, SPA_N_ELEMENTS(video_format_map), id)) == -1)
return NULL;
return gst_video_format_to_string(idx);
}
static const char *audio_id_to_string(uint32_t id)
{
int idx;
if ((idx = find_index(audio_format_map, SPA_N_ELEMENTS(audio_format_map), id)) == -1)
return NULL;
return gst_audio_format_to_string(idx);
}
static void
handle_id_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
handle_id_prop (struct spa_pod_prop *prop, const char *key, id_to_string_func func, GstCaps *res)
{
const char * str;
uint32_t *id = SPA_POD_CONTENTS (struct spa_pod_prop, prop);
@ -636,7 +631,7 @@ handle_id_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
switch (flags & SPA_POD_PROP_RANGE_MASK) {
case SPA_POD_PROP_RANGE_NONE:
if (!(str = spa_type_map_get_type (type.map, id[0])))
if (!(str = func(id[0])))
return;
gst_caps_set_simple (res, key, G_TYPE_STRING, rindex (str, ':') + 1, NULL);
break;
@ -646,7 +641,7 @@ handle_id_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
g_value_init (&list, GST_TYPE_LIST);
for (i = 1; i < n_items; i++) {
if (!(str = spa_type_map_get_type (type.map, id[i])))
if (!(str = func(id[i])))
continue;
g_value_init (&v, G_TYPE_STRING);
@ -798,58 +793,56 @@ handle_fraction_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
}
}
GstCaps *
gst_caps_from_format (const struct spa_pod *format, struct spa_type_map *map)
gst_caps_from_format (const struct spa_pod *format)
{
GstCaps *res = NULL;
uint32_t media_type, media_subtype;
struct spa_pod_prop *prop;
ensure_types(map);
spa_pod_object_parse(format, "I", &media_type,
"I", &media_subtype);
if (media_type == type.media_type.video) {
if (media_subtype == type.media_subtype.raw) {
if (media_type == SPA_MEDIA_TYPE_video) {
if (media_subtype == SPA_MEDIA_SUBTYPE_raw) {
res = gst_caps_new_empty_simple ("video/x-raw");
if ((prop = spa_pod_find_prop (format, type.format_video.format))) {
handle_id_prop (prop, "format", res);
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_format))) {
handle_id_prop (prop, "format", video_id_to_string, res);
}
}
else if (media_subtype == type.media_subtype_video.mjpg) {
else if (media_subtype == SPA_MEDIA_SUBTYPE_mjpg) {
res = gst_caps_new_empty_simple ("image/jpeg");
}
else if (media_subtype == type.media_subtype_video.h264) {
else if (media_subtype == SPA_MEDIA_SUBTYPE_h264) {
res = gst_caps_new_simple ("video/x-h264",
"stream-format", G_TYPE_STRING, "byte-stream",
"alignment", G_TYPE_STRING, "au",
NULL);
}
if ((prop = spa_pod_find_prop (format, type.format_video.size))) {
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_size))) {
handle_rect_prop (prop, "width", "height", res);
}
if ((prop = spa_pod_find_prop (format, type.format_video.framerate))) {
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_framerate))) {
handle_fraction_prop (prop, "framerate", res);
}
if ((prop = spa_pod_find_prop (format, type.format_video.max_framerate))) {
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_maxFramerate))) {
handle_fraction_prop (prop, "max-framerate", res);
}
} else if (media_type == type.media_type.audio) {
if (media_subtype == type.media_subtype.raw) {
} else if (media_type == SPA_MEDIA_TYPE_audio) {
if (media_subtype == SPA_MEDIA_SUBTYPE_raw) {
res = gst_caps_new_simple ("audio/x-raw",
"layout", G_TYPE_STRING, "interleaved",
NULL);
if ((prop = spa_pod_find_prop (format, type.format_audio.format))) {
handle_id_prop (prop, "format", res);
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_AUDIO_format))) {
handle_id_prop (prop, "format", audio_id_to_string, res);
}
if ((prop = spa_pod_find_prop (format, type.format_audio.rate))) {
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_AUDIO_rate))) {
handle_int_prop (prop, "rate", res);
}
if ((prop = spa_pod_find_prop (format, type.format_audio.channels))) {
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_AUDIO_channels))) {
handle_int_prop (prop, "channels", res);
}
}
else if (media_subtype == type.media_subtype_audio.aac) {
else if (media_subtype == SPA_MEDIA_SUBTYPE_aac) {
}
}
return res;

View file

@ -22,17 +22,15 @@
#include <gst/gst.h>
#include <spa/support/type-map.h>
#include <spa/pod/pod.h>
G_BEGIN_DECLS
struct spa_pod * gst_caps_to_format (GstCaps *caps,
guint index, uint32_t id,
struct spa_type_map *map);
GPtrArray * gst_caps_to_format_all (GstCaps *caps, uint32_t id, struct spa_type_map *map);
guint index, uint32_t id);
GPtrArray * gst_caps_to_format_all (GstCaps *caps, uint32_t id);
GstCaps * gst_caps_from_format (const struct spa_pod *format, struct spa_type_map *map);
GstCaps * gst_caps_from_format (const struct spa_pod *format);
G_END_DECLS

View file

@ -71,7 +71,6 @@ void gst_pipewire_pool_wrap_buffer (GstPipeWirePool *pool, struct pw_buffer *b)
GstBuffer *buf;
uint32_t i;
GstPipeWirePoolData *data;
struct pw_type *t = pool->t;
GST_LOG_OBJECT (pool, "wrap buffer");
@ -84,19 +83,19 @@ void gst_pipewire_pool_wrap_buffer (GstPipeWirePool *pool, struct pw_buffer *b)
GstMemory *gmem = NULL;
GST_LOG_OBJECT (pool, "wrap buffer %d %d", d->mapoffset, d->maxsize);
if (d->type == t->data.MemFd) {
if (d->type == SPA_DATA_MemFd) {
gmem = gst_fd_allocator_alloc (pool->fd_allocator, dup (d->fd),
d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (gmem, d->mapoffset, d->maxsize);
data->offset = d->mapoffset;
}
else if(d->type == t->data.DmaBuf) {
else if(d->type == SPA_DATA_DmaBuf) {
gmem = gst_dmabuf_allocator_alloc (pool->dmabuf_allocator, dup (d->fd),
d->mapoffset + d->maxsize);
gst_memory_resize (gmem, d->mapoffset, d->maxsize);
data->offset = d->mapoffset;
}
else if (d->type == t->data.MemPtr) {
else if (d->type == SPA_DATA_MemPtr) {
gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, 0,
d->maxsize, NULL, NULL);
data->offset = 0;
@ -107,7 +106,7 @@ void gst_pipewire_pool_wrap_buffer (GstPipeWirePool *pool, struct pw_buffer *b)
data->pool = gst_object_ref (pool);
data->owner = NULL;
data->header = spa_buffer_find_meta_data (b->buffer, t->meta.Header, sizeof(*data->header));
data->header = spa_buffer_find_meta_data (b->buffer, SPA_META_Header, sizeof(*data->header));
data->flags = GST_BUFFER_FLAGS (buf);
data->b = b;
data->buf = buf;

View file

@ -217,7 +217,6 @@ gst_pipewire_sink_class_init (GstPipeWireSinkClass * klass)
static void
pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
{
struct pw_type *t = sink->type;
GstStructure *config;
GstCaps *caps;
guint size;
@ -231,27 +230,27 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers, &max_buffers);
spa_pod_builder_init (&b, buffer, sizeof (buffer));
spa_pod_builder_push_object (&b, t->param.idBuffers, t->param_buffers.Buffers);
spa_pod_builder_push_object (&b, SPA_ID_PARAM_Buffers, SPA_ID_OBJECT_ParamBuffers);
if (size == 0)
spa_pod_builder_add (&b,
":", t->param_buffers.size, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX), NULL);
":", SPA_PARAM_BUFFERS_size, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX), NULL);
else
spa_pod_builder_add (&b,
":", t->param_buffers.size, "iru", size, SPA_POD_PROP_MIN_MAX(size, INT32_MAX), NULL);
":", SPA_PARAM_BUFFERS_size, "iru", size, SPA_POD_PROP_MIN_MAX(size, INT32_MAX), NULL);
spa_pod_builder_add (&b,
":", t->param_buffers.stride, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX),
":", t->param_buffers.buffers, "iru", min_buffers,
":", SPA_PARAM_BUFFERS_stride, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX),
":", SPA_PARAM_BUFFERS_buffers, "iru", min_buffers,
SPA_POD_PROP_MIN_MAX(min_buffers,
max_buffers ? max_buffers : INT32_MAX),
":", t->param_buffers.align, "i", 16,
":", SPA_PARAM_BUFFERS_align, "i", 16,
NULL);
port_params[0] = spa_pod_builder_pop (&b);
port_params[1] = spa_pod_builder_object (&b,
t->param.idMeta, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof (struct spa_meta_header));
SPA_ID_PARAM_Meta, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof (struct spa_meta_header));
pw_thread_loop_lock (sink->main_loop);
@ -274,8 +273,6 @@ gst_pipewire_sink_init (GstPipeWireSink * sink)
sink->loop = pw_loop_new (NULL);
sink->main_loop = pw_thread_loop_new (sink->loop, "pipewire-sink-loop");
sink->core = pw_core_new (sink->loop, NULL);
sink->type = pw_core_get_type (sink->core);
sink->pool->t = sink->type;
GST_DEBUG ("loop %p %p", sink->loop, sink->main_loop);
}
@ -510,12 +507,10 @@ gst_pipewire_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
enum pw_stream_state state;
const char *error = NULL;
gboolean res = FALSE;
struct pw_type *t;
pwsink = GST_PIPEWIRE_SINK (bsink);
t = pwsink->type;
possible = gst_caps_to_format_all (caps, t->param.idEnumFormat, t->map);
possible = gst_caps_to_format_all (caps, SPA_ID_PARAM_EnumFormat);
pw_thread_loop_lock (pwsink->main_loop);
state = pw_stream_get_state (pwsink->stream, &error);

View file

@ -82,7 +82,6 @@ struct _GstPipeWireSink {
struct pw_thread_loop *main_loop;
struct pw_core *core;
struct pw_type *type;
struct pw_remote *remote;
struct spa_hook remote_listener;

View file

@ -203,7 +203,6 @@ gst_pipewire_src_finalize (GObject * object)
pw_core_destroy (pwsrc->core);
pwsrc->core = NULL;
pwsrc->type = NULL;
pw_thread_loop_destroy (pwsrc->main_loop);
pwsrc->main_loop = NULL;
pw_loop_destroy (pwsrc->loop);
@ -326,8 +325,6 @@ gst_pipewire_src_init (GstPipeWireSrc * src)
src->loop = pw_loop_new (NULL);
src->main_loop = pw_thread_loop_new (src->loop, "pipewire-main-loop");
src->core = pw_core_new (src->loop, NULL);
src->type = pw_core_get_type (src->core);
src->pool->t = src->type;
GST_DEBUG ("loop %p, mainloop %p", src->loop, src->main_loop);
}
@ -590,7 +587,7 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc)
GST_DEBUG_OBJECT (basesrc, "have common caps: %" GST_PTR_FORMAT, caps);
/* open a connection with these caps */
possible = gst_caps_to_format_all (caps, pwsrc->type->param.idEnumFormat, pwsrc->type->map);
possible = gst_caps_to_format_all (caps, SPA_ID_PARAM_EnumFormat);
gst_caps_unref (caps);
/* first disconnect */
@ -686,8 +683,6 @@ on_format_changed (void *data,
GstPipeWireSrc *pwsrc = data;
GstCaps *caps;
gboolean res;
struct pw_core *core = pwsrc->core;
struct pw_type *t = pw_core_get_type(core);
if (format == NULL) {
GST_DEBUG_OBJECT (pwsrc, "clear format");
@ -695,7 +690,7 @@ on_format_changed (void *data,
return;
}
caps = gst_caps_from_format (format, t->map);
caps = gst_caps_from_format (format);
GST_DEBUG_OBJECT (pwsrc, "we got format %" GST_PTR_FORMAT, caps);
res = gst_base_src_set_caps (GST_BASE_SRC (pwsrc), caps);
gst_caps_unref (caps);
@ -707,16 +702,17 @@ on_format_changed (void *data,
spa_pod_builder_init (&b, buffer, sizeof (buffer));
params[0] = spa_pod_builder_object (&b,
t->param.idBuffers, t->param_buffers.Buffers,
":", t->param_buffers.size, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX),
":", t->param_buffers.stride, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX),
":", t->param_buffers.buffers, "iru", 16, SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->param_buffers.align, "i", 16);
SPA_ID_PARAM_Buffers, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 16, SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", SPA_PARAM_BUFFERS_blocks, "iru", 0, SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", SPA_PARAM_BUFFERS_size, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX),
":", SPA_PARAM_BUFFERS_stride, "iru", 0, SPA_POD_PROP_MIN_MAX(0, INT32_MAX),
":", SPA_PARAM_BUFFERS_align, "i", 16);
params[1] = spa_pod_builder_object (&b,
t->param.idMeta, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof (struct spa_meta_header));
SPA_ID_PARAM_Meta, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof (struct spa_meta_header));
GST_DEBUG_OBJECT (pwsrc, "doing finish format");
pw_stream_finish_format (pwsrc->stream, 0, params, 2);

View file

@ -70,7 +70,6 @@ struct _GstPipeWireSrc {
struct pw_thread_loop *main_loop;
struct pw_core *core;
struct pw_type *type;
struct pw_remote *remote;
struct spa_hook remote_listener;

View file

@ -180,13 +180,12 @@ static const struct pw_module_events module_events = {
static int module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = pw_module_get_core(module);
struct pw_type *t = pw_core_get_type(core);
struct pw_factory *factory;
struct factory_data *data;
factory = pw_factory_new(core,
"audio-dsp",
t->node,
PW_ID_INTERFACE_Node,
PW_VERSION_NODE,
NULL,
sizeof(*data));

View file

@ -46,8 +46,6 @@ struct factory_data {
struct pw_module *module;
struct spa_hook module_listener;
uint32_t type_client_node;
};
static void *create_object(void *_data,
@ -122,16 +120,12 @@ static const struct pw_module_events module_events = {
static int module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = pw_module_get_core(module);
struct pw_type *t = pw_core_get_type(core);
struct pw_factory *factory;
struct factory_data *data;
uint32_t type_client_node;
type_client_node = spa_type_map_get_id(t->map, PW_TYPE_INTERFACE__ClientNode);
factory = pw_factory_new(core,
"client-node",
type_client_node,
PW_ID_INTERFACE_ClientNode,
PW_VERSION_CLIENT_NODE,
NULL,
sizeof(*data));
@ -142,7 +136,6 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
data->this = factory;
data->module = module;
data->properties = properties;
data->type_client_node = type_client_node;
pw_log_debug("module %p: new", module);

View file

@ -30,6 +30,7 @@
#include <spa/node/node.h>
#include <spa/pod/filter.h>
#include <spa/debug/types.h>
#include "pipewire/pipewire.h"
#include "pipewire/interfaces.h"
@ -65,15 +66,6 @@
#define CHECK_PORT_BUFFER(this,b,p) (b < p->n_buffers)
struct type {
uint32_t client_node_position;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->client_node_position = spa_type_map_get_id(map, PW_TYPE_CLIENT_NODE_IO__Position);
}
struct mem {
uint32_t id;
int ref;
@ -130,7 +122,6 @@ struct node {
struct impl *impl;
struct spa_type_map *map;
struct spa_log *log;
struct spa_loop *data_loop;
@ -158,10 +149,7 @@ struct node {
struct impl {
struct pw_client_node this;
struct type type;
struct pw_core *core;
struct pw_type *t;
struct node node;
@ -315,7 +303,6 @@ static int clear_buffers(struct node *this, struct mix *mix)
{
uint32_t i, j;
struct impl *impl = this->impl;
struct pw_type *t = impl->t;
for (i = 0; i < mix->n_buffers; i++) {
struct buffer *b = &mix->buffers[i];
@ -326,8 +313,8 @@ static int clear_buffers(struct node *this, struct mix *mix)
for (j = 0; j < b->buffer.n_datas; j++) {
struct spa_data *d = &b->datas[j];
if (d->type == t->data.DmaBuf ||
d->type == t->data.MemFd) {
if (d->type == SPA_DATA_DmaBuf ||
d->type == SPA_DATA_MemFd) {
uint32_t id;
id = SPA_PTR_TO_UINT32(b->buffer.datas[j].data);
@ -501,7 +488,6 @@ do_update_port(struct node *this,
const struct spa_pod **params,
const struct spa_port_info *info)
{
struct pw_type *t = this->impl->t;
int i;
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) {
@ -516,7 +502,7 @@ do_update_port(struct node *this,
for (i = 0; i < port->n_params; i++) {
port->params[i] = pw_spa_pod_copy(params[i]);
if (spa_pod_is_object_id(port->params[i], t->param.idFormat))
if (spa_pod_is_object_id(port->params[i], SPA_ID_PARAM_Format))
port->have_format = true;
}
}
@ -698,7 +684,6 @@ static int do_port_set_io(struct impl *impl,
uint32_t id, void *data, size_t size)
{
struct node *this = &impl->node;
struct pw_type *t = impl->t;
struct pw_memblock *mem;
struct mem *m;
uint32_t memid, mem_offset, mem_size;
@ -729,7 +714,7 @@ static int do_port_set_io(struct impl *impl,
return -EINVAL;
mem_offset += mem->offset;
m = ensure_mem(impl, mem->fd, t->data.MemFd, mem->flags);
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
memid = m->id;
}
else {
@ -779,7 +764,6 @@ do_port_use_buffers(struct impl *impl,
struct mix *mix;
uint32_t i, j;
struct pw_client_node_buffer *mb;
struct pw_type *t = impl->t;
spa_log_debug(this->log, "client-node %p: %s port %d.%d use buffers %p %u", impl,
direction == SPA_DIRECTION_INPUT ? "input" : "output",
@ -836,11 +820,11 @@ do_port_use_buffers(struct impl *impl,
for (j = 0; j < buffers[i]->n_datas; j++) {
struct spa_data *d = buffers[i]->datas;
data_size += sizeof(struct spa_chunk);
if (d->type == t->data.MemPtr)
if (d->type == SPA_DATA_MemPtr)
data_size += d->maxsize;
}
m = ensure_mem(impl, mem->fd, t->data.MemFd, mem->flags);
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
b->memid = m->id;
mb[i].buffer = &b->buffer;
@ -858,11 +842,11 @@ do_port_use_buffers(struct impl *impl,
memcpy(&b->buffer.datas[j], d, sizeof(struct spa_data));
if (d->type == t->data.DmaBuf ||
d->type == t->data.MemFd) {
if (d->type == SPA_DATA_DmaBuf ||
d->type == SPA_DATA_MemFd) {
m = ensure_mem(impl, d->fd, d->type, d->flags);
b->buffer.datas[j].data = SPA_UINT32_TO_PTR(m->id);
} else if (d->type == t->data.MemPtr) {
} else if (d->type == SPA_DATA_MemPtr) {
b->buffer.datas[j].data = SPA_INT_TO_PTR(size);
size += d->maxsize;
} else {
@ -950,8 +934,6 @@ impl_node_port_send_command(struct spa_node *node,
uint32_t port_id, const struct spa_command *command)
{
struct node *this;
struct impl *impl;
struct pw_type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
spa_return_val_if_fail(command != NULL, -EINVAL);
@ -961,11 +943,8 @@ impl_node_port_send_command(struct spa_node *node,
if (this->resource == NULL)
return 0;
impl = this->impl;
t = impl->t;
spa_log_trace(this->log, "send command %s",
spa_type_map_get_type(t->map, SPA_COMMAND_TYPE(command)));
spa_debug_type_find_name(spa_debug_types, SPA_COMMAND_TYPE(command)));
pw_client_node_resource_port_command(this->resource,
direction, port_id,
@ -1175,21 +1154,21 @@ node_init(struct node *this,
uint32_t i;
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
switch (support[i].type) {
case SPA_ID_INTERFACE_Log:
this->log = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
break;
case SPA_ID_INTERFACE_DataLoop:
this->data_loop = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
break;
default:
break;
}
}
if (this->data_loop == NULL) {
spa_log_error(this->log, "a data-loop is needed");
return -EINVAL;
}
if (this->map == NULL) {
spa_log_error(this->log, "a type map is needed");
return -EINVAL;
}
this->node = impl_node;
@ -1266,7 +1245,6 @@ static void node_initialized(void *data)
struct impl *impl = data;
struct pw_client_node *this = &impl->this;
struct pw_node *node = this->node;
struct pw_type *t = impl->t;
struct pw_global *global;
uint32_t area_size, size;
struct mem *m;
@ -1297,11 +1275,11 @@ static void node_initialized(void *data)
impl->position = SPA_MEMBER(impl->io_areas->ptr,
area_size, struct pw_client_node_position);
m = ensure_mem(impl, impl->io_areas->fd, t->data.MemFd, impl->io_areas->flags);
m = ensure_mem(impl, impl->io_areas->fd, SPA_DATA_MemFd, impl->io_areas->flags);
pw_log_debug("client-node %p: io areas %p", node, impl->io_areas->ptr);
pw_client_node_resource_set_io(this->resource,
impl->type.client_node_position,
PW_ID_IO_ClientNodePosition,
m->id,
area_size,
sizeof(struct pw_client_node_position));
@ -1451,13 +1429,12 @@ static int impl_mix_port_set_io(struct spa_node *node,
struct pw_port *port = p->port;
struct impl *impl = port->owner_data;
struct pw_port_mix *mix;
struct pw_type *t = impl->t;
mix = pw_map_lookup(&port->mix_port_map, mix_id);
if (mix == NULL)
return -EIO;
if (id == t->io.Buffers) {
if (id == SPA_ID_IO_Buffers) {
if (data && size >= sizeof(struct spa_io_buffers))
mix->io = data;
else
@ -1606,12 +1583,9 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
this = &impl->this;
impl->core = core;
impl->t = pw_core_get_type(core);
impl->fds[0] = impl->fds[1] = -1;
pw_log_debug("client-node %p: new", impl);
init_type(&impl->type, impl->t->map);
support = pw_core_get_support(impl->core, &n_support);
node_init(&impl->node, NULL, support, n_support);
impl->node.impl = impl;

View file

@ -47,23 +47,11 @@
/** \cond */
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
}
struct node {
struct spa_node node;
struct impl *impl;
struct spa_type_map *map;
struct spa_log *log;
const struct spa_node_callbacks *callbacks;
@ -75,10 +63,7 @@ struct node {
struct impl {
struct pw_client_stream this;
struct type type;
struct pw_core *core;
struct pw_type *t;
struct node node;
@ -253,14 +238,12 @@ impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t
{
struct node *this;
struct impl *impl;
struct pw_type *t;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
t = impl->t;
if (direction != impl->direction)
return -EINVAL;
@ -270,7 +253,7 @@ impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t
if ((res = spa_node_port_set_io(impl->adapter_mix,
direction, port_id,
t->io.ControlRange,
SPA_ID_IO_ControlRange,
&impl->ctrl,
sizeof(&impl->ctrl))) < 0)
return res;
@ -344,14 +327,13 @@ static int debug_params(struct impl *impl, struct spa_node *node,
enum spa_direction direction, uint32_t port_id, uint32_t id, struct spa_pod *filter)
{
struct node *this = &impl->node;
struct pw_type *t = impl->t;
struct spa_pod_builder b = { 0 };
uint8_t buffer[4096];
uint32_t state;
struct spa_pod *param;
int res;
spa_log_error(this->log, "params %s:", spa_type_map_get_type(t->map, id));
spa_log_error(this->log, "params %s:", spa_debug_type_find_name(spa_debug_types, id));
state = 0;
while (true) {
@ -365,12 +347,12 @@ static int debug_params(struct impl *impl, struct spa_node *node,
spa_log_error(this->log, " error: %s", spa_strerror(res));
break;
}
spa_debug_pod(2, t->map, param);
spa_debug_pod(2, spa_debug_types, param);
}
spa_log_error(this->log, "failed filter:");
if (filter)
spa_debug_pod(2, t->map, filter);
spa_debug_pod(2, spa_debug_types, filter);
return 0;
}
@ -383,7 +365,6 @@ static int negotiate_format(struct impl *impl)
struct spa_pod *format;
uint8_t buffer[4096];
struct spa_pod_builder b = { 0 };
struct pw_type *t = impl->t;
int res;
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -393,35 +374,35 @@ static int negotiate_format(struct impl *impl)
state = 0;
if ((res = spa_node_port_enum_params(impl->adapter_mix,
SPA_DIRECTION_REVERSE(impl->direction), 0,
t->param.idEnumFormat, &state,
SPA_ID_PARAM_EnumFormat, &state,
NULL, &format, &b)) <= 0) {
debug_params(impl, impl->adapter_mix, SPA_DIRECTION_REVERSE(impl->direction), 0,
t->param.idEnumFormat, NULL);
SPA_ID_PARAM_EnumFormat, NULL);
return -ENOTSUP;
}
state = 0;
if ((res = spa_node_port_enum_params(impl->cnode,
impl->direction, 0,
t->param.idEnumFormat, &state,
SPA_ID_PARAM_EnumFormat, &state,
format, &format, &b)) <= 0) {
debug_params(impl, impl->cnode, impl->direction, 0,
t->param.idEnumFormat, format);
SPA_ID_PARAM_EnumFormat, format);
return -ENOTSUP;
}
spa_pod_fixate(format);
spa_debug_format(0, t->map, format);
spa_debug_format(0, NULL, format);
if ((res = spa_node_port_set_param(impl->adapter_mix,
SPA_DIRECTION_REVERSE(impl->direction), 0,
t->param.idFormat, 0,
SPA_ID_PARAM_Format, 0,
format)) < 0)
return res;
if ((res = spa_node_port_set_param(impl->cnode,
impl->direction, 0,
t->param.idFormat, 0,
SPA_ID_PARAM_Format, 0,
format)) < 0)
return res;
@ -431,7 +412,6 @@ static int negotiate_format(struct impl *impl)
static int negotiate_buffers(struct impl *impl)
{
struct node *this = &impl->node;
struct pw_type *t = impl->t;
uint8_t buffer[4096];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
uint32_t state;
@ -453,10 +433,10 @@ static int negotiate_buffers(struct impl *impl)
state = 0;
if ((res = spa_node_port_enum_params(impl->adapter_mix,
SPA_DIRECTION_REVERSE(impl->direction), 0,
t->param.idBuffers, &state,
SPA_ID_PARAM_Buffers, &state,
param, &param, &b)) <= 0) {
debug_params(impl, impl->adapter_mix, SPA_DIRECTION_REVERSE(impl->direction), 0,
t->param.idBuffers, param);
SPA_ID_PARAM_Buffers, param);
return -ENOTSUP;
}
if (res == 0)
@ -465,10 +445,10 @@ static int negotiate_buffers(struct impl *impl)
state = 0;
if ((res = spa_node_port_enum_params(impl->cnode,
impl->direction, 0,
t->param.idBuffers, &state,
SPA_ID_PARAM_Buffers, &state,
param, &param, &b)) < 0) {
debug_params(impl, impl->cnode, impl->direction, 0,
t->param.idBuffers, param);
SPA_ID_PARAM_Buffers, param);
return res;
}
@ -494,10 +474,10 @@ static int negotiate_buffers(struct impl *impl)
}
if (spa_pod_object_parse(param,
":", t->param_buffers.buffers, "i", &buffers,
":", t->param_buffers.blocks, "i", &blocks,
":", t->param_buffers.size, "i", &size,
":", t->param_buffers.align, "i", &align,
":", SPA_PARAM_BUFFERS_buffers, "i", &buffers,
":", SPA_PARAM_BUFFERS_blocks, "i", &blocks,
":", SPA_PARAM_BUFFERS_size, "i", &size,
":", SPA_PARAM_BUFFERS_align, "i", &align,
NULL) < 0)
return -EINVAL;
@ -508,7 +488,7 @@ static int negotiate_buffers(struct impl *impl)
memset(datas, 0, sizeof(struct spa_data) * blocks);
aligns = alloca(sizeof(uint32_t) * blocks);
for (i = 0; i < blocks; i++) {
datas[i].type = t->data.MemPtr;
datas[i].type = SPA_DATA_MemPtr;
datas[i].maxsize = size;
aligns[i] = align;
}
@ -603,14 +583,12 @@ impl_node_port_set_param(struct spa_node *node,
{
struct node *this;
struct impl *impl;
struct pw_type *t;
int res;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
t = impl->t;
if (direction != impl->direction)
return -EINVAL;
@ -619,7 +597,7 @@ impl_node_port_set_param(struct spa_node *node,
flags, param)) < 0)
return res;
if (id == t->param.idFormat && impl->use_converter) {
if (id == SPA_ID_PARAM_Format && impl->use_converter) {
if (param == NULL) {
if ((res = spa_node_port_set_param(impl->adapter_mix,
SPA_DIRECTION_REVERSE(direction), 0, id,
@ -644,14 +622,12 @@ impl_node_port_set_io(struct spa_node *node,
{
struct node *this;
struct impl *impl;
struct pw_type *t;
int res = 0;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct node, node);
impl = this->impl;
t = impl->t;
spa_log_debug(this->log, "set io %d %d %d", id, direction, impl->direction);
if (direction != impl->direction)
@ -660,7 +636,7 @@ impl_node_port_set_io(struct spa_node *node,
if (impl->use_converter)
res = spa_node_port_set_io(impl->adapter_mix, direction, port_id, id, data, size);
if (id == t->io.Buffers && size >= sizeof(struct spa_io_buffers)) {
if (id == SPA_ID_IO_Buffers && size >= sizeof(struct spa_io_buffers)) {
impl->io = data;
}
@ -837,16 +813,9 @@ node_init(struct node *this,
uint32_t i;
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "a type map is needed");
return -EINVAL;
}
this->node = impl_node;
this->seq = 1;
@ -859,7 +828,6 @@ static void client_node_initialized(void *data)
struct impl *impl = data;
uint32_t n_input_ports, n_output_ports, max_input_ports, max_output_ports, state;
uint32_t media_type, media_subtype;
struct pw_type *t = impl->t;
struct spa_pod *format;
uint8_t buffer[4096];
struct spa_pod_builder b;
@ -906,7 +874,7 @@ static void client_node_initialized(void *data)
if ((res = spa_node_port_set_io(impl->client_port->mix,
impl->direction, 0,
t->io.Buffers,
SPA_ID_IO_Buffers,
impl->client_port_mix.io,
sizeof(impl->client_port_mix.io))) < 0)
return;
@ -915,7 +883,7 @@ static void client_node_initialized(void *data)
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if ((res = spa_node_port_enum_params(impl->cnode,
impl->direction, 0,
t->param.idEnumFormat, &state,
SPA_ID_PARAM_EnumFormat, &state,
NULL, &format, &b)) <= 0) {
pw_log_warn("client-stream %p: no format given", &impl->this);
impl->adapter = impl->cnode;
@ -929,15 +897,15 @@ static void client_node_initialized(void *data)
"I", &media_subtype);
pw_log_debug("client-stream %p: %s/%s", &impl->this,
spa_type_map_get_type(t->map, media_type),
spa_type_map_get_type(t->map, media_subtype));
spa_debug_type_find_name(spa_debug_types, media_type),
spa_debug_type_find_name(spa_debug_types, media_subtype));
if (!exclusive &&
media_type == impl->type.media_type.audio &&
media_subtype == impl->type.media_subtype.raw) {
media_type == SPA_MEDIA_TYPE_audio &&
media_subtype == SPA_MEDIA_SUBTYPE_raw) {
if ((impl->adapter = pw_load_spa_interface("audioconvert/libspa-audioconvert",
"audioconvert", SPA_TYPE__Node, NULL, 0, NULL)) == NULL)
"audioconvert", SPA_ID_INTERFACE_Node, NULL, 0, NULL)) == NULL)
return;
impl->adapter_mix = impl->adapter;
@ -952,7 +920,7 @@ static void client_node_initialized(void *data)
if (impl->use_converter) {
if ((res = spa_node_port_set_io(impl->adapter_mix,
SPA_DIRECTION_REVERSE(impl->direction), 0,
t->io.Buffers,
SPA_ID_IO_Buffers,
impl->client_port_mix.io,
sizeof(impl->client_port_mix.io))) < 0)
return;
@ -960,9 +928,9 @@ static void client_node_initialized(void *data)
}
if (media_type == impl->type.media_type.audio)
if (media_type == SPA_MEDIA_TYPE_audio)
type = "Audio";
else if (media_type == impl->type.media_type.video)
else if (media_type == SPA_MEDIA_TYPE_video)
type = "Video";
else
type = "Generic";
@ -1108,9 +1076,6 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource,
this = &impl->this;
impl->core = core;
impl->t = pw_core_get_type(core);
init_type(&impl->type, impl->t->map);
pw_log_debug("client-stream %p: new", impl);

View file

@ -938,7 +938,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_client_node_
};
static const struct pw_protocol_marshal pw_protocol_native_client_node_marshal = {
PW_TYPE_INTERFACE__ClientNode,
PW_ID_INTERFACE_ClientNode,
PW_VERSION_CLIENT_NODE,
&pw_protocol_native_client_node_method_marshal,
&pw_protocol_native_client_node_method_demarshal,

View file

@ -46,7 +46,6 @@ static const struct spa_dict_item module_props[] = {
struct impl {
struct pw_core *core;
struct pw_type *type;
struct pw_properties *properties;
struct spa_dbus_connection *conn;
@ -211,7 +210,6 @@ static int
set_global_permissions(void *data, struct pw_global *global)
{
struct client_info *cinfo = data;
struct impl *impl = cinfo->impl;
struct pw_client *client = cinfo->client;
const struct pw_properties *props;
const char *str;
@ -222,25 +220,27 @@ set_global_permissions(void *data, struct pw_global *global)
props = pw_global_get_properties(global);
if (pw_global_get_type(global) == impl->type->core) {
switch (pw_global_get_type(global)) {
case PW_ID_INTERFACE_Core:
allowed = true;
}
else if (pw_global_get_type(global) == impl->type->factory) {
break;
case PW_ID_INTERFACE_Factory:
if (props && (str = pw_properties_get(props, "factory.name"))) {
if (strcmp(str, "client-node") == 0)
allowed = true;
}
}
else if (pw_global_get_type(global) == impl->type->node) {
break;
case PW_ID_INTERFACE_Node:
if (props && (str = pw_properties_get(props, "media.class"))) {
if (strcmp(str, "Video/Source") == 0 && cinfo->camera_allowed)
allowed = true;
}
allowed |= check_global_owner(client, global);
}
else
break;
default:
allowed = check_global_owner(client, global);
break;
}
snprintf(perms, sizeof(perms), "%d:%c--", pw_global_get_id(global), allowed ? 'r' : '-');
items[n_items++] = SPA_DICT_ITEM_INIT(PW_CORE_PROXY_PERMISSIONS_GLOBAL, perms);
pw_client_update_permissions(client, &SPA_DICT_INIT(items, n_items));
@ -393,7 +393,7 @@ core_global_added(void *data, struct pw_global *global)
struct client_info *cinfo;
int res;
if (pw_global_get_type(global) == impl->type->client) {
if (pw_global_get_type(global) == PW_ID_INTERFACE_Client) {
struct pw_client *client = pw_global_get_object(global);
res = check_sandboxed(client);
@ -432,7 +432,7 @@ core_global_removed(void *data, struct pw_global *global)
{
struct impl *impl = data;
if (pw_global_get_type(global) == impl->type->client) {
if (pw_global_get_type(global) == PW_ID_INTERFACE_Client) {
struct pw_client *client = pw_global_get_object(global);
struct client_info *cinfo;
@ -483,7 +483,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
support = pw_core_get_support(core, &n_support);
dbus = spa_support_find(support, n_support, SPA_TYPE__DBus);
dbus = spa_support_find(support, n_support, SPA_ID_INTERFACE_DBus);
if (dbus == NULL)
return -ENOTSUP;
@ -494,7 +494,6 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
pw_log_debug("module %p: new", impl);
impl->core = core;
impl->type = pw_core_get_type(core);
impl->properties = properties;
impl->conn = spa_dbus_get_connection(dbus, SPA_DBUS_TYPE_SESSION);

View file

@ -54,7 +54,6 @@ static void *create_object(void *_data,
struct pw_node *output_node, *input_node;
struct pw_port *outport, *inport;
struct pw_core *core;
struct pw_type *t;
struct pw_global *global;
struct pw_link *link;
uint32_t output_node_id, input_node_id;
@ -87,16 +86,15 @@ static void *create_object(void *_data,
client = pw_resource_get_client(resource);
core = pw_client_get_core(client);
t = pw_core_get_type(core);
global = pw_core_find_global(core, output_node_id);
if (global == NULL || pw_global_get_type(global) != t->node)
if (global == NULL || pw_global_get_type(global) != PW_ID_INTERFACE_Node)
goto no_output;
output_node = pw_global_get_object(global);
global = pw_core_find_global(core, input_node_id);
if (global == NULL || pw_global_get_type(global) != t->node)
if (global == NULL || pw_global_get_type(global) != PW_ID_INTERFACE_Node)
goto no_input;
input_node = pw_global_get_object(global);
@ -105,7 +103,7 @@ static void *create_object(void *_data,
outport = pw_node_find_port(output_node, SPA_DIRECTION_OUTPUT, SPA_ID_INVALID);
else {
global = pw_core_find_global(core, output_port_id);
if (global == NULL || pw_global_get_type(global) != t->port)
if (global == NULL || pw_global_get_type(global) != PW_ID_INTERFACE_Port)
goto no_output_port;
outport = pw_global_get_object(global);
@ -117,7 +115,7 @@ static void *create_object(void *_data,
inport = pw_node_find_port(input_node, SPA_DIRECTION_INPUT, SPA_ID_INVALID);
else {
global = pw_core_find_global(core, input_port_id);
if (global == NULL || pw_global_get_type(global) != t->port)
if (global == NULL || pw_global_get_type(global) != PW_ID_INTERFACE_Port)
goto no_output_port;
inport = pw_global_get_object(global);
@ -201,13 +199,12 @@ static const struct pw_module_events module_events = {
static int module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = pw_module_get_core(module);
struct pw_type *t = pw_core_get_type(core);
struct pw_factory *factory;
struct factory_data *data;
factory = pw_factory_new(core,
"link-factory",
t->link,
PW_ID_INTERFACE_Link,
PW_VERSION_LINK,
NULL,
sizeof(*data));

View file

@ -29,6 +29,7 @@
#include <spa/utils/hook.h>
#include <spa/param/audio/format-utils.h>
#include <spa/debug/format.h>
#include <spa/debug/types.h>
#include "pipewire/core.h"
#include "pipewire/control.h"
@ -52,30 +53,10 @@ static const struct spa_dict_item module_props[] = {
#define MIN_QUANTUM_SIZE 64
#define MAX_QUANTUM_SIZE 1024
struct type {
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_media_subtype_audio media_subtype_audio;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_media_subtype_audio_map(map, &type->media_subtype_audio);
}
struct impl {
struct type type;
struct timespec now;
struct pw_core *core;
struct pw_type *t;
struct pw_module *module;
struct spa_hook core_listener;
struct spa_hook module_listener;
@ -650,7 +631,6 @@ static int collect_audio_format(void *data, uint32_t id,
uint32_t index, uint32_t next, struct spa_pod *param)
{
struct channel_data *d = data;
struct impl *impl = d->impl;
uint32_t media_type, media_subtype;
struct spa_audio_info_raw info;
@ -658,14 +638,14 @@ static int collect_audio_format(void *data, uint32_t id,
"I", &media_type,
"I", &media_subtype);
if (media_type != impl->type.media_type.audio ||
media_subtype != impl->type.media_subtype.raw)
if (media_type != SPA_MEDIA_TYPE_audio ||
media_subtype != SPA_MEDIA_SUBTYPE_raw)
return 0;
spa_pod_fixate(param);
spa_debug_format(0, impl->t->map, param);
spa_debug_format(0, NULL, param);
if (spa_format_audio_raw_parse(param, &info, &impl->type.format_audio) < 0)
if (spa_format_audio_raw_parse(param, &info) < 0)
return 0;
if (info.channels > d->channels) {
@ -679,11 +659,10 @@ static int collect_audio_format(void *data, uint32_t id,
static int find_port_format(struct impl *impl, struct pw_port *port,
uint32_t *channels, uint32_t *rate)
{
struct pw_type *t = impl->t;
struct channel_data data = { impl, 0, 0 };
pw_port_for_each_param(port,
t->param.idEnumFormat,
SPA_ID_PARAM_EnumFormat,
0, 0, NULL,
collect_audio_format, &data);
@ -708,7 +687,7 @@ static int on_global(void *data, struct pw_global *global)
bool need_dsp;
uint64_t plugged;
if (pw_global_get_type(global) != impl->t->node)
if (pw_global_get_type(global) != PW_ID_INTERFACE_Node)
return 0;
node = pw_global_get_object(global);
@ -846,12 +825,9 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
pw_log_debug("module %p: new", impl);
impl->core = core;
impl->t = pw_core_get_type(core);
impl->module = module;
impl->properties = properties;
init_type(&impl->type, core->type.map);
spa_list_init(&impl->session_list);
clock_gettime(CLOCK_MONOTONIC, &impl->now);

View file

@ -66,7 +66,6 @@ struct port {
struct node {
struct pw_core *core;
struct pw_type *t;
struct pw_node *node;
void *user_data;
@ -80,14 +79,13 @@ struct node {
static void init_buffer(struct port *port, uint32_t id)
{
struct pw_type *t = port->node->t;
struct buffer *b = &port->buffers[id];
b->buf.id = id;
b->buf.n_metas = 0;
b->buf.metas = NULL;
b->buf.n_datas = 1;
b->buf.datas = b->datas;
b->datas[0].type = t->data.MemPtr;
b->datas[0].type = SPA_DATA_MemPtr;
b->datas[0].flags = 0;
b->datas[0].fd = -1;
b->datas[0].mapoffset = 0;
@ -153,7 +151,6 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
{
struct pw_node *node;
struct pw_port *port;
struct pw_type *t = pw_core_get_type(core);
struct node *n;
const char *api, *alias, *plugged, *str;
char node_name[128];
@ -204,7 +201,6 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
n = pw_spa_node_get_user_data(node);
n->core = core;
n->t = pw_core_get_type(core);
n->node = node;
n->channels = channels;
@ -258,7 +254,7 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
p->spa_handle, NULL,
support, n_support);
spa_handle_get_interface(p->spa_handle, t->spa_node, &iface);
spa_handle_get_interface(p->spa_handle, SPA_ID_INTERFACE_Node, &iface);
p->spa_node = iface;

View file

@ -22,7 +22,6 @@
#include <stdio.h>
#include <spa/support/log.h>
#include <spa/support/type-map.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
@ -88,55 +87,10 @@ struct port {
size_t queued_bytes;
};
struct type {
uint32_t node;
uint32_t format;
uint32_t prop_volume;
uint32_t prop_mute;
uint32_t io_prop_volume;
uint32_t io_prop_mute;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_command_node command_node;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->node = spa_type_map_get_id(map, SPA_TYPE__Node);
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->prop_mute = spa_type_map_get_id(map, SPA_TYPE_PROPS__mute);
type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume");
type->io_prop_mute = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "mute");
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
spa_type_format_audio_map(map, &type->format_audio);
spa_type_audio_format_map(map, &type->audio_format);
spa_type_command_node_map(map, &type->command_node);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_param_buffers_map(map, &type->param_buffers);
spa_type_param_meta_map(map, &type->param_meta);
spa_type_param_io_map(map, &type->param_io);
}
struct impl {
struct spa_handle handle;
struct spa_node node;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
const struct spa_node_callbacks *callbacks;
@ -188,13 +142,16 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman
this = SPA_CONTAINER_OF(node, struct impl, node);
if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Start:
this->started = true;
} else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) {
break;
case SPA_ID_COMMAND_NODE_Pause:
this->started = false;
} else
break;
default:
return -ENOTSUP;
}
return 0;
}
@ -365,29 +322,28 @@ static int port_enum_formats(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
switch (*index) {
case 0:
if (this->have_format) {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", this->format.info.raw.format,
":", t->format_audio.layout, "i", this->format.info.raw.layout,
":", t->format_audio.rate, "i", this->format.info.raw.rate,
":", t->format_audio.channels, "i", this->format.info.raw.channels);
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", this->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "i", this->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels);
} else {
*param = spa_pod_builder_object(builder,
t->param.idEnumFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", t->audio_format.F32,
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", t->format_audio.rate, "iru", 44100,
SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
":", SPA_FORMAT_AUDIO_rate, "iru", 44100,
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
":", t->format_audio.channels, "iru", 1);
":", SPA_FORMAT_AUDIO_channels, "iru", 1);
}
break;
default:
@ -403,7 +359,6 @@ static int port_get_format(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct type *t = &this->type;
struct port *port = GET_PORT(this, direction, port_id);
if (!port->have_format)
@ -412,13 +367,13 @@ static int port_get_format(struct spa_node *node,
return 0;
*param = spa_pod_builder_object(builder,
t->param.idFormat, t->format,
"I", t->media_type.audio,
"I", t->media_subtype.raw,
":", t->format_audio.format, "I", this->format.info.raw.format,
":", t->format_audio.layout, "i", this->format.info.raw.layout,
":", t->format_audio.rate, "i", this->format.info.raw.rate,
":", t->format_audio.channels, "i", this->format.info.raw.channels);
SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", this->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "i", this->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels);
return 1;
}
@ -432,7 +387,6 @@ impl_node_port_enum_params(struct spa_node *node,
struct spa_pod_builder *builder)
{
struct impl *this;
struct type *t;
struct port *port;
struct spa_pod *param;
struct spa_pod_builder b = { 0 };
@ -444,7 +398,6 @@ impl_node_port_enum_params(struct spa_node *node,
spa_return_val_if_fail(builder != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -453,83 +406,83 @@ impl_node_port_enum_params(struct spa_node *node,
next:
spa_pod_builder_init(&b, buffer, sizeof(buffer));
if (id == t->param.idList) {
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta,
t->param_io.idBuffers,
t->param_io.idControl,
t->param_io.idPropsIn };
switch (id) {
case SPA_ID_PARAM_List:
{
uint32_t list[] = { SPA_ID_PARAM_EnumFormat,
SPA_ID_PARAM_Format,
SPA_ID_PARAM_Buffers,
SPA_ID_PARAM_Meta,
SPA_ID_PARAM_IO };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(&b, id, t->param.List,
":", t->param.listId, "I", list[*index]);
param = spa_pod_builder_object(&b, id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", list[*index]);
else
return 0;
break;
}
else if (id == t->param.idEnumFormat) {
case SPA_ID_PARAM_EnumFormat:
if ((res = port_enum_formats(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idFormat) {
break;
case SPA_ID_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, &param, &b)) <= 0)
return res;
}
else if (id == t->param.idBuffers) {
break;
case SPA_ID_PARAM_Buffers:
if (!port->have_format)
return -EIO;
if (*index > 0)
return 0;
param = spa_pod_builder_object(&b,
id, t->param_buffers.Buffers,
":", t->param_buffers.size, "iru", 1024 * this->stride,
SPA_POD_PROP_MIN_MAX(16 * this->stride, INT32_MAX / this->stride),
":", t->param_buffers.stride, "i", this->stride,
":", t->param_buffers.buffers, "iru", 1,
id, SPA_ID_OBJECT_ParamBuffers,
":", SPA_PARAM_BUFFERS_buffers, "iru", 1,
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
":", t->param_buffers.align, "i", 16);
}
else if (id == t->param.idMeta) {
":", SPA_PARAM_BUFFERS_blocks, "i", 1,
":", SPA_PARAM_BUFFERS_size, "iru", 1024 * this->stride,
SPA_POD_PROP_MIN_MAX(16 * this->stride, INT32_MAX / this->stride),
":", SPA_PARAM_BUFFERS_stride, "i", this->stride,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
case SPA_ID_PARAM_Meta:
if (!port->have_format)
return -EIO;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof(struct spa_meta_header));
id, SPA_ID_OBJECT_ParamMeta,
":", SPA_PARAM_META_type, "I", SPA_META_Header,
":", SPA_PARAM_META_size, "i", sizeof(struct spa_meta_header));
break;
default:
return 0;
}
}
else if (id == t->param_io.idBuffers) {
break;
case SPA_ID_PARAM_IO:
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Buffers,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
else if (id == t->param_io.idControl) {
switch (*index) {
case 0:
case 1:
param = spa_pod_builder_object(&b,
id, t->param_io.Control,
":", t->param_io.id, "I", t->io.ControlRange,
":", t->param_io.size, "i", sizeof(struct spa_io_control_range));
id, SPA_ID_OBJECT_ParamIO,
":", SPA_PARAM_IO_id, "I", SPA_ID_IO_ControlRange,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_control_range));
break;
default:
return 0;
}
}
break;
#if 0
else if (id == t->param_io.idPropsIn) {
struct port_props *p = &port->props;
@ -558,8 +511,10 @@ impl_node_port_enum_params(struct spa_node *node,
return 0;
}
}
else
#endif
default:
return -ENOENT;
}
(*index)++;
@ -612,7 +567,6 @@ static int port_set_format(struct spa_node *node,
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port;
struct type *t = &this->type;
port = GET_PORT(this, direction, port_id);
@ -630,18 +584,18 @@ static int port_set_format(struct spa_node *node,
"I", &info.media_type,
"I", &info.media_subtype);
if (info.media_type != t->media_type.audio ||
info.media_subtype != t->media_subtype.raw)
if (info.media_type != SPA_MEDIA_TYPE_audio ||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
return -EINVAL;
if (spa_format_audio_raw_parse(format, &info.info.raw, &t->format_audio) < 0)
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
return -EINVAL;
if (this->have_format) {
if (memcmp(&info, &this->format, sizeof(struct spa_audio_info)))
return -EINVAL;
} else {
if (info.info.raw.format != t->audio_format.F32)
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32)
return -EINVAL;
this->stride = sizeof(float);
@ -667,16 +621,14 @@ impl_node_port_set_param(struct spa_node *node,
const struct spa_pod *param)
{
struct impl *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
}
else
@ -693,12 +645,10 @@ impl_node_port_use_buffers(struct spa_node *node,
struct impl *this;
struct port *port;
uint32_t i;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
@ -719,11 +669,11 @@ impl_node_port_use_buffers(struct spa_node *node,
b->buffer = buffers[i];
b->flags = 0;
b->id = i;
b->h = spa_buffer_find_meta_data(buffers[i], t->meta.Header, sizeof(*b->h));
b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h));
if (!((d[0].type == t->data.MemPtr ||
d[0].type == t->data.MemFd ||
d[0].type == t->data.DmaBuf) && d[0].data != NULL)) {
if (!((d[0].type == SPA_DATA_MemPtr ||
d[0].type == SPA_DATA_MemFd ||
d[0].type == SPA_DATA_DmaBuf) && d[0].data != NULL)) {
spa_log_error(this->log, NAME " %p: invalid memory on buffer %p", this,
buffers[i]);
return -EINVAL;
@ -755,21 +705,20 @@ impl_node_port_set_io(struct spa_node *node,
{
struct impl *this;
struct port *port;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct impl, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
port = GET_PORT(this, direction, port_id);
if (id == t->io.Buffers)
if (id == SPA_ID_IO_Buffers)
port->io = data;
else if (id == t->io.ControlRange)
else if (id == SPA_ID_IO_ControlRange)
port->ctrl = data;
#if 0
else if (id == t->io_prop_volume && direction == SPA_DIRECTION_INPUT)
if (data && size >= sizeof(struct spa_pod_double))
port->io_volume = &SPA_POD_VALUE(struct spa_pod_double, data);
@ -780,6 +729,7 @@ impl_node_port_set_io(struct spa_node *node,
port->io_mute = &SPA_POD_VALUE(struct spa_pod_bool, data);
else
port->io_mute = &port->props.mute;
#endif
else
return -ENOENT;
@ -985,7 +935,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
this = (struct impl *) handle;
if (interface_id == this->type.node)
if (interface_id == SPA_ID_INTERFACE_Node)
*interface = &this->node;
else
return -ENOENT;
@ -1025,16 +975,9 @@ impl_init(const struct spa_handle_factory *factory,
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE__Log) == 0)
if (support[i].type == SPA_ID_INTERFACE_Log)
this->log = support[i].data;
}
if (this->map == NULL) {
spa_log_error(this->log, "an id-map is needed");
return -EINVAL;
}
init_type(&this->type, this->map);
this->node = impl_node;
@ -1049,7 +992,7 @@ impl_init(const struct spa_handle_factory *factory,
}
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_ID_INTERFACE_Node,},
};
static int

View file

@ -29,6 +29,7 @@
#include <spa/pod/iter.h>
#include <spa/debug/pod.h>
#include <spa/debug/types.h>
#include "config.h"
@ -108,6 +109,7 @@ struct client_data {
bool busy;
};
#if 0
static bool pod_remap_data(uint32_t type, void *body, uint32_t size, struct pw_map *types)
{
void *t;
@ -172,6 +174,7 @@ static bool pod_remap_data(uint32_t type, void *body, uint32_t size, struct pw_m
}
return true;
}
#endif
static void
process_messages(struct client_data *data)
@ -227,13 +230,15 @@ process_messages(struct client_data *data)
continue;
}
#if 0
if (demarshal[opcode].flags & PW_PROTOCOL_NATIVE_REMAP)
if (!pod_remap_data(SPA_POD_TYPE_STRUCT, message, size, &client->types))
goto invalid_message;
#endif
if (debug_messages) {
fprintf(stderr, "<<<<<<<<< in: %d %d %d\n", id, opcode, size);
spa_debug_pod(0, core->type.map, (struct spa_pod *)message);
spa_debug_pod(0, spa_debug_types, (struct spa_pod *)message);
}
if (demarshal[opcode].func(resource, message, size) < 0)
goto invalid_message;
@ -557,6 +562,7 @@ on_remote_data(void *data, int fd, enum spa_io mask)
continue;
}
#if 0
if (demarshal[opcode].flags & PW_PROTOCOL_NATIVE_REMAP) {
if (!pod_remap_data(SPA_POD_TYPE_STRUCT, message, size, &this->types)) {
pw_log_error
@ -565,9 +571,10 @@ on_remote_data(void *data, int fd, enum spa_io mask)
continue;
}
}
#endif
if (debug_messages) {
fprintf(stderr, "<<<<<<<<< in: %d %d %d\n", id, opcode, size);
spa_debug_pod(0, core->type.map, (struct spa_pod *)message);
spa_debug_pod(0, spa_debug_types, (struct spa_pod *)message);
}
if (demarshal[opcode].func(proxy, message, size) < 0) {
pw_log_error ("protocol-native %p: invalid message received %u for %u", this,

View file

@ -365,21 +365,6 @@ pw_protocol_native_connection_begin_resource(struct pw_protocol_native_connectio
uint8_t opcode)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
uint32_t diff, base, i, b;
struct pw_client *client = resource->client;
struct pw_core *core = client->core;
const char **types;
base = client->n_types;
diff = spa_type_map_get_size(core->type.map) - base;
if (diff > 0) {
types = alloca(diff * sizeof(char *));
for (i = 0, b = base; i < diff; i++, b++)
types[i] = spa_type_map_get_type(core->type.map, b);
client->n_types += diff;
pw_core_resource_update_types(client->core_resource, base, types, diff);
}
impl->dest_id = resource->id;
impl->opcode = opcode;
@ -394,21 +379,6 @@ pw_protocol_native_connection_begin_proxy(struct pw_protocol_native_connection *
uint8_t opcode)
{
struct impl *impl = SPA_CONTAINER_OF(conn, struct impl, this);
uint32_t diff, base, i, b;
const char **types;
struct pw_remote *remote = proxy->remote;
struct pw_core *core = remote->core;
base = remote->n_types;
diff = spa_type_map_get_size(core->type.map) - base;
if (diff > 0) {
types = alloca(diff * sizeof(char *));
for (i = 0, b = base; i < diff; i++, b++)
types[i] = spa_type_map_get_type(core->type.map, b);
remote->n_types += diff;
pw_core_proxy_update_types(remote->core_proxy, base, types, diff);
}
impl->dest_id = proxy->id;
impl->opcode = opcode;
@ -435,7 +405,7 @@ pw_protocol_native_connection_end(struct pw_protocol_native_connection *conn,
if (debug_messages) {
fprintf(stderr, ">>>>>>>>> out: %d %d %d\n", impl->dest_id, impl->opcode, size);
spa_debug_pod(0, impl->core->type.map, (struct spa_pod *)p);
spa_debug_pod(0, spa_debug_types, (struct spa_pod *)p);
}
spa_hook_list_call(&conn->listener_list,
struct pw_protocol_native_connection_events, need_flush, 0);

View file

@ -158,28 +158,6 @@ core_marshal_destroy(void *object, uint32_t id)
pw_protocol_native_end_proxy(proxy, b);
}
static void
core_marshal_update_types_client(void *object, uint32_t first_id, const char **types, uint32_t n_types)
{
struct pw_proxy *proxy = object;
struct spa_pod_builder *b;
uint32_t i;
b = pw_protocol_native_begin_proxy(proxy, PW_CORE_PROXY_METHOD_UPDATE_TYPES);
spa_pod_builder_add(b,
"["
" i", first_id,
" i", n_types, NULL);
for (i = 0; i < n_types; i++) {
spa_pod_builder_add(b, "s", types[i], NULL);
}
spa_pod_builder_add(b, "]", NULL);
pw_protocol_native_end_proxy(proxy, b);
}
static int core_demarshal_info(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
@ -260,30 +238,6 @@ static int core_demarshal_remove_id(void *object, void *data, size_t size)
return 0;
}
static int core_demarshal_update_types_client(void *object, void *data, size_t size)
{
struct pw_proxy *proxy = object;
struct spa_pod_parser prs;
uint32_t first_id, n_types;
const char **types;
uint32_t i;
spa_pod_parser_init(&prs, data, size, 0);
if (spa_pod_parser_get(&prs,
"["
" i", &first_id,
" i", &n_types, NULL) < 0)
return -EINVAL;
types = alloca(n_types * sizeof(char *));
for (i = 0; i < n_types; i++) {
if (spa_pod_parser_get(&prs, "s", &types[i], NULL) < 0)
return -EINVAL;
}
pw_proxy_notify(proxy, struct pw_core_proxy_events, update_types, 0, first_id, types, n_types);
return 0;
}
static void core_marshal_info(void *object, struct pw_core_info *info)
{
struct pw_resource *resource = object;
@ -360,28 +314,6 @@ static void core_marshal_remove_id(void *object, uint32_t id)
pw_protocol_native_end_resource(resource, b);
}
static void
core_marshal_update_types_server(void *object, uint32_t first_id, const char **types, uint32_t n_types)
{
struct pw_resource *resource = object;
struct spa_pod_builder *b;
uint32_t i;
b = pw_protocol_native_begin_resource(resource, PW_CORE_PROXY_EVENT_UPDATE_TYPES);
spa_pod_builder_add(b,
"[",
"i", first_id,
"i", n_types, NULL);
for (i = 0; i < n_types; i++) {
spa_pod_builder_add(b, "s", types[i], NULL);
}
spa_pod_builder_add(b, "]", NULL);
pw_protocol_native_end_resource(resource, b);
}
static int core_demarshal_client_update(void *object, void *data, size_t size)
{
struct pw_resource *resource = object;
@ -516,30 +448,6 @@ static int core_demarshal_destroy(void *object, void *data, size_t size)
return 0;
}
static int core_demarshal_update_types_server(void *object, void *data, size_t size)
{
struct pw_resource *resource = object;
struct spa_pod_parser prs;
uint32_t first_id, n_types;
const char **types;
uint32_t i;
spa_pod_parser_init(&prs, data, size, 0);
if (spa_pod_parser_get(&prs,
"["
"i", &first_id,
"i", &n_types, NULL) < 0)
return -EINVAL;
types = alloca(n_types * sizeof(char *));
for (i = 0; i < n_types; i++) {
if (spa_pod_parser_get(&prs, "s", &types[i], NULL) < 0)
return -EINVAL;
}
pw_resource_do(resource, struct pw_core_proxy_methods, update_types, 0, first_id, types, n_types);
return 0;
}
static void registry_marshal_global(void *object, uint32_t id, uint32_t parent_id, uint32_t permissions,
uint32_t type, uint32_t version, const struct spa_dict *props)
{
@ -1164,7 +1072,6 @@ static void registry_marshal_bind(void *object, uint32_t id,
static const struct pw_core_proxy_methods pw_protocol_native_core_method_marshal = {
PW_VERSION_CORE_PROXY_METHODS,
&core_marshal_hello,
&core_marshal_update_types_client,
&core_marshal_sync,
&core_marshal_get_registry,
&core_marshal_client_update,
@ -1175,7 +1082,6 @@ static const struct pw_core_proxy_methods pw_protocol_native_core_method_marshal
static const struct pw_protocol_native_demarshal pw_protocol_native_core_method_demarshal[PW_CORE_PROXY_METHOD_NUM] = {
{ &core_demarshal_hello, 0, },
{ &core_demarshal_update_types_server, 0, },
{ &core_demarshal_sync, 0, },
{ &core_demarshal_get_registry, 0, },
{ &core_demarshal_client_update, 0, },
@ -1186,7 +1092,6 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_core_method_
static const struct pw_core_proxy_events pw_protocol_native_core_event_marshal = {
PW_VERSION_CORE_PROXY_EVENTS,
&core_marshal_update_types_server,
&core_marshal_done,
&core_marshal_error,
&core_marshal_remove_id,
@ -1194,7 +1099,6 @@ static const struct pw_core_proxy_events pw_protocol_native_core_event_marshal =
};
static const struct pw_protocol_native_demarshal pw_protocol_native_core_event_demarshal[PW_CORE_PROXY_EVENT_NUM] = {
{ &core_demarshal_update_types_client, 0, },
{ &core_demarshal_done, 0, },
{ &core_demarshal_error, 0, },
{ &core_demarshal_remove_id, 0, },
@ -1202,7 +1106,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_core_event_d
};
static const struct pw_protocol_marshal pw_protocol_native_core_marshal = {
PW_TYPE_INTERFACE__Core,
PW_ID_INTERFACE_Core,
PW_VERSION_CORE,
&pw_protocol_native_core_method_marshal,
pw_protocol_native_core_method_demarshal,
@ -1233,7 +1137,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_registry_eve
};
const struct pw_protocol_marshal pw_protocol_native_registry_marshal = {
PW_TYPE_INTERFACE__Registry,
PW_ID_INTERFACE_Registry,
PW_VERSION_REGISTRY,
&pw_protocol_native_registry_method_marshal,
pw_protocol_native_registry_method_demarshal,
@ -1253,7 +1157,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_module_event
};
const struct pw_protocol_marshal pw_protocol_native_module_marshal = {
PW_TYPE_INTERFACE__Module,
PW_ID_INTERFACE_Module,
PW_VERSION_MODULE,
NULL, NULL, 0,
&pw_protocol_native_module_event_marshal,
@ -1271,7 +1175,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_factory_even
};
const struct pw_protocol_marshal pw_protocol_native_factory_marshal = {
PW_TYPE_INTERFACE__Factory,
PW_ID_INTERFACE_Factory,
PW_VERSION_FACTORY,
NULL, NULL, 0,
&pw_protocol_native_factory_event_marshal,
@ -1300,7 +1204,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_node_event_d
};
static const struct pw_protocol_marshal pw_protocol_native_node_marshal = {
PW_TYPE_INTERFACE__Node,
PW_ID_INTERFACE_Node,
PW_VERSION_NODE,
&pw_protocol_native_node_method_marshal,
pw_protocol_native_node_method_demarshal,
@ -1332,7 +1236,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_port_event_d
};
static const struct pw_protocol_marshal pw_protocol_native_port_marshal = {
PW_TYPE_INTERFACE__Port,
PW_ID_INTERFACE_Port,
PW_VERSION_PORT,
&pw_protocol_native_port_method_marshal,
pw_protocol_native_port_method_demarshal,
@ -1352,7 +1256,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_client_event
};
static const struct pw_protocol_marshal pw_protocol_native_client_marshal = {
PW_TYPE_INTERFACE__Client,
PW_ID_INTERFACE_Client,
PW_VERSION_CLIENT,
NULL, NULL, 0,
&pw_protocol_native_client_event_marshal,
@ -1370,7 +1274,7 @@ static const struct pw_protocol_native_demarshal pw_protocol_native_link_event_d
};
static const struct pw_protocol_marshal pw_protocol_native_link_marshal = {
PW_TYPE_INTERFACE__Link,
PW_ID_INTERFACE_Link,
PW_VERSION_LINK,
NULL, NULL, 0,
&pw_protocol_native_link_event_marshal,

View file

@ -49,7 +49,6 @@ static const struct spa_dict_item module_props[] = {
struct impl {
struct pw_core *core;
struct pw_type *type;
struct pw_properties *properties;
struct spa_loop *loop;
@ -482,7 +481,7 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
support = pw_core_get_support(core, &n_support);
loop = spa_support_find(support, n_support, SPA_TYPE_LOOP__DataLoop);
loop = spa_support_find(support, n_support, SPA_ID_INTERFACE_DataLoop);
if (loop == NULL)
return -ENOTSUP;
@ -493,7 +492,6 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
pw_log_debug("module %p: new", impl);
impl->core = core;
impl->type = pw_core_get_type(core);
impl->properties = properties;
impl->loop = loop;

View file

@ -37,7 +37,6 @@ static const struct spa_dict_item module_props[] = {
struct impl {
struct pw_core *core;
struct pw_type *t;
struct pw_properties *properties;
struct spa_hook module_listener;
@ -128,7 +127,7 @@ core_global_added(void *data, struct pw_global *global)
{
struct impl *impl = data;
if (pw_global_get_type(global) == impl->t->node) {
if (pw_global_get_type(global) == PW_ID_INTERFACE_Node) {
struct pw_node *node = pw_global_get_object(global);
struct node_info *info;
@ -148,7 +147,7 @@ core_global_removed(void *data, struct pw_global *global)
{
struct impl *impl = data;
if (pw_global_get_type(global) == impl->t->node) {
if (pw_global_get_type(global) == PW_ID_INTERFACE_Node) {
struct pw_node *node = pw_global_get_object(global);
struct node_info *info;
@ -207,7 +206,6 @@ static int module_init(struct pw_module *module, struct pw_properties *propertie
pw_log_debug("module %p: new", impl);
impl->core = pw_module_get_core(module);
impl->t = pw_core_get_type(impl->core);
impl->properties = properties;
spa_list_init(&impl->node_list);

View file

@ -172,13 +172,12 @@ static const struct pw_module_events module_events = {
static int module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = pw_module_get_core(module);
struct pw_type *t = pw_core_get_type(core);
struct pw_factory *factory;
struct factory_data *data;
factory = pw_factory_new(core,
"spa-node-factory",
t->node,
PW_ID_INTERFACE_Node,
PW_VERSION_NODE,
NULL,
sizeof(*data));

View file

@ -50,7 +50,6 @@ struct impl {
struct pw_spa_monitor this;
struct pw_core *core;
struct pw_type *t;
struct pw_global *parent;
void *hnd;
@ -71,18 +70,17 @@ static struct monitor_item *add_item(struct pw_spa_monitor *this,
struct spa_handle_factory *factory;
enum spa_monitor_item_state state;
struct spa_pod *info = NULL;
struct pw_type *t = pw_core_get_type(impl->core);
const struct spa_support *support;
enum pw_spa_node_flags flags;
uint32_t n_support;
if (spa_pod_object_parse(item,
":",t->monitor.id, "s", &id,
":",t->monitor.state, "i", &state,
":",t->monitor.name, "s", &name,
":",t->monitor.klass, "s", &klass,
":",t->monitor.factory, "p", &factory,
":",t->monitor.info, "T", &info, NULL) < 0)
":", SPA_MONITOR_ITEM_id, "s", &id,
":", SPA_MONITOR_ITEM_state, "i", &state,
":", SPA_MONITOR_ITEM_name, "s", &name,
":", SPA_MONITOR_ITEM_class, "s", &klass,
":", SPA_MONITOR_ITEM_factory, "p", &factory,
":", SPA_MONITOR_ITEM_info, "T", &info, NULL) < 0)
return NULL;
pw_log_debug("monitor %p: add: \"%s\" (%s)", this, name, id);
@ -120,7 +118,7 @@ static struct monitor_item *add_item(struct pw_spa_monitor *this,
pw_log_error("can't make factory instance: %d", res);
return NULL;
}
if ((res = spa_handle_get_interface(handle, t->spa_node, &node_iface)) < 0) {
if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &node_iface)) < 0) {
pw_log_error("can't get NODE interface: %d", res);
return NULL;
}
@ -165,14 +163,12 @@ void destroy_item(struct monitor_item *mitem)
static void remove_item(struct pw_spa_monitor *this, struct spa_pod *item, uint64_t now)
{
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
struct monitor_item *mitem;
const char *name, *id;
struct pw_type *t = pw_core_get_type(impl->core);
if (spa_pod_object_parse(item,
":",t->monitor.name, "s", &name,
":",t->monitor.id, "s", &id, NULL) < 0)
":", SPA_MONITOR_ITEM_name, "s", &name,
":", SPA_MONITOR_ITEM_id, "s", &id, NULL) < 0)
return;
pw_log_debug("monitor %p: remove: \"%s\" (%s)", this, name, id);
@ -183,16 +179,14 @@ static void remove_item(struct pw_spa_monitor *this, struct spa_pod *item, uint6
static void change_item(struct pw_spa_monitor *this, struct spa_pod *item, uint64_t now)
{
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
struct monitor_item *mitem;
const char *name, *id;
struct pw_type *t = pw_core_get_type(impl->core);
enum spa_monitor_item_state state;
if (spa_pod_object_parse(item,
":",t->monitor.name, "s", &name,
":",t->monitor.state, "i", &state,
":",t->monitor.id, "s", &id, NULL) < 0)
":", SPA_MONITOR_ITEM_name, "s", &name,
":", SPA_MONITOR_ITEM_state, "i", &state,
":", SPA_MONITOR_ITEM_id, "s", &id, NULL) < 0)
return;
pw_log_debug("monitor %p: change: \"%s\" (%s)", this, name, id);
@ -217,22 +211,24 @@ static void on_monitor_event(void *data, struct spa_event *event)
{
struct impl *impl = data;
struct pw_spa_monitor *this = &impl->this;
struct pw_type *t = pw_core_get_type(impl->core);
struct timespec now;
uint64_t now_nsec;
struct spa_pod *item;
clock_gettime(CLOCK_MONOTONIC, &now);
now_nsec = now.tv_sec * SPA_NSEC_PER_SEC + now.tv_nsec;
if (SPA_EVENT_TYPE(event) == t->monitor.Added) {
struct spa_pod *item = SPA_POD_CONTENTS(struct spa_event, event);
item = SPA_POD_CONTENTS(struct spa_event, event);
switch(SPA_EVENT_TYPE(event)) {
case SPA_ID_EVENT_MONITOR_Added:
add_item(this, item, now_nsec);
} else if (SPA_EVENT_TYPE(event) == t->monitor.Removed) {
struct spa_pod *item = SPA_POD_CONTENTS(struct spa_event, event);
break;
case SPA_ID_EVENT_MONITOR_Removed:
remove_item(this, item, now_nsec);
} else if (SPA_EVENT_TYPE(event) == t->monitor.Changed) {
struct spa_pod *item = SPA_POD_CONTENTS(struct spa_event, event);
break;
case SPA_ID_EVENT_MONITOR_Changed:
change_item(this, item, now_nsec);
break;
}
}
@ -287,7 +283,6 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
char *filename;
const struct spa_support *support;
uint32_t n_support;
struct pw_type *t = pw_core_get_type(core);
asprintf(&filename, "%s/%s.so", dir, lib);
@ -320,14 +315,13 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
pw_log_error("can't make factory instance: %d", res);
goto init_failed;
}
if ((res = spa_handle_get_interface(handle, t->spa_monitor, &iface)) < 0) {
if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Monitor, &iface)) < 0) {
pw_log_error("can't get MONITOR interface: %d", res);
goto interface_failed;
}
impl = calloc(1, sizeof(struct impl) + user_data_size);
impl->core = core;
impl->t = t;
impl->parent = parent;
impl->hnd = hnd;

View file

@ -28,6 +28,7 @@
#include <spa/node/node.h>
#include <spa/param/props.h>
#include <spa/pod/iter.h>
#include <spa/debug/types.h>
#include "spa-node.h"
#include "pipewire/node.h"
@ -158,24 +159,25 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
struct spa_pod *props;
void *state = NULL;
const char *key;
struct pw_type *t = pw_core_get_type(core);
uint32_t index = 0;
uint8_t buf[2048];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buf, sizeof(buf));
if ((res = spa_node_enum_params(spa_node, t->param.idProps, &index, NULL, &props, &b)) <= 0) {
if ((res = spa_node_enum_params(spa_node, SPA_ID_PARAM_Props, &index, NULL, &props, &b)) <= 0) {
pw_log_debug("spa_node_get_props failed: %d", res);
return res;
}
while ((key = pw_properties_iterate(pw_props, &state))) {
struct spa_pod_prop *prop;
uint32_t id;
uint32_t id = 0;
#if 0
if (!spa_type_is_a(key, SPA_TYPE_PROPS_BASE))
continue;
id = spa_type_map_get_id(t->map, key);
#endif
id = spa_debug_type_find_id(spa_debug_types, key);
if (id == SPA_ID_INVALID)
continue;
@ -191,7 +193,7 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
break;
case SPA_POD_TYPE_ID:
SPA_POD_VALUE(struct spa_pod_id, &prop->body.value) =
spa_type_map_get_id(t->map, value);
spa_debug_type_find_id(spa_debug_types, value);
break;
case SPA_POD_TYPE_INT:
SPA_POD_VALUE(struct spa_pod_int, &prop->body.value) =
@ -217,7 +219,7 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
}
}
if ((res = spa_node_set_param(spa_node, t->param.idProps, 0, props)) < 0) {
if ((res = spa_node_set_param(spa_node, SPA_ID_PARAM_Props, 0, props)) < 0) {
pw_log_debug("spa_node_set_props failed: %d", res);
return res;
}
@ -249,7 +251,6 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
const char *dir;
const struct spa_support *support;
uint32_t n_support;
struct pw_type *t = pw_core_get_type(core);
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL)
dir = PLUGINDIR;
@ -292,7 +293,7 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
if (SPA_RESULT_IS_ASYNC(res))
flags |= PW_SPA_NODE_FLAG_ASYNC;
if ((res = spa_handle_get_interface(handle, t->spa_node, &iface)) < 0) {
if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) {
pw_log_error("can't get node interface %d", res);
goto interface_failed;
}

View file

@ -228,7 +228,7 @@ int pw_client_register(struct pw_client *client,
client->registered = true;
client->global = pw_global_new(core,
core->type.client, PW_VERSION_CLIENT,
PW_ID_INTERFACE_Client, PW_VERSION_CLIENT,
properties,
client);
if (client->global == NULL)

View file

@ -18,6 +18,7 @@
*/
#include <spa/pod/parser.h>
#include <spa/debug/types.h>
#include <pipewire/control.h>
#include <pipewire/private.h>
@ -37,7 +38,6 @@ pw_control_new(struct pw_core *core,
struct impl *impl;
struct pw_control *this;
enum spa_direction direction;
struct pw_type *t = &core->type;
impl = calloc(1, sizeof(struct impl) + user_data_size);
if (impl == NULL)
@ -45,7 +45,9 @@ pw_control_new(struct pw_core *core,
this = &impl->this;
direction = spa_pod_is_object_id(param, t->param_io.idPropsOut) ?
direction = SPA_DIRECTION_OUTPUT;
#if 0
direction = spa_pod_is_object_id(param, SPA_ID_PARAM_PropsOut) ?
SPA_DIRECTION_OUTPUT : SPA_DIRECTION_INPUT;
if (spa_pod_object_parse(param,
@ -53,9 +55,10 @@ pw_control_new(struct pw_core *core,
":", t->param_io.size, "i", &this->size,
":", t->param.propId, "I", &this->prop_id) < 0)
goto exit_free;
#endif
pw_log_debug("control %p: new %s %d", this,
spa_type_map_get_type(t->map, this->prop_id), direction);
spa_debug_type_find_name(spa_debug_types, this->prop_id), direction);
this->core = core;
this->port = port;
@ -77,8 +80,8 @@ pw_control_new(struct pw_core *core,
return this;
exit_free:
free(impl);
// exit_free:
// free(impl);
exit:
return NULL;
}
@ -155,7 +158,7 @@ int pw_control_link(struct pw_control *control, struct pw_control *other)
impl = SPA_CONTAINER_OF(control, struct impl, this);
pw_log_debug("control %p: link to %p %s", control, other,
spa_type_map_get_type(control->core->type.map, control->prop_id));
spa_debug_type_find_name(spa_debug_types, control->prop_id));
if (impl->mem == NULL) {
if ((res = pw_memblock_alloc(PW_MEMBLOCK_FLAG_WITH_FD |

View file

@ -25,6 +25,7 @@
#include <spa/support/dbus.h>
#include <spa/debug/format.h>
#include <spa/debug/types.h>
#include <pipewire/pipewire.h>
#include <pipewire/private.h>
@ -66,7 +67,7 @@ static void registry_bind(void *object, uint32_t id,
goto wrong_interface;
pw_log_debug("global %p: bind global id %d, iface %s to %d", global, id,
spa_type_map_get_type(core->type.map, type), new_id);
spa_debug_type_find_name(spa_debug_types, type), new_id);
if (pw_global_bind(global, client, permissions, version, new_id) < 0)
goto exit;
@ -147,7 +148,7 @@ static void core_get_registry(void *object, uint32_t version, uint32_t new_id)
registry_resource = pw_resource_new(client,
new_id,
PW_PERM_RWX,
this->type.registry,
PW_ID_INTERFACE_Registry,
version,
sizeof(*data));
if (registry_resource == NULL)
@ -266,24 +267,9 @@ static void core_destroy(void *object, uint32_t id)
pw_global_destroy(global);
}
static void core_update_types(void *object, uint32_t first_id, const char **types, uint32_t n_types)
{
struct pw_resource *resource = object;
struct pw_core *this = resource->core;
struct pw_client *client = resource->client;
int i;
for (i = 0; i < n_types; i++, first_id++) {
uint32_t this_id = spa_type_map_get_id(this->type.map, types[i]);
if (!pw_map_insert_at(&client->types, first_id, PW_MAP_ID_TO_PTR(this_id)))
pw_log_error("can't add type %d->%d for client", first_id, this_id);
}
}
static const struct pw_core_proxy_methods core_methods = {
PW_VERSION_CORE_PROXY_METHODS,
.hello = core_hello,
.update_types = core_update_types,
.sync = core_sync,
.get_registry = core_get_registry,
.client_update = core_client_update,
@ -389,18 +375,14 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro
this->data_loop = pw_data_loop_get_loop(this->data_loop_impl);
this->main_loop = main_loop;
pw_type_init(&this->type);
pw_map_init(&this->globals, 128, 32);
this->support[0] = SPA_SUPPORT_INIT(SPA_TYPE__TypeMap, this->type.map);
this->support[1] = SPA_SUPPORT_INIT(SPA_TYPE_LOOP__DataLoop, this->data_loop->loop);
this->support[2] = SPA_SUPPORT_INIT(SPA_TYPE_LOOP__MainLoop, this->main_loop->loop);
this->support[3] = SPA_SUPPORT_INIT(SPA_TYPE__LoopUtils, this->main_loop->utils);
this->support[4] = SPA_SUPPORT_INIT(SPA_TYPE__Log, pw_log_get());
this->support[5] = SPA_SUPPORT_INIT(SPA_TYPE__DBus, pw_get_spa_dbus(this->main_loop));
this->n_support = 6;
pw_log_debug("%p", this->support[5].data);
this->support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, this->data_loop->loop);
this->support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, this->main_loop->loop);
this->support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_LoopUtils, this->main_loop->utils);
this->support[3] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, pw_log_get());
this->support[4] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DBus, pw_get_spa_dbus(this->main_loop));
this->n_support = 5;
pw_data_loop_start(this->data_loop_impl);
@ -437,7 +419,7 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro
this->sc_pagesize = sysconf(_SC_PAGESIZE);
this->global = pw_global_new(this,
this->type.core,
PW_ID_INTERFACE_Core,
PW_VERSION_CORE,
pw_properties_new(
PW_CORE_PROP_USER_NAME, this->info.user_name,
@ -521,11 +503,6 @@ void pw_core_add_listener(struct pw_core *core,
spa_hook_list_append(&core->listener_list, listener, events, data);
}
struct pw_type *pw_core_get_type(struct pw_core *core)
{
return &core->type;
}
const struct spa_support *pw_core_get_support(struct pw_core *core, uint32_t *n_support)
{
*n_support = core->n_support;
@ -731,7 +708,6 @@ int pw_core_find_format(struct pw_core *core,
uint32_t out_state, in_state;
int res;
uint32_t iidx = 0, oidx = 0;
struct pw_type *t = &core->type;
out_state = output->state;
in_state = input->state;
@ -750,7 +726,7 @@ int pw_core_find_format(struct pw_core *core,
/* only input needs format */
if ((res = spa_node_port_enum_params(output->node->node,
output->direction, output->port_id,
t->param.idFormat, &oidx,
SPA_ID_PARAM_Format, &oidx,
NULL, format, builder)) <= 0) {
if (res == 0)
res = -EBADF;
@ -759,12 +735,12 @@ int pw_core_find_format(struct pw_core *core,
}
pw_log_debug("Got output format:");
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_format(2, t->map, *format);
spa_debug_format(2, NULL, *format);
} else if (out_state >= PW_PORT_STATE_CONFIGURE && in_state > PW_PORT_STATE_CONFIGURE) {
/* only output needs format */
if ((res = spa_node_port_enum_params(input->node->node,
input->direction, input->port_id,
t->param.idFormat, &iidx,
SPA_ID_PARAM_Format, &iidx,
NULL, format, builder)) <= 0) {
if (res == 0)
res = -EBADF;
@ -773,7 +749,7 @@ int pw_core_find_format(struct pw_core *core,
}
pw_log_debug("Got input format:");
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_format(2, t->map, *format);
spa_debug_format(2, NULL, *format);
} else if (in_state == PW_PORT_STATE_CONFIGURE && out_state == PW_PORT_STATE_CONFIGURE) {
struct spa_pod_builder fb = { 0 };
uint8_t fbuf[4096];
@ -784,7 +760,7 @@ int pw_core_find_format(struct pw_core *core,
spa_pod_builder_init(&fb, fbuf, sizeof(fbuf));
if ((res = spa_node_port_enum_params(input->node->node,
input->direction, input->port_id,
t->param.idEnumFormat, &iidx,
SPA_ID_PARAM_EnumFormat, &iidx,
NULL, &filter, &fb)) <= 0) {
if (res == 0 && iidx == 0) {
asprintf(error, "error input enum formats: %s", spa_strerror(res));
@ -795,11 +771,11 @@ int pw_core_find_format(struct pw_core *core,
}
pw_log_debug("enum output %d with filter: %p", oidx, filter);
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_format(2, t->map, filter);
spa_debug_format(2, NULL, filter);
if ((res = spa_node_port_enum_params(output->node->node,
output->direction, output->port_id,
t->param.idEnumFormat, &oidx,
SPA_ID_PARAM_EnumFormat, &oidx,
filter, format, builder)) <= 0) {
if (res == 0) {
oidx = 0;
@ -811,7 +787,7 @@ int pw_core_find_format(struct pw_core *core,
pw_log_debug("Got filtered:");
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_format(2, core->type.map, *format);
spa_debug_format(2, NULL, *format);
} else {
res = -EBADF;
asprintf(error, "error node state");

View file

@ -123,9 +123,6 @@ void pw_core_add_listener(struct pw_core *core,
const struct pw_core_events *events,
void *data);
/** Get the type object of a core */
struct pw_type *pw_core_get_type(struct pw_core *core);
/** Get the core info object */
const struct pw_core_info *pw_core_get_info(struct pw_core *core);

View file

@ -19,6 +19,8 @@
#include <errno.h>
#include <spa/debug/types.h>
#include "pipewire/pipewire.h"
#include "pipewire/factory.h"
#include "pipewire/private.h"
@ -147,14 +149,14 @@ int pw_factory_register(struct pw_factory *factory,
pw_properties_set(properties, "factory.name", factory->info.name);
pw_properties_setf(properties, "factory.type.name", "%s",
spa_type_map_get_type(core->type.map, factory->info.type));
spa_debug_type_find_name(spa_debug_types, factory->info.type));
pw_properties_setf(properties, "factory.type.version", "%d", factory->info.version);
spa_list_append(&core->factory_list, &factory->link);
factory->registered = true;
factory->global = pw_global_new(core,
core->type.factory, PW_VERSION_FACTORY,
PW_ID_INTERFACE_Factory, PW_VERSION_FACTORY,
properties,
factory);
if (factory->global == NULL)

View file

@ -26,6 +26,8 @@
#include <pipewire/private.h>
#include <pipewire/global.h>
#include <spa/debug/types.h>
/** \cond */
struct impl {
struct pw_global this;
@ -82,7 +84,7 @@ pw_global_new(struct pw_core *core,
spa_hook_list_init(&this->listener_list);
pw_log_debug("global %p: new %s %d", this,
spa_type_map_get_type(core->type.map, this->type),
spa_debug_type_find_name(spa_debug_types, this->type),
this->id);
return this;

View file

@ -69,14 +69,13 @@ struct pw_link_proxy;
#define PW_VERSION_CORE 0
#define PW_CORE_PROXY_METHOD_HELLO 0
#define PW_CORE_PROXY_METHOD_UPDATE_TYPES 1
#define PW_CORE_PROXY_METHOD_SYNC 2
#define PW_CORE_PROXY_METHOD_GET_REGISTRY 3
#define PW_CORE_PROXY_METHOD_CLIENT_UPDATE 4
#define PW_CORE_PROXY_METHOD_PERMISSIONS 5
#define PW_CORE_PROXY_METHOD_CREATE_OBJECT 6
#define PW_CORE_PROXY_METHOD_DESTROY 7
#define PW_CORE_PROXY_METHOD_NUM 8
#define PW_CORE_PROXY_METHOD_SYNC 1
#define PW_CORE_PROXY_METHOD_GET_REGISTRY 2
#define PW_CORE_PROXY_METHOD_CLIENT_UPDATE 3
#define PW_CORE_PROXY_METHOD_PERMISSIONS 4
#define PW_CORE_PROXY_METHOD_CREATE_OBJECT 5
#define PW_CORE_PROXY_METHOD_DESTROY 6
#define PW_CORE_PROXY_METHOD_NUM 7
/**
* Key to update default permissions of globals without specific
@ -119,19 +118,6 @@ struct pw_core_proxy_methods {
* the core info and server types.
*/
void (*hello) (void *object);
/**
* Update the type map
*
* Send a type map update to the PipeWire server. The server uses this
* information to keep a mapping between client types and the server types.
* \param first_id the id of the first type
* \param types the types as a string
* \param n_types the number of types
*/
void (*update_types) (void *object,
uint32_t first_id,
const char **types,
uint32_t n_types);
/**
* Do server roundtrip
*
@ -201,12 +187,6 @@ pw_core_proxy_hello(struct pw_core_proxy *core)
pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, hello);
}
static inline void
pw_core_proxy_update_types(struct pw_core_proxy *core, uint32_t first_id, const char **types, uint32_t n_types)
{
pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, update_types, first_id, types, n_types);
}
static inline void
pw_core_proxy_sync(struct pw_core_proxy *core, uint32_t seq)
{
@ -253,12 +233,11 @@ pw_core_proxy_destroy(struct pw_core_proxy *core, uint32_t id)
pw_proxy_do((struct pw_proxy*)core, struct pw_core_proxy_methods, destroy, id);
}
#define PW_CORE_PROXY_EVENT_UPDATE_TYPES 0
#define PW_CORE_PROXY_EVENT_DONE 1
#define PW_CORE_PROXY_EVENT_ERROR 2
#define PW_CORE_PROXY_EVENT_REMOVE_ID 3
#define PW_CORE_PROXY_EVENT_INFO 4
#define PW_CORE_PROXY_EVENT_NUM 5
#define PW_CORE_PROXY_EVENT_DONE 0
#define PW_CORE_PROXY_EVENT_ERROR 1
#define PW_CORE_PROXY_EVENT_REMOVE_ID 2
#define PW_CORE_PROXY_EVENT_INFO 3
#define PW_CORE_PROXY_EVENT_NUM 4
/** \struct pw_core_proxy_events
* \brief Core events
@ -267,19 +246,6 @@ pw_core_proxy_destroy(struct pw_core_proxy *core, uint32_t id)
struct pw_core_proxy_events {
#define PW_VERSION_CORE_PROXY_EVENTS 0
uint32_t version;
/**
* Update the type map
*
* Send a type map update to the client. The client uses this
* information to keep a mapping between server types and the client types.
* \param first_id the id of the first type
* \param types the types as a string
* \param n_types the number of \a types
*/
void (*update_types) (void *object,
uint32_t first_id,
const char **types,
uint32_t n_types);
/**
* Emit a done event
*
@ -330,7 +296,6 @@ pw_core_proxy_add_listener(struct pw_core_proxy *core,
}
#define pw_core_resource_update_types(r,...) pw_resource_notify(r,struct pw_core_proxy_events,update_types,__VA_ARGS__)
#define pw_core_resource_done(r,...) pw_resource_notify(r,struct pw_core_proxy_events,done,__VA_ARGS__)
#define pw_core_resource_error(r,...) pw_resource_notify(r,struct pw_core_proxy_events,error,__VA_ARGS__)
#define pw_core_resource_remove_id(r,...) pw_resource_notify(r,struct pw_core_proxy_events,remove_id,__VA_ARGS__)

View file

@ -152,7 +152,6 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
struct pw_port *input, *output;
uint8_t buffer[4096];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
struct pw_type *t = &this->core->type;
uint32_t index;
uint32_t in_mix_state, out_mix_state;
@ -184,7 +183,7 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
index = 0;
if ((res = spa_node_port_enum_params(output->node->node,
output->direction, output->port_id,
t->param.idFormat, &index,
SPA_ID_PARAM_Format, &index,
format, &current, &b)) <= 0) {
if (res == 0)
res = -EBADF;
@ -205,7 +204,7 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
index = 0;
if ((res = spa_node_port_enum_params(input->node->node,
input->direction, input->port_id,
t->param.idFormat, &index,
SPA_ID_PARAM_Format, &index,
format, &current, &b)) <= 0) {
if (res == 0)
res = -EBADF;
@ -225,13 +224,13 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
pw_log_debug("link %p: doing set format %p", this, format);
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_format(2, t->map, format);
spa_debug_format(2, NULL, format);
if (out_mix_state == PW_PORT_STATE_CONFIGURE) {
pw_log_debug("link %p: doing set format on output mix", this);
if ((res = pw_port_set_param(output,
this->rt.out_mix.port.port_id,
t->param.idFormat, SPA_NODE_PARAM_FLAG_NEAREST,
SPA_ID_PARAM_Format, SPA_NODE_PARAM_FLAG_NEAREST,
format)) < 0) {
asprintf(&error, "error set output format: %d", res);
goto error;
@ -244,7 +243,7 @@ static int do_negotiate(struct pw_link *this, uint32_t in_state, uint32_t out_st
pw_log_debug("link %p: doing set format on input mix", this);
if ((res2 = pw_port_set_param(input,
this->rt.in_mix.port.port_id,
t->param.idFormat, SPA_NODE_PARAM_FLAG_NEAREST,
SPA_ID_PARAM_Format, SPA_NODE_PARAM_FLAG_NEAREST,
format)) < 0) {
asprintf(&error, "error set input format: %d", res2);
goto error;
@ -373,7 +372,6 @@ static int alloc_buffers(struct pw_link *this,
uint32_t n_metas;
struct spa_meta *metas;
struct pw_memblock *m;
struct pw_type *t = &this->core->type;
n_metas = data_size = meta_size = 0;
@ -383,12 +381,12 @@ static int alloc_buffers(struct pw_link *this,
/* collect metadata */
for (i = 0; i < n_params; i++) {
if (spa_pod_is_object_type (params[i], t->param_meta.Meta)) {
if (spa_pod_is_object_type (params[i], SPA_ID_OBJECT_ParamMeta)) {
uint32_t type, size;
if (spa_pod_object_parse(params[i],
":", t->param_meta.type, "I", &type,
":", t->param_meta.size, "i", &size, NULL) < 0)
":", SPA_PARAM_META_type, "I", &type,
":", SPA_PARAM_META_size, "i", &size, NULL) < 0)
continue;
pw_log_debug("link %p: enable meta %d %d", this, type, size);
@ -450,7 +448,7 @@ static int alloc_buffers(struct pw_link *this,
d->chunk = &cdp[j];
if (data_sizes[j] > 0) {
d->type = t->data.MemFd;
d->type = SPA_DATA_MemFd;
d->flags = 0;
d->fd = m->fd;
d->mapoffset = SPA_PTRDIFF(ddp, m->ptr);
@ -502,7 +500,7 @@ param_filter(struct pw_link *this,
}
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG) && iparam != NULL)
spa_debug_pod(2, this->core->type.map, iparam);
spa_debug_pod(2, spa_debug_types, iparam);
for (oidx = 0;;) {
pw_log_debug("oparam %d", oidx);
@ -513,7 +511,7 @@ param_filter(struct pw_link *this,
}
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_pod(2, this->core->type.map, oparam);
spa_debug_pod(2, spa_debug_types, oparam);
num++;
}
@ -526,7 +524,6 @@ param_filter(struct pw_link *this,
static int port_set_io(struct pw_link *this, struct pw_port *port, void *data, size_t size,
struct pw_port_mix *mix)
{
struct pw_type *t = &this->core->type;
struct spa_graph_port *p = &mix->port;
int res = 0;
@ -539,7 +536,7 @@ static int port_set_io(struct pw_link *this, struct pw_port *port, void *data, s
if ((res = spa_node_port_set_io(port->mix,
p->direction,
p->port_id,
t->io.Buffers,
SPA_ID_IO_Buffers,
data, size)) < 0)
pw_log_warn("port %p: can't set io: %s", port, spa_strerror(res));
}
@ -586,7 +583,6 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
uint32_t in_flags, out_flags;
char *error = NULL;
struct pw_port *input, *output;
struct pw_type *t = &this->core->type;
struct allocation allocation;
uint32_t in_mix_state, out_mix_state;
@ -646,8 +642,8 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
size_t data_sizes[1];
ssize_t data_strides[1];
n_params = param_filter(this, input, output, t->param.idBuffers, &b);
n_params += param_filter(this, input, output, t->param.idMeta, &b);
n_params = param_filter(this, input, output, SPA_ID_PARAM_Buffers, &b);
n_params += param_filter(this, input, output, SPA_ID_PARAM_Meta, &b);
params = alloca(n_params * sizeof(struct spa_pod *));
for (i = 0, offset = 0; i < n_params; i++) {
@ -655,21 +651,21 @@ static int do_allocation(struct pw_link *this, uint32_t in_state, uint32_t out_s
spa_pod_fixate(params[i]);
pw_log_debug("fixated param %d:", i);
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG))
spa_debug_pod(2, this->core->type.map, params[i]);
spa_debug_pod(2, spa_debug_types, params[i]);
offset += SPA_ROUND_UP_N(SPA_POD_SIZE(params[i]), 8);
}
max_buffers = MAX_BUFFERS;
minsize = stride = 0;
param = find_param(params, n_params, t->param_buffers.Buffers);
param = find_param(params, n_params, SPA_ID_OBJECT_ParamBuffers);
if (param) {
uint32_t qmax_buffers = max_buffers,
qminsize = minsize, qstride = stride;
spa_pod_object_parse(param,
":", t->param_buffers.size, "i", &qminsize,
":", t->param_buffers.stride, "i", &qstride,
":", t->param_buffers.buffers, "i", &qmax_buffers, NULL);
":", SPA_PARAM_BUFFERS_size, "i", &qminsize,
":", SPA_PARAM_BUFFERS_stride, "i", &qstride,
":", SPA_PARAM_BUFFERS_buffers, "i", &qmax_buffers, NULL);
max_buffers =
qmax_buffers == 0 ? max_buffers : SPA_MIN(qmax_buffers,
@ -1332,7 +1328,7 @@ int pw_link_register(struct pw_link *link,
link->registered = true;
link->global = pw_global_new(core,
core->type.link, PW_VERSION_LINK,
PW_ID_INTERFACE_Link, PW_VERSION_LINK,
properties,
link);
if (link->global == NULL)

View file

@ -20,7 +20,7 @@
#include <stdio.h>
#include <spa/support/loop.h>
#include <spa/support/type-map.h>
#include <spa/support/loop-types.h>
#include <pipewire/pipewire.h>
#include <pipewire/loop.h>
@ -47,7 +47,6 @@ struct pw_loop *pw_loop_new(struct pw_properties *properties)
struct impl *impl;
struct pw_loop *this;
const struct spa_handle_factory *factory;
struct spa_type_map *map;
void *iface;
const struct spa_support *support;
uint32_t n_support;
@ -56,10 +55,6 @@ struct pw_loop *pw_loop_new(struct pw_properties *properties)
if (support == NULL)
return NULL;
map = spa_support_find(support, n_support, SPA_TYPE__TypeMap);
if (map == NULL)
return NULL;
factory = pw_get_support_factory("loop");
if (factory == NULL)
return NULL;
@ -82,7 +77,7 @@ struct pw_loop *pw_loop_new(struct pw_properties *properties)
}
if ((res = spa_handle_get_interface(impl->handle,
spa_type_map_get_id(map, SPA_TYPE__Loop),
SPA_ID_INTERFACE_Loop,
&iface)) < 0) {
fprintf(stderr, "can't get %s interface %d\n", SPA_TYPE__Loop, res);
goto failed;
@ -90,7 +85,7 @@ struct pw_loop *pw_loop_new(struct pw_properties *properties)
this->loop = iface;
if ((res = spa_handle_get_interface(impl->handle,
spa_type_map_get_id(map, SPA_TYPE__LoopControl),
SPA_ID_INTERFACE_LoopControl,
&iface)) < 0) {
fprintf(stderr, "can't get %s interface %d\n", SPA_TYPE__LoopControl, res);
goto failed;
@ -98,7 +93,7 @@ struct pw_loop *pw_loop_new(struct pw_properties *properties)
this->control = iface;
if ((res = spa_handle_get_interface(impl->handle,
spa_type_map_get_id(map, SPA_TYPE__LoopUtils),
SPA_ID_INTERFACE_LoopUtils,
&iface)) < 0) {
fprintf(stderr, "can't get %s interface %d\n", SPA_TYPE__LoopUtils, res);
goto failed;

View file

@ -56,7 +56,6 @@ pipewire_sources = [
'resource.c',
'stream.c',
'thread-loop.c',
'type.c',
'utils.c',
'work-queue.c',
]

View file

@ -238,7 +238,7 @@ pw_module_load(struct pw_core *core,
spa_list_append(&core->module_list, &this->link);
this->global = pw_global_new(core,
core->type.module, PW_VERSION_MODULE,
PW_ID_INTERFACE_Module, PW_VERSION_MODULE,
pw_properties_new(
PW_MODULE_PROP_NAME, name,
NULL),

View file

@ -76,7 +76,7 @@ static int do_pause_node(struct pw_node *this)
pw_log_debug("node %p: pause node", this);
res = spa_node_send_command(this->node,
&SPA_COMMAND_INIT(this->core->type.command_node.Pause));
&SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause));
if (res < 0)
pw_log_debug("node %p: pause node error %s", this, spa_strerror(res));
@ -97,7 +97,7 @@ static int start_node(struct pw_node *this)
pw_log_debug("node %p: start node", this);
res = spa_node_send_command(this->node,
&SPA_COMMAND_INIT(this->core->type.command_node.Start));
&SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start));
if (res < 0)
pw_log_debug("node %p: start node error %s", this, spa_strerror(res));
@ -112,14 +112,14 @@ static int suspend_node(struct pw_node *this)
pw_log_debug("node %p: suspend node", this);
spa_list_for_each(p, &this->input_ports, link) {
if ((res = pw_port_set_param(p, SPA_ID_INVALID, this->core->type.param.idFormat, 0, NULL)) < 0)
if ((res = pw_port_set_param(p, SPA_ID_INVALID, SPA_ID_PARAM_Format, 0, NULL)) < 0)
pw_log_warn("error unset format input: %s", spa_strerror(res));
/* force CONFIGURE in case of async */
p->state = PW_PORT_STATE_CONFIGURE;
}
spa_list_for_each(p, &this->output_ports, link) {
if ((res = pw_port_set_param(p, SPA_ID_INVALID, this->core->type.param.idFormat, 0, NULL)) < 0)
if ((res = pw_port_set_param(p, SPA_ID_INVALID, SPA_ID_PARAM_Format, 0, NULL)) < 0)
pw_log_warn("error unset format output: %s", spa_strerror(res));
/* force CONFIGURE in case of async */
p->state = PW_PORT_STATE_CONFIGURE;
@ -354,7 +354,7 @@ int pw_node_register(struct pw_node *this,
this->registered = true;
this->global = pw_global_new(core,
core->type.node, PW_VERSION_NODE,
PW_ID_INTERFACE_Node, PW_VERSION_NODE,
properties,
this);
if (this->global == NULL)

View file

@ -59,7 +59,7 @@ struct interface {
int ref;
struct spa_list link;
struct handle *handle;
const char *type;
uint32_t type;
void *iface;
};
@ -232,27 +232,22 @@ static void unref_handle(struct handle *handle)
static struct interface *
load_interface(struct plugin *plugin,
const char *factory_name,
const char *type,
uint32_t type_id,
const struct spa_dict *info,
uint32_t n_support,
struct spa_support support[n_support])
{
int res;
struct handle *handle;
uint32_t type_id;
void *ptr;
struct spa_type_map *map = NULL;
struct interface *iface;
handle = load_handle(plugin, factory_name, info, n_support, support);
if (handle == NULL)
goto not_found;
map = spa_support_find(support, n_support, SPA_TYPE__TypeMap);
type_id = map ? spa_type_map_get_id(map, type) : 0;
if ((res = spa_handle_get_interface(handle->handle, type_id, &ptr)) < 0) {
fprintf(stderr, "can't get %s interface %d\n", type, res);
fprintf(stderr, "can't get %d interface %d\n", type_id, res);
goto interface_failed;
}
@ -261,7 +256,7 @@ load_interface(struct plugin *plugin,
iface->ref = 1;
iface->handle = handle;
iface->type = type;
iface->type = type_id;
iface->iface = ptr;
spa_list_append(&handle->interfaces, &iface->link);
@ -302,7 +297,7 @@ static void configure_debug(struct support *support, const char *str)
* \param type the interface type
* \return the interface or NULL when not configured
*/
void *pw_get_support_interface(const char *type)
void *pw_get_support_interface(uint32_t type)
{
return spa_support_find(global_support.support, global_support.n_support, type);
}
@ -319,7 +314,7 @@ const struct spa_support *pw_get_support(uint32_t *n_support)
return global_support.support;
}
void *pw_load_spa_interface(const char *lib, const char *factory_name, const char *type,
void *pw_load_spa_interface(const char *lib, const char *factory_name, uint32_t type,
const struct spa_dict *info,
uint32_t n_support,
struct spa_support support[n_support])
@ -384,9 +379,9 @@ int pw_unload_spa_interface(void *iface)
void *pw_get_spa_dbus(struct pw_loop *loop)
{
struct spa_support support = SPA_SUPPORT_INIT(SPA_TYPE__LoopUtils, loop->utils);
struct spa_support support = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_LoopUtils, loop->utils);
return pw_load_spa_interface("support/libspa-dbus", "dbus", SPA_TYPE__DBus,
return pw_load_spa_interface("support/libspa-dbus", "dbus", SPA_ID_INTERFACE_DBus,
NULL, 1, &support);
}
@ -435,17 +430,11 @@ void pw_init(int *argc, char **argv[])
items[0] = SPA_DICT_ITEM_INIT("log.colors", "1");
info = SPA_DICT_INIT(items, 1);
iface = load_interface(plugin, "mapper", SPA_TYPE__TypeMap, NULL,
support->n_support, support->support);
if (iface != NULL)
support->support[support->n_support++] =
SPA_SUPPORT_INIT(SPA_TYPE__TypeMap, iface->iface);
iface = load_interface(plugin, "logger", SPA_TYPE__Log, &info,
iface = load_interface(plugin, "logger", SPA_ID_INTERFACE_Log, &info,
support->n_support, support->support);
if (iface != NULL) {
support->support[support->n_support++] =
SPA_SUPPORT_INIT(SPA_TYPE__Log, iface->iface);
SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, iface->iface);
pw_log_set(iface->iface);
}
pw_log_info("version %s", pw_get_library_version());

View file

@ -131,9 +131,9 @@ enum pw_direction
pw_direction_reverse(enum pw_direction direction);
void *
pw_get_support_interface(const char *type);
pw_get_support_interface(uint32_t type);
void *pw_load_spa_interface(const char *lib, const char *factory_name, const char *type,
void *pw_load_spa_interface(const char *lib, const char *factory_name, uint32_t type,
const struct spa_dict *info,
uint32_t n_support,
struct spa_support support[n_support]);

View file

@ -22,6 +22,7 @@
#include <errno.h>
#include <spa/pod/parser.h>
#include <spa/debug/types.h>
#include "pipewire/pipewire.h"
#include "pipewire/private.h"
@ -340,6 +341,7 @@ static int do_add_port(struct spa_loop *loop,
return 0;
}
#if 0
static int make_control(void *data, uint32_t id, uint32_t index, uint32_t next, struct spa_pod *param)
{
struct pw_port *port = data;
@ -347,6 +349,7 @@ static int make_control(void *data, uint32_t id, uint32_t index, uint32_t next,
pw_control_new(node->core, port, param, 0);
return 0;
}
#endif
static void port_unbind_func(void *data)
{
@ -440,7 +443,7 @@ int pw_port_register(struct pw_port *port,
struct pw_core *core = node->core;
port->global = pw_global_new(core,
core->type.port, PW_VERSION_PORT,
PW_ID_INTERFACE_Port, PW_VERSION_PORT,
properties,
port);
if (port->global == NULL)
@ -454,8 +457,6 @@ int pw_port_register(struct pw_port *port,
int pw_port_add(struct pw_port *port, struct pw_node *node)
{
uint32_t port_id = port->port_id;
struct pw_core *core = node->core;
struct pw_type *t = &core->type;
struct spa_list *ports;
struct pw_map *portmap;
struct pw_port *find;
@ -525,25 +526,27 @@ int pw_port_add(struct pw_port *port, struct pw_node *node)
node->info.change_mask |= PW_NODE_CHANGE_MASK_OUTPUT_PORTS;
}
pw_port_for_each_param(port, t->param_io.idPropsOut, 0, 0, NULL, make_control, port);
pw_port_for_each_param(port, t->param_io.idPropsIn, 0, 0, NULL, make_control, port);
#if 0
pw_port_for_each_param(port, SPA_ID_PARAM_PropsOut, 0, 0, NULL, make_control, port);
pw_port_for_each_param(port, SPA_ID_PARAM_PropsIn, 0, 0, NULL, make_control, port);
#endif
pw_log_debug("port %p: setting node io", port);
spa_node_port_set_io(node->node,
port->direction, port_id,
t->io.Buffers,
SPA_ID_IO_Buffers,
&port->rt.io, sizeof(port->rt.io));
if (port->mix && port->mix->port_set_io) {
spa_node_port_set_io(port->mix,
pw_direction_reverse(port->direction), 0,
t->io.Buffers,
SPA_ID_IO_Buffers,
&port->rt.io, sizeof(port->rt.io));
}
if (spa_node_port_set_io(node->node,
port->direction, port_id,
t->io.Clock,
SPA_ID_IO_Clock,
&port->rt.clock, sizeof(port->rt.clock)) >= 0) {
node->rt.clock = &port->rt.clock;
pw_log_debug("port %p: set node clock %p", port, node->rt.clock);
@ -780,8 +783,6 @@ int pw_port_set_param(struct pw_port *port, uint32_t mix_id, uint32_t id, uint32
{
int res = 0;
struct pw_node *node = port->node;
struct pw_core *core = node->core;
struct pw_type *t = &core->type;
struct pw_port_mix *mix = NULL;
if (mix_id != SPA_ID_INVALID)
@ -796,7 +797,7 @@ int pw_port_set_param(struct pw_port *port, uint32_t mix_id, uint32_t id, uint32
pw_log_debug("port %p: %d set param on mix %d:%d.%d %s: %d (%s)", port, port->state,
port->direction, port->port_id, p->port_id,
spa_type_map_get_type(t->map, id), res, spa_strerror(res));
spa_debug_type_find_name(spa_debug_types, id), res, spa_strerror(res));
if (port->state == PW_PORT_STATE_CONFIGURE) {
spa_node_port_set_param(port->mix,
@ -808,11 +809,11 @@ int pw_port_set_param(struct pw_port *port, uint32_t mix_id, uint32_t id, uint32
res = spa_node_port_set_param(node->node, port->direction, port->port_id, id, flags, param);
pw_log_debug("port %p: %d set param on node %d:%d %s: %d (%s)", port, port->state,
port->direction, port->port_id,
spa_type_map_get_type(t->map, id), res, spa_strerror(res));
spa_debug_type_find_name(spa_debug_types, id), res, spa_strerror(res));
}
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
if (param == NULL || res < 0) {
free_allocation(&port->allocation);
port->allocated = false;

View file

@ -161,8 +161,6 @@ struct pw_core {
struct pw_properties *properties; /**< properties of the core */
struct pw_type type; /**< type map and common types */
struct pw_map globals; /**< map of globals */
struct spa_list protocol_list; /**< list of protocols */

View file

@ -19,6 +19,8 @@
#include <errno.h>
#include <spa/debug/types.h>
#include <pipewire/protocol.h>
#include <pipewire/private.h>
@ -30,7 +32,6 @@ struct impl {
struct marshal {
struct spa_list link;
const struct pw_protocol_marshal *marshal;
uint32_t type;
};
/** \endcond */
@ -124,11 +125,11 @@ pw_protocol_add_marshal(struct pw_protocol *protocol,
return -ENOMEM;
impl->marshal = marshal;
impl->type = spa_type_map_get_id (protocol->core->type.map, marshal->type);
spa_list_append(&protocol->marshal_list, &impl->link);
pw_log_debug("Add marshal %s:%d to protocol %s", marshal->type, marshal->version,
pw_log_debug("Add marshal %d/%s:%d to protocol %s", marshal->type,
spa_debug_type_find_name(spa_debug_types, marshal->type), marshal->version,
protocol->name);
return 0;
@ -143,7 +144,7 @@ pw_protocol_get_marshal(struct pw_protocol *protocol, uint32_t type)
return NULL;
spa_list_for_each(impl, &protocol->marshal_list, link) {
if (impl->type == type)
if (impl->marshal->type == type)
return impl->marshal;
}
return NULL;

View file

@ -68,7 +68,7 @@ struct pw_protocol_server {
#define pw_protocol_server_destroy(l) ((l)->destroy(l))
struct pw_protocol_marshal {
const char *type; /**< interface type */
uint32_t type; /**< interface type */
uint32_t version; /**< version */
const void *method_marshal;
const void *method_demarshal;

View file

@ -25,6 +25,7 @@
#include <sys/mman.h>
#include <spa/pod/parser.h>
#include <spa/debug/types.h>
#include "pipewire/pipewire.h"
#include "pipewire/private.h"
@ -42,18 +43,8 @@
/** \cond */
struct type {
uint32_t client_node_position;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->client_node_position = spa_type_map_get_id(map, PW_TYPE_CLIENT_NODE_IO__Position);
}
struct remote {
struct pw_remote this;
uint32_t type_client_node;
struct spa_hook core_listener;
};
@ -95,9 +86,6 @@ struct mix {
struct node_data {
struct pw_remote *remote;
struct pw_core *core;
struct pw_type *t;
struct type type;
int rtwritefd;
struct spa_source *rtsocket_source;
@ -211,22 +199,8 @@ static void core_event_remove_id(void *data, uint32_t id)
pw_map_remove(&this->objects, id);
}
static void
core_event_update_types(void *data, uint32_t first_id, const char **types, uint32_t n_types)
{
struct pw_remote *this = data;
int i;
for (i = 0; i < n_types; i++, first_id++) {
uint32_t this_id = spa_type_map_get_id(this->core->type.map, types[i]);
if (!pw_map_insert_at(&this->types, first_id, PW_MAP_ID_TO_PTR(this_id)))
pw_log_error("can't add type for client");
}
}
static const struct pw_core_proxy_events core_proxy_events = {
PW_VERSION_CORE_PROXY_EVENTS,
.update_types = core_event_update_types,
.done = core_event_done,
.error = core_event_error,
.remove_id = core_event_remove_id,
@ -262,7 +236,6 @@ struct pw_remote *pw_remote_new(struct pw_core *core,
pw_fill_remote_properties(core, properties);
this->properties = properties;
impl->type_client_node = spa_type_map_get_id(core->type.map, PW_TYPE_INTERFACE__ClientNode);
this->state = PW_REMOTE_STATE_UNCONNECTED;
pw_map_init(&this->objects, 64, 32);
@ -385,7 +358,8 @@ static int do_connect(struct pw_remote *remote)
dummy.remote = remote;
remote->core_proxy = (struct pw_core_proxy*)pw_proxy_new(&dummy, remote->core->type.core, 0);
remote->core_proxy = (struct pw_core_proxy*)pw_proxy_new(&dummy,
PW_ID_INTERFACE_Core, PW_VERSION_CORE);
if (remote->core_proxy == NULL)
goto no_proxy;
@ -801,12 +775,12 @@ static void add_port_update(struct pw_proxy *proxy, struct pw_port *port, uint32
spa_pod_builder_init(&b, buf, sizeof(buf));
if (spa_node_port_enum_params(port->node->node,
port->direction, port->port_id,
data->t->param.idList, &idx1,
SPA_ID_PARAM_List, &idx1,
NULL, &param, &b) <= 0)
break;
spa_pod_object_parse(param,
":", data->t->param.listId, "I", &id, NULL);
":", SPA_PARAM_LIST_id, "I", &id, NULL);
for (idx2 = 0;; n_params++) {
spa_pod_builder_init(&b, buf, sizeof(buf));
@ -858,7 +832,6 @@ client_node_set_io(void *object,
{
struct pw_proxy *proxy = object;
struct node_data *data = proxy->user_data;
struct pw_type *t = data->t;
struct mem *m;
void *ptr;
@ -880,9 +853,9 @@ client_node_set_io(void *object,
}
pw_log_debug("node %p: set io %s %p", proxy,
spa_type_map_get_type(t->map, id), ptr);
spa_debug_type_find_name(spa_debug_types, id), ptr);
if (id == data->type.client_node_position) {
if (id == PW_ID_IO_ClientNodePosition) {
if (ptr == NULL && data->position) {
m = find_mem_ptr(data, data->position);
if (m && --m->ref == 0)
@ -912,7 +885,8 @@ static void client_node_command(void *object, uint32_t seq, const struct spa_com
struct pw_remote *remote = proxy->remote;
int res;
if (SPA_COMMAND_TYPE(command) == remote->core->type.command_node.Pause) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Pause:
pw_log_debug("node %p: pause %d", proxy, seq);
pw_loop_update_io(remote->core->data_loop,
@ -923,8 +897,8 @@ static void client_node_command(void *object, uint32_t seq, const struct spa_com
pw_log_warn("node %p: pause failed", proxy);
pw_client_node_proxy_done(data->node_proxy, seq, res);
}
else if (SPA_COMMAND_TYPE(command) == remote->core->type.command_node.Start) {
break;
case SPA_ID_COMMAND_NODE_Start:
pw_log_debug("node %p: start %d", proxy, seq);
pw_loop_update_io(remote->core->data_loop,
@ -935,8 +909,8 @@ static void client_node_command(void *object, uint32_t seq, const struct spa_com
pw_log_warn("node %p: start failed", proxy);
pw_client_node_proxy_done(data->node_proxy, seq, res);
}
else {
break;
default:
pw_log_warn("unhandled node command %d", SPA_COMMAND_TYPE(command));
pw_client_node_proxy_done(data->node_proxy, seq, -ENOTSUP);
}
@ -990,7 +964,6 @@ client_node_port_set_param(void *object,
{
struct pw_proxy *proxy = object;
struct node_data *data = proxy->user_data;
struct pw_type *t = data->t;
struct pw_port *port;
int res;
@ -1000,7 +973,7 @@ client_node_port_set_param(void *object,
goto done;
}
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
struct mix *mix;
spa_list_for_each(mix, &data->mix[direction], link) {
if (mix->port->port_id == port_id)
@ -1032,7 +1005,6 @@ client_node_port_use_buffers(void *object,
uint32_t i, j, len;
struct spa_buffer *b, **bufs;
struct mix *mix;
struct pw_type *t = data->t;
int res, prot;
mix = ensure_mix(data, direction, port_id, mix_id);
@ -1125,7 +1097,7 @@ client_node_port_use_buffers(void *object,
SPA_MEMBER(bmem.map.ptr, offset + sizeof(struct spa_chunk) * j,
struct spa_chunk);
if (d->type == t->data.MemFd || d->type == t->data.DmaBuf) {
if (d->type == SPA_DATA_MemFd || d->type == SPA_DATA_DmaBuf) {
uint32_t mem_id = SPA_PTR_TO_UINT32(d->data);
struct mem *bm = find_mem(data, mem_id);
struct buffer_mem bm2;
@ -1146,7 +1118,7 @@ client_node_port_use_buffers(void *object,
pw_log_debug(" data %d %u -> fd %d maxsize %d",
j, bm->id, bm->fd, d->maxsize);
} else if (d->type == t->data.MemPtr) {
} else if (d->type == SPA_DATA_MemPtr) {
int offs = SPA_PTR_TO_INT(d->data);
d->data = SPA_MEMBER(bmem.map.ptr, offs, void);
d->fd = -1;
@ -1201,8 +1173,6 @@ client_node_port_set_io(void *object,
{
struct pw_proxy *proxy = object;
struct node_data *data = proxy->user_data;
struct pw_core *core = proxy->remote->core;
struct pw_type *t = data->t;
struct mix *mix;
struct mem *m;
void *ptr;
@ -1230,9 +1200,9 @@ client_node_port_set_io(void *object,
}
pw_log_debug("port %p: set io %s %p", mix->port,
spa_type_map_get_type(core->type.map, id), ptr);
spa_debug_type_find_name(spa_debug_types, id), ptr);
if (id == t->io.Buffers) {
if (id == SPA_ID_IO_Buffers) {
if (ptr == NULL && mix->mix.io) {
deactivate_mix(data, mix);
m = find_mem_ptr(data, mix->mix.io);
@ -1374,7 +1344,6 @@ static const struct pw_proxy_events proxy_events = {
struct pw_proxy *pw_remote_export(struct pw_remote *remote,
struct pw_node *node)
{
struct remote *impl = SPA_CONTAINER_OF(remote, struct remote, this);
struct pw_proxy *proxy;
struct node_data *data;
int i;
@ -1386,7 +1355,7 @@ struct pw_proxy *pw_remote_export(struct pw_remote *remote,
proxy = pw_core_proxy_create_object(remote->core_proxy,
"client-node",
impl->type_client_node,
PW_ID_INTERFACE_ClientNode,
PW_VERSION_CLIENT_NODE,
&node->properties->dict,
sizeof(struct node_data));
@ -1399,9 +1368,7 @@ struct pw_proxy *pw_remote_export(struct pw_remote *remote,
data->remote = remote;
data->node = node;
data->core = pw_node_get_core(node);
data->t = pw_core_get_type(data->core);
data->node_proxy = (struct pw_client_node_proxy *)proxy;
init_type(&data->type, data->t->map);
node->exported = true;

View file

@ -23,14 +23,13 @@
#include <sys/mman.h>
#include <time.h>
#include <spa/support/type-map.h>
#include <spa/buffer/alloc.h>
#include <spa/param/format-utils.h>
#include <spa/param/props.h>
#include <spa/node/io.h>
#include <spa/utils/ringbuffer.h>
#include <spa/pod/filter.h>
#include <spa/debug/format.h>
#include <spa/debug/types.h>
#include "pipewire/pipewire.h"
#include "pipewire/stream.h"
@ -43,22 +42,6 @@
#define MASK_BUFFERS (MAX_BUFFERS-1)
#define MAX_PORTS 1
struct type {
uint32_t prop_volume;
uint32_t io_prop_volume;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
};
static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume");
spa_type_media_type_map(map, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype);
}
struct buffer {
struct pw_buffer this;
uint32_t id;
@ -108,14 +91,12 @@ struct control {
struct stream {
struct pw_stream this;
struct type type;
struct props props;
struct control control;
const char *path;
struct pw_core *core;
struct pw_type *t;
enum spa_direction direction;
enum pw_stream_flags flags;
@ -269,14 +250,15 @@ static int impl_send_command(struct spa_node *node, const struct spa_command *co
{
struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node);
struct pw_stream *stream = &impl->this;
struct pw_type *t = impl->t;
if (SPA_COMMAND_TYPE(command) == t->command_node.Pause) {
switch (SPA_COMMAND_TYPE(command)) {
case SPA_ID_COMMAND_NODE_Pause:
if (stream->state == PW_STREAM_STATE_STREAMING) {
pw_log_debug("stream %p: pause", stream);
stream_set_state(stream, PW_STREAM_STATE_PAUSED, NULL);
}
} else if (SPA_COMMAND_TYPE(command) == t->command_node.Start) {
break;
case SPA_ID_COMMAND_NODE_Start:
if (stream->state == PW_STREAM_STATE_PAUSED) {
pw_log_debug("stream %p: start %d", stream, impl->direction);
@ -289,8 +271,10 @@ static int impl_send_command(struct spa_node *node, const struct spa_command *co
}
stream_set_state(stream, PW_STREAM_STATE_STREAMING, NULL);
}
} else {
break;
default:
pw_log_warn("unhandled node command %d", SPA_COMMAND_TYPE(command));
break;
}
return 0;
}
@ -347,18 +331,18 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction,
uint32_t id, void *data, size_t size)
{
struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node);
struct pw_type *t = impl->t;
int res = 0;
pw_log_debug("stream %p: set io %s %p %zd", impl,
spa_type_map_get_type(t->map, id), data, size);
spa_debug_type_find_name(spa_debug_types, id), data, size);
if (id == t->io.Buffers) {
if (id == SPA_ID_IO_Buffers) {
if (data && size >= sizeof(struct spa_io_buffers))
impl->io = data;
else
impl->io = NULL;
}
#if 0
else if (id == impl->type.io_prop_volume) {
if (data && size >= sizeof(struct spa_pod_float)) {
impl->control.volume = data;
@ -367,6 +351,7 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction,
else
impl->control.volume = NULL;
}
#endif
else
res = -ENOENT;
@ -410,13 +395,13 @@ static int impl_port_enum_params(struct spa_node *node,
(*index)++;
if (id == d->t->param.idList) {
if (id == SPA_ID_PARAM_List) {
uint32_t new_id = ((struct spa_pod_object *) param)->body.id;
if (last_id == SPA_ID_INVALID){
*result = spa_pod_builder_object(builder,
id, d->t->param.List,
":", d->t->param.listId, "I", new_id);
id, SPA_ID_OBJECT_ParamList,
":", SPA_PARAM_LIST_id, "I", new_id);
last_id = new_id;
}
else if (last_id != new_id) {
@ -440,21 +425,20 @@ static int port_set_format(struct spa_node *node,
{
struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node);
struct pw_stream *stream = &impl->this;
struct pw_type *t = impl->t;
struct param *p;
int count;
pw_log_debug("stream %p: format changed:", impl);
if (pw_log_level >= SPA_LOG_LEVEL_DEBUG)
spa_debug_format(2, t->map, format);
spa_debug_format(2, NULL, format);
clear_params(stream, PARAM_TYPE_FORMAT);
if (spa_pod_is_object_type(format, t->spa_format)) {
if (spa_pod_is_object_type(format, SPA_ID_OBJECT_Format)) {
p = add_param(stream, PARAM_TYPE_FORMAT, format);
if (p == NULL)
goto no_mem;
((struct spa_pod_object*)p->param)->body.id = t->param.idFormat;
((struct spa_pod_object*)p->param)->body.id = SPA_ID_PARAM_Format;
}
else
p = NULL;
@ -482,10 +466,7 @@ static int impl_port_set_param(struct spa_node *node,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
struct stream *d = SPA_CONTAINER_OF(node, struct stream, impl_node);
struct pw_type *t = d->t;
if (id == t->param.idFormat) {
if (id == SPA_ID_PARAM_Format) {
return port_set_format(node, direction, port_id, flags, param);
}
else
@ -555,7 +536,6 @@ static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direc
{
struct stream *impl = SPA_CONTAINER_OF(node, struct stream, impl_node);
struct pw_stream *stream = &impl->this;
struct pw_type *t = impl->t;
uint32_t flags = impl->flags;
int i, j, prot, res;
int size = 0;
@ -574,8 +554,8 @@ static int impl_port_use_buffers(struct spa_node *node, enum spa_direction direc
if (SPA_FLAG_CHECK(flags, PW_STREAM_FLAG_MAP_BUFFERS)) {
for (j = 0; j < buffers[i]->n_datas; j++) {
struct spa_data *d = &buffers[i]->datas[j];
if (d->type == t->data.MemFd ||
d->type == t->data.DmaBuf) {
if (d->type == SPA_DATA_MemFd ||
d->type == SPA_DATA_DmaBuf) {
if ((res = map_data(impl, d, prot)) < 0)
return res;
}
@ -838,7 +818,6 @@ struct pw_stream * pw_stream_new(struct pw_remote *remote, const char *name,
this->remote = remote;
this->name = name ? strdup(name) : NULL;
init_type(&impl->type, remote->core->type.map);
reset_props(&impl->props);
spa_ringbuffer_init(&impl->dequeued.ring);
@ -850,7 +829,6 @@ struct pw_stream * pw_stream_new(struct pw_remote *remote, const char *name,
this->state = PW_STREAM_STATE_UNCONNECTED;
impl->core = remote->core;
impl->t = &remote->core->type;
impl->pending_seq = SPA_ID_INVALID;
pw_remote_add_listener(remote, &impl->remote_listener, &remote_events, this);
@ -981,10 +959,10 @@ struct pw_remote *pw_stream_get_remote(struct pw_stream *stream)
static void add_controls(struct pw_stream *stream)
{
#if 0
struct stream *s = SPA_CONTAINER_OF(stream, struct stream, this);
uint8_t buffer[4096];
struct spa_pod_builder b;
struct pw_type *t = s->t;
spa_pod_builder_init(&b, buffer, 4096);
add_param(stream, PARAM_TYPE_INIT,
@ -995,6 +973,7 @@ static void add_controls(struct pw_stream *stream)
":", t->param.propId, "I", s->type.prop_volume,
":", t->param.propType, "fru", s->props.volume,
SPA_POD_PROP_MIN_MAX(0.0, 10.0)));
#endif
}
int

View file

@ -1,67 +0,0 @@
/* PipeWire
* Copyright (C) 2015 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.
*/
#include <string.h>
#include <spa/support/type-map.h>
#include <spa/utils/defs.h>
#include <spa/param/format.h>
#include <spa/param/props.h>
#include <spa/monitor/monitor.h>
#include "pipewire/pipewire.h"
#include "pipewire/type.h"
#include "pipewire/module.h"
/** Initializes the type system
* \param type a type structure
* \memberof pw_type
*/
int pw_type_init(struct pw_type *type)
{
type->map = pw_get_support_interface(SPA_TYPE__TypeMap);
type->core = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Core);
type->registry = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Registry);
type->node = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Node);
type->port = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Port);
type->factory = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Factory);
type->link = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Link);
type->client = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Client);
type->module = spa_type_map_get_id(type->map, PW_TYPE_INTERFACE__Module);
type->spa_log = spa_type_map_get_id(type->map, SPA_TYPE__Log);
type->spa_node = spa_type_map_get_id(type->map, SPA_TYPE__Node);
type->spa_monitor = spa_type_map_get_id(type->map, SPA_TYPE__Monitor);
type->spa_format = spa_type_map_get_id(type->map, SPA_TYPE__Format);
type->spa_props = spa_type_map_get_id(type->map, SPA_TYPE__Props);
spa_type_io_map(type->map, &type->io);
spa_type_param_map(type->map, &type->param);
spa_type_meta_map(type->map, &type->meta);
spa_type_data_map(type->map, &type->data);
spa_type_event_node_map(type->map, &type->event_node);
spa_type_command_node_map(type->map, &type->command_node);
spa_type_monitor_map(type->map, &type->monitor);
spa_type_param_buffers_map(type->map, &type->param_buffers);
spa_type_param_meta_map(type->map, &type->param_meta);
spa_type_param_io_map(type->map, &type->param_io);
return 0;
}

View file

@ -24,7 +24,6 @@
extern "C" {
#endif
#include <spa/support/type-map.h>
#include <spa/node/event.h>
#include <spa/node/command.h>
#include <spa/monitor/monitor.h>
@ -35,6 +34,23 @@ extern "C" {
#include <pipewire/map.h>
enum {
PW_ID_FIRST = SPA_ID_VENDOR_PipeWire,
PW_ID_INTERFACE_Core,
PW_ID_INTERFACE_Registry,
PW_ID_INTERFACE_Node,
PW_ID_INTERFACE_Port,
PW_ID_INTERFACE_Factory,
PW_ID_INTERFACE_Link,
PW_ID_INTERFACE_Client,
PW_ID_INTERFACE_Module,
PW_ID_INTERFACE_ClientNode,
PW_ID_IO_BASE = PW_ID_FIRST + SPA_ID_IO_BASE,
PW_ID_IO_ClientNodePosition,
};
#define PW_TYPE_BASE "PipeWire:"
#define PW_TYPE__Object PW_TYPE_BASE "Object"
@ -43,44 +59,6 @@ extern "C" {
#define PW_TYPE__Interface PW_TYPE_BASE "Interface"
#define PW_TYPE_INTERFACE_BASE PW_TYPE__Interface ":"
/** \class pw_type
* \brief PipeWire type support struct
*
* This structure contains some of the most common types
* and should be initialized with \ref pw_type_init() */
struct pw_type {
struct spa_type_map *map; /**< the type mapper */
uint32_t core;
uint32_t registry;
uint32_t node;
uint32_t port;
uint32_t factory;
uint32_t link;
uint32_t client;
uint32_t module;
uint32_t spa_log;
uint32_t spa_node;
uint32_t spa_clock;
uint32_t spa_monitor;
uint32_t spa_format;
uint32_t spa_props;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_event_node event_node;
struct spa_type_command_node command_node;
struct spa_type_monitor monitor;
struct spa_type_param_buffers param_buffers;
struct spa_type_param_meta param_meta;
struct spa_type_param_io param_io;
};
int pw_type_init(struct pw_type *type);
#ifdef __cplusplus
}
#endif

View file

@ -40,7 +40,6 @@ struct remote_data;
struct data {
struct pw_main_loop *loop;
struct pw_core *core;
struct pw_type *t;
struct spa_list remotes;
struct remote_data *current;
@ -262,15 +261,12 @@ static void on_sync_reply(void *_data, uint32_t seq)
static int print_global(void *obj, void *data)
{
struct global *global = obj;
struct pw_type *t;
if (global == NULL)
return 0;
t = global->rd->data->t;
fprintf(stdout, "\tid %d, parent %d, type %s/%d\n", global->id, global->parent_id,
spa_type_map_get_type(t->map, global->type),
spa_debug_type_find_name(spa_debug_types, global->type),
global->version);
if (global->properties)
print_properties(&global->properties->dict, ' ', false);
@ -360,7 +356,6 @@ static void on_state_changed(void *_data, enum pw_remote_state old,
{
struct remote_data *rd = _data;
struct data *data = rd->data;
struct pw_type *t = data->t;
switch (state) {
case PW_REMOTE_STATE_ERROR:
@ -372,7 +367,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old,
fprintf(stdout, "remote %d state: \"%s\"\n", rd->id, pw_remote_state_as_string(state));
rd->core_proxy = pw_remote_get_core_proxy(rd->remote);
rd->registry_proxy = pw_core_proxy_get_registry(rd->core_proxy,
t->registry,
PW_ID_INTERFACE_Registry,
PW_VERSION_REGISTRY, 0);
pw_registry_proxy_add_listener(rd->registry_proxy,
&rd->registry_listener,
@ -497,7 +492,6 @@ static bool do_switch_remote(struct data *data, const char *cmd, char *args, cha
static void info_global(struct proxy_data *pd)
{
struct global *global = pd->global;
struct pw_type *t = pd->rd->data->t;
if (global == NULL)
return;
@ -507,7 +501,7 @@ static void info_global(struct proxy_data *pd)
fprintf(stdout, "\tpermissions: %c%c%c\n", global->permissions & PW_PERM_R ? 'r' : '-',
global->permissions & PW_PERM_W ? 'w' : '-',
global->permissions & PW_PERM_X ? 'x' : '-');
fprintf(stdout, "\ttype: %s/%d\n", spa_type_map_get_type(t->map, global->type), pd->global->version);
fprintf(stdout, "\ttype: %s/%d\n", spa_debug_type_find_name(spa_debug_types, global->type), pd->global->version);
}
static void info_core(struct proxy_data *pd)
@ -570,11 +564,10 @@ static void info_port(struct proxy_data *pd)
static void info_factory(struct proxy_data *pd)
{
struct pw_factory_info *info = pd->info;
struct pw_type *t = pd->rd->data->t;
info_global(pd);
fprintf(stdout, "\tname: \"%s\"\n", info->name);
fprintf(stdout, "\tobject-type: %s/%d\n", spa_type_map_get_type(t->map, info->type), info->version);
fprintf(stdout, "\tobject-type: %s/%d\n", spa_debug_type_find_name(spa_debug_types, info->type), info->version);
print_properties(info->props, MARK_CHANGE(0), true);
info->change_mask = 0;
}
@ -599,7 +592,7 @@ static void info_link(struct proxy_data *pd)
fprintf(stdout, "%c\tinput-port-id: %u\n", MARK_CHANGE(1), info->input_port_id);
fprintf(stdout, "%c\tformat:\n", MARK_CHANGE(2));
if (info->format)
spa_debug_format(2, pd->rd->data->t->map, info->format);
spa_debug_format(2, NULL, info->format);
else
fprintf(stdout, "\t\tnone\n");
print_properties(info->props, MARK_CHANGE(3), true);
@ -668,15 +661,14 @@ static void node_event_param(void *object, uint32_t id, uint32_t index, uint32_t
{
struct proxy_data *data = object;
struct remote_data *rd = data->rd;
struct pw_type *t = rd->data->t;
fprintf(stdout, "remote %d node %d param %d index %d\n",
rd->id, data->global->id, id, index);
if (spa_pod_is_object_type(param, t->spa_format))
spa_debug_format(2, t->map, param);
if (spa_pod_is_object_type(param, SPA_ID_OBJECT_Format))
spa_debug_format(2, NULL, param);
else
spa_debug_pod(2, t->map, param);
spa_debug_pod(2, spa_debug_types, param);
}
static const struct pw_node_proxy_events node_events = {
@ -706,15 +698,14 @@ static void port_event_param(void *object, uint32_t id, uint32_t index, uint32_t
{
struct proxy_data *data = object;
struct remote_data *rd = data->rd;
struct pw_type *t = rd->data->t;
fprintf(stdout, "remote %d port %d param %d index %d\n",
rd->id, data->global->id, id, index);
if (spa_pod_is_object_type(param, t->spa_format))
spa_debug_format(2, t->map, param);
if (spa_pod_is_object_type(param, SPA_ID_OBJECT_Format))
spa_debug_format(2, NULL, param);
else
spa_debug_pod(2, t->map, param);
spa_debug_pod(2, spa_debug_types, param);
}
static const struct pw_port_proxy_events port_events = {
@ -813,7 +804,6 @@ static bool do_list_objects(struct data *data, const char *cmd, char *args, char
static bool bind_global(struct remote_data *rd, struct global *global, char **error)
{
struct pw_type *t = rd->data->t;
const void *events;
uint32_t client_version;
info_func_t info_func;
@ -821,50 +811,51 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er
struct proxy_data *pd;
struct pw_proxy *proxy;
if (global->type == t->core) {
switch (global->type) {
case PW_ID_INTERFACE_Core:
events = &core_events;
client_version = PW_VERSION_CORE;
destroy = (pw_destroy_t) pw_core_info_free;
info_func = info_core;
}
else if (global->type == t->module) {
break;
case PW_ID_INTERFACE_Module:
events = &module_events;
client_version = PW_VERSION_MODULE;
destroy = (pw_destroy_t) pw_module_info_free;
info_func = info_module;
}
else if (global->type == t->node) {
break;
case PW_ID_INTERFACE_Node:
events = &node_events;
client_version = PW_VERSION_NODE;
destroy = (pw_destroy_t) pw_node_info_free;
info_func = info_node;
}
else if (global->type == t->port) {
break;
case PW_ID_INTERFACE_Port:
events = &port_events;
client_version = PW_VERSION_PORT;
destroy = (pw_destroy_t) pw_port_info_free;
info_func = info_port;
}
else if (global->type == t->factory) {
break;
case PW_ID_INTERFACE_Factory:
events = &factory_events;
client_version = PW_VERSION_FACTORY;
destroy = (pw_destroy_t) pw_factory_info_free;
info_func = info_factory;
}
else if (global->type == t->client) {
break;
case PW_ID_INTERFACE_Client:
events = &client_events;
client_version = PW_VERSION_CLIENT;
destroy = (pw_destroy_t) pw_client_info_free;
info_func = info_client;
}
else if (global->type == t->link) {
break;
case PW_ID_INTERFACE_Link:
events = &link_events;
client_version = PW_VERSION_LINK;
destroy = (pw_destroy_t) pw_link_info_free;
info_func = info_link;
}
else {
asprintf(error, "unsupported type %s", spa_type_map_get_type(t->map, global->type));
break;
default:
asprintf(error, "unsupported type %s", spa_debug_type_find_name(spa_debug_types, global->type));
return false;
}
@ -953,7 +944,6 @@ static bool do_create_node(struct data *data, const char *cmd, char *args, char
char *a[2];
int n;
uint32_t id;
struct pw_type *t = data->t;
struct pw_proxy *proxy;
struct pw_properties *props = NULL;
struct proxy_data *pd;
@ -967,7 +957,7 @@ static bool do_create_node(struct data *data, const char *cmd, char *args, char
props = parse_props(a[1]);
proxy = pw_core_proxy_create_object(rd->core_proxy, a[0],
t->node, PW_VERSION_NODE,
PW_ID_INTERFACE_Node, PW_VERSION_NODE,
props ? &props->dict : NULL,
sizeof(struct proxy_data));
@ -1014,7 +1004,6 @@ static bool do_create_link(struct data *data, const char *cmd, char *args, char
char *a[5];
int n;
uint32_t id;
struct pw_type *t = data->t;
struct pw_proxy *proxy;
struct pw_properties *props = NULL;
struct proxy_data *pd;
@ -1036,7 +1025,7 @@ static bool do_create_link(struct data *data, const char *cmd, char *args, char
proxy = (struct pw_proxy*)pw_core_proxy_create_object(rd->core_proxy,
"link-factory",
t->link,
PW_ID_INTERFACE_Link,
PW_VERSION_LINK,
props ? &props->dict : NULL,
sizeof(struct proxy_data));
@ -1056,7 +1045,6 @@ static bool do_create_link(struct data *data, const char *cmd, char *args, char
static bool do_export_node(struct data *data, const char *cmd, char *args, char **error)
{
struct pw_type *t = data->t;
struct remote_data *rd = data->current;
struct pw_global *global;
struct pw_node *node;
@ -1082,7 +1070,7 @@ static bool do_export_node(struct data *data, const char *cmd, char *args, char
asprintf(error, "object %d does not exist", atoi(a[0]));
return false;
}
if (pw_global_get_type(global) != t->node) {
if (pw_global_get_type(global) != PW_ID_INTERFACE_Node) {
asprintf(error, "object %d is not a node", atoi(a[0]));
return false;
}
@ -1101,7 +1089,6 @@ static bool do_export_node(struct data *data, const char *cmd, char *args, char
static bool do_node_params(struct data *data, const char *cmd, char *args, char **error)
{
struct pw_type *t = data->t;
struct remote_data *rd = data->current;
char *a[2];
int n;
@ -1114,9 +1101,9 @@ static bool do_node_params(struct data *data, const char *cmd, char *args, char
return false;
}
if (n == 2)
param_id = spa_type_map_get_id(t->map, a[1]);
param_id = SPA_ID_PARAM_List;
else
param_id = t->param.idList;
param_id = SPA_ID_PARAM_List;
id = atoi(a[0]);
global = pw_map_lookup(&rd->globals, id);
@ -1124,7 +1111,7 @@ static bool do_node_params(struct data *data, const char *cmd, char *args, char
asprintf(error, "%s: unknown global %d", cmd, id);
return false;
}
if (global->type != t->node) {
if (global->type != PW_ID_INTERFACE_Node) {
asprintf(error, "object %d is not a node", atoi(a[0]));
return false;
}
@ -1136,7 +1123,6 @@ static bool do_node_params(struct data *data, const char *cmd, char *args, char
static bool do_port_params(struct data *data, const char *cmd, char *args, char **error)
{
struct pw_type *t = data->t;
struct remote_data *rd = data->current;
char *a[2];
int n;
@ -1149,9 +1135,9 @@ static bool do_port_params(struct data *data, const char *cmd, char *args, char
return false;
}
if (n == 2)
param_id = spa_type_map_get_id(t->map, a[1]);
param_id = SPA_ID_PARAM_List;
else
param_id = t->param.idList;
param_id = SPA_ID_PARAM_List;
id = atoi(a[0]);
global = pw_map_lookup(&rd->globals, id);
@ -1159,7 +1145,7 @@ static bool do_port_params(struct data *data, const char *cmd, char *args, char
asprintf(error, "%s: unknown global %d", cmd, id);
return false;
}
if (global->type != t->port) {
if (global->type != PW_ID_INTERFACE_Port) {
asprintf(error, "object %d is not a port", atoi(a[0]));
return false;
}
@ -1264,7 +1250,6 @@ int main(int argc, char *argv[])
pw_map_init(&data.vars, 64, 16);
data.core = pw_core_new(l, pw_properties_new(PW_CORE_PROP_DAEMON, "1", NULL));
data.t = pw_core_get_type(data.core);
info = pw_core_get_info(data.core);
pw_module_load(data.core, "libpipewire-module-link-factory", NULL, NULL, NULL, NULL);

View file

@ -22,6 +22,7 @@
#include <spa/debug/pod.h>
#include <spa/debug/format.h>
#include <spa/debug/types.h>
#include <pipewire/pipewire.h>
#include <pipewire/interfaces.h>
@ -192,7 +193,6 @@ static void print_node(struct proxy_data *data)
{
struct pw_node_info *info = data->info;
bool print_all, print_mark;
struct pw_type *t = pw_core_get_type(data->data->core);
print_all = true;
if (data->first) {
@ -217,10 +217,10 @@ static void print_node(struct proxy_data *data)
printf("%c\tname: \"%s\"\n", MARK_CHANGE(0), info->name);
printf("%c\tparams:\n", MARK_CHANGE(5));
for (i = 0; i < data->n_params; i++) {
if (spa_pod_is_object_type(data->params[i], t->spa_format))
spa_debug_format(2, t->map, data->params[i]);
if (spa_pod_is_object_type(data->params[i], SPA_ID_OBJECT_Format))
spa_debug_format(2, NULL, data->params[i]);
else
spa_debug_pod(2, t->map, data->params[i]);
spa_debug_pod(2, spa_debug_types, data->params[i]);
}
printf("%c\tinput ports: %u/%u\n", MARK_CHANGE(1),
info->n_input_ports, info->max_input_ports);
@ -240,13 +240,12 @@ static void print_node(struct proxy_data *data)
static void node_event_info(void *object, struct pw_node_info *info)
{
struct proxy_data *data = object;
struct pw_type *t = pw_core_get_type(data->data->core);
data->info = pw_node_info_update(data->info, info);
if (info->change_mask & PW_NODE_CHANGE_MASK_ENUM_PARAMS) {
pw_node_proxy_enum_params((struct pw_node_proxy*)data->proxy,
t->param.idList, 0, 0, NULL);
SPA_ID_PARAM_List, 0, 0, NULL);
add_pending(data);
}
if (data->pending_seq == SPA_ID_INVALID)
@ -270,7 +269,6 @@ static void print_port(struct proxy_data *data)
{
struct pw_port_info *info = data->info;
bool print_all, print_mark;
struct pw_type *t = pw_core_get_type(data->data->core);
print_all = true;
if (data->first) {
@ -294,10 +292,10 @@ static void print_port(struct proxy_data *data)
printf("%c\tname: \"%s\"\n", MARK_CHANGE(0), info->name);
printf("%c\tparams:\n", MARK_CHANGE(2));
for (i = 0; i < data->n_params; i++) {
if (spa_pod_is_object_type(data->params[i], t->spa_format))
spa_debug_format(2, t->map, data->params[i]);
if (spa_pod_is_object_type(data->params[i], SPA_ID_OBJECT_Format))
spa_debug_format(2, NULL, data->params[i]);
else
spa_debug_pod(2, t->map, data->params[i]);
spa_debug_pod(2, spa_debug_types, data->params[i]);
}
print_properties(info->props, MARK_CHANGE(1));
}
@ -307,13 +305,12 @@ static void port_event_info(void *object, struct pw_port_info *info)
{
struct proxy_data *data = object;
struct pw_type *t = pw_core_get_type(data->data->core);
data->info = pw_port_info_update(data->info, info);
if (info->change_mask & PW_PORT_CHANGE_MASK_ENUM_PARAMS) {
pw_port_proxy_enum_params((struct pw_port_proxy*)data->proxy,
t->param.idEnumFormat, 0, 0, NULL);
SPA_ID_PARAM_EnumFormat, 0, 0, NULL);
add_pending(data);
}
if (data->pending_seq == SPA_ID_INVALID)
@ -336,7 +333,6 @@ static const struct pw_port_proxy_events port_events = {
static void factory_event_info(void *object, struct pw_factory_info *info)
{
struct proxy_data *data = object;
struct pw_type *t = pw_core_get_type(data->data->core);
bool print_all, print_mark;
print_all = true;
@ -358,7 +354,7 @@ static void factory_event_info(void *object, struct pw_factory_info *info)
data->permissions & PW_PERM_X ? 'x' : '-');
printf("\ttype: %s (version %d)\n", PW_TYPE_INTERFACE__Factory, data->version);
printf("\tname: \"%s\"\n", info->name);
printf("\tobject-type: %s/%d\n", spa_type_map_get_type(t->map, info->type), info->version);
printf("\tobject-type: %s/%d\n", spa_debug_type_find_name(spa_debug_types, info->type), info->version);
if (print_all) {
print_properties(info->props, MARK_CHANGE(0));
}
@ -405,7 +401,6 @@ static const struct pw_client_proxy_events client_events = {
static void link_event_info(void *object, struct pw_link_info *info)
{
struct proxy_data *data = object;
struct pw_type *t = pw_core_get_type(data->data->core);
bool print_all, print_mark;
print_all = true;
@ -433,7 +428,7 @@ static void link_event_info(void *object, struct pw_link_info *info)
printf("%c\tinput-port-id: %u\n", MARK_CHANGE(1), info->input_port_id);
printf("%c\tformat:\n", MARK_CHANGE(2));
if (info->format)
spa_debug_format(2, t->map, info->format);
spa_debug_format(2, NULL, info->format);
else
printf("\t\tnone\n");
print_properties(info->props, MARK_CHANGE(3));
@ -474,40 +469,38 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
struct pw_proxy *proxy;
uint32_t client_version;
const void *events;
struct pw_core *core = d->core;
struct pw_type *t = pw_core_get_type(core);
struct proxy_data *pd;
pw_destroy_t destroy;
print_func_t print_func = NULL;
if (type == t->node) {
if (type == PW_ID_INTERFACE_Node) {
events = &node_events;
client_version = PW_VERSION_NODE;
destroy = (pw_destroy_t) pw_node_info_free;
print_func = print_node;
}
else if (type == t->port) {
else if (type == PW_ID_INTERFACE_Port) {
events = &port_events;
client_version = PW_VERSION_PORT;
destroy = (pw_destroy_t) pw_port_info_free;
print_func = print_port;
}
else if (type == t->module) {
else if (type == PW_ID_INTERFACE_Module) {
events = &module_events;
client_version = PW_VERSION_MODULE;
destroy = (pw_destroy_t) pw_module_info_free;
}
else if (type == t->factory) {
else if (type == PW_ID_INTERFACE_Factory) {
events = &factory_events;
client_version = PW_VERSION_FACTORY;
destroy = (pw_destroy_t) pw_factory_info_free;
}
else if (type == t->client) {
else if (type == PW_ID_INTERFACE_Client) {
events = &client_events;
client_version = PW_VERSION_CLIENT;
destroy = (pw_destroy_t) pw_client_info_free;
}
else if (type == t->link) {
else if (type == PW_ID_INTERFACE_Link) {
events = &link_events;
client_version = PW_VERSION_LINK;
destroy = (pw_destroy_t) pw_link_info_free;
@ -519,7 +512,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
printf("\tpermissions: %c%c%c\n", permissions & PW_PERM_R ? 'r' : '-',
permissions & PW_PERM_W ? 'w' : '-',
permissions & PW_PERM_X ? 'x' : '-');
printf("\ttype: %s (version %d)\n", spa_type_map_get_type(t->map, type), version);
printf("\ttype: %s (version %d)\n", spa_debug_type_find_name(spa_debug_types, type), version);
print_properties(props, ' ');
return;
}
@ -567,7 +560,6 @@ static void on_state_changed(void *_data, enum pw_remote_state old,
enum pw_remote_state state, const char *error)
{
struct data *data = _data;
struct pw_type *t = pw_core_get_type(data->core);
switch (state) {
case PW_REMOTE_STATE_ERROR:
@ -580,7 +572,7 @@ static void on_state_changed(void *_data, enum pw_remote_state old,
data->core_proxy = pw_remote_get_core_proxy(data->remote);
data->registry_proxy = pw_core_proxy_get_registry(data->core_proxy,
t->registry,
PW_ID_INTERFACE_Registry,
PW_VERSION_REGISTRY, 0);
pw_registry_proxy_add_listener(data->registry_proxy,
&data->registry_listener,