From fca3e1d85d604d3a1fa2cd5d4548a470021a96fb Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 23 Aug 2018 17:47:57 +0200 Subject: [PATCH] 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. --- spa/include/spa/buffer/buffer-types.h | 52 +++ spa/include/spa/buffer/buffer.h | 37 +- spa/include/spa/buffer/meta-types.h | 50 +++ spa/include/spa/buffer/meta.h | 35 +- spa/include/spa/debug/buffer.h | 23 +- spa/include/spa/debug/format.h | 42 ++- spa/include/spa/debug/pod.h | 33 +- spa/include/spa/debug/types.h | 80 ++++ spa/include/spa/meson.build | 5 - spa/include/spa/monitor/monitor-types.h | 86 +++++ spa/include/spa/monitor/monitor.h | 63 +--- spa/include/spa/node/command-types.h | 55 +++ spa/include/spa/node/command.h | 48 --- spa/include/spa/node/event-types.h | 41 +++ spa/include/spa/node/event.h | 24 -- spa/include/spa/node/io-types.h | 51 +++ spa/include/spa/node/io.h | 46 +-- spa/include/spa/node/node-types.h | 42 +++ spa/include/spa/node/node.h | 4 +- spa/include/spa/param/audio/format-types.h | 50 +++ spa/include/spa/param/audio/format-utils.h | 49 +-- spa/include/spa/param/audio/format.h | 18 +- spa/include/spa/param/audio/raw-types.h | 90 +++++ spa/include/spa/param/audio/raw-utils.h | 119 ------ spa/include/spa/param/audio/raw.h | 129 +++++-- spa/include/spa/param/buffers-types.h | 58 +++ spa/include/spa/param/buffers.h | 45 +-- spa/include/spa/param/format-types.h | 109 ++++++ spa/include/spa/param/format-utils.h | 145 -------- spa/include/spa/param/format.h | 88 ++--- spa/include/spa/param/io-types.h | 101 +++++ spa/include/spa/param/io.h | 69 +--- spa/include/spa/param/meta-types.h | 66 ++++ spa/include/spa/param/meta.h | 34 +- spa/include/spa/param/param-types.h | 92 +++++ spa/include/spa/param/param.h | 99 +---- spa/include/spa/param/props-types.h | 70 ++++ spa/include/spa/param/props.h | 76 ++-- spa/include/spa/param/video-padding.h | 29 +- spa/include/spa/param/video/format-types.h | 60 +++ spa/include/spa/param/video/format-utils.h | 100 ++--- spa/include/spa/param/video/format.h | 25 +- spa/include/spa/param/video/raw-types.h | 117 ++++++ spa/include/spa/param/video/raw-utils.h | 200 ---------- spa/include/spa/param/video/raw.h | 163 ++++----- spa/include/spa/pod/command-types.h | 36 ++ spa/include/spa/pod/command.h | 3 - spa/include/spa/pod/event-types.h | 36 ++ spa/include/spa/pod/event.h | 3 - spa/include/spa/pod/pod-types.h | 43 +++ spa/include/spa/pod/pod.h | 9 - spa/include/spa/support/loop-types.h | 43 +++ spa/include/spa/support/loop.h | 11 +- spa/include/spa/support/plugin.h | 12 +- spa/include/spa/support/type-map-impl.h | 87 ----- .../{support/type-map.h => utils/type-info.h} | 50 +-- spa/include/spa/utils/type.h | 80 +++- spa/plugins/alsa/alsa-monitor.c | 71 ++-- spa/plugins/alsa/alsa-sink.c | 275 +++++++------- spa/plugins/alsa/alsa-source.c | 254 +++++++------ spa/plugins/alsa/alsa-utils.c | 82 ++--- spa/plugins/alsa/alsa-utils.h | 55 --- spa/plugins/audioconvert/audioconvert.c | 155 +++----- spa/plugins/audioconvert/channelmix.c | 223 +++++------- spa/plugins/audioconvert/fmt-ops.c | 65 ++-- spa/plugins/audioconvert/fmtconvert.c | 275 ++++++-------- spa/plugins/audioconvert/merger.c | 262 ++++++------- spa/plugins/audioconvert/resample.c | 214 ++++------- spa/plugins/audioconvert/splitter.c | 257 ++++++------- spa/plugins/audiomixer/audiomixer.c | 231 +++++------- spa/plugins/audiotestsrc/audiotestsrc.c | 344 +++++++----------- spa/plugins/bluez5/a2dp-sink.c | 266 ++++++-------- spa/plugins/bluez5/bluez5-monitor.c | 51 +-- spa/plugins/ffmpeg/ffmpeg-dec.c | 90 ++--- spa/plugins/ffmpeg/ffmpeg-enc.c | 94 ++--- spa/plugins/ffmpeg/ffmpeg.c | 2 +- spa/plugins/support/dbus.c | 29 +- spa/plugins/support/logger.c | 27 +- spa/plugins/support/loop.c | 46 +-- spa/plugins/support/mapper.c | 227 ------------ spa/plugins/support/meson.build | 3 +- spa/plugins/test/fakesink.c | 184 ++++------ spa/plugins/test/fakesrc.c | 190 ++++------ spa/plugins/v4l2/v4l2-monitor.c | 53 +-- spa/plugins/v4l2/v4l2-source.c | 330 +++++++---------- spa/plugins/v4l2/v4l2-utils.c | 272 +++++++------- spa/plugins/videotestsrc/draw.c | 8 +- spa/plugins/videotestsrc/videotestsrc.c | 260 ++++++------- spa/plugins/volume/volume.c | 285 ++++++--------- spa/tests/test-bluez5.c | 106 ++---- spa/tests/test-control.c | 128 ++----- spa/tests/test-convert.c | 113 ++---- spa/tests/test-convert2.c | 122 ++----- spa/tests/test-graph.c | 131 ++----- spa/tests/test-graph2.c | 17 - spa/tests/test-mixer.c | 147 +++----- spa/tests/test-perf.c | 84 +---- spa/tests/test-props.c | 124 +++---- spa/tests/test-props2.c | 9 +- spa/tests/test-ringbuffer.c | 112 ++---- spa/tests/test-v4l2.c | 98 ++--- spa/tools/spa-inspect.c | 67 +--- spa/tools/spa-monitor.c | 36 +- src/examples/audio-src.c | 36 +- src/examples/export-sink.c | 245 +++---------- src/examples/export-source.c | 159 ++++---- src/examples/export-spa.c | 7 +- src/examples/local-v4l2.c | 191 +++++----- src/examples/media-session.c | 32 +- src/examples/video-play.c | 160 +------- src/examples/video-src.c | 71 ++-- src/gst/gstpipewiredeviceprovider.c | 28 +- src/gst/gstpipewiredeviceprovider.h | 1 - src/gst/gstpipewireformat.c | 325 ++++++++--------- src/gst/gstpipewireformat.h | 8 +- src/gst/gstpipewirepool.c | 9 +- src/gst/gstpipewiresink.c | 25 +- src/gst/gstpipewiresink.h | 1 - src/gst/gstpipewiresrc.c | 26 +- src/gst/gstpipewiresrc.h | 1 - src/modules/module-audio-dsp.c | 3 +- src/modules/module-client-node.c | 9 +- src/modules/module-client-node/client-node.c | 70 ++-- .../module-client-node/client-stream.c | 101 ++--- .../module-client-node/protocol-native.c | 2 +- src/modules/module-flatpak.c | 27 +- src/modules/module-link-factory.c | 13 +- src/modules/module-media-session.c | 38 +- src/modules/module-media-session/audio-dsp.c | 8 +- src/modules/module-media-session/floatmix.c | 235 +++++------- src/modules/module-protocol-native.c | 11 +- .../module-protocol-native/connection.c | 32 +- .../module-protocol-native/protocol-native.c | 112 +----- src/modules/module-rtkit.c | 4 +- src/modules/module-suspend-on-idle.c | 6 +- src/modules/spa/module-node-factory.c | 3 +- src/modules/spa/spa-monitor.c | 50 ++- src/modules/spa/spa-node.c | 17 +- src/pipewire/client.c | 2 +- src/pipewire/control.c | 15 +- src/pipewire/core.c | 60 +-- src/pipewire/core.h | 3 - src/pipewire/factory.c | 6 +- src/pipewire/global.c | 4 +- src/pipewire/interfaces.h | 59 +-- src/pipewire/link.c | 44 +-- src/pipewire/loop.c | 13 +- src/pipewire/meson.build | 1 - src/pipewire/module.c | 2 +- src/pipewire/node.c | 10 +- src/pipewire/pipewire.c | 31 +- src/pipewire/pipewire.h | 4 +- src/pipewire/port.c | 27 +- src/pipewire/private.h | 2 - src/pipewire/protocol.c | 9 +- src/pipewire/protocol.h | 2 +- src/pipewire/remote.c | 71 +--- src/pipewire/stream.c | 67 ++-- src/pipewire/type.c | 67 ---- src/pipewire/type.h | 56 +-- src/tools/pipewire-cli.c | 89 ++--- src/tools/pipewire-monitor.c | 46 +-- 162 files changed, 5200 insertions(+), 7461 deletions(-) create mode 100644 spa/include/spa/buffer/buffer-types.h create mode 100644 spa/include/spa/buffer/meta-types.h create mode 100644 spa/include/spa/debug/types.h create mode 100644 spa/include/spa/monitor/monitor-types.h create mode 100644 spa/include/spa/node/command-types.h create mode 100644 spa/include/spa/node/event-types.h create mode 100644 spa/include/spa/node/io-types.h create mode 100644 spa/include/spa/node/node-types.h create mode 100644 spa/include/spa/param/audio/format-types.h create mode 100644 spa/include/spa/param/audio/raw-types.h delete mode 100644 spa/include/spa/param/audio/raw-utils.h create mode 100644 spa/include/spa/param/buffers-types.h create mode 100644 spa/include/spa/param/format-types.h delete mode 100644 spa/include/spa/param/format-utils.h create mode 100644 spa/include/spa/param/io-types.h create mode 100644 spa/include/spa/param/meta-types.h create mode 100644 spa/include/spa/param/param-types.h create mode 100644 spa/include/spa/param/props-types.h create mode 100644 spa/include/spa/param/video/format-types.h create mode 100644 spa/include/spa/param/video/raw-types.h delete mode 100644 spa/include/spa/param/video/raw-utils.h create mode 100644 spa/include/spa/pod/command-types.h create mode 100644 spa/include/spa/pod/event-types.h create mode 100644 spa/include/spa/pod/pod-types.h create mode 100644 spa/include/spa/support/loop-types.h delete mode 100644 spa/include/spa/support/type-map-impl.h rename spa/include/spa/{support/type-map.h => utils/type-info.h} (51%) delete mode 100644 spa/plugins/support/mapper.c delete mode 100644 src/pipewire/type.c diff --git a/spa/include/spa/buffer/buffer-types.h b/spa/include/spa/buffer/buffer-types.h new file mode 100644 index 000000000..36fbe0781 --- /dev/null +++ b/spa/include/spa/buffer/buffer-types.h @@ -0,0 +1,52 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_BUFFER_TYPES_H__ +#define __SPA_BUFFER_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__Buffer SPA_TYPE_POINTER_BASE "Buffer" +#define SPA_TYPE_BUFFER_BASE SPA_TYPE__Buffer ":" + +/** Buffers contain data of a certain type */ +#define SPA_TYPE__Data SPA_TYPE_ENUM_BASE "Data" +#define SPA_TYPE_DATA_BASE SPA_TYPE__Data ":" + +/** base type for fd based memory */ +#define SPA_TYPE_DATA__Fd SPA_TYPE_DATA_BASE "Fd" +#define SPA_TYPE_DATA_FD_BASE SPA_TYPE_DATA__Fd ":" + +static const struct spa_type_info spa_type_data_type[] = { + { SPA_DATA_MemPtr, SPA_TYPE_DATA_BASE "MemPtr", SPA_POD_TYPE_INT, }, + { SPA_DATA_MemFd, SPA_TYPE_DATA_FD_BASE "MemFd", SPA_POD_TYPE_INT, }, + { SPA_DATA_DmaBuf, SPA_TYPE_DATA_FD_BASE "DmaBuf", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_BUFFER_TYPES_H__ */ diff --git a/spa/include/spa/buffer/buffer.h b/spa/include/spa/buffer/buffer.h index 9cf6514a3..1949a96b1 100644 --- a/spa/include/spa/buffer/buffer.h +++ b/spa/include/spa/buffer/buffer.h @@ -26,46 +26,19 @@ extern "C" { #include #include -#include /** \page page_buffer Buffers * * Buffers describe the data and metadata that is exchanged between * ports of a node. */ -#define SPA_TYPE__Buffer SPA_TYPE_POINTER_BASE "Buffer" -#define SPA_TYPE_BUFFER_BASE SPA_TYPE__Buffer ":" -/** Buffers contain data of a certain type */ -#define SPA_TYPE__Data SPA_TYPE_ENUM_BASE "DataType" -#define SPA_TYPE_DATA_BASE SPA_TYPE__Data ":" - -/** The data type for a plain memory pointer. The data member points to - * the memory. */ -#define SPA_TYPE_DATA__MemPtr SPA_TYPE_DATA_BASE "MemPtr" - -/** base type for fd based memory */ -#define SPA_TYPE_DATA__Fd SPA_TYPE_DATA_BASE "Fd" -#define SPA_TYPE_DATA_FD_BASE SPA_TYPE_DATA__Fd ":" - -#define SPA_TYPE_DATA_FD__MemFd SPA_TYPE_DATA_FD_BASE "MemFd" -#define SPA_TYPE_DATA_FD__DmaBuf SPA_TYPE_DATA_FD_BASE "DmaBuf" - -struct spa_type_data { - uint32_t MemPtr; /**< system memory */ - uint32_t MemFd; /**< memory accesible with an fd */ - uint32_t DmaBuf; /**< dmabuf fd */ +enum spa_data_type { + SPA_DATA_MemPtr, + SPA_DATA_MemFd, + SPA_DATA_DmaBuf, }; -static inline void spa_type_data_map(struct spa_type_map *map, struct spa_type_data *type) -{ - if (type->MemPtr == 0) { - type->MemPtr = spa_type_map_get_id(map, SPA_TYPE_DATA__MemPtr); - type->MemFd = spa_type_map_get_id(map, SPA_TYPE_DATA_FD__MemFd); - type->DmaBuf = spa_type_map_get_id(map, SPA_TYPE_DATA_FD__DmaBuf); - } -} - /** Chunk of memory */ struct spa_chunk { uint32_t offset; /**< offset of valid data. Should be taken @@ -79,7 +52,7 @@ struct spa_chunk { /** Data for a buffer */ struct spa_data { - uint32_t type; /**< memory type */ + uint32_t type; /**< memory type, one of enum spa_data_type */ uint32_t flags; /**< data flags */ int fd; /**< optional fd for data */ uint32_t mapoffset; /**< offset to map fd at */ diff --git a/spa/include/spa/buffer/meta-types.h b/spa/include/spa/buffer/meta-types.h new file mode 100644 index 000000000..ff4c8a3f5 --- /dev/null +++ b/spa/include/spa/buffer/meta-types.h @@ -0,0 +1,50 @@ +/* Simple Plugin API + * Copyright (C) 2017 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_META_H__ +#define __SPA_META_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__Meta SPA_TYPE_POINTER_BASE "Meta" +#define SPA_TYPE_META_BASE SPA_TYPE__Meta ":" + +#define SPA_TYPE_META__Region SPA_TYPE_META_BASE "Region" +#define SPA_TYPE_META_REGION_BASE SPA_TYPE_META__Region ":" + +#define SPA_TYPE_META__RegionArray SPA_TYPE_META_BASE "RegionArray" +#define SPA_TYPE_META_REGION_ARRAY_BASE SPA_TYPE_META__RegionArray ":" + +static const struct spa_type_info spa_type_meta_type[] = { + { SPA_META_Header, SPA_TYPE_META_BASE "Header", SPA_POD_TYPE_INT, }, + { SPA_META_VideoCrop, SPA_TYPE_META_REGION_BASE "VideoCrop", SPA_POD_TYPE_INT, }, + { SPA_META_VideoDamage, SPA_TYPE_META_REGION_ARRAY_BASE "VideoDamage", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_META_H__ */ diff --git a/spa/include/spa/buffer/meta.h b/spa/include/spa/buffer/meta.h index b0416912e..b98306b01 100644 --- a/spa/include/spa/buffer/meta.h +++ b/spa/include/spa/buffer/meta.h @@ -25,24 +25,16 @@ extern "C" { #endif #include -#include /** \page page_meta Metadata * * Metadata contains extra information on a buffer. */ -#define SPA_TYPE__Meta SPA_TYPE_POINTER_BASE "Meta" -#define SPA_TYPE_META_BASE SPA_TYPE__Meta ":" - -#define SPA_TYPE_META__Header SPA_TYPE_META_BASE "Header" -#define SPA_TYPE_META__Region SPA_TYPE_META_BASE "Region" -#define SPA_TYPE_META_REGION_BASE SPA_TYPE_META__Region ":" - -#define SPA_TYPE_META__RegionArray SPA_TYPE_META_BASE "RegionArray" -#define SPA_TYPE_META_REGION_ARRAY_BASE SPA_TYPE_META__RegionArray ":" - -#define SPA_TYPE_META__VideoCrop SPA_TYPE_META_REGION_BASE "VideoCrop" -#define SPA_TYPE_META__VideoDamage SPA_TYPE_META_REGION_ARRAY_BASE "VideoDamage" +enum spa_meta_type { + SPA_META_Header, + SPA_META_VideoCrop, + SPA_META_VideoDamage, +}; /** * A metadata element. @@ -52,7 +44,7 @@ extern "C" { * itself. */ struct spa_meta { - uint32_t type; /**< metadata type */ + uint32_t type; /**< metadata type, one of enum spa_meta_type */ void *data; /**< pointer to metadata */ uint32_t size; /**< size of metadata */ }; @@ -91,21 +83,6 @@ struct spa_meta_region { spa_meta_check(pos, meta); \ (pos)++) -struct spa_type_meta { - uint32_t Header; - uint32_t VideoCrop; - uint32_t VideoDamage; -}; - -static inline void spa_type_meta_map(struct spa_type_map *map, struct spa_type_meta *type) -{ - if (type->Header == 0) { - type->Header = spa_type_map_get_id(map, SPA_TYPE_META__Header); - type->VideoCrop = spa_type_map_get_id(map, SPA_TYPE_META__VideoCrop); - type->VideoDamage = spa_type_map_get_id(map, SPA_TYPE_META__VideoDamage); - } -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/debug/buffer.h b/spa/include/spa/debug/buffer.h index f90a0cfef..6277218a7 100644 --- a/spa/include/spa/debug/buffer.h +++ b/spa/include/spa/debug/buffer.h @@ -24,15 +24,14 @@ extern "C" { #endif -#include #include +#include #ifndef spa_debug #define spa_debug(...) ({ fprintf(stderr, __VA_ARGS__);fputc('\n', stderr); }) #endif -static inline int spa_debug_buffer(int indent, - struct spa_type_map *map, const struct spa_buffer *buffer) +static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer) { int i; @@ -43,25 +42,33 @@ static inline int spa_debug_buffer(int indent, struct spa_meta *m = &buffer->metas[i]; const char *type_name; - type_name = spa_type_map_get_type(map, m->type); + type_name = spa_debug_type_find_name(spa_type_meta_type, m->type); spa_debug("%*s" " meta %d: type %d (%s), data %p, size %d:", indent, "", i, m->type, type_name, m->data, m->size); - if (!strcmp(type_name, SPA_TYPE_META__Header)) { + switch (m->type) { + case SPA_META_Header: + { struct spa_meta_header *h = m->data; spa_debug("%*s" " struct spa_meta_header:", indent, ""); spa_debug("%*s" " flags: %08x", indent, "", h->flags); spa_debug("%*s" " seq: %u", indent, "", h->seq); spa_debug("%*s" " pts: %" PRIi64, indent, "", h->pts); spa_debug("%*s" " dts_offset: %" PRIi64, indent, "", h->dts_offset); - } else if (!strcmp(type_name, SPA_TYPE_META__VideoCrop)) { + break; + } + case SPA_META_VideoCrop: + { struct spa_meta_video_crop *h = m->data; spa_debug("%*s" " struct spa_meta_video_crop:", indent, ""); spa_debug("%*s" " x: %d", indent, "", h->x); spa_debug("%*s" " y: %d", indent, "", h->y); spa_debug("%*s" " width: %d", indent, "", h->width); spa_debug("%*s" " height: %d", indent, "", h->height); - } else { + break; + } + case SPA_META_VideoDamage: + default: spa_debug("%*s" " Unknown:", indent, ""); spa_debug_mem(5, m->data, m->size); } @@ -70,7 +77,7 @@ static inline int spa_debug_buffer(int indent, for (i = 0; i < buffer->n_datas; i++) { struct spa_data *d = &buffer->datas[i]; spa_debug("%*s" " type: %d (%s)", indent, "", d->type, - spa_type_map_get_type(map, d->type)); + spa_debug_type_find_name(spa_type_data_type, d->type)); spa_debug("%*s" " flags: %d", indent, "", d->flags); spa_debug("%*s" " data: %p", indent, "", d->data); spa_debug("%*s" " fd: %d", indent, "", d->fd); diff --git a/spa/include/spa/debug/format.h b/spa/include/spa/debug/format.h index 820240a6b..bd8d9523f 100644 --- a/spa/include/spa/debug/format.h +++ b/spa/include/spa/debug/format.h @@ -24,11 +24,13 @@ extern "C" { #endif -#include #include +#include +#include +#include static inline int -spa_debug_format_value(struct spa_type_map *map, +spa_debug_format_value(const struct spa_type_info *info, uint32_t type, void *body, uint32_t size) { switch (type) { @@ -36,21 +38,21 @@ spa_debug_format_value(struct spa_type_map *map, fprintf(stderr, "%s", *(int32_t *) body ? "true" : "false"); break; case SPA_POD_TYPE_ID: + case SPA_POD_TYPE_INT: { - const char *str = map ? spa_type_map_get_type(map, *(int32_t *) body) : NULL; + const char *str = spa_debug_type_find_name(info, *(int32_t *) body); + char tmp[64]; if (str) { const char *h = rindex(str, ':'); if (h) str = h + 1; } else { - str = "unknown"; + snprintf(tmp, sizeof(tmp), "%d", *(int32_t*)body); + str = tmp; } fprintf(stderr, "%s", str); break; } - case SPA_POD_TYPE_INT: - fprintf(stderr, "%" PRIi32, *(int32_t *) body); - break; case SPA_POD_TYPE_LONG: fprintf(stderr, "%" PRIi64, *(int64_t *) body); break; @@ -88,7 +90,7 @@ spa_debug_format_value(struct spa_type_map *map, } static inline int spa_debug_format(int indent, - struct spa_type_map *map, const struct spa_pod *format) + const struct spa_type_info *info, const struct spa_pod *format) { int i; const char *media_type; @@ -121,19 +123,25 @@ static inline int spa_debug_format(int indent, if (format == NULL || SPA_POD_TYPE(format) != SPA_POD_TYPE_OBJECT) return -EINVAL; + + if (spa_pod_object_parse(format, "I", &mtype, "I", &mstype) < 0) return -EINVAL; - media_type = spa_type_map_get_type(map, mtype); - media_subtype = spa_type_map_get_type(map, mstype); + media_type = spa_debug_type_find_name(spa_type_media_type, mtype); + media_subtype = spa_debug_type_find_name(spa_type_media_subtype, mstype); - fprintf(stderr, "%-6s %s/%s\n", "", rindex(media_type, ':') + 1, - rindex(media_subtype, ':') + 1); + fprintf(stderr, "%-6s %s/%s\n", "", + media_type ? rindex(media_type, ':') + 1 : "unknown", + media_subtype ? rindex(media_subtype, ':') + 1 : "unknown"); + + info = spa_type_format_get_ids(mtype, mstype); SPA_POD_OBJECT_FOREACH((struct spa_pod_object*)format, pod) { struct spa_pod_prop *prop; const char *key; + const struct spa_type_info *ti; if (pod->type != SPA_POD_TYPE_PROP) continue; @@ -144,13 +152,15 @@ static inline int spa_debug_format(int indent, (prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL)) continue; - key = spa_type_map_get_type(map, prop->body.key); + ti = spa_debug_type_find(info, prop->body.key); + key = ti ? ti->name : NULL; - fprintf(stderr, " %20s : (%s) ", rindex(key, ':') + 1, + fprintf(stderr, " %20s : (%s) ", + key ? rindex(key, ':') + 1 : "unknown", pod_type_names[prop->body.value.type]); if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) { - spa_debug_format_value(map, + spa_debug_format_value(ti->values, prop->body.value.type, SPA_POD_BODY(&prop->body.value), prop->body.value.size); @@ -180,7 +190,7 @@ static inline int spa_debug_format(int indent, SPA_POD_PROP_ALTERNATIVE_FOREACH(&prop->body, prop->pod.size, alt) { if (i > 0) fprintf(stderr, "%s", sep); - spa_debug_format_value(map, + spa_debug_format_value(ti->values, prop->body.value.type, alt, prop->body.value.size); diff --git a/spa/include/spa/debug/pod.h b/spa/include/spa/debug/pod.h index 5a2d4c9e9..135d585fc 100644 --- a/spa/include/spa/debug/pod.h +++ b/spa/include/spa/debug/pod.h @@ -24,8 +24,8 @@ extern "C" { #endif -#include #include +#include #include #include @@ -34,7 +34,7 @@ extern "C" { #endif static inline int -spa_debug_pod_value(int indent, struct spa_type_map *map, +spa_debug_pod_value(int indent, const struct spa_type_info *info, uint32_t type, void *body, uint32_t size) { switch (type) { @@ -43,7 +43,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, break; case SPA_POD_TYPE_ID: spa_debug("%*s" "Id %d %s", indent, "", *(int32_t *) body, - spa_type_map_get_type(map, *(int32_t *) body)); + spa_debug_type_find_name(info, *(int32_t *) body)); break; case SPA_POD_TYPE_INT: spa_debug("%*s" "Int %d", indent, "", *(int32_t *) body); @@ -67,7 +67,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, { struct spa_pod_pointer_body *b = body; spa_debug("%*s" "Pointer %s %p", indent, "", - map ? spa_type_map_get_type(map, b->type) : "*no map*", b->value); + spa_debug_type_find_name(info, b->type), b->value); break; } case SPA_POD_TYPE_RECTANGLE: @@ -93,7 +93,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, b->child.size, b->child.type); SPA_POD_ARRAY_BODY_FOREACH(b, size, p) - spa_debug_pod_value(indent + 2, map, b->child.type, p, b->child.size); + spa_debug_pod_value(indent + 2, info, b->child.type, p, b->child.size); break; } case SPA_POD_TYPE_STRUCT: @@ -101,19 +101,20 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, struct spa_pod *b = body, *p; spa_debug("%*s" "Struct: size %d", indent, "", size); SPA_POD_FOREACH(b, size, p) - spa_debug_pod_value(indent + 2, map, p->type, SPA_POD_BODY(p), p->size); + spa_debug_pod_value(indent + 2, info, p->type, SPA_POD_BODY(p), p->size); break; } case SPA_POD_TYPE_OBJECT: { struct spa_pod_object_body *b = body; struct spa_pod *p; + const struct spa_type_info *ti = spa_debug_type_find(info, b->type); spa_debug("%*s" "Object: size %d, id %s, type %s", indent, "", size, - map ? spa_type_map_get_type(map, b->id) : "*no map*", - map ? spa_type_map_get_type(map, b->type) : "*no map*"); + spa_debug_type_find_name(info, b->id), ti ? ti->name : "unknown"); SPA_POD_OBJECT_BODY_FOREACH(b, size, p) - spa_debug_pod_value(indent + 2, map, p->type, SPA_POD_BODY(p), p->size); + spa_debug_pod_value(indent + 2, ti ? ti->values : NULL, + p->type, SPA_POD_BODY(p), p->size); break; } case SPA_POD_TYPE_PROP: @@ -123,12 +124,12 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, int i; spa_debug("%*s" "Prop: key %s, flags %d", indent, "", - map ? spa_type_map_get_type(map, b->key) : "*no map*", b->flags); + spa_debug_type_find_name(info, b->key), b->flags); if (b->flags & SPA_POD_PROP_FLAG_UNSET) spa_debug("%*s" "Unset (Default):", indent + 2, ""); else spa_debug("%*s" "Value: size %u", indent + 2, "", b->value.size); - spa_debug_pod_value(indent + 4, map, b->value.type, SPA_POD_BODY(&b->value), + spa_debug_pod_value(indent + 4, info, b->value.type, SPA_POD_BODY(&b->value), b->value.size); i = 0; @@ -143,7 +144,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, spa_debug("%*s" "Max: ", indent + 2, ""); else break; - spa_debug_pod_value(indent + 4, map, b->value.type, alt, b->value.size); + spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size); i++; } break; @@ -157,7 +158,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, spa_debug("%*s" "Step: ", indent + 2, ""); else break; - spa_debug_pod_value(indent + 4, map, b->value.type, alt, b->value.size); + spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size); i++; } break; @@ -166,7 +167,7 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, if (i == 0) { spa_debug("%*s" "Enum:", indent + 2, ""); } - spa_debug_pod_value(indent + 4, map, b->value.type, alt, b->value.size); + spa_debug_pod_value(indent + 4, info, b->value.type, alt, b->value.size); i++; } break; @@ -191,9 +192,9 @@ spa_debug_pod_value(int indent, struct spa_type_map *map, } static inline int spa_debug_pod(int indent, - struct spa_type_map *map, const struct spa_pod *pod) + const struct spa_type_info *info, const struct spa_pod *pod) { - return spa_debug_pod_value(indent, map, + return spa_debug_pod_value(indent, info, SPA_POD_TYPE(pod), SPA_POD_BODY(pod), SPA_POD_BODY_SIZE(pod)); diff --git a/spa/include/spa/debug/types.h b/spa/include/spa/debug/types.h new file mode 100644 index 000000000..3335b6202 --- /dev/null +++ b/spa/include/spa/debug/types.h @@ -0,0 +1,80 @@ +/* Simple Plugin API + * Copyright (C) 2018 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_DEBUG_TYPES_H__ +#define __SPA_DEBUG_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +static const struct spa_type_info spa_debug_types[] = +{ + { SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_monitor }, + { SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_node }, + { SPA_ID_INVALID, "", SPA_POD_TYPE_ID, spa_type_param_buffers }, + { 0, NULL, }, +}; + +static inline const struct spa_type_info *spa_debug_type_find(const struct spa_type_info *info, uint32_t id) +{ + const struct spa_type_info *res; + + while (info && info->name) { + if (info->id == SPA_ID_INVALID) + if ((res = spa_debug_type_find(info->values, id))) + return res; + if (info->id == id) + return info; + info++; + } + return NULL; +} + +static inline const char *spa_debug_type_find_name(const struct spa_type_info *info, uint32_t id) +{ + const struct spa_type_info *type; + if ((type = spa_debug_type_find(info, id)) == NULL) + return NULL; + return type->name; +} + +static inline uint32_t spa_debug_type_find_id(const struct spa_type_info *info, const char *name) +{ + while (info && info->name) { + uint32_t res; + if (strcmp(info->name, name) == 0) + return info->id; + if ((res = spa_debug_type_find_id(info->values, name)) != SPA_ID_INVALID) + return res; + info++; + } + return SPA_ID_INVALID; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_DEBUG_NODE_H__ */ diff --git a/spa/include/spa/meson.build b/spa/include/spa/meson.build index cae70833d..7af03580a 100644 --- a/spa/include/spa/meson.build +++ b/spa/include/spa/meson.build @@ -37,7 +37,6 @@ spa_param_headers = [ 'param/meta.h', 'param/io.h', 'param/format.h', - 'param/format-utils.h', ] install_headers(spa_param_headers, @@ -60,8 +59,6 @@ spa_support_headers = [ 'support/log-impl.h', 'support/loop.h', 'support/plugin.h', - 'support/type-map.h', - 'support/type-map-impl.h', ] install_headers(spa_support_headers, @@ -83,7 +80,6 @@ spa_audio_headers = [ 'param/audio/format.h', 'param/audio/format-utils.h', 'param/audio/raw.h', - 'param/audio/raw-utils.h', ] install_headers(spa_audio_headers, @@ -97,7 +93,6 @@ spa_video_headers = [ 'param/video/format-utils.h', 'param/video/multiview.h', 'param/video/raw.h', - 'param/video/raw-utils.h', ] install_headers(spa_video_headers, diff --git a/spa/include/spa/monitor/monitor-types.h b/spa/include/spa/monitor/monitor-types.h new file mode 100644 index 000000000..cb09ebeba --- /dev/null +++ b/spa/include/spa/monitor/monitor-types.h @@ -0,0 +1,86 @@ +/* Simple Plugin API + * Copyright (C) 2018 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_MONITOR_TYPES_H__ +#define __SPA_MONITOR_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define SPA_TYPE_EVENT__Monitor SPA_TYPE_EVENT_BASE "Monitor" +#define SPA_TYPE_EVENT_MONITOR_BASE SPA_TYPE_EVENT__Monitor ":" + + +#define SPA_TYPE__MonitorItemFlags SPA_TYPE_FLAGS_BASE "MonitorItemFlags" +#define SPA_TYPE_MONITOR_ITEM_FLAGS_BASE SPA_TYPE__MonitorItemFlags ":" + +static const struct spa_type_info spa_type_monitor_item_flags[] = { + { SPA_MONITOR_ITEM_FLAG_NONE, SPA_TYPE_MONITOR_ITEM_FLAGS_BASE "none", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#define SPA_TYPE__MonitorItemState SPA_TYPE_ENUM_BASE "MonitorItemState" +#define SPA_TYPE_MONITOR_ITEM_STATE_BASE SPA_TYPE__MonitorItemState ":" + +static const struct spa_type_info spa_type_monitor_item_state[] = { + { SPA_MONITOR_ITEM_STATE_AVAILABLE, SPA_TYPE_MONITOR_ITEM_STATE_BASE "available", SPA_POD_TYPE_INT, }, + { SPA_MONITOR_ITEM_STATE_DISABLED, SPA_TYPE_MONITOR_ITEM_STATE_BASE "disabled", SPA_POD_TYPE_INT, }, + { SPA_MONITOR_ITEM_STATE_UNAVAILABLE, SPA_TYPE_MONITOR_ITEM_STATE_BASE "unavailable", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#define SPA_TYPE__MonitorItem SPA_TYPE_POD_OBJECT_BASE "MonitorItem" +#define SPA_TYPE_MONITOR_ITEM_BASE SPA_TYPE__MonitorItem ":" + +static const struct spa_type_info spa_type_monitor_item_ids[] = { + { SPA_MONITOR_ITEM_id, SPA_TYPE_MONITOR_ITEM_BASE "id", SPA_POD_TYPE_STRING, }, + { SPA_MONITOR_ITEM_flags, SPA_TYPE_MONITOR_ITEM_BASE "flags", SPA_POD_TYPE_INT, + spa_type_monitor_item_flags }, + { SPA_MONITOR_ITEM_state, SPA_TYPE_MONITOR_ITEM_BASE "state", SPA_POD_TYPE_INT, + spa_type_monitor_item_state }, + { SPA_MONITOR_ITEM_name, SPA_TYPE_MONITOR_ITEM_BASE "name", SPA_POD_TYPE_STRING, }, + { SPA_MONITOR_ITEM_class, SPA_TYPE_MONITOR_ITEM_BASE "class", SPA_POD_TYPE_STRING, }, + { SPA_MONITOR_ITEM_info, SPA_TYPE_MONITOR_ITEM_BASE "info", SPA_POD_TYPE_POD, }, + { SPA_MONITOR_ITEM_factory, SPA_TYPE_MONITOR_ITEM_BASE "factory", SPA_POD_TYPE_POINTER, }, + { 0, NULL, }, +}; + +#define SPA_TYPE__Monitor SPA_TYPE_INTERFACE_BASE "Monitor" +#define SPA_TYPE_MONITOR_BASE SPA_TYPE__Monitor ":" + +static const struct spa_type_info spa_type_monitor[] = { + { SPA_ID_INTERFACE_Monitor, SPA_TYPE__Monitor, SPA_POD_TYPE_ID, }, + { SPA_ID_EVENT_MONITOR_Added, SPA_TYPE_EVENT_MONITOR_BASE "Added", SPA_POD_TYPE_ID, }, + { SPA_ID_EVENT_MONITOR_Removed, SPA_TYPE_EVENT_MONITOR_BASE "Removed", SPA_POD_TYPE_ID, }, + { SPA_ID_EVENT_MONITOR_Changed, SPA_TYPE_EVENT_MONITOR_BASE "Changed", SPA_POD_TYPE_ID, }, + { SPA_ID_OBJECT_MonitorItem, SPA_TYPE__MonitorItem, SPA_POD_TYPE_OBJECT, + spa_type_monitor_item_ids}, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_MONITOR_TYPES_H__ */ diff --git a/spa/include/spa/monitor/monitor.h b/spa/include/spa/monitor/monitor.h index e509db238..17bc6aeb1 100644 --- a/spa/include/spa/monitor/monitor.h +++ b/spa/include/spa/monitor/monitor.h @@ -25,68 +25,23 @@ extern "C" { #endif struct spa_monitor; -#define SPA_TYPE__Monitor SPA_TYPE_INTERFACE_BASE "Monitor" -#define SPA_TYPE_MONITOR_BASE SPA_TYPE__Monitor ":" #include #include #include #include -#define SPA_TYPE_EVENT__Monitor SPA_TYPE_EVENT_BASE "Monitor" -#define SPA_TYPE_EVENT_MONITOR_BASE SPA_TYPE_EVENT__Monitor ":" - -#define SPA_TYPE_EVENT_MONITOR__Added SPA_TYPE_EVENT_MONITOR_BASE "Added" -#define SPA_TYPE_EVENT_MONITOR__Removed SPA_TYPE_EVENT_MONITOR_BASE "Removed" -#define SPA_TYPE_EVENT_MONITOR__Changed SPA_TYPE_EVENT_MONITOR_BASE "Changed" - - -#define SPA_TYPE__MonitorItem SPA_TYPE_POD_OBJECT_BASE "MonitorItem" -#define SPA_TYPE_MONITOR_ITEM_BASE SPA_TYPE__MonitorItem ":" - -#define SPA_TYPE_MONITOR_ITEM__id SPA_TYPE_MONITOR_ITEM_BASE "id" -#define SPA_TYPE_MONITOR_ITEM__flags SPA_TYPE_MONITOR_ITEM_BASE "flags" -#define SPA_TYPE_MONITOR_ITEM__state SPA_TYPE_MONITOR_ITEM_BASE "state" -#define SPA_TYPE_MONITOR_ITEM__name SPA_TYPE_MONITOR_ITEM_BASE "name" -#define SPA_TYPE_MONITOR_ITEM__class SPA_TYPE_MONITOR_ITEM_BASE "class" -#define SPA_TYPE_MONITOR_ITEM__info SPA_TYPE_MONITOR_ITEM_BASE "info" -#define SPA_TYPE_MONITOR_ITEM__factory SPA_TYPE_MONITOR_ITEM_BASE "factory" - -struct spa_type_monitor { - uint32_t Monitor; /*< the monitor object */ - - uint32_t Added; /*< item added event */ - uint32_t Removed; /*< item removed event */ - uint32_t Changed; /*< item changed event */ - - uint32_t MonitorItem; /*< monitor item object */ - uint32_t id; /*< item id property */ - uint32_t flags; /*< item flags property */ - uint32_t state; /*< item state property */ - uint32_t name; /*< item name property */ - uint32_t klass; /*< item klass property */ - uint32_t info; /*< item info property */ - uint32_t factory; /*< item factory property */ +/** properties for SPA_ID_OBJECT_MonitorItem */ +enum spa_monitor_item { + SPA_MONITOR_ITEM_id, + SPA_MONITOR_ITEM_flags, + SPA_MONITOR_ITEM_state, + SPA_MONITOR_ITEM_name, + SPA_MONITOR_ITEM_class, + SPA_MONITOR_ITEM_info, + SPA_MONITOR_ITEM_factory, }; -static inline void spa_type_monitor_map(struct spa_type_map *map, struct spa_type_monitor *type) -{ - if (type->Monitor == 0) { - type->Monitor = spa_type_map_get_id(map, SPA_TYPE__Monitor); - type->Added = spa_type_map_get_id(map, SPA_TYPE_EVENT_MONITOR__Added); - type->Removed = spa_type_map_get_id(map, SPA_TYPE_EVENT_MONITOR__Removed); - type->Changed = spa_type_map_get_id(map, SPA_TYPE_EVENT_MONITOR__Changed); - type->MonitorItem = spa_type_map_get_id(map, SPA_TYPE__MonitorItem); - type->id = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__id); - type->flags = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__flags); - type->state = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__state); - type->name = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__name); - type->klass = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__class); - type->info = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__info); - type->factory = spa_type_map_get_id(map, SPA_TYPE_MONITOR_ITEM__factory); - } -} - enum spa_monitor_item_flags { SPA_MONITOR_ITEM_FLAG_NONE = 0, }; diff --git a/spa/include/spa/node/command-types.h b/spa/include/spa/node/command-types.h new file mode 100644 index 000000000..b8be1af38 --- /dev/null +++ b/spa/include/spa/node/command-types.h @@ -0,0 +1,55 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_COMMAND_NODE_TYPES_H__ +#define __SPA_COMMAND_NODE_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE_COMMAND__Node SPA_TYPE_COMMAND_BASE "Node" +#define SPA_TYPE_COMMAND_NODE_BASE SPA_TYPE_COMMAND__Node ":" + +/** Suspend a node. This will release all resources of the node */ +#define SPA_TYPE_COMMAND_NODE__Suspend SPA_TYPE_COMMAND_NODE_BASE "Suspend" +/** Pause processing of a node */ +#define SPA_TYPE_COMMAND_NODE__Pause SPA_TYPE_COMMAND_NODE_BASE "Pause" +/** Start processing of a node */ +#define SPA_TYPE_COMMAND_NODE__Start SPA_TYPE_COMMAND_NODE_BASE "Start" +/** Enable ports of a node. When sent to a port, enables just that port. Enabled + * ports on a Started node begin streaming immediately */ +#define SPA_TYPE_COMMAND_NODE__Enable SPA_TYPE_COMMAND_NODE_BASE "Enable" +/** Disable ports of a node. When sent to a port, disables just that port. */ +#define SPA_TYPE_COMMAND_NODE__Disable SPA_TYPE_COMMAND_NODE_BASE "Disable" +/** Flush all data from the node or port */ +#define SPA_TYPE_COMMAND_NODE__Flush SPA_TYPE_COMMAND_NODE_BASE "Flush" +/** Drain all data from the node or port */ +#define SPA_TYPE_COMMAND_NODE__Drain SPA_TYPE_COMMAND_NODE_BASE "Drain" +/** Set a marker on a node or port */ +#define SPA_TYPE_COMMAND_NODE__Marker SPA_TYPE_COMMAND_NODE_BASE "Marker" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _SPA_COMMAND_NODE_TYPES_H__ */ diff --git a/spa/include/spa/node/command.h b/spa/include/spa/node/command.h index 9f7734e36..047c3e36a 100644 --- a/spa/include/spa/node/command.h +++ b/spa/include/spa/node/command.h @@ -24,56 +24,8 @@ extern "C" { #endif -#include #include -#define SPA_TYPE_COMMAND__Node SPA_TYPE_COMMAND_BASE "Node" -#define SPA_TYPE_COMMAND_NODE_BASE SPA_TYPE_COMMAND__Node ":" - -/** Suspend a node. This will release all resources of the node */ -#define SPA_TYPE_COMMAND_NODE__Suspend SPA_TYPE_COMMAND_NODE_BASE "Suspend" -/** Pause processing of a node */ -#define SPA_TYPE_COMMAND_NODE__Pause SPA_TYPE_COMMAND_NODE_BASE "Pause" -/** Start processing of a node */ -#define SPA_TYPE_COMMAND_NODE__Start SPA_TYPE_COMMAND_NODE_BASE "Start" -/** Enable ports of a node. When sent to a port, enables just that port. Enabled - * ports on a Started node begin streaming immediately */ -#define SPA_TYPE_COMMAND_NODE__Enable SPA_TYPE_COMMAND_NODE_BASE "Enable" -/** Disable ports of a node. When sent to a port, disables just that port. */ -#define SPA_TYPE_COMMAND_NODE__Disable SPA_TYPE_COMMAND_NODE_BASE "Disable" -/** Flush all data from the node or port */ -#define SPA_TYPE_COMMAND_NODE__Flush SPA_TYPE_COMMAND_NODE_BASE "Flush" -/** Drain all data from the node or port */ -#define SPA_TYPE_COMMAND_NODE__Drain SPA_TYPE_COMMAND_NODE_BASE "Drain" -/** Set a marker on a node or port */ -#define SPA_TYPE_COMMAND_NODE__Marker SPA_TYPE_COMMAND_NODE_BASE "Marker" - -struct spa_type_command_node { - uint32_t Suspend; - uint32_t Pause; - uint32_t Start; - uint32_t Enable; - uint32_t Disable; - uint32_t Flush; - uint32_t Drain; - uint32_t Marker; -}; - -static inline void -spa_type_command_node_map(struct spa_type_map *map, struct spa_type_command_node *type) -{ - if (type->Suspend == 0) { - type->Suspend = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Suspend); - type->Pause = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Pause); - type->Start = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Start); - type->Enable = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Enable); - type->Disable = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Disable); - type->Flush = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Flush); - type->Drain = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Drain); - type->Marker = spa_type_map_get_id(map, SPA_TYPE_COMMAND_NODE__Marker); - } -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/node/event-types.h b/spa/include/spa/node/event-types.h new file mode 100644 index 000000000..6eeb1cd44 --- /dev/null +++ b/spa/include/spa/node/event-types.h @@ -0,0 +1,41 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_EVENT_NODE_TYPES_H__ +#define __SPA_EVENT_NODE_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE_EVENT__Node SPA_TYPE_EVENT_BASE "Node" +#define SPA_TYPE_EVENT_NODE_BASE SPA_TYPE_EVENT__Node ":" + +#define SPA_TYPE_EVENT_NODE__Error SPA_TYPE_EVENT_NODE_BASE "Error" +#define SPA_TYPE_EVENT_NODE__Buffering SPA_TYPE_EVENT_NODE_BASE "Buffering" +#define SPA_TYPE_EVENT_NODE__RequestRefresh SPA_TYPE_EVENT_NODE_BASE "RequestRefresh" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_EVENT_NODE_TYPES_H__ */ diff --git a/spa/include/spa/node/event.h b/spa/include/spa/node/event.h index 98499813b..defc930f4 100644 --- a/spa/include/spa/node/event.h +++ b/spa/include/spa/node/event.h @@ -26,32 +26,8 @@ extern "C" { #include #include -#include #include -#define SPA_TYPE_EVENT__Node SPA_TYPE_EVENT_BASE "Node" -#define SPA_TYPE_EVENT_NODE_BASE SPA_TYPE_EVENT__Node ":" - -#define SPA_TYPE_EVENT_NODE__Error SPA_TYPE_EVENT_NODE_BASE "Error" -#define SPA_TYPE_EVENT_NODE__Buffering SPA_TYPE_EVENT_NODE_BASE "Buffering" -#define SPA_TYPE_EVENT_NODE__RequestRefresh SPA_TYPE_EVENT_NODE_BASE "RequestRefresh" - -struct spa_type_event_node { - uint32_t Error; - uint32_t Buffering; - uint32_t RequestRefresh; -}; - -static inline void -spa_type_event_node_map(struct spa_type_map *map, struct spa_type_event_node *type) -{ - if (type->Error == 0) { - type->Error = spa_type_map_get_id(map, SPA_TYPE_EVENT_NODE__Error); - type->Buffering = spa_type_map_get_id(map, SPA_TYPE_EVENT_NODE__Buffering); - type->RequestRefresh = spa_type_map_get_id(map, SPA_TYPE_EVENT_NODE__RequestRefresh); - } -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/node/io-types.h b/spa/include/spa/node/io-types.h new file mode 100644 index 000000000..4d93915bf --- /dev/null +++ b/spa/include/spa/node/io-types.h @@ -0,0 +1,51 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_IO_TYPES_H__ +#define __SPA_IO_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** Base for IO structures to interface with node ports */ +#define SPA_TYPE__IO SPA_TYPE_POINTER_BASE "IO" +#define SPA_TYPE_IO_BASE SPA_TYPE__IO ":" + +/** Base for control structures */ +#define SPA_TYPE_IO__Control SPA_TYPE_IO_BASE "Control" +#define SPA_TYPE_IO_CONTROL_BASE SPA_TYPE_IO__Control ":" + +/** An io area to exchange buffers with a port */ +#define SPA_TYPE_IO__Buffers SPA_TYPE_IO_BASE "Buffers" + +/** IO area with clock information */ +#define SPA_TYPE_IO__Clock SPA_TYPE_IO_BASE "Clock" + +/** IO area with latency information */ +#define SPA_TYPE_IO__Latency SPA_TYPE_IO_BASE "Latency" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_IO_TYPES_H__ */ diff --git a/spa/include/spa/node/io.h b/spa/include/spa/node/io.h index 9de00cb24..21dd36208 100644 --- a/spa/include/spa/node/io.h +++ b/spa/include/spa/node/io.h @@ -24,34 +24,14 @@ extern "C" { #endif -#include - -/** Base for IO structures to interface with node ports */ -#define SPA_TYPE__IO SPA_TYPE_POINTER_BASE "IO" -#define SPA_TYPE_IO_BASE SPA_TYPE__IO ":" - -/** Base for control structures */ -#define SPA_TYPE_IO__Control SPA_TYPE_IO_BASE "Control" -#define SPA_TYPE_IO_CONTROL_BASE SPA_TYPE_IO__Control ":" - -/** Base for controlable properties */ -#define SPA_TYPE_IO__Prop SPA_TYPE_IO_BASE "Prop" -#define SPA_TYPE_IO_PROP_BASE SPA_TYPE_IO__Prop ":" - -/** An io area to exchange buffers with a port */ -#define SPA_TYPE_IO__Buffers SPA_TYPE_IO_BASE "Buffers" - -/** IO area with clock information */ -#define SPA_TYPE_IO__Clock SPA_TYPE_IO_BASE "Clock" - -/** IO area with latency information */ -#define SPA_TYPE_IO__Latency SPA_TYPE_IO_BASE "Latency" +#include /** Buffers IO area * * IO information for a port on a node. This is allocated * by the host and configured on all ports for which IO is requested. */ + struct spa_io_buffers { #define SPA_STATUS_OK 0 #define SPA_STATUS_NEED_BUFFER (1<<0) @@ -65,9 +45,6 @@ struct spa_io_buffers { #define SPA_IO_BUFFERS_INIT (struct spa_io_buffers) { SPA_STATUS_OK, SPA_ID_INVALID, } -/** Information about requested range */ -#define SPA_TYPE_IO_CONTROL__Range SPA_TYPE_IO_CONTROL_BASE "Range" - /** A range, suitable for input ports that can suggest a range to output ports */ struct spa_io_control_range { uint64_t offset; /**< offset in range */ @@ -92,25 +69,6 @@ struct spa_io_latency { uint64_t max; /**< max latency */ }; -struct spa_type_io { - uint32_t Buffers; - uint32_t ControlRange; - uint32_t Prop; - uint32_t Clock; - uint32_t Latency; -}; - -static inline void spa_type_io_map(struct spa_type_map *map, struct spa_type_io *type) -{ - if (type->Buffers == 0) { - type->Buffers = spa_type_map_get_id(map, SPA_TYPE_IO__Buffers); - type->ControlRange = spa_type_map_get_id(map, SPA_TYPE_IO_CONTROL__Range); - type->Prop = spa_type_map_get_id(map, SPA_TYPE_IO__Prop); - type->Clock = spa_type_map_get_id(map, SPA_TYPE_IO__Clock); - type->Latency = spa_type_map_get_id(map, SPA_TYPE_IO__Latency); - } -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/node/node-types.h b/spa/include/spa/node/node-types.h new file mode 100644 index 000000000..6ab13c1b1 --- /dev/null +++ b/spa/include/spa/node/node-types.h @@ -0,0 +1,42 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_NODE_TYPES_H__ +#define __SPA_NODE_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__Node SPA_TYPE_INTERFACE_BASE "Node" +#define SPA_TYPE_NODE_BASE SPA_TYPE__Node ":" + +static const struct spa_type_info spa_type_node[] = { + { SPA_ID_INTERFACE_Node, SPA_TYPE__Node, SPA_POD_TYPE_ID, }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_NODE_TYPES_H__ */ diff --git a/spa/include/spa/node/node.h b/spa/include/spa/node/node.h index 0d1fcf029..1af3f336e 100644 --- a/spa/include/spa/node/node.h +++ b/spa/include/spa/node/node.h @@ -24,12 +24,10 @@ extern "C" { #endif -#define SPA_TYPE__Node SPA_TYPE_INTERFACE_BASE "Node" -#define SPA_TYPE_NODE_BASE SPA_TYPE__Node ":" - struct spa_node; #include +#include #include diff --git a/spa/include/spa/param/audio/format-types.h b/spa/include/spa/param/audio/format-types.h new file mode 100644 index 000000000..54de2b589 --- /dev/null +++ b/spa/include/spa/param/audio/format-types.h @@ -0,0 +1,50 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_AUDIO_FORMAT_TYPES_H__ +#define __SPA_PARAM_AUDIO_FORMAT_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__FormatAudio SPA_TYPE_FORMAT_BASE "Audio" +#define SPA_TYPE_FORMAT_AUDIO_BASE SPA_TYPE__FormatAudio ":" + +static const struct spa_type_info spa_type_format_audio_ids[] = { + { SPA_FORMAT_AUDIO_format, SPA_TYPE_FORMAT_AUDIO_BASE "format", SPA_POD_TYPE_INT, + spa_type_audio_format }, + { SPA_FORMAT_AUDIO_flags, SPA_TYPE_FORMAT_AUDIO_BASE "flags", SPA_POD_TYPE_INT, + spa_type_audio_flags }, + { SPA_FORMAT_AUDIO_layout, SPA_TYPE_FORMAT_AUDIO_BASE "layout", SPA_POD_TYPE_INT, + spa_type_audio_layout }, + { SPA_FORMAT_AUDIO_rate, SPA_TYPE_FORMAT_AUDIO_BASE "rate", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_AUDIO_channels, SPA_TYPE_FORMAT_AUDIO_BASE "channels", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_AUDIO_channelMask, SPA_TYPE_FORMAT_AUDIO_BASE "channelMask", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_AUDIO_FORMAT_TYPES_H */ diff --git a/spa/include/spa/param/audio/format-utils.h b/spa/include/spa/param/audio/format-utils.h index a53d39b60..06de5eea5 100644 --- a/spa/include/spa/param/audio/format-utils.h +++ b/spa/include/spa/param/audio/format-utils.h @@ -24,43 +24,32 @@ extern "C" { #endif -#include + +#include #include -#include -struct spa_type_format_audio { - uint32_t format; - uint32_t flags; - uint32_t layout; - uint32_t rate; - uint32_t channels; - uint32_t channel_mask; -}; +#if 0 +#define SPA_TYPE_FORMAT__Audio SPA_TYPE_FORMAT_BASE "Audio" +#define SPA_TYPE_FORMAT_AUDIO_BASE SPA_TYPE_FORMAT__Audio ":" -static inline void -spa_type_format_audio_map(struct spa_type_map *map, struct spa_type_format_audio *type) -{ - if (type->format == 0) { - type->format = spa_type_map_get_id(map, SPA_TYPE_FORMAT_AUDIO__format); - type->flags = spa_type_map_get_id(map, SPA_TYPE_FORMAT_AUDIO__flags); - type->layout = spa_type_map_get_id(map, SPA_TYPE_FORMAT_AUDIO__layout); - type->rate = spa_type_map_get_id(map, SPA_TYPE_FORMAT_AUDIO__rate); - type->channels = spa_type_map_get_id(map, SPA_TYPE_FORMAT_AUDIO__channels); - type->channel_mask = spa_type_map_get_id(map, SPA_TYPE_FORMAT_AUDIO__channelMask); - } -} +#define SPA_TYPE_FORMAT_AUDIO__format SPA_TYPE_FORMAT_AUDIO_BASE "format" +#define SPA_TYPE_FORMAT_AUDIO__flags SPA_TYPE_FORMAT_AUDIO_BASE "flags" +#define SPA_TYPE_FORMAT_AUDIO__layout SPA_TYPE_FORMAT_AUDIO_BASE "layout" +#define SPA_TYPE_FORMAT_AUDIO__rate SPA_TYPE_FORMAT_AUDIO_BASE "rate" +#define SPA_TYPE_FORMAT_AUDIO__channels SPA_TYPE_FORMAT_AUDIO_BASE "channels" +#define SPA_TYPE_FORMAT_AUDIO__channelMask SPA_TYPE_FORMAT_AUDIO_BASE "channel-mask" +#endif static inline int -spa_format_audio_raw_parse(const struct spa_pod *format, - struct spa_audio_info_raw *info, struct spa_type_format_audio *type) +spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_raw *info) { return spa_pod_object_parse(format, - ":",type->format, "I", &info->format, - ":",type->layout, "i", &info->layout, - ":",type->rate, "i", &info->rate, - ":",type->channels, "i", &info->channels, - ":",type->flags, "?i", &info->flags, - ":",type->channel_mask, "?i", &info->channel_mask, NULL); + ":", SPA_FORMAT_AUDIO_format, "I", &info->format, + ":", SPA_FORMAT_AUDIO_layout, "i", &info->layout, + ":", SPA_FORMAT_AUDIO_rate, "i", &info->rate, + ":", SPA_FORMAT_AUDIO_channels, "i", &info->channels, + ":", SPA_FORMAT_AUDIO_flags, "?i", &info->flags, + ":", SPA_FORMAT_AUDIO_channelMask, "?i", &info->channel_mask, NULL); } #ifdef __cplusplus diff --git a/spa/include/spa/param/audio/format.h b/spa/include/spa/param/audio/format.h index 22491ca9f..76d105b85 100644 --- a/spa/include/spa/param/audio/format.h +++ b/spa/include/spa/param/audio/format.h @@ -27,15 +27,15 @@ extern "C" { #include #include -#define SPA_TYPE_FORMAT__Audio SPA_TYPE_FORMAT_BASE "Audio" -#define SPA_TYPE_FORMAT_AUDIO_BASE SPA_TYPE_FORMAT__Audio ":" - -#define SPA_TYPE_FORMAT_AUDIO__format SPA_TYPE_FORMAT_AUDIO_BASE "format" -#define SPA_TYPE_FORMAT_AUDIO__flags SPA_TYPE_FORMAT_AUDIO_BASE "flags" -#define SPA_TYPE_FORMAT_AUDIO__layout SPA_TYPE_FORMAT_AUDIO_BASE "layout" -#define SPA_TYPE_FORMAT_AUDIO__rate SPA_TYPE_FORMAT_AUDIO_BASE "rate" -#define SPA_TYPE_FORMAT_AUDIO__channels SPA_TYPE_FORMAT_AUDIO_BASE "channels" -#define SPA_TYPE_FORMAT_AUDIO__channelMask SPA_TYPE_FORMAT_AUDIO_BASE "channel-mask" +/** properties for audio SPA_ID_OBJECT_Format */ +enum spa_format_audio { + SPA_FORMAT_AUDIO_format, + SPA_FORMAT_AUDIO_flags, + SPA_FORMAT_AUDIO_layout, + SPA_FORMAT_AUDIO_rate, + SPA_FORMAT_AUDIO_channels, + SPA_FORMAT_AUDIO_channelMask, +}; struct spa_audio_info { uint32_t media_type; diff --git a/spa/include/spa/param/audio/raw-types.h b/spa/include/spa/param/audio/raw-types.h new file mode 100644 index 000000000..360f5540c --- /dev/null +++ b/spa/include/spa/param/audio/raw-types.h @@ -0,0 +1,90 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_AUDIO_RAW_TYPES_H__ +#define __SPA_AUDIO_RAW_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define SPA_TYPE__AudioFormat SPA_TYPE_ENUM_BASE "AudioFormat" +#define SPA_TYPE_AUDIO_FORMAT_BASE SPA_TYPE__AudioFormat ":" + +static const struct spa_type_info spa_type_audio_format[] = { + { SPA_AUDIO_FORMAT_UNKNOWN, SPA_TYPE_AUDIO_FORMAT_BASE "UNKNOWN", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_ENCODED, SPA_TYPE_AUDIO_FORMAT_BASE "ENCODED", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S8, SPA_TYPE_AUDIO_FORMAT_BASE "S8", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U8, SPA_TYPE_AUDIO_FORMAT_BASE "U8", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S16_LE, SPA_TYPE_AUDIO_FORMAT_BASE "S16LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S16_BE, SPA_TYPE_AUDIO_FORMAT_BASE "S16BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U16_LE, SPA_TYPE_AUDIO_FORMAT_BASE "U16LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U16_BE, SPA_TYPE_AUDIO_FORMAT_BASE "U16BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S24_32_LE, SPA_TYPE_AUDIO_FORMAT_BASE "S24_32LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S24_32_BE, SPA_TYPE_AUDIO_FORMAT_BASE "S24_32BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U24_32_LE, SPA_TYPE_AUDIO_FORMAT_BASE "U24_32LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U24_32_BE, SPA_TYPE_AUDIO_FORMAT_BASE "U24_32BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S32_LE, SPA_TYPE_AUDIO_FORMAT_BASE "S32LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S32_BE, SPA_TYPE_AUDIO_FORMAT_BASE "S32BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U32_LE, SPA_TYPE_AUDIO_FORMAT_BASE "U32LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U32_BE, SPA_TYPE_AUDIO_FORMAT_BASE "U32BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S24_LE, SPA_TYPE_AUDIO_FORMAT_BASE "S24LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S24_BE, SPA_TYPE_AUDIO_FORMAT_BASE "S24BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U24_LE, SPA_TYPE_AUDIO_FORMAT_BASE "U24LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U24_BE, SPA_TYPE_AUDIO_FORMAT_BASE "U24BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S20_LE, SPA_TYPE_AUDIO_FORMAT_BASE "S20LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S20_BE, SPA_TYPE_AUDIO_FORMAT_BASE "S20BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U20_LE, SPA_TYPE_AUDIO_FORMAT_BASE "U20LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U20_BE, SPA_TYPE_AUDIO_FORMAT_BASE "U20BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S18_LE, SPA_TYPE_AUDIO_FORMAT_BASE "S18LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_S18_BE, SPA_TYPE_AUDIO_FORMAT_BASE "S18BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U18_LE, SPA_TYPE_AUDIO_FORMAT_BASE "U18LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_U18_BE, SPA_TYPE_AUDIO_FORMAT_BASE "U18BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_F32_LE, SPA_TYPE_AUDIO_FORMAT_BASE "F32LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_F32_BE, SPA_TYPE_AUDIO_FORMAT_BASE "F32BE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_F64_LE, SPA_TYPE_AUDIO_FORMAT_BASE "F64LE", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FORMAT_F64_BE, SPA_TYPE_AUDIO_FORMAT_BASE "F64BE", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#define SPA_TYPE__AudioFlags SPA_TYPE_FLAGS_BASE "AudioFlags" +#define SPA_TYPE_AUDIO_FLAGS_BASE SPA_TYPE__AudioFlags ":" + +static const struct spa_type_info spa_type_audio_flags[] = { + { SPA_AUDIO_FLAG_NONE, SPA_TYPE_AUDIO_FLAGS_BASE "none", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_FLAG_UNPOSITIONED, SPA_TYPE_AUDIO_FLAGS_BASE "unpositioned", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#define SPA_TYPE__AudioLayout SPA_TYPE_ENUM_BASE "AudioLayout" +#define SPA_TYPE_AUDIO_ENUM_BASE SPA_TYPE__AudioLayout ":" + +static const struct spa_type_info spa_type_audio_layout[] = { + { SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_TYPE_AUDIO_ENUM_BASE "interleaved", SPA_POD_TYPE_INT, }, + { SPA_AUDIO_LAYOUT_NON_INTERLEAVED, SPA_TYPE_AUDIO_ENUM_BASE "non-interleaved", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_AUDIO_RAW_TYPES_H__ */ diff --git a/spa/include/spa/param/audio/raw-utils.h b/spa/include/spa/param/audio/raw-utils.h deleted file mode 100644 index 3fcc471f0..000000000 --- a/spa/include/spa/param/audio/raw-utils.h +++ /dev/null @@ -1,119 +0,0 @@ -/* Simple Plugin API - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __SPA_AUDIO_RAW_UTILS_H__ -#define __SPA_AUDIO_RAW_UTILS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#if __BYTE_ORDER == __BIG_ENDIAN -#define _SPA_TYPE_AUDIO_FORMAT_NE(fmt) SPA_TYPE_AUDIO_FORMAT_BASE fmt "BE" -#define _SPA_TYPE_AUDIO_FORMAT_OE(fmt) SPA_TYPE_AUDIO_FORMAT_BASE fmt "LE" -#elif __BYTE_ORDER == __LITTLE_ENDIAN -#define _SPA_TYPE_AUDIO_FORMAT_NE(fmt) SPA_TYPE_AUDIO_FORMAT_BASE fmt "LE" -#define _SPA_TYPE_AUDIO_FORMAT_OE(fmt) SPA_TYPE_AUDIO_FORMAT_BASE fmt "BE" -#endif - -struct spa_type_audio_format { - uint32_t UNKNOWN; - uint32_t ENCODED; - uint32_t S8; - uint32_t U8; - uint32_t S16; - uint32_t U16; - uint32_t S24_32; - uint32_t U24_32; - uint32_t S32; - uint32_t U32; - uint32_t S24; - uint32_t U24; - uint32_t S20; - uint32_t U20; - uint32_t S18; - uint32_t U18; - uint32_t F32; - uint32_t F64; - uint32_t S16_OE; - uint32_t U16_OE; - uint32_t S24_32_OE; - uint32_t U24_32_OE; - uint32_t S32_OE; - uint32_t U32_OE; - uint32_t S24_OE; - uint32_t U24_OE; - uint32_t S20_OE; - uint32_t U20_OE; - uint32_t S18_OE; - uint32_t U18_OE; - uint32_t F32_OE; - uint32_t F64_OE; -}; - -static inline void -spa_type_audio_format_map(struct spa_type_map *map, struct spa_type_audio_format *type) -{ - if (type->ENCODED == 0) { - type->UNKNOWN = 0; - type->ENCODED = spa_type_map_get_id(map, SPA_TYPE_AUDIO_FORMAT__ENCODED); - - type->S8 = spa_type_map_get_id(map, SPA_TYPE_AUDIO_FORMAT__S8); - type->U8 = spa_type_map_get_id(map, SPA_TYPE_AUDIO_FORMAT__U8); - - type->S16 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("S16")); - type->U16 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("U16")); - type->S24_32 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("S24_32")); - type->U24_32 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("U24_32")); - type->S32 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("S32")); - type->U32 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("U32")); - type->S24 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("S24")); - type->U24 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("U24")); - type->S20 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("S20")); - type->U20 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("U20")); - type->S18 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("S18")); - type->U18 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("U18")); - type->F32 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("F32")); - type->F64 = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_NE("F64")); - - type->S16_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("S16")); - type->U16_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("U16")); - type->S24_32_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("S24_32")); - type->U24_32_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("U24_32")); - type->S32_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("S32")); - type->U32_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("U32")); - type->S24_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("S24")); - type->U24_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("U24")); - type->S20_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("S20")); - type->U20_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("U20")); - type->S18_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("S18")); - type->U18_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("U18")); - type->F32_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("F32")); - type->F64_OE = spa_type_map_get_id(map, _SPA_TYPE_AUDIO_FORMAT_OE("F64")); - } -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __SPA_AUDIO_RAW_UTILS_H__ */ diff --git a/spa/include/spa/param/audio/raw.h b/spa/include/spa/param/audio/raw.h index 0b1fe19f6..65d3b1429 100644 --- a/spa/include/spa/param/audio/raw.h +++ b/spa/include/spa/param/audio/raw.h @@ -26,41 +26,100 @@ extern "C" { #include -#define SPA_TYPE__AudioFormat SPA_TYPE_ENUM_BASE "AudioFormat" -#define SPA_TYPE_AUDIO_FORMAT_BASE SPA_TYPE__AudioFormat ":" +enum spa_audio_format { + SPA_AUDIO_FORMAT_UNKNOWN, + SPA_AUDIO_FORMAT_ENCODED, + SPA_AUDIO_FORMAT_S8, + SPA_AUDIO_FORMAT_U8, + SPA_AUDIO_FORMAT_S16_LE, + SPA_AUDIO_FORMAT_S16_BE, + SPA_AUDIO_FORMAT_U16_LE, + SPA_AUDIO_FORMAT_U16_BE, + SPA_AUDIO_FORMAT_S24_32_LE, + SPA_AUDIO_FORMAT_S24_32_BE, + SPA_AUDIO_FORMAT_U24_32_LE, + SPA_AUDIO_FORMAT_U24_32_BE, + SPA_AUDIO_FORMAT_S32_LE, + SPA_AUDIO_FORMAT_S32_BE, + SPA_AUDIO_FORMAT_U32_LE, + SPA_AUDIO_FORMAT_U32_BE, + SPA_AUDIO_FORMAT_S24_LE, + SPA_AUDIO_FORMAT_S24_BE, + SPA_AUDIO_FORMAT_U24_LE, + SPA_AUDIO_FORMAT_U24_BE, + SPA_AUDIO_FORMAT_S20_LE, + SPA_AUDIO_FORMAT_S20_BE, + SPA_AUDIO_FORMAT_U20_LE, + SPA_AUDIO_FORMAT_U20_BE, + SPA_AUDIO_FORMAT_S18_LE, + SPA_AUDIO_FORMAT_S18_BE, + SPA_AUDIO_FORMAT_U18_LE, + SPA_AUDIO_FORMAT_U18_BE, + SPA_AUDIO_FORMAT_F32_LE, + SPA_AUDIO_FORMAT_F32_BE, + SPA_AUDIO_FORMAT_F64_LE, + SPA_AUDIO_FORMAT_F64_BE, -#define SPA_TYPE_AUDIO_FORMAT__UNKNOWN SPA_TYPE_AUDIO_FORMAT_BASE "UNKNOWN" -#define SPA_TYPE_AUDIO_FORMAT__ENCODED SPA_TYPE_AUDIO_FORMAT_BASE "ENCODED" -#define SPA_TYPE_AUDIO_FORMAT__S8 SPA_TYPE_AUDIO_FORMAT_BASE "S8" -#define SPA_TYPE_AUDIO_FORMAT__U8 SPA_TYPE_AUDIO_FORMAT_BASE "U8" -#define SPA_TYPE_AUDIO_FORMAT__S16LE SPA_TYPE_AUDIO_FORMAT_BASE "S16LE" -#define SPA_TYPE_AUDIO_FORMAT__S16BE SPA_TYPE_AUDIO_FORMAT_BASE "S16BE" -#define SPA_TYPE_AUDIO_FORMAT__U16LE SPA_TYPE_AUDIO_FORMAT_BASE "U16LE" -#define SPA_TYPE_AUDIO_FORMAT__U16BE SPA_TYPE_AUDIO_FORMAT_BASE "U16BE" -#define SPA_TYPE_AUDIO_FORMAT__S24_32LE SPA_TYPE_AUDIO_FORMAT_BASE "S24_32LE" -#define SPA_TYPE_AUDIO_FORMAT__S24_32BE SPA_TYPE_AUDIO_FORMAT_BASE "S24_32BE" -#define SPA_TYPE_AUDIO_FORMAT__U24_32LE SPA_TYPE_AUDIO_FORMAT_BASE "U24_32LE" -#define SPA_TYPE_AUDIO_FORMAT__U24_32BE SPA_TYPE_AUDIO_FORMAT_BASE "U24_32BE" -#define SPA_TYPE_AUDIO_FORMAT__S32LE SPA_TYPE_AUDIO_FORMAT_BASE "S32LE" -#define SPA_TYPE_AUDIO_FORMAT__S32BE SPA_TYPE_AUDIO_FORMAT_BASE "S32BE" -#define SPA_TYPE_AUDIO_FORMAT__U32LE SPA_TYPE_AUDIO_FORMAT_BASE "U32LE" -#define SPA_TYPE_AUDIO_FORMAT__U32BE SPA_TYPE_AUDIO_FORMAT_BASE "U32BE" -#define SPA_TYPE_AUDIO_FORMAT__S24LE SPA_TYPE_AUDIO_FORMAT_BASE "S24LE" -#define SPA_TYPE_AUDIO_FORMAT__S24BE SPA_TYPE_AUDIO_FORMAT_BASE "S24BE" -#define SPA_TYPE_AUDIO_FORMAT__U24LE SPA_TYPE_AUDIO_FORMAT_BASE "U24LE" -#define SPA_TYPE_AUDIO_FORMAT__U24BE SPA_TYPE_AUDIO_FORMAT_BASE "U24BE" -#define SPA_TYPE_AUDIO_FORMAT__S20LE SPA_TYPE_AUDIO_FORMAT_BASE "S20LE" -#define SPA_TYPE_AUDIO_FORMAT__S20BE SPA_TYPE_AUDIO_FORMAT_BASE "S20BE" -#define SPA_TYPE_AUDIO_FORMAT__U20LE SPA_TYPE_AUDIO_FORMAT_BASE "U20LE" -#define SPA_TYPE_AUDIO_FORMAT__U20BE SPA_TYPE_AUDIO_FORMAT_BASE "U20BE" -#define SPA_TYPE_AUDIO_FORMAT__S18LE SPA_TYPE_AUDIO_FORMAT_BASE "S18LE" -#define SPA_TYPE_AUDIO_FORMAT__S18BE SPA_TYPE_AUDIO_FORMAT_BASE "S18BE" -#define SPA_TYPE_AUDIO_FORMAT__U18LE SPA_TYPE_AUDIO_FORMAT_BASE "U18LE" -#define SPA_TYPE_AUDIO_FORMAT__U18BE SPA_TYPE_AUDIO_FORMAT_BASE "U18BE" -#define SPA_TYPE_AUDIO_FORMAT__F32LE SPA_TYPE_AUDIO_FORMAT_BASE "F32LE" -#define SPA_TYPE_AUDIO_FORMAT__F32BE SPA_TYPE_AUDIO_FORMAT_BASE "F32BE" -#define SPA_TYPE_AUDIO_FORMAT__F64LE SPA_TYPE_AUDIO_FORMAT_BASE "F64LE" -#define SPA_TYPE_AUDIO_FORMAT__F64BE SPA_TYPE_AUDIO_FORMAT_BASE "F64BE" +#if __BYTE_ORDER == __BIG_ENDIAN + SPA_AUDIO_FORMAT_S16 = SPA_AUDIO_FORMAT_S16_BE, + SPA_AUDIO_FORMAT_U16 = SPA_AUDIO_FORMAT_U16_BE, + SPA_AUDIO_FORMAT_S24_32 = SPA_AUDIO_FORMAT_S24_32_BE, + SPA_AUDIO_FORMAT_U24_32 = SPA_AUDIO_FORMAT_U24_32_BE, + SPA_AUDIO_FORMAT_S32 = SPA_AUDIO_FORMAT_S32_BE, + SPA_AUDIO_FORMAT_U32 = SPA_AUDIO_FORMAT_U32_BE, + SPA_AUDIO_FORMAT_S24 = SPA_AUDIO_FORMAT_S24_BE, + SPA_AUDIO_FORMAT_U24 = SPA_AUDIO_FORMAT_U24_BE, + SPA_AUDIO_FORMAT_S20 = SPA_AUDIO_FORMAT_S20_BE, + SPA_AUDIO_FORMAT_U20 = SPA_AUDIO_FORMAT_U20_BE, + SPA_AUDIO_FORMAT_S18 = SPA_AUDIO_FORMAT_S18_BE, + SPA_AUDIO_FORMAT_U18 = SPA_AUDIO_FORMAT_U18_BE, + SPA_AUDIO_FORMAT_F32 = SPA_AUDIO_FORMAT_F32_BE, + SPA_AUDIO_FORMAT_F64 = SPA_AUDIO_FORMAT_F64_BE, + SPA_AUDIO_FORMAT_S16_OE = SPA_AUDIO_FORMAT_S16_LE, + SPA_AUDIO_FORMAT_U16_OE = SPA_AUDIO_FORMAT_U16_LE, + SPA_AUDIO_FORMAT_S24_32_OE = SPA_AUDIO_FORMAT_S24_32_LE, + SPA_AUDIO_FORMAT_U24_32_OE = SPA_AUDIO_FORMAT_U24_32_LE, + SPA_AUDIO_FORMAT_S32_OE = SPA_AUDIO_FORMAT_S32_LE, + SPA_AUDIO_FORMAT_U32_OE = SPA_AUDIO_FORMAT_U32_LE, + SPA_AUDIO_FORMAT_S24_OE = SPA_AUDIO_FORMAT_S24_LE, + SPA_AUDIO_FORMAT_U24_OE = SPA_AUDIO_FORMAT_U24_LE, + SPA_AUDIO_FORMAT_S20_OE = SPA_AUDIO_FORMAT_S20_LE, + SPA_AUDIO_FORMAT_U20_OE = SPA_AUDIO_FORMAT_U20_LE, + SPA_AUDIO_FORMAT_S18_OE = SPA_AUDIO_FORMAT_S18_LE, + SPA_AUDIO_FORMAT_U18_OE = SPA_AUDIO_FORMAT_U18_LE, + SPA_AUDIO_FORMAT_F32_OE = SPA_AUDIO_FORMAT_F32_LE, + SPA_AUDIO_FORMAT_F64_OE = SPA_AUDIO_FORMAT_F64_LE, +#elif __BYTE_ORDER == __LITTLE_ENDIAN + SPA_AUDIO_FORMAT_S16 = SPA_AUDIO_FORMAT_S16_LE, + SPA_AUDIO_FORMAT_U16 = SPA_AUDIO_FORMAT_U16_LE, + SPA_AUDIO_FORMAT_S24_32 = SPA_AUDIO_FORMAT_S24_32_LE, + SPA_AUDIO_FORMAT_U24_32 = SPA_AUDIO_FORMAT_U24_32_LE, + SPA_AUDIO_FORMAT_S32 = SPA_AUDIO_FORMAT_S32_LE, + SPA_AUDIO_FORMAT_U32 = SPA_AUDIO_FORMAT_U32_LE, + SPA_AUDIO_FORMAT_S24 = SPA_AUDIO_FORMAT_S24_LE, + SPA_AUDIO_FORMAT_U24 = SPA_AUDIO_FORMAT_U24_LE, + SPA_AUDIO_FORMAT_S20 = SPA_AUDIO_FORMAT_S20_LE, + SPA_AUDIO_FORMAT_U20 = SPA_AUDIO_FORMAT_U20_LE, + SPA_AUDIO_FORMAT_S18 = SPA_AUDIO_FORMAT_S18_LE, + SPA_AUDIO_FORMAT_U18 = SPA_AUDIO_FORMAT_U18_LE, + SPA_AUDIO_FORMAT_F32 = SPA_AUDIO_FORMAT_F32_LE, + SPA_AUDIO_FORMAT_F64 = SPA_AUDIO_FORMAT_F64_LE, + SPA_AUDIO_FORMAT_S16_OE = SPA_AUDIO_FORMAT_S16_BE, + SPA_AUDIO_FORMAT_U16_OE = SPA_AUDIO_FORMAT_U16_BE, + SPA_AUDIO_FORMAT_S24_32_OE = SPA_AUDIO_FORMAT_S24_32_BE, + SPA_AUDIO_FORMAT_U24_32_OE = SPA_AUDIO_FORMAT_U24_32_BE, + SPA_AUDIO_FORMAT_S32_OE = SPA_AUDIO_FORMAT_S32_BE, + SPA_AUDIO_FORMAT_U32_OE = SPA_AUDIO_FORMAT_U32_BE, + SPA_AUDIO_FORMAT_S24_OE = SPA_AUDIO_FORMAT_S24_BE, + SPA_AUDIO_FORMAT_U24_OE = SPA_AUDIO_FORMAT_U24_BE, + SPA_AUDIO_FORMAT_S20_OE = SPA_AUDIO_FORMAT_S20_BE, + SPA_AUDIO_FORMAT_U20_OE = SPA_AUDIO_FORMAT_U20_BE, + SPA_AUDIO_FORMAT_S18_OE = SPA_AUDIO_FORMAT_S18_BE, + SPA_AUDIO_FORMAT_U18_OE = SPA_AUDIO_FORMAT_U18_BE, + SPA_AUDIO_FORMAT_F32_OE = SPA_AUDIO_FORMAT_F32_BE, + SPA_AUDIO_FORMAT_F64_OE = SPA_AUDIO_FORMAT_F64_BE, +#endif +}; /** Extra audio flags */ enum spa_audio_flags { @@ -77,7 +136,7 @@ enum spa_audio_layout { /** Audio information description */ struct spa_audio_info_raw { - uint32_t format; /*< format, one of SPA_TYPE__AudioFormat */ + enum spa_audio_format format; /*< format, one of enum spa_audio_format */ enum spa_audio_flags flags; /*< extra flags */ enum spa_audio_layout layout; /*< sample layout */ uint32_t rate; /*< sample rate */ diff --git a/spa/include/spa/param/buffers-types.h b/spa/include/spa/param/buffers-types.h new file mode 100644 index 000000000..29b653883 --- /dev/null +++ b/spa/include/spa/param/buffers-types.h @@ -0,0 +1,58 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_BUFFERS_TYPES_H__ +#define __SPA_PARAM_BUFFERS_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE_PARAM__Buffers SPA_TYPE_PARAM_BASE "Buffers" +#define SPA_TYPE_PARAM_BUFFERS_BASE SPA_TYPE_PARAM__Buffers ":" + +#define SPA_TYPE_PARAM_BUFFERS__buffers SPA_TYPE_PARAM_BUFFERS_BASE "buffers" +#define SPA_TYPE_PARAM_BUFFERS__blocks SPA_TYPE_PARAM_BUFFERS_BASE "blocks" + +#define SPA_TYPE_PARAM__BlockInfo SPA_TYPE_PARAM_BASE "BlockInfo" +#define SPA_TYPE_PARAM_BLOCK_INFO_BASE SPA_TYPE_PARAM__BlockInfo ":" + +static const struct spa_type_info spa_type_param_buffers_items[] = { + { SPA_PARAM_BUFFERS_buffers, SPA_TYPE_PARAM_BUFFERS_BASE "buffers", SPA_POD_TYPE_INT, }, + { SPA_PARAM_BUFFERS_blocks, SPA_TYPE_PARAM_BUFFERS_BASE "blocks", SPA_POD_TYPE_INT, }, + { SPA_PARAM_BUFFERS_size, SPA_TYPE_PARAM_BLOCK_INFO_BASE "size", SPA_POD_TYPE_INT, }, + { SPA_PARAM_BUFFERS_stride, SPA_TYPE_PARAM_BLOCK_INFO_BASE "stride", SPA_POD_TYPE_INT, }, + { SPA_PARAM_BUFFERS_align, SPA_TYPE_PARAM_BLOCK_INFO_BASE "align", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +static const struct spa_type_info spa_type_param_buffers[] = { + { SPA_ID_OBJECT_ParamBuffers, SPA_TYPE_PARAM__Buffers, SPA_POD_TYPE_OBJECT, + spa_type_param_buffers_items }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_BUFFERS_TYPES_H__ */ diff --git a/spa/include/spa/param/buffers.h b/spa/include/spa/param/buffers.h index 63fe3e922..bfcca8701 100644 --- a/spa/include/spa/param/buffers.h +++ b/spa/include/spa/param/buffers.h @@ -25,47 +25,16 @@ extern "C" { #endif #include -#include -#include -#define SPA_TYPE_PARAM__Buffers SPA_TYPE_PARAM_BASE "Buffers" -#define SPA_TYPE_PARAM_BUFFERS_BASE SPA_TYPE_PARAM__Buffers ":" - -#define SPA_TYPE_PARAM_BUFFERS__buffers SPA_TYPE_PARAM_BUFFERS_BASE "buffers" -#define SPA_TYPE_PARAM_BUFFERS__blocks SPA_TYPE_PARAM_BUFFERS_BASE "blocks" - -#define SPA_TYPE_PARAM__BlockInfo SPA_TYPE_PARAM_BASE "BlockInfo" -#define SPA_TYPE_PARAM_BLOCK_INFO_BASE SPA_TYPE_PARAM__BlockInfo ":" - -#define SPA_TYPE_PARAM_BLOCK_INFO__size SPA_TYPE_PARAM_BLOCK_INFO_BASE "size" -#define SPA_TYPE_PARAM_BLOCK_INFO__stride SPA_TYPE_PARAM_BLOCK_INFO_BASE "stride" -#define SPA_TYPE_PARAM_BLOCK_INFO__align SPA_TYPE_PARAM_BLOCK_INFO_BASE "align" - -struct spa_type_param_buffers { - uint32_t Buffers; - uint32_t buffers; - uint32_t blocks; - uint32_t BlockInfo; - uint32_t size; - uint32_t stride; - uint32_t align; +/** properties for SPA_ID_OBJECT_ParamBuffers */ +enum spa_param_buffers { + SPA_PARAM_BUFFERS_buffers, /**< number of buffers */ + SPA_PARAM_BUFFERS_blocks, /**< number of data blocks per buffer */ + SPA_PARAM_BUFFERS_size, /**< size of a data block memory */ + SPA_PARAM_BUFFERS_stride, /**< stride of data block memory */ + SPA_PARAM_BUFFERS_align, /**< alignment of data block memory */ }; -static inline void -spa_type_param_buffers_map(struct spa_type_map *map, - struct spa_type_param_buffers *type) -{ - if (type->Buffers == 0) { - type->Buffers = spa_type_map_get_id(map, SPA_TYPE_PARAM__Buffers); - type->buffers = spa_type_map_get_id(map, SPA_TYPE_PARAM_BUFFERS__buffers); - type->blocks = spa_type_map_get_id(map, SPA_TYPE_PARAM_BUFFERS__blocks); - type->BlockInfo = spa_type_map_get_id(map, SPA_TYPE_PARAM__BlockInfo); - type->size = spa_type_map_get_id(map, SPA_TYPE_PARAM_BLOCK_INFO__size); - type->stride = spa_type_map_get_id(map, SPA_TYPE_PARAM_BLOCK_INFO__stride); - type->align = spa_type_map_get_id(map, SPA_TYPE_PARAM_BLOCK_INFO__align); - } -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/param/format-types.h b/spa/include/spa/param/format-types.h new file mode 100644 index 000000000..520daf77d --- /dev/null +++ b/spa/include/spa/param/format-types.h @@ -0,0 +1,109 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_FORMAT_TYPES_H__ +#define __SPA_PARAM_FORMAT_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__Format SPA_TYPE_PARAM_BASE "Format" +#define SPA_TYPE_FORMAT_BASE SPA_TYPE__Format ":" + +#define SPA_TYPE__MediaType SPA_TYPE_ENUM_BASE "MediaType" +#define SPA_TYPE_MEDIA_TYPE_BASE SPA_TYPE__MediaType ":" + +#include +#include + +static const struct spa_type_info spa_type_media_type[] = { + { SPA_MEDIA_TYPE_audio, SPA_TYPE_MEDIA_TYPE_BASE "audio", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_TYPE_video, SPA_TYPE_MEDIA_TYPE_BASE "video", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_TYPE_image, SPA_TYPE_MEDIA_TYPE_BASE "image", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_TYPE_binary, SPA_TYPE_MEDIA_TYPE_BASE "binary", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_TYPE_stream, SPA_TYPE_MEDIA_TYPE_BASE "stream", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#define SPA_TYPE__MediaSubtype SPA_TYPE_ENUM_BASE "MediaSubtype" +#define SPA_TYPE_MEDIA_SUBTYPE_BASE SPA_TYPE__MediaSubtype ":" + +static const struct spa_type_info spa_type_media_subtype[] = { + /* generic subtypes */ + { SPA_MEDIA_SUBTYPE_raw, SPA_TYPE_MEDIA_SUBTYPE_BASE "raw", SPA_POD_TYPE_INT, }, + /* audio subtypes */ + { SPA_MEDIA_SUBTYPE_mp3, SPA_TYPE_MEDIA_SUBTYPE_BASE "mp3", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_aac, SPA_TYPE_MEDIA_SUBTYPE_BASE "aac", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_vorbis, SPA_TYPE_MEDIA_SUBTYPE_BASE "vorbis", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_wma, SPA_TYPE_MEDIA_SUBTYPE_BASE "wma", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_ra, SPA_TYPE_MEDIA_SUBTYPE_BASE "ra", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_sbc, SPA_TYPE_MEDIA_SUBTYPE_BASE "sbc", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_adpcm, SPA_TYPE_MEDIA_SUBTYPE_BASE "adpcm", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_g723, SPA_TYPE_MEDIA_SUBTYPE_BASE "g723", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_g726, SPA_TYPE_MEDIA_SUBTYPE_BASE "g726", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_g729, SPA_TYPE_MEDIA_SUBTYPE_BASE "g729", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_amr, SPA_TYPE_MEDIA_SUBTYPE_BASE "amr", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_gsm, SPA_TYPE_MEDIA_SUBTYPE_BASE "gsm", SPA_POD_TYPE_INT, }, + /* video subtypes */ + { SPA_MEDIA_SUBTYPE_h264, SPA_TYPE_MEDIA_SUBTYPE_BASE "h264", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_mjpg, SPA_TYPE_MEDIA_SUBTYPE_BASE "mjpg", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_dv, SPA_TYPE_MEDIA_SUBTYPE_BASE "dv", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_mpegts, SPA_TYPE_MEDIA_SUBTYPE_BASE "mpegts", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_h263, SPA_TYPE_MEDIA_SUBTYPE_BASE "h263", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_mpeg1, SPA_TYPE_MEDIA_SUBTYPE_BASE "mpeg1", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_mpeg2, SPA_TYPE_MEDIA_SUBTYPE_BASE "mpeg2", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_mpeg4, SPA_TYPE_MEDIA_SUBTYPE_BASE "mpeg4", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_xvid, SPA_TYPE_MEDIA_SUBTYPE_BASE "xvid", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_vc1, SPA_TYPE_MEDIA_SUBTYPE_BASE "vc1", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_vp8, SPA_TYPE_MEDIA_SUBTYPE_BASE "vp8", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_vp9, SPA_TYPE_MEDIA_SUBTYPE_BASE "vp9", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_jpeg, SPA_TYPE_MEDIA_SUBTYPE_BASE "jpeg", SPA_POD_TYPE_INT, }, + { SPA_MEDIA_SUBTYPE_bayer, SPA_TYPE_MEDIA_SUBTYPE_BASE "bayer", SPA_POD_TYPE_INT, }, + + { SPA_MEDIA_SUBTYPE_midi, SPA_TYPE_MEDIA_SUBTYPE_BASE "midi", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +static const struct spa_type_info spa_type_format[] = { + { SPA_ID_OBJECT_Format, SPA_TYPE__Format, SPA_POD_TYPE_OBJECT, }, + { 0, NULL, }, +}; + +static inline const struct spa_type_info * +spa_type_format_get_ids(uint32_t media_type, uint32_t media_subtype) +{ + switch (media_type) { + case SPA_MEDIA_TYPE_audio: + return spa_type_format_audio_ids; + case SPA_MEDIA_TYPE_video: + return spa_type_format_video_ids; + default: + return NULL; + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_FORMAT_TYPES_H__ */ diff --git a/spa/include/spa/param/format-utils.h b/spa/include/spa/param/format-utils.h deleted file mode 100644 index 6c2bde9b6..000000000 --- a/spa/include/spa/param/format-utils.h +++ /dev/null @@ -1,145 +0,0 @@ -/* Simple Plugin API - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __SPA_PARAM_FORMAT_UTILS_H__ -#define __SPA_PARAM_FORMAT_UTILS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include -#include -#include - -struct spa_type_media_type { - uint32_t audio; - uint32_t video; - uint32_t image; - uint32_t binary; - uint32_t stream; -}; - -static inline void -spa_type_media_type_map(struct spa_type_map *map, struct spa_type_media_type *type) -{ - if (type->audio == 0) { - type->audio = spa_type_map_get_id(map, SPA_TYPE_MEDIA_TYPE__audio); - type->video = spa_type_map_get_id(map, SPA_TYPE_MEDIA_TYPE__video); - type->image = spa_type_map_get_id(map, SPA_TYPE_MEDIA_TYPE__image); - type->binary = spa_type_map_get_id(map, SPA_TYPE_MEDIA_TYPE__binary); - type->stream = spa_type_map_get_id(map, SPA_TYPE_MEDIA_TYPE__stream); - } -} - -struct spa_type_media_subtype { - uint32_t raw; -}; - -static inline void -spa_type_media_subtype_map(struct spa_type_map *map, struct spa_type_media_subtype *type) -{ - if (type->raw == 0) { - type->raw = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__raw); - } -} - -struct spa_type_media_subtype_video { - uint32_t h264; - uint32_t mjpg; - uint32_t dv; - uint32_t mpegts; - uint32_t h263; - uint32_t mpeg1; - uint32_t mpeg2; - uint32_t mpeg4; - uint32_t xvid; - uint32_t vc1; - uint32_t vp8; - uint32_t vp9; - uint32_t jpeg; - uint32_t bayer; -}; - -static inline void -spa_type_media_subtype_video_map(struct spa_type_map *map, - struct spa_type_media_subtype_video *type) -{ - if (type->h264 == 0) { - type->h264 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__h264); - type->mjpg = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__mjpg); - type->dv = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__dv); - type->mpegts = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__mpegts); - type->h263 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__h263); - type->mpeg1 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__mpeg1); - type->mpeg2 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__mpeg2); - type->mpeg4 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__mpeg4); - type->xvid = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__xvid); - type->vc1 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__vc1); - type->vp8 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__vp8); - type->vp9 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__vp9); - type->jpeg = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__jpeg); - type->bayer = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__bayer); - } -} - -struct spa_type_media_subtype_audio { - uint32_t mp3; - uint32_t aac; - uint32_t vorbis; - uint32_t wma; - uint32_t ra; - uint32_t sbc; - uint32_t adpcm; - uint32_t g723; - uint32_t g726; - uint32_t g729; - uint32_t amr; - uint32_t gsm; - uint32_t midi; -}; - -static inline void -spa_type_media_subtype_audio_map(struct spa_type_map *map, - struct spa_type_media_subtype_audio *type) -{ - if (type->mp3 == 0) { - type->mp3 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__mp3); - type->aac = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__aac); - type->vorbis = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__vorbis); - type->wma = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__wma); - type->ra = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__ra); - type->sbc = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__sbc); - type->adpcm = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__adpcm); - type->g723 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__g723); - type->g726 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__g726); - type->g729 = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__g729); - type->amr = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__amr); - type->gsm = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__gsm); - type->midi = spa_type_map_get_id(map, SPA_TYPE_MEDIA_SUBTYPE__midi); - } -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __PARAM_SPA_FORMAT_UTILS_H__ */ diff --git a/spa/include/spa/param/format.h b/spa/include/spa/param/format.h index 70de0f69b..6abb7e4a9 100644 --- a/spa/include/spa/param/format.h +++ b/spa/include/spa/param/format.h @@ -26,54 +26,58 @@ extern "C" { #include -#define SPA_TYPE__Format SPA_TYPE_PARAM_BASE "Format" -#define SPA_TYPE_FORMAT_BASE SPA_TYPE__Format ":" +/** media type for SPA_ID_OBJECT_Format */ +enum spa_media_type { + SPA_MEDIA_TYPE_audio, + SPA_MEDIA_TYPE_video, + SPA_MEDIA_TYPE_image, + SPA_MEDIA_TYPE_binary, + SPA_MEDIA_TYPE_stream, +}; -#define SPA_TYPE__MediaType SPA_TYPE_ENUM_BASE "MediaType" -#define SPA_TYPE_MEDIA_TYPE_BASE SPA_TYPE__MediaType ":" +/** media subtype for SPA_ID_OBJECT_Format */ +enum spa_media_subtype { + SPA_MEDIA_SUBTYPE_BASE_Generic, + SPA_MEDIA_SUBTYPE_raw, -#define SPA_TYPE_MEDIA_TYPE__audio SPA_TYPE_MEDIA_TYPE_BASE "audio" -#define SPA_TYPE_MEDIA_TYPE__video SPA_TYPE_MEDIA_TYPE_BASE "video" -#define SPA_TYPE_MEDIA_TYPE__image SPA_TYPE_MEDIA_TYPE_BASE "image" -#define SPA_TYPE_MEDIA_TYPE__binary SPA_TYPE_MEDIA_TYPE_BASE "binary" -#define SPA_TYPE_MEDIA_TYPE__stream SPA_TYPE_MEDIA_TYPE_BASE "stream" + SPA_MEDIA_SUBTYPE_BASE_Audio = 0x10000, + SPA_MEDIA_SUBTYPE_mp3, + SPA_MEDIA_SUBTYPE_aac, + SPA_MEDIA_SUBTYPE_vorbis, + SPA_MEDIA_SUBTYPE_wma, + SPA_MEDIA_SUBTYPE_ra, + SPA_MEDIA_SUBTYPE_sbc, + SPA_MEDIA_SUBTYPE_adpcm, + SPA_MEDIA_SUBTYPE_g723, + SPA_MEDIA_SUBTYPE_g726, + SPA_MEDIA_SUBTYPE_g729, + SPA_MEDIA_SUBTYPE_amr, + SPA_MEDIA_SUBTYPE_gsm, -#define SPA_TYPE__MediaSubtype SPA_TYPE_ENUM_BASE "MediaSubtype" -#define SPA_TYPE_MEDIA_SUBTYPE_BASE SPA_TYPE__MediaSubtype ":" + SPA_MEDIA_SUBTYPE_BASE_Video = 0x20000, + SPA_MEDIA_SUBTYPE_h264, + SPA_MEDIA_SUBTYPE_mjpg, + SPA_MEDIA_SUBTYPE_dv, + SPA_MEDIA_SUBTYPE_mpegts, + SPA_MEDIA_SUBTYPE_h263, + SPA_MEDIA_SUBTYPE_mpeg1, + SPA_MEDIA_SUBTYPE_mpeg2, + SPA_MEDIA_SUBTYPE_mpeg4, + SPA_MEDIA_SUBTYPE_xvid, + SPA_MEDIA_SUBTYPE_vc1, + SPA_MEDIA_SUBTYPE_vp8, + SPA_MEDIA_SUBTYPE_vp9, + SPA_MEDIA_SUBTYPE_jpeg, + SPA_MEDIA_SUBTYPE_bayer, -/* generic subtypes */ -#define SPA_TYPE_MEDIA_SUBTYPE__raw SPA_TYPE_MEDIA_SUBTYPE_BASE "raw" + SPA_MEDIA_SUBTYPE_BASE_Image = 0x30000, -/* video subtypes */ -#define SPA_TYPE_MEDIA_SUBTYPE__h264 SPA_TYPE_MEDIA_SUBTYPE_BASE "h264" -#define SPA_TYPE_MEDIA_SUBTYPE__mjpg SPA_TYPE_MEDIA_SUBTYPE_BASE "mjpg" -#define SPA_TYPE_MEDIA_SUBTYPE__dv SPA_TYPE_MEDIA_SUBTYPE_BASE "dv" -#define SPA_TYPE_MEDIA_SUBTYPE__mpegts SPA_TYPE_MEDIA_SUBTYPE_BASE "mpegts" -#define SPA_TYPE_MEDIA_SUBTYPE__h263 SPA_TYPE_MEDIA_SUBTYPE_BASE "h263" -#define SPA_TYPE_MEDIA_SUBTYPE__mpeg1 SPA_TYPE_MEDIA_SUBTYPE_BASE "mpeg1" -#define SPA_TYPE_MEDIA_SUBTYPE__mpeg2 SPA_TYPE_MEDIA_SUBTYPE_BASE "mpeg2" -#define SPA_TYPE_MEDIA_SUBTYPE__mpeg4 SPA_TYPE_MEDIA_SUBTYPE_BASE "mpeg4" -#define SPA_TYPE_MEDIA_SUBTYPE__xvid SPA_TYPE_MEDIA_SUBTYPE_BASE "xvid" -#define SPA_TYPE_MEDIA_SUBTYPE__vc1 SPA_TYPE_MEDIA_SUBTYPE_BASE "vc1" -#define SPA_TYPE_MEDIA_SUBTYPE__vp8 SPA_TYPE_MEDIA_SUBTYPE_BASE "vp8" -#define SPA_TYPE_MEDIA_SUBTYPE__vp9 SPA_TYPE_MEDIA_SUBTYPE_BASE "vp9" -#define SPA_TYPE_MEDIA_SUBTYPE__jpeg SPA_TYPE_MEDIA_SUBTYPE_BASE "jpeg" -#define SPA_TYPE_MEDIA_SUBTYPE__bayer SPA_TYPE_MEDIA_SUBTYPE_BASE "bayer" + SPA_MEDIA_SUBTYPE_BASE_Binary = 0x40000, + + SPA_MEDIA_SUBTYPE_BASE_Stream = 0x50000, + SPA_MEDIA_SUBTYPE_midi, +}; -/* audio subtypes */ -#define SPA_TYPE_MEDIA_SUBTYPE__mp3 SPA_TYPE_MEDIA_SUBTYPE_BASE "mp3" -#define SPA_TYPE_MEDIA_SUBTYPE__aac SPA_TYPE_MEDIA_SUBTYPE_BASE "aac" -#define SPA_TYPE_MEDIA_SUBTYPE__vorbis SPA_TYPE_MEDIA_SUBTYPE_BASE "vorbis" -#define SPA_TYPE_MEDIA_SUBTYPE__wma SPA_TYPE_MEDIA_SUBTYPE_BASE "wma" -#define SPA_TYPE_MEDIA_SUBTYPE__ra SPA_TYPE_MEDIA_SUBTYPE_BASE "ra" -#define SPA_TYPE_MEDIA_SUBTYPE__sbc SPA_TYPE_MEDIA_SUBTYPE_BASE "sbc" -#define SPA_TYPE_MEDIA_SUBTYPE__adpcm SPA_TYPE_MEDIA_SUBTYPE_BASE "adpcm" -#define SPA_TYPE_MEDIA_SUBTYPE__g723 SPA_TYPE_MEDIA_SUBTYPE_BASE "g723" -#define SPA_TYPE_MEDIA_SUBTYPE__g726 SPA_TYPE_MEDIA_SUBTYPE_BASE "g726" -#define SPA_TYPE_MEDIA_SUBTYPE__g729 SPA_TYPE_MEDIA_SUBTYPE_BASE "g729" -#define SPA_TYPE_MEDIA_SUBTYPE__amr SPA_TYPE_MEDIA_SUBTYPE_BASE "amr" -#define SPA_TYPE_MEDIA_SUBTYPE__gsm SPA_TYPE_MEDIA_SUBTYPE_BASE "gsm" -#define SPA_TYPE_MEDIA_SUBTYPE__midi SPA_TYPE_MEDIA_SUBTYPE_BASE "midi" #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/param/io-types.h b/spa/include/spa/param/io-types.h new file mode 100644 index 000000000..22585c0d6 --- /dev/null +++ b/spa/include/spa/param/io-types.h @@ -0,0 +1,101 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_IO_H__ +#define __SPA_PARAM_IO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** type ID of property, uniquely identifies the io area for a port */ +#define SPA_TYPE_PARAM_IO__id SPA_TYPE_PARAM_IO_BASE "id" +/** size of the io area for a port */ +#define SPA_TYPE_PARAM_IO__size SPA_TYPE_PARAM_IO_BASE "size" + +/** enumerate buffer io areas */ +#define SPA_TYPE_PARAM_ID_IO__Buffers SPA_TYPE_PARAM_ID_IO_BASE "Buffers" +/* an io area to exchange buffers */ +#define SPA_TYPE_PARAM_IO__Buffers SPA_TYPE_PARAM_IO_BASE "Buffers" + +/** enumerate Control io areas */ +#define SPA_TYPE_PARAM_ID_IO__Control SPA_TYPE_PARAM_ID_IO_BASE "Control" +/* an io area to exchange control information */ +#define SPA_TYPE_PARAM_IO__Control SPA_TYPE_PARAM_IO_BASE "Control" + +/** enumerate input or output properties */ +#define SPA_TYPE_PARAM_ID_IO__Props SPA_TYPE_PARAM_ID_IO_BASE "Props" +#define SPA_TYPE_PARAM_ID_IO_PROPS_BASE SPA_TYPE_PARAM_ID_IO__Props ":" +/** enumerate input property io areas */ +#define SPA_TYPE_PARAM_ID_IO_PROPS__In SPA_TYPE_PARAM_ID_IO_PROPS_BASE "In" +/** enumerate output property io areas */ +#define SPA_TYPE_PARAM_ID_IO_PROPS__Out SPA_TYPE_PARAM_ID_IO_PROPS_BASE "Out" + +/* an io area to exchange properties. Contents can include + * SPA_TYPE_PARAM__PropInfo */ +#define SPA_TYPE_PARAM_IO__Prop SPA_TYPE_PARAM_IO_BASE "Prop" +#define SPA_TYPE_PARAM_IO_PROP_BASE SPA_TYPE_PARAM_IO__Prop ":" + +/** enumerate clock io areas */ +#define SPA_TYPE_PARAM_ID_IO__Clock SPA_TYPE_PARAM_ID_IO_BASE "Clock" +/* an io area to exchange clock information */ +#define SPA_TYPE_PARAM_IO__Clock SPA_TYPE_PARAM_IO_BASE "Clock" + +struct spa_type_param_io { + uint32_t id; /**< id to configure the io area */ + uint32_t size; /**< size of io area */ + uint32_t idBuffers; /**< id to enumerate buffer io */ + uint32_t Buffers; /**< object type of buffer io area */ + uint32_t idControl; /**< id to enumerate control io */ + uint32_t Control; /**< object type of Control area */ + uint32_t idPropsIn; /**< id to enumerate input properties io */ + uint32_t idPropsOut; /**< id to enumerate output properties io */ + uint32_t Prop; /**< object type of property area */ + uint32_t idClock; /**< id to enumerate clock io */ + uint32_t Clock; /**< object type of clock io area */ +}; + +static inline void +spa_type_param_io_map(struct spa_type_map *map, + struct spa_type_param_io *type) +{ + if (type->id == 0) { + type->id = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__id); + type->size = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__size); + type->idBuffers = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO__Buffers); + type->Buffers = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Buffers); + type->idControl = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO__Control); + type->Control = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Control); + type->idPropsIn = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO_PROPS__In); + type->idPropsOut = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO_PROPS__Out); + type->Prop = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Prop); + type->idClock = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO__Clock); + type->Clock = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Clock); + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_IO_H__ */ diff --git a/spa/include/spa/param/io.h b/spa/include/spa/param/io.h index 22585c0d6..46c96bb6a 100644 --- a/spa/include/spa/param/io.h +++ b/spa/include/spa/param/io.h @@ -26,74 +26,13 @@ extern "C" { #include #include -#include -/** type ID of property, uniquely identifies the io area for a port */ -#define SPA_TYPE_PARAM_IO__id SPA_TYPE_PARAM_IO_BASE "id" -/** size of the io area for a port */ -#define SPA_TYPE_PARAM_IO__size SPA_TYPE_PARAM_IO_BASE "size" - -/** enumerate buffer io areas */ -#define SPA_TYPE_PARAM_ID_IO__Buffers SPA_TYPE_PARAM_ID_IO_BASE "Buffers" -/* an io area to exchange buffers */ -#define SPA_TYPE_PARAM_IO__Buffers SPA_TYPE_PARAM_IO_BASE "Buffers" - -/** enumerate Control io areas */ -#define SPA_TYPE_PARAM_ID_IO__Control SPA_TYPE_PARAM_ID_IO_BASE "Control" -/* an io area to exchange control information */ -#define SPA_TYPE_PARAM_IO__Control SPA_TYPE_PARAM_IO_BASE "Control" - -/** enumerate input or output properties */ -#define SPA_TYPE_PARAM_ID_IO__Props SPA_TYPE_PARAM_ID_IO_BASE "Props" -#define SPA_TYPE_PARAM_ID_IO_PROPS_BASE SPA_TYPE_PARAM_ID_IO__Props ":" -/** enumerate input property io areas */ -#define SPA_TYPE_PARAM_ID_IO_PROPS__In SPA_TYPE_PARAM_ID_IO_PROPS_BASE "In" -/** enumerate output property io areas */ -#define SPA_TYPE_PARAM_ID_IO_PROPS__Out SPA_TYPE_PARAM_ID_IO_PROPS_BASE "Out" - -/* an io area to exchange properties. Contents can include - * SPA_TYPE_PARAM__PropInfo */ -#define SPA_TYPE_PARAM_IO__Prop SPA_TYPE_PARAM_IO_BASE "Prop" -#define SPA_TYPE_PARAM_IO_PROP_BASE SPA_TYPE_PARAM_IO__Prop ":" - -/** enumerate clock io areas */ -#define SPA_TYPE_PARAM_ID_IO__Clock SPA_TYPE_PARAM_ID_IO_BASE "Clock" -/* an io area to exchange clock information */ -#define SPA_TYPE_PARAM_IO__Clock SPA_TYPE_PARAM_IO_BASE "Clock" - -struct spa_type_param_io { - uint32_t id; /**< id to configure the io area */ - uint32_t size; /**< size of io area */ - uint32_t idBuffers; /**< id to enumerate buffer io */ - uint32_t Buffers; /**< object type of buffer io area */ - uint32_t idControl; /**< id to enumerate control io */ - uint32_t Control; /**< object type of Control area */ - uint32_t idPropsIn; /**< id to enumerate input properties io */ - uint32_t idPropsOut; /**< id to enumerate output properties io */ - uint32_t Prop; /**< object type of property area */ - uint32_t idClock; /**< id to enumerate clock io */ - uint32_t Clock; /**< object type of clock io area */ +/** properties for SPA_ID_OBJECT_ParamIO */ +enum spa_param_io { + SPA_PARAM_IO_id, /**< type ID, uniquely identifies the io area */ + SPA_PARAM_IO_size, /**< size of the io area */ }; -static inline void -spa_type_param_io_map(struct spa_type_map *map, - struct spa_type_param_io *type) -{ - if (type->id == 0) { - type->id = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__id); - type->size = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__size); - type->idBuffers = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO__Buffers); - type->Buffers = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Buffers); - type->idControl = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO__Control); - type->Control = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Control); - type->idPropsIn = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO_PROPS__In); - type->idPropsOut = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO_PROPS__Out); - type->Prop = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Prop); - type->idClock = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID_IO__Clock); - type->Clock = spa_type_map_get_id(map, SPA_TYPE_PARAM_IO__Clock); - } -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/param/meta-types.h b/spa/include/spa/param/meta-types.h new file mode 100644 index 000000000..7576ff1a6 --- /dev/null +++ b/spa/include/spa/param/meta-types.h @@ -0,0 +1,66 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_META_H__ +#define __SPA_PARAM_META_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include /* for off_t */ + +#include +#include +#include + +#define SPA_TYPE_PARAM__Meta SPA_TYPE_PARAM_BASE "Meta" +#define SPA_TYPE_PARAM_META_BASE SPA_TYPE_PARAM__Meta ":" +#define SPA_TYPE_PARAM_META__type SPA_TYPE_PARAM_META_BASE "type" +#define SPA_TYPE_PARAM_META__size SPA_TYPE_PARAM_META_BASE "size" + +struct spa_type_param_meta { + uint32_t Meta; + uint32_t type; + uint32_t size; +}; + +static inline void +spa_type_param_meta_map(struct spa_type_map *map, + struct spa_type_param_meta *type) +{ + if (type->Meta == 0) { + size_t i; +#define OFF(n) offsetof(struct spa_type_param_meta, n) + static struct { off_t offset; const char *type; } tab[] = { + { OFF(Meta), SPA_TYPE_PARAM__Meta }, + { OFF(type), SPA_TYPE_PARAM_META__type }, + { OFF(size), SPA_TYPE_PARAM_META__size }, + }; +#undef OFF + for (i = 0; i < SPA_N_ELEMENTS(tab); i++) + *SPA_MEMBER(type, tab[i].offset, uint32_t) = spa_type_map_get_id(map, tab[i].type); + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_META_H__ */ diff --git a/spa/include/spa/param/meta.h b/spa/include/spa/param/meta.h index 7576ff1a6..12670ece8 100644 --- a/spa/include/spa/param/meta.h +++ b/spa/include/spa/param/meta.h @@ -24,41 +24,15 @@ extern "C" { #endif -#include /* for off_t */ - #include #include -#include -#define SPA_TYPE_PARAM__Meta SPA_TYPE_PARAM_BASE "Meta" -#define SPA_TYPE_PARAM_META_BASE SPA_TYPE_PARAM__Meta ":" -#define SPA_TYPE_PARAM_META__type SPA_TYPE_PARAM_META_BASE "type" -#define SPA_TYPE_PARAM_META__size SPA_TYPE_PARAM_META_BASE "size" - -struct spa_type_param_meta { - uint32_t Meta; - uint32_t type; - uint32_t size; +/** properties for SPA_ID_OBJECT_ParamMeta */ +enum spa_param_meta { + SPA_PARAM_META_type, /**< the metadata, one of enum spa_meta_type */ + SPA_PARAM_META_size, /**< the expected maximum size the meta */ }; -static inline void -spa_type_param_meta_map(struct spa_type_map *map, - struct spa_type_param_meta *type) -{ - if (type->Meta == 0) { - size_t i; -#define OFF(n) offsetof(struct spa_type_param_meta, n) - static struct { off_t offset; const char *type; } tab[] = { - { OFF(Meta), SPA_TYPE_PARAM__Meta }, - { OFF(type), SPA_TYPE_PARAM_META__type }, - { OFF(size), SPA_TYPE_PARAM_META__size }, - }; -#undef OFF - for (i = 0; i < SPA_N_ELEMENTS(tab); i++) - *SPA_MEMBER(type, tab[i].offset, uint32_t) = spa_type_map_get_id(map, tab[i].type); - } -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/spa/include/spa/param/param-types.h b/spa/include/spa/param/param-types.h new file mode 100644 index 000000000..347674952 --- /dev/null +++ b/spa/include/spa/param/param-types.h @@ -0,0 +1,92 @@ +/* Simple Plugin API + * Copyright (C) 2017 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_TYPES_H__ +#define __SPA_PARAM_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/* base for parameter objects */ +#define SPA_TYPE__Param SPA_TYPE_POD_OBJECT_BASE "Param" +#define SPA_TYPE_PARAM_BASE SPA_TYPE__Param ":" + +/* base for parameter object enumerations */ +#define SPA_TYPE__ParamId SPA_TYPE_ENUM_BASE "ParamId" +#define SPA_TYPE_PARAM_ID_BASE SPA_TYPE__ParamId ":" + +/** List of supported parameters */ +#define SPA_TYPE_PARAM_ID__List SPA_TYPE_PARAM_ID_BASE "List" + +/* object with supported parameter id */ +#define SPA_TYPE_PARAM__List SPA_TYPE_PARAM_BASE "List" +#define SPA_TYPE_PARAM_LIST_BASE SPA_TYPE_PARAM__List ":" +#define SPA_TYPE_PARAM_LIST__id SPA_TYPE_PARAM_LIST_BASE "id" + +/** Enum Property info */ +#define SPA_TYPE_PARAM_ID__PropInfo SPA_TYPE_PARAM_ID_BASE "PropInfo" + +#define SPA_TYPE_PARAM__PropInfo SPA_TYPE_PARAM_BASE "PropInfo" +#define SPA_TYPE_PARAM_PROP_INFO_BASE SPA_TYPE_PARAM__PropInfo ":" + +/** associated id of the property */ +#define SPA_TYPE_PARAM_PROP_INFO__id SPA_TYPE_PARAM_PROP_INFO_BASE "id" +/** name of property */ +#define SPA_TYPE_PARAM_PROP_INFO__name SPA_TYPE_PARAM_PROP_INFO_BASE "name" +/** associated type and range/enums of property */ +#define SPA_TYPE_PARAM_PROP_INFO__type SPA_TYPE_PARAM_PROP_INFO_BASE "type" +/** associated labels of property if any, this is a struct with pairs of values, + * the first one is of the type of the property, the second one is a string with + * a user readable label for the value. */ +#define SPA_TYPE_PARAM_PROP_INFO__labels SPA_TYPE_PARAM_PROP_INFO_BASE "labels" + +/** Property parameter id, deals with SPA_TYPE__Props */ +#define SPA_TYPE_PARAM_ID__Props SPA_TYPE_PARAM_ID_BASE "Props" + +/** The available formats */ +#define SPA_TYPE_PARAM_ID__EnumFormat SPA_TYPE_PARAM_ID_BASE "EnumFormat" + +/** The current format */ +#define SPA_TYPE_PARAM_ID__Format SPA_TYPE_PARAM_ID_BASE "Format" + +/** The supported buffer sizes */ +#define SPA_TYPE_PARAM_ID__Buffers SPA_TYPE_PARAM_ID_BASE "Buffers" + +/** The supported metadata */ +#define SPA_TYPE_PARAM_ID__Meta SPA_TYPE_PARAM_ID_BASE "Meta" + +/** The supported io areas */ +#define SPA_TYPE_PARAM_ID__IO SPA_TYPE_PARAM_ID_BASE "IO" +#define SPA_TYPE_PARAM_ID_IO_BASE SPA_TYPE_PARAM_ID__IO ":" + +/** Base for parameters that describe IO areas to exchange data, + * control and properties with a node. + */ +#define SPA_TYPE_PARAM__IO SPA_TYPE_PARAM_BASE "IO" +#define SPA_TYPE_PARAM_IO_BASE SPA_TYPE_PARAM__IO ":" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_TYPES_H__ */ diff --git a/spa/include/spa/param/param.h b/spa/include/spa/param/param.h index 5a8cc689f..5e1ab4e31 100644 --- a/spa/include/spa/param/param.h +++ b/spa/include/spa/param/param.h @@ -25,105 +25,12 @@ extern "C" { #endif #include -#include -#include -/* base for parameter objects */ -#define SPA_TYPE__Param SPA_TYPE_POD_OBJECT_BASE "Param" -#define SPA_TYPE_PARAM_BASE SPA_TYPE__Param ":" - -/* base for parameter object enumerations */ -#define SPA_TYPE__ParamId SPA_TYPE_ENUM_BASE "ParamId" -#define SPA_TYPE_PARAM_ID_BASE SPA_TYPE__ParamId ":" - -/** List of supported parameters */ -#define SPA_TYPE_PARAM_ID__List SPA_TYPE_PARAM_ID_BASE "List" - -/* object with supported parameter id */ -#define SPA_TYPE_PARAM__List SPA_TYPE_PARAM_BASE "List" -#define SPA_TYPE_PARAM_LIST_BASE SPA_TYPE_PARAM__List ":" -#define SPA_TYPE_PARAM_LIST__id SPA_TYPE_PARAM_LIST_BASE "id" - -/** Enum Property info */ -#define SPA_TYPE_PARAM_ID__PropInfo SPA_TYPE_PARAM_ID_BASE "PropInfo" - -#define SPA_TYPE_PARAM__PropInfo SPA_TYPE_PARAM_BASE "PropInfo" -#define SPA_TYPE_PARAM_PROP_INFO_BASE SPA_TYPE_PARAM__PropInfo ":" - -/** associated id of the property */ -#define SPA_TYPE_PARAM_PROP_INFO__id SPA_TYPE_PARAM_PROP_INFO_BASE "id" -/** name of property */ -#define SPA_TYPE_PARAM_PROP_INFO__name SPA_TYPE_PARAM_PROP_INFO_BASE "name" -/** associated type and range/enums of property */ -#define SPA_TYPE_PARAM_PROP_INFO__type SPA_TYPE_PARAM_PROP_INFO_BASE "type" -/** associated labels of property if any, this is a struct with pairs of values, - * the first one is of the type of the property, the second one is a string with - * a user readable label for the value. */ -#define SPA_TYPE_PARAM_PROP_INFO__labels SPA_TYPE_PARAM_PROP_INFO_BASE "labels" - -/** Property parameter id, deals with SPA_TYPE__Props */ -#define SPA_TYPE_PARAM_ID__Props SPA_TYPE_PARAM_ID_BASE "Props" - -/** The available formats */ -#define SPA_TYPE_PARAM_ID__EnumFormat SPA_TYPE_PARAM_ID_BASE "EnumFormat" - -/** The current format */ -#define SPA_TYPE_PARAM_ID__Format SPA_TYPE_PARAM_ID_BASE "Format" - -/** The supported buffer sizes */ -#define SPA_TYPE_PARAM_ID__Buffers SPA_TYPE_PARAM_ID_BASE "Buffers" - -/** The supported metadata */ -#define SPA_TYPE_PARAM_ID__Meta SPA_TYPE_PARAM_ID_BASE "Meta" - -/** The supported io areas */ -#define SPA_TYPE_PARAM_ID__IO SPA_TYPE_PARAM_ID_BASE "IO" -#define SPA_TYPE_PARAM_ID_IO_BASE SPA_TYPE_PARAM_ID__IO ":" - -/** Base for parameters that describe IO areas to exchange data, - * control and properties with a node. - */ -#define SPA_TYPE_PARAM__IO SPA_TYPE_PARAM_BASE "IO" -#define SPA_TYPE_PARAM_IO_BASE SPA_TYPE_PARAM__IO ":" - -struct spa_type_param { - uint32_t idList; /**< id of the list param */ - uint32_t List; /**< list object type */ - uint32_t listId; /**< id in the list object */ - uint32_t idPropInfo; /**< id to enumerate property info */ - uint32_t PropInfo; /**< property info object */ - uint32_t propId; /**< property id */ - uint32_t propName; /**< property name */ - uint32_t propType; /**< property type */ - uint32_t propLabels; /**< property labels */ - uint32_t idProps; /**< id to enumerate properties */ - uint32_t idEnumFormat; /**< id to enumerate formats */ - uint32_t idFormat; /**< id to get/set format parameter */ - uint32_t idBuffers; /**< id to enumerate buffer requirements */ - uint32_t idMeta; /**< id to enumerate supported metadata */ +/** Properties for SPA_ID_OBJECT_ParamList */ +enum spa_param_list { + SPA_PARAM_LIST_id, /**< id of the supported list param */ }; -static inline void -spa_type_param_map(struct spa_type_map *map, - struct spa_type_param *type) -{ - if (type->idList == 0) { - type->idList = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__List); - type->List = spa_type_map_get_id(map, SPA_TYPE_PARAM__List); - type->listId = spa_type_map_get_id(map, SPA_TYPE_PARAM_LIST__id); - type->idPropInfo = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__PropInfo); - type->PropInfo = spa_type_map_get_id(map, SPA_TYPE_PARAM__PropInfo); - type->propId = spa_type_map_get_id(map, SPA_TYPE_PARAM_PROP_INFO__id); - type->propName = spa_type_map_get_id(map, SPA_TYPE_PARAM_PROP_INFO__name); - type->propType = spa_type_map_get_id(map, SPA_TYPE_PARAM_PROP_INFO__type); - type->propLabels = spa_type_map_get_id(map, SPA_TYPE_PARAM_PROP_INFO__labels); - type->idProps = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__Props); - type->idEnumFormat = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__EnumFormat); - type->idFormat = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__Format); - type->idBuffers = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__Buffers); - type->idMeta = spa_type_map_get_id(map, SPA_TYPE_PARAM_ID__Meta); - } -} #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/param/props-types.h b/spa/include/spa/param/props-types.h new file mode 100644 index 000000000..1872ea3cf --- /dev/null +++ b/spa/include/spa/param/props-types.h @@ -0,0 +1,70 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_PROPS_TYPES_H__ +#define __SPA_PARAM_PROPS_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define SPA_TYPE__Props SPA_TYPE_PARAM_BASE "Props" +#define SPA_TYPE_PROPS_BASE SPA_TYPE__Props ":" + +/** an unknown property */ +#define SPA_TYPE_PROPS__unknown SPA_TYPE_PROPS_BASE "unknown" + +/** Common property ids */ +#define SPA_TYPE_PROPS__device SPA_TYPE_PROPS_BASE "device" +#define SPA_TYPE_PROPS__deviceName SPA_TYPE_PROPS_BASE "deviceName" +#define SPA_TYPE_PROPS__deviceFd SPA_TYPE_PROPS_BASE "deviceFd" +#define SPA_TYPE_PROPS__card SPA_TYPE_PROPS_BASE "card" +#define SPA_TYPE_PROPS__cardName SPA_TYPE_PROPS_BASE "cardName" + +#define SPA_TYPE_PROPS__minLatency SPA_TYPE_PROPS_BASE "minLatency" +#define SPA_TYPE_PROPS__maxLatency SPA_TYPE_PROPS_BASE "maxLatency" +#define SPA_TYPE_PROPS__periods SPA_TYPE_PROPS_BASE "periods" +#define SPA_TYPE_PROPS__periodSize SPA_TYPE_PROPS_BASE "periodSize" +#define SPA_TYPE_PROPS__periodEvent SPA_TYPE_PROPS_BASE "periodEvent" + +#define SPA_TYPE_PROPS__live SPA_TYPE_PROPS_BASE "live" +#define SPA_TYPE_PROPS__waveType SPA_TYPE_PROPS_BASE "waveType" +#define SPA_TYPE_PROPS__frequency SPA_TYPE_PROPS_BASE "frequency" +#define SPA_TYPE_PROPS__volume SPA_TYPE_PROPS_BASE "volume" +#define SPA_TYPE_PROPS__mute SPA_TYPE_PROPS_BASE "mute" +#define SPA_TYPE_PROPS__patternType SPA_TYPE_PROPS_BASE "patternType" +#define SPA_TYPE_PROPS__ditherType SPA_TYPE_PROPS_BASE "ditherType" +#define SPA_TYPE_PROPS__truncate SPA_TYPE_PROPS_BASE "truncate" + +#define SPA_TYPE_PROPS__brightness SPA_TYPE_PROPS_BASE "brightness" +#define SPA_TYPE_PROPS__contrast SPA_TYPE_PROPS_BASE "contrast" +#define SPA_TYPE_PROPS__saturation SPA_TYPE_PROPS_BASE "saturation" +#define SPA_TYPE_PROPS__hue SPA_TYPE_PROPS_BASE "hue" +#define SPA_TYPE_PROPS__gamma SPA_TYPE_PROPS_BASE "gamma" +#define SPA_TYPE_PROPS__exposure SPA_TYPE_PROPS_BASE "exposure" +#define SPA_TYPE_PROPS__gain SPA_TYPE_PROPS_BASE "gain" +#define SPA_TYPE_PROPS__sharpness SPA_TYPE_PROPS_BASE "sharpness" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_PROPS_TYPES_H__ */ diff --git a/spa/include/spa/param/props.h b/spa/include/spa/param/props.h index edb9275d4..ead58f568 100644 --- a/spa/include/spa/param/props.h +++ b/spa/include/spa/param/props.h @@ -26,42 +26,56 @@ extern "C" { #include -#define SPA_TYPE__Props SPA_TYPE_PARAM_BASE "Props" -#define SPA_TYPE_PROPS_BASE SPA_TYPE__Props ":" +/** properties of SPA_ID_OBJECT_PropInfo */ +enum spa_prop_info { + SPA_PROP_INFO_id, /**< associated id of the property */ + SPA_PROP_INFO_name, /**< name of the property */ + SPA_PROP_INFO_type, /**< type and range/enums of property */ + SPA_PROP_INFO_labels, /**< labels of property if any, this is a + * struct with pairs of values, the first one + * is of the type of the property, the second + * one is a string with a user readable label + * for the value. */ +}; -/** an unknown property */ -#define SPA_TYPE_PROPS__unknown SPA_TYPE_PROPS_BASE "unknown" +/** predefined properties for SPA_ID_OBJECT_Props */ +enum spa_prop { + SPA_PROP_BASE_GENERIC = 0x0, -/** Common property ids */ -#define SPA_TYPE_PROPS__device SPA_TYPE_PROPS_BASE "device" -#define SPA_TYPE_PROPS__deviceName SPA_TYPE_PROPS_BASE "deviceName" -#define SPA_TYPE_PROPS__deviceFd SPA_TYPE_PROPS_BASE "deviceFd" -#define SPA_TYPE_PROPS__card SPA_TYPE_PROPS_BASE "card" -#define SPA_TYPE_PROPS__cardName SPA_TYPE_PROPS_BASE "cardName" + SPA_PROP_unknown, /**< an unknown property */ -#define SPA_TYPE_PROPS__minLatency SPA_TYPE_PROPS_BASE "minLatency" -#define SPA_TYPE_PROPS__maxLatency SPA_TYPE_PROPS_BASE "maxLatency" -#define SPA_TYPE_PROPS__periods SPA_TYPE_PROPS_BASE "periods" -#define SPA_TYPE_PROPS__periodSize SPA_TYPE_PROPS_BASE "periodSize" -#define SPA_TYPE_PROPS__periodEvent SPA_TYPE_PROPS_BASE "periodEvent" + SPA_PROP_device, + SPA_PROP_deviceName, + SPA_PROP_deviceFd, + SPA_PROP_card, + SPA_PROP_cardName, -#define SPA_TYPE_PROPS__live SPA_TYPE_PROPS_BASE "live" -#define SPA_TYPE_PROPS__waveType SPA_TYPE_PROPS_BASE "waveType" -#define SPA_TYPE_PROPS__frequency SPA_TYPE_PROPS_BASE "frequency" -#define SPA_TYPE_PROPS__volume SPA_TYPE_PROPS_BASE "volume" -#define SPA_TYPE_PROPS__mute SPA_TYPE_PROPS_BASE "mute" -#define SPA_TYPE_PROPS__patternType SPA_TYPE_PROPS_BASE "patternType" -#define SPA_TYPE_PROPS__ditherType SPA_TYPE_PROPS_BASE "ditherType" -#define SPA_TYPE_PROPS__truncate SPA_TYPE_PROPS_BASE "truncate" + SPA_PROP_minLatency, + SPA_PROP_maxLatency, + SPA_PROP_periods, + SPA_PROP_periodSize, + SPA_PROP_periodEvent, + SPA_PROP_live, -#define SPA_TYPE_PROPS__brightness SPA_TYPE_PROPS_BASE "brightness" -#define SPA_TYPE_PROPS__contrast SPA_TYPE_PROPS_BASE "contrast" -#define SPA_TYPE_PROPS__saturation SPA_TYPE_PROPS_BASE "saturation" -#define SPA_TYPE_PROPS__hue SPA_TYPE_PROPS_BASE "hue" -#define SPA_TYPE_PROPS__gamma SPA_TYPE_PROPS_BASE "gamma" -#define SPA_TYPE_PROPS__exposure SPA_TYPE_PROPS_BASE "exposure" -#define SPA_TYPE_PROPS__gain SPA_TYPE_PROPS_BASE "gain" -#define SPA_TYPE_PROPS__sharpness SPA_TYPE_PROPS_BASE "sharpness" + SPA_PROP_waveType, + SPA_PROP_frequency, + SPA_PROP_volume, + SPA_PROP_mute, + SPA_PROP_patternType, + SPA_PROP_ditherType, + SPA_PROP_truncate, + + SPA_PROP_brightness, + SPA_PROP_contrast, + SPA_PROP_saturation, + SPA_PROP_hue, + SPA_PROP_gamma, + SPA_PROP_exposure, + SPA_PROP_gain, + SPA_PROP_sharpness, + + SPA_PROP_BASE_CUSTOM = 0x10000, +}; #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/param/video-padding.h b/spa/include/spa/param/video-padding.h index 4b7d52308..b9cb0ca3b 100644 --- a/spa/include/spa/param/video-padding.h +++ b/spa/include/spa/param/video-padding.h @@ -26,8 +26,8 @@ extern "C" { #include #include -#include +#if 0 #define SPA_TYPE_PARAM__VideoPadding SPA_TYPE_PARAM_BASE "VideoPadding" #define SPA_TYPE_PARAM_VIDEO_PADDING_BASE SPA_TYPE_PARAM__VideoPadding ":" @@ -39,32 +39,7 @@ extern "C" { #define SPA_TYPE_PARAM_VIDEO_PADDING__strideAlign1 SPA_TYPE_PARAM_VIDEO_PADDING_BASE "strideAlign1" #define SPA_TYPE_PARAM_VIDEO_PADDING__strideAlign2 SPA_TYPE_PARAM_VIDEO_PADDING_BASE "strideAlign2" #define SPA_TYPE_PARAM_VIDEO_PADDING__strideAlign3 SPA_TYPE_PARAM_VIDEO_PADDING_BASE "strideAlign3" - -struct spa_type_param_video_padding { - uint32_t VideoPadding; - uint32_t top; - uint32_t bottom; - uint32_t left; - uint32_t right; - uint32_t strideAlign[4]; -}; - -static inline void -spa_type_param_video_padding_map(struct spa_type_map *map, - struct spa_type_param_video_padding *type) -{ - if (type->VideoPadding == 0) { - type->VideoPadding = spa_type_map_get_id(map, SPA_TYPE_PARAM__VideoPadding); - type->top = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__top); - type->bottom = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__bottom); - type->left = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__left); - type->right = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__right); - type->strideAlign[0] = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__strideAlign0); - type->strideAlign[1] = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__strideAlign1); - type->strideAlign[2] = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__strideAlign2); - type->strideAlign[3] = spa_type_map_get_id(map, SPA_TYPE_PARAM_VIDEO_PADDING__strideAlign3); - } -} +#endif #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/include/spa/param/video/format-types.h b/spa/include/spa/param/video/format-types.h new file mode 100644 index 000000000..43c96b1ec --- /dev/null +++ b/spa/include/spa/param/video/format-types.h @@ -0,0 +1,60 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_PARAM_VIDEO_FORMAT_TYPES_H__ +#define __SPA_PARAM_VIDEO_FORMAT_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__FormatVideo SPA_TYPE_FORMAT_BASE "Video" +#define SPA_TYPE_FORMAT_VIDEO_BASE SPA_TYPE__FormatVideo ":" + +static const struct spa_type_info spa_type_format_video_ids[] = { + { SPA_FORMAT_VIDEO_format, SPA_TYPE_FORMAT_VIDEO_BASE "format", SPA_POD_TYPE_ID, + spa_type_video_format, }, + { SPA_FORMAT_VIDEO_size, SPA_TYPE_FORMAT_VIDEO_BASE "size", SPA_POD_TYPE_RECTANGLE, }, + { SPA_FORMAT_VIDEO_framerate, SPA_TYPE_FORMAT_VIDEO_BASE "framerate", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_maxFramerate, SPA_TYPE_FORMAT_VIDEO_BASE "maxFramerate", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_views, SPA_TYPE_FORMAT_VIDEO_BASE "views", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_interlaceMode, SPA_TYPE_FORMAT_VIDEO_BASE "interlaceMode", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_pixelAspectRatio, SPA_TYPE_FORMAT_VIDEO_BASE "pixelAspectRatio", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_multiviewMode, SPA_TYPE_FORMAT_VIDEO_BASE "multiviewMode", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_multiviewFlags, SPA_TYPE_FORMAT_VIDEO_BASE "multiviewFlags", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_chromaSite, SPA_TYPE_FORMAT_VIDEO_BASE "chromaSite", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_colorRange, SPA_TYPE_FORMAT_VIDEO_BASE "colorRange", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_colorMatrix, SPA_TYPE_FORMAT_VIDEO_BASE "colorMatrix", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_transferFunction, SPA_TYPE_FORMAT_VIDEO_BASE "transferFunction", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_colorPrimaries, SPA_TYPE_FORMAT_VIDEO_BASE "colorPrimaries", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_profile, SPA_TYPE_FORMAT_VIDEO_BASE "profile", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_level, SPA_TYPE_FORMAT_VIDEO_BASE "level", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_streamFormat, SPA_TYPE_FORMAT_VIDEO_BASE "streamFormat", SPA_POD_TYPE_INT, }, + { SPA_FORMAT_VIDEO_alignment, SPA_TYPE_FORMAT_VIDEO_BASE "alignment", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_PARAM_VIDEO_FORMAT_TYPES_H */ diff --git a/spa/include/spa/param/video/format-utils.h b/spa/include/spa/param/video/format-utils.h index 68e56ae9e..06def9113 100644 --- a/spa/include/spa/param/video/format-utils.h +++ b/spa/include/spa/param/video/format-utils.h @@ -24,98 +24,50 @@ extern "C" { #endif -#include -#include +#include #include -#include - -struct spa_type_format_video { - uint32_t format; - uint32_t size; - uint32_t framerate; - uint32_t max_framerate; - uint32_t views; - uint32_t interlace_mode; - uint32_t pixel_aspect_ratio; - uint32_t multiview_mode; - uint32_t multiview_flags; - uint32_t chroma_site; - uint32_t color_range; - uint32_t color_matrix; - uint32_t transfer_function; - uint32_t color_primaries; - uint32_t profile; - uint32_t level; - uint32_t stream_format; - uint32_t alignment; -}; - -static inline void -spa_type_format_video_map(struct spa_type_map *map, struct spa_type_format_video *type) -{ - if (type->format == 0) { - type->format = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__format); - type->size = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__size); - type->framerate = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__framerate); - type->max_framerate = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__maxFramerate); - type->views = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__views); - type->interlace_mode = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__interlaceMode); - type->pixel_aspect_ratio = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__pixelAspectRatio); - type->multiview_mode = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__multiviewMode); - type->multiview_flags = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__multiviewFlags); - type->chroma_site = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__chromaSite); - type->color_range = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__colorRange); - type->color_matrix = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__colorMatrix); - type->transfer_function = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__transferFunction); - type->color_primaries = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__colorPrimaries); - type->profile = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__profile); - type->level = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__level); - type->stream_format = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__streamFormat); - type->alignment = spa_type_map_get_id(map, SPA_TYPE_FORMAT_VIDEO__alignment); - } -} static inline int spa_format_video_raw_parse(const struct spa_pod *format, - struct spa_video_info_raw *info, struct spa_type_format_video *type) + struct spa_video_info_raw *info) { return spa_pod_object_parse(format, - ":",type->format, "I", &info->format, - ":",type->size, "R", &info->size, - ":",type->framerate, "F", &info->framerate, - ":",type->max_framerate, "?F", &info->max_framerate, - ":",type->views, "?i", &info->views, - ":",type->interlace_mode, "?i", &info->interlace_mode, - ":",type->pixel_aspect_ratio, "?F", &info->pixel_aspect_ratio, - ":",type->multiview_mode, "?i", &info->multiview_mode, - ":",type->multiview_flags, "?i", &info->multiview_flags, - ":",type->chroma_site, "?i", &info->chroma_site, - ":",type->color_range, "?i", &info->color_range, - ":",type->color_matrix, "?i", &info->color_matrix, - ":",type->transfer_function, "?i", &info->transfer_function, - ":",type->color_primaries, "?i", &info->color_primaries, NULL); + ":", SPA_FORMAT_VIDEO_format, "I", &info->format, + ":", SPA_FORMAT_VIDEO_size, "R", &info->size, + ":", SPA_FORMAT_VIDEO_framerate, "F", &info->framerate, + ":", SPA_FORMAT_VIDEO_maxFramerate, "?F", &info->max_framerate, + ":", SPA_FORMAT_VIDEO_views, "?i", &info->views, + ":", SPA_FORMAT_VIDEO_interlaceMode, "?i", &info->interlace_mode, + ":", SPA_FORMAT_VIDEO_pixelAspectRatio, "?F", &info->pixel_aspect_ratio, + ":", SPA_FORMAT_VIDEO_multiviewMode, "?i", &info->multiview_mode, + ":", SPA_FORMAT_VIDEO_multiviewFlags, "?i", &info->multiview_flags, + ":", SPA_FORMAT_VIDEO_chromaSite, "?i", &info->chroma_site, + ":", SPA_FORMAT_VIDEO_colorRange, "?i", &info->color_range, + ":", SPA_FORMAT_VIDEO_colorMatrix, "?i", &info->color_matrix, + ":", SPA_FORMAT_VIDEO_transferFunction, "?i", &info->transfer_function, + ":", SPA_FORMAT_VIDEO_colorPrimaries, "?i", &info->color_primaries, NULL); } static inline int spa_format_video_h264_parse(const struct spa_pod *format, - struct spa_video_info_h264 *info, struct spa_type_format_video *type) + struct spa_video_info_h264 *info) { return spa_pod_object_parse(format, - ":",type->size, "?R", &info->size, - ":",type->framerate, "?F", &info->framerate, - ":",type->max_framerate, "?F", &info->max_framerate, - ":",type->stream_format, "?i", &info->stream_format, - ":",type->alignment, "?i", &info->alignment, NULL); + ":", SPA_FORMAT_VIDEO_size, "?R", &info->size, + ":", SPA_FORMAT_VIDEO_framerate, "?F", &info->framerate, + ":", SPA_FORMAT_VIDEO_maxFramerate, "?F", &info->max_framerate, + ":", SPA_FORMAT_VIDEO_streamFormat, "?i", &info->stream_format, + ":", SPA_FORMAT_VIDEO_alignment, "?i", &info->alignment, NULL); } static inline int spa_format_video_mjpg_parse(const struct spa_pod *format, - struct spa_video_info_mjpg *info, struct spa_type_format_video *type) + struct spa_video_info_mjpg *info) { return spa_pod_object_parse(format, - ":",type->size, "?R", &info->size, - ":",type->framerate, "?F", &info->framerate, - ":",type->max_framerate, "?F", &info->max_framerate, NULL); + ":", SPA_FORMAT_VIDEO_size, "?R", &info->size, + ":", SPA_FORMAT_VIDEO_framerate, "?F", &info->framerate, + ":", SPA_FORMAT_VIDEO_maxFramerate, "?F", &info->max_framerate, NULL); } #ifdef __cplusplus diff --git a/spa/include/spa/param/video/format.h b/spa/include/spa/param/video/format.h index b557eb767..1f5a79049 100644 --- a/spa/include/spa/param/video/format.h +++ b/spa/include/spa/param/video/format.h @@ -24,10 +24,32 @@ extern "C" { #endif -#include #include #include +/** properties for audio SPA_ID_OBJECT_Format */ +enum spa_format_video { + SPA_FORMAT_VIDEO_format, + SPA_FORMAT_VIDEO_size, + SPA_FORMAT_VIDEO_framerate, + SPA_FORMAT_VIDEO_maxFramerate, + SPA_FORMAT_VIDEO_views, + SPA_FORMAT_VIDEO_interlaceMode, + SPA_FORMAT_VIDEO_pixelAspectRatio, + SPA_FORMAT_VIDEO_multiviewMode, + SPA_FORMAT_VIDEO_multiviewFlags, + SPA_FORMAT_VIDEO_chromaSite, + SPA_FORMAT_VIDEO_colorRange, + SPA_FORMAT_VIDEO_colorMatrix, + SPA_FORMAT_VIDEO_transferFunction, + SPA_FORMAT_VIDEO_colorPrimaries, + SPA_FORMAT_VIDEO_profile, + SPA_FORMAT_VIDEO_level, + SPA_FORMAT_VIDEO_streamFormat, + SPA_FORMAT_VIDEO_alignment, +}; + +#if 0 #define SPA_TYPE_FORMAT__Video SPA_TYPE_FORMAT_BASE "Video" #define SPA_TYPE_FORMAT_VIDEO_BASE SPA_TYPE_FORMAT__Video ":" @@ -49,6 +71,7 @@ extern "C" { #define SPA_TYPE_FORMAT_VIDEO__level SPA_TYPE_FORMAT_VIDEO_BASE "level" #define SPA_TYPE_FORMAT_VIDEO__streamFormat SPA_TYPE_FORMAT_VIDEO_BASE "stream-format" #define SPA_TYPE_FORMAT_VIDEO__alignment SPA_TYPE_FORMAT_VIDEO_BASE "alignment" +#endif struct spa_video_info { uint32_t media_type; diff --git a/spa/include/spa/param/video/raw-types.h b/spa/include/spa/param/video/raw-types.h new file mode 100644 index 000000000..15113a2f5 --- /dev/null +++ b/spa/include/spa/param/video/raw-types.h @@ -0,0 +1,117 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_VIDEO_RAW_TYPES_H__ +#define __SPA_VIDEO_RAW_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define SPA_TYPE__VideoFormat SPA_TYPE_ENUM_BASE "VideoFormat" +#define SPA_TYPE_VIDEO_FORMAT_BASE SPA_TYPE__VideoFormat ":" + +static const struct spa_type_info spa_type_video_format[] = { + { SPA_VIDEO_FORMAT_ENCODED, SPA_TYPE_VIDEO_FORMAT_BASE "encoded", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I420, SPA_TYPE_VIDEO_FORMAT_BASE "I420", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_YV12, SPA_TYPE_VIDEO_FORMAT_BASE "YV12", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_YUY2, SPA_TYPE_VIDEO_FORMAT_BASE "YUY2", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_UYVY, SPA_TYPE_VIDEO_FORMAT_BASE "UYVY", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_AYUV, SPA_TYPE_VIDEO_FORMAT_BASE "AYUV", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_RGBx, SPA_TYPE_VIDEO_FORMAT_BASE "RGBx", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_BGRx, SPA_TYPE_VIDEO_FORMAT_BASE "BGRx", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_xRGB, SPA_TYPE_VIDEO_FORMAT_BASE "xRGB", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_xBGR, SPA_TYPE_VIDEO_FORMAT_BASE "xBGR", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_RGBA, SPA_TYPE_VIDEO_FORMAT_BASE "RGBA", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_BGRA, SPA_TYPE_VIDEO_FORMAT_BASE "BGRA", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_ARGB, SPA_TYPE_VIDEO_FORMAT_BASE "ARGB", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_ABGR, SPA_TYPE_VIDEO_FORMAT_BASE "ABGR", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_RGB, SPA_TYPE_VIDEO_FORMAT_BASE "RGB", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_BGR, SPA_TYPE_VIDEO_FORMAT_BASE "BGR", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_Y41B, SPA_TYPE_VIDEO_FORMAT_BASE "Y41B", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_Y42B, SPA_TYPE_VIDEO_FORMAT_BASE "Y42B", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_YVYU, SPA_TYPE_VIDEO_FORMAT_BASE "YVYU", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_Y444, SPA_TYPE_VIDEO_FORMAT_BASE "Y444", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_v210, SPA_TYPE_VIDEO_FORMAT_BASE "v210", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_v216, SPA_TYPE_VIDEO_FORMAT_BASE "v216", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_NV12, SPA_TYPE_VIDEO_FORMAT_BASE "NV12", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_NV21, SPA_TYPE_VIDEO_FORMAT_BASE "NV21", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GRAY8, SPA_TYPE_VIDEO_FORMAT_BASE "GRAY8", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GRAY16_BE, SPA_TYPE_VIDEO_FORMAT_BASE "GRAY16_BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GRAY16_LE, SPA_TYPE_VIDEO_FORMAT_BASE "GRAY16_LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_v308, SPA_TYPE_VIDEO_FORMAT_BASE "v308", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_RGB16, SPA_TYPE_VIDEO_FORMAT_BASE "RGB16", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_BGR16, SPA_TYPE_VIDEO_FORMAT_BASE "BGR16", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_RGB15, SPA_TYPE_VIDEO_FORMAT_BASE "RGB15", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_BGR15, SPA_TYPE_VIDEO_FORMAT_BASE "BGR15", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_UYVP, SPA_TYPE_VIDEO_FORMAT_BASE "UYVP", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_A420, SPA_TYPE_VIDEO_FORMAT_BASE "A420", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_RGB8P, SPA_TYPE_VIDEO_FORMAT_BASE "RGB8P", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_YUV9, SPA_TYPE_VIDEO_FORMAT_BASE "YUV9", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_YVU9, SPA_TYPE_VIDEO_FORMAT_BASE "YVU9", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_IYU1, SPA_TYPE_VIDEO_FORMAT_BASE "IYU1", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_ARGB64, SPA_TYPE_VIDEO_FORMAT_BASE "ARGB64", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_AYUV64, SPA_TYPE_VIDEO_FORMAT_BASE "AYUV64", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_r210, SPA_TYPE_VIDEO_FORMAT_BASE "r210", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I420_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "I420_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I420_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "I420_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I422_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "I422_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I422_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "I422_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_Y444_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "Y444_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_Y444_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "Y444_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBR, SPA_TYPE_VIDEO_FORMAT_BASE "GBR", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBR_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "GBR_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBR_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "GBR_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_NV16, SPA_TYPE_VIDEO_FORMAT_BASE "NV16", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_NV24, SPA_TYPE_VIDEO_FORMAT_BASE "NV24", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_NV12_64Z32, SPA_TYPE_VIDEO_FORMAT_BASE "NV12_64Z32", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_A420_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "A420_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_A420_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "A420_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_A422_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "A422_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_A422_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "A422_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_A444_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "A444_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_A444_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "A444_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_NV61, SPA_TYPE_VIDEO_FORMAT_BASE "NV61", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_P010_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "P010_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_P010_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "P010_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_IYU2, SPA_TYPE_VIDEO_FORMAT_BASE "IYU2", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_VYUY, SPA_TYPE_VIDEO_FORMAT_BASE "VYUY", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBRA, SPA_TYPE_VIDEO_FORMAT_BASE "GBRA", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBRA_10BE, SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_10BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBRA_10LE, SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_10LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBR_12BE, SPA_TYPE_VIDEO_FORMAT_BASE "GBR_12BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBR_12LE, SPA_TYPE_VIDEO_FORMAT_BASE "GBR_12LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBRA_12BE, SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_12BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_GBRA_12LE, SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_12LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I420_12BE, SPA_TYPE_VIDEO_FORMAT_BASE "I420_12BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I420_12LE, SPA_TYPE_VIDEO_FORMAT_BASE "I420_12LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I422_12BE, SPA_TYPE_VIDEO_FORMAT_BASE "I422_12BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_I422_12LE, SPA_TYPE_VIDEO_FORMAT_BASE "I422_12LE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_Y444_12BE, SPA_TYPE_VIDEO_FORMAT_BASE "Y444_12BE", SPA_POD_TYPE_INT, }, + { SPA_VIDEO_FORMAT_Y444_12LE, SPA_TYPE_VIDEO_FORMAT_BASE "Y444_12LE", SPA_POD_TYPE_INT, }, + { 0, NULL, }, +}; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_VIDEO_RAW_TYPES_H__ */ diff --git a/spa/include/spa/param/video/raw-utils.h b/spa/include/spa/param/video/raw-utils.h deleted file mode 100644 index 9a6dcf4f0..000000000 --- a/spa/include/spa/param/video/raw-utils.h +++ /dev/null @@ -1,200 +0,0 @@ -/* Simple Plugin API - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __SPA_VIDEO_RAW_UTILS_H__ -#define __SPA_VIDEO_RAW_UTILS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -struct spa_type_video_format { - uint32_t UNKNOWN; - uint32_t ENCODED; - uint32_t I420; - uint32_t YV12; - uint32_t YUY2; - uint32_t UYVY; - uint32_t AYUV; - uint32_t RGBx; - uint32_t BGRx; - uint32_t xRGB; - uint32_t xBGR; - uint32_t RGBA; - uint32_t BGRA; - uint32_t ARGB; - uint32_t ABGR; - uint32_t RGB; - uint32_t BGR; - uint32_t Y41B; - uint32_t Y42B; - uint32_t YVYU; - uint32_t Y444; - uint32_t v210; - uint32_t v216; - uint32_t NV12; - uint32_t NV21; - uint32_t GRAY8; - uint32_t GRAY16_BE; - uint32_t GRAY16_LE; - uint32_t v308; - uint32_t RGB16; - uint32_t BGR16; - uint32_t RGB15; - uint32_t BGR15; - uint32_t UYVP; - uint32_t A420; - uint32_t RGB8P; - uint32_t YUV9; - uint32_t YVU9; - uint32_t IYU1; - uint32_t ARGB64; - uint32_t AYUV64; - uint32_t r210; - uint32_t I420_10BE; - uint32_t I420_10LE; - uint32_t I422_10BE; - uint32_t I422_10LE; - uint32_t Y444_10BE; - uint32_t Y444_10LE; - uint32_t GBR; - uint32_t GBR_10BE; - uint32_t GBR_10LE; - uint32_t NV16; - uint32_t NV24; - uint32_t NV12_64Z32; - uint32_t A420_10BE; - uint32_t A420_10LE; - uint32_t A422_10BE; - uint32_t A422_10LE; - uint32_t A444_10BE; - uint32_t A444_10LE; - uint32_t NV61; - uint32_t P010_10BE; - uint32_t P010_10LE; - uint32_t IYU2; - uint32_t VYUY; - uint32_t GBRA; - uint32_t GBRA_10BE; - uint32_t GBRA_10LE; - uint32_t GBR_12BE; - uint32_t GBR_12LE; - uint32_t GBRA_12BE; - uint32_t GBRA_12LE; - uint32_t I420_12BE; - uint32_t I420_12LE; - uint32_t I422_12BE; - uint32_t I422_12LE; - uint32_t Y444_12BE; - uint32_t Y444_12LE; -}; - -static inline void -spa_type_video_format_map(struct spa_type_map *map, struct spa_type_video_format *type) -{ - if (type->ENCODED == 0) { - type->UNKNOWN = 0; - type->ENCODED = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__ENCODED); - type->I420 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I420); - type->YV12 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__YV12); - type->YUY2 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__YUY2); - type->UYVY = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__UYVY); - type->AYUV = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__AYUV); - type->RGBx = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__RGBx); - type->BGRx = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__BGRx); - type->xRGB = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__xRGB); - type->xBGR = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__xBGR); - type->RGBA = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__RGBA); - type->BGRA = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__BGRA); - type->ARGB = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__ARGB); - type->ABGR = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__ABGR); - type->RGB = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__RGB); - type->BGR = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__BGR); - type->Y41B = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__Y41B); - type->Y42B = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__Y42B); - type->YVYU = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__YVYU); - type->Y444 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__Y444); - type->v210 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__v210); - type->v216 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__v216); - type->NV12 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__NV12); - type->NV21 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__NV21); - type->GRAY8 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GRAY8); - type->GRAY16_BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GRAY16_BE); - type->GRAY16_LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GRAY16_LE); - type->v308 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__v308); - type->RGB16 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__RGB16); - type->BGR16 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__BGR16); - type->RGB15 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__RGB15); - type->BGR15 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__BGR15); - type->UYVP = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__UYVP); - type->A420 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__A420); - type->RGB8P = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__RGB8P); - type->YUV9 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__YUV9); - type->YVU9 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__YVU9); - type->IYU1 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__IYU1); - type->ARGB64 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__ARGB64); - type->AYUV64 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__AYUV64); - type->r210 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__r210); - type->I420_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I420_10BE); - type->I420_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I420_10LE); - type->I422_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I422_10BE); - type->I422_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I422_10LE); - type->Y444_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__Y444_10BE); - type->Y444_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__Y444_10LE); - type->GBR = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBR); - type->GBR_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBR_10BE); - type->GBR_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBR_10LE); - type->NV16 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__NV16); - type->NV24 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__NV24); - type->NV12_64Z32 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__NV12_64Z32); - type->A420_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__A420_10BE); - type->A420_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__A420_10LE); - type->A422_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__A422_10BE); - type->A422_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__A422_10LE); - type->A444_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__A444_10BE); - type->A444_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__A444_10LE); - type->NV61 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__NV61); - type->P010_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__P010_10BE); - type->P010_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__P010_10LE); - type->IYU2 = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__IYU2); - type->VYUY = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__VYUY); - type->GBRA = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBRA); - type->GBRA_10BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBRA_10BE); - type->GBRA_10LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBRA_10LE); - type->GBR_12BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBR_12BE); - type->GBR_12LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBR_12LE); - type->GBRA_12BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBRA_12BE); - type->GBRA_12LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__GBRA_12LE); - type->I420_12BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I420_12BE); - type->I420_12LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I420_12LE); - type->I422_12BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I422_12BE); - type->I422_12LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__I422_12LE); - type->Y444_12BE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__Y444_12BE); - type->Y444_12LE = spa_type_map_get_id(map, SPA_TYPE_VIDEO_FORMAT__Y444_12LE); - } -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __SPA_VIDEO_RAW_UTILS_H__ */ diff --git a/spa/include/spa/param/video/raw.h b/spa/include/spa/param/video/raw.h index 5c9a85712..7d3cc2f4d 100644 --- a/spa/include/spa/param/video/raw.h +++ b/spa/include/spa/param/video/raw.h @@ -24,6 +24,7 @@ extern "C" { #endif +#include #include #include #include @@ -31,86 +32,86 @@ extern "C" { #define SPA_VIDEO_MAX_PLANES 4 #define SPA_VIDEO_MAX_COMPONENTS 4 -#define SPA_TYPE__VideoFormat SPA_TYPE_ENUM_BASE "VideoFormat" -#define SPA_TYPE_VIDEO_FORMAT_BASE SPA_TYPE__VideoFormat ":" - -#define SPA_TYPE_VIDEO_FORMAT__ENCODED SPA_TYPE_VIDEO_FORMAT_BASE "encoded" -#define SPA_TYPE_VIDEO_FORMAT__I420 SPA_TYPE_VIDEO_FORMAT_BASE "I420" -#define SPA_TYPE_VIDEO_FORMAT__YV12 SPA_TYPE_VIDEO_FORMAT_BASE "YV12" -#define SPA_TYPE_VIDEO_FORMAT__YUY2 SPA_TYPE_VIDEO_FORMAT_BASE "YUY2" -#define SPA_TYPE_VIDEO_FORMAT__UYVY SPA_TYPE_VIDEO_FORMAT_BASE "UYVY" -#define SPA_TYPE_VIDEO_FORMAT__AYUV SPA_TYPE_VIDEO_FORMAT_BASE "AYUV" -#define SPA_TYPE_VIDEO_FORMAT__RGBx SPA_TYPE_VIDEO_FORMAT_BASE "RGBx" -#define SPA_TYPE_VIDEO_FORMAT__BGRx SPA_TYPE_VIDEO_FORMAT_BASE "BGRx" -#define SPA_TYPE_VIDEO_FORMAT__xRGB SPA_TYPE_VIDEO_FORMAT_BASE "xRGB" -#define SPA_TYPE_VIDEO_FORMAT__xBGR SPA_TYPE_VIDEO_FORMAT_BASE "xBGR" -#define SPA_TYPE_VIDEO_FORMAT__RGBA SPA_TYPE_VIDEO_FORMAT_BASE "RGBA" -#define SPA_TYPE_VIDEO_FORMAT__BGRA SPA_TYPE_VIDEO_FORMAT_BASE "BGRA" -#define SPA_TYPE_VIDEO_FORMAT__ARGB SPA_TYPE_VIDEO_FORMAT_BASE "ARGB" -#define SPA_TYPE_VIDEO_FORMAT__ABGR SPA_TYPE_VIDEO_FORMAT_BASE "ABGR" -#define SPA_TYPE_VIDEO_FORMAT__RGB SPA_TYPE_VIDEO_FORMAT_BASE "RGB" -#define SPA_TYPE_VIDEO_FORMAT__BGR SPA_TYPE_VIDEO_FORMAT_BASE "BGR" -#define SPA_TYPE_VIDEO_FORMAT__Y41B SPA_TYPE_VIDEO_FORMAT_BASE "Y41B" -#define SPA_TYPE_VIDEO_FORMAT__Y42B SPA_TYPE_VIDEO_FORMAT_BASE "Y42B" -#define SPA_TYPE_VIDEO_FORMAT__YVYU SPA_TYPE_VIDEO_FORMAT_BASE "YVYU" -#define SPA_TYPE_VIDEO_FORMAT__Y444 SPA_TYPE_VIDEO_FORMAT_BASE "Y444" -#define SPA_TYPE_VIDEO_FORMAT__v210 SPA_TYPE_VIDEO_FORMAT_BASE "v210" -#define SPA_TYPE_VIDEO_FORMAT__v216 SPA_TYPE_VIDEO_FORMAT_BASE "v216" -#define SPA_TYPE_VIDEO_FORMAT__NV12 SPA_TYPE_VIDEO_FORMAT_BASE "NV12" -#define SPA_TYPE_VIDEO_FORMAT__NV21 SPA_TYPE_VIDEO_FORMAT_BASE "NV21" -#define SPA_TYPE_VIDEO_FORMAT__GRAY8 SPA_TYPE_VIDEO_FORMAT_BASE "GRAY8" -#define SPA_TYPE_VIDEO_FORMAT__GRAY16_BE SPA_TYPE_VIDEO_FORMAT_BASE "GRAY16_BE" -#define SPA_TYPE_VIDEO_FORMAT__GRAY16_LE SPA_TYPE_VIDEO_FORMAT_BASE "GRAY16_LE" -#define SPA_TYPE_VIDEO_FORMAT__v308 SPA_TYPE_VIDEO_FORMAT_BASE "v308" -#define SPA_TYPE_VIDEO_FORMAT__RGB16 SPA_TYPE_VIDEO_FORMAT_BASE "RGB16" -#define SPA_TYPE_VIDEO_FORMAT__BGR16 SPA_TYPE_VIDEO_FORMAT_BASE "BGR16" -#define SPA_TYPE_VIDEO_FORMAT__RGB15 SPA_TYPE_VIDEO_FORMAT_BASE "RGB15" -#define SPA_TYPE_VIDEO_FORMAT__BGR15 SPA_TYPE_VIDEO_FORMAT_BASE "BGR15" -#define SPA_TYPE_VIDEO_FORMAT__UYVP SPA_TYPE_VIDEO_FORMAT_BASE "UYVP" -#define SPA_TYPE_VIDEO_FORMAT__A420 SPA_TYPE_VIDEO_FORMAT_BASE "A420" -#define SPA_TYPE_VIDEO_FORMAT__RGB8P SPA_TYPE_VIDEO_FORMAT_BASE "RGB8P" -#define SPA_TYPE_VIDEO_FORMAT__YUV9 SPA_TYPE_VIDEO_FORMAT_BASE "YUV9" -#define SPA_TYPE_VIDEO_FORMAT__YVU9 SPA_TYPE_VIDEO_FORMAT_BASE "YVU9" -#define SPA_TYPE_VIDEO_FORMAT__IYU1 SPA_TYPE_VIDEO_FORMAT_BASE "IYU1" -#define SPA_TYPE_VIDEO_FORMAT__ARGB64 SPA_TYPE_VIDEO_FORMAT_BASE "ARGB64" -#define SPA_TYPE_VIDEO_FORMAT__AYUV64 SPA_TYPE_VIDEO_FORMAT_BASE "AYUV64" -#define SPA_TYPE_VIDEO_FORMAT__r210 SPA_TYPE_VIDEO_FORMAT_BASE "r210" -#define SPA_TYPE_VIDEO_FORMAT__I420_10BE SPA_TYPE_VIDEO_FORMAT_BASE "I420_10BE" -#define SPA_TYPE_VIDEO_FORMAT__I420_10LE SPA_TYPE_VIDEO_FORMAT_BASE "I420_10LE" -#define SPA_TYPE_VIDEO_FORMAT__I422_10BE SPA_TYPE_VIDEO_FORMAT_BASE "I422_10BE" -#define SPA_TYPE_VIDEO_FORMAT__I422_10LE SPA_TYPE_VIDEO_FORMAT_BASE "I422_10LE" -#define SPA_TYPE_VIDEO_FORMAT__Y444_10BE SPA_TYPE_VIDEO_FORMAT_BASE "Y444_10BE" -#define SPA_TYPE_VIDEO_FORMAT__Y444_10LE SPA_TYPE_VIDEO_FORMAT_BASE "Y444_10LE" -#define SPA_TYPE_VIDEO_FORMAT__GBR SPA_TYPE_VIDEO_FORMAT_BASE "GBR" -#define SPA_TYPE_VIDEO_FORMAT__GBR_10BE SPA_TYPE_VIDEO_FORMAT_BASE "GBR_10BE" -#define SPA_TYPE_VIDEO_FORMAT__GBR_10LE SPA_TYPE_VIDEO_FORMAT_BASE "GBR_10LE" -#define SPA_TYPE_VIDEO_FORMAT__NV16 SPA_TYPE_VIDEO_FORMAT_BASE "NV16" -#define SPA_TYPE_VIDEO_FORMAT__NV24 SPA_TYPE_VIDEO_FORMAT_BASE "NV24" -#define SPA_TYPE_VIDEO_FORMAT__NV12_64Z32 SPA_TYPE_VIDEO_FORMAT_BASE "NV12_64Z32" -#define SPA_TYPE_VIDEO_FORMAT__A420_10BE SPA_TYPE_VIDEO_FORMAT_BASE "A420_10BE" -#define SPA_TYPE_VIDEO_FORMAT__A420_10LE SPA_TYPE_VIDEO_FORMAT_BASE "A420_10LE" -#define SPA_TYPE_VIDEO_FORMAT__A422_10BE SPA_TYPE_VIDEO_FORMAT_BASE "A422_10BE" -#define SPA_TYPE_VIDEO_FORMAT__A422_10LE SPA_TYPE_VIDEO_FORMAT_BASE "A422_10LE" -#define SPA_TYPE_VIDEO_FORMAT__A444_10BE SPA_TYPE_VIDEO_FORMAT_BASE "A444_10BE" -#define SPA_TYPE_VIDEO_FORMAT__A444_10LE SPA_TYPE_VIDEO_FORMAT_BASE "A444_10LE" -#define SPA_TYPE_VIDEO_FORMAT__NV61 SPA_TYPE_VIDEO_FORMAT_BASE "NV61" -#define SPA_TYPE_VIDEO_FORMAT__P010_10BE SPA_TYPE_VIDEO_FORMAT_BASE "P010_10BE" -#define SPA_TYPE_VIDEO_FORMAT__P010_10LE SPA_TYPE_VIDEO_FORMAT_BASE "P010_10LE" -#define SPA_TYPE_VIDEO_FORMAT__IYU2 SPA_TYPE_VIDEO_FORMAT_BASE "IYU2" -#define SPA_TYPE_VIDEO_FORMAT__VYUY SPA_TYPE_VIDEO_FORMAT_BASE "VYUY" -#define SPA_TYPE_VIDEO_FORMAT__GBRA SPA_TYPE_VIDEO_FORMAT_BASE "GBRA" -#define SPA_TYPE_VIDEO_FORMAT__GBRA_10BE SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_10BE" -#define SPA_TYPE_VIDEO_FORMAT__GBRA_10LE SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_10LE" -#define SPA_TYPE_VIDEO_FORMAT__GBR_12BE SPA_TYPE_VIDEO_FORMAT_BASE "GBR_12BE" -#define SPA_TYPE_VIDEO_FORMAT__GBR_12LE SPA_TYPE_VIDEO_FORMAT_BASE "GBR_12LE" -#define SPA_TYPE_VIDEO_FORMAT__GBRA_12BE SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_12BE" -#define SPA_TYPE_VIDEO_FORMAT__GBRA_12LE SPA_TYPE_VIDEO_FORMAT_BASE "GBRA_12LE" -#define SPA_TYPE_VIDEO_FORMAT__I420_12BE SPA_TYPE_VIDEO_FORMAT_BASE "I420_12BE" -#define SPA_TYPE_VIDEO_FORMAT__I420_12LE SPA_TYPE_VIDEO_FORMAT_BASE "I420_12LE" -#define SPA_TYPE_VIDEO_FORMAT__I422_12BE SPA_TYPE_VIDEO_FORMAT_BASE "I422_12BE" -#define SPA_TYPE_VIDEO_FORMAT__I422_12LE SPA_TYPE_VIDEO_FORMAT_BASE "I422_12LE" -#define SPA_TYPE_VIDEO_FORMAT__Y444_12BE SPA_TYPE_VIDEO_FORMAT_BASE "Y444_12BE" -#define SPA_TYPE_VIDEO_FORMAT__Y444_12LE SPA_TYPE_VIDEO_FORMAT_BASE "Y444_12LE" +enum spa_video_format { + 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, +}; /** * spa_video_flags: @@ -174,7 +175,7 @@ enum spa_video_interlace_mode { * @color_primaries: color primaries. used to convert between R'G'B' and CIE XYZ */ struct spa_video_info_raw { - uint32_t format; + enum spa_video_format format; struct spa_rectangle size; struct spa_fraction framerate; struct spa_fraction max_framerate; diff --git a/spa/include/spa/pod/command-types.h b/spa/include/spa/pod/command-types.h new file mode 100644 index 000000000..b38470128 --- /dev/null +++ b/spa/include/spa/pod/command-types.h @@ -0,0 +1,36 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_COMMAND_TYPES_H__ +#define __SPA_COMMAND_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define SPA_TYPE__Command SPA_TYPE_POD_OBJECT_BASE "Command" +#define SPA_TYPE_COMMAND_BASE SPA_TYPE__Command ":" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_COMMAND_TYPES_H__ */ diff --git a/spa/include/spa/pod/command.h b/spa/include/spa/pod/command.h index 2c4289d10..1ee4ba901 100644 --- a/spa/include/spa/pod/command.h +++ b/spa/include/spa/pod/command.h @@ -27,9 +27,6 @@ extern "C" { #include #include -#define SPA_TYPE__Command SPA_TYPE_POD_OBJECT_BASE "Command" -#define SPA_TYPE_COMMAND_BASE SPA_TYPE__Command ":" - struct spa_command_body { struct spa_pod_object_body body; }; diff --git a/spa/include/spa/pod/event-types.h b/spa/include/spa/pod/event-types.h new file mode 100644 index 000000000..8cc144d59 --- /dev/null +++ b/spa/include/spa/pod/event-types.h @@ -0,0 +1,36 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_EVENT_TYPES_H__ +#define __SPA_EVENT_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define SPA_TYPE__Event SPA_TYPE_POD_OBJECT_BASE "Event" +#define SPA_TYPE_EVENT_BASE SPA_TYPE__Event ":" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_EVENT_TYPES_H__ */ diff --git a/spa/include/spa/pod/event.h b/spa/include/spa/pod/event.h index 18444399a..35b9d740d 100644 --- a/spa/include/spa/pod/event.h +++ b/spa/include/spa/pod/event.h @@ -26,9 +26,6 @@ extern "C" { #include -#define SPA_TYPE__Event SPA_TYPE_POD_OBJECT_BASE "Event" -#define SPA_TYPE_EVENT_BASE SPA_TYPE__Event ":" - struct spa_event_body { struct spa_pod_object_body body; }; diff --git a/spa/include/spa/pod/pod-types.h b/spa/include/spa/pod/pod-types.h new file mode 100644 index 000000000..8f6d2eb50 --- /dev/null +++ b/spa/include/spa/pod/pod-types.h @@ -0,0 +1,43 @@ +/* Simple Plugin API + * Copyright (C) 2017 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_POD_TYPES_H__ +#define __SPA_POD_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__POD SPA_TYPE_BASE "POD" +#define SPA_TYPE_POD_BASE SPA_TYPE__POD ":" + +#define SPA_TYPE_POD__Object SPA_TYPE_POD_BASE "Object" +#define SPA_TYPE_POD_OBJECT_BASE SPA_TYPE_POD__Object ":" + +#define SPA_TYPE_POD__Struct SPA_TYPE_POD_BASE "Struct" +#define SPA_TYPE_POD_STRUCT_BASE SPA_TYPE_POD__Struct ":" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_POD_TYPES_H__ */ diff --git a/spa/include/spa/pod/pod.h b/spa/include/spa/pod/pod.h index 22c88f883..8c0f5827b 100644 --- a/spa/include/spa/pod/pod.h +++ b/spa/include/spa/pod/pod.h @@ -28,15 +28,6 @@ extern "C" { #include -#define SPA_TYPE__POD SPA_TYPE_BASE "POD" -#define SPA_TYPE_POD_BASE SPA_TYPE__POD ":" - -#define SPA_TYPE_POD__Object SPA_TYPE_POD_BASE "Object" -#define SPA_TYPE_POD_OBJECT_BASE SPA_TYPE_POD__Object ":" - -#define SPA_TYPE_POD__Struct SPA_TYPE_POD_BASE "Struct" -#define SPA_TYPE_POD_STRUCT_BASE SPA_TYPE_POD__Struct ":" - #ifndef SPA_POD_MAX_DEPTH #define SPA_POD_MAX_DEPTH 16 #endif diff --git a/spa/include/spa/support/loop-types.h b/spa/include/spa/support/loop-types.h new file mode 100644 index 000000000..836bcddd8 --- /dev/null +++ b/spa/include/spa/support/loop-types.h @@ -0,0 +1,43 @@ +/* Simple Plugin API + * Copyright (C) 2016 Wim Taymans + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __SPA_LOOP_TYPES_H__ +#define __SPA_LOOP_TYPES_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define SPA_TYPE__Loop SPA_TYPE_INTERFACE_BASE "Loop" +#define SPA_TYPE_LOOP_BASE SPA_TYPE__Loop ":" + +#define SPA_TYPE__LoopControl SPA_TYPE_INTERFACE_BASE "LoopControl" +#define SPA_TYPE__LoopUtils SPA_TYPE_INTERFACE_BASE "LoopUtils" + +#define SPA_TYPE_LOOP__MainLoop SPA_TYPE_LOOP_BASE "MainLoop" +#define SPA_TYPE_LOOP__DataLoop SPA_TYPE_LOOP_BASE "DataLoop" + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* __SPA_LOOP_H__ */ diff --git a/spa/include/spa/support/loop.h b/spa/include/spa/support/loop.h index 8e43454e2..b24479e28 100644 --- a/spa/include/spa/support/loop.h +++ b/spa/include/spa/support/loop.h @@ -25,16 +25,9 @@ extern "C" { #endif struct spa_loop; -#define SPA_TYPE__Loop SPA_TYPE_INTERFACE_BASE "Loop" -#define SPA_TYPE_LOOP_BASE SPA_TYPE__Loop ":" - struct spa_loop_control; -#define SPA_TYPE__LoopControl SPA_TYPE_INTERFACE_BASE "LoopControl" struct spa_loop_utils; -#define SPA_TYPE__LoopUtils SPA_TYPE_INTERFACE_BASE "LoopUtils" - -#define SPA_TYPE_LOOP__MainLoop SPA_TYPE_LOOP_BASE "MainLoop" -#define SPA_TYPE_LOOP__DataLoop SPA_TYPE_LOOP_BASE "DataLoop" +struct spa_source; #include #include @@ -46,8 +39,6 @@ enum spa_io { SPA_IO_ERR = (1 << 3), }; -struct spa_source; - typedef void (*spa_source_func_t) (struct spa_source *source); struct spa_source { diff --git a/spa/include/spa/support/plugin.h b/spa/include/spa/support/plugin.h index c7e83a82a..5dd1b7ebb 100644 --- a/spa/include/spa/support/plugin.h +++ b/spa/include/spa/support/plugin.h @@ -66,8 +66,8 @@ struct spa_handle { * handles. */ struct spa_interface_info { - const char *type; /*< the type of the interface, can be - * used to get the interface */ + uint32_t type; /*< the type of the interface, can be + * used to get the interface */ }; /** @@ -75,18 +75,18 @@ struct spa_interface_info { * a factory. It can be extra information or interfaces such as logging. */ struct spa_support { - const char *type; /*< the type of the support item */ - void *data; /*< specific data for the item */ + uint32_t type; /*< the type of the support item */ + void *data; /*< specific data for the item */ }; /** Find a support item of the given type */ static inline void *spa_support_find(const struct spa_support *support, uint32_t n_support, - const char *type) + uint32_t type) { uint32_t i; for (i = 0; i < n_support; i++) { - if (strcmp(support[i].type, type) == 0) + if (support[i].type == type) return support[i].data; } return NULL; diff --git a/spa/include/spa/support/type-map-impl.h b/spa/include/spa/support/type-map-impl.h deleted file mode 100644 index 496945d10..000000000 --- a/spa/include/spa/support/type-map-impl.h +++ /dev/null @@ -1,87 +0,0 @@ -/* Simple Plugin API - * Copyright (C) 2016 Wim Taymans - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __SPA_TYPE_MAP_IMPL_H__ -#define __SPA_TYPE_MAP_IMPL_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -struct spa_type_map_impl_data { - struct spa_type_map map; - unsigned int n_types; - char *types[1]; -}; - -static inline uint32_t -spa_type_map_impl_get_id (struct spa_type_map *map, const char *type) -{ - struct spa_type_map_impl_data *impl = (struct spa_type_map_impl_data *) map; - uint32_t i = 0; - - for (i = 1; i <= impl->n_types; i++) { - if (strcmp(impl->types[i], type) == 0) - return i; - } - impl->types[i] = (char *) type; - impl->n_types++; - return i; -} - -static inline const char * -spa_type_map_impl_get_type (const struct spa_type_map *map, uint32_t id) -{ - struct spa_type_map_impl_data *impl = (struct spa_type_map_impl_data *) map; - if (id <= impl->n_types) - return impl->types[id]; - return NULL; -} - -static inline size_t spa_type_map_impl_get_size (const struct spa_type_map *map) -{ - struct spa_type_map_impl_data *impl = (struct spa_type_map_impl_data *) map; - return impl->n_types; -} - -#define SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) \ -struct { \ - struct spa_type_map map; \ - unsigned int n_types; \ - char *types[maxtypes]; \ -} name - -#define SPA_TYPE_MAP_IMPL_INIT \ - { { SPA_VERSION_TYPE_MAP, \ - NULL, \ - spa_type_map_impl_get_id, \ - spa_type_map_impl_get_type, \ - spa_type_map_impl_get_size,}, \ - 0, { NULL, } } - -#define SPA_TYPE_MAP_IMPL(name,maxtypes) \ - SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) = SPA_TYPE_MAP_IMPL_INIT - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* __SPA_TYPE_MAP_IMPL_H__ */ diff --git a/spa/include/spa/support/type-map.h b/spa/include/spa/utils/type-info.h similarity index 51% rename from spa/include/spa/support/type-map.h rename to spa/include/spa/utils/type-info.h index 9e5335000..36c467e9f 100644 --- a/spa/include/spa/support/type-map.h +++ b/spa/include/spa/utils/type-info.h @@ -17,44 +17,46 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __SPA_TYPE_MAP_H__ -#define __SPA_TYPE_MAP_H__ +#ifndef __SPA_TYPE_INFO_H__ +#define __SPA_TYPE_INFO_H__ #ifdef __cplusplus extern "C" { #endif #include -#include -#define SPA_TYPE__TypeMap SPA_TYPE_INTERFACE_BASE "TypeMap" +#define SPA_TYPE_BASE "Spa:" -/** - * Maps between string types and their type id - */ -struct spa_type_map { - /** the version of this structure. This can be used to expand this - * structure in the future */ -#define SPA_VERSION_TYPE_MAP 0 - uint32_t version; - /** - * Extra information about the type map - */ - const struct spa_dict *info; +#define SPA_TYPE__Enum SPA_TYPE_BASE "Enum" +#define SPA_TYPE_ENUM_BASE SPA_TYPE__Enum ":" - uint32_t (*get_id) (struct spa_type_map *map, const char *type); +#define SPA_TYPE__Flags SPA_TYPE_BASE "Flags" +#define SPA_TYPE_FLAGS_BASE SPA_TYPE__Flags ":" - const char *(*get_type) (const struct spa_type_map *map, uint32_t id); +#define SPA_TYPE__Pointer SPA_TYPE_BASE "Pointer" +#define SPA_TYPE_POINTER_BASE SPA_TYPE__Pointer ":" - size_t (*get_size) (const struct spa_type_map *map); +#define SPA_TYPE__Interface SPA_TYPE_BASE "Interface" +#define SPA_TYPE_INTERFACE_BASE SPA_TYPE__Interface ":" + +#define SPA_TYPE__Object SPA_TYPE_BASE "Object" +#define SPA_TYPE_OBJECT_BASE SPA_TYPE__Object ":" + +static inline bool spa_type_is_a(const char *type, const char *parent) +{ + return type != NULL && parent != NULL && strncmp(type, parent, strlen(parent)) == 0; +} + +struct spa_type_info { + uint32_t id; + const char *name; + uint32_t type; + const struct spa_type_info *values; }; -#define spa_type_map_get_id(n,...) (n)->get_id((n),__VA_ARGS__) -#define spa_type_map_get_type(n,...) (n)->get_type((n),__VA_ARGS__) -#define spa_type_map_get_size(n) (n)->get_size(n) - #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* __SPA_TYPE_MAP_H__ */ +#endif /* __SPA_TYPE_INFO_H__ */ diff --git a/spa/include/spa/utils/type.h b/spa/include/spa/utils/type.h index 4ddcece9a..298e354c4 100644 --- a/spa/include/spa/utils/type.h +++ b/spa/include/spa/utils/type.h @@ -26,24 +26,78 @@ extern "C" { #include -#define SPA_TYPE_BASE "Spa:" +enum { + SPA_ID_UNASSIGNED = 0, + /* Interfaces */ + SPA_ID_INTERFACE_Handle, + SPA_ID_INTERFACE_HandleFactory, + SPA_ID_INTERFACE_Log, + SPA_ID_INTERFACE_Loop, + SPA_ID_INTERFACE_LoopControl, + SPA_ID_INTERFACE_LoopUtils, + SPA_ID_INTERFACE_DataLoop, + SPA_ID_INTERFACE_MainLoop, + SPA_ID_INTERFACE_DBus, + SPA_ID_INTERFACE_Monitor, + SPA_ID_INTERFACE_Node, -#define SPA_TYPE__Enum SPA_TYPE_BASE "Enum" -#define SPA_TYPE_ENUM_BASE SPA_TYPE__Enum ":" + /* Events */ + SPA_ID_EVENT_BASE = 0x10000, + SPA_ID_EVENT_MONITOR_Added, + SPA_ID_EVENT_MONITOR_Removed, + SPA_ID_EVENT_MONITOR_Changed, + SPA_ID_EVENT_NODE_Error, + SPA_ID_EVENT_NODE_Buffering, + SPA_ID_EVENT_NODE_RequestRefresh, -#define SPA_TYPE__Pointer SPA_TYPE_BASE "Pointer" -#define SPA_TYPE_POINTER_BASE SPA_TYPE__Pointer ":" + /* Commands */ + SPA_ID_COMMAND_BASE = 0x20000, + SPA_ID_COMMAND_NODE_Suspend, + SPA_ID_COMMAND_NODE_Pause, + SPA_ID_COMMAND_NODE_Start, + SPA_ID_COMMAND_NODE_Enable, + SPA_ID_COMMAND_NODE_Disable, + SPA_ID_COMMAND_NODE_Flush, + SPA_ID_COMMAND_NODE_Drain, + SPA_ID_COMMAND_NODE_Marker, -#define SPA_TYPE__Interface SPA_TYPE_BASE "Interface" -#define SPA_TYPE_INTERFACE_BASE SPA_TYPE__Interface ":" + /* Objects */ + SPA_ID_OBJECT_BASE = 0x30000, + SPA_ID_OBJECT_MonitorItem, -#define SPA_TYPE__Object SPA_TYPE_BASE "Object" -#define SPA_TYPE_OBJECT_BASE SPA_TYPE__Object ":" + SPA_ID_OBJECT_ParamList, + SPA_ID_OBJECT_PropInfo, + SPA_ID_OBJECT_Props, + SPA_ID_OBJECT_Format, + SPA_ID_OBJECT_ParamBuffers, + SPA_ID_OBJECT_ParamMeta, + SPA_ID_OBJECT_ParamIO, + + /* IO */ + SPA_ID_IO_BASE = 0x40000, + SPA_ID_IO_Buffers, + SPA_ID_IO_ControlRange, + SPA_ID_IO_Clock, + SPA_ID_IO_Prop, + SPA_ID_IO_Latency, + + /* Params */ + SPA_ID_PARAM_BASE = 0x50000, + SPA_ID_PARAM_List, /**< available params */ + SPA_ID_PARAM_PropInfo, /**< property information */ + SPA_ID_PARAM_Props, /**< properties */ + SPA_ID_PARAM_EnumFormat, /**< available formats */ + SPA_ID_PARAM_Format, /**< configured format */ + SPA_ID_PARAM_Buffers, /**< buffer configurations */ + SPA_ID_PARAM_Meta, /**< allowed metadata for buffers */ + SPA_ID_PARAM_IO, /**< configurable IO areas */ + + /* vendor extensions */ + SPA_ID_VENDOR_PipeWire = 0x01000000, + + SPA_ID_VENDOR_Other = 0x7f000000, +}; -static inline bool spa_type_is_a(const char *type, const char *parent) -{ - return type != NULL && parent != NULL && strncmp(type, parent, strlen(parent)) == 0; -} #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c index 6c1a6574d..400a1c835 100644 --- a/spa/plugins/alsa/alsa-monitor.c +++ b/spa/plugins/alsa/alsa-monitor.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -41,17 +41,6 @@ extern const struct spa_handle_factory spa_alsa_sink_factory; extern const struct spa_handle_factory spa_alsa_source_factory; -struct type { - uint32_t handle_factory; - struct spa_type_monitor monitor; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->handle_factory = spa_type_map_get_id(map, SPA_TYPE__HandleFactory); - spa_type_monitor_map(map, &type->monitor); -} - struct device { int id; #define DEVICE_FLAG_VALID (1<<0) @@ -76,8 +65,6 @@ struct impl { struct spa_handle handle; struct spa_monitor monitor; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *main_loop; @@ -133,7 +120,6 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, const char *str, *name, *klass = NULL; const struct spa_handle_factory *factory = NULL; char device_name[64], id[66]; - struct type *t = &this->type; struct udev_device *dev = card->dev; struct device *device; int device_idx = snd_pcm_info_get_device(dev_info); @@ -175,16 +161,14 @@ fill_item(struct impl *this, snd_ctl_card_info_t *card_info, name = "Unknown"; spa_pod_builder_add(builder, - "<", 0, t->monitor.MonitorItem, - ":", t->monitor.id, "s", id, - ":", t->monitor.flags, "i", 0, - ":", t->monitor.state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE, - ":", t->monitor.name, "s", name, - ":", t->monitor.klass, "s", klass, - ":", t->monitor.factory, "p", t->handle_factory, factory, NULL); - - spa_pod_builder_add(builder, - ":", t->monitor.info, "[", NULL); + "<", 0, SPA_ID_OBJECT_MonitorItem, + ":", SPA_MONITOR_ITEM_id, "s", id, + ":", SPA_MONITOR_ITEM_flags, "i", SPA_MONITOR_ITEM_FLAG_NONE, + ":", SPA_MONITOR_ITEM_state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE, + ":", SPA_MONITOR_ITEM_name, "s", name, + ":", SPA_MONITOR_ITEM_class, "s", klass, + ":", SPA_MONITOR_ITEM_factory, "p", SPA_ID_INTERFACE_HandleFactory, factory, + ":", SPA_MONITOR_ITEM_info, "[", NULL); spa_pod_builder_add(builder, "s", "alsa.card", "s", card->name, @@ -366,7 +350,6 @@ static void impl_on_fd_events(struct spa_source *source) uint32_t type; struct card *card; struct spa_event *event; - struct type *t = &this->type; dev = udev_monitor_receive_device(this->umonitor); @@ -374,18 +357,18 @@ static void impl_on_fd_events(struct spa_source *source) action = "change"; if (strcmp(action, "add") == 0) { - type = this->type.monitor.Added; + type = SPA_ID_EVENT_MONITOR_Added; } else if (strcmp(action, "change") == 0) { - type = this->type.monitor.Changed; + type = SPA_ID_EVENT_MONITOR_Changed; } else if (strcmp(action, "remove") == 0) { - type = this->type.monitor.Removed; + type = SPA_ID_EVENT_MONITOR_Removed; } else return; if ((card = find_card(this, dev)) == NULL) return; - if (type == this->type.monitor.Removed) { + if (type == SPA_ID_EVENT_MONITOR_Removed) { int i; for (i = 0; i < MAX_DEVICES; i++) { @@ -399,18 +382,18 @@ static void impl_on_fd_events(struct spa_source *source) snprintf(id, 64, "%s,%d/P", card->name, device->id); event = spa_pod_builder_object(&b, 0, type); spa_pod_builder_object(&b, - 0, t->monitor.MonitorItem, - ":", t->monitor.id, "s", id, - ":", t->monitor.name, "s", id); + 0, SPA_ID_OBJECT_MonitorItem, + ":", SPA_MONITOR_ITEM_id, "s", id, + ":", SPA_MONITOR_ITEM_name, "s", id); this->callbacks->event(this->callbacks_data, event); } if (SPA_FLAG_CHECK(device->flags, DEVICE_FLAG_RECORD)) { snprintf(id, 64, "%s,%d/C", card->name, device->id); event = spa_pod_builder_object(&b, 0, type); spa_pod_builder_object(&b, - 0, t->monitor.MonitorItem, - ":", t->monitor.id, "s", id, - ":", t->monitor.name, "s", id); + 0, SPA_ID_OBJECT_MonitorItem, + ":", SPA_MONITOR_ITEM_id, "s", id, + ":", SPA_MONITOR_ITEM_name, "s", id); this->callbacks->event(this->callbacks_data, event); } device->flags = 0; @@ -561,7 +544,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, this = (struct impl *) handle; - if (interface_id == this->type.monitor.Monitor) + if (interface_id == SPA_ID_INTERFACE_Monitor) *interface = &this->monitor; else return -ENOENT; @@ -613,31 +596,23 @@ 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_MainLoop) this->main_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "an id-map is needed"); - return -EINVAL; - } if (this->main_loop == NULL) { spa_log_error(this->log, "a main-loop is needed"); return -EINVAL; } - init_type(&this->type, this->map); - this->monitor = impl_monitor; return 0; } static const struct spa_interface_info impl_interfaces[] = { - {SPA_TYPE__Monitor,}, + {SPA_ID_INTERFACE_Monitor,}, }; static int diff --git a/spa/plugins/alsa/alsa-sink.c b/spa/plugins/alsa/alsa-sink.c index 98eca7382..b6deaf6b8 100644 --- a/spa/plugins/alsa/alsa-sink.c +++ b/spa/plugins/alsa/alsa-sink.c @@ -49,7 +49,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct state *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -59,85 +58,92 @@ static int impl_node_enum_params(struct spa_node *node, spa_return_val_if_fail(builder != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idPropInfo, - t->param.idProps }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + SPA_ID_PARAM_Props }; 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.idPropInfo) { + case SPA_ID_PARAM_PropInfo: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_device, - ":", t->param.propName, "s", "The ALSA device", - ":", t->param.propType, "S", p->device, sizeof(p->device)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_device, + ":", SPA_PROP_INFO_name, "s", "The ALSA device", + ":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device)); break; case 1: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_device_name, - ":", t->param.propName, "s", "The ALSA device name", - ":", t->param.propType, "S-r", p->device_name, sizeof(p->device_name)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName, + ":", SPA_PROP_INFO_name, "s", "The ALSA device name", + ":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name)); break; case 2: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_card_name, - ":", t->param.propName, "s", "The ALSA card name", - ":", t->param.propType, "S-r", p->card_name, sizeof(p->card_name)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_cardName, + ":", SPA_PROP_INFO_name, "s", "The ALSA card name", + ":", SPA_PROP_INFO_type, "S-r", p->card_name, sizeof(p->card_name)); break; case 3: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_min_latency, - ":", t->param.propName, "s", "The minimum latency", - ":", t->param.propType, "ir", p->min_latency, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency, + ":", SPA_PROP_INFO_name, "s", "The minimum latency", + ":", SPA_PROP_INFO_type, "ir", p->min_latency, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; case 4: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_max_latency, - ":", t->param.propName, "s", "The maximum latency", - ":", t->param.propType, "ir", p->max_latency, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency, + ":", SPA_PROP_INFO_name, "s", "The maximum latency", + ":", SPA_PROP_INFO_type, "ir", p->max_latency, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; default: return 0; } + break; } - else if (id == t->param.idProps) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_device, "S", p->device, sizeof(p->device), - ":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name), - ":", t->prop_card_name, "S-r", p->card_name, sizeof(p->card_name), - ":", t->prop_min_latency, "i", p->min_latency, - ":", t->prop_max_latency, "i", p->max_latency); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "S", p->device, sizeof(p->device), + ":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name), + ":", SPA_PROP_cardName, "S-r", p->card_name, sizeof(p->card_name), + ":", SPA_PROP_minLatency, "i", p->min_latency, + ":", SPA_PROP_maxLatency, "i", p->max_latency); break; default: return 0; } + break; } - else + default: return -ENOENT; + } (*index)++; @@ -151,14 +157,12 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag const struct spa_pod *param) { struct state *this; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; - if (id == t->param.idProps) { + if (id == SPA_ID_PARAM_Props) { struct props *p = &this->props; if (param == NULL) { @@ -166,9 +170,9 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } spa_pod_object_parse(param, - ":", t->prop_device, "?S", p->device, sizeof(p->device), - ":", t->prop_min_latency, "?i", &p->min_latency, - ":", t->prop_max_latency, "?i", &p->max_latency, NULL); + ":", SPA_PROP_device, "?S", p->device, sizeof(p->device), + ":", SPA_PROP_minLatency, "?i", &p->min_latency, + ":", SPA_PROP_maxLatency, "?i", &p->max_latency, NULL); } else return -ENOENT; @@ -186,7 +190,8 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this = SPA_CONTAINER_OF(node, struct state, node); - if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) { + switch (SPA_COMMAND_TYPE(command)) { + case SPA_ID_COMMAND_NODE_Start: if (!this->have_format) return -EIO; if (this->n_buffers == 0) @@ -194,12 +199,14 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman if ((res = spa_alsa_start(this, false)) < 0) return res; - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + case SPA_ID_COMMAND_NODE_Pause: if ((res = spa_alsa_pause(this, false)) < 0) return res; - } else + break; + default: return -ENOTSUP; - + } return 0; } @@ -295,7 +302,6 @@ impl_node_port_enum_params(struct spa_node *node, { struct state *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -305,115 +311,110 @@ impl_node_port_enum_params(struct spa_node *node, spa_return_val_if_fail(builder != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); 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.idClock, }; + 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: return spa_alsa_enum_format(this, index, filter, result, builder); - } - else if (id == t->param.idFormat) { + + case SPA_ID_PARAM_Format: if (!this->have_format) return -EIO; if (*index > 0) return 0; param = spa_pod_builder_object(&b, - t->param.idFormat, t->format, - "I", t->media_type.audio, - "I", t->media_subtype.raw, - ":", t->format_audio.format, "I", this->current_format.info.raw.format, - ":", t->format_audio.layout, "i", this->current_format.info.raw.layout, - ":", t->format_audio.rate, "i", this->current_format.info.raw.rate, - ":", t->format_audio.channels, "i", this->current_format.info.raw.channels); - } - else if (id == t->param.idBuffers) { + id, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", this->current_format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); + break; + + case SPA_ID_PARAM_Buffers: if (!this->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", this->props.max_latency * - this->frame_size, + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "ir", 1, + SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), + ":", SPA_PARAM_BUFFERS_blocks, "i", 1, + ":", SPA_PARAM_BUFFERS_size, "iru", + this->props.max_latency * this->frame_size, SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size, INT32_MAX), - ":", t->param_buffers.stride, "i", 0, - ":", t->param_buffers.buffers, "ir", 1, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", t->param_buffers.align, "i", 16); - } - else if (id == t->param.idMeta) { + ":", SPA_PARAM_BUFFERS_stride, "i", 0, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; + + case SPA_ID_PARAM_Meta: if (!this->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; - } - } - else if (id == t->param_io.idClock) { - switch (*index) { - case 0: + case 2: param = spa_pod_builder_object(&b, - id, t->param_io.Clock, - ":", t->param_io.id, "I", t->io.Clock, - ":", t->param_io.size, "i", sizeof(struct spa_io_clock)); + id, SPA_ID_OBJECT_ParamIO, + ":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Clock, + ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock)); break; default: return 0; } - } - else + break; + + default: return -ENOENT; + } (*index)++; @@ -454,11 +455,11 @@ static int port_set_format(struct spa_node *node, "I", &info.media_subtype)) < 0) return err; - if (info.media_type != this->type.media_type.audio || - info.media_subtype != this->type.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, &this->type.format_audio) < 0) + if (spa_format_audio_raw_parse(format, &info.info.raw) < 0) return -EINVAL; if ((err = spa_alsa_set_format(this, &info, flags)) < 0) @@ -481,17 +482,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct state *this; - struct type *t; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; + spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); - 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 @@ -531,12 +526,12 @@ impl_node_port_use_buffers(struct spa_node *node, b->buf = buffers[i]; b->flags = BUFFER_FLAG_OUT; - b->h = spa_buffer_find_meta_data(b->buf, this->type.meta.Header, sizeof(*b->h)); + b->h = spa_buffer_find_meta_data(b->buf, SPA_META_Header, sizeof(*b->h)); type = d[0].type; - if ((type == this->type.data.MemFd || - type == this->type.data.DmaBuf || - type == this->type.data.MemPtr) && d[0].data == NULL) { + if ((type == SPA_DATA_MemFd || + type == SPA_DATA_DmaBuf || + type == SPA_DATA_MemPtr) && d[0].data == NULL) { spa_log_error(this->log, NAME " %p: need mapped memory", this); return -EINVAL; } @@ -580,24 +575,26 @@ impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { struct state *this; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); - if (id == t->io.Buffers) + switch (id) { + case SPA_ID_IO_Buffers: this->io = data; - else if (id == t->io.ControlRange) + break; + case SPA_ID_IO_ControlRange: this->range = data; - else if (id == t->io.Clock) + break; + case SPA_ID_IO_Clock: this->clock = data; - else + break; + default: return -ENOENT; - + } return 0; } @@ -692,7 +689,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, this = (struct state *) handle; - if (interface_id == this->type.node) + if (interface_id == SPA_ID_INTERFACE_Node) *interface = &this->node; else return -ENOENT; @@ -726,21 +723,14 @@ impl_init(const struct spa_handle_factory *factory, handle->clear = impl_clear; this = (struct state *) 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) this->data_loop = support[i].data; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_MainLoop) this->main_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } if (this->data_loop == NULL) { spa_log_error(this->log, "a data loop is needed"); return -EINVAL; @@ -749,7 +739,6 @@ impl_init(const struct spa_handle_factory *factory, spa_log_error(this->log, "a main loop is needed"); return -EINVAL; } - init_type(&this->type, this->map); this->node = impl_node; this->stream = SND_PCM_STREAM_PLAYBACK; @@ -772,7 +761,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 diff --git a/spa/plugins/alsa/alsa-source.c b/spa/plugins/alsa/alsa-source.c index 4ca8ab68c..9148873f2 100644 --- a/spa/plugins/alsa/alsa-source.c +++ b/spa/plugins/alsa/alsa-source.c @@ -50,7 +50,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct state *this; - struct type *t; struct spa_pod *param; uint8_t buffer[1024]; struct spa_pod_builder b = { 0 }; @@ -62,82 +61,87 @@ static int impl_node_enum_params(struct spa_node *node, spa_return_val_if_fail(builder != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; p = &this->props; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idPropInfo, - t->param.idProps }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + SPA_ID_PARAM_Props, }; 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.idPropInfo) { + case SPA_ID_PARAM_PropInfo: switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_device, - ":", t->param.propName, "s", "The ALSA device", - ":", t->param.propType, "S", p->device, sizeof(p->device)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_device, + ":", SPA_PROP_INFO_name, "s", "The ALSA device", + ":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device)); break; case 1: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_device_name, - ":", t->param.propName, "s", "The ALSA device name", - ":", t->param.propType, "S-r", p->device_name, sizeof(p->device_name)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName, + ":", SPA_PROP_INFO_name, "s", "The ALSA device name", + ":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name)); break; case 2: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_card_name, - ":", t->param.propName, "s", "The ALSA card name", - ":", t->param.propType, "S-r", p->card_name, sizeof(p->card_name)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_cardName, + ":", SPA_PROP_INFO_name, "s", "The ALSA card name", + ":", SPA_PROP_INFO_type, "S-r", p->card_name, sizeof(p->card_name)); break; case 3: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_min_latency, - ":", t->param.propName, "s", "The minimum latency", - ":", t->param.propType, "ir", p->min_latency, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency, + ":", SPA_PROP_INFO_name, "s", "The minimum latency", + ":", SPA_PROP_INFO_type, "ir", p->min_latency, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; case 4: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_max_latency, - ":", t->param.propName, "s", "The maximum latency", - ":", t->param.propType, "ir", p->max_latency, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency, + ":", SPA_PROP_INFO_name, "s", "The maximum latency", + ":", SPA_PROP_INFO_type, "ir", p->max_latency, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; default: return 0; } - } - else if (id == t->param.idProps) { + break; + + case SPA_ID_PARAM_Props: switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_device, "S", p->device, sizeof(p->device), - ":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name), - ":", t->prop_card_name, "S-r", p->card_name, sizeof(p->card_name), - ":", t->prop_min_latency, "i", p->min_latency, - ":", t->prop_max_latency, "i", p->max_latency); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "S", p->device, sizeof(p->device), + ":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name), + ":", SPA_PROP_cardName, "S-r", p->card_name, sizeof(p->card_name), + ":", SPA_PROP_minLatency, "i", p->min_latency, + ":", SPA_PROP_maxLatency, "i", p->max_latency); break; default: return 0; } - } - else + break; + + default: return -ENOENT; + } (*index)++; @@ -151,14 +155,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag const struct spa_pod *param) { struct state *this; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; - if (id == t->param.idProps) { + switch (id) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; if (param == NULL) { @@ -166,12 +170,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } spa_pod_object_parse(param, - ":", t->prop_device, "?S", p->device, sizeof(p->device), - ":", t->prop_min_latency, "?i", &p->min_latency, - ":", t->prop_max_latency, "?i", &p->max_latency, NULL); + ":", SPA_PROP_device, "?S", p->device, sizeof(p->device), + ":", SPA_PROP_minLatency, "?i", &p->min_latency, + ":", SPA_PROP_maxLatency, "?i", &p->max_latency, NULL); + break; } - else + default: return -ENOENT; + } return 0; } @@ -186,7 +192,8 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this = SPA_CONTAINER_OF(node, struct state, node); - if (SPA_COMMAND_TYPE(command) == this->type.command_node.Start) { + switch (SPA_COMMAND_TYPE(command)) { + case SPA_ID_COMMAND_NODE_Start: if (!this->have_format) return -EIO; if (this->n_buffers == 0) @@ -194,12 +201,14 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman if ((res = spa_alsa_start(this, false)) < 0) return res; - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + case SPA_ID_COMMAND_NODE_Pause: if ((res = spa_alsa_pause(this, false)) < 0) return res; - } else + break; + default: return -ENOTSUP; - + } return 0; } @@ -303,7 +312,6 @@ static int port_get_format(struct spa_node *node, struct spa_pod_builder *builder) { struct state *this = SPA_CONTAINER_OF(node, struct state, node); - struct type *t = &this->type; if (!this->have_format) return -EIO; @@ -311,13 +319,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->current_format.info.raw.format, - ":", t->format_audio.layout, "i", this->current_format.info.raw.layout, - ":", t->format_audio.rate, "i", this->current_format.info.raw.rate, - ":", t->format_audio.channels, "i", this->current_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->current_format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", this->current_format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); return 1; } @@ -331,7 +339,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct state *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -342,90 +349,92 @@ impl_node_port_enum_params(struct spa_node *node, spa_return_val_if_fail(builder != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); 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 }; + 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 }; 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: return spa_alsa_enum_format(this, index, filter, result, builder); - } - else if (id == t->param.idFormat) { + + case SPA_ID_PARAM_Format: if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + + case SPA_ID_PARAM_Buffers: if (!this->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", this->props.max_latency * + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, + SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), + ":", SPA_PARAM_BUFFERS_blocks, "i", 1, + ":", SPA_PARAM_BUFFERS_size, "iru", this->props.max_latency * this->frame_size, SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size, INT32_MAX), - ":", t->param_buffers.stride, "i", this->frame_size, - ":", t->param_buffers.buffers, "ir", 2, - SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", t->param_buffers.align, "i", 16); - } - else if (id == t->param.idMeta) { + ":", SPA_PARAM_BUFFERS_stride, "i", this->frame_size, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; + + case SPA_ID_PARAM_Meta: if (!this->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.idClock) { - switch (*index) { - case 0: + case 1: param = spa_pod_builder_object(&b, - id, t->param_io.Clock, - ":", t->param_io.id, "I", t->io.Clock, - ":", t->param_io.size, "i", sizeof(struct spa_io_clock)); + id, SPA_ID_OBJECT_ParamIO, + ":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Clock, + ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock)); break; default: return 0; } - } - else + break; + + default: return -ENOENT; + } (*index)++; @@ -464,11 +473,11 @@ static int port_set_format(struct spa_node *node, "I", &info.media_type, "I", &info.media_subtype); - if (info.media_type != this->type.media_type.audio || - info.media_subtype != this->type.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, &this->type.format_audio) < 0) + if (spa_format_audio_raw_parse(format, &info.info.raw) < 0) return -EINVAL; if ((err = spa_alsa_set_format(this, &info, flags)) < 0) @@ -491,17 +500,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct state *this; - struct type *t; - spa_return_val_if_fail(node != NULL, -EINVAL); - this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; + spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); - 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 @@ -538,11 +541,11 @@ impl_node_port_use_buffers(struct spa_node *node, b->buf = buffers[i]; b->flags = 0; - b->h = spa_buffer_find_meta_data(b->buf, this->type.meta.Header, sizeof(*b->h)); + b->h = spa_buffer_find_meta_data(b->buf, SPA_META_Header, sizeof(*b->h)); - if (!((d[0].type == this->type.data.MemFd || - d[0].type == this->type.data.DmaBuf || - d[0].type == this->type.data.MemPtr) && d[0].data != NULL)) { + if (!((d[0].type == SPA_DATA_MemFd || + d[0].type == SPA_DATA_DmaBuf || + d[0].type == SPA_DATA_MemPtr) && d[0].data != NULL)) { spa_log_error(this->log, NAME " %p: need mapped memory", this); return -EINVAL; } @@ -589,18 +592,16 @@ impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { struct state *this; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct state, node); - t = &this->type; spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL); - if (id == t->io.Buffers) + if (id == SPA_ID_IO_Buffers) this->io = data; - else if (id == t->io.Clock) + else if (id == SPA_ID_IO_Clock) this->clock = data; else return -ENOENT; @@ -712,7 +713,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, this = (struct state *) handle; - if (interface_id == this->type.node) + if (interface_id == SPA_ID_INTERFACE_Node) *interface = &this->node; else return -ENOENT; @@ -751,19 +752,13 @@ impl_init(const struct spa_handle_factory *factory, this = (struct state *) 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) this->data_loop = support[i].data; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_MainLoop) this->main_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "an id-map is needed"); - return -EINVAL; - } if (this->data_loop == NULL) { spa_log_error(this->log, "a data loop is needed"); return -EINVAL; @@ -772,7 +767,6 @@ impl_init(const struct spa_handle_factory *factory, spa_log_error(this->log, "a main loop is needed"); return -EINVAL; } - init_type(&this->type, this->map); this->node = impl_node; this->stream = SND_PCM_STREAM_CAPTURE; @@ -795,7 +789,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 diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index b1f1205b3..45710ebb5 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -57,51 +57,42 @@ int spa_alsa_close(struct state *state) } struct format_info { - off_t format_offset; + uint32_t spa_format; snd_pcm_format_t format; }; -#if __BYTE_ORDER == __BIG_ENDIAN -#define _FORMAT_LE(fmt) offsetof(struct type, audio_format. fmt ## _OE) -#define _FORMAT_BE(fmt) offsetof(struct type, audio_format. fmt) -#elif __BYTE_ORDER == __LITTLE_ENDIAN -#define _FORMAT_LE(fmt) offsetof(struct type, audio_format. fmt) -#define _FORMAT_BE(fmt) offsetof(struct type, audio_format. fmt ## _OE) -#endif - static const struct format_info format_info[] = { - {offsetof(struct type, audio_format.UNKNOWN), SND_PCM_FORMAT_UNKNOWN}, - {offsetof(struct type, audio_format.S8), SND_PCM_FORMAT_S8}, - {offsetof(struct type, audio_format.U8), SND_PCM_FORMAT_U8}, - {_FORMAT_LE(S16), SND_PCM_FORMAT_S16_LE}, - {_FORMAT_BE(S16), SND_PCM_FORMAT_S16_BE}, - {_FORMAT_LE(U16), SND_PCM_FORMAT_U16_LE}, - {_FORMAT_BE(U16), SND_PCM_FORMAT_U16_BE}, - {_FORMAT_LE(S24_32), SND_PCM_FORMAT_S24_LE}, - {_FORMAT_BE(S24_32), SND_PCM_FORMAT_S24_BE}, - {_FORMAT_LE(U24_32), SND_PCM_FORMAT_U24_LE}, - {_FORMAT_BE(U24_32), SND_PCM_FORMAT_U24_BE}, - {_FORMAT_LE(S24), SND_PCM_FORMAT_S24_3LE}, - {_FORMAT_BE(S24), SND_PCM_FORMAT_S24_3BE}, - {_FORMAT_LE(U24), SND_PCM_FORMAT_U24_3LE}, - {_FORMAT_BE(U24), SND_PCM_FORMAT_U24_3BE}, - {_FORMAT_LE(S32), SND_PCM_FORMAT_S32_LE}, - {_FORMAT_BE(S32), SND_PCM_FORMAT_S32_BE}, - {_FORMAT_LE(U32), SND_PCM_FORMAT_U32_LE}, - {_FORMAT_BE(U32), SND_PCM_FORMAT_U32_BE}, - {_FORMAT_LE(F32), SND_PCM_FORMAT_FLOAT_LE}, - {_FORMAT_BE(F32), SND_PCM_FORMAT_FLOAT_BE}, - {_FORMAT_LE(F64), SND_PCM_FORMAT_FLOAT64_LE}, - {_FORMAT_BE(F64), SND_PCM_FORMAT_FLOAT64_BE}, + { SPA_AUDIO_FORMAT_UNKNOWN, SND_PCM_FORMAT_UNKNOWN}, + { SPA_AUDIO_FORMAT_S8, SND_PCM_FORMAT_S8}, + { SPA_AUDIO_FORMAT_U8, SND_PCM_FORMAT_U8}, + { SPA_AUDIO_FORMAT_S16_LE, SND_PCM_FORMAT_S16_LE}, + { SPA_AUDIO_FORMAT_S16_BE, SND_PCM_FORMAT_S16_BE}, + { SPA_AUDIO_FORMAT_U16_LE, SND_PCM_FORMAT_U16_LE}, + { SPA_AUDIO_FORMAT_U16_BE, SND_PCM_FORMAT_U16_BE}, + { SPA_AUDIO_FORMAT_S24_32_LE, SND_PCM_FORMAT_S24_LE}, + { SPA_AUDIO_FORMAT_S24_32_BE, SND_PCM_FORMAT_S24_BE}, + { SPA_AUDIO_FORMAT_U24_32_LE, SND_PCM_FORMAT_U24_LE}, + { SPA_AUDIO_FORMAT_U24_32_BE, SND_PCM_FORMAT_U24_BE}, + { SPA_AUDIO_FORMAT_S24_LE, SND_PCM_FORMAT_S24_3LE}, + { SPA_AUDIO_FORMAT_S24_BE, SND_PCM_FORMAT_S24_3BE}, + { SPA_AUDIO_FORMAT_U24_LE, SND_PCM_FORMAT_U24_3LE}, + { SPA_AUDIO_FORMAT_U24_BE, SND_PCM_FORMAT_U24_3BE}, + { SPA_AUDIO_FORMAT_S32_LE, SND_PCM_FORMAT_S32_LE}, + { SPA_AUDIO_FORMAT_S32_BE, SND_PCM_FORMAT_S32_BE}, + { SPA_AUDIO_FORMAT_U32_LE, SND_PCM_FORMAT_U32_LE}, + { SPA_AUDIO_FORMAT_U32_BE, SND_PCM_FORMAT_U32_BE}, + { SPA_AUDIO_FORMAT_F32_LE, SND_PCM_FORMAT_FLOAT_LE}, + { SPA_AUDIO_FORMAT_F32_BE, SND_PCM_FORMAT_FLOAT_BE}, + { SPA_AUDIO_FORMAT_F64_LE, SND_PCM_FORMAT_FLOAT64_LE}, + { SPA_AUDIO_FORMAT_F64_BE, SND_PCM_FORMAT_FLOAT64_BE}, }; -static snd_pcm_format_t spa_alsa_format_to_alsa(struct type *map, uint32_t format) +static snd_pcm_format_t spa_format_to_alsa(uint32_t format) { int i; for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) { - uint32_t f = *SPA_MEMBER(map, format_info[i].format_offset, uint32_t); - if (f == format) + if (format_info[i].spa_format == format) return format_info[i].format; } return SND_PCM_FORMAT_UNKNOWN; @@ -142,26 +133,25 @@ spa_alsa_enum_format(struct state *state, uint32_t *index, snd_pcm_hw_params_alloca(¶ms); CHECK(snd_pcm_hw_params_any(hndl, params), "Broken configuration: no configurations available"); - spa_pod_builder_push_object(&b, state->type.param.idEnumFormat, state->type.format); + spa_pod_builder_push_object(&b, SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format); spa_pod_builder_add(&b, - "I", state->type.media_type.audio, - "I", state->type.media_subtype.raw, 0); + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, 0); snd_pcm_format_mask_alloca(&fmask); snd_pcm_hw_params_get_format_mask(params, fmask); prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, state->type.format_audio.format, + spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_format, SPA_POD_PROP_RANGE_NONE)); for (i = 1, j = 0; i < SPA_N_ELEMENTS(format_info); i++) { const struct format_info *fi = &format_info[i]; if (snd_pcm_format_mask_test(fmask, fi->format)) { - uint32_t f = *SPA_MEMBER(&state->type, fi->format_offset, uint32_t); if (j++ == 0) - spa_pod_builder_id(&b, f); - spa_pod_builder_id(&b, f); + spa_pod_builder_id(&b, fi->spa_format); + spa_pod_builder_id(&b, fi->spa_format); } } if (j > 1) @@ -172,7 +162,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index, snd_pcm_hw_params_get_access_mask(params, amask); prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, state->type.format_audio.layout, + spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_layout, SPA_POD_PROP_RANGE_NONE)); j = 0; if (snd_pcm_access_mask_test(amask, SND_PCM_ACCESS_MMAP_INTERLEAVED)) { @@ -193,7 +183,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index, CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max"); prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, state->type.format_audio.rate, SPA_POD_PROP_RANGE_NONE)); + spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_rate, SPA_POD_PROP_RANGE_NONE)); spa_pod_builder_int(&b, SPA_CLAMP(DEFAULT_RATE, min, max)); if (min != max) { @@ -207,7 +197,7 @@ spa_alsa_enum_format(struct state *state, uint32_t *index, CHECK(snd_pcm_hw_params_get_channels_max(params, &max), "get_channels_max"); prop = spa_pod_builder_deref(&b, - spa_pod_builder_push_prop(&b, state->type.format_audio.channels, SPA_POD_PROP_RANGE_NONE)); + spa_pod_builder_push_prop(&b, SPA_FORMAT_AUDIO_channels, SPA_POD_PROP_RANGE_NONE)); spa_pod_builder_int(&b, SPA_CLAMP(DEFAULT_CHANNELS, min, max)); if (min != max) { @@ -261,7 +251,7 @@ int spa_alsa_set_format(struct state *state, struct spa_audio_info *fmt, uint32_ CHECK(snd_pcm_hw_params_set_period_wakeup(hndl, params, 0), "set_period_wakeup"); /* set the sample format */ - format = spa_alsa_format_to_alsa(&state->type, info->format); + format = spa_format_to_alsa(info->format); if (format == SND_PCM_FORMAT_UNKNOWN) return -EINVAL; diff --git a/spa/plugins/alsa/alsa-utils.h b/spa/plugins/alsa/alsa-utils.h index 97cc92d75..009d4c999 100644 --- a/spa/plugins/alsa/alsa-utils.h +++ b/spa/plugins/alsa/alsa-utils.h @@ -28,7 +28,6 @@ extern "C" { #include -#include #include #include #include @@ -61,66 +60,12 @@ struct buffer { struct spa_list link; }; -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_device; - uint32_t prop_device_name; - uint32_t prop_card_name; - uint32_t prop_min_latency; - uint32_t prop_max_latency; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - struct spa_type_media_type media_type; - struct spa_type_media_subtype media_subtype; - struct spa_type_media_subtype_audio media_subtype_audio; - struct spa_type_audio_format audio_format; - struct spa_type_event_node event_node; - struct spa_type_command_node command_node; - struct spa_type_format_audio format_audio; - 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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->prop_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->prop_device_name = spa_type_map_get_id(map, SPA_TYPE_PROPS__deviceName); - type->prop_card_name = spa_type_map_get_id(map, SPA_TYPE_PROPS__cardName); - type->prop_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->prop_max_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__maxLatency); - - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - spa_type_media_type_map(map, &type->media_type); - spa_type_media_subtype_map(map, &type->media_subtype); - spa_type_media_subtype_audio_map(map, &type->media_subtype_audio); - spa_type_audio_format_map(map, &type->audio_format); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_format_audio_map(map, &type->format_audio); - 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 state { struct spa_handle handle; struct spa_node node; uint32_t seq; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *main_loop; struct spa_loop *data_loop; diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c index 77867d624..de57ffbb1 100644 --- a/spa/plugins/audioconvert/audioconvert.c +++ b/spa/plugins/audioconvert/audioconvert.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -33,58 +32,13 @@ #include #include #include +#include #define NAME "audioconvert" #define PROP_DEFAULT_TRUNCATE false #define PROP_DEFAULT_DITHER 0 -struct type { - uint32_t node; - uint32_t format; - uint32_t prop_truncate; - uint32_t prop_dither; - - uint32_t prop_volume; - uint32_t io_prop_volume; - - 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_truncate = spa_type_map_get_id(map, SPA_TYPE_PROPS__truncate); - type->prop_dither = spa_type_map_get_id(map, SPA_TYPE_PROPS__ditherType); - - 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_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 props { bool truncate; uint32_t dither; @@ -125,8 +79,6 @@ struct impl { struct spa_handle handle; struct spa_node node; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct props props; @@ -157,7 +109,6 @@ static int make_link(struct impl *this, struct spa_audio_info *info) { struct link *l = &this->links[this->n_links++]; - struct type *t = &this->type; l->out_node = out_node; l->out_port = out_port; @@ -173,28 +124,26 @@ static int make_link(struct impl *this, &l->out_info); spa_node_port_set_io(out_node, SPA_DIRECTION_OUTPUT, out_port, - t->io.Buffers, + SPA_ID_IO_Buffers, &l->io, sizeof(l->io)); spa_node_port_get_info(in_node, SPA_DIRECTION_INPUT, in_port, &l->in_info); spa_node_port_set_io(in_node, SPA_DIRECTION_INPUT, in_port, - t->io.Buffers, + SPA_ID_IO_Buffers, &l->io, sizeof(l->io)); return 0; } static void clean_link(struct impl *this, struct link *link) { - struct type *t = &this->type; - spa_node_port_set_param(link->in_node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idFormat, 0, NULL); + SPA_ID_PARAM_Format, 0, NULL); spa_node_port_set_param(link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idFormat, 0, NULL); + SPA_ID_PARAM_Format, 0, NULL); if (link->buffers) free(link->buffers); link->buffers = NULL; @@ -221,19 +170,18 @@ static int debug_params(struct impl *this, struct spa_node *node, if (res <= 0) break; - spa_debug_pod(2, this->map, param); + spa_debug_pod(2, spa_debug_types, param); } spa_log_error(this->log, "failed filter:"); if (filter) - spa_debug_pod(2, this->map, filter); + spa_debug_pod(2, spa_debug_types, filter); return 0; } static int negotiate_link_format(struct impl *this, struct link *link) { - struct type *t = &this->type; struct spa_pod_builder b = { 0 }; uint8_t buffer[4096]; uint32_t state; @@ -249,20 +197,20 @@ static int negotiate_link_format(struct impl *this, struct link *link) filter = NULL; if ((res = spa_node_port_enum_params(link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) { debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idEnumFormat, filter); + SPA_ID_PARAM_EnumFormat, filter); return -ENOTSUP; } filter = format; state = 0; if ((res = spa_node_port_enum_params(link->in_node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) { debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idEnumFormat, filter); + SPA_ID_PARAM_EnumFormat, filter); return -ENOTSUP; } filter = format; @@ -271,13 +219,13 @@ static int negotiate_link_format(struct impl *this, struct link *link) if ((res = spa_node_port_set_param(link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idFormat, 0, + SPA_ID_PARAM_Format, 0, filter)) < 0) return res; if ((res = spa_node_port_set_param(link->in_node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idFormat, 0, + SPA_ID_PARAM_Format, 0, filter)) < 0) return res; @@ -317,7 +265,6 @@ static int setup_convert(struct impl *this) static int negotiate_link_buffers(struct impl *this, struct link *link) { - struct type *t = &this->type; uint8_t buffer[4096]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); uint32_t state; @@ -334,19 +281,19 @@ static int negotiate_link_buffers(struct impl *this, struct link *link) state = 0; if ((res = spa_node_port_enum_params(link->in_node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idBuffers, &state, + SPA_ID_PARAM_Buffers, &state, param, ¶m, &b)) <= 0) { debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idBuffers, param); + SPA_ID_PARAM_Buffers, param); return -ENOTSUP; } state = 0; if ((res = spa_node_port_enum_params(link->out_node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idBuffers, &state, + SPA_ID_PARAM_Buffers, &state, param, ¶m, &b)) <= 0) { debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idBuffers, param); + SPA_ID_PARAM_Buffers, param); return -ENOTSUP; } @@ -372,10 +319,10 @@ static int negotiate_link_buffers(struct impl *this, struct link *link) } 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; @@ -386,7 +333,7 @@ static int negotiate_link_buffers(struct impl *this, struct link *link) 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; } @@ -484,16 +431,19 @@ 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: if ((res = setup_convert(this)) < 0) goto error; setup_buffers(this, SPA_DIRECTION_INPUT); 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; error: @@ -607,25 +557,22 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct impl, node); - t = &this->type; - if (id == t->param_io.idPropsIn) { + switch (id) { next: + case SPA_ID_PARAM_PropInfo: spa_pod_builder_init(&b, buffer, sizeof(buffer)); switch (*index) { case 0: param = spa_pod_builder_object(builder, - id, t->param_io.Prop, - ":", t->param_io.id, "I", this->type.io_prop_volume, - ":", t->param_io.size, "i", sizeof(struct spa_pod_float), - ":", t->param.propId, "I", this->type.prop_volume, - ":", t->param.propType, "fru", 1.0, + id, SPA_ID_PARAM_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_volume, + ":", SPA_PROP_INFO_type, "fru", 1.0, SPA_POD_PROP_MIN_MAX(0.0, 10.0)); break; default: @@ -638,10 +585,10 @@ impl_node_port_enum_params(struct spa_node *node, goto next; return 1; - } - else + default: return spa_node_port_enum_params(this->fmt[direction], direction, port_id, id, index, filter, result, builder); + } } static int @@ -700,20 +647,18 @@ impl_node_port_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) { struct impl *this; - struct type *t; int res; spa_return_val_if_fail(node != NULL, -EINVAL); this = SPA_CONTAINER_OF(node, struct impl, node); - t = &this->type; spa_log_debug(this->log, "set io %d %d %d", id, direction, port_id); - if (id == t->io.ControlRange) + if (id == SPA_ID_IO_ControlRange) res = spa_node_port_set_io(this->resample, direction, 0, id, data, size); - else if (id == t->io_prop_volume) - res = spa_node_port_set_io(this->channelmix, direction, 0, id, data, size); +// else if (id == t->io_prop_volume) +// res = spa_node_port_set_io(this->channelmix, direction, 0, id, data, size); else res = spa_node_port_set_io(this->fmt[direction], direction, port_id, id, data, size); @@ -818,7 +763,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; @@ -877,17 +822,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; this->hnd_fmt[SPA_DIRECTION_INPUT] = SPA_MEMBER(this, sizeof(struct impl), struct spa_handle); @@ -914,13 +851,13 @@ impl_init(const struct spa_handle_factory *factory, info, support, n_support); size = spa_handle_factory_get_size(&spa_resample_factory, info); - spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_INPUT], this->type.node, &iface); + spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_INPUT], SPA_ID_INTERFACE_Node, &iface); this->fmt[SPA_DIRECTION_INPUT] = iface; - spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_OUTPUT], this->type.node, &iface); + spa_handle_get_interface(this->hnd_fmt[SPA_DIRECTION_OUTPUT], SPA_ID_INTERFACE_Node, &iface); this->fmt[SPA_DIRECTION_OUTPUT] = iface; - spa_handle_get_interface(this->hnd_channelmix, this->type.node, &iface); + spa_handle_get_interface(this->hnd_channelmix, SPA_ID_INTERFACE_Node, &iface); this->channelmix = iface; - spa_handle_get_interface(this->hnd_resample, this->type.node, &iface); + spa_handle_get_interface(this->hnd_resample, SPA_ID_INTERFACE_Node, &iface); this->resample = iface; props_reset(&this->props); @@ -929,7 +866,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 diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index 2682e5ef3..c38f770b8 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -84,58 +83,12 @@ struct port { struct spa_list queue; }; -struct type { - uint32_t node; - uint32_t format; - - uint32_t prop_volume; - uint32_t io_prop_volume; - - 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->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume"); - - 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); -} - - #include "channelmix-ops.c" struct impl { struct spa_handle handle; struct spa_node node; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct props props; @@ -245,13 +198,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; } @@ -350,7 +306,6 @@ 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; struct port *other; other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0); @@ -359,24 +314,24 @@ static int port_enum_formats(struct spa_node *node, case 0: if (other->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", t->audio_format.F32, - ":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", t->format_audio.rate, "i", other->format.info.raw.rate, - ":", t->format_audio.channels, "iru", 2, + 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, "i", other->format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "iru", 2, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); } 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", 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_NON_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "iru", DEFAULT_CHANNELS, + ":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); } break; @@ -393,7 +348,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) @@ -402,13 +356,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", port->format.info.raw.format, - ":", t->format_audio.layout, "i", port->format.info.raw.layout, - ":", t->format_audio.rate, "i", port->format.info.raw.rate, - ":", t->format_audio.channels, "i", port->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", port->format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); return 1; } @@ -422,7 +376,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct port *port, *other; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -434,7 +387,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); @@ -444,28 +396,34 @@ 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 }; + 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, ¶m, &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, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + + case SPA_ID_PARAM_Buffers: + { uint32_t buffers, size; if (!port->have_format) @@ -482,44 +440,47 @@ impl_node_port_enum_params(struct spa_node *node, } param = spa_pod_builder_object(&b, - id, t->param_buffers.Buffers, - ":", t->param_buffers.buffers, "iru", buffers, + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "iru", buffers, SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", t->param_buffers.blocks, "i", port->blocks, - ":", t->param_buffers.size, "iru", size * port->stride, + ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, + ":", SPA_PARAM_BUFFERS_size, "iru", size * port->stride, SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride), - ":", t->param_buffers.stride, "i", port->stride, - ":", t->param_buffers.align, "i", 16); + ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; } - else if (id == t->param.idMeta) { + 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 + break; + default: return -ENOENT; + } (*index)++; @@ -547,7 +508,6 @@ static int port_set_format(struct spa_node *node, { struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); struct port *port, *other; - struct type *t = &this->type; int res = 0; port = GET_PORT(this, direction, port_id); @@ -566,14 +526,14 @@ 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 (info.info.raw.format != t->audio_format.F32) + if (info.info.raw.format != SPA_AUDIO_FORMAT_F32) return -EINVAL; if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED) return -EINVAL; @@ -599,17 +559,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -626,12 +580,10 @@ impl_node_port_use_buffers(struct spa_node *node, struct impl *this; struct port *port; uint32_t i, size = SPA_ID_INVALID; - 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); @@ -650,7 +602,7 @@ impl_node_port_use_buffers(struct spa_node *node, b = &port->buffers[i]; b->flags = 0; b->outbuf = buffers[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 (size == SPA_ID_INVALID) size = d[0].maxsize; @@ -658,9 +610,9 @@ impl_node_port_use_buffers(struct spa_node *node, if (size != d[0].maxsize) return -EINVAL; - 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; @@ -695,21 +647,19 @@ 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_prop_volume) - port->control.volume = data; +// else if (id == t->io_prop_volume) +// port->control.volume = data; else return -ENOENT; @@ -879,7 +829,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; @@ -919,16 +869,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; @@ -948,7 +891,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 diff --git a/spa/plugins/audioconvert/fmt-ops.c b/spa/plugins/audioconvert/fmt-ops.c index 839a495ec..8416e9742 100644 --- a/spa/plugins/audioconvert/fmt-ops.c +++ b/spa/plugins/audioconvert/fmt-ops.c @@ -670,8 +670,8 @@ typedef void (*convert_func_t) (void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_bytes); static const struct conv_info { - off_t src_fmt; - off_t dst_fmt; + uint32_t src_fmt; + uint32_t dst_fmt; #define FEATURE_SSE (1<<0) uint32_t features; @@ -681,86 +681,67 @@ static const struct conv_info { } conv_table[] = { /* to f32 */ - { offsetof(struct spa_type_audio_format, U8), - offsetof(struct spa_type_audio_format, F32), 0, + { SPA_AUDIO_FORMAT_U8, SPA_AUDIO_FORMAT_F32, 0, conv_u8_to_f32, conv_u8_to_f32d, conv_u8d_to_f32 }, #if defined (__SSE2__) - { offsetof(struct spa_type_audio_format, S16), - offsetof(struct spa_type_audio_format, F32), FEATURE_SSE, + { SPA_AUDIO_FORMAT_S16, SPA_AUDIO_FORMAT_F32, FEATURE_SSE, conv_s16_to_f32, conv_s16_to_f32d_sse, conv_s16d_to_f32 }, #endif - { offsetof(struct spa_type_audio_format, S16), - offsetof(struct spa_type_audio_format, F32), 0, + { SPA_AUDIO_FORMAT_S16, SPA_AUDIO_FORMAT_F32, 0, conv_s16_to_f32, conv_s16_to_f32d, conv_s16d_to_f32 }, - { offsetof(struct spa_type_audio_format, F32), - offsetof(struct spa_type_audio_format, F32), 0, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_F32, 0, conv_copy, deinterleave_32, interleave_32 }, - { offsetof(struct spa_type_audio_format, S32), - offsetof(struct spa_type_audio_format, F32), 0, + { SPA_AUDIO_FORMAT_S32, SPA_AUDIO_FORMAT_F32, 0, conv_s32_to_f32, conv_s32_to_f32d, conv_s32d_to_f32 }, - { offsetof(struct spa_type_audio_format, S24), - offsetof(struct spa_type_audio_format, F32), 0, + { SPA_AUDIO_FORMAT_S24, SPA_AUDIO_FORMAT_F32, 0, conv_s24_to_f32, conv_s24_to_f32d, conv_s24d_to_f32 }, - { offsetof(struct spa_type_audio_format, S24_32), - offsetof(struct spa_type_audio_format, F32), 0, + { SPA_AUDIO_FORMAT_S24_32, SPA_AUDIO_FORMAT_F32, 0, conv_s24_32_to_f32, conv_s24_32_to_f32d, conv_s24_32d_to_f32 }, /* from f32 */ - { offsetof(struct spa_type_audio_format, F32), - offsetof(struct spa_type_audio_format, U8), 0, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_U8, 0, conv_f32_to_u8, conv_f32_to_u8d, conv_f32d_to_u8 }, - { offsetof(struct spa_type_audio_format, F32), - offsetof(struct spa_type_audio_format, S16), 0, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S16, 0, conv_f32_to_s16, conv_f32_to_s16d, conv_f32d_to_s16 }, #if defined (__SSE2__) - { offsetof(struct spa_type_audio_format, F32), - offsetof(struct spa_type_audio_format, S32), FEATURE_SSE, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S32, FEATURE_SSE, conv_f32_to_s32, conv_f32_to_s32d, conv_f32d_to_s32_sse }, #endif - { offsetof(struct spa_type_audio_format, F32), - offsetof(struct spa_type_audio_format, S32), 0, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S32, 0, conv_f32_to_s32, conv_f32_to_s32d, conv_f32d_to_s32 }, - { offsetof(struct spa_type_audio_format, F32), - offsetof(struct spa_type_audio_format, S24), 0, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S24, 0, conv_f32_to_s24, conv_f32_to_s24d, conv_f32d_to_s24 }, - { offsetof(struct spa_type_audio_format, F32), - offsetof(struct spa_type_audio_format, S24_32), 0, + { SPA_AUDIO_FORMAT_F32, SPA_AUDIO_FORMAT_S24_32, 0, conv_f32_to_s24_32, conv_f32_to_s24_32d, conv_f32d_to_s24_32 }, /* u8 */ - { offsetof(struct spa_type_audio_format, U8), - offsetof(struct spa_type_audio_format, U8), 0, + { SPA_AUDIO_FORMAT_U8, SPA_AUDIO_FORMAT_U8, 0, conv_copy, deinterleave_8, interleave_8 }, /* s16 */ - { offsetof(struct spa_type_audio_format, S16), - offsetof(struct spa_type_audio_format, S16), 0, + { SPA_AUDIO_FORMAT_S16, SPA_AUDIO_FORMAT_S16, 0, conv_copy, deinterleave_16, interleave_16 }, /* s32 */ - { offsetof(struct spa_type_audio_format, S32), - offsetof(struct spa_type_audio_format, S32), 0, + { SPA_AUDIO_FORMAT_S32, SPA_AUDIO_FORMAT_S32, 0, conv_copy, deinterleave_32, interleave_32 }, /* s24 */ - { offsetof(struct spa_type_audio_format, S24), - offsetof(struct spa_type_audio_format, S24), 0, + { SPA_AUDIO_FORMAT_S24, SPA_AUDIO_FORMAT_S24, 0, conv_copy, deinterleave_24, interleave_24 }, /* s24_32 */ - { offsetof(struct spa_type_audio_format, S24_32), - offsetof(struct spa_type_audio_format, S24_32), 0, + { SPA_AUDIO_FORMAT_S24_32, SPA_AUDIO_FORMAT_S24_32, 0, conv_copy, deinterleave_32, interleave_32 }, }; -static const struct conv_info *find_conv_info(struct spa_type_audio_format *audio_format, - uint32_t src_fmt, uint32_t dst_fmt, uint32_t features) +static const struct conv_info *find_conv_info(uint32_t src_fmt, uint32_t dst_fmt, uint32_t features) { int i; for (i = 0; i < SPA_N_ELEMENTS(conv_table); i++) { - if (*SPA_MEMBER(audio_format, conv_table[i].src_fmt, uint32_t) == src_fmt && - *SPA_MEMBER(audio_format, conv_table[i].dst_fmt, uint32_t) == dst_fmt && + if (conv_table[i].src_fmt == src_fmt && + conv_table[i].dst_fmt == dst_fmt && (conv_table[i].features == 0 || (conv_table[i].features & features) != 0)) return &conv_table[i]; } diff --git a/spa/plugins/audioconvert/fmtconvert.c b/spa/plugins/audioconvert/fmtconvert.c index e62c54a2d..be5412e9a 100644 --- a/spa/plugins/audioconvert/fmtconvert.c +++ b/spa/plugins/audioconvert/fmtconvert.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include #define NAME "fmtconvert" @@ -96,54 +96,12 @@ struct port { struct spa_list queue; }; -struct type { - uint32_t node; - uint32_t format; - uint32_t prop_truncate; - uint32_t prop_dither; - 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_truncate = spa_type_map_get_id(map, SPA_TYPE_PROPS__truncate); - type->prop_dither = spa_type_map_get_id(map, SPA_TYPE_PROPS__ditherType); - 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); -} - - #include "fmt-ops.c" struct impl { struct spa_handle handle; struct spa_node node; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct props props; @@ -193,7 +151,6 @@ static int collect_format(struct impl *this, enum spa_direction direction, struc static int setup_convert(struct impl *this) { uint32_t src_fmt, dst_fmt; - struct type *t = &this->type; struct format informat, outformat; const struct conv_info *conv; @@ -206,11 +163,11 @@ static int setup_convert(struct impl *this) dst_fmt = outformat.format.info.raw.format; spa_log_info(this->log, NAME " %p: %s/%d@%d.%d->%s/%d@%d.%d", this, - spa_type_map_get_type(this->map, src_fmt), + spa_debug_type_find_name(spa_debug_types, src_fmt), informat.format.info.raw.channels, informat.format.info.raw.rate, informat.format.info.raw.layout, - spa_type_map_get_type(this->map, dst_fmt), + spa_debug_type_find_name(spa_debug_types, dst_fmt), outformat.format.info.raw.channels, outformat.format.info.raw.rate, outformat.format.info.raw.layout); @@ -222,7 +179,7 @@ static int setup_convert(struct impl *this) return -EINVAL; /* find fast path */ - conv = find_conv_info(&t->audio_format, src_fmt, dst_fmt, FEATURE_SSE); + conv = find_conv_info(src_fmt, dst_fmt, FEATURE_SSE); if (conv != NULL) { spa_log_info(this->log, NAME " %p: got converter features %08x", this, conv->features); @@ -267,13 +224,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; } @@ -455,7 +415,6 @@ 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; struct spa_audio_info *other; other = &this->formats[SPA_DIRECTION_REVERSE(direction)].format; @@ -464,41 +423,41 @@ static int port_enum_formats(struct spa_node *node, case 0: if (other->info.raw.channels > 0) { *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, "Ieu", other->info.raw.format, + SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "Ieu", other->info.raw.format, SPA_POD_PROP_ENUM(3, other->info.raw.format, - t->audio_format.F32, - t->audio_format.F32_OE), - ":", t->format_audio.layout, "ieu", other->info.raw.layout, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE), + ":", SPA_FORMAT_AUDIO_layout, "ieu", other->info.raw.layout, SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", t->format_audio.rate, "i", other->info.raw.rate, - ":", t->format_audio.channels, "i", other->info.raw.channels); + ":", SPA_FORMAT_AUDIO_rate, "i", other->info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", other->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, "Ieu", t->audio_format.S16, - SPA_POD_PROP_ENUM(11, t->audio_format.U8, - t->audio_format.S16, - t->audio_format.S16_OE, - t->audio_format.F32, - t->audio_format.F32_OE, - t->audio_format.S32, - t->audio_format.S32_OE, - t->audio_format.S24, - t->audio_format.S24_OE, - t->audio_format.S24_32, - t->audio_format.S24_32_OE), - ":", t->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(11, SPA_AUDIO_FORMAT_U8, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16_OE, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_S32_OE, + SPA_AUDIO_FORMAT_S24, + SPA_AUDIO_FORMAT_S24_OE, + SPA_AUDIO_FORMAT_S24_32, + SPA_AUDIO_FORMAT_S24_32_OE), + ":", SPA_FORMAT_AUDIO_layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", t->format_audio.rate, "iru", DEFAULT_RATE, + ":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "iru", DEFAULT_CHANNELS, + ":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); } break; @@ -515,7 +474,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) @@ -524,13 +482,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", port->format.info.raw.format, - ":", t->format_audio.layout, "i", port->format.info.raw.layout, - ":", t->format_audio.rate, "i", port->format.info.raw.rate, - ":", t->format_audio.channels, "i", port->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", port->format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); return 1; } @@ -544,7 +502,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct port *port, *other; struct spa_pod *param; @@ -557,7 +514,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); @@ -567,28 +523,34 @@ 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 }; + 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, ¶m, &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, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + + case SPA_ID_PARAM_Buffers: + { uint32_t buffers, size; const char *size_fmt; @@ -608,44 +570,48 @@ impl_node_port_enum_params(struct spa_node *node, } param = spa_pod_builder_object(&b, - id, t->param_buffers.Buffers, - ":", t->param_buffers.buffers, "iru", buffers, + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "iru", buffers, SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS), - ":", t->param_buffers.blocks, "i", port->blocks, - ":", t->param_buffers.size, size_fmt, size * port->stride, + ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, + ":", SPA_PARAM_BUFFERS_size, size_fmt, size * port->stride, SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride), - ":", t->param_buffers.stride, "i", port->stride, - ":", t->param_buffers.align, "i", 16); + ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; } - else if (id == t->param.idMeta) { + 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 + break; + + default: return -ENOENT; + } (*index)++; @@ -655,18 +621,20 @@ impl_node_port_enum_params(struct spa_node *node, return 1; } -static int calc_width(struct spa_audio_info *info, struct type *t) +static int calc_width(struct spa_audio_info *info) { - if (info->info.raw.format == t->audio_format.U8) + switch (info->info.raw.format) { + case SPA_AUDIO_FORMAT_U8: return 1; - else if (info->info.raw.format == t->audio_format.S16 || - info->info.raw.format == t->audio_format.S16_OE) + case SPA_AUDIO_FORMAT_S16: + case SPA_AUDIO_FORMAT_S16_OE: return 2; - else if (info->info.raw.format == t->audio_format.S24 || - info->info.raw.format == t->audio_format.S24_OE) + case SPA_AUDIO_FORMAT_S24: + case SPA_AUDIO_FORMAT_S24_OE: return 3; - else + default: return 4; + } } static int clear_buffers(struct impl *this, struct port *port) @@ -695,7 +663,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; int res = 0; port = GET_PORT(this, direction, port_id); @@ -715,11 +682,11 @@ 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->n_formats[direction] > 0) { @@ -735,7 +702,7 @@ static int port_set_format(struct spa_node *node, port->have_format = true; port->format = info; - port->stride = calc_width(&info, t); + port->stride = calc_width(&info); if (info.info.raw.layout == SPA_AUDIO_LAYOUT_INTERLEAVED) { port->stride *= info.info.raw.channels; @@ -762,20 +729,19 @@ 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) { + switch (id) { + case SPA_ID_PARAM_Format: return port_set_format(node, direction, port_id, flags, param); - } - else + default: return -ENOENT; + } } static int @@ -788,12 +754,10 @@ impl_node_port_use_buffers(struct spa_node *node, struct impl *this; struct port *port; uint32_t i, size = SPA_ID_INVALID; - 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); @@ -812,7 +776,7 @@ impl_node_port_use_buffers(struct spa_node *node, b = &port->buffers[i]; b->flags = 0; b->outbuf = buffers[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 (size == SPA_ID_INVALID) size = d[0].maxsize; @@ -820,9 +784,9 @@ impl_node_port_use_buffers(struct spa_node *node, if (size != d[0].maxsize) return -EINVAL; - 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; @@ -859,12 +823,10 @@ 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); @@ -873,13 +835,16 @@ impl_node_port_set_io(struct spa_node *node, spa_log_debug(this->log, NAME " %p: port %d:%d update io %d %p", this, direction, port_id, id, data); - if (id == t->io.Buffers) + switch (id) { + case SPA_ID_IO_Buffers: port->io = data; - else if (id == t->io.ControlRange) + break; + case SPA_ID_IO_ControlRange: port->ctrl = data; - else + break; + default: return -ENOENT; - + } return 0; } @@ -1172,7 +1137,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; @@ -1211,17 +1176,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; init_port(this, SPA_DIRECTION_OUTPUT, 0, SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS); @@ -1233,7 +1190,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 diff --git a/spa/plugins/audioconvert/merger.c b/spa/plugins/audioconvert/merger.c index a5a10b573..d84810771 100644 --- a/spa/plugins/audioconvert/merger.c +++ b/spa/plugins/audioconvert/merger.c @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -32,6 +31,7 @@ #include #include #include +#include #define NAME "merger" @@ -41,41 +41,6 @@ #define MAX_BUFFERS 64 #define MAX_PORTS 128 -struct type { - uint32_t node; - uint32_t format; - 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); - 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 buffer { #define BUFFER_FLAG_QUEUED (1<<0) uint32_t flags; @@ -109,8 +74,6 @@ 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; @@ -164,13 +127,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; } @@ -339,7 +305,6 @@ 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; uint32_t rate; const char *rspec; @@ -356,39 +321,39 @@ static int port_enum_formats(struct spa_node *node, if (direction == SPA_DIRECTION_OUTPUT) { *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, "Ieu", t->audio_format.F32, + 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_F32, SPA_POD_PROP_ENUM(11, - t->audio_format.F32, - t->audio_format.F32_OE, - t->audio_format.S32, - t->audio_format.S32_OE, - t->audio_format.S24_32, - t->audio_format.S24_32_OE, - t->audio_format.S24, - t->audio_format.S24_OE, - t->audio_format.S16, - t->audio_format.S16_OE, - t->audio_format.U8), - ":", t->format_audio.layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_S32_OE, + SPA_AUDIO_FORMAT_S24_32, + SPA_AUDIO_FORMAT_S24_32_OE, + SPA_AUDIO_FORMAT_S24, + SPA_AUDIO_FORMAT_S24_OE, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16_OE, + SPA_AUDIO_FORMAT_U8), + ":", SPA_FORMAT_AUDIO_layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", t->format_audio.rate, rspec, rate, + ":", SPA_FORMAT_AUDIO_rate, rspec, rate, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "i", this->port_count); + ":", SPA_FORMAT_AUDIO_channels, "i", this->port_count); } 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, rspec, 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_NON_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, rspec, rate, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "i", 1); + ":", SPA_FORMAT_AUDIO_channels, "i", 1); } break; default: @@ -404,7 +369,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) @@ -413,13 +377,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", port->format.info.raw.format, - ":", t->format_audio.layout, "i", port->format.info.raw.layout, - ":", t->format_audio.rate, "i", port->format.info.raw.rate, - ":", t->format_audio.channels, "i", port->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", port->format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); return 1; } @@ -433,7 +397,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 }; @@ -445,7 +408,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); @@ -456,72 +418,75 @@ impl_node_port_enum_params(struct spa_node *node, spa_log_debug(this->log, NAME " %p: enum param %d %d", this, id, this->have_format); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idEnumFormat, - t->param.idFormat, - t->param.idBuffers, - t->param.idMeta, - t->param_io.idBuffers }; + 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; } - else if (id == t->param.idEnumFormat) { + case SPA_ID_PARAM_EnumFormat: if ((res = port_enum_formats(node, direction, port_id, index, ¶m, &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, ¶m, &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 * port->stride, - SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride), - ":", t->param_buffers.blocks, "i", port->blocks, - ":", t->param_buffers.stride, "i", port->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", port->blocks, + ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * port->stride, + SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride), + ":", SPA_PARAM_BUFFERS_stride, "i", port->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 + break; + default: return -ENOENT; + } (*index)++; @@ -557,7 +522,6 @@ static struct port *find_in_port(struct impl *this) static int setup_convert(struct impl *this) { const struct conv_info *conv; - struct type *t = &this->type; struct port *inport, *outport; uint32_t src_fmt, dst_fmt; @@ -570,17 +534,17 @@ static int setup_convert(struct impl *this) dst_fmt = outport->format.info.raw.format; spa_log_info(this->log, NAME " %p: %s/%d@%d.%dx%d->%s/%d@%d.%d", this, - spa_type_map_get_type(this->map, src_fmt), + spa_debug_type_find_name(spa_debug_types, src_fmt), inport->format.info.raw.channels, inport->format.info.raw.rate, inport->format.info.raw.layout, this->port_count, - spa_type_map_get_type(this->map, dst_fmt), + spa_debug_type_find_name(spa_debug_types, dst_fmt), outport->format.info.raw.channels, outport->format.info.raw.rate, outport->format.info.raw.layout); - conv = find_conv_info(&t->audio_format, src_fmt, dst_fmt, FEATURE_SSE); + conv = find_conv_info(src_fmt, dst_fmt, FEATURE_SSE); if (conv != NULL) { spa_log_info(this->log, NAME " %p: got converter features %08x", this, conv->features); @@ -601,18 +565,20 @@ static int setup_convert(struct impl *this) return -ENOTSUP; } -static int calc_width(struct spa_audio_info *info, struct type *t) +static int calc_width(struct spa_audio_info *info) { - if (info->info.raw.format == t->audio_format.U8) + switch (info->info.raw.format) { + case SPA_AUDIO_FORMAT_U8: return 1; - else if (info->info.raw.format == t->audio_format.S16 || - info->info.raw.format == t->audio_format.S16_OE) + case SPA_AUDIO_FORMAT_S16: + case SPA_AUDIO_FORMAT_S16_OE: return 2; - else if (info->info.raw.format == t->audio_format.S24 || - info->info.raw.format == t->audio_format.S24_OE) + case SPA_AUDIO_FORMAT_S24: + case SPA_AUDIO_FORMAT_S24_OE: return 3; - else + default: return 4; + } } static int port_set_format(struct spa_node *node, @@ -623,7 +589,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); @@ -643,11 +608,11 @@ 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 || this->force_rate) && @@ -658,7 +623,7 @@ static int port_set_format(struct spa_node *node, if (info.info.raw.channels != this->port_count) return -EINVAL; } else { - if (info.info.raw.format != t->audio_format.F32) + if (info.info.raw.format != SPA_AUDIO_FORMAT_F32) return -EINVAL; if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED) return -EINVAL; @@ -667,7 +632,7 @@ static int port_set_format(struct spa_node *node, } port->format = info; - port->stride = calc_width(&info, t); + port->stride = calc_width(&info); if (info.info.raw.layout == SPA_AUDIO_LAYOUT_INTERLEAVED) { port->stride *= info.info.raw.channels; port->blocks = 1; @@ -700,20 +665,19 @@ 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) { + switch (id) { + case SPA_ID_PARAM_Format: return port_set_format(node, direction, port_id, flags, param); - } - else + default: return -ENOENT; + } } static void queue_buffer(struct impl *this, struct port *port, uint32_t id) @@ -755,12 +719,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); @@ -780,9 +742,9 @@ impl_node_port_use_buffers(struct spa_node *node, b->buf = buffers[i]; b->flags = 0; - 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 %d %p", this, buffers[i], d[0].type, d[0].data); return -EINVAL; @@ -814,24 +776,25 @@ 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) + switch (id) { + case SPA_ID_IO_Buffers: port->io = data; - else if (id == t->io.ControlRange) + break; + case SPA_ID_IO_ControlRange: port->ctrl = data; - else + break; + default: return -ENOENT; - + } return 0; } @@ -983,7 +946,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; @@ -1026,16 +989,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); if ((str = spa_dict_lookup(info, "node.format.rate"))) if ((rate = atoi(str)) != 0) { @@ -1056,7 +1012,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 diff --git a/spa/plugins/audioconvert/resample.c b/spa/plugins/audioconvert/resample.c index 2b7f09259..85e774d85 100644 --- a/spa/plugins/audioconvert/resample.c +++ b/spa/plugins/audioconvert/resample.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -79,52 +78,10 @@ struct port { uint32_t offset; }; -struct type { - uint32_t node; - uint32_t format; - uint32_t prop_truncate; - uint32_t prop_dither; - 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_truncate = spa_type_map_get_id(map, SPA_TYPE_PROPS__truncate); - type->prop_dither = spa_type_map_get_id(map, SPA_TYPE_PROPS__ditherType); - 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; struct props props; @@ -211,13 +168,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; } @@ -316,7 +276,6 @@ 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; struct port *other; other = GET_PORT(this, SPA_DIRECTION_REVERSE(direction), 0); @@ -325,24 +284,24 @@ static int port_enum_formats(struct spa_node *node, case 0: if (other->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", t->audio_format.F32, - ":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED, - ":", t->format_audio.rate, "iru", other->format.info.raw.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_NON_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "iru", other->format.info.raw.rate, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "i", other->format.info.raw.channels); + ":", SPA_FORMAT_AUDIO_channels, "i", other->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", 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_NON_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "iru", DEFAULT_RATE, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "iru", DEFAULT_CHANNELS, + ":", SPA_FORMAT_AUDIO_channels, "iru", DEFAULT_CHANNELS, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); } break; @@ -359,7 +318,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) @@ -368,13 +326,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", port->format.info.raw.format, - ":", t->format_audio.layout, "i", port->format.info.raw.layout, - ":", t->format_audio.rate, "i", port->format.info.raw.rate, - ":", t->format_audio.channels, "i", port->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", port->format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); return 1; } @@ -388,7 +346,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct port *port, *other; struct spa_pod *param; struct spa_pod_builder b = { 0 }; @@ -400,7 +357,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); @@ -410,28 +366,32 @@ 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 }; + 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, ¶m, &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, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + case SPA_ID_PARAM_Buffers: + { uint32_t buffers, size; if (!port->have_format) @@ -449,44 +409,46 @@ impl_node_port_enum_params(struct spa_node *node, } param = spa_pod_builder_object(&b, - id, t->param_buffers.Buffers, - ":", t->param_buffers.buffers, "iru", buffers, + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "iru", buffers, SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", t->param_buffers.blocks, "i", port->blocks, - ":", t->param_buffers.size, "iru", size * port->stride, + ":", SPA_PARAM_BUFFERS_blocks, "i", port->blocks, + ":", SPA_PARAM_BUFFERS_size, "iru", size * port->stride, SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride), - ":", t->param_buffers.stride, "i", port->stride, - ":", t->param_buffers.align, "i", 16); + ":", SPA_PARAM_BUFFERS_stride, "i", port->stride, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; } - else if (id == t->param.idMeta) { + 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 + break; + default: return -ENOENT; + } (*index)++; @@ -514,7 +476,6 @@ static int port_set_format(struct spa_node *node, { struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); struct port *port, *other; - struct type *t = &this->type; int res = 0; port = GET_PORT(this, direction, port_id); @@ -532,14 +493,14 @@ 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 (info.info.raw.format != t->audio_format.F32) + if (info.info.raw.format != SPA_AUDIO_FORMAT_F32) return -EINVAL; if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED) return -EINVAL; @@ -565,17 +526,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -592,12 +547,10 @@ impl_node_port_use_buffers(struct spa_node *node, struct impl *this; struct port *port; uint32_t i, size = SPA_ID_INVALID; - 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); @@ -616,7 +569,7 @@ impl_node_port_use_buffers(struct spa_node *node, b = &port->buffers[i]; b->flags = 0; b->outbuf = buffers[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 (size == SPA_ID_INVALID) size = d[0].maxsize; @@ -624,9 +577,9 @@ impl_node_port_use_buffers(struct spa_node *node, if (size != d[0].maxsize) return -EINVAL; - 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; @@ -663,20 +616,18 @@ 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; else return -ENOENT; @@ -859,7 +810,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; @@ -907,16 +858,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; @@ -936,7 +880,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 diff --git a/spa/plugins/audioconvert/splitter.c b/spa/plugins/audioconvert/splitter.c index abbeeb528..18d20c57d 100644 --- a/spa/plugins/audioconvert/splitter.c +++ b/spa/plugins/audioconvert/splitter.c @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -32,6 +31,7 @@ #include #include #include +#include #define NAME "splitter" @@ -41,41 +41,6 @@ #define MAX_BUFFERS 64 #define MAX_PORTS 128 -struct type { - uint32_t node; - uint32_t format; - 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); - 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 buffer { #define BUFFER_FLAG_QUEUED (1<<0) uint32_t flags; @@ -109,8 +74,6 @@ 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; @@ -164,13 +127,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; } @@ -339,7 +305,6 @@ 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; uint32_t rate; const char *rspec; @@ -356,39 +321,39 @@ static int port_enum_formats(struct spa_node *node, if (direction == SPA_DIRECTION_INPUT) { *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, "Ieu", t->audio_format.F32, + 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_F32, SPA_POD_PROP_ENUM(11, - t->audio_format.F32, - t->audio_format.F32_OE, - t->audio_format.S32, - t->audio_format.S32_OE, - t->audio_format.S24_32, - t->audio_format.S24_32_OE, - t->audio_format.S24, - t->audio_format.S24_OE, - t->audio_format.S16, - t->audio_format.S16_OE, - t->audio_format.U8), - ":", t->format_audio.layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F32_OE, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_S32_OE, + SPA_AUDIO_FORMAT_S24_32, + SPA_AUDIO_FORMAT_S24_32_OE, + SPA_AUDIO_FORMAT_S24, + SPA_AUDIO_FORMAT_S24_OE, + SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S16_OE, + SPA_AUDIO_FORMAT_U8), + ":", SPA_FORMAT_AUDIO_layout, "ieu", SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_POD_PROP_ENUM(2, SPA_AUDIO_LAYOUT_INTERLEAVED, SPA_AUDIO_LAYOUT_NON_INTERLEAVED), - ":", t->format_audio.rate, rspec, rate, + ":", SPA_FORMAT_AUDIO_rate, rspec, rate, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "i", this->port_count); + ":", SPA_FORMAT_AUDIO_channels, "i", this->port_count); } 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, rspec, 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_NON_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, rspec, rate, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "i", 1); + ":", SPA_FORMAT_AUDIO_channels, "i", 1); } break; default: @@ -404,7 +369,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) @@ -413,13 +377,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", port->format.info.raw.format, - ":", t->format_audio.layout, "i", port->format.info.raw.layout, - ":", t->format_audio.rate, "i", port->format.info.raw.rate, - ":", t->format_audio.channels, "i", port->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", port->format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", port->format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels); return 1; } @@ -433,7 +397,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 }; @@ -445,7 +408,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); @@ -456,72 +418,77 @@ impl_node_port_enum_params(struct spa_node *node, spa_log_debug(this->log, NAME " %p: enum param %d %d", this, id, this->have_format); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idEnumFormat, - t->param.idFormat, - t->param.idBuffers, - t->param.idMeta, - t->param_io.idBuffers }; + 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, ¶m, &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, ¶m, &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 * port->stride, - SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride), - ":", t->param_buffers.blocks, "i", port->blocks, - ":", t->param_buffers.stride, "i", port->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", port->blocks, + ":", SPA_PARAM_BUFFERS_size, "iru", 1024 * port->stride, + SPA_POD_PROP_MIN_MAX(16 * port->stride, MAX_SAMPLES * port->stride), + ":", SPA_PARAM_BUFFERS_stride, "i", port->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 + break; + default: return -ENOENT; + } (*index)++; @@ -557,7 +524,6 @@ static struct port *find_out_port(struct impl *this) static int setup_convert(struct impl *this) { const struct conv_info *conv; - struct type *t = &this->type; struct port *inport, *outport; uint32_t src_fmt, dst_fmt; @@ -570,17 +536,17 @@ static int setup_convert(struct impl *this) dst_fmt = outport->format.info.raw.format; spa_log_info(this->log, NAME " %p: %s/%d@%d.%dx%d->%s/%d@%d.%d", this, - spa_type_map_get_type(this->map, src_fmt), + spa_debug_type_find_name(spa_debug_types, src_fmt), inport->format.info.raw.channels, inport->format.info.raw.rate, inport->format.info.raw.layout, this->port_count, - spa_type_map_get_type(this->map, dst_fmt), + spa_debug_type_find_name(spa_debug_types, dst_fmt), outport->format.info.raw.channels, outport->format.info.raw.rate, outport->format.info.raw.layout); - conv = find_conv_info(&t->audio_format, src_fmt, dst_fmt, FEATURE_SSE); + conv = find_conv_info(src_fmt, dst_fmt, FEATURE_SSE); if (conv != NULL) { spa_log_info(this->log, NAME " %p: got converter features %08x", this, conv->features); @@ -601,18 +567,20 @@ static int setup_convert(struct impl *this) return -ENOTSUP; } -static int calc_width(struct spa_audio_info *info, struct type *t) +static int calc_width(struct spa_audio_info *info) { - if (info->info.raw.format == t->audio_format.U8) + switch (info->info.raw.format) { + case SPA_AUDIO_FORMAT_U8: return 1; - else if (info->info.raw.format == t->audio_format.S16 || - info->info.raw.format == t->audio_format.S16_OE) + case SPA_AUDIO_FORMAT_S16: + case SPA_AUDIO_FORMAT_S16_OE: return 2; - else if (info->info.raw.format == t->audio_format.S24 || - info->info.raw.format == t->audio_format.S24_OE) + case SPA_AUDIO_FORMAT_S24: + case SPA_AUDIO_FORMAT_S24_OE: return 3; - else + default: return 4; + } } static int port_set_format(struct spa_node *node, @@ -623,7 +591,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); @@ -643,11 +610,11 @@ 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 || this->force_rate) && @@ -658,7 +625,7 @@ static int port_set_format(struct spa_node *node, if (info.info.raw.channels != this->port_count) return -EINVAL; } else { - if (info.info.raw.format != t->audio_format.F32) + if (info.info.raw.format != SPA_AUDIO_FORMAT_F32) return -EINVAL; if (info.info.raw.layout != SPA_AUDIO_LAYOUT_NON_INTERLEAVED) return -EINVAL; @@ -667,7 +634,7 @@ static int port_set_format(struct spa_node *node, } port->format = info; - port->stride = calc_width(&info, t); + port->stride = calc_width(&info); if (info.info.raw.layout == SPA_AUDIO_LAYOUT_INTERLEAVED) { port->stride *= info.info.raw.channels; port->blocks = 1; @@ -700,20 +667,19 @@ 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) { + switch (id) { + case SPA_ID_PARAM_Format: return port_set_format(node, direction, port_id, flags, param); - } - else + default: return -ENOENT; + } } static void queue_buffer(struct impl *this, struct port *port, uint32_t id) @@ -755,12 +721,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); @@ -780,9 +744,9 @@ impl_node_port_use_buffers(struct spa_node *node, b->buf = buffers[i]; b->flags = 0; - 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 %d %p", this, buffers[i], d[0].type, d[0].data); return -EINVAL; @@ -814,20 +778,18 @@ 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; else return -ENOENT; @@ -993,7 +955,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; @@ -1036,16 +998,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); if ((str = spa_dict_lookup(info, "node.format.rate"))) if ((rate = atoi(str)) != 0) { @@ -1065,7 +1020,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 diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index a21a150bd..bc251cba3 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -84,55 +83,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; struct spa_audiomixer_ops ops; @@ -191,13 +145,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; } @@ -367,29 +324,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.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_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, "Ieu", t->audio_format.S16, - SPA_POD_PROP_ENUM(2, t->audio_format.S16, - t->audio_format.F32), - ":", 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, "Ieu", SPA_AUDIO_FORMAT_S16, + SPA_POD_PROP_ENUM(2, SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_F32), + ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "iru", 2, + ":", SPA_FORMAT_AUDIO_channels, "iru", 2, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); } break; @@ -406,7 +362,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) @@ -415,12 +370,12 @@ 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.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_rate, "i", this->format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels); return 1; } @@ -434,7 +389,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 }; @@ -446,7 +400,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); @@ -455,83 +408,79 @@ 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, ¶m, &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, ¶m, &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->bpf, - SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), - ":", 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, 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->bpf, + SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), + ":", SPA_PARAM_BUFFERS_stride, "i", 0, + ":", 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; } - } +#if 0 else if (id == t->param_io.idPropsIn) { struct port_props *p = &port->props; @@ -560,8 +509,10 @@ impl_node_port_enum_params(struct spa_node *node, return 0; } } - else +#endif + default: return -ENOENT; + } (*index)++; @@ -589,7 +540,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); @@ -607,18 +557,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.S16) { + if (info.info.raw.format == SPA_AUDIO_FORMAT_S16) { this->clear = this->ops.clear[FMT_S16]; this->copy = this->ops.copy[FMT_S16]; this->add = this->ops.add[FMT_S16]; @@ -626,7 +576,7 @@ static int port_set_format(struct spa_node *node, this->add_scale = this->ops.add_scale[FMT_S16]; this->bpf = sizeof(int16_t) * info.info.raw.channels; } - else if (info.info.raw.format == t->audio_format.F32) { + else if (info.info.raw.format == SPA_AUDIO_FORMAT_F32) { this->clear = this->ops.clear[FMT_F32]; this->copy = this->ops.copy[FMT_F32]; this->add = this->ops.add[FMT_F32]; @@ -658,16 +608,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 @@ -684,12 +632,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); @@ -708,11 +654,11 @@ impl_node_port_use_buffers(struct spa_node *node, b = &port->buffers[i]; b->outbuf = buffers[i]; b->outstanding = (direction == SPA_DIRECTION_INPUT); - 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; @@ -748,21 +694,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->io_range = 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); @@ -773,6 +718,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; @@ -1036,7 +982,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; @@ -1076,16 +1022,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; @@ -1102,7 +1041,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 diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index aa738967b..0179f1953 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -42,59 +41,6 @@ #define BYTES_TO_SAMPLES(this,b) ((b)/(this)->bpf) #define BYTES_TO_TIME(this,b) SAMPLES_TO_TIME(this, BYTES_TO_SAMPLES (this, b)) -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_live; - uint32_t prop_wave; - uint32_t prop_freq; - uint32_t prop_volume; - uint32_t io_prop_wave; - uint32_t io_prop_freq; - uint32_t io_prop_volume; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; - 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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->prop_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - type->prop_wave = spa_type_map_get_id(map, SPA_TYPE_PROPS__waveType); - type->prop_freq = spa_type_map_get_id(map, SPA_TYPE_PROPS__frequency); - type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume); - type->io_prop_wave = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "waveType"); - type->io_prop_freq = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "frequency"); - type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume"); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - 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); -} - enum wave_type { WAVE_SINE, WAVE_SQUARE, @@ -138,8 +84,6 @@ struct impl { struct spa_handle handle; struct spa_node node; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *data_loop; @@ -186,7 +130,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -196,80 +139,87 @@ static int impl_node_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; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idPropInfo, - t->param.idProps }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + SPA_ID_PARAM_Props }; 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.idPropInfo) { + case SPA_ID_PARAM_PropInfo: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_live, - ":", t->param.propName, "s", "Configure live mode of the source", - ":", t->param.propType, "b", p->live); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_live, + ":", SPA_PROP_INFO_name, "s", "Configure live mode of the source", + ":", SPA_PROP_INFO_type, "b", p->live); break; case 1: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_wave, - ":", t->param.propName, "s", "Select the waveform", - ":", t->param.propType, "i", p->wave, - ":", t->param.propLabels, "[-i", + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_waveType, + ":", SPA_PROP_INFO_name, "s", "Select the waveform", + ":", SPA_PROP_INFO_type, "i", p->wave, + ":", SPA_PROP_INFO_labels, "[-i", "i", WAVE_SINE, "s", "Sine wave", "i", WAVE_SQUARE, "s", "Square wave", "]"); break; case 2: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_freq, - ":", t->param.propName, "s", "Select the frequency", - ":", t->param.propType, "dr", p->freq, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_frequency, + ":", SPA_PROP_INFO_name, "s", "Select the frequency", + ":", SPA_PROP_INFO_type, "dr", p->freq, SPA_POD_PROP_MIN_MAX(0.0, 50000000.0)); break; case 3: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_volume, - ":", t->param.propName, "s", "Select the volume", - ":", t->param.propType, "dr", p->volume, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_volume, + ":", SPA_PROP_INFO_name, "s", "Select the volume", + ":", SPA_PROP_INFO_type, "dr", p->volume, SPA_POD_PROP_MIN_MAX(0.0, 10.0)); break; default: return 0; } + break; } - else if (id == t->param.idProps) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_live, "b", p->live, - ":", t->prop_wave, "i", p->wave, - ":", t->prop_freq, "d", p->freq, - ":", t->prop_volume, "d", p->volume); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_live, "b", p->live, + ":", SPA_PROP_waveType, "i", p->wave, + ":", SPA_PROP_frequency, "d", p->freq, + ":", SPA_PROP_volume, "d", p->volume); break; default: return 0; } + break; } - else + default: return -ENOENT; + } (*index)++; @@ -283,14 +233,12 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag 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; - if (id == t->param.idProps) { + if (id == SPA_ID_PARAM_Props) { struct props *p = &this->props; if (param == NULL) { @@ -298,10 +246,10 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } spa_pod_object_parse(param, - ":",t->prop_live, "?b", &p->live, - ":",t->prop_wave, "?i", &p->wave, - ":",t->prop_freq, "?d", &p->freq, - ":",t->prop_volume, "?d", &p->volume, + ":",SPA_PROP_live, "?b", &p->live, + ":",SPA_PROP_waveType, "?i", &p->wave, + ":",SPA_PROP_frequency, "?d", &p->freq, + ":",SPA_PROP_volume, "?d", &p->volume, NULL); if (p->live) @@ -440,7 +388,9 @@ 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: + { struct timespec now; if (!this->have_format) @@ -461,7 +411,9 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = true; set_timer(this, true); - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + } + case SPA_ID_COMMAND_NODE_Pause: if (!this->have_format) return -EIO; if (this->n_buffers == 0) @@ -472,9 +424,11 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = false; set_timer(this, false); - } else - return -ENOTSUP; + break; + default: + return -ENOTSUP; + } return 0; } @@ -569,22 +523,20 @@ port_enum_formats(struct impl *this, struct spa_pod **param, struct spa_pod_builder *builder) { - struct type *t = &this->type; - switch (*index) { case 0: *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, "Ieu", t->audio_format.S16, - SPA_POD_PROP_ENUM(4, t->audio_format.S16, - t->audio_format.S32, - t->audio_format.F32, - t->audio_format.F64), - ":", 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, "Ieu", SPA_AUDIO_FORMAT_S16, + SPA_POD_PROP_ENUM(4, SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S32, + SPA_AUDIO_FORMAT_F32, + SPA_AUDIO_FORMAT_F64), + ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels, "iru", 2, + ":", SPA_FORMAT_AUDIO_channels, "iru", 2, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; default: @@ -601,20 +553,18 @@ port_get_format(struct impl *this, struct spa_pod **param, struct spa_pod_builder *builder) { - struct type *t = &this->type; - if (!this->have_format) return -EIO; if (*index > 0) 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->current_format.info.raw.format, - ":", t->format_audio.rate, "i", this->current_format.info.raw.rate, - ":", t->format_audio.channels, "i", this->current_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->current_format.info.raw.format, + ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); return 1; } @@ -628,7 +578,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -639,90 +588,87 @@ 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); 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(this, direction, port_id, index, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idFormat) { + break; + case SPA_ID_PARAM_Format: if ((res = port_get_format(this, direction, port_id, index, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + + case SPA_ID_PARAM_Buffers: if (!this->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->bpf, - SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), - ":", 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, 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->bpf, + SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), + ":", SPA_PARAM_BUFFERS_stride, "i", 0, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; + case SPA_ID_PARAM_Meta: if (!this->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 props *p = &this->props; @@ -732,9 +678,9 @@ impl_node_port_enum_params(struct spa_node *node, id, t->param_io.Prop, ":", t->param_io.id, "I", t->io_prop_wave, ":", t->param_io.size, "i", sizeof(struct spa_pod_id), - ":", t->param.propId, "I", t->prop_wave, - ":", t->param.propType, "i", p->wave, - ":", t->param.propLabels, "[-i", + ":", SPA_PROP_INFO_id, "I", SPA_PROP_wave, + ":", SPA_PROP_INFO_type, "i", p->wave, + ":", SPA_PROP_INFO_labels, "[-i", "i", WAVE_SINE, "s", "Sine wave", "i", WAVE_SQUARE, "s", "Square wave", "]"); break; @@ -743,8 +689,8 @@ impl_node_port_enum_params(struct spa_node *node, id, t->param_io.Prop, ":", t->param_io.id, "I", t->io_prop_freq, ":", t->param_io.size, "i", sizeof(struct spa_pod_double), - ":", t->param.propId, "I", t->prop_freq, - ":", t->param.propType, "dr", p->freq, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_freq, + ":", SPA_PROP_INFO_type, "dr", p->freq, SPA_POD_PROP_MIN_MAX(0.0, 50000000.0)); break; case 2: @@ -752,16 +698,18 @@ impl_node_port_enum_params(struct spa_node *node, id, t->param_io.Prop, ":", t->param_io.id, "I", t->io_prop_volume, ":", t->param_io.size, "i", sizeof(struct spa_pod_double), - ":", t->param.propId, "I", t->prop_volume, - ":", t->param.propType, "dr", p->volume, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_volume, + ":", SPA_PROP_INFO_type, "dr", p->volume, SPA_POD_PROP_MIN_MAX(0.0, 10.0)); break; default: return 0; } } - else +#endif + default: return -ENOENT; + } (*index)++; @@ -790,8 +738,6 @@ port_set_format(struct impl *this, uint32_t flags, const struct spa_pod *format) { - struct type *t = &this->type; - if (format == NULL) { this->have_format = false; clear_buffers(this); @@ -804,20 +750,20 @@ port_set_format(struct impl *this, "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 (info.info.raw.format == t->audio_format.S16) + if (info.info.raw.format == SPA_AUDIO_FORMAT_S16) idx = 0; - else if (info.info.raw.format == t->audio_format.S32) + else if (info.info.raw.format == SPA_AUDIO_FORMAT_S32) idx = 1; - else if (info.info.raw.format == t->audio_format.F32) + else if (info.info.raw.format == SPA_AUDIO_FORMAT_F32) idx = 2; - else if (info.info.raw.format == t->audio_format.F64) + else if (info.info.raw.format == SPA_AUDIO_FORMAT_F64) idx = 3; else return -EINVAL; @@ -841,16 +787,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(this, direction, port_id, flags, param); return -ENOENT; @@ -865,7 +809,6 @@ impl_node_port_use_buffers(struct spa_node *node, { struct impl *this; uint32_t i; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); @@ -876,8 +819,6 @@ impl_node_port_use_buffers(struct spa_node *node, if (!this->have_format) return -EIO; - t = &this->type; - clear_buffers(this); for (i = 0; i < n_buffers; i++) { @@ -887,11 +828,11 @@ impl_node_port_use_buffers(struct spa_node *node, b = &this->buffers[i]; b->outbuf = buffers[i]; b->outstanding = false; - 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; @@ -934,19 +875,18 @@ impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { 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->io.Buffers) + if (id == SPA_ID_IO_Buffers) this->io = data; - else if (id == t->io.ControlRange) + else if (id == SPA_ID_IO_ControlRange) this->io_range = data; +#if 0 else if (id == t->io_prop_wave) { if (data && size >= sizeof(struct spa_pod_id)) this->io_wave = &SPA_POD_VALUE(struct spa_pod_id, data); @@ -963,6 +903,7 @@ impl_node_port_set_io(struct spa_node *node, this->io_volume = &SPA_POD_VALUE(struct spa_pod_double, data); else this->io_volume = &this->props.volume; +#endif else return -ENOENT; @@ -1073,7 +1014,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; @@ -1122,18 +1063,11 @@ 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) this->data_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } - init_type(&this->type, this->map); this->node = impl_node; reset_props(&this->props); @@ -1167,7 +1101,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 diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 208effe22..c9eec4931 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -59,58 +58,12 @@ struct buffer { struct spa_list link; }; -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_min_latency; - uint32_t prop_max_latency; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - struct spa_type_media_type media_type; - struct spa_type_media_subtype media_subtype; - struct spa_type_media_subtype_audio media_subtype_audio; - struct spa_type_audio_format audio_format; - struct spa_type_event_node event_node; - struct spa_type_command_node command_node; - struct spa_type_format_audio format_audio; - struct spa_type_param_buffers param_buffers; - struct spa_type_param_meta param_meta; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->prop_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->prop_max_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__maxLatency); - - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - spa_type_media_type_map(map, &type->media_type); - spa_type_media_subtype_map(map, &type->media_subtype); - spa_type_media_subtype_audio_map(map, &type->media_subtype_audio); - spa_type_audio_format_map(map, &type->audio_format); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_format_audio_map(map, &type->format_audio); - spa_type_param_buffers_map(map, &type->param_buffers); - spa_type_param_meta_map(map, &type->param_meta); -} - struct impl { struct spa_handle handle; struct spa_node node; uint32_t seq; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *main_loop; struct spa_loop *data_loop; @@ -194,7 +147,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -204,61 +156,68 @@ static int impl_node_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; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idPropInfo, - t->param.idProps }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + SPA_ID_PARAM_Props }; 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.idPropInfo) { + case SPA_ID_PARAM_PropInfo: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_min_latency, - ":", t->param.propName, "s", "The minimum latency", - ":", t->param.propType, "ir", p->min_latency, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_minLatency, + ":", SPA_PROP_INFO_name, "s", "The minimum latency", + ":", SPA_PROP_INFO_type, "ir", p->min_latency, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; case 1: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_max_latency, - ":", t->param.propName, "s", "The maximum latency", - ":", t->param.propType, "ir", p->max_latency, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_maxLatency, + ":", SPA_PROP_INFO_name, "s", "The maximum latency", + ":", SPA_PROP_INFO_type, "ir", p->max_latency, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; default: return 0; } + break; } - else if (id == t->param.idProps) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_min_latency, "i", p->min_latency, - ":", t->prop_max_latency, "i", p->max_latency); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_minLatency, "i", p->min_latency, + ":", SPA_PROP_maxLatency, "i", p->max_latency); break; default: return 0; } + break; } - else + default: return -ENOENT; + } (*index)++; @@ -272,14 +231,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag 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; - if (id == t->param.idProps) { + switch (id) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; if (param == NULL) { @@ -287,11 +246,13 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } spa_pod_object_parse(param, - ":", t->prop_min_latency, "?i", &p->min_latency, - ":", t->prop_max_latency, "?i", &p->max_latency, NULL); + ":", SPA_PROP_minLatency, "?i", &p->min_latency, + ":", SPA_PROP_maxLatency, "?i", &p->max_latency, NULL); + break; } - else + default: return -ENOENT; + } return 0; } @@ -850,7 +811,8 @@ 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: if (!this->have_format) return -EIO; if (this->n_buffers == 0) @@ -858,13 +820,14 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman if ((res = do_start(this)) < 0) return res; - - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + case SPA_ID_COMMAND_NODE_Pause: if ((res = do_stop(this)) < 0) return res; - } else + break; + default: return -ENOTSUP; - + } return 0; } @@ -960,7 +923,6 @@ impl_node_port_enum_params(struct spa_node *node, { struct impl *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -970,26 +932,28 @@ 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); 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 }; + 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 }; 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 (*index > 0) return 0; @@ -1003,65 +967,72 @@ impl_node_port_enum_params(struct spa_node *node, return -EIO; param = spa_pod_builder_object(&b, - id, t->format, - "I", t->media_type.audio, - "I", t->media_subtype.raw, - ":", t->format_audio.format, "I", t->audio_format.S16, - ":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", t->format_audio.rate, "i", rate, - ":", t->format_audio.channels, "i", channels); + id, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, + ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "i", rate, + ":", SPA_FORMAT_AUDIO_channels, "i", channels); } else return -EIO; - } - else if (id == t->param.idFormat) { + break; + + case SPA_ID_PARAM_Format: if (!this->have_format) return -EIO; if (*index > 0) return 0; param = spa_pod_builder_object(&b, - id, t->format, - "I", t->media_type.audio, - "I", t->media_subtype.raw, - ":", t->format_audio.format, "I", this->current_format.info.raw.format, - ":", t->format_audio.rate, "i", this->current_format.info.raw.rate, - ":", t->format_audio.channels, "i", this->current_format.info.raw.channels); - } - else if (id == t->param.idBuffers) { + id, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format, + ":", SPA_FORMAT_AUDIO_layout, "i", this->current_format.info.raw.layout, + ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); + break; + + case SPA_ID_PARAM_Buffers: if (!this->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", this->props.min_latency * + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, + SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS), + ":", SPA_PARAM_BUFFERS_blocks, "i", 1, + ":", SPA_PARAM_BUFFERS_size, "iru", this->props.min_latency * this->frame_size, SPA_POD_PROP_MIN_MAX(this->props.min_latency * this->frame_size, INT32_MAX), - ":", t->param_buffers.stride, "i", 0, - ":", t->param_buffers.buffers, "ir", 2, - SPA_POD_PROP_MIN_MAX(2, MAX_BUFFERS), - ":", t->param_buffers.align, "i", 16); - } - else if (id == t->param.idMeta) { + ":", SPA_PARAM_BUFFERS_stride, "i", 0, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; + + case SPA_ID_PARAM_Meta: if (!this->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 + break; + + default: return -ENOENT; + } (*index)++; @@ -1101,11 +1072,11 @@ static int port_set_format(struct spa_node *node, "I", &info.media_subtype)) < 0) return err; - if (info.media_type != this->type.media_type.audio || - info.media_subtype != this->type.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, &this->type.format_audio) < 0) + if (spa_format_audio_raw_parse(format, &info.info.raw) < 0) return -EINVAL; this->frame_size = info.info.raw.channels * 2; @@ -1128,17 +1099,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -1152,7 +1117,6 @@ impl_node_port_use_buffers(struct spa_node *node, { struct impl *this; int i; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); @@ -1165,8 +1129,6 @@ impl_node_port_use_buffers(struct spa_node *node, if (!this->have_format) return -EIO; - t = &this->type; - clear_buffers(this); for (i = 0; i < n_buffers; i++) { @@ -1176,12 +1138,12 @@ impl_node_port_use_buffers(struct spa_node *node, b->buf = buffers[i]; b->outstanding = true; - 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)); type = buffers[i]->datas[0].type; - if ((type == t->data.MemFd || - type == t->data.DmaBuf || - type == t->data.MemPtr) && buffers[i]->datas[0].data == NULL) { + if ((type == SPA_DATA_MemFd || + type == SPA_DATA_DmaBuf || + type == SPA_DATA_MemPtr) && buffers[i]->datas[0].data == NULL) { spa_log_error(this->log, NAME " %p: need mapped memory", this); return -EINVAL; } @@ -1224,22 +1186,23 @@ impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { 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->io.Buffers) + switch (id) { + case SPA_ID_IO_Buffers: this->io = data; - else if (id == t->io.ControlRange) + break; + case SPA_ID_IO_ControlRange: this->range = data; - else + break; + default: return -ENOENT; - + } return 0; } @@ -1335,7 +1298,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; @@ -1374,19 +1337,13 @@ 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) this->data_loop = support[i].data; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_MainLoop) this->main_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } if (this->data_loop == NULL) { spa_log_error(this->log, "a data loop is needed"); return -EINVAL; @@ -1395,7 +1352,6 @@ impl_init(const struct spa_handle_factory *factory, spa_log_error(this->log, "a main loop is needed"); return -EINVAL; } - init_type(&this->type, this->map); this->node = impl_node; reset_props(&this->props); @@ -1418,7 +1374,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 diff --git a/spa/plugins/bluez5/bluez5-monitor.c b/spa/plugins/bluez5/bluez5-monitor.c index 50c37030b..3670b24e3 100644 --- a/spa/plugins/bluez5/bluez5-monitor.c +++ b/spa/plugins/bluez5/bluez5-monitor.c @@ -30,34 +30,21 @@ #include #include -#include #include #include #include #include +#include #include "a2dp-codecs.h" #include "defs.h" #define NAME "bluez5-monitor" -struct type { - uint32_t handle_factory; - struct spa_type_monitor monitor; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->handle_factory = spa_type_map_get_id(map, SPA_TYPE__HandleFactory); - spa_type_monitor_map(map, &type->monitor); -} - struct spa_bt_monitor { struct spa_handle handle; struct spa_monitor monitor; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_dbus *dbus; struct spa_dbus_connection *dbus_connection; @@ -80,18 +67,17 @@ struct spa_handle_factory spa_a2dp_sink_factory; static void fill_item(struct spa_bt_monitor *this, struct spa_bt_transport *transport, struct spa_pod **result, struct spa_pod_builder *builder) { - struct type *t = &this->type; char trans[16]; spa_pod_builder_add(builder, - "<", 0, t->monitor.MonitorItem, - ":", t->monitor.id, "s", transport->path, - ":", t->monitor.flags, "i", 0, - ":", t->monitor.state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE, - ":", t->monitor.name, "s", transport->path, - ":", t->monitor.klass, "s", "Adapter/Bluetooth", - ":", t->monitor.factory, "p", t->handle_factory, &spa_a2dp_sink_factory, - ":", t->monitor.info, "[", + "<", 0, SPA_ID_OBJECT_MonitorItem, + ":", SPA_MONITOR_ITEM_id, "s", transport->path, + ":", SPA_MONITOR_ITEM_flags, "i", SPA_MONITOR_ITEM_FLAG_NONE, + ":", SPA_MONITOR_ITEM_state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE, + ":", SPA_MONITOR_ITEM_name, "s", transport->path, + ":", SPA_MONITOR_ITEM_class, "s", "Adapter/Bluetooth", + ":", SPA_MONITOR_ITEM_factory, "p", SPA_ID_INTERFACE_HandleFactory, &spa_a2dp_sink_factory, + ":", SPA_MONITOR_ITEM_info, "[", NULL); snprintf(trans, sizeof(trans), "%p", transport); @@ -654,7 +640,7 @@ static struct spa_bt_node *node_create(struct spa_bt_monitor *monitor, struct sp struct spa_pod *item; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - event = spa_pod_builder_object(&b, 0, monitor->type.monitor.Added); + event = spa_pod_builder_object(&b, 0, SPA_ID_EVENT_MONITOR_Added); fill_item(monitor, transport, &item, &b); monitor->callbacks->event(monitor->callbacks_data, event); @@ -670,7 +656,7 @@ static struct spa_bt_node *node_destroy(struct spa_bt_monitor *monitor, struct s struct spa_pod *item; spa_pod_builder_init(&b, buffer, sizeof(buffer)); - event = spa_pod_builder_object(&b, 0, monitor->type.monitor.Removed); + event = spa_pod_builder_object(&b, 0, SPA_ID_EVENT_MONITOR_Removed); fill_item(monitor, transport, &item, &b); monitor->callbacks->event(monitor->callbacks_data, event); @@ -1201,7 +1187,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, this = (struct spa_bt_monitor *) handle; - if (interface_id == this->type.monitor.Monitor) + if (interface_id == SPA_ID_INTERFACE_Monitor) *interface = &this->monitor; else return -ENOENT; @@ -1240,22 +1226,15 @@ impl_init(const struct spa_handle_factory *factory, this = (struct spa_bt_monitor *) 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; - else if (strcmp(support[i].type, SPA_TYPE__DBus) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DBus) this->dbus = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } if (this->dbus == NULL) { spa_log_error(this->log, "a dbus is needed"); return -EINVAL; } - init_type(&this->type, this->map); this->dbus_connection = spa_dbus_get_connection(this->dbus, DBUS_BUS_SYSTEM); if (this->dbus_connection == NULL) { @@ -1274,7 +1253,7 @@ impl_init(const struct spa_handle_factory *factory, } static const struct spa_interface_info impl_interfaces[] = { - {SPA_TYPE__Monitor,}, + {SPA_ID_INTERFACE_Monitor,}, }; static int diff --git a/spa/plugins/ffmpeg/ffmpeg-dec.c b/spa/plugins/ffmpeg/ffmpeg-dec.c index 52dea2343..526e03940 100644 --- a/spa/plugins/ffmpeg/ffmpeg-dec.c +++ b/spa/plugins/ffmpeg/ffmpeg-dec.c @@ -23,11 +23,11 @@ #include #include -#include #include #include #include #include +#include #include #define IS_VALID_PORT(this,d,id) ((id) == 0) @@ -52,33 +52,10 @@ struct port { struct spa_io_buffers *io; }; -struct type { - uint32_t node; - 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_video format_video; - struct spa_type_command_node command_node; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->node = spa_type_map_get_id(map, SPA_TYPE__Node); - 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_video_map(map, &type->format_video); - spa_type_command_node_map(map, &type->command_node); -} - 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; @@ -115,13 +92,16 @@ static int spa_ffmpeg_dec_node_send_command(struct spa_node *node, const struct 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; } @@ -280,8 +260,6 @@ spa_ffmpeg_dec_node_port_enum_params(struct spa_node *node, struct spa_pod **result, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct type *t = &this->type; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -290,26 +268,32 @@ spa_ffmpeg_dec_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 }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_EnumFormat, + SPA_ID_PARAM_Format }; 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, filter, ¶m, &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, filter, ¶m, &b)) <= 0) return res; - } - else + break; + + default: return -ENOENT; + } (*index)++; @@ -347,11 +331,11 @@ static int port_set_format(struct spa_node *node, "I", &info.media_type, "I", &info.media_subtype); - if (info.media_type != this->type.media_type.video && - info.media_subtype != this->type.media_subtype.raw) + if (info.media_type != SPA_MEDIA_TYPE_video && + info.media_subtype != SPA_MEDIA_SUBTYPE_raw) return -EINVAL; - if (spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video) < 0) + if (spa_format_video_raw_parse(format, &info.info.raw) < 0) return -EINVAL; if (!(flags & SPA_NODE_PARAM_FLAG_TEST_ONLY)) { @@ -368,10 +352,7 @@ spa_ffmpeg_dec_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct type *t = &this->type; - - if (id == t->param.idFormat) { + if (id == SPA_ID_PARAM_Format) { return port_set_format(node, direction, port_id, flags, param); } else @@ -415,20 +396,18 @@ spa_ffmpeg_dec_node_port_set_io(struct spa_node *node, { struct impl *this; struct port *port; - struct type *t; if (node == NULL) return -EINVAL; this = SPA_CONTAINER_OF(node, struct impl, node); - t = &this->type; if (!IS_VALID_PORT(this, direction, port_id)) return -EINVAL; port = GET_PORT(this, direction, port_id); - if (id == t->io.Buffers) + if (id == SPA_ID_IO_Buffers) port->io = data; else return -ENOENT; @@ -515,7 +494,7 @@ spa_ffmpeg_dec_get_interface(struct spa_handle *handle, uint32_t interface_id, v this = (struct impl *) handle; - if (interface_id == this->type.node) + if (interface_id == SPA_ID_INTERFACE_Node) *interface = &this->node; else return -ENOENT; @@ -537,16 +516,9 @@ spa_ffmpeg_dec_init(struct spa_handle *handle, 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, "a type-map is needed"); - return -EINVAL; - } - init_type(&this->type, this->map); this->node = ffmpeg_dec_node; diff --git a/spa/plugins/ffmpeg/ffmpeg-enc.c b/spa/plugins/ffmpeg/ffmpeg-enc.c index dd685b7c6..fd6fa3625 100644 --- a/spa/plugins/ffmpeg/ffmpeg-enc.c +++ b/spa/plugins/ffmpeg/ffmpeg-enc.c @@ -24,13 +24,11 @@ #include #include -#include #include #include #include #include - #define IS_VALID_PORT(this,d,id) ((id) == 0) #define GET_IN_PORT(this,p) (&this->in_ports[p]) #define GET_OUT_PORT(this,p) (&this->out_ports[p]) @@ -57,33 +55,10 @@ struct port { struct spa_io_buffers *io; }; -struct type { - uint32_t node; - 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_video format_video; - struct spa_type_command_node command_node; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->node = spa_type_map_get_id(map, SPA_TYPE__Node); - 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_video_map(map, &type->format_video); - spa_type_command_node_map(map, &type->command_node); -} - 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; @@ -119,13 +94,16 @@ static int spa_ffmpeg_enc_node_send_command(struct spa_node *node, const struct 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; } @@ -230,11 +208,6 @@ static int port_enum_formats(struct spa_node *node, struct spa_pod **param, struct spa_pod_builder *builder) { - //struct impl *this = SPA_CONTAINER_OF (node, struct impl, node); - //struct port *port; - - //port = GET_PORT(this, direction, port_id); - switch (*index) { case 0: *param = NULL; @@ -276,8 +249,6 @@ spa_ffmpeg_enc_node_port_enum_params(struct spa_node *node, struct spa_pod **result, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct type *t = &this->type; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -286,26 +257,32 @@ spa_ffmpeg_enc_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 }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_EnumFormat, + SPA_ID_PARAM_Format }; 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, filter, ¶m, &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, filter, ¶m, &b)) <= 0) return res; - } - else + break; + + default: return -ENOENT; + } (*index)++; @@ -334,11 +311,11 @@ static int port_set_format(struct spa_node *node, "I", &info.media_type, "I", &info.media_subtype); - if (info.media_type != this->type.media_type.video && - info.media_subtype != this->type.media_subtype.raw) + if (info.media_type != SPA_MEDIA_TYPE_video && + info.media_subtype != SPA_MEDIA_SUBTYPE_raw) return -EINVAL; - if (spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video) < 0) + if (spa_format_video_raw_parse(format, &info.info.raw) < 0) return -EINVAL; if (!(flags & SPA_NODE_PARAM_FLAG_TEST_ONLY)) { @@ -355,10 +332,7 @@ spa_ffmpeg_enc_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, const struct spa_pod *param) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct type *t = &this->type; - - if (id == t->param.idFormat) { + if (id == SPA_ID_PARAM_Format) { return port_set_format(node, direction, port_id, flags, param); } else @@ -401,20 +375,18 @@ spa_ffmpeg_enc_node_port_set_io(struct spa_node *node, { struct impl *this; struct port *port; - struct type *t; if (node == NULL) return -EINVAL; this = SPA_CONTAINER_OF(node, struct impl, node); - t = &this->type; if (!IS_VALID_PORT(this, direction, port_id)) return -EINVAL; port = GET_PORT(this, direction, port_id); - if (id == t->io.Buffers) + if (id == SPA_ID_IO_Buffers) port->io = data; else return -ENOENT; @@ -499,7 +471,7 @@ spa_ffmpeg_enc_get_interface(struct spa_handle *handle, uint32_t interface_id, v this = (struct impl *) handle; - if (interface_id == this->type.node) + if (interface_id == SPA_ID_INTERFACE_Node) *interface = &this->node; else return -ENOENT; @@ -520,15 +492,9 @@ spa_ffmpeg_enc_init(struct spa_handle *handle, 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, "a type-map is needed"); - return -EINVAL; - } this->node = ffmpeg_enc_node; diff --git a/spa/plugins/ffmpeg/ffmpeg.c b/spa/plugins/ffmpeg/ffmpeg.c index e9ff12197..3d8dd6d73 100644 --- a/spa/plugins/ffmpeg/ffmpeg.c +++ b/spa/plugins/ffmpeg/ffmpeg.c @@ -58,7 +58,7 @@ ffmpeg_enc_init(const struct spa_handle_factory *factory, } static const struct spa_interface_info ffmpeg_interfaces[] = { - {SPA_TYPE__Node, }, + {SPA_ID_INTERFACE_Node, }, }; static int diff --git a/spa/plugins/support/dbus.c b/spa/plugins/support/dbus.c index 3e1db92a0..f272222b6 100644 --- a/spa/plugins/support/dbus.c +++ b/spa/plugins/support/dbus.c @@ -27,29 +27,17 @@ #include -#include +#include #include #include #include #define NAME "dbus" -struct type { - uint32_t dbus; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->dbus = spa_type_map_get_id(map, SPA_TYPE__DBus); -} - struct impl { struct spa_handle handle; struct spa_dbus dbus; - struct type type; - - struct spa_type_map *map; struct spa_log *log; struct spa_loop_utils *utils; @@ -339,7 +327,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, this = (struct impl *) handle; - if (interface_id == this->type.dbus) + if (interface_id == SPA_ID_INTERFACE_DBus) *interface = &this->dbus; else return -ENOENT; @@ -382,22 +370,15 @@ impl_init(const struct spa_handle_factory *factory, this->dbus = impl_dbus; 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; - else if (strcmp(support[i].type, SPA_TYPE__LoopUtils) == 0) + else if (support[i].type == SPA_ID_INTERFACE_LoopUtils) this->utils = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } if (this->utils == NULL) { spa_log_error(this->log, "a LoopUtils is needed"); return -EINVAL; } - init_type(&this->type, this->map); spa_log_debug(this->log, NAME " %p: initialized", this); @@ -405,7 +386,7 @@ impl_init(const struct spa_handle_factory *factory, } static const struct spa_interface_info impl_interfaces[] = { - {SPA_TYPE__DBus,}, + {SPA_ID_INTERFACE_DBus,}, }; static int diff --git a/spa/plugins/support/logger.c b/spa/plugins/support/logger.c index eb339de5f..43eedc8a5 100644 --- a/spa/plugins/support/logger.c +++ b/spa/plugins/support/logger.c @@ -24,11 +24,11 @@ #include #include -#include #include #include #include #include +#include #define NAME "logger" @@ -36,22 +36,10 @@ #define TRACE_BUFFER (16*1024) -struct type { - uint32_t log; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->log = spa_type_map_get_id(map, SPA_TYPE__Log); -} - struct impl { struct spa_handle handle; struct spa_log log; - struct type type; - struct spa_type_map *map; - bool colors; struct spa_ringbuffer trace_rb; @@ -170,7 +158,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, this = (struct impl *) handle; - if (interface_id == this->type.log) + if (interface_id == SPA_ID_INTERFACE_Log) *interface = &this->log; else return -ENOENT; @@ -224,16 +212,9 @@ impl_init(const struct spa_handle_factory *factory, this->log = impl_log; for (i = 0; i < n_support; i++) { - if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0) - this->map = support[i].data; - if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) + if (support[i].type == SPA_ID_INTERFACE_MainLoop) loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(&this->log, "a type-map is needed"); - return -EINVAL; - } - init_type(&this->type, this->map); if (info && (str = spa_dict_lookup(info, "log.colors")) != NULL) this->colors = (strcmp(str, "true") == 0 || atoi(str) == 1); @@ -256,7 +237,7 @@ impl_init(const struct spa_handle_factory *factory, } static const struct spa_interface_info impl_interfaces[] = { - {SPA_TYPE__Log,}, + {SPA_ID_INTERFACE_Log,}, }; static int diff --git a/spa/plugins/support/loop.c b/spa/plugins/support/loop.c index 2c158240b..bd49410fb 100644 --- a/spa/plugins/support/loop.c +++ b/spa/plugins/support/loop.c @@ -31,9 +31,9 @@ #include #include -#include #include #include +#include #include #define NAME "loop" @@ -53,21 +53,8 @@ struct invoke_item { int res; }; -struct type { - uint32_t loop; - uint32_t loop_control; - uint32_t loop_utils; -}; - static void loop_signal_event(struct spa_source *source); -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->loop = spa_type_map_get_id(map, SPA_TYPE__Loop); - type->loop_control = spa_type_map_get_id(map, SPA_TYPE__LoopControl); - type->loop_utils = spa_type_map_get_id(map, SPA_TYPE__LoopUtils); -} - struct impl { struct spa_handle handle; struct spa_loop loop; @@ -75,8 +62,6 @@ struct impl { struct spa_loop_utils utils; struct spa_log *log; - struct type type; - struct spa_type_map *map; struct spa_list source_list; struct spa_list destroy_list; @@ -676,15 +661,19 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, impl = (struct impl *) handle; - if (interface_id == impl->type.loop) + switch (interface_id) { + case SPA_ID_INTERFACE_Loop: *interface = &impl->loop; - else if (interface_id == impl->type.loop_control) + break; + case SPA_ID_INTERFACE_LoopControl: *interface = &impl->control; - else if (interface_id == impl->type.loop_utils) + break; + case SPA_ID_INTERFACE_LoopUtils: *interface = &impl->utils; - else + break; + default: return -ENOENT; - + } return 0; } @@ -737,16 +726,9 @@ impl_init(const struct spa_handle_factory *factory, impl->utils = impl_loop_utils; for (i = 0; i < n_support; i++) { - if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0) - impl->map = support[i].data; - else if (strcmp(support[i].type, SPA_TYPE__Log) == 0) + if (support[i].type == SPA_ID_INTERFACE_Log) impl->log = support[i].data; } - if (impl->map == NULL) { - spa_log_error(impl->log, NAME " %p: a type-map is needed", impl); - return -EINVAL; - } - init_type(&impl->type, impl->map); impl->epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (impl->epoll_fd == -1) @@ -767,9 +749,9 @@ impl_init(const struct spa_handle_factory *factory, } static const struct spa_interface_info impl_interfaces[] = { - {SPA_TYPE__Loop,}, - {SPA_TYPE__LoopControl,}, - {SPA_TYPE__LoopUtils,}, + {SPA_ID_INTERFACE_Loop,}, + {SPA_ID_INTERFACE_LoopControl,}, + {SPA_ID_INTERFACE_LoopUtils,}, }; static int diff --git a/spa/plugins/support/mapper.c b/spa/plugins/support/mapper.c deleted file mode 100644 index f2a40335b..000000000 --- a/spa/plugins/support/mapper.c +++ /dev/null @@ -1,227 +0,0 @@ -/* Spa - * Copyright (C) 2017 Wim Taymans - * - * 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 -#include -#include -#include -#include -#include - -#include -#include - -#define NAME "mapper" - -struct type { - uint32_t type_map; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->type_map = spa_type_map_get_id(map, SPA_TYPE__TypeMap); -} - -struct array { - size_t size; - size_t maxsize; - void *data; -}; - -struct impl { - struct spa_handle handle; - struct spa_type_map map; - - struct type type; - - struct array types; - struct array strings; -}; - -static inline void * alloc_size(struct array *array, size_t size, size_t extend) -{ - void *res; - if (array->size + size > array->maxsize) { - array->maxsize = SPA_ROUND_UP_N(array->size + size, extend); - array->data = realloc(array->data, array->maxsize); - } - res = SPA_MEMBER(array->data, array->size, void); - array->size += size; - return res; -} - -static uint32_t -impl_type_map_get_id(struct spa_type_map *map, const char *type) -{ - struct impl *impl = SPA_CONTAINER_OF(map, struct impl, map); - uint32_t i, len; - void *p; - off_t o, *off; - - if (type == NULL) - return SPA_ID_INVALID; - - for (i = 0; i < impl->types.size / sizeof(off_t); i++) { - o = ((off_t *)impl->types.data)[i]; - if (strcmp(SPA_MEMBER(impl->strings.data, o, char), type) == 0) - return i; - } - len = strlen(type); - p = alloc_size(&impl->strings, len+1, 1024); - memcpy(p, type, len + 1); - - off = alloc_size(&impl->types, sizeof(off_t), 128); - *off = SPA_PTRDIFF(p, impl->strings.data); - i = SPA_PTRDIFF(off, impl->types.data) / sizeof(off_t); - - return i; - -} - -static const char * -impl_type_map_get_type(const struct spa_type_map *map, uint32_t id) -{ - struct impl *impl = SPA_CONTAINER_OF(map, struct impl, map); - - if (id < impl->types.size / sizeof(off_t)) { - off_t o = ((off_t *)impl->types.data)[id]; - return SPA_MEMBER(impl->strings.data, o, char); - } - return NULL; -} - -static size_t -impl_type_map_get_size(const struct spa_type_map *map) -{ - struct impl *impl = SPA_CONTAINER_OF(map, struct impl, map); - return impl->types.size / sizeof(off_t); -} - -static const struct spa_type_map impl_type_map = { - SPA_VERSION_TYPE_MAP, - NULL, - impl_type_map_get_id, - impl_type_map_get_type, - impl_type_map_get_size, -}; - -static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface) -{ - struct impl *impl; - - spa_return_val_if_fail(handle != NULL, -EINVAL); - spa_return_val_if_fail(interface != NULL, -EINVAL); - - impl = (struct impl *) handle; - - if (interface_id == impl->type.type_map) - *interface = &impl->map; - else - return -ENOENT; - - return 0; -} - -static int impl_clear(struct spa_handle *handle) -{ - struct impl *impl; - - spa_return_val_if_fail(handle != NULL, -EINVAL); - - impl = (struct impl *) handle; - - if (impl->types.data) - free(impl->types.data); - if (impl->strings.data) - free(impl->strings.data); - - return 0; -} - -static size_t -impl_get_size(const struct spa_handle_factory *factory, - const struct spa_dict *params) -{ - return sizeof(struct impl); -} - -static int -impl_init(const struct spa_handle_factory *factory, - struct spa_handle *handle, - const struct spa_dict *info, - const struct spa_support *support, - uint32_t n_support) -{ - struct impl *impl; - - spa_return_val_if_fail(factory != NULL, -EINVAL); - spa_return_val_if_fail(handle != NULL, -EINVAL); - - handle->get_interface = impl_get_interface; - handle->clear = impl_clear; - - impl = (struct impl *) handle; - - impl->map = impl_type_map; - - init_type(&impl->type, &impl->map); - - return 0; -} - -static const struct spa_interface_info impl_interfaces[] = { - {SPA_TYPE__TypeMap,}, -}; - -static int -impl_enum_interface_info(const struct spa_handle_factory *factory, - const struct spa_interface_info **info, - uint32_t *index) -{ - spa_return_val_if_fail(factory != NULL, -EINVAL); - spa_return_val_if_fail(info != NULL, -EINVAL); - spa_return_val_if_fail(index != NULL, -EINVAL); - - switch (*index) { - case 0: - *info = &impl_interfaces[*index]; - break; - default: - return 0; - } - (*index)++; - return 1; -} - -static const struct spa_handle_factory type_map_factory = { - SPA_VERSION_HANDLE_FACTORY, - NAME, - NULL, - impl_get_size, - impl_init, - impl_enum_interface_info, -}; - -int spa_handle_factory_register(const struct spa_handle_factory *factory); - -static void reg(void) __attribute__ ((constructor)); -static void reg(void) -{ - spa_handle_factory_register(&type_map_factory); -} diff --git a/spa/plugins/support/meson.build b/spa/plugins/support/meson.build index 475e295f2..c996c04ec 100644 --- a/spa/plugins/support/meson.build +++ b/spa/plugins/support/meson.build @@ -1,5 +1,4 @@ -spa_support_sources = ['mapper.c', - 'logger.c', +spa_support_sources = ['logger.c', 'loop.c', 'plugin.c'] diff --git a/spa/plugins/test/fakesink.c b/spa/plugins/test/fakesink.c index a6ec3bed3..8e30aad30 100644 --- a/spa/plugins/test/fakesink.c +++ b/spa/plugins/test/fakesink.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -38,37 +37,6 @@ #define NAME "fakesink" -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_live; - 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_param_buffers param_buffers; - struct spa_type_param_meta param_meta; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->prop_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_param_buffers_map(map, &type->param_buffers); - spa_type_param_meta_map(map, &type->param_meta); -} - struct props { bool live; }; @@ -87,8 +55,6 @@ struct impl { struct spa_handle handle; struct spa_node node; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *data_loop; @@ -133,7 +99,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -142,29 +107,30 @@ static int impl_node_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; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { + switch (id) { + case SPA_ID_PARAM_List: if (*index > 0) return 0; param = spa_pod_builder_object(&b, - id, t->param.List, - ":", t->param.listId, "I", t->param.idProps); - } - else if (id == t->param.idProps) { + id, SPA_ID_OBJECT_ParamList, + ":", SPA_PARAM_LIST_id, "I", SPA_ID_PARAM_Props); + break; + case SPA_ID_PARAM_Props: if (*index > 0) return 0; param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_live, "b", this->props.live); - } - else + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_live, "b", this->props.live); + break; + default: return -ENOENT; + } (*index)++; @@ -178,29 +144,29 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag 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; - if (id == t->param.idProps) { + switch (id) { + case SPA_ID_PARAM_Props: if (param == NULL) { reset_props(this, &this->props); return 0; } spa_pod_object_parse(param, - ":", t->prop_live, "?b", &this->props.live, NULL); + ":", SPA_PROP_live, "?b", &this->props.live, NULL); if (this->props.live) this->info.flags |= SPA_PORT_INFO_FLAG_LIVE; else this->info.flags &= ~SPA_PORT_INFO_FLAG_LIVE; - } - else - return -ENOENT; + break; + default: + return -ENOENT; + } return 0; } @@ -302,7 +268,9 @@ 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: + { struct timespec now; if (!this->have_format) @@ -323,7 +291,9 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = true; set_timer(this, true); - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + } + case SPA_ID_COMMAND_NODE_Pause: if (!this->have_format) return -EIO; if (this->n_buffers == 0) @@ -334,8 +304,10 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = false; set_timer(this, false); - } else + break; + default: return -ENOTSUP; + } return 0; } @@ -466,8 +438,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod **result, struct spa_pod_builder *builder) { - struct impl *this; - struct type *t; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -477,60 +447,62 @@ impl_node_port_enum_params(struct spa_node *node, spa_return_val_if_fail(index != NULL, -EINVAL); 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); + spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); 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 }; + 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 }; 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, filter, ¶m, &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, filter, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + case SPA_ID_PARAM_Buffers: if (*index > 0) return 0; param = spa_pod_builder_object(&b, - id, t->param_buffers.Buffers, - ":", t->param_buffers.size, "i", 128, - ":", t->param_buffers.stride, "i", 1, - ":", t->param_buffers.buffers, "ir", 2, - 2, 1, 32, - ":", t->param_buffers.align, "i", 16); - } - else if (id == t->param.idMeta) { + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, + SPA_POD_PROP_MIN_MAX(1, 32), + ":", SPA_PARAM_BUFFERS_blocks, "i", 1, + ":", SPA_PARAM_BUFFERS_size, "i", 128, + ":", SPA_PARAM_BUFFERS_stride, "i", 1, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; + case SPA_ID_PARAM_Meta: 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 + break; + default: return -ENOENT; + } (*index)++; @@ -577,17 +549,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -603,7 +569,6 @@ impl_node_port_use_buffers(struct spa_node *node, { struct impl *this; uint32_t i; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); @@ -614,8 +579,6 @@ impl_node_port_use_buffers(struct spa_node *node, if (!this->have_format) return -EIO; - t = &this->type; - clear_buffers(this); for (i = 0; i < n_buffers; i++) { @@ -625,11 +588,11 @@ impl_node_port_use_buffers(struct spa_node *node, b = &this->buffers[i]; b->outbuf = buffers[i]; b->outstanding = true; - 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]); } @@ -670,16 +633,14 @@ impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { 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->io.Buffers) + if (id == SPA_ID_IO_Buffers) this->io = data; else return -ENOENT; @@ -767,7 +728,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; @@ -816,18 +777,11 @@ 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) this->data_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } - init_type(&this->type, this->map); this->node = impl_node; reset_props(this, &this->props); @@ -857,7 +811,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 diff --git a/spa/plugins/test/fakesrc.c b/spa/plugins/test/fakesrc.c index 24107d20c..3217dffd0 100644 --- a/spa/plugins/test/fakesrc.c +++ b/spa/plugins/test/fakesrc.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -38,39 +37,6 @@ #define NAME "fakesrc" -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_live; - uint32_t prop_pattern; - 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_param_buffers param_buffers; - struct spa_type_param_meta param_meta; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->prop_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - type->prop_pattern = spa_type_map_get_id(map, SPA_TYPE_PROPS__patternType); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_param_buffers_map(map, &type->param_buffers); - spa_type_param_meta_map(map, &type->param_meta); -} - struct props { bool live; uint32_t pattern; @@ -90,8 +56,6 @@ struct impl { struct spa_handle handle; struct spa_node node; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *data_loop; @@ -139,7 +103,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -149,33 +112,37 @@ static int impl_node_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; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { + switch (id) { + case SPA_ID_PARAM_List: if (*index > 0) return 0; param = spa_pod_builder_object(&b, - id, t->param.List, - ":", t->param.listId, "I", t->param.idProps); - } - else if (id == t->param.idProps) { + id, SPA_ID_OBJECT_ParamList, + ":", SPA_PARAM_LIST_id, "I", SPA_ID_PARAM_Props); + break; + + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; if (*index > 0) return 0; param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_live, "b", p->live, - ":", t->prop_pattern, "Ie", p->pattern, - 1, p->pattern); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_live, "b", p->live, + ":", SPA_PROP_patternType, "Ie", p->pattern, + SPA_POD_PROP_ENUM(1, p->pattern)); + break; } - else + default: return -ENOENT; + } (*index)++; @@ -189,14 +156,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag 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; - if (id == t->param.idProps) { + switch (id) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; if (param == NULL) { @@ -204,17 +171,18 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } spa_pod_object_parse(param, - ":", t->prop_live, "?b", &p->live, - ":", t->prop_pattern, "?I", &p->pattern, NULL); + ":", SPA_PROP_live, "?b", &p->live, + ":", SPA_PROP_patternType, "?I", &p->pattern, NULL); if (p->live) this->info.flags |= SPA_PORT_INFO_FLAG_LIVE; else this->info.flags &= ~SPA_PORT_INFO_FLAG_LIVE; + break; } - else + default: return -ENOENT; - + } return 0; } @@ -317,7 +285,9 @@ 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: + { struct timespec now; if (!this->have_format) @@ -339,7 +309,9 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = true; set_timer(this, true); - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + } + case SPA_ID_COMMAND_NODE_Pause: if (!this->have_format) return -EIO; if (this->n_buffers == 0) @@ -350,9 +322,10 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = false; set_timer(this, false); - } else + break; + default: return -ENOTSUP; - + } return 0; } @@ -481,8 +454,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod **result, struct spa_pod_builder *builder) { - struct impl *this; - struct type *t; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -492,60 +463,62 @@ impl_node_port_enum_params(struct spa_node *node, spa_return_val_if_fail(index != NULL, -EINVAL); 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); + spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); 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 }; + 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 }; 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, filter, ¶m, &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, filter, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + case SPA_ID_PARAM_Buffers: if (*index > 0) return 0; param = spa_pod_builder_object(&b, - id, t->param_buffers.Buffers, - ":", t->param_buffers.size, "i", 128, - ":", t->param_buffers.stride, "i", 1, - ":", t->param_buffers.buffers, "ir", 32, - 2, 2, 32, - ":", t->param_buffers.align, "i", 16); - } - else if (id == t->param.idMeta) { + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "ir", 32, + SPA_POD_PROP_MIN_MAX(2, 32), + ":", SPA_PARAM_BUFFERS_blocks, "i", 1, + ":", SPA_PARAM_BUFFERS_size, "i", 128, + ":", SPA_PARAM_BUFFERS_stride, "i", 1, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; + case SPA_ID_PARAM_Meta: 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 + break; + default: return -ENOENT; + } (*index)++; @@ -592,17 +565,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -637,11 +604,11 @@ impl_node_port_use_buffers(struct spa_node *node, b = &this->buffers[i]; b->outbuf = buffers[i]; b->outstanding = false; - b->h = spa_buffer_find_meta_data(buffers[i], this->type.meta.Header, sizeof(*b->h)); + b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h)); - if ((d[0].type == this->type.data.MemPtr || - d[0].type == this->type.data.MemFd || - d[0].type == this->type.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]); } @@ -684,16 +651,14 @@ impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { 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->io.Buffers) + if (id == SPA_ID_IO_Buffers) this->io = data; else return -ENOENT; @@ -799,7 +764,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; @@ -848,18 +813,11 @@ 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) this->data_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } - init_type(&this->type, this->map); this->node = impl_node; reset_props(this, &this->props); @@ -889,7 +847,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 diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c index 9ff609b19..9bb727902 100644 --- a/spa/plugins/v4l2/v4l2-monitor.c +++ b/spa/plugins/v4l2/v4l2-monitor.c @@ -27,9 +27,9 @@ #include #include -#include #include #include +#include #include #define NAME "v4l2-monitor" @@ -40,23 +40,10 @@ struct item { struct udev_device *udevice; }; -struct type { - uint32_t handle_factory; - struct spa_type_monitor monitor; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->handle_factory = spa_type_map_get_id(map, SPA_TYPE__HandleFactory); - spa_type_monitor_map(map, &type->monitor); -} - struct impl { struct spa_handle handle; struct spa_monitor monitor; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *main_loop; @@ -90,7 +77,6 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device * struct spa_pod **result, struct spa_pod_builder *builder) { const char *str, *name; - struct type *t = &this->type; if (item->udevice) udev_device_unref(item->udevice); @@ -112,14 +98,14 @@ static void fill_item(struct impl *this, struct item *item, struct udev_device * name = "Unknown"; spa_pod_builder_add(builder, - "<", 0, t->monitor.MonitorItem, - ":", t->monitor.id, "s", udev_device_get_syspath(item->udevice), - ":", t->monitor.flags, "i", 0, - ":", t->monitor.state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE, - ":", t->monitor.name, "s", name, - ":", t->monitor.klass, "s", "Video/Source", - ":", t->monitor.factory, "p", t->handle_factory, &spa_v4l2_source_factory, - ":", t->monitor.info, "[", + "<", 0, SPA_ID_OBJECT_MonitorItem, + ":", SPA_MONITOR_ITEM_id, "s", udev_device_get_syspath(item->udevice), + ":", SPA_MONITOR_ITEM_flags, "i", SPA_MONITOR_ITEM_FLAG_NONE, + ":", SPA_MONITOR_ITEM_state, "i", SPA_MONITOR_ITEM_STATE_AVAILABLE, + ":", SPA_MONITOR_ITEM_name, "s", name, + ":", SPA_MONITOR_ITEM_class, "s", "Video/Source", + ":", SPA_MONITOR_ITEM_factory, "p", SPA_ID_INTERFACE_HandleFactory, &spa_v4l2_source_factory, + ":", SPA_MONITOR_ITEM_info, "[", NULL); spa_pod_builder_add(builder, @@ -192,11 +178,11 @@ static void impl_on_fd_events(struct spa_source *source) action = "change"; if (strcmp(action, "add") == 0) { - type = this->type.monitor.Added; + type = SPA_ID_EVENT_MONITOR_Added; } else if (strcmp(action, "change") == 0) { - type = this->type.monitor.Changed; + type = SPA_ID_EVENT_MONITOR_Changed; } else if (strcmp(action, "remove") == 0) { - type = this->type.monitor.Removed; + type = SPA_ID_EVENT_MONITOR_Removed; } else return; @@ -314,7 +300,7 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, this = (struct impl *) handle; - if (interface_id == this->type.monitor.Monitor) + if (interface_id == SPA_ID_INTERFACE_Monitor) *interface = &this->monitor; else return -ENOENT; @@ -364,22 +350,15 @@ 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_MainLoop) this->main_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } if (this->main_loop == NULL) { spa_log_error(this->log, "a main-loop is needed"); return -EINVAL; } - init_type(&this->type, this->map); this->monitor = impl_monitor; @@ -387,7 +366,7 @@ impl_init(const struct spa_handle_factory *factory, } static const struct spa_interface_info impl_interfaces[] = { - {SPA_TYPE__Monitor,}, + {SPA_ID_INTERFACE_Monitor,}, }; static int diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index f66ca56bc..39beedea0 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -24,7 +24,6 @@ #include -#include #include #include #include @@ -66,71 +65,6 @@ struct buffer { void *ptr; }; -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_unknown; - uint32_t prop_device; - uint32_t prop_device_name; - uint32_t prop_device_fd; - uint32_t prop_brightness; - uint32_t prop_contrast; - uint32_t prop_saturation; - uint32_t prop_hue; - uint32_t prop_gamma; - uint32_t prop_exposure; - uint32_t prop_gain; - uint32_t prop_sharpness; - 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_media_subtype_video media_subtype_video; - struct spa_type_format_video format_video; - struct spa_type_video_format video_format; - struct spa_type_event_node event_node; - struct spa_type_command_node command_node; - struct spa_type_param_buffers param_buffers; - struct spa_type_param_meta param_meta; - struct spa_type_param_io param_io; - struct spa_type_meta meta; - struct spa_type_data data; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->prop_unknown = spa_type_map_get_id(map, SPA_TYPE_PROPS__unknown); - type->prop_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->prop_device_name = spa_type_map_get_id(map, SPA_TYPE_PROPS__deviceName); - type->prop_device_fd = spa_type_map_get_id(map, SPA_TYPE_PROPS__deviceFd); - type->prop_brightness = spa_type_map_get_id(map, SPA_TYPE_PROPS__brightness); - type->prop_contrast = spa_type_map_get_id(map, SPA_TYPE_PROPS__contrast); - type->prop_saturation = spa_type_map_get_id(map, SPA_TYPE_PROPS__saturation); - type->prop_hue = spa_type_map_get_id(map, SPA_TYPE_PROPS__hue); - type->prop_gamma = spa_type_map_get_id(map, SPA_TYPE_PROPS__gamma); - type->prop_exposure = spa_type_map_get_id(map, SPA_TYPE_PROPS__exposure); - type->prop_gain = spa_type_map_get_id(map, SPA_TYPE_PROPS__gain); - type->prop_sharpness = spa_type_map_get_id(map, SPA_TYPE_PROPS__sharpness); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_format_video_map(map, &type->format_video); - spa_type_video_format_map(map, &type->video_format); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_param_map(map, &type->param); - spa_type_param_buffers_map(map, &type->param_buffers); - spa_type_param_meta_map(map, &type->param_meta); - spa_type_io_map(map, &type->io); - spa_type_param_io_map(map, &type->param_io); -} - #define MAX_CONTROLS 64 struct control { @@ -184,9 +118,7 @@ struct impl { struct spa_handle handle; struct spa_node node; - struct spa_type_map *map; struct spa_log *log; - struct type type; uint32_t seq; @@ -212,7 +144,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -222,67 +153,74 @@ static int impl_node_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; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idPropInfo, - t->param.idProps }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + SPA_ID_PARAM_Props }; 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.idPropInfo) { + case SPA_ID_PARAM_PropInfo: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_device, - ":", t->param.propName, "s", "The V4L2 device", - ":", t->param.propType, "S", p->device, sizeof(p->device)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_device, + ":", SPA_PROP_INFO_name, "s", "The V4L2 device", + ":", SPA_PROP_INFO_type, "S", p->device, sizeof(p->device)); break; case 1: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_device_name, - ":", t->param.propName, "s", "The V4L2 device name", - ":", t->param.propType, "S-r", p->device_name, sizeof(p->device_name)); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceName, + ":", SPA_PROP_INFO_name, "s", "The V4L2 device name", + ":", SPA_PROP_INFO_type, "S-r", p->device_name, sizeof(p->device_name)); break; case 2: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_device_fd, - ":", t->param.propName, "s", "The V4L2 fd", - ":", t->param.propType, "i-r", p->device_fd); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_deviceFd, + ":", SPA_PROP_INFO_name, "s", "The V4L2 fd", + ":", SPA_PROP_INFO_type, "i-r", p->device_fd); break; default: return 0; } + break; } - else if (id == t->param.idProps) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_device, "S", p->device, sizeof(p->device), - ":", t->prop_device_name, "S-r", p->device_name, sizeof(p->device_name), - ":", t->prop_device_fd, "i-r", p->device_fd); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "S", p->device, sizeof(p->device), + ":", SPA_PROP_deviceName, "S-r", p->device_name, sizeof(p->device_name), + ":", SPA_PROP_deviceFd, "i-r", p->device_fd); break; default: return 0; } + break; } - else + default: return -ENOENT; + } (*index)++; @@ -297,14 +235,14 @@ static int impl_node_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; - if (id == t->param.idProps) { + switch (id) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; if (param == NULL) { @@ -312,11 +250,12 @@ static int impl_node_set_param(struct spa_node *node, return 0; } spa_pod_object_parse(param, - ":", t->prop_device, "?S", p->device, sizeof(p->device), NULL); + ":", SPA_PROP_device, "?S", p->device, sizeof(p->device), NULL); + break; } - else + default: return -ENOENT; - + } return 0; } @@ -330,7 +269,9 @@ 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: + { struct port *port = GET_OUT_PORT(this, 0); if (!port->have_format) @@ -340,12 +281,15 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman if ((res = spa_v4l2_stream_on(this)) < 0) return res; - - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + } + case SPA_ID_COMMAND_NODE_Pause: if ((res = spa_v4l2_stream_off(this)) < 0) return res; - } else + break; + default: return -ENOTSUP; + } return 0; } @@ -443,7 +387,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) @@ -451,28 +394,33 @@ static int port_get_format(struct spa_node *node, if (*index > 0) return 0; - spa_pod_builder_push_object(builder, t->param.idFormat, t->format); + spa_pod_builder_push_object(builder, SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format); spa_pod_builder_add(builder, "I", port->current_format.media_type, "I", port->current_format.media_subtype, 0); - if (port->current_format.media_subtype == t->media_subtype.raw) { + switch (port->current_format.media_subtype) { + case SPA_MEDIA_SUBTYPE_raw: spa_pod_builder_add(builder, - ":", t->format_video.format, "I", port->current_format.info.raw.format, - ":", t->format_video.size, "R", &port->current_format.info.raw.size, - ":", t->format_video.framerate, "F", &port->current_format.info.raw.framerate, 0); - } else if (port->current_format.media_subtype == t->media_subtype_video.mjpg || - port->current_format.media_subtype == t->media_subtype_video.jpeg) { + ":", SPA_FORMAT_VIDEO_format, "I", port->current_format.info.raw.format, + ":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.raw.size, + ":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.raw.framerate, 0); + break; + case SPA_MEDIA_SUBTYPE_mjpg: + case SPA_MEDIA_SUBTYPE_jpeg: spa_pod_builder_add(builder, - ":", t->format_video.size, "R", &port->current_format.info.mjpg.size, - ":", t->format_video.framerate, "F", &port->current_format.info.mjpg.framerate, 0); - } else if (port->current_format.media_subtype == t->media_subtype_video.h264) { + ":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.mjpg.size, + ":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.mjpg.framerate, 0); + break; + case SPA_MEDIA_SUBTYPE_h264: spa_pod_builder_add(builder, - ":", t->format_video.size, "R", &port->current_format.info.h264.size, - ":", t->format_video.framerate, "F", &port->current_format.info.h264.framerate, 0); - } else + ":", SPA_FORMAT_VIDEO_size, "R", &port->current_format.info.h264.size, + ":", SPA_FORMAT_VIDEO_framerate, "F", &port->current_format.info.h264.framerate, 0); + break; + default: return -EIO; + } *param = spa_pod_builder_pop(builder); @@ -490,7 +438,6 @@ static int impl_node_port_enum_params(struct spa_node *node, struct impl *this; struct port *port; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -501,7 +448,6 @@ static int 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); @@ -510,81 +456,87 @@ static int 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.idPropsIn }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + 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_PropInfo: + return spa_v4l2_enum_controls(this, index, filter, result, builder); + + case SPA_ID_PARAM_EnumFormat: return spa_v4l2_enum_format(this, index, filter, result, builder); - } - else if (id == t->param.idFormat) { + + case SPA_ID_PARAM_Format: if((res = port_get_format(node, direction, port_id, index, filter, ¶m, &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, "i", port->fmt.fmt.pix.sizeimage, - ":", t->param_buffers.stride, "i", port->fmt.fmt.pix.bytesperline, - ":", t->param_buffers.buffers, "iru", MAX_BUFFERS, + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "iru", MAX_BUFFERS, 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", port->fmt.fmt.pix.sizeimage, + ":", SPA_PARAM_BUFFERS_stride, "i", port->fmt.fmt.pix.bytesperline, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; + + case SPA_ID_PARAM_Meta: 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; } - } + break; +#if 0 else if (id == t->param_io.idPropsIn) { return spa_v4l2_enum_controls(this, index, filter, result, builder); } - else if (id == t->param_io.idBuffers) { +#endif + 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; + case 1: + param = spa_pod_builder_object(&b, + id, SPA_ID_OBJECT_ParamIO, + ":", SPA_PARAM_IO_id, "I", SPA_ID_IO_Clock, + ":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_clock)); break; default: return 0; } - } - else if (id == t->param_io.idClock) { - switch (*index) { - case 0: - param = spa_pod_builder_object(&b, - id, t->param_io.Clock, - ":", t->param_io.id, "I", t->io.Clock, - ":", t->param_io.size, "i", sizeof(struct spa_io_clock)); - break; - default: - return 0; - } - } - else + break; + default: return -ENOENT; + } (*index)++; @@ -601,7 +553,6 @@ static int port_set_format(struct spa_node *node, { struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); struct spa_video_info info; - struct type *t = &this->type; struct port *port = GET_PORT(this, direction, port_id); if (format == NULL) { @@ -615,13 +566,14 @@ static int port_set_format(struct spa_node *node, "I", &info.media_type, "I", &info.media_subtype); - if (info.media_type != t->media_type.video) { + if (info.media_type != SPA_MEDIA_TYPE_video) { spa_log_error(this->log, "media type must be video"); return -EINVAL; } - if (info.media_subtype == t->media_subtype.raw) { - if (spa_format_video_raw_parse(format, &info.info.raw, &t->format_video) < 0) { + switch (info.media_subtype) { + case SPA_MEDIA_SUBTYPE_raw: + if (spa_format_video_raw_parse(format, &info.info.raw) < 0) { spa_log_error(this->log, "can't parse video raw"); return -EINVAL; } @@ -632,8 +584,9 @@ static int port_set_format(struct spa_node *node, info.info.raw.size.width == port->current_format.info.raw.size.width && info.info.raw.size.height == port->current_format.info.raw.size.height) return 0; - } else if (info.media_subtype == t->media_subtype_video.mjpg) { - if (spa_format_video_mjpg_parse(format, &info.info.mjpg, &t->format_video) < 0) + break; + case SPA_MEDIA_SUBTYPE_mjpg: + if (spa_format_video_mjpg_parse(format, &info.info.mjpg) < 0) return -EINVAL; if (port->have_format && info.media_type == port->current_format.media_type && @@ -641,8 +594,9 @@ static int port_set_format(struct spa_node *node, info.info.mjpg.size.width == port->current_format.info.mjpg.size.width && info.info.mjpg.size.height == port->current_format.info.mjpg.size.height) return 0; - } else if (info.media_subtype == t->media_subtype_video.h264) { - if (spa_format_video_h264_parse(format, &info.info.h264, &t->format_video) < 0) + break; + case SPA_MEDIA_SUBTYPE_h264: + if (spa_format_video_h264_parse(format, &info.info.h264) < 0) return -EINVAL; if (port->have_format && info.media_type == port->current_format.media_type && @@ -650,6 +604,9 @@ static int port_set_format(struct spa_node *node, info.info.h264.size.width == port->current_format.info.h264.size.width && info.info.h264.size.height == port->current_format.info.h264.size.height) return 0; + break; + default: + return -EINVAL; } } @@ -674,17 +631,11 @@ static int impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -772,23 +723,21 @@ static int impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { struct impl *this; - struct type *t; struct port *port; struct control *control; 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.Clock) { + else if (id == SPA_ID_IO_Clock) { port->clock = data; } else if ((control = find_control(port, id))) { @@ -934,7 +883,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; @@ -976,19 +925,13 @@ impl_init(const struct spa_handle_factory *factory, port = GET_OUT_PORT(this, 0); 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_MainLoop) port->main_loop = support[i].data; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) port->data_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } if (port->main_loop == NULL) { spa_log_error(this->log, "a main_loop is needed"); return -EINVAL; @@ -997,7 +940,6 @@ impl_init(const struct spa_handle_factory *factory, spa_log_error(this->log, "a data_loop is needed"); return -EINVAL; } - init_type(&this->type, this->map); this->node = impl_node; @@ -1023,7 +965,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 impl_enum_interface_info(const struct spa_handle_factory *factory, diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index bd303f302..f67d08893 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -190,59 +190,59 @@ static int spa_v4l2_close(struct impl *this) struct format_info { uint32_t fourcc; - off_t format_offset; - off_t media_type_offset; - off_t media_subtype_offset; + uint32_t format; + uint32_t media_type; + uint32_t media_subtype; }; -#define VIDEO offsetof(struct type, media_type.video) -#define IMAGE offsetof(struct type, media_type.image) +#define VIDEO SPA_MEDIA_TYPE_video +#define IMAGE SPA_MEDIA_TYPE_image -#define RAW offsetof(struct type, media_subtype.raw) +#define RAW SPA_MEDIA_SUBTYPE_raw -#define BAYER offsetof(struct type, media_subtype_video.bayer) -#define MJPG offsetof(struct type, media_subtype_video.mjpg) -#define JPEG offsetof(struct type, media_subtype_video.jpeg) -#define DV offsetof(struct type, media_subtype_video.dv) -#define MPEGTS offsetof(struct type, media_subtype_video.mpegts) -#define H264 offsetof(struct type, media_subtype_video.h264) -#define H263 offsetof(struct type, media_subtype_video.h263) -#define MPEG1 offsetof(struct type, media_subtype_video.mpeg1) -#define MPEG2 offsetof(struct type, media_subtype_video.mpeg2) -#define MPEG4 offsetof(struct type, media_subtype_video.mpeg4) -#define XVID offsetof(struct type, media_subtype_video.xvid) -#define VC1 offsetof(struct type, media_subtype_video.vc1) -#define VP8 offsetof(struct type, media_subtype_video.vp8) +#define BAYER SPA_MEDIA_SUBTYPE_bayer +#define MJPG SPA_MEDIA_SUBTYPE_mjpg +#define JPEG SPA_MEDIA_SUBTYPE_jpeg +#define DV SPA_MEDIA_SUBTYPE_dv +#define MPEGTS SPA_MEDIA_SUBTYPE_mpegts +#define H264 SPA_MEDIA_SUBTYPE_h264 +#define H263 SPA_MEDIA_SUBTYPE_h263 +#define MPEG1 SPA_MEDIA_SUBTYPE_mpeg1 +#define MPEG2 SPA_MEDIA_SUBTYPE_mpeg2 +#define MPEG4 SPA_MEDIA_SUBTYPE_mpeg4 +#define XVID SPA_MEDIA_SUBTYPE_xvid +#define VC1 SPA_MEDIA_SUBTYPE_vc1 +#define VP8 SPA_MEDIA_SUBTYPE_vp8 -#define FORMAT_UNKNOWN offsetof(struct type, video_format.UNKNOWN) -#define FORMAT_ENCODED offsetof(struct type, video_format.ENCODED) -#define FORMAT_RGB15 offsetof(struct type, video_format.RGB15) -#define FORMAT_BGR15 offsetof(struct type, video_format.BGR15) -#define FORMAT_RGB16 offsetof(struct type, video_format.RGB16) -#define FORMAT_BGR offsetof(struct type, video_format.BGR) -#define FORMAT_RGB offsetof(struct type, video_format.RGB) -#define FORMAT_BGRA offsetof(struct type, video_format.BGRA) -#define FORMAT_BGRx offsetof(struct type, video_format.BGRx) -#define FORMAT_ARGB offsetof(struct type, video_format.ARGB) -#define FORMAT_xRGB offsetof(struct type, video_format.xRGB) -#define FORMAT_GRAY8 offsetof(struct type, video_format.GRAY8) -#define FORMAT_GRAY16_LE offsetof(struct type, video_format.GRAY16_LE) -#define FORMAT_GRAY16_BE offsetof(struct type, video_format.GRAY16_BE) -#define FORMAT_YVU9 offsetof(struct type, video_format.YVU9) -#define FORMAT_YV12 offsetof(struct type, video_format.YV12) -#define FORMAT_YUY2 offsetof(struct type, video_format.YUY2) -#define FORMAT_YVYU offsetof(struct type, video_format.YVYU) -#define FORMAT_UYVY offsetof(struct type, video_format.UYVY) -#define FORMAT_Y42B offsetof(struct type, video_format.Y42B) -#define FORMAT_Y41B offsetof(struct type, video_format.Y41B) -#define FORMAT_YUV9 offsetof(struct type, video_format.YUV9) -#define FORMAT_I420 offsetof(struct type, video_format.I420) -#define FORMAT_NV12 offsetof(struct type, video_format.NV12) -#define FORMAT_NV12_64Z32 offsetof(struct type, video_format.NV12_64Z32) -#define FORMAT_NV21 offsetof(struct type, video_format.NV21) -#define FORMAT_NV16 offsetof(struct type, video_format.NV16) -#define FORMAT_NV61 offsetof(struct type, video_format.NV61) -#define FORMAT_NV24 offsetof(struct type, video_format.NV24) +#define FORMAT_UNKNOWN SPA_VIDEO_FORMAT_UNKNOWN +#define FORMAT_ENCODED SPA_VIDEO_FORMAT_ENCODED +#define FORMAT_RGB15 SPA_VIDEO_FORMAT_RGB15 +#define FORMAT_BGR15 SPA_VIDEO_FORMAT_BGR15 +#define FORMAT_RGB16 SPA_VIDEO_FORMAT_RGB16 +#define FORMAT_BGR SPA_VIDEO_FORMAT_BGR +#define FORMAT_RGB SPA_VIDEO_FORMAT_RGB +#define FORMAT_BGRA SPA_VIDEO_FORMAT_BGRA +#define FORMAT_BGRx SPA_VIDEO_FORMAT_BGRx +#define FORMAT_ARGB SPA_VIDEO_FORMAT_ARGB +#define FORMAT_xRGB SPA_VIDEO_FORMAT_xRGB +#define FORMAT_GRAY8 SPA_VIDEO_FORMAT_GRAY8 +#define FORMAT_GRAY16_LE SPA_VIDEO_FORMAT_GRAY16_LE +#define FORMAT_GRAY16_BE SPA_VIDEO_FORMAT_GRAY16_BE +#define FORMAT_YVU9 SPA_VIDEO_FORMAT_YVU9 +#define FORMAT_YV12 SPA_VIDEO_FORMAT_YV12 +#define FORMAT_YUY2 SPA_VIDEO_FORMAT_YUY2 +#define FORMAT_YVYU SPA_VIDEO_FORMAT_YVYU +#define FORMAT_UYVY SPA_VIDEO_FORMAT_UYVY +#define FORMAT_Y42B SPA_VIDEO_FORMAT_Y42B +#define FORMAT_Y41B SPA_VIDEO_FORMAT_Y41B +#define FORMAT_YUV9 SPA_VIDEO_FORMAT_YUV9 +#define FORMAT_I420 SPA_VIDEO_FORMAT_I420 +#define FORMAT_NV12 SPA_VIDEO_FORMAT_NV12 +#define FORMAT_NV12_64Z32 SPA_VIDEO_FORMAT_NV12_64Z32 +#define FORMAT_NV21 SPA_VIDEO_FORMAT_NV21 +#define FORMAT_NV16 SPA_VIDEO_FORMAT_NV16 +#define FORMAT_NV61 SPA_VIDEO_FORMAT_NV61 +#define FORMAT_NV24 SPA_VIDEO_FORMAT_NV24 static const struct format_info format_info[] = { /* RGB formats */ @@ -376,8 +376,7 @@ static const struct format_info *video_format_to_format_info(uint32_t format) } #endif -static const struct format_info *find_format_info_by_media_type(struct type *types, - uint32_t type, +static const struct format_info *find_format_info_by_media_type(uint32_t type, uint32_t subtype, uint32_t format, int startidx) @@ -385,37 +384,33 @@ static const struct format_info *find_format_info_by_media_type(struct type *typ int i; for (i = startidx; i < SPA_N_ELEMENTS(format_info); i++) { - uint32_t media_type, media_subtype, media_format; - - media_type = *SPA_MEMBER(types, format_info[i].media_type_offset, uint32_t); - media_subtype = *SPA_MEMBER(types, format_info[i].media_subtype_offset, uint32_t); - media_format = *SPA_MEMBER(types, format_info[i].format_offset, uint32_t); - - if ((media_type == type) && - (media_subtype == subtype) && (format == 0 || media_format == format)) + if ((format_info[i].media_type == type) && + (format_info[i].media_subtype == subtype) && + (format == 0 || format_info[i].format == format)) return &format_info[i]; } return NULL; } static uint32_t -enum_filter_format(struct type *type, uint32_t media_type, int32_t media_subtype, +enum_filter_format(uint32_t media_type, int32_t media_subtype, const struct spa_pod *filter, uint32_t index) { uint32_t video_format = 0; - if ((media_type == type->media_type.video || - media_type == type->media_type.image)) { - if (media_subtype == type->media_subtype.raw) { + switch (media_type) { + case SPA_MEDIA_TYPE_video: + case SPA_MEDIA_TYPE_image: + if (media_subtype == SPA_MEDIA_SUBTYPE_raw) { struct spa_pod_prop *p; uint32_t n_values; const uint32_t *values; - if (!(p = spa_pod_find_prop(filter, type->format_video.format))) - return type->video_format.UNKNOWN; + if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_format))) + return SPA_VIDEO_FORMAT_UNKNOWN; if (p->body.value.type != SPA_POD_TYPE_ID) - return type->video_format.UNKNOWN; + return SPA_VIDEO_FORMAT_UNKNOWN; values = SPA_POD_BODY_CONST(&p->body.value); n_values = SPA_POD_PROP_N_VALUES(p); @@ -429,7 +424,7 @@ enum_filter_format(struct type *type, uint32_t media_type, int32_t media_subtype } } else { if (index == 0) - video_format = type->video_format.ENCODED; + video_format = SPA_VIDEO_FORMAT_ENCODED; } } return video_format; @@ -533,9 +528,7 @@ spa_v4l2_enum_format(struct impl *this, int res, n_fractions; const struct format_info *info; struct spa_pod_prop *prop; - uint32_t media_type, media_subtype, video_format; - uint32_t filter_media_type, filter_media_subtype; - struct type *t = &this->type; + uint32_t filter_media_type, filter_media_subtype, video_format; if ((res = spa_v4l2_open(this)) < 0) return res; @@ -564,16 +557,14 @@ spa_v4l2_enum_format(struct impl *this, while (port->next_fmtdesc) { if (filter) { - video_format = enum_filter_format(t, - filter_media_type, + video_format = enum_filter_format(filter_media_type, filter_media_subtype, filter, port->fmtdesc.index); - if (video_format == t->video_format.UNKNOWN) + if (video_format == SPA_VIDEO_FORMAT_UNKNOWN) goto enum_end; - info = find_format_info_by_media_type(t, - filter_media_type, + info = find_format_info_by_media_type(filter_media_type, filter_media_subtype, video_format, 0); if (info == NULL) @@ -602,7 +593,7 @@ spa_v4l2_enum_format(struct impl *this, struct spa_pod_prop *p; /* check if we have a fixed frame size */ - if (!(p = spa_pod_find_prop(filter, t->format_video.size))) + if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size))) goto do_frmsize; if (p->body.value.type != SPA_POD_TYPE_RECTANGLE) { @@ -638,7 +629,7 @@ spa_v4l2_enum_format(struct impl *this, uint32_t i, n_values; /* check if we have a fixed frame size */ - if (!(p = spa_pod_find_prop(filter, t->format_video.size))) + if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_size))) goto have_size; range = p->body.flags & SPA_POD_PROP_RANGE_MASK; @@ -684,25 +675,21 @@ spa_v4l2_enum_format(struct impl *this, } } - media_type = *SPA_MEMBER(t, info->media_type_offset, uint32_t); - media_subtype = *SPA_MEMBER(t, info->media_subtype_offset, uint32_t); - video_format = *SPA_MEMBER(t, info->format_offset, uint32_t); - - spa_pod_builder_push_object(builder, t->param.idEnumFormat, t->format); + spa_pod_builder_push_object(builder, SPA_ID_PARAM_EnumFormat, SPA_ID_OBJECT_Format); spa_pod_builder_add(builder, - "I", media_type, - "I", media_subtype, 0); + "I", info->media_type, + "I", info->media_subtype, 0); - if (media_subtype == t->media_subtype.raw) { + if (info->media_subtype == SPA_MEDIA_SUBTYPE_raw) { spa_pod_builder_add(builder, - ":", t->format_video.format, "I", video_format, 0); + ":", SPA_FORMAT_VIDEO_format, "I", info->format, 0); } spa_pod_builder_add(builder, - ":", t->format_video.size, "R", &SPA_RECTANGLE(port->frmsize.discrete.width, - port->frmsize.discrete.height), 0); + ":", SPA_FORMAT_VIDEO_size, "R", &SPA_RECTANGLE(port->frmsize.discrete.width, + port->frmsize.discrete.height), 0); prop = spa_pod_builder_deref(builder, - spa_pod_builder_push_prop(builder, t->format_video.framerate, + spa_pod_builder_push_prop(builder, SPA_FORMAT_VIDEO_framerate, SPA_POD_PROP_RANGE_NONE | SPA_POD_PROP_FLAG_UNSET)); n_fractions = 0; @@ -727,7 +714,7 @@ spa_v4l2_enum_format(struct impl *this, uint32_t i, n_values; const struct spa_fraction step = { 1, 1 }, *values; - if (!(p = spa_pod_find_prop(filter, t->format_video.framerate))) + if (!(p = spa_pod_find_prop(filter, SPA_FORMAT_VIDEO_framerate))) goto have_framerate; if (p->body.value.type != SPA_POD_TYPE_FRACTION) @@ -824,32 +811,35 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format, uint32_t video_format; struct spa_rectangle *size = NULL; struct spa_fraction *framerate = NULL; - struct type *t = &this->type; spa_zero(fmt); spa_zero(streamparm); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (format->media_subtype == this->type.media_subtype.raw) { + switch (format->media_subtype) { + case SPA_MEDIA_SUBTYPE_raw: video_format = format->info.raw.format; size = &format->info.raw.size; framerate = &format->info.raw.framerate; - } else if (format->media_subtype == this->type.media_subtype_video.mjpg || - format->media_subtype == this->type.media_subtype_video.jpeg) { - video_format = this->type.video_format.ENCODED; + break; + case SPA_MEDIA_SUBTYPE_mjpg: + case SPA_MEDIA_SUBTYPE_jpeg: + video_format = SPA_VIDEO_FORMAT_ENCODED; size = &format->info.mjpg.size; framerate = &format->info.mjpg.framerate; - } else if (format->media_subtype == this->type.media_subtype_video.h264) { - video_format = this->type.video_format.ENCODED; + break; + case SPA_MEDIA_SUBTYPE_h264: + video_format = SPA_VIDEO_FORMAT_ENCODED; size = &format->info.h264.size; framerate = &format->info.h264.framerate; - } else { - video_format = this->type.video_format.ENCODED; + break; + default: + video_format = SPA_VIDEO_FORMAT_ENCODED; + break; } - info = find_format_info_by_media_type(t, - format->media_type, + info = find_format_info_by_media_type(format->media_type, format->media_subtype, video_format, 0); if (info == NULL || size == NULL || framerate == NULL) { spa_log_error(port->log, "v4l2: unknown media type %d %d %d", format->media_type, @@ -965,23 +955,23 @@ static uint32_t control_to_prop_id(struct impl *impl, uint32_t control_id) { switch (control_id) { case V4L2_CID_BRIGHTNESS: - return impl->type.prop_brightness; + return SPA_PROP_brightness; case V4L2_CID_CONTRAST: - return impl->type.prop_contrast; + return SPA_PROP_contrast; case V4L2_CID_SATURATION: - return impl->type.prop_saturation; + return SPA_PROP_saturation; case V4L2_CID_HUE: - return impl->type.prop_hue; + return SPA_PROP_hue; case V4L2_CID_GAMMA: - return impl->type.prop_gamma; + return SPA_PROP_gamma; case V4L2_CID_EXPOSURE: - return impl->type.prop_exposure; + return SPA_PROP_exposure; case V4L2_CID_GAIN: - return impl->type.prop_gain; + return SPA_PROP_gain; case V4L2_CID_SHARPNESS: - return impl->type.prop_sharpness; + return SPA_PROP_sharpness; default: - return impl->type.prop_unknown; + return SPA_PROP_unknown; } } @@ -993,12 +983,10 @@ spa_v4l2_enum_controls(struct impl *this, struct spa_pod_builder *builder) { struct port *port = &this->out_ports[0]; - struct type *t = &this->type; struct v4l2_query_ext_ctrl queryctrl; struct spa_pod *param; struct spa_pod_builder b = { 0 }; - char type_id[128]; - uint32_t id, prop_id, ctrl_id; + uint32_t prop_id, ctrl_id; uint8_t buffer[1024]; int res; const unsigned next_fl = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND; @@ -1051,12 +1039,9 @@ spa_v4l2_enum_controls(struct impl *this, spa_pod_builder_init(&b, buffer, sizeof(buffer)); - snprintf(type_id, sizeof(type_id), SPA_TYPE_PARAM_IO_PROP_BASE"%08x", ctrl_id); - id = spa_type_map_get_id(this->map, type_id); - prop_id = control_to_prop_id(this, ctrl_id); - port->controls[port->n_controls].id = id; + port->controls[port->n_controls].id = prop_id; port->controls[port->n_controls].ctrl_id = ctrl_id; port->controls[port->n_controls].value = queryctrl.default_value; @@ -1067,42 +1052,36 @@ spa_v4l2_enum_controls(struct impl *this, switch (queryctrl.type) { case V4L2_CTRL_TYPE_INTEGER: param = spa_pod_builder_object(&b, - t->param_io.idPropsIn, t->param_io.Prop, - ":", t->param_io.id, "I", id, - ":", t->param_io.size, "i", sizeof(struct spa_pod_int), - ":", t->param.propId, "I", prop_id, - ":", t->param.propType, "isu", queryctrl.default_value, - 3, queryctrl.minimum, - queryctrl.maximum, - queryctrl.step, - ":", t->param.propName, "s", queryctrl.name); + SPA_ID_PARAM_PropInfo, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", prop_id, + ":", SPA_PROP_INFO_type, "isu", queryctrl.default_value, + SPA_POD_PROP_STEP(queryctrl.minimum, + queryctrl.maximum, + queryctrl.step), + ":", SPA_PROP_INFO_name, "s", queryctrl.name); break; case V4L2_CTRL_TYPE_BOOLEAN: param = spa_pod_builder_object(&b, - t->param_io.idPropsIn, t->param_io.Prop, - ":", t->param_io.id, "I", id, - ":", t->param_io.size, "i", sizeof(struct spa_pod_bool), - ":", t->param.propId, "I", prop_id, - ":", t->param.propType, "b-u", queryctrl.default_value, - ":", t->param.propName, "s", queryctrl.name); + SPA_ID_PARAM_PropInfo, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", prop_id, + ":", SPA_PROP_INFO_type, "b-u", queryctrl.default_value, + ":", SPA_PROP_INFO_name, "s", queryctrl.name); break; case V4L2_CTRL_TYPE_MENU: { struct v4l2_querymenu querymenu; - spa_pod_builder_push_object(&b, t->param_io.idPropsIn, t->param_io.Prop); + spa_pod_builder_push_object(&b, SPA_ID_PARAM_PropInfo, SPA_ID_OBJECT_PropInfo); spa_pod_builder_add(&b, - ":", t->param_io.id, "I", id, - ":", t->param_io.size, "i", sizeof(struct spa_pod_double), - ":", t->param.propId, "I", prop_id, - ":", t->param.propName, "s", queryctrl.name, - ":", t->param.propType, "i-u", queryctrl.default_value, + ":", SPA_PROP_INFO_id, "I", prop_id, + ":", SPA_PROP_INFO_type, "i-u", queryctrl.default_value, + ":", SPA_PROP_INFO_name, "s", queryctrl.name, NULL); spa_zero(querymenu); querymenu.id = queryctrl.id; - spa_pod_builder_push_prop(&b, t->param.propLabels, 0); + spa_pod_builder_push_prop(&b, SPA_PROP_INFO_labels, 0); spa_pod_builder_push_struct(&b); for (querymenu.index = queryctrl.minimum; querymenu.index <= queryctrl.maximum; @@ -1218,14 +1197,13 @@ static int spa_v4l2_use_buffers(struct impl *this, struct spa_buffer **buffers, if (n_buffers > 0) { d = buffers[0]->datas; - if (d[0].type == this->type.data.MemFd || - (d[0].type == this->type.data.MemPtr && d[0].data != NULL)) { + if (d[0].type == SPA_DATA_MemFd || + (d[0].type == SPA_DATA_MemPtr && d[0].data != NULL)) { port->memtype = V4L2_MEMORY_USERPTR; - } else if (d[0].type == this->type.data.DmaBuf) { + } else if (d[0].type == SPA_DATA_DmaBuf) { port->memtype = V4L2_MEMORY_DMABUF; } else { - spa_log_error(port->log, "v4l2: can't use buffers of type %s (%d)", - spa_type_map_get_type (this->map, d[0].type), d[0].type); + spa_log_error(port->log, "v4l2: can't use buffers of type %d", d[0].type); return -EINVAL; } } @@ -1251,7 +1229,7 @@ static int spa_v4l2_use_buffers(struct impl *this, struct spa_buffer **buffers, b = &port->buffers[i]; b->outbuf = buffers[i]; b->flags = BUFFER_FLAG_OUTSTANDING; - b->h = spa_buffer_find_meta_data(buffers[i], this->type.meta.Header, sizeof(*b->h)); + b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h)); spa_log_info(port->log, "v4l2: import buffer %p", buffers[i]); @@ -1345,7 +1323,7 @@ mmap_init(struct impl *this, b = &port->buffers[i]; b->outbuf = buffers[i]; b->flags = BUFFER_FLAG_OUTSTANDING; - b->h = spa_buffer_find_meta_data(buffers[i], this->type.meta.Header, sizeof(*b->h)); + b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h)); spa_zero(b->v4l2_buffer); b->v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -1375,12 +1353,12 @@ mmap_init(struct impl *this, spa_log_error(port->log, "VIDIOC_EXPBUF: %m"); continue; } - d[0].type = this->type.data.DmaBuf; + d[0].type = SPA_DATA_DmaBuf; d[0].fd = expbuf.fd; d[0].data = NULL; SPA_FLAG_SET(b->flags, BUFFER_FLAG_ALLOCATED); } else { - d[0].type = this->type.data.MemPtr; + d[0].type = SPA_DATA_MemPtr; d[0].fd = -1; d[0].data = mmap(NULL, b->v4l2_buffer.length, diff --git a/spa/plugins/videotestsrc/draw.c b/spa/plugins/videotestsrc/draw.c index 193ad19c8..5217736ea 100644 --- a/spa/plugins/videotestsrc/draw.c +++ b/spa/plugins/videotestsrc/draw.c @@ -135,13 +135,13 @@ static int drawing_data_init(DrawingData * dd, struct impl *this, char *data) struct spa_video_info *format = &this->current_format; struct spa_rectangle *size = &format->info.raw.size; - if ((format->media_type != this->type.media_type.video) || - (format->media_subtype != this->type.media_subtype.raw)) + if ((format->media_type != SPA_MEDIA_TYPE_video) || + (format->media_subtype != SPA_MEDIA_SUBTYPE_raw)) return -ENOTSUP; - if (format->info.raw.format == this->type.video_format.RGB) { + if (format->info.raw.format == SPA_VIDEO_FORMAT_RGB) { dd->draw_pixel = draw_pixel_rgb; - } else if (format->info.raw.format == this->type.video_format.UYVY) { + } else if (format->info.raw.format == SPA_VIDEO_FORMAT_UYVY) { dd->draw_pixel = draw_pixel_uyvy; } else return -ENOTSUP; diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index 58e120f8f..1bbbb8e4e 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -41,47 +40,6 @@ #define FRAMES_TO_TIME(this,f) ((this->current_format.info.raw.framerate.denom * (f) * SPA_NSEC_PER_SEC) / \ (this->current_format.info.raw.framerate.num)) -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_live; - uint32_t prop_pattern; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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; - struct spa_type_event_node event_node; - struct spa_type_command_node command_node; - struct spa_type_param_buffers param_buffers; - struct spa_type_param_meta param_meta; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->prop_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - type->prop_pattern = spa_type_map_get_id(map, SPA_TYPE_PROPS__patternType); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_param_buffers_map(map, &type->param_buffers); - spa_type_param_meta_map(map, &type->param_meta); -} - enum pattern { PATTERN_SMPTE_SNOW, PATTERN_SNOW, @@ -115,8 +73,6 @@ struct impl { struct spa_handle handle; struct spa_node node; - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *data_loop; @@ -157,7 +113,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod *param; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; @@ -166,62 +121,69 @@ static int impl_node_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; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idPropInfo, - t->param.idProps }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + SPA_ID_PARAM_Props }; 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.idPropInfo) { + case SPA_ID_PARAM_PropInfo: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_live, - ":", t->param.propName, "s", "Configure live mode of the source", - ":", t->param.propType, "b", p->live); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_live, + ":", SPA_PROP_INFO_name, "s", "Configure live mode of the source", + ":", SPA_PROP_INFO_type, "b", p->live); break; case 1: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_pattern, - ":", t->param.propName, "s", "The pattern", - ":", t->param.propType, "i", p->pattern, - ":", t->param.propLabels, "[-i", + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_patternType, + ":", SPA_PROP_INFO_name, "s", "The pattern", + ":", SPA_PROP_INFO_type, "i", p->pattern, + ":", SPA_PROP_INFO_labels, "[-i", "i", PATTERN_SMPTE_SNOW, "s", "SMPTE snow", "i", PATTERN_SNOW, "s", "Snow", "]"); break; default: return 0; } + break; } - else if (id == t->param.idProps) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_live, "b", p->live, - ":", t->prop_pattern, "i", p->pattern); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_live, "b", p->live, + ":", SPA_PROP_patternType, "i", p->pattern); break; default: return 0; } + break; } - else + default: return -ENOENT; + } (*index)++; @@ -235,14 +197,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag 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; - if (id == t->param.idProps) { + switch (id) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; if (param == NULL) { @@ -250,8 +212,8 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } spa_pod_object_parse(param, - ":", t->prop_live, "?b", &p->live, - ":", t->prop_pattern, "?i", &p->pattern, + ":", SPA_PROP_live, "?b", &p->live, + ":", SPA_PROP_patternType, "?i", &p->pattern, NULL); if (p->live) @@ -259,9 +221,9 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag else this->info.flags &= ~SPA_PORT_INFO_FLAG_LIVE; } - else + default: return -ENOENT; - + } return 0; } @@ -365,7 +327,9 @@ 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: + { struct timespec now; if (!this->have_format) @@ -386,7 +350,9 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = true; set_timer(this, true); - } else if (SPA_COMMAND_TYPE(command) == this->type.command_node.Pause) { + break; + } + case SPA_ID_COMMAND_NODE_Pause: if (!this->have_format) return -EIO; if (this->n_buffers == 0) @@ -397,9 +363,10 @@ static int impl_node_send_command(struct spa_node *node, const struct spa_comman this->started = false; set_timer(this, false); - } else + break; + default: return -ENOTSUP; - + } return 0; } @@ -494,22 +461,19 @@ static int port_enum_formats(struct spa_node *node, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct type *t = &this->type; - switch (*index) { case 0: *param = spa_pod_builder_object(builder, - t->param.idEnumFormat, t->format, - "I", t->media_type.video, - "I", t->media_subtype.raw, - ":", t->format_video.format, "Ieu", t->video_format.RGB, - SPA_POD_PROP_ENUM(2, t->video_format.RGB, - t->video_format.UYVY), - ":", t->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, "Ieu", SPA_VIDEO_FORMAT_RGB, + SPA_POD_PROP_ENUM(2, SPA_VIDEO_FORMAT_RGB, + SPA_VIDEO_FORMAT_UYVY), + ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320, 240), SPA_POD_PROP_MIN_MAX(&SPA_RECTANGLE(1, 1), &SPA_RECTANGLE(INT32_MAX, INT32_MAX)), - ":", t->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(INT32_MAX, 1))); break; @@ -527,7 +491,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; if (!this->have_format) return -EIO; @@ -535,12 +498,12 @@ 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.video, - "I", t->media_subtype.raw, - ":", t->format_video.format, "I", this->current_format.info.raw.format, - ":", t->format_video.size, "R", &this->current_format.info.raw.size, - ":", t->format_video.framerate, "F", &this->current_format.info.raw.framerate); + SPA_ID_PARAM_Format, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_video, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_VIDEO_format, "I", this->current_format.info.raw.format, + ":", SPA_FORMAT_VIDEO_size, "R", &this->current_format.info.raw.size, + ":", SPA_FORMAT_VIDEO_framerate, "F", &this->current_format.info.raw.framerate); return 1; } @@ -554,7 +517,6 @@ impl_node_port_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -565,34 +527,39 @@ 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); 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 }; + 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 }; 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, filter, ¶m, &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, filter, ¶m, &b)) <= 0) return res; - } - else if (id == t->param.idBuffers) { + break; + + case SPA_ID_PARAM_Buffers: + { struct spa_video_info_raw *raw_info = &this->current_format.info.raw; if (!this->have_format) @@ -601,31 +568,34 @@ impl_node_port_enum_params(struct spa_node *node, return 0; param = spa_pod_builder_object(&b, - id, t->param_buffers.Buffers, - ":", t->param_buffers.size, "i", this->stride * raw_info->size.height, - ":", t->param_buffers.stride, "i", this->stride, - ":", t->param_buffers.buffers, "ir", 2, + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "ir", 2, SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS), - ":", t->param_buffers.align, "i", 16); + ":", SPA_PARAM_BUFFERS_blocks, "i", 1, + ":", SPA_PARAM_BUFFERS_size, "i", this->stride * raw_info->size.height, + ":", SPA_PARAM_BUFFERS_stride, "i", this->stride, + ":", SPA_PARAM_BUFFERS_align, "i", 16); + break; } - else if (id == t->param.idMeta) { + case SPA_ID_PARAM_Meta: if (!this->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 + break; + default: return -ENOENT; + } (*index)++; @@ -664,16 +634,16 @@ static int port_set_format(struct spa_node *node, "I", &info.media_type, "I", &info.media_subtype); - if (info.media_type != this->type.media_type.video && - info.media_subtype != this->type.media_subtype.raw) + if (info.media_type != SPA_MEDIA_TYPE_video && + info.media_subtype != SPA_MEDIA_SUBTYPE_raw) return -EINVAL; - if (spa_format_video_raw_parse(format, &info.info.raw, &this->type.format_video) < 0) + if (spa_format_video_raw_parse(format, &info.info.raw) < 0) return -EINVAL; - if (info.info.raw.format == this->type.video_format.RGB) + if (info.info.raw.format == SPA_VIDEO_FORMAT_RGB) this->bpp = 3; - else if (info.info.raw.format == this->type.video_format.UYVY) + else if (info.info.raw.format == SPA_VIDEO_FORMAT_UYVY) this->bpp = 2; else return -EINVAL; @@ -696,17 +666,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -722,7 +686,6 @@ impl_node_port_use_buffers(struct spa_node *node, { struct impl *this; uint32_t i; - struct type *t; spa_return_val_if_fail(node != NULL, -EINVAL); @@ -733,8 +696,6 @@ impl_node_port_use_buffers(struct spa_node *node, if (!this->have_format) return -EIO; - t = &this->type; - clear_buffers(this); for (i = 0; i < n_buffers; i++) { @@ -744,11 +705,11 @@ impl_node_port_use_buffers(struct spa_node *node, b = &this->buffers[i]; b->outbuf = buffers[i]; b->outstanding = false; - 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; @@ -791,16 +752,14 @@ impl_node_port_set_io(struct spa_node *node, void *data, size_t size) { 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->io.Buffers) + if (id == SPA_ID_IO_Buffers) this->io = data; else return -ENOENT; @@ -912,7 +871,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; @@ -961,18 +920,11 @@ 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; - else if (strcmp(support[i].type, SPA_TYPE_LOOP__DataLoop) == 0) + else if (support[i].type == SPA_ID_INTERFACE_DataLoop) this->data_loop = support[i].data; } - if (this->map == NULL) { - spa_log_error(this->log, "a type-map is needed"); - return -EINVAL; - } - init_type(&this->type, this->map); this->node = impl_node; reset_props(&this->props); @@ -1002,7 +954,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 diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index d342ff275..83f2ca26c 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -72,55 +71,10 @@ struct port { struct spa_list empty; }; -struct type { - uint32_t node; - uint32_t format; - uint32_t props; - uint32_t prop_volume; - uint32_t prop_mute; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; - 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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - 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); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - 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; struct props props; @@ -151,7 +105,6 @@ static int impl_node_enum_params(struct spa_node *node, struct spa_pod_builder *builder) { struct impl *this; - struct type *t; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; @@ -162,57 +115,60 @@ static int impl_node_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; p = &this->props; next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); - if (id == t->param.idList) { - uint32_t list[] = { t->param.idPropInfo, - t->param.idProps }; + switch (id) { + case SPA_ID_PARAM_List: + { + uint32_t list[] = { SPA_ID_PARAM_PropInfo, + SPA_ID_PARAM_Props }; 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.idPropInfo) { + case SPA_ID_PARAM_PropInfo: switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_volume, - ":", t->param.propName, "s", "The volume", - ":", t->param.propType, "dr", p->volume, + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_volume, + ":", SPA_PROP_INFO_name, "s", "The volume", + ":", SPA_PROP_INFO_type, "dr", p->volume, SPA_POD_PROP_MIN_MAX(0.0, 10.0)); break; case 1: param = spa_pod_builder_object(&b, - id, t->param.PropInfo, - ":", t->param.propId, "I", t->prop_mute, - ":", t->param.propName, "s", "Mute", - ":", t->param.propType, "b", p->mute); + id, SPA_ID_OBJECT_PropInfo, + ":", SPA_PROP_INFO_id, "I", SPA_PROP_mute, + ":", SPA_PROP_INFO_name, "s", "Mute", + ":", SPA_PROP_INFO_type, "b", p->mute); break; default: return 0; } - } - else if (id == t->param.idProps) { + break; + case SPA_ID_PARAM_Props: switch (*index) { case 0: param = spa_pod_builder_object(&b, - id, t->props, - ":", t->prop_volume, "d", p->volume, - ":", t->prop_mute, "b", p->mute); + id, SPA_ID_OBJECT_Props, + ":", SPA_PROP_volume, "d", p->volume, + ":", SPA_PROP_mute, "b", p->mute); break; default: return 0; } - } - else + break; + default: return -ENOENT; + } (*index)++; @@ -226,14 +182,14 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag 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; - if (id == t->param.idProps) { + switch (id) { + case SPA_ID_PARAM_Props: + { struct props *p = &this->props; if (param == NULL) { @@ -241,11 +197,13 @@ static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flag return 0; } spa_pod_object_parse(param, - ":", t->prop_volume, "?d", &p->volume, - ":", t->prop_mute, "?b", &p->mute, NULL); + ":", SPA_PROP_volume, "?d", &p->volume, + ":", SPA_PROP_mute, "?b", &p->mute, NULL); + break; } - else + default: return -ENOENT; + } return 0; } @@ -259,13 +217,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,21 +326,18 @@ static int port_enum_formats(struct spa_node *node, struct spa_pod **param, struct spa_pod_builder *builder) { - struct impl *this = SPA_CONTAINER_OF(node, struct impl, node); - struct type *t = &this->type; - switch (*index) { case 0: *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, "Ieu", t->audio_format.S16, - SPA_POD_PROP_ENUM(2, t->audio_format.S16, - t->audio_format.S32), - ":", 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, "Ieu", SPA_AUDIO_FORMAT_S16, + SPA_POD_PROP_ENUM(2, SPA_AUDIO_FORMAT_S16, + SPA_AUDIO_FORMAT_S32), + ":", SPA_FORMAT_AUDIO_rate, "iru", 44100, SPA_POD_PROP_MIN_MAX(1, INT32_MAX), - ":", t->format_audio.channels,"iru", 2, + ":", SPA_FORMAT_AUDIO_channels,"iru", 2, SPA_POD_PROP_MIN_MAX(1, INT32_MAX)); break; default: @@ -397,7 +355,6 @@ static int port_get_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); @@ -407,12 +364,12 @@ 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->current_format.info.raw.format, - ":", t->format_audio.rate, "i", this->current_format.info.raw.rate, - ":", t->format_audio.channels, "i", this->current_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->current_format.info.raw.format, + ":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate, + ":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels); return 1; } @@ -426,7 +383,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_builder b = { 0 }; uint8_t buffer[1024]; @@ -438,7 +394,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); @@ -447,81 +402,79 @@ 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 }; + 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, filter, ¶m, &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, filter, ¶m, &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->bpf, - SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), - ":", t->param_buffers.stride, "i", 0, - ":", t->param_buffers.buffers, "iru", 2, + id, SPA_ID_OBJECT_ParamBuffers, + ":", SPA_PARAM_BUFFERS_buffers, "iru", 2, 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->bpf, + SPA_POD_PROP_MIN_MAX(16 * this->bpf, INT32_MAX / this->bpf), + ":", 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(&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; + case 1: + param = spa_pod_builder_object(&b, + 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; } - } - else if (id == t->param_io.idControl) { - switch (*index) { - case 0: - 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)); - break; - default: - return 0; - } - } - else + break; + default: return -ENOENT; + } (*index)++; @@ -561,11 +514,11 @@ static int port_set_format(struct spa_node *node, "I", &info.media_type, "I", &info.media_subtype); - if (info.media_type != this->type.media_type.audio || - info.media_subtype != this->type.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, &this->type.format_audio) < 0) + if (spa_format_audio_raw_parse(format, &info.info.raw) < 0) return -EINVAL; this->bpf = 2 * info.info.raw.channels; @@ -582,17 +535,11 @@ impl_node_port_set_param(struct spa_node *node, uint32_t id, uint32_t flags, 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(node, direction, port_id), -EINVAL); - 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 @@ -609,7 +556,6 @@ 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); @@ -622,8 +568,6 @@ impl_node_port_use_buffers(struct spa_node *node, if (!port->have_format) return -EIO; - t = &this->type; - clear_buffers(this, port); for (i = 0; i < n_buffers; i++) { @@ -633,11 +577,11 @@ impl_node_port_use_buffers(struct spa_node *node, b = &port->buffers[i]; b->outbuf = buffers[i]; b->outstanding = direction == SPA_DIRECTION_INPUT; - 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) { b->ptr = d[0].data; b->size = d[0].maxsize; } else { @@ -674,20 +618,18 @@ 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->range = data; else return -ENOENT; @@ -888,7 +830,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; @@ -927,16 +869,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, "a type-map is needed"); - return -EINVAL; - } - init_type(&this->type, this->map); this->node = impl_node; reset_props(&this->props); @@ -953,7 +888,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 diff --git a/spa/tests/test-bluez5.c b/spa/tests/test-bluez5.c index 7ac7b1431..cc2305bb5 100644 --- a/spa/tests/test-bluez5.c +++ b/spa/tests/test-bluez5.c @@ -30,7 +30,6 @@ #include #include -#include #include #include #include @@ -38,7 +37,6 @@ #include #include #include -#include #include #define M_PI_M2 ( M_PI + M_PI ) @@ -51,45 +49,7 @@ static struct spa_log *logger; #include #include - -struct type { - uint32_t log; - uint32_t node; - uint32_t props; - uint32_t format; - struct spa_type_monitor monitor; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; - struct spa_type_param_io param_io; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->log = spa_type_map_get_id(map, SPA_TYPE__Log); - type->node = spa_type_map_get_id(map, SPA_TYPE__Node); - type->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - spa_type_monitor_map(map, &type->monitor); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_param_io_map(map, &type->param_io); -} +#include struct buffer { struct spa_buffer buffer; @@ -100,8 +60,6 @@ struct buffer { }; struct data { - struct type type; - struct spa_type_map *map; struct spa_log *log; struct spa_loop *loop; @@ -134,22 +92,26 @@ struct data { static void inspect_item(struct data *data, struct spa_pod *item) { - spa_debug_pod(0, data->map, item); + spa_debug_pod(0, spa_debug_types, item); } static void monitor_event(void *_data, struct spa_event *event) { struct data *data = _data; - if (SPA_EVENT_TYPE(event) == data->type.monitor.Added) { + switch (SPA_EVENT_TYPE(event)) { + case SPA_ID_EVENT_MONITOR_Added: fprintf(stderr, "added:\n"); inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event)); - } else if (SPA_EVENT_TYPE(event) == data->type.monitor.Removed) { + break; + case SPA_ID_EVENT_MONITOR_Removed: fprintf(stderr, "removed:\n"); inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event)); - } else if (SPA_EVENT_TYPE(event) == data->type.monitor.Changed) { + break; + case SPA_ID_EVENT_MONITOR_Changed: fprintf(stderr, "changed:\n"); inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event)); + break; } } @@ -210,20 +172,6 @@ int main(int argc, char *argv[]) void *iface; spa_zero(data); - if ((res = get_handle(&data, &handle, - "build/spa/plugins/support/libspa-support.so", - "mapper")) < 0) { - error(-1, res, "can't create mapper"); - } - if ((res = spa_handle_get_interface(handle, 0, &iface)) < 0) - error(-1, res, "can't get mapper interface"); - - data.map = iface; - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.n_support = 1; - init_type(&data.type, data.map); - if ((res = get_handle(&data, &handle, "build/spa/plugins/support/libspa-support.so", "logger")) < 0) { @@ -231,14 +179,13 @@ int main(int argc, char *argv[]) } if ((res = spa_handle_get_interface(handle, - spa_type_map_get_id(data.map, SPA_TYPE__Log), + SPA_ID_INTERFACE_Log, &iface)) < 0) error(-1, res, "can't get log interface"); data.log = iface; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.n_support = 2; + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.n_support = 1; if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); @@ -249,32 +196,28 @@ int main(int argc, char *argv[]) error(-1, res, "can't create loop"); } if ((res = spa_handle_get_interface(handle, - spa_type_map_get_id(data.map, SPA_TYPE__Loop), + SPA_ID_INTERFACE_Loop, &iface)) < 0) error(-1, res, "can't get loop interface"); data.loop = iface; if ((res = spa_handle_get_interface(handle, - spa_type_map_get_id(data.map, SPA_TYPE__LoopControl), + SPA_ID_INTERFACE_LoopControl, &iface)) < 0) error(-1, res, "can't get loopcontrol interface"); data.loop_control = iface; if ((res = spa_handle_get_interface(handle, - spa_type_map_get_id(data.map, SPA_TYPE__LoopUtils), + SPA_ID_INTERFACE_LoopUtils, &iface)) < 0) error(-1, res, "can't get looputils interface"); data.loop_utils = iface; - data.support[2].type = SPA_TYPE_LOOP__DataLoop; - data.support[2].data = data.loop; - data.support[3].type = SPA_TYPE_LOOP__MainLoop; - data.support[3].data = data.loop; - data.support[4].type = SPA_TYPE__LoopControl; - data.support[4].data = data.loop_control; - data.support[5].type = SPA_TYPE__LoopUtils; - data.support[5].data = data.loop_utils; - data.n_support = 6; + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, data.loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, data.loop); + data.support[3] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_LoopControl, data.loop_control); + data.support[4] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_LoopUtils, data.loop_utils); + data.n_support = 5; if ((res = get_handle(&data, &handle, "build/spa/plugins/support/libspa-dbus.so", @@ -283,14 +226,13 @@ int main(int argc, char *argv[]) } if ((res = spa_handle_get_interface(handle, - spa_type_map_get_id(data.map, SPA_TYPE__DBus), + SPA_ID_INTERFACE_DBus, &iface)) < 0) error(-1, res, "can't get dbus interface"); data.dbus = iface; - data.support[6].type = SPA_TYPE__DBus; - data.support[6].data = data.dbus; - data.n_support = 7; + data.support[5] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DBus, data.dbus); + data.n_support = 6; if ((res = get_handle(&data, &handle, "build/spa/plugins/bluez5/libspa-bluez5.so", @@ -299,7 +241,7 @@ int main(int argc, char *argv[]) } if ((res = spa_handle_get_interface(handle, - spa_type_map_get_id(data.map, SPA_TYPE__Monitor), + SPA_ID_INTERFACE_Monitor, &iface)) < 0) error(-1, res, "can't get monitor interface"); diff --git a/spa/tests/test-control.c b/spa/tests/test-control.c index cdc138cdb..1caaf60ef 100644 --- a/spa/tests/test-control.c +++ b/spa/tests/test-control.c @@ -30,18 +30,15 @@ #include #include -#include #include #include #include #include #include -#include #include #define M_PI_M2 ( M_PI + M_PI ) -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); #define spa_debug(f,...) spa_log_trace(&default_log.log, f, __VA_ARGS__) @@ -51,51 +48,6 @@ static SPA_LOG_IMPL(default_log); #include -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - uint32_t props_device; - uint32_t props_freq; - uint32_t props_volume; - uint32_t props_min_latency; - uint32_t props_live; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; - 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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - type->props_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->props_freq = spa_type_map_get_id(map, SPA_TYPE_PROPS__frequency); - type->props_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume); - type->props_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->props_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); - spa_type_param_io_map(map, &type->param_io); -} - struct buffer { struct spa_buffer buffer; struct spa_meta metas[1]; @@ -105,10 +57,8 @@ struct buffer { }; struct data { - struct spa_type_map *map; struct spa_log *log; struct spa_loop data_loop; - struct type type; struct spa_support support[4]; uint32_t n_support; @@ -170,11 +120,11 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int b->header.seq = 0; b->header.pts = 0; b->header.dts_offset = 0; - b->metas[0].type = data->type.meta.Header; + b->metas[0].type = SPA_META_Header; b->metas[0].data = &b->header; b->metas[0].size = sizeof(b->header); - b->datas[0].type = data->type.data.MemPtr; + b->datas[0].type = SPA_DATA_MemPtr; b->datas[0].flags = 0; b->datas[0].fd = -1; b->datas[0].mapoffset = 0; @@ -223,7 +173,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, data->type.node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -314,7 +264,7 @@ static int make_nodes(struct data *data, const char *device) struct spa_pod *props; struct spa_pod_builder b = { 0 }; uint8_t buffer[512]; - uint32_t idx; + //uint32_t idx; if ((res = make_node(data, &data->sink, "build/spa/plugins/alsa/libspa-alsa.so", "alsa-sink")) < 0) { @@ -325,13 +275,13 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_device, "s", device ? device : "hw:0", - ":", data->type.props_min_latency, "i", MIN_LATENCY); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "s", device ? device : "hw:0", + ":", SPA_PROP_minLatency, "i", MIN_LATENCY); - spa_debug_pod(0, data->map, props); + spa_debug_pod(0, spa_debug_types, props); - if ((res = spa_node_set_param(data->sink, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->sink, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); if ((res = make_node(data, &data->source, @@ -343,17 +293,18 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_freq, "d", 600.0, - ":", data->type.props_volume, "d", 0.5, - ":", data->type.props_live, "b", false); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_frequency, "d", 600.0, + ":", SPA_PROP_volume, "d", 0.5, + ":", SPA_PROP_live, "b", false); data->ctrl_source_freq = SPA_POD_DOUBLE_INIT(600.0); data->ctrl_source_volume = SPA_POD_DOUBLE_INIT(0.5); - if ((res = spa_node_set_param(data->source, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->source, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); +#if 0 for (idx = 0;;) { struct spa_pod *param; uint32_t id = 0, propId = 0; @@ -387,16 +338,17 @@ static int make_nodes(struct data *data, const char *device) error(0, -res, "set_io volume"); } } +#endif data->source_sink_io[0] = SPA_IO_BUFFERS_INIT; spa_node_port_set_io(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_sink_io[0], sizeof(data->source_sink_io[0])); spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_sink_io[0], sizeof(data->source_sink_io[0])); spa_graph_node_init(&data->source_node, &data->source_state); @@ -426,34 +378,34 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); filter = spa_pod_builder_object(&b, - 0, data->type.format, - "I", data->type.media_type.audio, - "I", data->type.media_subtype.raw, - ":", data->type.format_audio.format, "I", data->type.audio_format.S16, - ":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", data->type.format_audio.rate, "i", 44100, - ":", data->type.format_audio.channels, "i", 2); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, + ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "i", 44100, + ":", SPA_FORMAT_AUDIO_channels, "i", 2); - spa_debug_pod(0, data->map, filter); + spa_debug_pod(0, spa_debug_types, filter); spa_log_debug(&default_log.log, "enum_params"); if ((res = spa_node_port_enum_params(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) return -EBADF; - spa_debug_pod(0, data->map, format); + spa_debug_pod(0, spa_debug_types, format); spa_log_debug(&default_log.log, "sink set_param"); if ((res = spa_node_port_set_param(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idFormat, 0, format)) < 0) + SPA_ID_PARAM_Format, 0, format)) < 0) return res; if ((res = spa_node_port_set_param(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, format)) < 0) + SPA_ID_PARAM_Format, 0, format)) < 0) return res; init_buffer(data, data->source_buffers, data->source_buffer, 1, BUFFER_SIZE); @@ -529,7 +481,7 @@ static void run_async_sink(struct data *data) int err; { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); if ((res = spa_node_send_command(data->source, &cmd)) < 0) printf("got source error %d\n", res); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) @@ -551,7 +503,7 @@ static void run_async_sink(struct data *data) } { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) printf("got error %d\n", res); if ((res = spa_node_send_command(data->source, &cmd)) < 0) @@ -569,7 +521,6 @@ int main(int argc, char *argv[]) spa_graph_data_init(&data.graph_data, &data.graph); spa_graph_set_callbacks(&data.graph, &spa_graph_impl_default, &data.graph_data); - data.map = &default_map.map; data.log = &default_log.log; data.data_loop.version = SPA_VERSION_LOOP; data.data_loop.add_source = do_add_source; @@ -580,17 +531,10 @@ int main(int argc, char *argv[]) if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__DataLoop; - data.support[2].data = &data.data_loop; - data.support[3].type = SPA_TYPE_LOOP__MainLoop; - data.support[3].data = &data.data_loop; - data.n_support = 4; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.data_loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, &data.data_loop); + data.n_support = 3; if ((res = make_nodes(&data, argc > 1 ? argv[1] : NULL)) < 0) { printf("can't make nodes: %d\n", res); diff --git a/spa/tests/test-convert.c b/spa/tests/test-convert.c index 5f47aa9f8..49df327ae 100644 --- a/spa/tests/test-convert.c +++ b/spa/tests/test-convert.c @@ -28,62 +28,17 @@ #include #include -#include #include #include #include #include #include -#include #include #include +#include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - uint32_t props_device; - uint32_t props_freq; - uint32_t props_volume; - uint32_t props_min_latency; - uint32_t props_live; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - type->props_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->props_freq = spa_type_map_get_id(map, SPA_TYPE_PROPS__frequency); - type->props_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume); - type->props_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->props_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); -} - struct buffer { struct spa_buffer buffer; struct spa_meta metas[1]; @@ -93,9 +48,7 @@ struct buffer { }; struct data { - struct spa_type_map *map; struct spa_log *log; - struct type type; struct spa_support support[4]; uint32_t n_support; @@ -133,14 +86,14 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int b->header.seq = 0; b->header.pts = 0; b->header.dts_offset = 0; - b->metas[0].type = data->type.meta.Header; + b->metas[0].type = SPA_META_Header; b->metas[0].data = &b->header; b->metas[0].size = sizeof(b->header); d = malloc(size * n_datas); for (j = 0; j < n_datas; j++) { - b->datas[j].type = data->type.data.MemPtr; + b->datas[j].type = SPA_DATA_MemPtr; b->datas[j].flags = 0; b->datas[j].fd = -1; b->datas[j].mapoffset = 0; @@ -190,7 +143,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, data->type.node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -254,17 +207,17 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); format = spa_pod_builder_object(&b, - 0, data->type.format, - "I", data->type.media_type.audio, - "I", data->type.media_subtype.raw, - ":", data->type.format_audio.format, "I", data->type.audio_format.S16, - ":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", data->type.format_audio.rate, "i", 44100, - ":", data->type.format_audio.channels, "i", 2); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, + ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "i", 44100, + ":", SPA_FORMAT_AUDIO_channels, "i", 2); if ((res = spa_node_port_set_param(data->conv, SPA_DIRECTION_INPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -273,28 +226,28 @@ static int negotiate_formats(struct data *data) spa_node_port_set_io(data->conv, SPA_DIRECTION_INPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->io_in[0], sizeof(data->io_in[0])); spa_node_port_set_io(data->conv, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->io_out[0], sizeof(data->io_out[0])); spa_pod_builder_init(&b, buffer, sizeof(buffer)); format = spa_pod_builder_object(&b, - 0, data->type.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_NON_INTERLEAVED, - ":", data->type.format_audio.rate, "i", 44100, - ":", data->type.format_audio.channels, "i", 2); + 0, 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, "i", 44100, + ":", SPA_FORMAT_AUDIO_channels, "i", 2); if ((res = spa_node_port_set_param(data->conv, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -314,11 +267,11 @@ static int negotiate_buffers(struct data *data) state = 0; if ((res = spa_node_port_enum_params(data->conv, SPA_DIRECTION_INPUT, 0, - data->type.param.idBuffers, &state, + SPA_ID_PARAM_Buffers, &state, NULL, ¶m, &b)) <= 0) return -EBADF; - spa_debug_pod(0, data->map, param); + spa_debug_pod(0, spa_debug_types, param); init_buffer(data, data->in_buffers, data->in_buffer, 1, BUFFER_SIZE, 1); if ((res = @@ -331,11 +284,11 @@ static int negotiate_buffers(struct data *data) state = 0; if ((res = spa_node_port_enum_params(data->conv, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idBuffers, &state, + SPA_ID_PARAM_Buffers, &state, NULL, ¶m, &b)) <= 0) return -EBADF; - spa_debug_pod(0, data->map, param); + spa_debug_pod(0, spa_debug_types, param); init_buffer(data, data->out_buffers, data->out_buffer, 1, BUFFER_SIZE, 2); if ((res = @@ -361,7 +314,7 @@ static void run_convert(struct data *data) int res; { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); if ((res = spa_node_send_command(data->conv, &cmd)) < 0) printf("got convert error %d\n", res); } @@ -383,7 +336,7 @@ static void run_convert(struct data *data) spa_debug_mem(0, data->out_buffers[0]->datas[1].data, BUFFER_SIZE); { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); if ((res = spa_node_send_command(data->conv, &cmd)) < 0) printf("got convert error %d\n", res); } @@ -395,19 +348,13 @@ int main(int argc, char *argv[]) int res; const char *str; - data.map = &default_map.map; data.log = &default_log.log; if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.n_support = 2; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.n_support = 1; if ((res = make_nodes(&data, argc > 1 ? argv[1] : NULL)) < 0) { printf("can't make nodes: %d\n", res); diff --git a/spa/tests/test-convert2.c b/spa/tests/test-convert2.c index 355b95dc3..2f1e7aa52 100644 --- a/spa/tests/test-convert2.c +++ b/spa/tests/test-convert2.c @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -36,49 +35,13 @@ #include #include #include -#include #include #include #include +#include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_param_buffers param_buffers; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_param_buffers_map(map, &type->param_buffers); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); -} - struct buffer { struct spa_buffer buffer; struct spa_meta metas[1]; @@ -104,9 +67,7 @@ struct link { }; struct data { - struct spa_type_map *map; struct spa_log *log; - struct type type; struct spa_support support[4]; uint32_t n_support; @@ -117,7 +78,6 @@ struct data { static int make_node(struct data *data, struct spa_node **node, const char *lib, const char *name) { - struct type *t = &data->type; struct spa_handle *handle; int res; void *hnd; @@ -152,7 +112,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, t->node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -198,8 +158,6 @@ static int make_link(struct data *data, struct link *link, struct node *out_node, uint32_t out_port, struct node *in_node, uint32_t in_port) { - struct type *t = &data->type; - link->out_node = out_node; link->out_port = out_port; link->in_node = in_node; @@ -216,7 +174,7 @@ static int make_link(struct data *data, struct link *link, &link->out_info); spa_node_port_set_io(out_node->node, SPA_DIRECTION_OUTPUT, out_port, - t->io.Buffers, + SPA_ID_IO_Buffers, &link->io, sizeof(link->io)); } if (in_node != NULL) { @@ -225,7 +183,7 @@ static int make_link(struct data *data, struct link *link, &link->in_info); spa_node_port_set_io(in_node->node, SPA_DIRECTION_INPUT, in_port, - t->io.Buffers, + SPA_ID_IO_Buffers, &link->io, sizeof(link->io)); } return 0; @@ -243,7 +201,6 @@ static int link_nodes(struct data *data) static int negotiate_link_format(struct data *data, struct link *link, struct spa_pod *filter) { - struct type *t = &data->type; struct spa_pod_builder b = { 0 }; uint8_t buffer[4096]; uint32_t state; @@ -256,7 +213,7 @@ static int negotiate_link_format(struct data *data, struct link *link, struct sp state = 0; if ((res = spa_node_port_enum_params(link->out_node->node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) return -ENOTSUP; @@ -266,7 +223,7 @@ static int negotiate_link_format(struct data *data, struct link *link, struct sp state = 0; if ((res = spa_node_port_enum_params(link->in_node->node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) return -ENOTSUP; @@ -274,19 +231,19 @@ static int negotiate_link_format(struct data *data, struct link *link, struct sp } spa_pod_fixate(filter); - spa_debug_format(0, data->map, filter); + spa_debug_format(0, NULL, filter); if (link->out_node != NULL) { if ((res = spa_node_port_set_param(link->out_node->node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idFormat, 0, + SPA_ID_PARAM_Format, 0, filter)) < 0) return res; } if (link->in_node != NULL) { if ((res = spa_node_port_set_param(link->in_node->node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idFormat, 0, + SPA_ID_PARAM_Format, 0, filter)) < 0) return res; } @@ -298,31 +255,30 @@ static int negotiate_formats(struct data *data) int res; struct spa_pod *format; struct spa_pod_builder b = { 0 }; - struct type *t = &data->type; uint8_t buffer[4096]; spa_pod_builder_init(&b, buffer, sizeof(buffer)); format = spa_pod_builder_object(&b, - 0, t->format, - "I", t->media_type.audio, - "I", t->media_subtype.raw, - ":", t->format_audio.format, "I", t->audio_format.S16, - ":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", t->format_audio.rate, "i", 44100, - ":", t->format_audio.channels, "i", 2); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, + ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "i", 44100, + ":", SPA_FORMAT_AUDIO_channels, "i", 2); if ((res = negotiate_link_format(data, &data->links[0], format)) < 0) return res; spa_pod_builder_init(&b, buffer, sizeof(buffer)); format = spa_pod_builder_object(&b, - 0, 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, "i", 48000, - ":", t->format_audio.channels, "i", 1); + 0, 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, "i", 48000, + ":", SPA_FORMAT_AUDIO_channels, "i", 1); if ((res = negotiate_link_format(data, &data->links[4], format)) < 0) return res; @@ -341,7 +297,6 @@ static int negotiate_formats(struct data *data) static int negotiate_link_buffers(struct data *data, struct link *link) { - struct type *t = &data->type; uint8_t buffer[4096]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); uint32_t state; @@ -356,7 +311,7 @@ static int negotiate_link_buffers(struct data *data, struct link *link) state = 0; if ((res = spa_node_port_enum_params(link->out_node->node, SPA_DIRECTION_OUTPUT, link->out_port, - t->param.idBuffers, &state, + SPA_ID_PARAM_Buffers, &state, param, ¶m, &b)) <= 0) return -ENOTSUP; } @@ -364,13 +319,13 @@ static int negotiate_link_buffers(struct data *data, struct link *link) state = 0; if ((res = spa_node_port_enum_params(link->in_node->node, SPA_DIRECTION_INPUT, link->in_port, - t->param.idBuffers, &state, + SPA_ID_PARAM_Buffers, &state, param, ¶m, &b)) <= 0) return -ENOTSUP; } spa_pod_fixate(param); - spa_debug_pod(0, data->map, param); + spa_debug_pod(0, spa_debug_types, param); if (link->in_info) in_alloc = SPA_FLAG_CHECK(link->in_info->flags, SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS); @@ -390,17 +345,17 @@ static int negotiate_link_buffers(struct data *data, struct link *link) } 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; datas = alloca(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; } @@ -476,12 +431,11 @@ static void fill_buffer(struct data *data, struct spa_buffer *buffers[], int id) static void run_convert(struct data *data) { - struct type *t = &data->type; struct spa_buffer *b; int res, i, j; { - struct spa_command cmd = SPA_COMMAND_INIT(t->command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); for (i = 0; i < 4; i++) { if ((res = spa_node_send_command(data->nodes[i].node, &cmd)) < 0) printf("got command error %d\n", res); @@ -514,7 +468,7 @@ static void run_convert(struct data *data) spa_debug_mem(0, b->datas[i].data, b->datas[i].maxsize); { - struct spa_command cmd = SPA_COMMAND_INIT(t->command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); for (i = 0; i < 4; i++) { if ((res = spa_node_send_command(data->nodes[i].node, &cmd)) < 0) printf("got command error %d\n", res); @@ -528,19 +482,13 @@ int main(int argc, char *argv[]) int res; const char *str; - data.map = &default_map.map; data.log = &default_log.log; if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.n_support = 2; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.n_support = 1; if ((res = make_nodes(&data, argc > 1 ? argv[1] : NULL)) < 0) { printf("can't make nodes: %d\n", res); diff --git a/spa/tests/test-graph.c b/spa/tests/test-graph.c index 99b0bcbc5..9a08f356b 100644 --- a/spa/tests/test-graph.c +++ b/spa/tests/test-graph.c @@ -28,15 +28,12 @@ #include #include -#include #include #include #include #include #include -#include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); #define spa_debug(f,...) spa_log_trace(&default_log.log, f, __VA_ARGS__) @@ -45,49 +42,7 @@ static SPA_LOG_IMPL(default_log); #include #include - -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - uint32_t props_device; - uint32_t props_freq; - uint32_t props_volume; - uint32_t props_min_latency; - uint32_t props_live; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - type->props_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->props_freq = spa_type_map_get_id(map, SPA_TYPE_PROPS__frequency); - type->props_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume); - type->props_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->props_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); -} +#include struct buffer { struct spa_buffer buffer; @@ -98,10 +53,8 @@ struct buffer { }; struct data { - struct spa_type_map *map; struct spa_log *log; struct spa_loop data_loop; - struct type type; struct spa_support support[4]; uint32_t n_support; @@ -167,11 +120,11 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int b->header.seq = 0; b->header.pts = 0; b->header.dts_offset = 0; - b->metas[0].type = data->type.meta.Header; + b->metas[0].type = SPA_META_Header; b->metas[0].data = &b->header; b->metas[0].size = sizeof(b->header); - b->datas[0].type = data->type.data.MemPtr; + b->datas[0].type = SPA_DATA_MemPtr; b->datas[0].flags = 0; b->datas[0].fd = -1; b->datas[0].mapoffset = 0; @@ -220,7 +173,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, data->type.node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -304,13 +257,13 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_device, "s", device ? device : "hw:0", - ":", data->type.props_min_latency, "i", MIN_LATENCY); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "s", device ? device : "hw:0", + ":", SPA_PROP_minLatency, "i", MIN_LATENCY); - spa_debug_pod(0, data->map, props); + spa_debug_pod(0, spa_debug_types, props); - if ((res = spa_node_set_param(data->sink, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->sink, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); if ((res = make_node(data, &data->volume, @@ -328,12 +281,12 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_freq, "d", 600.0, - ":", data->type.props_volume, "d", 0.5, - ":", data->type.props_live, "b", false); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_frequency, "d", 600.0, + ":", SPA_PROP_volume, "d", 0.5, + ":", SPA_PROP_live, "b", false); - if ((res = spa_node_set_param(data->source, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->source, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); data->source_volume_io[0] = SPA_IO_BUFFERS_INIT; @@ -341,19 +294,19 @@ static int make_nodes(struct data *data, const char *device) spa_node_port_set_io(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_volume_io[0], sizeof(data->source_volume_io[0])); spa_node_port_set_io(data->volume, SPA_DIRECTION_INPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_volume_io[0], sizeof(data->source_volume_io[0])); spa_node_port_set_io(data->volume, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->volume_sink_io[0], sizeof(data->volume_sink_io[0])); spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->volume_sink_io[0], sizeof(data->volume_sink_io[0])); spa_graph_node_init(&data->source_node, &data->source_state); @@ -394,35 +347,35 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); filter = spa_pod_builder_object(&b, - 0, data->type.format, - "I", data->type.media_type.audio, - "I", data->type.media_subtype.raw, - ":", data->type.format_audio.format, "I", data->type.audio_format.S16, - ":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", data->type.format_audio.rate, "i", 44100, - ":", data->type.format_audio.channels, "i", 2); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, + ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "i", 44100, + ":", SPA_FORMAT_AUDIO_channels, "i", 2); - spa_debug_pod(0, data->map, filter); + spa_debug_pod(0, spa_debug_types, filter); spa_log_debug(&default_log.log, "enum_params"); if ((res = spa_node_port_enum_params(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) return -EBADF; - spa_debug_pod(0, data->map, format); + spa_debug_pod(0, spa_debug_types, format); spa_log_debug(&default_log.log, "sink set_param"); if ((res = spa_node_port_set_param(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idFormat, 0, format)) < 0) + SPA_ID_PARAM_Format, 0, format)) < 0) return res; spa_log_debug(&default_log.log, "volume set_param"); if ((res = spa_node_port_set_param(data->volume, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, format)) < 0) + SPA_ID_PARAM_Format, 0, format)) < 0) return res; init_buffer(data, data->volume_buffers, data->volume_buffer, 1, BUFFER_SIZE); @@ -437,11 +390,11 @@ static int negotiate_formats(struct data *data) if ((res = spa_node_port_set_param(data->volume, SPA_DIRECTION_INPUT, 0, - data->type.param.idFormat, 0, format)) < 0) + SPA_ID_PARAM_Format, 0, format)) < 0) return res; if ((res = spa_node_port_set_param(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, format)) < 0) + SPA_ID_PARAM_Format, 0, format)) < 0) return res; init_buffer(data, data->source_buffers, data->source_buffer, 1, BUFFER_SIZE); @@ -517,7 +470,7 @@ static void run_async_sink(struct data *data) int err; { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); if ((res = spa_node_send_command(data->source, &cmd)) < 0) printf("got source error %d\n", res); if ((res = spa_node_send_command(data->volume, &cmd)) < 0) @@ -541,7 +494,7 @@ static void run_async_sink(struct data *data) } { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) printf("got error %d\n", res); if ((res = spa_node_send_command(data->volume, &cmd)) < 0) @@ -561,7 +514,6 @@ int main(int argc, char *argv[]) spa_graph_data_init(&data.graph_data, &data.graph); spa_graph_set_callbacks(&data.graph, &spa_graph_impl_default, &data.graph_data); - data.map = &default_map.map; data.log = &default_log.log; data.data_loop.version = SPA_VERSION_LOOP; data.data_loop.add_source = do_add_source; @@ -572,17 +524,10 @@ int main(int argc, char *argv[]) if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__DataLoop; - data.support[2].data = &data.data_loop; - data.support[3].type = SPA_TYPE_LOOP__MainLoop; - data.support[3].data = &data.data_loop; - data.n_support = 4; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.data_loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, &data.data_loop); + data.n_support = 3; if ((res = make_nodes(&data, argc > 1 ? argv[1] : NULL)) < 0) { printf("can't make nodes: %d\n", res); diff --git a/spa/tests/test-graph2.c b/spa/tests/test-graph2.c index 288049ab5..61ee58bb1 100644 --- a/spa/tests/test-graph2.c +++ b/spa/tests/test-graph2.c @@ -28,37 +28,23 @@ #include #include -#include #include #include #include #include -#include #include #include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - uint32_t node; -}; - -static inline void init_type(struct type *type, struct spa_type_map *map) -{ - type->node = spa_type_map_get_id(map, SPA_TYPE__Node); -} - struct version { uint16_t current; uint16_t pending; }; struct data { - struct spa_type_map *map; struct spa_log *log; struct spa_loop data_loop; - struct type type; int writers; struct version version; @@ -233,14 +219,11 @@ int main(int argc, char *argv[]) spa_graph_init(&data.graph[0], &data.graph_state[0]); spa_graph_init(&data.graph[1], &data.graph_state[1]); - data.map = &default_map.map; data.log = &default_log.log; if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - init_type(&data.type, data.map); - print_graph(&data, 0); print_graph(&data, 1); make_graph1(&data); diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index 08702a71b..b4c5e8f61 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -31,20 +31,16 @@ #include #include #include -#include -#include #include #include #include #include #include -#include #define USE_GRAPH #define M_PI_M2 ( M_PI + M_PI ) -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); #define spa_debug(...) spa_log_trace(&default_log.log,__VA_ARGS__) @@ -52,51 +48,6 @@ static SPA_LOG_IMPL(default_log); #include #include -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - uint32_t props_device; - uint32_t props_freq; - uint32_t props_volume; - uint32_t props_min_latency; - uint32_t props_live; - uint32_t io_inprop_volume; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - type->props_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->props_freq = spa_type_map_get_id(map, SPA_TYPE_PROPS__frequency); - type->props_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume); - type->props_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->props_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - type->io_inprop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume"); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); -} - struct buffer { struct spa_buffer buffer; struct spa_meta metas[1]; @@ -106,10 +57,8 @@ struct buffer { }; struct data { - struct spa_type_map *map; struct spa_log *log; struct spa_loop data_loop; - struct type type; struct spa_support support[4]; uint32_t n_support; @@ -187,11 +136,11 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int b->header.seq = 0; b->header.pts = 0; b->header.dts_offset = 0; - b->metas[0].type = data->type.meta.Header; + b->metas[0].type = SPA_META_Header; b->metas[0].data = &b->header; b->metas[0].size = sizeof(b->header); - b->datas[0].type = data->type.data.MemPtr; + b->datas[0].type = SPA_DATA_MemPtr; b->datas[0].flags = 0; b->datas[0].fd = -1; b->datas[0].mapoffset = 0; @@ -240,7 +189,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, data->type.node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -370,11 +319,11 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_device, "s", device ? device : "hw:0", - ":", data->type.props_min_latency, "i", MIN_LATENCY); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "s", device ? device : "hw:0", + ":", SPA_PROP_minLatency, "i", MIN_LATENCY); - if ((res = spa_node_set_param(data->sink, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->sink, SPA_ID_PARAM_Props, 0, props)) < 0) error(0, -res, "set_param props"); if ((res = make_node(data, &data->mix, @@ -393,12 +342,12 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_freq, "d", 600.0, - ":", data->type.props_volume, "d", 1.0, - ":", data->type.props_live, "b", false); + SPA_ID_PARAM_Props, SPA_ID_OBJECT_Props, + ":", SPA_PROP_frequency, "d", 600.0, + ":", SPA_PROP_volume, "d", 1.0, + ":", SPA_PROP_live, "b", false); - if ((res = spa_node_set_param(data->source1, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->source1, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); if ((res = make_node(data, &data->source2, @@ -410,12 +359,12 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_freq, "d", 440.0, - ":", data->type.props_volume, "d", 1.0, - ":", data->type.props_live, "b", false); + SPA_ID_PARAM_Props, SPA_ID_OBJECT_Props, + ":", SPA_PROP_frequency, "d", 440.0, + ":", SPA_PROP_volume, "d", 1.0, + ":", SPA_PROP_live, "b", false); - if ((res = spa_node_set_param(data->source2, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->source2, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); data->mix_ports[0] = 0; @@ -432,32 +381,33 @@ static int make_nodes(struct data *data, const char *device) spa_node_port_set_io(data->source1, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source1_mix_io[0], sizeof(data->source1_mix_io[0])); spa_node_port_set_io(data->source2, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source2_mix_io[0], sizeof(data->source2_mix_io[0])); spa_node_port_set_io(data->mix, SPA_DIRECTION_INPUT, data->mix_ports[0], - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source1_mix_io[0], sizeof(data->source1_mix_io[0])); spa_node_port_set_io(data->mix, SPA_DIRECTION_INPUT, data->mix_ports[1], - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source2_mix_io[0], sizeof(data->source2_mix_io[0])); spa_node_port_set_io(data->mix, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->mix_sink_io[0], sizeof(data->mix_sink_io[0])); spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->mix_sink_io[0], sizeof(data->mix_sink_io[0])); data->ctrl_volume[0] = SPA_POD_DOUBLE_INIT(0.5); data->ctrl_volume[1] = SPA_POD_DOUBLE_INIT(0.5); +#if 0 if ((res = spa_node_port_set_io(data->mix, SPA_DIRECTION_INPUT, data->mix_ports[0], data->type.io_inprop_volume, @@ -469,6 +419,7 @@ static int make_nodes(struct data *data, const char *device) data->type.io_inprop_volume, &data->ctrl_volume[1], sizeof(data->ctrl_volume[1]))) < 0) error(0, -res, "set_io volume 1"); +#endif #ifdef USE_GRAPH @@ -522,30 +473,30 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); filter = spa_pod_builder_object(&b, - 0, data->type.format, - "I", data->type.media_type.audio, - "I", data->type.media_subtype.raw, - ":", data->type.format_audio.format, "I", data->type.audio_format.S16, - ":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", data->type.format_audio.rate, "i", 44100, - ":", data->type.format_audio.channels, "i", 2); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, + ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "i", 44100, + ":", SPA_FORMAT_AUDIO_channels, "i", 2); if ((res = spa_node_port_enum_params(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) return -EBADF; if ((res = spa_node_port_set_param(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; if ((res = spa_node_port_set_param(data->mix, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -560,13 +511,13 @@ static int negotiate_formats(struct data *data) if ((res = spa_node_port_set_param(data->mix, SPA_DIRECTION_INPUT, data->mix_ports[0], - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; if ((res = spa_node_port_set_param(data->source1, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -583,13 +534,13 @@ static int negotiate_formats(struct data *data) if ((res = spa_node_port_set_param(data->mix, SPA_DIRECTION_INPUT, data->mix_ports[1], - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; if ((res = spa_node_port_set_param(data->source2, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -666,7 +617,7 @@ static void run_async_sink(struct data *data) int err; { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); if ((res = spa_node_send_command(data->source1, &cmd)) < 0) printf("got source1 error %d\n", res); if ((res = spa_node_send_command(data->source2, &cmd)) < 0) @@ -692,7 +643,7 @@ static void run_async_sink(struct data *data) } { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) printf("got error %d\n", res); if ((res = spa_node_send_command(data->mix, &cmd)) < 0) @@ -710,7 +661,6 @@ int main(int argc, char *argv[]) int res; const char *str; - data.map = &default_map.map; data.log = &default_log.log; data.data_loop.version = SPA_VERSION_LOOP; data.data_loop.add_source = do_add_source; @@ -725,17 +675,10 @@ int main(int argc, char *argv[]) if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__DataLoop; - data.support[2].data = &data.data_loop; - data.support[3].type = SPA_TYPE_LOOP__MainLoop; - data.support[3].data = &data.data_loop; - data.n_support = 4; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.data_loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, &data.data_loop); + data.n_support = 3; if ((res = make_nodes(&data, argc > 1 ? argv[1] : NULL)) < 0) { printf("can't make nodes: %d\n", res); diff --git a/spa/tests/test-perf.c b/spa/tests/test-perf.c index 609b5cf06..2d41079fa 100644 --- a/spa/tests/test-perf.c +++ b/spa/tests/test-perf.c @@ -28,13 +28,11 @@ #include #include -#include #include #include #include #include #include -#include #include #include @@ -45,48 +43,8 @@ #define MODE_ASYNC_BOTH (MODE_ASYNC_PUSH|MODE_ASYNC_PULL) #define MODE_DIRECT (1<<4) -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - uint32_t props_device; - uint32_t props_freq; - uint32_t props_volume; - uint32_t props_min_latency; - uint32_t props_live; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - struct spa_type_media_type media_type; - struct spa_type_media_subtype media_subtype; - struct spa_type_event_node event_node; - struct spa_type_command_node command_node; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - type->props_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->props_freq = spa_type_map_get_id(map, SPA_TYPE_PROPS__frequency); - type->props_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume); - type->props_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->props_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - spa_type_media_type_map(map, &type->media_type); - spa_type_media_subtype_map(map, &type->media_subtype); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); -} - struct buffer { struct spa_buffer buffer; struct spa_meta metas[1]; @@ -96,10 +54,8 @@ struct buffer { }; struct data { - struct spa_type_map *map; struct spa_log *log; struct spa_loop data_loop; - struct type type; int mode; @@ -162,11 +118,11 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int b->header.seq = 0; b->header.pts = 0; b->header.dts_offset = 0; - b->metas[0].type = data->type.meta.Header; + b->metas[0].type = SPA_META_Header; b->metas[0].data = &b->header; b->metas[0].size = sizeof(b->header); - b->datas[0].type = data->type.data.MemPtr; + b->datas[0].type = SPA_DATA_MemPtr; b->datas[0].flags = 0; b->datas[0].fd = -1; b->datas[0].mapoffset = 0; @@ -216,7 +172,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, data->type.node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -368,11 +324,11 @@ static int make_nodes(struct data *data) spa_node_port_set_io(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_sink_io[0], sizeof(data->source_sink_io[0])); spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_sink_io[0], sizeof(data->source_sink_io[0])); spa_graph_node_init(&data->source_node, &data->source_state); @@ -403,19 +359,19 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); format = spa_pod_builder_object(&b, - 0, data->type.format, - "I", data->type.media_type.binary, - "I", data->type.media_subtype.raw); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_binary, + "I", SPA_MEDIA_SUBTYPE_raw); if ((res = spa_node_port_set_param(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; if ((res = spa_node_port_set_param(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -495,7 +451,7 @@ static void run_graph(struct data *data) int64_t start, stop; { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); if ((res = spa_node_send_command(data->source, &cmd)) < 0) printf("got source error %d\n", res); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) @@ -530,7 +486,7 @@ static void run_graph(struct data *data) printf("stopping, elapsed %" PRIi64 "\n", stop - start); { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) printf("got error %d\n", res); if ((res = spa_node_send_command(data->source, &cmd)) < 0) @@ -548,7 +504,6 @@ int main(int argc, char *argv[]) spa_graph_data_init(&data.graph_data, &data.graph); spa_graph_set_callbacks(&data.graph, &spa_graph_impl_default, &data.graph_data); - data.map = &default_map.map; data.log = &default_log.log; data.data_loop.version = SPA_VERSION_LOOP; data.data_loop.add_source = do_add_source; @@ -564,17 +519,10 @@ int main(int argc, char *argv[]) printf("mode %08x\n", data.mode); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__DataLoop; - data.support[2].data = &data.data_loop; - data.support[3].type = SPA_TYPE_LOOP__MainLoop; - data.support[3].data = &data.data_loop; - data.n_support = 4; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.data_loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, &data.data_loop); + data.n_support = 3; if ((res = make_nodes(&data)) < 0) { printf("can't make nodes: %d\n", res); diff --git a/spa/tests/test-props.c b/spa/tests/test-props.c index 53b0c4c30..43e891cab 100644 --- a/spa/tests/test-props.c +++ b/spa/tests/test-props.c @@ -24,13 +24,13 @@ #include #include -#include #include #include #include #include #include #include +#include #if 0 /* { video/raw, @@ -148,42 +148,23 @@ key: "" ] spa_build(SPA_MEDIA_TYPE_VIDEO, SPA_MEDIA_SUBTYPE_RAW, - type.format_video.format, SPA_PROP_TYPE_ID, + SPA_FORMAT_VIDEO_format, SPA_PROP_TYPE_ID, video_format.I420 SPA_POD_PROP_FLAG_UNSET | SPA_PROP_RANGE_ENUM, 2, video_format.I420, video_format.YUY2, - type.format_video.size, SPA_PROP_TYPE_RECTANGLE, + SPA_FORMAT_VIDEO_size, SPA_PROP_TYPE_RECTANGLE, 320, 240, SPA_POD_PROP_FLAG_UNSET | SPA_PROP_RANGE_MIN_MAX, 1, 1, INT32_MAX, INT32_MAX, - type.format_video.framerate, SPA_PROP_TYPE_FRACTION, 25, 1, + SPA_FORMAT_VIDEO_framerate, SPA_PROP_TYPE_FRACTION, 25, 1, SPA_POD_PROP_FLAG_UNSET | SPA_PROP_RANGE_MIN_MAX, 0, 1, INT32_MAX, 1, 0); #endif -static SPA_TYPE_MAP_IMPL(default_map, 4096); - -static struct { - uint32_t format; - 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; -} type = { 0,}; - -static inline void type_init(struct spa_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_format_video_map(map, &type.format_video); - spa_type_video_format_map(map, &type.video_format); -} - -static void do_static_struct(struct spa_type_map *map) +static void do_static_struct(void) { struct _test_format { struct spa_pod_object fmt; @@ -214,23 +195,23 @@ static void do_static_struct(struct spa_type_map *map) } props; } test_format = { SPA_POD_OBJECT_INIT(sizeof(test_format.props) + sizeof(struct spa_pod_object_body), - 0, type.format), + 0, SPA_ID_OBJECT_Format), { - SPA_POD_ID_INIT(type.media_type.video), - SPA_POD_ID_INIT(type.media_subtype.raw), + SPA_POD_ID_INIT(SPA_MEDIA_TYPE_video), + SPA_POD_ID_INIT(SPA_MEDIA_SUBTYPE_raw), SPA_POD_PROP_INIT(sizeof(test_format.props.format_vals) + sizeof(struct spa_pod_prop_body), - type.format_video.format, + SPA_FORMAT_VIDEO_format, SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET, sizeof(uint32_t), SPA_POD_TYPE_ID), { - type.video_format.I420, - { type.video_format.I420, type.video_format.YUY2 } + SPA_VIDEO_FORMAT_I420, + { SPA_VIDEO_FORMAT_I420, SPA_VIDEO_FORMAT_YUY2 } }, SPA_POD_PROP_INIT(sizeof(test_format.props.size_vals) + sizeof(struct spa_pod_prop_body), - type.format_video.size, + SPA_FORMAT_VIDEO_size, SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET, sizeof(struct spa_rectangle), SPA_POD_TYPE_RECTANGLE), @@ -240,7 +221,7 @@ static void do_static_struct(struct spa_type_map *map) }, SPA_POD_PROP_INIT(sizeof(test_format.props.framerate_vals) + sizeof(struct spa_pod_prop_body), - type.format_video.framerate, + SPA_FORMAT_VIDEO_framerate, SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET, sizeof(struct spa_fraction), SPA_POD_TYPE_FRACTION), { @@ -250,8 +231,8 @@ static void do_static_struct(struct spa_type_map *map) } }; - spa_debug_pod(0, map, &test_format.fmt.pod); - spa_debug_format(0, map, &test_format.fmt.pod); + spa_debug_pod(0, spa_debug_types, &test_format.fmt.pod); + spa_debug_format(0, NULL, &test_format.fmt.pod); { uint32_t format = -1; @@ -259,16 +240,16 @@ static void do_static_struct(struct spa_type_map *map) struct spa_fraction frac = { -1, -1 }; res = spa_pod_object_parse(&test_format.fmt.pod, - ":",type.format_video.format, "I", &format, - ":",type.format_video.framerate, "F", &frac, NULL); + ":", SPA_FORMAT_VIDEO_format, "I", &format, + ":", SPA_FORMAT_VIDEO_framerate, "F", &frac, NULL); printf("%d format %d num %d denom %d\n", res, format, frac.num, frac.denom); spa_pod_fixate(&test_format.fmt.pod); res = spa_pod_object_parse(&test_format.fmt.pod, - ":",type.format_video.format, "I", &format, - ":",type.format_video.framerate, "F", &frac, NULL); + ":", SPA_FORMAT_VIDEO_format, "I", &format, + ":", SPA_FORMAT_VIDEO_framerate, "F", &frac, NULL); printf("%d format %d num %d denom %d\n", res, format, frac.num, frac.denom); } @@ -280,27 +261,24 @@ int main(int argc, char *argv[]) struct spa_pod_builder b = { NULL, }; uint8_t buffer[1024]; struct spa_pod_object *fmt; - struct spa_type_map *map = &default_map.map; - - type_init(map); spa_pod_builder_init(&b, buffer, sizeof(buffer)); - spa_pod_builder_push_object(&b, 0, type.format); + spa_pod_builder_push_object(&b, 0, SPA_ID_OBJECT_Format); - spa_pod_builder_id(&b, type.media_type.video); - spa_pod_builder_id(&b, type.media_subtype.raw); + spa_pod_builder_id(&b, SPA_MEDIA_TYPE_video); + spa_pod_builder_id(&b, SPA_MEDIA_SUBTYPE_raw); - spa_pod_builder_push_prop(&b, type.format_video.format, + spa_pod_builder_push_prop(&b, SPA_FORMAT_VIDEO_format, SPA_POD_PROP_RANGE_ENUM | SPA_POD_PROP_FLAG_UNSET); - spa_pod_builder_id(&b, type.video_format.I420); - spa_pod_builder_id(&b, type.video_format.I420); - spa_pod_builder_id(&b, type.video_format.YUY2); + spa_pod_builder_id(&b, SPA_VIDEO_FORMAT_I420); + spa_pod_builder_id(&b, SPA_VIDEO_FORMAT_I420); + spa_pod_builder_id(&b, SPA_VIDEO_FORMAT_YUY2); spa_pod_builder_pop(&b); struct spa_rectangle size_min_max[] = { {1, 1}, {INT32_MAX, INT32_MAX} }; spa_pod_builder_push_prop(&b, - type.format_video.size, + SPA_FORMAT_VIDEO_size, SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET); spa_pod_builder_rectangle(&b, 320, 240); spa_pod_builder_raw(&b, size_min_max, sizeof(size_min_max)); @@ -308,7 +286,7 @@ int main(int argc, char *argv[]) struct spa_fraction rate_min_max[] = { {0, 1}, {INT32_MAX, 1} }; spa_pod_builder_push_prop(&b, - type.format_video.framerate, + SPA_FORMAT_VIDEO_framerate, SPA_POD_PROP_RANGE_MIN_MAX | SPA_POD_PROP_FLAG_UNSET); spa_pod_builder_fraction(&b, 25, 1); spa_pod_builder_raw(&b, rate_min_max, sizeof(rate_min_max)); @@ -316,26 +294,26 @@ int main(int argc, char *argv[]) fmt = spa_pod_builder_pop(&b); - spa_debug_pod(0, map, &fmt->pod); + spa_debug_pod(0, spa_debug_types, &fmt->pod); spa_pod_builder_init(&b, buffer, sizeof(buffer)); fmt = spa_pod_builder_object(&b, - 0, type.format, - "I", type.media_type.video, - "I", type.media_subtype.raw, - ":", type.format_video.format, "Ieu", type.video_format.I420, - 2, type.video_format.I420, - type.video_format.YUY2, - ":", type.format_video.size, "Rru", &SPA_RECTANGLE(320,241), + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_video, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_VIDEO_format, "Ieu", SPA_VIDEO_FORMAT_I420, + 2, SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_YUY2, + ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320,241), 2, &SPA_RECTANGLE(1,1), &SPA_RECTANGLE(INT32_MAX,INT32_MAX), - ":", type.format_video.framerate, "Fru", &SPA_FRACTION(25,1), + ":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1), 2, &SPA_FRACTION(0,1), &SPA_FRACTION(INT32_MAX,1)); - spa_debug_pod(0, map, &fmt->pod); - spa_debug_format(0, map, &fmt->pod); + spa_debug_pod(0, spa_debug_types, &fmt->pod); + spa_debug_format(0, NULL, &fmt->pod); spa_pod_builder_init(&b, buffer, sizeof(buffer)); @@ -350,31 +328,33 @@ int main(int argc, char *argv[]) * ) */ fmt = spa_pod_builder_add(&b, - "<", 0, type.format, - "I", type.media_type.video, - "I", type.media_subtype.raw, - ":", type.format_video.format, "Ieu", type.video_format.I420, - 2, type.video_format.I420, - type.video_format.YUY2, - ":", type.format_video.size, "Rru", &SPA_RECTANGLE(320,242), + "<", 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_video, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_VIDEO_format, "Ieu", SPA_VIDEO_FORMAT_I420, + 2, SPA_VIDEO_FORMAT_I420, + SPA_VIDEO_FORMAT_YUY2, + ":", SPA_FORMAT_VIDEO_size, "Rru", &SPA_RECTANGLE(320,242), 2, &SPA_RECTANGLE(1,1), &SPA_RECTANGLE(INT32_MAX,INT32_MAX), - ":", type.format_video.framerate, "Fru", &SPA_FRACTION(25,1), + ":", SPA_FORMAT_VIDEO_framerate, "Fru", &SPA_FRACTION(25,1), 2, &SPA_FRACTION(0,1), &SPA_FRACTION(INT32_MAX,1), ">", NULL); - spa_debug_pod(0, map, &fmt->pod); - spa_debug_format(0, map, &fmt->pod); + spa_debug_pod(0, spa_debug_types, &fmt->pod); + spa_debug_format(0, NULL, &fmt->pod); - do_static_struct(map); + do_static_struct(); +#if 0 printf("media type is enum %d\n", spa_type_is_a(SPA_TYPE__MediaType, SPA_TYPE_ENUM_BASE)); printf("media sybtype is enum %d\n", spa_type_is_a(SPA_TYPE__MediaSubtype, SPA_TYPE_ENUM_BASE)); printf("format is enum %d\n", spa_type_is_a(SPA_TYPE__Format, SPA_TYPE_ENUM_BASE)); printf("format is pod %d\n", spa_type_is_a(SPA_TYPE__Format, SPA_TYPE_POD_BASE)); printf("format is object %d\n", spa_type_is_a(SPA_TYPE__Format, SPA_TYPE_POD_OBJECT_BASE)); +#endif return 0; } diff --git a/spa/tests/test-props2.c b/spa/tests/test-props2.c index 692b95c52..1236437a7 100644 --- a/spa/tests/test-props2.c +++ b/spa/tests/test-props2.c @@ -24,15 +24,13 @@ #include #include -#include #include #include #include #include #include - -static SPA_TYPE_MAP_IMPL(default_map, 4096); +#include int main(int argc, char *argv[]) { @@ -41,7 +39,6 @@ int main(int argc, char *argv[]) uint32_t ref; struct spa_pod *obj; struct spa_pod_parser prs; - struct spa_type_map *map = &default_map.map; b.data = buffer; b.size = 1024; @@ -84,11 +81,11 @@ int main(int argc, char *argv[]) spa_pod_builder_pop(&b); obj = spa_pod_builder_pop(&b); - spa_debug_pod(0, map, obj); + spa_debug_pod(0, spa_debug_types, obj); struct spa_pod_prop *p = spa_pod_find_prop(obj, 4); printf("%d %d\n", p->body.key, p->body.flags); - spa_debug_pod(0, map, &p->body.value); + spa_debug_pod(0, spa_debug_types, &p->body.value); obj = spa_pod_builder_deref(&b, ref); diff --git a/spa/tests/test-ringbuffer.c b/spa/tests/test-ringbuffer.c index aa3839056..3c9f69740 100644 --- a/spa/tests/test-ringbuffer.c +++ b/spa/tests/test-ringbuffer.c @@ -28,60 +28,14 @@ #include #include -#include #include #include #include #include #include -#include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - uint32_t props_device; - uint32_t props_freq; - uint32_t props_volume; - uint32_t props_min_latency; - uint32_t props_live; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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_event_node event_node; - struct spa_type_command_node command_node; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - type->props_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->props_freq = spa_type_map_get_id(map, SPA_TYPE_PROPS__frequency); - type->props_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume); - type->props_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency); - type->props_live = spa_type_map_get_id(map, SPA_TYPE_PROPS__live); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); -} - struct buffer { struct spa_buffer buffer; struct spa_meta metas[1]; @@ -91,10 +45,8 @@ struct buffer { }; struct data { - struct spa_type_map *map; struct spa_log *log; struct spa_loop data_loop; - struct type type; struct spa_support support[4]; uint32_t n_support; @@ -139,11 +91,11 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int b->header.seq = 0; b->header.pts = 0; b->header.dts_offset = 0; - b->metas[0].type = data->type.meta.Header; + b->metas[0].type = SPA_META_Header; b->metas[0].data = &b->header; b->metas[0].size = sizeof(b->header); - b->datas[0].type = data->type.data.MemPtr; + b->datas[0].type = SPA_DATA_MemPtr; b->datas[0].flags = 0; b->datas[0].fd = -1; b->datas[0].mapoffset = 0; @@ -192,7 +144,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, data->type.node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -284,11 +236,11 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_device, "s", device ? device : "hw:0", - ":", data->type.props_min_latency, "i", 64); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "s", device ? device : "hw:0", + ":", SPA_PROP_minLatency, "i", 64); - if ((res = spa_node_set_param(data->sink, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->sink, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); if ((res = make_node(data, &data->source, @@ -300,10 +252,10 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_live, "b", false); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_live, "b", false); - if ((res = spa_node_set_param(data->source, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->source, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); return res; } @@ -319,23 +271,23 @@ static int negotiate_formats(struct data *data) spa_pod_builder_init(&b, buffer, sizeof(buffer)); filter = spa_pod_builder_object(&b, - 0, data->type.format, - "I", data->type.media_type.audio, - "I", data->type.media_subtype.raw, - ":", data->type.format_audio.format, "I", data->type.audio_format.S16, - ":", data->type.format_audio.layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, - ":", data->type.format_audio.rate, "i", 44100, - ":", data->type.format_audio.channels, "i", 2); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_audio, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16, + ":", SPA_FORMAT_AUDIO_layout, "i", SPA_AUDIO_LAYOUT_INTERLEAVED, + ":", SPA_FORMAT_AUDIO_rate, "i", 44100, + ":", SPA_FORMAT_AUDIO_channels, "i", 2); if ((res = spa_node_port_enum_params(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idEnumFormat, &state, + SPA_ID_PARAM_EnumFormat, &state, filter, &format, &b)) <= 0) return -EBADF; if ((res = spa_node_port_set_param(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -343,16 +295,16 @@ static int negotiate_formats(struct data *data) spa_node_port_set_io(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_sink_io[0], sizeof(data->source_sink_io[0])); spa_node_port_set_io(data->sink, SPA_DIRECTION_INPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_sink_io[0], sizeof(data->source_sink_io[0])); if ((res = spa_node_port_set_param(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -430,7 +382,7 @@ static void run_async_sink(struct data *data) int err; { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); if ((res = spa_node_send_command(data->source, &cmd)) < 0) printf("got source error %d\n", res); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) @@ -452,7 +404,7 @@ static void run_async_sink(struct data *data) } { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); if ((res = spa_node_send_command(data->sink, &cmd)) < 0) printf("got sink error %d\n", res); if ((res = spa_node_send_command(data->source, &cmd)) < 0) @@ -466,7 +418,6 @@ int main(int argc, char *argv[]) int res; const char *str; - data.map = &default_map.map; data.log = &default_log.log; data.data_loop.version = SPA_VERSION_LOOP; data.data_loop.add_source = do_add_source; @@ -477,17 +428,10 @@ int main(int argc, char *argv[]) if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__DataLoop; - data.support[2].data = &data.data_loop; - data.support[3].type = SPA_TYPE_LOOP__MainLoop; - data.support[3].data = &data.data_loop; - data.n_support = 4; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.data_loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, &data.data_loop); + data.n_support = 3; if ((res = make_nodes(&data, argc > 1 ? argv[1] : NULL)) < 0) { printf("can't make nodes: %d\n", res); diff --git a/spa/tests/test-v4l2.c b/spa/tests/test-v4l2.c index 215764fdb..1f35f64a0 100644 --- a/spa/tests/test-v4l2.c +++ b/spa/tests/test-v4l2.c @@ -31,53 +31,14 @@ #include #include -#include #include #include #include #include #include -#include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - uint32_t node; - uint32_t props; - uint32_t format; - uint32_t props_device; - uint32_t SDL_Texture; - struct spa_type_io io; - struct spa_type_param param; - struct spa_type_meta meta; - struct spa_type_data data; - 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; - struct spa_type_event_node event_node; - struct spa_type_command_node command_node; -}; - -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->props = spa_type_map_get_id(map, SPA_TYPE__Props); - type->format = spa_type_map_get_id(map, SPA_TYPE__Format); - type->props_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device); - type->SDL_Texture = spa_type_map_get_id(map, SPA_TYPE_POINTER_BASE "SDL_Texture"); - spa_type_io_map(map, &type->io); - spa_type_param_map(map, &type->param); - spa_type_meta_map(map, &type->meta); - spa_type_data_map(map, &type->data); - 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); - spa_type_event_node_map(map, &type->event_node); - spa_type_command_node_map(map, &type->command_node); -} #define MAX_BUFFERS 8 @@ -91,9 +52,6 @@ struct buffer { }; struct data { - struct type type; - - struct spa_type_map *map; struct spa_log *log; struct spa_loop data_loop; @@ -160,7 +118,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib, printf("can't make factory instance: %d\n", res); return res; } - if ((res = spa_handle_get_interface(handle, data->type.node, &iface)) < 0) { + if ((res = spa_handle_get_interface(handle, SPA_ID_INTERFACE_Node, &iface)) < 0) { printf("can't get interface %d\n", res); return res; } @@ -227,7 +185,7 @@ static void on_source_process(void *_data, int status) fprintf(stderr, "Couldn't lock texture: %s\n", SDL_GetError()); return; } - datas[0].type = data->type.data.MemPtr; + datas[0].type = SPA_DATA_MemPtr; datas[0].flags = 0; datas[0].fd = -1; datas[0].mapoffset = 0; @@ -244,12 +202,12 @@ static void on_source_process(void *_data, int status) return; } sdata = datas[0].data; - if (datas[0].type == data->type.data.MemFd || - datas[0].type == data->type.data.DmaBuf) { + if (datas[0].type == SPA_DATA_MemFd || + datas[0].type == SPA_DATA_DmaBuf) { map = mmap(NULL, datas[0].maxsize + datas[0].mapoffset, PROT_READ, MAP_PRIVATE, datas[0].fd, 0); sdata = SPA_MEMBER(map, datas[0].mapoffset, uint8_t); - } else if (datas[0].type == data->type.data.MemPtr) { + } else if (datas[0].type == SPA_DATA_MemPtr) { map = NULL; sdata = datas[0].data; } else @@ -330,10 +288,10 @@ static int make_nodes(struct data *data, const char *device) spa_pod_builder_init(&b, buffer, sizeof(buffer)); props = spa_pod_builder_object(&b, - 0, data->type.props, - ":", data->type.props_device, "s", device ? device : "/dev/video0"); + 0, SPA_ID_OBJECT_Props, + ":", SPA_PROP_device, "s", device ? device : "/dev/video0"); - if ((res = spa_node_set_param(data->source, data->type.param.idProps, 0, props)) < 0) + if ((res = spa_node_set_param(data->source, SPA_ID_PARAM_Props, 0, props)) < 0) printf("got set_props error %d\n", res); return res; @@ -360,7 +318,7 @@ static int setup_buffers(struct data *data) b->header.seq = 0; b->header.pts = 0; b->header.dts_offset = 0; - b->metas[0].type = data->type.meta.Header; + b->metas[0].type = SPA_META_Header; b->metas[0].data = &b->header; b->metas[0].size = sizeof(b->header); @@ -402,7 +360,7 @@ static int sdl_alloc_buffers(struct data *data) } b->texture = texture; - b->datas[0].type = data->type.data.MemPtr; + b->datas[0].type = SPA_DATA_MemPtr; b->datas[0].maxsize = stride * 240; b->datas[0].data = ptr; b->datas[0].chunk->offset = 0; @@ -425,21 +383,21 @@ static int negotiate_formats(struct data *data) if ((res = spa_node_port_set_io(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.io.Buffers, + SPA_ID_IO_Buffers, &data->source_output[0], sizeof(data->source_output[0]))) < 0) return res; format = spa_pod_builder_object(&b, - 0, data->type.format, - "I", data->type.media_type.video, - "I", data->type.media_subtype.raw, - ":", data->type.format_video.format, "I", data->type.video_format.YUY2, - ":", data->type.format_video.size, "R", &SPA_RECTANGLE(320, 240), - ":", data->type.format_video.framerate, "F", &SPA_FRACTION(25,1)); + 0, SPA_ID_OBJECT_Format, + "I", SPA_MEDIA_TYPE_video, + "I", SPA_MEDIA_SUBTYPE_raw, + ":", SPA_FORMAT_VIDEO_format, "I", SPA_VIDEO_FORMAT_YUY2, + ":", SPA_FORMAT_VIDEO_size, "R", &SPA_RECTANGLE(320, 240), + ":", SPA_FORMAT_VIDEO_framerate, "F", &SPA_FRACTION(25,1)); if ((res = spa_node_port_set_param(data->source, SPA_DIRECTION_OUTPUT, 0, - data->type.param.idFormat, 0, + SPA_ID_PARAM_Format, 0, format)) < 0) return res; @@ -539,7 +497,7 @@ static void run_async_source(struct data *data) int err; { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Start); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Start); if ((res = spa_node_send_command(data->source, &cmd)) < 0) printf("got error %d\n", res); } @@ -558,7 +516,7 @@ static void run_async_source(struct data *data) } { - struct spa_command cmd = SPA_COMMAND_INIT(data->type.command_node.Pause); + struct spa_command cmd = SPA_COMMAND_INIT(SPA_ID_COMMAND_NODE_Pause); if ((res = spa_node_send_command(data->source, &cmd)) < 0) printf("got error %d\n", res); } @@ -572,7 +530,6 @@ int main(int argc, char *argv[]) data.use_buffer = true; - data.map = &default_map.map; data.log = &default_log.log; if ((str = getenv("SPA_DEBUG"))) @@ -584,17 +541,10 @@ int main(int argc, char *argv[]) data.data_loop.remove_source = do_remove_source; data.data_loop.invoke = do_invoke; - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__DataLoop; - data.support[2].data = &data.data_loop; - data.support[3].type = SPA_TYPE_LOOP__MainLoop; - data.support[3].data = &data.data_loop; - data.n_support = 4; - - init_type(&data.type, data.map); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.data_loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, &data.data_loop); + data.n_support = 3; if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("can't initialize SDL: %s\n", SDL_GetError()); diff --git a/spa/tools/spa-inspect.c b/spa/tools/spa-inspect.c index ddf661258..ca06192a5 100644 --- a/spa/tools/spa-inspect.c +++ b/spa/tools/spa-inspect.c @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -34,22 +33,13 @@ #include #include #include +#include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - uint32_t node; - uint32_t format; - struct spa_type_param param; -}; - struct data { - struct type type; - struct spa_support support[4]; uint32_t n_support; - struct spa_type_map *map; struct spa_log *log; struct spa_loop loop; }; @@ -68,7 +58,7 @@ inspect_node_params(struct data *data, struct spa_node *node) spa_pod_builder_init(&b, buffer, sizeof(buffer)); if ((res = spa_node_enum_params(node, - data->type.param.idList, &idx1, + SPA_ID_PARAM_List, &idx1, NULL, ¶m, &b)) <= 0) { if (res != 0) error(0, -res, "enum_params"); @@ -76,10 +66,10 @@ inspect_node_params(struct data *data, struct spa_node *node) } spa_pod_object_parse(param, - ":", data->type.param.listId, "I", &id, + ":", SPA_PARAM_LIST_id, "I", &id, NULL); - printf("enumerating: %s:\n", spa_type_map_get_type(data->map, id)); + printf("enumerating: %s:\n", spa_debug_type_find_name(spa_debug_types, id)); for (idx2 = 0;;) { spa_pod_builder_init(&b, buffer, sizeof(buffer)); if ((res = spa_node_enum_params(node, @@ -89,7 +79,7 @@ inspect_node_params(struct data *data, struct spa_node *node) error(0, -res, "enum_params %d", id); break; } - spa_debug_pod(0, data->map, param); + spa_debug_pod(0, spa_debug_types, param); } } } @@ -110,17 +100,17 @@ inspect_port_params(struct data *data, struct spa_node *node, spa_pod_builder_init(&b, buffer, sizeof(buffer)); if ((res = spa_node_port_enum_params(node, direction, port_id, - data->type.param.idList, &idx1, + SPA_ID_PARAM_List, &idx1, NULL, ¶m, &b)) <= 0) { if (res != 0) error(0, -res, "port_enum_params"); break; } spa_pod_object_parse(param, - ":", data->type.param.listId, "I", &id, + ":", SPA_PARAM_LIST_id, "I", &id, NULL); - printf("enumerating: %s:\n", spa_type_map_get_type(data->map, id)); + printf("enumerating: %s:\n", spa_debug_type_find_name(spa_debug_types, id)); for (idx2 = 0;;) { spa_pod_builder_init(&b, buffer, sizeof(buffer)); if ((res = spa_node_port_enum_params(node, @@ -132,10 +122,10 @@ inspect_port_params(struct data *data, struct spa_node *node, break; } - if (spa_pod_is_object_type(param, data->type.format)) - spa_debug_format(0, data->map, param); + if (spa_pod_is_object_type(param, SPA_ID_OBJECT_Format)) + spa_debug_format(0, NULL, param); else - spa_debug_pod(0, data->map, param); + spa_debug_pod(0, spa_debug_types, param); } } } @@ -203,7 +193,7 @@ static void inspect_factory(struct data *data, const struct spa_handle_factory * else error(0, -res, "spa_handle_factory_enum_interface_info"); } - printf(" interface: '%s'\n", info->type); + printf(" interface: '%d'\n", info->type); } handle = calloc(1, spa_handle_factory_get_size(factory, NULL)); @@ -216,27 +206,20 @@ static void inspect_factory(struct data *data, const struct spa_handle_factory * printf("factory instance:\n"); for (index = 0;;) { - uint32_t interface_id; - if ((res = spa_handle_factory_enum_interface_info(factory, &info, &index)) <= 0) { if (res == 0) break; else error(0, -res, "spa_handle_factory_enum_interface_info"); } - printf(" interface: '%s'\n", info->type); + printf(" interface: '%d'\n", info->type); - if (strcmp(info->type, SPA_TYPE__TypeMap) == 0) - interface_id = 0; - else - interface_id = spa_type_map_get_id(data->map, info->type); - - if ((res = spa_handle_get_interface(handle, interface_id, &interface)) < 0) { - printf("can't get interface: %d %d\n", interface_id, res); + if ((res = spa_handle_get_interface(handle, info->type, &interface)) < 0) { + printf("can't get interface: %d %d\n", info->type, res); continue; } - if (interface_id == data->type.node) + if (info->type == SPA_ID_INTERFACE_Node) inspect_node(data, interface); else printf("skipping unknown interface\n"); @@ -271,7 +254,6 @@ int main(int argc, char *argv[]) return -1; } - data.map = &default_map.map; data.log = &default_log.log; data.loop.version = SPA_VERSION_LOOP; data.loop.add_source = do_add_source; @@ -281,19 +263,10 @@ int main(int argc, char *argv[]) if ((str = getenv("SPA_DEBUG"))) data.log->level = atoi(str); - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__MainLoop; - data.support[2].data = &data.loop; - data.support[3].type = SPA_TYPE_LOOP__DataLoop; - data.support[3].data = &data.loop; - data.n_support = 4; - - data.type.node = spa_type_map_get_id(data.map, SPA_TYPE__Node); - data.type.format = spa_type_map_get_id(data.map, SPA_TYPE__Format); - spa_type_param_map(data.map, &data.type.param); + data.support[0] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.loop); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_DataLoop, &data.loop); + data.n_support = 3; if ((handle = dlopen(argv[1], RTLD_NOW)) == NULL) { printf("can't load %s\n", argv[1]); diff --git a/spa/tools/spa-monitor.c b/spa/tools/spa-monitor.c index 1fad9bc92..010fb75df 100644 --- a/spa/tools/spa-monitor.c +++ b/spa/tools/spa-monitor.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -34,17 +33,9 @@ #include #include -static SPA_TYPE_MAP_IMPL(default_map, 4096); static SPA_LOG_IMPL(default_log); -struct type { - struct spa_type_monitor monitor; -}; - struct data { - struct type type; - - struct spa_type_map *map; struct spa_log *log; struct spa_loop main_loop; @@ -62,22 +53,26 @@ struct data { static void inspect_item(struct data *data, struct spa_pod *item) { - spa_debug_pod(0, data->map, item); + spa_debug_pod(0, spa_type_monitor, item); } static void on_monitor_event(void *_data, struct spa_event *event) { struct data *data = _data; - if (SPA_EVENT_TYPE(event) == data->type.monitor.Added) { + switch (SPA_EVENT_TYPE(event)) { + case SPA_ID_EVENT_MONITOR_Added: fprintf(stderr, "added:\n"); inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event)); - } else if (SPA_EVENT_TYPE(event) == data->type.monitor.Removed) { + break; + case SPA_ID_EVENT_MONITOR_Removed: fprintf(stderr, "removed:\n"); inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event)); - } else if (SPA_EVENT_TYPE(event) == data->type.monitor.Changed) { + break; + case SPA_ID_EVENT_MONITOR_Changed: fprintf(stderr, "changed:\n"); inspect_item(data, SPA_POD_CONTENTS(struct spa_event, event)); + break; } } @@ -169,23 +164,16 @@ int main(int argc, char *argv[]) spa_handle_factory_enum_func_t enum_func; uint32_t fidx; - data.map = &default_map.map; data.log = &default_log.log; data.main_loop.version = SPA_VERSION_LOOP; data.main_loop.add_source = do_add_source; data.main_loop.update_source = do_update_source; data.main_loop.remove_source = do_remove_source; - data.support[0].type = SPA_TYPE__TypeMap; - data.support[0].data = data.map; - data.support[1].type = SPA_TYPE__Log; - data.support[1].data = data.log; - data.support[2].type = SPA_TYPE_LOOP__MainLoop; - data.support[2].data = &data.main_loop; + data.support[1] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_Log, data.log); + data.support[2] = SPA_SUPPORT_INIT(SPA_ID_INTERFACE_MainLoop, &data.main_loop); data.n_support = 3; - spa_type_monitor_map(data.map, &data.type.monitor); - if (argc < 2) { printf("usage: %s \n", argv[0]); return -1; @@ -220,7 +208,7 @@ int main(int argc, char *argv[]) break; } - if (!strcmp(info->type, SPA_TYPE__Monitor)) { + if (info->type == SPA_ID_INTERFACE_Monitor) { struct spa_handle *handle; void *interface; @@ -233,7 +221,7 @@ int main(int argc, char *argv[]) } if ((res = - spa_handle_get_interface(handle, data.type.monitor.Monitor, + spa_handle_get_interface(handle, SPA_ID_INTERFACE_Monitor, &interface)) < 0) { printf("can't get interface: %s\n", strerror(res)); continue; diff --git a/src/examples/audio-src.c b/src/examples/audio-src.c index cac81d721..865c4a139 100644 --- a/src/examples/audio-src.c +++ b/src/examples/audio-src.c @@ -23,8 +23,6 @@ #include #include -#include -#include #include #include @@ -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, diff --git a/src/examples/export-sink.c b/src/examples/export-sink.c index b5a394e35..bdd7ab02e 100644 --- a/src/examples/export-sink.c +++ b/src/examples/export-sink.c @@ -21,10 +21,6 @@ #include #include -#include - -#include -#include #include #include #include @@ -34,29 +30,16 @@ #include #include +#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) { diff --git a/src/examples/export-source.c b/src/examples/export-source.c index 57f158447..5fe9d2cbd 100644 --- a/src/examples/export-source.c +++ b/src/examples/export-source.c @@ -22,8 +22,6 @@ #include #include -#include -#include #include #include #include @@ -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); diff --git a/src/examples/export-spa.c b/src/examples/export-spa.c index 91121daca..5d473bb15 100644 --- a/src/examples/export-spa.c +++ b/src/examples/export-spa.c @@ -21,8 +21,6 @@ #include #include -#include -#include #include #include @@ -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]; diff --git a/src/examples/local-v4l2.c b/src/examples/local-v4l2.c index 442446e11..440f2427a 100644 --- a/src/examples/local-v4l2.c +++ b/src/examples/local-v4l2.c @@ -22,8 +22,6 @@ #include -#include -#include #include #include #include @@ -33,28 +31,11 @@ #include #include -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; diff --git a/src/examples/media-session.c b/src/examples/media-session.c index d1413b7b7..53b41873f 100644 --- a/src/examples/media-session.c +++ b/src/examples/media-session.c @@ -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); diff --git a/src/examples/video-play.c b/src/examples/video-play.c index caf609449..02675e3c2 100644 --- a/src/examples/video-play.c +++ b/src/examples/video-play.c @@ -21,38 +21,19 @@ #include #include -#include - -#include -#include #include #include #include #include -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; diff --git a/src/examples/video-src.c b/src/examples/video-src.c index 03f6b9db7..5512525a4 100644 --- a/src/examples/video-src.c +++ b/src/examples/video-src.c @@ -22,38 +22,18 @@ #include #include -#include -#include #include #include #include -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); diff --git a/src/gst/gstpipewiredeviceprovider.c b/src/gst/gstpipewiredeviceprovider.c index b6472d961..cd104cdff 100644 --- a/src/gst/gstpipewiredeviceprovider.c +++ b/src/gst/gstpipewiredeviceprovider.c @@ -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, ®istry_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); diff --git a/src/gst/gstpipewiredeviceprovider.h b/src/gst/gstpipewiredeviceprovider.h index 816226052..004b4eeb9 100644 --- a/src/gst/gstpipewiredeviceprovider.h +++ b/src/gst/gstpipewiredeviceprovider.h @@ -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; diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c index 5a5d42018..fd9e49e99 100644 --- a/src/gst/gstpipewireformat.c +++ b/src/gst/gstpipewireformat.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/src/gst/gstpipewireformat.h b/src/gst/gstpipewireformat.h index b179d4e64..0d427913a 100644 --- a/src/gst/gstpipewireformat.h +++ b/src/gst/gstpipewireformat.h @@ -22,17 +22,15 @@ #include -#include #include 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 diff --git a/src/gst/gstpipewirepool.c b/src/gst/gstpipewirepool.c index 78998a4f5..22270bbb0 100644 --- a/src/gst/gstpipewirepool.c +++ b/src/gst/gstpipewirepool.c @@ -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; diff --git a/src/gst/gstpipewiresink.c b/src/gst/gstpipewiresink.c index bc21250b7..0507f0fd8 100644 --- a/src/gst/gstpipewiresink.c +++ b/src/gst/gstpipewiresink.c @@ -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); diff --git a/src/gst/gstpipewiresink.h b/src/gst/gstpipewiresink.h index 5ff61f2e4..d72004b5b 100644 --- a/src/gst/gstpipewiresink.h +++ b/src/gst/gstpipewiresink.h @@ -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; diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index 332dabd46..1b8dac69d 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -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); diff --git a/src/gst/gstpipewiresrc.h b/src/gst/gstpipewiresrc.h index 613f888f0..ffa6fe1d7 100644 --- a/src/gst/gstpipewiresrc.h +++ b/src/gst/gstpipewiresrc.h @@ -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; diff --git a/src/modules/module-audio-dsp.c b/src/modules/module-audio-dsp.c index 6233f95e6..8a367fd10 100644 --- a/src/modules/module-audio-dsp.c +++ b/src/modules/module-audio-dsp.c @@ -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)); diff --git a/src/modules/module-client-node.c b/src/modules/module-client-node.c index d492b3cd7..ee0f05e19 100644 --- a/src/modules/module-client-node.c +++ b/src/modules/module-client-node.c @@ -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); diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index e7ec4e2a4..e96856d12 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -30,6 +30,7 @@ #include #include +#include #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; diff --git a/src/modules/module-client-node/client-stream.c b/src/modules/module-client-node/client-stream.c index 49fffa6b9..05edd9db0 100644 --- a/src/modules/module-client-node/client-stream.c +++ b/src/modules/module-client-node/client-stream.c @@ -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, ¶m, &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, ¶m, &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); diff --git a/src/modules/module-client-node/protocol-native.c b/src/modules/module-client-node/protocol-native.c index bcdb2e3a7..cf61d077e 100644 --- a/src/modules/module-client-node/protocol-native.c +++ b/src/modules/module-client-node/protocol-native.c @@ -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, diff --git a/src/modules/module-flatpak.c b/src/modules/module-flatpak.c index b9f253f73..0cb175f11 100644 --- a/src/modules/module-flatpak.c +++ b/src/modules/module-flatpak.c @@ -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); diff --git a/src/modules/module-link-factory.c b/src/modules/module-link-factory.c index a63df78d7..b8c3c0536 100644 --- a/src/modules/module-link-factory.c +++ b/src/modules/module-link-factory.c @@ -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)); diff --git a/src/modules/module-media-session.c b/src/modules/module-media-session.c index 800104b83..609b6f73c 100644 --- a/src/modules/module-media-session.c +++ b/src/modules/module-media-session.c @@ -29,6 +29,7 @@ #include #include #include +#include #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); diff --git a/src/modules/module-media-session/audio-dsp.c b/src/modules/module-media-session/audio-dsp.c index b9218355e..9d81f5b2a 100644 --- a/src/modules/module-media-session/audio-dsp.c +++ b/src/modules/module-media-session/audio-dsp.c @@ -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; diff --git a/src/modules/module-media-session/floatmix.c b/src/modules/module-media-session/floatmix.c index f47f0668c..02cc3fc25 100644 --- a/src/modules/module-media-session/floatmix.c +++ b/src/modules/module-media-session/floatmix.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -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, ¶m, &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, ¶m, &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 diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 8a1143615..49294fa83 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -29,6 +29,7 @@ #include #include +#include #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, diff --git a/src/modules/module-protocol-native/connection.c b/src/modules/module-protocol-native/connection.c index 7bf7b2f35..8c0b564f4 100644 --- a/src/modules/module-protocol-native/connection.c +++ b/src/modules/module-protocol-native/connection.c @@ -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); diff --git a/src/modules/module-protocol-native/protocol-native.c b/src/modules/module-protocol-native/protocol-native.c index b81f6d52f..295676636 100644 --- a/src/modules/module-protocol-native/protocol-native.c +++ b/src/modules/module-protocol-native/protocol-native.c @@ -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, diff --git a/src/modules/module-rtkit.c b/src/modules/module-rtkit.c index 9d10bd8ce..3298fd93c 100644 --- a/src/modules/module-rtkit.c +++ b/src/modules/module-rtkit.c @@ -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; diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c index 2ac42fa2a..4c0f48f9e 100644 --- a/src/modules/module-suspend-on-idle.c +++ b/src/modules/module-suspend-on-idle.c @@ -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); diff --git a/src/modules/spa/module-node-factory.c b/src/modules/spa/module-node-factory.c index 2457ad445..31a2491ea 100644 --- a/src/modules/spa/module-node-factory.c +++ b/src/modules/spa/module-node-factory.c @@ -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)); diff --git a/src/modules/spa/spa-monitor.c b/src/modules/spa/spa-monitor.c index 870f3fa34..343054d54 100644 --- a/src/modules/spa/spa-monitor.c +++ b/src/modules/spa/spa-monitor.c @@ -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; diff --git a/src/modules/spa/spa-node.c b/src/modules/spa/spa-node.c index 50b01d3f7..cb30e6864 100644 --- a/src/modules/spa/spa-node.c +++ b/src/modules/spa/spa-node.c @@ -28,6 +28,7 @@ #include #include #include +#include #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; } diff --git a/src/pipewire/client.c b/src/pipewire/client.c index e25eb648e..6512568f0 100644 --- a/src/pipewire/client.c +++ b/src/pipewire/client.c @@ -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) diff --git a/src/pipewire/control.c b/src/pipewire/control.c index 6456b654d..2a827224b 100644 --- a/src/pipewire/control.c +++ b/src/pipewire/control.c @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -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 | diff --git a/src/pipewire/core.c b/src/pipewire/core.c index 3993d317c..5c363f265 100644 --- a/src/pipewire/core.c +++ b/src/pipewire/core.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -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"); diff --git a/src/pipewire/core.h b/src/pipewire/core.h index b8f16b4ee..14e8d0e20 100644 --- a/src/pipewire/core.h +++ b/src/pipewire/core.h @@ -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); diff --git a/src/pipewire/factory.c b/src/pipewire/factory.c index cda3267e9..e7688f6b9 100644 --- a/src/pipewire/factory.c +++ b/src/pipewire/factory.c @@ -19,6 +19,8 @@ #include +#include + #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) diff --git a/src/pipewire/global.c b/src/pipewire/global.c index 9269e242f..e03326886 100644 --- a/src/pipewire/global.c +++ b/src/pipewire/global.c @@ -26,6 +26,8 @@ #include #include +#include + /** \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; diff --git a/src/pipewire/interfaces.h b/src/pipewire/interfaces.h index 3794f702d..ea8b02de3 100644 --- a/src/pipewire/interfaces.h +++ b/src/pipewire/interfaces.h @@ -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__) diff --git a/src/pipewire/link.c b/src/pipewire/link.c index 049a27f0b..686731e3d 100644 --- a/src/pipewire/link.c +++ b/src/pipewire/link.c @@ -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, ¤t, &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, ¤t, &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) diff --git a/src/pipewire/loop.c b/src/pipewire/loop.c index e05cafdc2..2340cc895 100644 --- a/src/pipewire/loop.c +++ b/src/pipewire/loop.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -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; diff --git a/src/pipewire/meson.build b/src/pipewire/meson.build index 8aeb6f57c..b7bad972c 100644 --- a/src/pipewire/meson.build +++ b/src/pipewire/meson.build @@ -56,7 +56,6 @@ pipewire_sources = [ 'resource.c', 'stream.c', 'thread-loop.c', - 'type.c', 'utils.c', 'work-queue.c', ] diff --git a/src/pipewire/module.c b/src/pipewire/module.c index 089fe43dc..ffbe3cd25 100644 --- a/src/pipewire/module.c +++ b/src/pipewire/module.c @@ -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), diff --git a/src/pipewire/node.c b/src/pipewire/node.c index 789bca4f5..db490f7ae 100644 --- a/src/pipewire/node.c +++ b/src/pipewire/node.c @@ -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) diff --git a/src/pipewire/pipewire.c b/src/pipewire/pipewire.c index 317c506cc..18f297ecc 100644 --- a/src/pipewire/pipewire.c +++ b/src/pipewire/pipewire.c @@ -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()); diff --git a/src/pipewire/pipewire.h b/src/pipewire/pipewire.h index 6e7e40d64..944c50839 100644 --- a/src/pipewire/pipewire.h +++ b/src/pipewire/pipewire.h @@ -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]); diff --git a/src/pipewire/port.c b/src/pipewire/port.c index d86513720..de2661169 100644 --- a/src/pipewire/port.c +++ b/src/pipewire/port.c @@ -22,6 +22,7 @@ #include #include +#include #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; diff --git a/src/pipewire/private.h b/src/pipewire/private.h index a054fa66d..3ddc7fbd4 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -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 */ diff --git a/src/pipewire/protocol.c b/src/pipewire/protocol.c index 39f594099..de72f7637 100644 --- a/src/pipewire/protocol.c +++ b/src/pipewire/protocol.c @@ -19,6 +19,8 @@ #include +#include + #include #include @@ -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; diff --git a/src/pipewire/protocol.h b/src/pipewire/protocol.h index 2b6592d1a..1981ffefd 100644 --- a/src/pipewire/protocol.h +++ b/src/pipewire/protocol.h @@ -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; diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c index 25fecfc11..7a48bcc12 100644 --- a/src/pipewire/remote.c +++ b/src/pipewire/remote.c @@ -25,6 +25,7 @@ #include #include +#include #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, ¶m, &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; diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index af07cb791..ff199d328 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -23,14 +23,13 @@ #include #include -#include #include -#include #include #include #include #include #include +#include #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 diff --git a/src/pipewire/type.c b/src/pipewire/type.c deleted file mode 100644 index 3deee224f..000000000 --- a/src/pipewire/type.c +++ /dev/null @@ -1,67 +0,0 @@ -/* PipeWire - * Copyright (C) 2015 Wim Taymans - * - * 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 - -#include -#include -#include -#include -#include - -#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; -} diff --git a/src/pipewire/type.h b/src/pipewire/type.h index 6c4b75298..29f8d099a 100644 --- a/src/pipewire/type.h +++ b/src/pipewire/type.h @@ -24,7 +24,6 @@ extern "C" { #endif -#include #include #include #include @@ -35,6 +34,23 @@ extern "C" { #include +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 diff --git a/src/tools/pipewire-cli.c b/src/tools/pipewire-cli.c index bcfb3d769..dca0efaae 100644 --- a/src/tools/pipewire-cli.c +++ b/src/tools/pipewire-cli.c @@ -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); diff --git a/src/tools/pipewire-monitor.c b/src/tools/pipewire-monitor.c index 7f73ecd35..e3f499879 100644 --- a/src/tools/pipewire-monitor.c +++ b/src/tools/pipewire-monitor.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -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,