type: add function to map types

Add a helper function to map the types. This should be used instead
of calling directly into the type mapper when CFI is used.
This commit is contained in:
Wim Taymans 2019-02-06 11:09:32 +01:00
parent dd3eb55aee
commit 317f3b6be7
3 changed files with 66 additions and 1 deletions

View file

@ -18,6 +18,7 @@
*/
#include <string.h>
#include <errno.h>
#include <spa/support/type-map.h>
#include <spa/utils/defs.h>
@ -25,12 +26,17 @@
#include <spa/param/format.h>
#include <spa/param/props.h>
#include <spa/monitor/monitor.h>
#include <spa/param/format-utils.h>
#include <spa/param/video/format-utils.h>
#include <spa/param/video/raw.h>
#include <spa/param/video-padding.h>
#include <spa/param/audio/format-utils.h>
#include <spa/param/audio/raw.h>
#include "pipewire/pipewire.h"
#include "pipewire/type.h"
#include "pipewire/module.h"
/** Initializes the type system
* \param type a type structure
* \memberof pw_type
@ -38,6 +44,8 @@
int pw_type_init(struct pw_type *type)
{
type->map = pw_get_support_interface(SPA_TYPE__TypeMap);
if (type->map == NULL)
return -EFAULT;
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);
@ -67,3 +75,52 @@ int pw_type_init(struct pw_type *type)
spa_type_param_io_map(type->map, &type->param_io);
return 0;
}
int pw_type_get(struct pw_type *type, const char *id, void *data)
{
if (!strcmp(id, SPA_TYPE__MediaType)) {
struct spa_type_media_type *t = data;
spa_type_media_type_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE__MediaSubtype)) {
struct spa_type_media_subtype *t = data;
spa_type_media_subtype_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE_MEDIA_SUBTYPE__Video)) {
struct spa_type_media_subtype_video *t = data;
spa_type_media_subtype_video_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE_MEDIA_SUBTYPE__Audio)) {
struct spa_type_media_subtype_audio *t = data;
spa_type_media_subtype_audio_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE_FORMAT__Video)) {
struct spa_type_format_video *t = data;
spa_type_format_video_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE_FORMAT__Audio)) {
struct spa_type_format_audio *t = data;
spa_type_format_audio_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE__AudioFormat)) {
struct spa_type_audio_format *t = data;
spa_type_audio_format_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE__VideoFormat)) {
struct spa_type_video_format *t = data;
spa_type_video_format_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE__AudioFormat)) {
struct spa_type_audio_format *t = data;
spa_type_audio_format_map(type->map, t);
}
else if (!strcmp(id, SPA_TYPE_PARAM__VideoPadding)) {
struct spa_type_param_video_padding *t = data;
spa_type_param_video_padding_map(type->map, t);
}
else {
uint32_t *t = data;
*t = spa_type_map_get_id(type->map, id);
}
return 0;
}

View file

@ -81,6 +81,8 @@ struct pw_type {
int pw_type_init(struct pw_type *type);
int pw_type_get(struct pw_type *type, const char *id, void *data);
#ifdef __cplusplus
}
#endif