mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
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:
parent
dd3eb55aee
commit
317f3b6be7
3 changed files with 66 additions and 1 deletions
|
|
@ -45,6 +45,9 @@ extern "C" {
|
|||
#define SPA_TYPE_MEDIA_SUBTYPE__raw SPA_TYPE_MEDIA_SUBTYPE_BASE "raw"
|
||||
|
||||
/* video subtypes */
|
||||
#define SPA_TYPE_MEDIA_SUBTYPE__Video SPA_TYPE_MEDIA_SUBTYPE_BASE "Video"
|
||||
#define SPA_TYPE_MEDIA_SUBTYPE_VIDEO_BASE SPA_TYPE_MEDIA_SUBTYPE__Video ":"
|
||||
|
||||
#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"
|
||||
|
|
@ -61,6 +64,9 @@ extern "C" {
|
|||
#define SPA_TYPE_MEDIA_SUBTYPE__bayer SPA_TYPE_MEDIA_SUBTYPE_BASE "bayer"
|
||||
|
||||
/* audio subtypes */
|
||||
#define SPA_TYPE_MEDIA_SUBTYPE__Audio SPA_TYPE_MEDIA_SUBTYPE_BASE "Audio"
|
||||
#define SPA_TYPE_MEDIA_SUBTYPE_AUDIO_BASE SPA_TYPE_MEDIA_SUBTYPE__Audio ":"
|
||||
|
||||
#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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue