mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
Remove dynamic types
Do not use dynamic types anymore. The reason is that it's difficult: - to maintain a shared type database over a network. - the extra overhead when translating between processes and for maintaining the translation tables. - race conditions in translating in RT-threads, this is a problem because we want to make event streams. We now have simple enums with types and extension points for all types. This is also nicer to use in general. We don't need the mapper anymore or pass strings around as types. There is a parallel type info system to get more info about ids and enums and their hierarchy. It can also be used for debugging.
This commit is contained in:
parent
e6977fa178
commit
fca3e1d85d
162 changed files with 5200 additions and 7461 deletions
|
|
@ -24,6 +24,7 @@
|
|||
#include <gst/video/video.h>
|
||||
#include <gst/audio/audio.h>
|
||||
|
||||
#include <spa/utils/type.h>
|
||||
#include <spa/param/video/format-utils.h>
|
||||
#include <spa/param/audio/format-utils.h>
|
||||
#include <spa/pod/builder.h>
|
||||
|
|
@ -32,141 +33,112 @@
|
|||
|
||||
struct media_type {
|
||||
const char *name;
|
||||
uint32_t *media_type;
|
||||
uint32_t *media_subtype;
|
||||
uint32_t media_type;
|
||||
uint32_t media_subtype;
|
||||
};
|
||||
|
||||
static struct {
|
||||
struct spa_type_map *map;
|
||||
uint32_t format;
|
||||
struct spa_type_media_type media_type;
|
||||
struct spa_type_media_subtype media_subtype;
|
||||
struct spa_type_media_subtype_video media_subtype_video;
|
||||
struct spa_type_media_subtype_audio media_subtype_audio;
|
||||
struct spa_type_format_video format_video;
|
||||
struct spa_type_format_audio format_audio;
|
||||
struct spa_type_video_format video_format;
|
||||
struct spa_type_audio_format audio_format;
|
||||
} type = { NULL, };
|
||||
|
||||
static void
|
||||
ensure_types (struct spa_type_map *map)
|
||||
{
|
||||
type.map = map;
|
||||
|
||||
type.format = spa_type_map_get_id (map, SPA_TYPE__Format);
|
||||
spa_type_media_type_map (map, &type.media_type);
|
||||
spa_type_media_subtype_map (map, &type.media_subtype);
|
||||
spa_type_media_subtype_video_map (map, &type.media_subtype_video);
|
||||
spa_type_media_subtype_audio_map (map, &type.media_subtype_audio);
|
||||
spa_type_format_video_map (map, &type.format_video);
|
||||
spa_type_format_audio_map (map, &type.format_audio);
|
||||
spa_type_video_format_map (map, &type.video_format);
|
||||
spa_type_audio_format_map (map, &type.audio_format);
|
||||
}
|
||||
|
||||
static const struct media_type media_type_map[] = {
|
||||
{ "video/x-raw", &type.media_type.video, &type.media_subtype.raw },
|
||||
{ "audio/x-raw", &type.media_type.audio, &type.media_subtype.raw },
|
||||
{ "image/jpeg", &type.media_type.video, &type.media_subtype_video.mjpg },
|
||||
{ "video/x-h264", &type.media_type.video, &type.media_subtype_video.h264 },
|
||||
{ "video/x-raw", SPA_MEDIA_TYPE_video, SPA_MEDIA_SUBTYPE_raw },
|
||||
{ "audio/x-raw", SPA_MEDIA_TYPE_audio, SPA_MEDIA_SUBTYPE_raw },
|
||||
{ "image/jpeg", SPA_MEDIA_TYPE_video, SPA_MEDIA_SUBTYPE_mjpg },
|
||||
{ "video/x-h264", SPA_MEDIA_TYPE_video, SPA_MEDIA_SUBTYPE_h264 },
|
||||
{ NULL, }
|
||||
};
|
||||
|
||||
static const uint32_t *video_format_map[] = {
|
||||
&type.video_format.UNKNOWN,
|
||||
&type.video_format.ENCODED,
|
||||
&type.video_format.I420,
|
||||
&type.video_format.YV12,
|
||||
&type.video_format.YUY2,
|
||||
&type.video_format.UYVY,
|
||||
&type.video_format.AYUV,
|
||||
&type.video_format.RGBx,
|
||||
&type.video_format.BGRx,
|
||||
&type.video_format.xRGB,
|
||||
&type.video_format.xBGR,
|
||||
&type.video_format.RGBA,
|
||||
&type.video_format.BGRA,
|
||||
&type.video_format.ARGB,
|
||||
&type.video_format.ABGR,
|
||||
&type.video_format.RGB,
|
||||
&type.video_format.BGR,
|
||||
&type.video_format.Y41B,
|
||||
&type.video_format.Y42B,
|
||||
&type.video_format.YVYU,
|
||||
&type.video_format.Y444,
|
||||
&type.video_format.v210,
|
||||
&type.video_format.v216,
|
||||
&type.video_format.NV12,
|
||||
&type.video_format.NV21,
|
||||
&type.video_format.GRAY8,
|
||||
&type.video_format.GRAY16_BE,
|
||||
&type.video_format.GRAY16_LE,
|
||||
&type.video_format.v308,
|
||||
&type.video_format.RGB16,
|
||||
&type.video_format.BGR16,
|
||||
&type.video_format.RGB15,
|
||||
&type.video_format.BGR15,
|
||||
&type.video_format.UYVP,
|
||||
&type.video_format.A420,
|
||||
&type.video_format.RGB8P,
|
||||
&type.video_format.YUV9,
|
||||
&type.video_format.YVU9,
|
||||
&type.video_format.IYU1,
|
||||
&type.video_format.ARGB64,
|
||||
&type.video_format.AYUV64,
|
||||
&type.video_format.r210,
|
||||
&type.video_format.I420_10BE,
|
||||
&type.video_format.I420_10LE,
|
||||
&type.video_format.I422_10BE,
|
||||
&type.video_format.I422_10LE,
|
||||
&type.video_format.Y444_10BE,
|
||||
&type.video_format.Y444_10LE,
|
||||
&type.video_format.GBR,
|
||||
&type.video_format.GBR_10BE,
|
||||
&type.video_format.GBR_10LE,
|
||||
&type.video_format.NV16,
|
||||
&type.video_format.NV24,
|
||||
&type.video_format.NV12_64Z32,
|
||||
&type.video_format.A420_10BE,
|
||||
&type.video_format.A420_10LE,
|
||||
&type.video_format.A422_10BE,
|
||||
&type.video_format.A422_10LE,
|
||||
&type.video_format.A444_10BE,
|
||||
&type.video_format.A444_10LE,
|
||||
&type.video_format.NV61,
|
||||
&type.video_format.P010_10BE,
|
||||
&type.video_format.P010_10LE,
|
||||
&type.video_format.IYU2,
|
||||
&type.video_format.VYUY,
|
||||
&type.video_format.GBRA,
|
||||
&type.video_format.GBRA_10BE,
|
||||
&type.video_format.GBRA_10LE,
|
||||
&type.video_format.GBR_12BE,
|
||||
&type.video_format.GBR_12LE,
|
||||
&type.video_format.GBRA_12BE,
|
||||
&type.video_format.GBRA_12LE,
|
||||
&type.video_format.I420_12BE,
|
||||
&type.video_format.I420_12LE,
|
||||
&type.video_format.I422_12BE,
|
||||
&type.video_format.I422_12LE,
|
||||
&type.video_format.Y444_12BE,
|
||||
&type.video_format.Y444_12LE,
|
||||
static const uint32_t video_format_map[] = {
|
||||
SPA_VIDEO_FORMAT_UNKNOWN,
|
||||
SPA_VIDEO_FORMAT_ENCODED,
|
||||
SPA_VIDEO_FORMAT_I420,
|
||||
SPA_VIDEO_FORMAT_YV12,
|
||||
SPA_VIDEO_FORMAT_YUY2,
|
||||
SPA_VIDEO_FORMAT_UYVY,
|
||||
SPA_VIDEO_FORMAT_AYUV,
|
||||
SPA_VIDEO_FORMAT_RGBx,
|
||||
SPA_VIDEO_FORMAT_BGRx,
|
||||
SPA_VIDEO_FORMAT_xRGB,
|
||||
SPA_VIDEO_FORMAT_xBGR,
|
||||
SPA_VIDEO_FORMAT_RGBA,
|
||||
SPA_VIDEO_FORMAT_BGRA,
|
||||
SPA_VIDEO_FORMAT_ARGB,
|
||||
SPA_VIDEO_FORMAT_ABGR,
|
||||
SPA_VIDEO_FORMAT_RGB,
|
||||
SPA_VIDEO_FORMAT_BGR,
|
||||
SPA_VIDEO_FORMAT_Y41B,
|
||||
SPA_VIDEO_FORMAT_Y42B,
|
||||
SPA_VIDEO_FORMAT_YVYU,
|
||||
SPA_VIDEO_FORMAT_Y444,
|
||||
SPA_VIDEO_FORMAT_v210,
|
||||
SPA_VIDEO_FORMAT_v216,
|
||||
SPA_VIDEO_FORMAT_NV12,
|
||||
SPA_VIDEO_FORMAT_NV21,
|
||||
SPA_VIDEO_FORMAT_GRAY8,
|
||||
SPA_VIDEO_FORMAT_GRAY16_BE,
|
||||
SPA_VIDEO_FORMAT_GRAY16_LE,
|
||||
SPA_VIDEO_FORMAT_v308,
|
||||
SPA_VIDEO_FORMAT_RGB16,
|
||||
SPA_VIDEO_FORMAT_BGR16,
|
||||
SPA_VIDEO_FORMAT_RGB15,
|
||||
SPA_VIDEO_FORMAT_BGR15,
|
||||
SPA_VIDEO_FORMAT_UYVP,
|
||||
SPA_VIDEO_FORMAT_A420,
|
||||
SPA_VIDEO_FORMAT_RGB8P,
|
||||
SPA_VIDEO_FORMAT_YUV9,
|
||||
SPA_VIDEO_FORMAT_YVU9,
|
||||
SPA_VIDEO_FORMAT_IYU1,
|
||||
SPA_VIDEO_FORMAT_ARGB64,
|
||||
SPA_VIDEO_FORMAT_AYUV64,
|
||||
SPA_VIDEO_FORMAT_r210,
|
||||
SPA_VIDEO_FORMAT_I420_10BE,
|
||||
SPA_VIDEO_FORMAT_I420_10LE,
|
||||
SPA_VIDEO_FORMAT_I422_10BE,
|
||||
SPA_VIDEO_FORMAT_I422_10LE,
|
||||
SPA_VIDEO_FORMAT_Y444_10BE,
|
||||
SPA_VIDEO_FORMAT_Y444_10LE,
|
||||
SPA_VIDEO_FORMAT_GBR,
|
||||
SPA_VIDEO_FORMAT_GBR_10BE,
|
||||
SPA_VIDEO_FORMAT_GBR_10LE,
|
||||
SPA_VIDEO_FORMAT_NV16,
|
||||
SPA_VIDEO_FORMAT_NV24,
|
||||
SPA_VIDEO_FORMAT_NV12_64Z32,
|
||||
SPA_VIDEO_FORMAT_A420_10BE,
|
||||
SPA_VIDEO_FORMAT_A420_10LE,
|
||||
SPA_VIDEO_FORMAT_A422_10BE,
|
||||
SPA_VIDEO_FORMAT_A422_10LE,
|
||||
SPA_VIDEO_FORMAT_A444_10BE,
|
||||
SPA_VIDEO_FORMAT_A444_10LE,
|
||||
SPA_VIDEO_FORMAT_NV61,
|
||||
SPA_VIDEO_FORMAT_P010_10BE,
|
||||
SPA_VIDEO_FORMAT_P010_10LE,
|
||||
SPA_VIDEO_FORMAT_IYU2,
|
||||
SPA_VIDEO_FORMAT_VYUY,
|
||||
SPA_VIDEO_FORMAT_GBRA,
|
||||
SPA_VIDEO_FORMAT_GBRA_10BE,
|
||||
SPA_VIDEO_FORMAT_GBRA_10LE,
|
||||
SPA_VIDEO_FORMAT_GBR_12BE,
|
||||
SPA_VIDEO_FORMAT_GBR_12LE,
|
||||
SPA_VIDEO_FORMAT_GBRA_12BE,
|
||||
SPA_VIDEO_FORMAT_GBRA_12LE,
|
||||
SPA_VIDEO_FORMAT_I420_12BE,
|
||||
SPA_VIDEO_FORMAT_I420_12LE,
|
||||
SPA_VIDEO_FORMAT_I422_12BE,
|
||||
SPA_VIDEO_FORMAT_I422_12LE,
|
||||
SPA_VIDEO_FORMAT_Y444_12BE,
|
||||
SPA_VIDEO_FORMAT_Y444_12LE,
|
||||
};
|
||||
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define _FORMAT_LE(fmt) &type.audio_format. fmt ## _OE
|
||||
#define _FORMAT_BE(fmt) &type.audio_format. fmt
|
||||
#define _FORMAT_LE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## _OE
|
||||
#define _FORMAT_BE(fmt) SPA_AUDIO_FORMAT_ ## fmt
|
||||
#elif __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define _FORMAT_LE(fmt) &type.audio_format. fmt
|
||||
#define _FORMAT_BE(fmt) &type.audio_format. fmt ## _OE
|
||||
#define _FORMAT_LE(fmt) SPA_AUDIO_FORMAT_ ## fmt
|
||||
#define _FORMAT_BE(fmt) SPA_AUDIO_FORMAT_ ## fmt ## _OE
|
||||
#endif
|
||||
|
||||
static const uint32_t *audio_format_map[] = {
|
||||
&type.audio_format.UNKNOWN,
|
||||
&type.audio_format.ENCODED,
|
||||
&type.audio_format.S8,
|
||||
&type.audio_format.U8,
|
||||
static const uint32_t audio_format_map[] = {
|
||||
SPA_AUDIO_FORMAT_UNKNOWN,
|
||||
SPA_AUDIO_FORMAT_ENCODED,
|
||||
SPA_AUDIO_FORMAT_S8,
|
||||
SPA_AUDIO_FORMAT_U8,
|
||||
_FORMAT_LE (S16),
|
||||
_FORMAT_BE (S16),
|
||||
_FORMAT_LE (U16),
|
||||
|
|
@ -217,6 +189,15 @@ find_media_types (const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int find_index(const uint32_t *items, int n_items, uint32_t id)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n_items; i++)
|
||||
if (items[i] == id)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_nth_string (const GValue *val, int idx)
|
||||
{
|
||||
|
|
@ -385,12 +366,12 @@ handle_video_fields (ConvertData *d)
|
|||
for (i = 0; (v = get_nth_string (value, i)); i++) {
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_video.format,
|
||||
SPA_FORMAT_VIDEO_format,
|
||||
get_range_type (value));
|
||||
|
||||
idx = gst_video_format_from_string (v);
|
||||
if (idx < SPA_N_ELEMENTS (video_format_map))
|
||||
spa_pod_builder_id (&d->b, *video_format_map[idx]);
|
||||
spa_pod_builder_id (&d->b, video_format_map[idx]);
|
||||
}
|
||||
prop = spa_pod_builder_pop(&d->b);
|
||||
if (i > 1)
|
||||
|
|
@ -403,7 +384,7 @@ handle_video_fields (ConvertData *d)
|
|||
for (i = 0; get_nth_rectangle (value, value2, i, &v); i++) {
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_video.size,
|
||||
SPA_FORMAT_VIDEO_size,
|
||||
get_range_type2 (value, value2));
|
||||
|
||||
spa_pod_builder_rectangle (&d->b, v.width, v.height);
|
||||
|
|
@ -419,7 +400,7 @@ handle_video_fields (ConvertData *d)
|
|||
for (i = 0; get_nth_fraction (value, i, &v); i++) {
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_video.framerate,
|
||||
SPA_FORMAT_VIDEO_framerate,
|
||||
get_range_type (value));
|
||||
|
||||
spa_pod_builder_fraction (&d->b, v.num, v.denom);
|
||||
|
|
@ -435,7 +416,7 @@ handle_video_fields (ConvertData *d)
|
|||
for (i = 0; get_nth_fraction (value, i, &v); i++) {
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_video.max_framerate,
|
||||
SPA_FORMAT_VIDEO_maxFramerate,
|
||||
get_range_type (value));
|
||||
|
||||
spa_pod_builder_fraction (&d->b, v.num, v.denom);
|
||||
|
|
@ -461,12 +442,12 @@ handle_audio_fields (ConvertData *d)
|
|||
for (i = 0; (v = get_nth_string (value, i)); i++) {
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_audio.format,
|
||||
SPA_FORMAT_AUDIO_format,
|
||||
get_range_type (value));
|
||||
|
||||
idx = gst_audio_format_from_string (v);
|
||||
if (idx < SPA_N_ELEMENTS (audio_format_map))
|
||||
spa_pod_builder_id (&d->b, *audio_format_map[idx]);
|
||||
spa_pod_builder_id (&d->b, audio_format_map[idx]);
|
||||
}
|
||||
prop = spa_pod_builder_pop(&d->b);
|
||||
if (i > 1)
|
||||
|
|
@ -488,7 +469,7 @@ handle_audio_fields (ConvertData *d)
|
|||
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_audio.layout,
|
||||
SPA_FORMAT_AUDIO_layout,
|
||||
get_range_type (value));
|
||||
|
||||
spa_pod_builder_int (&d->b, layout);
|
||||
|
|
@ -503,7 +484,7 @@ handle_audio_fields (ConvertData *d)
|
|||
for (i = 0; get_nth_int (value, i, &v); i++) {
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_audio.rate,
|
||||
SPA_FORMAT_AUDIO_rate,
|
||||
get_range_type (value));
|
||||
|
||||
spa_pod_builder_int (&d->b, v);
|
||||
|
|
@ -518,7 +499,7 @@ handle_audio_fields (ConvertData *d)
|
|||
for (i = 0; get_nth_int (value, i, &v); i++) {
|
||||
if (i == 0)
|
||||
spa_pod_builder_push_prop (&d->b,
|
||||
type.format_audio.channels,
|
||||
SPA_FORMAT_AUDIO_channels,
|
||||
get_range_type (value));
|
||||
|
||||
spa_pod_builder_int (&d->b, v);
|
||||
|
|
@ -553,13 +534,13 @@ convert_1 (ConvertData *d)
|
|||
|
||||
d->b.write = write_pod;
|
||||
|
||||
spa_pod_builder_push_object (&d->b, d->id, type.format);
|
||||
spa_pod_builder_id(&d->b, *d->type->media_type);
|
||||
spa_pod_builder_id(&d->b, *d->type->media_subtype);
|
||||
spa_pod_builder_push_object (&d->b, d->id, SPA_ID_OBJECT_Format);
|
||||
spa_pod_builder_id(&d->b, d->type->media_type);
|
||||
spa_pod_builder_id(&d->b, d->type->media_subtype);
|
||||
|
||||
if (*d->type->media_type == type.media_type.video)
|
||||
if (d->type->media_type == SPA_MEDIA_TYPE_video)
|
||||
handle_video_fields (d);
|
||||
else if (*d->type->media_type == type.media_type.audio)
|
||||
else if (d->type->media_type == SPA_MEDIA_TYPE_audio)
|
||||
handle_audio_fields (d);
|
||||
|
||||
spa_pod_builder_pop (&d->b);
|
||||
|
|
@ -568,7 +549,7 @@ convert_1 (ConvertData *d)
|
|||
}
|
||||
|
||||
struct spa_pod *
|
||||
gst_caps_to_format (GstCaps *caps, guint index, uint32_t id, struct spa_type_map *map)
|
||||
gst_caps_to_format (GstCaps *caps, guint index, uint32_t id)
|
||||
{
|
||||
ConvertData d;
|
||||
struct spa_pod *res;
|
||||
|
|
@ -576,8 +557,6 @@ gst_caps_to_format (GstCaps *caps, guint index, uint32_t id, struct spa_type_map
|
|||
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
|
||||
g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
|
||||
|
||||
ensure_types(map);
|
||||
|
||||
spa_zero (d);
|
||||
d.cf = gst_caps_get_features (caps, index);
|
||||
d.cs = gst_caps_get_structure (caps, index);
|
||||
|
|
@ -607,12 +586,10 @@ foreach_func (GstCapsFeatures *features,
|
|||
|
||||
|
||||
GPtrArray *
|
||||
gst_caps_to_format_all (GstCaps *caps, uint32_t id, struct spa_type_map *map)
|
||||
gst_caps_to_format_all (GstCaps *caps, uint32_t id)
|
||||
{
|
||||
ConvertData d;
|
||||
|
||||
ensure_types(map);
|
||||
|
||||
spa_zero (d);
|
||||
d.id = id;
|
||||
d.array = g_ptr_array_new_full (gst_caps_get_size (caps), (GDestroyNotify)g_free);
|
||||
|
|
@ -622,8 +599,26 @@ gst_caps_to_format_all (GstCaps *caps, uint32_t id, struct spa_type_map *map)
|
|||
return d.array;
|
||||
}
|
||||
|
||||
typedef const char *(*id_to_string_func)(uint32_t id);
|
||||
|
||||
static const char *video_id_to_string(uint32_t id)
|
||||
{
|
||||
int idx;
|
||||
if ((idx = find_index(video_format_map, SPA_N_ELEMENTS(video_format_map), id)) == -1)
|
||||
return NULL;
|
||||
return gst_video_format_to_string(idx);
|
||||
}
|
||||
|
||||
static const char *audio_id_to_string(uint32_t id)
|
||||
{
|
||||
int idx;
|
||||
if ((idx = find_index(audio_format_map, SPA_N_ELEMENTS(audio_format_map), id)) == -1)
|
||||
return NULL;
|
||||
return gst_audio_format_to_string(idx);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_id_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
|
||||
handle_id_prop (struct spa_pod_prop *prop, const char *key, id_to_string_func func, GstCaps *res)
|
||||
{
|
||||
const char * str;
|
||||
uint32_t *id = SPA_POD_CONTENTS (struct spa_pod_prop, prop);
|
||||
|
|
@ -636,7 +631,7 @@ handle_id_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
|
|||
|
||||
switch (flags & SPA_POD_PROP_RANGE_MASK) {
|
||||
case SPA_POD_PROP_RANGE_NONE:
|
||||
if (!(str = spa_type_map_get_type (type.map, id[0])))
|
||||
if (!(str = func(id[0])))
|
||||
return;
|
||||
gst_caps_set_simple (res, key, G_TYPE_STRING, rindex (str, ':') + 1, NULL);
|
||||
break;
|
||||
|
|
@ -646,7 +641,7 @@ handle_id_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
|
|||
|
||||
g_value_init (&list, GST_TYPE_LIST);
|
||||
for (i = 1; i < n_items; i++) {
|
||||
if (!(str = spa_type_map_get_type (type.map, id[i])))
|
||||
if (!(str = func(id[i])))
|
||||
continue;
|
||||
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
|
|
@ -798,58 +793,56 @@ handle_fraction_prop (struct spa_pod_prop *prop, const char *key, GstCaps *res)
|
|||
}
|
||||
}
|
||||
GstCaps *
|
||||
gst_caps_from_format (const struct spa_pod *format, struct spa_type_map *map)
|
||||
gst_caps_from_format (const struct spa_pod *format)
|
||||
{
|
||||
GstCaps *res = NULL;
|
||||
uint32_t media_type, media_subtype;
|
||||
struct spa_pod_prop *prop;
|
||||
|
||||
ensure_types(map);
|
||||
|
||||
spa_pod_object_parse(format, "I", &media_type,
|
||||
"I", &media_subtype);
|
||||
|
||||
if (media_type == type.media_type.video) {
|
||||
if (media_subtype == type.media_subtype.raw) {
|
||||
if (media_type == SPA_MEDIA_TYPE_video) {
|
||||
if (media_subtype == SPA_MEDIA_SUBTYPE_raw) {
|
||||
res = gst_caps_new_empty_simple ("video/x-raw");
|
||||
if ((prop = spa_pod_find_prop (format, type.format_video.format))) {
|
||||
handle_id_prop (prop, "format", res);
|
||||
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_format))) {
|
||||
handle_id_prop (prop, "format", video_id_to_string, res);
|
||||
}
|
||||
}
|
||||
else if (media_subtype == type.media_subtype_video.mjpg) {
|
||||
else if (media_subtype == SPA_MEDIA_SUBTYPE_mjpg) {
|
||||
res = gst_caps_new_empty_simple ("image/jpeg");
|
||||
}
|
||||
else if (media_subtype == type.media_subtype_video.h264) {
|
||||
else if (media_subtype == SPA_MEDIA_SUBTYPE_h264) {
|
||||
res = gst_caps_new_simple ("video/x-h264",
|
||||
"stream-format", G_TYPE_STRING, "byte-stream",
|
||||
"alignment", G_TYPE_STRING, "au",
|
||||
NULL);
|
||||
}
|
||||
if ((prop = spa_pod_find_prop (format, type.format_video.size))) {
|
||||
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_size))) {
|
||||
handle_rect_prop (prop, "width", "height", res);
|
||||
}
|
||||
if ((prop = spa_pod_find_prop (format, type.format_video.framerate))) {
|
||||
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_framerate))) {
|
||||
handle_fraction_prop (prop, "framerate", res);
|
||||
}
|
||||
if ((prop = spa_pod_find_prop (format, type.format_video.max_framerate))) {
|
||||
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_VIDEO_maxFramerate))) {
|
||||
handle_fraction_prop (prop, "max-framerate", res);
|
||||
}
|
||||
} else if (media_type == type.media_type.audio) {
|
||||
if (media_subtype == type.media_subtype.raw) {
|
||||
} else if (media_type == SPA_MEDIA_TYPE_audio) {
|
||||
if (media_subtype == SPA_MEDIA_SUBTYPE_raw) {
|
||||
res = gst_caps_new_simple ("audio/x-raw",
|
||||
"layout", G_TYPE_STRING, "interleaved",
|
||||
NULL);
|
||||
if ((prop = spa_pod_find_prop (format, type.format_audio.format))) {
|
||||
handle_id_prop (prop, "format", res);
|
||||
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_AUDIO_format))) {
|
||||
handle_id_prop (prop, "format", audio_id_to_string, res);
|
||||
}
|
||||
if ((prop = spa_pod_find_prop (format, type.format_audio.rate))) {
|
||||
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_AUDIO_rate))) {
|
||||
handle_int_prop (prop, "rate", res);
|
||||
}
|
||||
if ((prop = spa_pod_find_prop (format, type.format_audio.channels))) {
|
||||
if ((prop = spa_pod_find_prop (format, SPA_FORMAT_AUDIO_channels))) {
|
||||
handle_int_prop (prop, "channels", res);
|
||||
}
|
||||
}
|
||||
else if (media_subtype == type.media_subtype_audio.aac) {
|
||||
else if (media_subtype == SPA_MEDIA_SUBTYPE_aac) {
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue