mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
format: improve format parsing
This commit is contained in:
parent
94019fb1f5
commit
29cb7bf39a
30 changed files with 459 additions and 406 deletions
|
|
@ -57,7 +57,7 @@ type_map_get_id (SpaTypeMap *map, const char *type)
|
|||
}
|
||||
|
||||
static const char *
|
||||
type_map_get_type (SpaTypeMap *map, uint32_t id)
|
||||
type_map_get_type (const SpaTypeMap *map, uint32_t id)
|
||||
{
|
||||
TypeMap *this = SPA_CONTAINER_OF (map, TypeMap, map);
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ type_map_get_type (SpaTypeMap *map, uint32_t id)
|
|||
}
|
||||
|
||||
static size_t
|
||||
type_map_get_size (SpaTypeMap *map)
|
||||
type_map_get_size (const SpaTypeMap *map)
|
||||
{
|
||||
TypeMap *this = SPA_CONTAINER_OF (map, TypeMap, map);
|
||||
return pinos_map_get_size (&this->types);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ typedef struct {
|
|||
} MediaType;
|
||||
|
||||
static struct {
|
||||
SpaTypeMap *map;
|
||||
uint32_t format;
|
||||
SpaTypeMediaType media_type;
|
||||
SpaTypeMediaSubtype media_subtype;
|
||||
|
|
@ -47,12 +48,12 @@ static struct {
|
|||
SpaTypeFormatAudio format_audio;
|
||||
SpaTypeVideoFormat video_format;
|
||||
SpaTypeAudioFormat audio_format;
|
||||
} type = { 0, };
|
||||
} type = { NULL, };
|
||||
|
||||
static void
|
||||
ensure_types (void)
|
||||
{
|
||||
SpaTypeMap *map = spa_type_map_get_default ();
|
||||
SpaTypeMap *map = type.map = spa_type_map_get_default ();
|
||||
|
||||
type.format = spa_type_map_get_id (map, SPA_TYPE__Format);
|
||||
spa_type_media_type_map (map, &type.media_type);
|
||||
|
|
@ -591,17 +592,19 @@ gst_caps_from_format (const SpaFormat *format)
|
|||
|
||||
ensure_types();
|
||||
|
||||
media_type = format->body.media_type.value;
|
||||
media_subtype = format->body.media_subtype.value;
|
||||
media_type = SPA_FORMAT_MEDIA_TYPE (format);
|
||||
media_subtype = SPA_FORMAT_MEDIA_SUBTYPE (format);
|
||||
|
||||
if (media_type == type.media_type.video) {
|
||||
SpaVideoInfo f;
|
||||
|
||||
if (spa_format_video_parse (format, &f) < 0)
|
||||
return NULL;
|
||||
SpaVideoInfo f = { media_type, media_subtype, };
|
||||
|
||||
if (media_subtype == type.media_subtype.raw) {
|
||||
const char * str = spa_type_map_get_type (spa_type_map_get_default (), f.info.raw.format);
|
||||
const char * str;
|
||||
|
||||
if (!spa_format_video_raw_parse (format, &f.info.raw, &type.format_video))
|
||||
return NULL;
|
||||
|
||||
str = spa_type_map_get_type (type.map, f.info.raw.format);
|
||||
|
||||
res = gst_caps_new_simple ("video/x-raw",
|
||||
"format", G_TYPE_STRING, rindex (str, ':') + 1,
|
||||
|
|
@ -611,6 +614,9 @@ gst_caps_from_format (const SpaFormat *format)
|
|||
NULL);
|
||||
}
|
||||
else if (media_subtype == type.media_subtype_video.mjpg) {
|
||||
if (!spa_format_video_mjpg_parse (format, &f.info.mjpg, &type.format_video))
|
||||
return NULL;
|
||||
|
||||
res = gst_caps_new_simple ("image/jpeg",
|
||||
"width", G_TYPE_INT, f.info.mjpg.size.width,
|
||||
"height", G_TYPE_INT, f.info.mjpg.size.height,
|
||||
|
|
@ -618,6 +624,9 @@ gst_caps_from_format (const SpaFormat *format)
|
|||
NULL);
|
||||
}
|
||||
else if (media_subtype == type.media_subtype_video.h264) {
|
||||
if (!spa_format_video_h264_parse (format, &f.info.h264, &type.format_video))
|
||||
return NULL;
|
||||
|
||||
res = gst_caps_new_simple ("video/x-h264",
|
||||
"width", G_TYPE_INT, f.info.h264.size.width,
|
||||
"height", G_TYPE_INT, f.info.h264.size.height,
|
||||
|
|
@ -627,13 +636,15 @@ gst_caps_from_format (const SpaFormat *format)
|
|||
NULL);
|
||||
}
|
||||
} else if (media_type == type.media_type.audio) {
|
||||
SpaAudioInfo f;
|
||||
|
||||
if (spa_format_audio_parse (format, &f) < 0)
|
||||
return NULL;
|
||||
SpaAudioInfo f = { media_type, media_subtype, };
|
||||
|
||||
if (media_subtype == type.media_subtype.raw) {
|
||||
const char * str = spa_type_map_get_type (spa_type_map_get_default (), f.info.raw.format);
|
||||
const char * str;
|
||||
|
||||
if (!spa_format_audio_raw_parse (format, &f.info.raw, &type.format_audio))
|
||||
return NULL;
|
||||
|
||||
str = spa_type_map_get_type (type.map, f.info.raw.format);
|
||||
|
||||
res = gst_caps_new_simple ("audio/x-raw",
|
||||
"format", G_TYPE_STRING, rindex (str, ':') + 1,
|
||||
|
|
|
|||
|
|
@ -587,7 +587,7 @@ again:
|
|||
}
|
||||
pinos_log_debug ("Try filter: %p", filter);
|
||||
if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG))
|
||||
spa_debug_format (filter);
|
||||
spa_debug_format (filter, core->type.map);
|
||||
|
||||
if ((res = spa_node_port_enum_formats (output->node->node,
|
||||
SPA_DIRECTION_OUTPUT,
|
||||
|
|
@ -605,7 +605,7 @@ again:
|
|||
}
|
||||
pinos_log_debug ("Got filtered:");
|
||||
if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG))
|
||||
spa_debug_format (format);
|
||||
spa_debug_format (format, core->type.map);
|
||||
|
||||
spa_format_fixate (format);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
|
||||
pinos_log_debug ("link %p: doing set format", this);
|
||||
if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG))
|
||||
spa_debug_format (format);
|
||||
spa_debug_format (format, this->core->type.map);
|
||||
|
||||
if (out_state == SPA_NODE_STATE_CONFIGURE) {
|
||||
pinos_log_debug ("link %p: doing set format on output", this);
|
||||
|
|
@ -347,8 +347,8 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
goto error;
|
||||
}
|
||||
if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG)) {
|
||||
spa_debug_port_info (oinfo);
|
||||
spa_debug_port_info (iinfo);
|
||||
spa_debug_port_info (oinfo, this->core->type.map);
|
||||
spa_debug_port_info (iinfo, this->core->type.map);
|
||||
}
|
||||
|
||||
in_flags = iinfo->flags;
|
||||
|
|
|
|||
|
|
@ -117,12 +117,12 @@ dump_node_info (PinosContext *c,
|
|||
printf ("%c\tinputs: %u/%u\n", MARK_CHANGE (1), info->n_inputs, info->max_inputs);
|
||||
printf ("%c\tinput formats:\n", MARK_CHANGE (2));
|
||||
for (i = 0; i < info->n_input_formats; i++)
|
||||
spa_debug_format (info->input_formats[i]);
|
||||
spa_debug_format (info->input_formats[i], c->type.map);
|
||||
|
||||
printf ("%c\toutputs: %u/%u\n", MARK_CHANGE (3), info->n_outputs, info->max_outputs);
|
||||
printf ("%c\toutput formats:\n", MARK_CHANGE (4));
|
||||
for (i = 0; i < info->n_output_formats; i++)
|
||||
spa_debug_format (info->output_formats[i]);
|
||||
spa_debug_format (info->output_formats[i], c->type.map);
|
||||
|
||||
printf ("%c\tstate: \"%s\"", MARK_CHANGE (5), pinos_node_state_as_string (info->state));
|
||||
if (info->state == PINOS_NODE_STATE_ERROR && info->error)
|
||||
|
|
|
|||
|
|
@ -50,8 +50,21 @@ spa_type_format_audio_map (SpaTypeMap *map, SpaTypeFormatAudio *type)
|
|||
}
|
||||
}
|
||||
|
||||
SpaResult spa_format_audio_parse (const SpaFormat *format,
|
||||
SpaAudioInfo *info);
|
||||
static inline bool
|
||||
spa_format_audio_raw_parse (const SpaFormat *format,
|
||||
SpaAudioInfoRaw *info,
|
||||
SpaTypeFormatAudio *type)
|
||||
{
|
||||
spa_format_query (format,
|
||||
type->format, SPA_POD_TYPE_ID, &info->format,
|
||||
type->flags, SPA_POD_TYPE_INT, &info->flags,
|
||||
type->layout, SPA_POD_TYPE_INT, &info->layout,
|
||||
type->rate, SPA_POD_TYPE_INT, &info->rate,
|
||||
type->channels, SPA_POD_TYPE_INT, &info->channels,
|
||||
type->channel_mask, SPA_POD_TYPE_INT, &info->channel_mask,
|
||||
0);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -144,6 +144,9 @@ spa_type_media_subtype_audio_map (SpaTypeMap *map, SpaTypeMediaSubtypeAudio *typ
|
|||
#define SPA_FORMAT_FOREACH(format, iter) \
|
||||
SPA_FORMAT_BODY_FOREACH(&format->body, SPA_POD_BODY_SIZE(format), iter)
|
||||
|
||||
#define SPA_FORMAT_MEDIA_TYPE(f) SPA_POD_VALUE (SpaPODId, &f->body.media_type)
|
||||
#define SPA_FORMAT_MEDIA_SUBTYPE(f) SPA_POD_VALUE (SpaPODId, &f->body.media_subtype)
|
||||
|
||||
static inline SpaPODProp *
|
||||
spa_format_find_prop (const SpaFormat *format, uint32_t key)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,10 +51,10 @@ struct _SpaTypeMap {
|
|||
SpaType (*get_id) (SpaTypeMap *map,
|
||||
const char *type);
|
||||
|
||||
const char * (*get_type) (SpaTypeMap *map,
|
||||
const char * (*get_type) (const SpaTypeMap *map,
|
||||
SpaType id);
|
||||
|
||||
size_t (*get_size) (SpaTypeMap *map);
|
||||
size_t (*get_size) (const SpaTypeMap *map);
|
||||
};
|
||||
|
||||
#define spa_type_map_get_id(n,...) (n)->get_id((n),__VA_ARGS__)
|
||||
|
|
|
|||
|
|
@ -74,8 +74,57 @@ spa_type_format_video_map (SpaTypeMap *map, SpaTypeFormatVideo *type)
|
|||
}
|
||||
}
|
||||
|
||||
SpaResult spa_format_video_parse (const SpaFormat *format,
|
||||
SpaVideoInfo *info);
|
||||
static inline bool
|
||||
spa_format_video_raw_parse (const SpaFormat *format,
|
||||
SpaVideoInfoRaw *info,
|
||||
SpaTypeFormatVideo *type)
|
||||
{
|
||||
spa_format_query (format,
|
||||
type->format, SPA_POD_TYPE_ID, &info->format,
|
||||
type->size, SPA_POD_TYPE_RECTANGLE, &info->size,
|
||||
type->framerate, SPA_POD_TYPE_FRACTION, &info->framerate,
|
||||
type->max_framerate, SPA_POD_TYPE_FRACTION, &info->max_framerate,
|
||||
type->views, SPA_POD_TYPE_INT, &info->views,
|
||||
type->interlace_mode, SPA_POD_TYPE_INT, &info->interlace_mode,
|
||||
type->pixel_aspect_ratio, SPA_POD_TYPE_FRACTION, &info->pixel_aspect_ratio,
|
||||
type->multiview_mode, SPA_POD_TYPE_INT, &info->multiview_mode,
|
||||
type->multiview_flags, SPA_POD_TYPE_INT, &info->multiview_flags,
|
||||
type->chroma_site, SPA_POD_TYPE_INT, &info->chroma_site,
|
||||
type->color_range, SPA_POD_TYPE_INT, &info->color_range,
|
||||
type->color_matrix, SPA_POD_TYPE_INT, &info->color_matrix,
|
||||
type->transfer_function, SPA_POD_TYPE_INT, &info->transfer_function,
|
||||
type->color_primaries, SPA_POD_TYPE_INT, &info->color_primaries,
|
||||
0);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_format_video_h264_parse (const SpaFormat *format,
|
||||
SpaVideoInfoH264 *info,
|
||||
SpaTypeFormatVideo *type)
|
||||
{
|
||||
spa_format_query (format,
|
||||
type->size, SPA_POD_TYPE_RECTANGLE, &info->size,
|
||||
type->framerate, SPA_POD_TYPE_FRACTION, &info->framerate,
|
||||
type->max_framerate, SPA_POD_TYPE_FRACTION, &info->max_framerate,
|
||||
type->stream_format, SPA_POD_TYPE_INT , &info->stream_format,
|
||||
type->alignment , SPA_POD_TYPE_INT , &info->alignment,
|
||||
0);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
spa_format_video_mjpg_parse (const SpaFormat *format,
|
||||
SpaVideoInfoMJPG *info,
|
||||
SpaTypeFormatVideo *type)
|
||||
{
|
||||
spa_format_query (format,
|
||||
type->size, SPA_POD_TYPE_RECTANGLE, &info->size,
|
||||
type->framerate, SPA_POD_TYPE_FRACTION, &info->framerate,
|
||||
type->max_framerate, SPA_POD_TYPE_FRACTION, &info->max_framerate,
|
||||
0);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <lib/mapper.h>
|
||||
#include <spa/audio/raw-utils.h>
|
||||
#include <spa/audio/format-utils.h>
|
||||
|
||||
SpaResult
|
||||
spa_format_audio_parse (const SpaFormat *format,
|
||||
SpaAudioInfo *info)
|
||||
{
|
||||
static SpaTypeMediaType media_type = { 0, };
|
||||
static SpaTypeMediaSubtype media_subtype = { 0, };
|
||||
static SpaTypeMediaSubtypeAudio media_subtype_audio = { 0, };
|
||||
static SpaTypeFormatAudio format_audio = { 0, };
|
||||
SpaTypeMap *map = spa_type_map_get_default();
|
||||
|
||||
spa_type_media_type_map (map, &media_type);
|
||||
spa_type_media_subtype_map (map, &media_subtype);
|
||||
spa_type_media_subtype_audio_map (map, &media_subtype_audio);
|
||||
spa_type_format_audio_map (map, &format_audio);
|
||||
|
||||
if (format->body.media_type.value != media_type.audio)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
info->media_type = format->body.media_type.value;
|
||||
info->media_subtype = format->body.media_subtype.value;
|
||||
|
||||
if (info->media_subtype == media_subtype.raw) {
|
||||
spa_format_query (format,
|
||||
format_audio.format, SPA_POD_TYPE_ID, &info->info.raw.format,
|
||||
format_audio.flags, SPA_POD_TYPE_INT, &info->info.raw.flags,
|
||||
format_audio.layout, SPA_POD_TYPE_INT, &info->info.raw.layout,
|
||||
format_audio.rate, SPA_POD_TYPE_INT, &info->info.raw.rate,
|
||||
format_audio.channels, SPA_POD_TYPE_INT, &info->info.raw.channels,
|
||||
format_audio.channel_mask, SPA_POD_TYPE_INT, &info->info.raw.channel_mask,
|
||||
0);
|
||||
}
|
||||
else
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ static const struct data_type_name {
|
|||
#define DATA_TYPE_NAME(t) data_type_names[SPA_CLAMP(t,0,SPA_N_ELEMENTS(data_type_names)-1)].name
|
||||
|
||||
SpaResult
|
||||
spa_debug_port_info (const SpaPortInfo *info)
|
||||
spa_debug_port_info (const SpaPortInfo *info, const SpaTypeMap *map)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ spa_debug_port_info (const SpaPortInfo *info)
|
|||
fprintf (stderr, " n_params: \t%d\n", info->n_params);
|
||||
for (i = 0; i < info->n_params; i++) {
|
||||
SpaAllocParam *param = info->params[i];
|
||||
spa_debug_pod (¶m->pod);
|
||||
spa_debug_pod (¶m->pod, map);
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -176,9 +176,9 @@ spa_debug_dump_mem (const void *mem, size_t size)
|
|||
}
|
||||
|
||||
SpaResult
|
||||
spa_debug_props (const SpaProps *props, bool print_ranges)
|
||||
spa_debug_props (const SpaProps *props, const SpaTypeMap *map)
|
||||
{
|
||||
spa_debug_pod (&props->pod);
|
||||
spa_debug_pod (&props->pod, map);
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ struct pod_type_name {
|
|||
};
|
||||
|
||||
static void
|
||||
print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
||||
print_pod_value (const SpaTypeMap *map, uint32_t size, uint32_t type, void *body, int prefix)
|
||||
{
|
||||
switch (type) {
|
||||
case SPA_POD_TYPE_BOOL:
|
||||
|
|
@ -215,7 +215,7 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
break;
|
||||
case SPA_POD_TYPE_ID:
|
||||
printf ("%-*sId %d %s\n", prefix, "", *(int32_t *) body,
|
||||
spa_type_map_get_type (spa_type_map_get_default(), *(int32_t*)body));
|
||||
spa_type_map_get_type (map, *(int32_t*)body));
|
||||
break;
|
||||
case SPA_POD_TYPE_INT:
|
||||
printf ("%-*sInt %d\n", prefix, "", *(int32_t *) body);
|
||||
|
|
@ -236,7 +236,7 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
{
|
||||
SpaPODPointerBody *b = body;
|
||||
printf ("%-*sPointer %s %p\n", prefix, "",
|
||||
spa_type_map_get_type (spa_type_map_get_default(), b->type), b->value);
|
||||
spa_type_map_get_type (map, b->type), b->value);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_RECTANGLE:
|
||||
|
|
@ -261,7 +261,7 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
printf ("%-*sArray: child.size %d, child.type %d\n", prefix, "", b->child.size, b->child.type);
|
||||
|
||||
SPA_POD_ARRAY_BODY_FOREACH (b, size, p)
|
||||
print_pod_value (b->child.size, b->child.type, p, prefix + 2);
|
||||
print_pod_value (map, b->child.size, b->child.type, p, prefix + 2);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_STRUCT:
|
||||
|
|
@ -269,7 +269,7 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
SpaPOD *b = body, *p;
|
||||
printf ("%-*sStruct: size %d\n", prefix, "", size);
|
||||
SPA_POD_FOREACH (b, size, p)
|
||||
print_pod_value (p->size, p->type, SPA_POD_BODY (p), prefix + 2);
|
||||
print_pod_value (map, p->size, p->type, SPA_POD_BODY (p), prefix + 2);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_OBJECT:
|
||||
|
|
@ -278,9 +278,9 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
SpaPOD *p;
|
||||
|
||||
printf ("%-*sObject: size %d, id %d, type %s\n", prefix, "", size, b->id,
|
||||
spa_type_map_get_type (spa_type_map_get_default(), b->type));
|
||||
spa_type_map_get_type (map, b->type));
|
||||
SPA_POD_OBJECT_BODY_FOREACH (b, size, p)
|
||||
print_pod_value (p->size, p->type, SPA_POD_BODY (p), prefix + 2);
|
||||
print_pod_value (map, p->size, p->type, SPA_POD_BODY (p), prefix + 2);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_PROP:
|
||||
|
|
@ -290,18 +290,18 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
int i;
|
||||
|
||||
printf ("%-*sProp: key %s, flags %d\n", prefix, "",
|
||||
spa_type_map_get_type (spa_type_map_get_default(), b->key), b->flags);
|
||||
spa_type_map_get_type (map, b->key), b->flags);
|
||||
if (b->flags & SPA_POD_PROP_FLAG_UNSET)
|
||||
printf ("%-*sUnset (Default):\n", prefix + 2, "");
|
||||
else
|
||||
printf ("%-*sValue: size %u\n", prefix + 2, "", b->value.size);
|
||||
print_pod_value (b->value.size, b->value.type, SPA_POD_BODY (&b->value), prefix + 4);
|
||||
print_pod_value (map, b->value.size, b->value.type, SPA_POD_BODY (&b->value), prefix + 4);
|
||||
|
||||
i = 0;
|
||||
SPA_POD_PROP_ALTERNATIVE_FOREACH (b, size, alt) {
|
||||
if (i == 0)
|
||||
printf ("%-*sAlternatives:\n", prefix + 2, "");
|
||||
print_pod_value (b->value.size, b->value.type, alt, prefix + 4);
|
||||
print_pod_value (map, b->value.size, b->value.type, alt, prefix + 4);
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -321,14 +321,15 @@ print_pod_value (uint32_t size, uint32_t type, void *body, int prefix)
|
|||
}
|
||||
|
||||
SpaResult
|
||||
spa_debug_pod (const SpaPOD *pod)
|
||||
spa_debug_pod (const SpaPOD *pod, const SpaTypeMap *map)
|
||||
{
|
||||
print_pod_value (pod->size, pod->type, SPA_POD_BODY (pod), 0);
|
||||
map = map ? map : spa_type_map_get_default ();
|
||||
print_pod_value (map, pod->size, pod->type, SPA_POD_BODY (pod), 0);
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
print_format_value (uint32_t size, uint32_t type, void *body)
|
||||
print_format_value (const SpaTypeMap *map, uint32_t size, uint32_t type, void *body)
|
||||
{
|
||||
switch (type) {
|
||||
case SPA_POD_TYPE_BOOL:
|
||||
|
|
@ -336,7 +337,7 @@ print_format_value (uint32_t size, uint32_t type, void *body)
|
|||
break;
|
||||
case SPA_POD_TYPE_ID:
|
||||
{
|
||||
const char *str = spa_type_map_get_type (spa_type_map_get_default(), *(int32_t*)body);
|
||||
const char *str = spa_type_map_get_type (map, *(int32_t*)body);
|
||||
if (str) {
|
||||
const char *h = rindex (str, ':');
|
||||
if (h)
|
||||
|
|
@ -386,7 +387,7 @@ print_format_value (uint32_t size, uint32_t type, void *body)
|
|||
}
|
||||
|
||||
SpaResult
|
||||
spa_debug_format (const SpaFormat *format)
|
||||
spa_debug_format (const SpaFormat *format, const SpaTypeMap *map)
|
||||
{
|
||||
int i;
|
||||
const char *media_type;
|
||||
|
|
@ -397,11 +398,13 @@ spa_debug_format (const SpaFormat *format)
|
|||
if (format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
map = map ? map : spa_type_map_get_default ();
|
||||
|
||||
mtype = format->body.media_type.value;
|
||||
mstype = format->body.media_subtype.value;
|
||||
|
||||
media_type = spa_type_map_get_type (spa_type_map_get_default (), mtype);
|
||||
media_subtype = spa_type_map_get_type (spa_type_map_get_default (), mstype);
|
||||
media_type = spa_type_map_get_type (map, mtype);
|
||||
media_subtype = spa_type_map_get_type (map, mstype);
|
||||
|
||||
fprintf (stderr, "%-6s %s/%s\n", "", rindex (media_type, ':')+1, rindex (media_subtype, ':')+1);
|
||||
|
||||
|
|
@ -412,12 +415,14 @@ spa_debug_format (const SpaFormat *format)
|
|||
(prop->body.flags & SPA_POD_PROP_FLAG_OPTIONAL))
|
||||
continue;
|
||||
|
||||
key = spa_type_map_get_type (spa_type_map_get_default (), prop->body.key);
|
||||
key = spa_type_map_get_type (map, prop->body.key);
|
||||
|
||||
fprintf (stderr, " %20s : (%s) ", rindex (key, ':')+1, pod_type_names[prop->body.value.type].name);
|
||||
|
||||
if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
|
||||
print_format_value (prop->body.value.size, prop->body.value.type, SPA_POD_BODY (&prop->body.value));
|
||||
print_format_value (map, prop->body.value.size,
|
||||
prop->body.value.type,
|
||||
SPA_POD_BODY (&prop->body.value));
|
||||
} else {
|
||||
const char *ssep, *esep, *sep;
|
||||
void *alt;
|
||||
|
|
@ -444,7 +449,7 @@ spa_debug_format (const SpaFormat *format)
|
|||
SPA_POD_PROP_ALTERNATIVE_FOREACH (&prop->body, prop->pod.size, alt) {
|
||||
if (i > 0)
|
||||
fprintf (stderr, "%s", sep);
|
||||
print_format_value (prop->body.value.size, prop->body.value.type, alt);
|
||||
print_format_value (map, prop->body.value.size, prop->body.value.type, alt);
|
||||
i++;
|
||||
}
|
||||
fprintf (stderr, esep);
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ extern "C" {
|
|||
#include <spa/format.h>
|
||||
#include <spa/dict.h>
|
||||
|
||||
SpaResult spa_debug_port_info (const SpaPortInfo *info);
|
||||
SpaResult spa_debug_port_info (const SpaPortInfo *info, const SpaTypeMap *map);
|
||||
SpaResult spa_debug_buffer (const SpaBuffer *buffer);
|
||||
SpaResult spa_debug_pod (const SpaPOD *pod);
|
||||
SpaResult spa_debug_props (const SpaProps *props, bool print_ranges);
|
||||
SpaResult spa_debug_format (const SpaFormat *format);
|
||||
SpaResult spa_debug_props (const SpaProps *props, const SpaTypeMap *map);
|
||||
SpaResult spa_debug_pod (const SpaPOD *pod, const SpaTypeMap *map);
|
||||
SpaResult spa_debug_format (const SpaFormat *format, const SpaTypeMap *map);
|
||||
SpaResult spa_debug_dump_mem (const void *data, size_t size);
|
||||
SpaResult spa_debug_dict (const SpaDict *dict);
|
||||
|
||||
|
|
|
|||
61
spa/lib/format.c
Normal file
61
spa/lib/format.c
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <spa/format-builder.h>
|
||||
#include <spa/video/format-utils.h>
|
||||
#include <lib/props.h>
|
||||
#include <lib/mapper.h>
|
||||
|
||||
SpaResult
|
||||
spa_format_filter (const SpaFormat *format,
|
||||
const SpaFormat *filter,
|
||||
SpaPODBuilder *result)
|
||||
{
|
||||
SpaPODFrame f;
|
||||
SpaResult res;
|
||||
|
||||
if (format == NULL || result == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (filter == NULL) {
|
||||
spa_pod_builder_raw_padded (result, format, SPA_POD_SIZE (format));
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
if (SPA_FORMAT_MEDIA_TYPE (filter) != SPA_FORMAT_MEDIA_TYPE (format) ||
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (filter) != SPA_FORMAT_MEDIA_SUBTYPE (format))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
spa_pod_builder_push_format (result, &f, filter->body.obj_body.type,
|
||||
SPA_FORMAT_MEDIA_TYPE (filter),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (filter));
|
||||
res = spa_props_filter (result,
|
||||
SPA_POD_CONTENTS (SpaFormat, format),
|
||||
SPA_POD_CONTENTS_SIZE (SpaFormat, format),
|
||||
SPA_POD_CONTENTS (SpaFormat, filter),
|
||||
SPA_POD_CONTENTS_SIZE (SpaFormat, filter));
|
||||
spa_pod_builder_pop (result, &f);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ type_map_get_id (SpaTypeMap *map, const char *type)
|
|||
}
|
||||
|
||||
static const char *
|
||||
type_map_get_type (SpaTypeMap *map, uint32_t id)
|
||||
type_map_get_type (const SpaTypeMap *map, uint32_t id)
|
||||
{
|
||||
TypeMap *this = SPA_CONTAINER_OF (map, TypeMap, map);
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ type_map_get_type (SpaTypeMap *map, uint32_t id)
|
|||
}
|
||||
|
||||
static size_t
|
||||
type_map_get_size (SpaTypeMap *map)
|
||||
type_map_get_size (const SpaTypeMap *map)
|
||||
{
|
||||
TypeMap *this = SPA_CONTAINER_OF (map, TypeMap, map);
|
||||
return this->n_types;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
spalib_sources = ['audio-raw.c',
|
||||
'debug.c',
|
||||
spalib_sources = ['debug.c',
|
||||
'mapper.c',
|
||||
'props.c',
|
||||
'video-raw.c']
|
||||
'format.c']
|
||||
|
||||
spalib = shared_library('spa-lib',
|
||||
spalib_sources,
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <spa/format-builder.h>
|
||||
#include <spa/video/format-utils.h>
|
||||
#include <lib/props.h>
|
||||
#include <lib/mapper.h>
|
||||
|
||||
SpaResult
|
||||
spa_format_video_parse (const SpaFormat *format,
|
||||
SpaVideoInfo *info)
|
||||
{
|
||||
static SpaTypeMediaType media_type = { 0, };
|
||||
static SpaTypeMediaSubtype media_subtype = { 0, };
|
||||
static SpaTypeMediaSubtypeVideo media_subtype_video = { 0, };
|
||||
static SpaTypeFormatVideo format_video = { 0, };
|
||||
SpaTypeMap *map = spa_type_map_get_default ();
|
||||
|
||||
spa_type_media_type_map (map, &media_type);
|
||||
spa_type_media_subtype_map (map, &media_subtype);
|
||||
spa_type_media_subtype_video_map (map, &media_subtype_video);
|
||||
spa_type_format_video_map (map, &format_video);
|
||||
|
||||
if (format->body.media_type.value != media_type.video)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
info->media_type = format->body.media_type.value;
|
||||
info->media_subtype = format->body.media_subtype.value;
|
||||
|
||||
if (info->media_subtype == media_subtype.raw)
|
||||
spa_format_query (format,
|
||||
format_video.format, SPA_POD_TYPE_ID, &info->info.raw.format,
|
||||
format_video.size, SPA_POD_TYPE_RECTANGLE, &info->info.raw.size,
|
||||
format_video.framerate, SPA_POD_TYPE_FRACTION, &info->info.raw.framerate,
|
||||
format_video.max_framerate, SPA_POD_TYPE_FRACTION, &info->info.raw.max_framerate,
|
||||
format_video.views, SPA_POD_TYPE_INT, &info->info.raw.views,
|
||||
format_video.interlace_mode, SPA_POD_TYPE_INT, &info->info.raw.interlace_mode,
|
||||
format_video.pixel_aspect_ratio, SPA_POD_TYPE_FRACTION, &info->info.raw.pixel_aspect_ratio,
|
||||
format_video.multiview_mode, SPA_POD_TYPE_INT, &info->info.raw.multiview_mode,
|
||||
format_video.multiview_flags, SPA_POD_TYPE_INT, &info->info.raw.multiview_flags,
|
||||
format_video.chroma_site, SPA_POD_TYPE_INT, &info->info.raw.chroma_site,
|
||||
format_video.color_range, SPA_POD_TYPE_INT, &info->info.raw.color_range,
|
||||
format_video.color_matrix, SPA_POD_TYPE_INT, &info->info.raw.color_matrix,
|
||||
format_video.transfer_function, SPA_POD_TYPE_INT, &info->info.raw.transfer_function,
|
||||
format_video.color_primaries, SPA_POD_TYPE_INT, &info->info.raw.color_primaries,
|
||||
0);
|
||||
else if (info->media_subtype == media_subtype_video.h264)
|
||||
spa_format_query (format,
|
||||
format_video.size, SPA_POD_TYPE_RECTANGLE, &info->info.h264.size,
|
||||
format_video.framerate, SPA_POD_TYPE_FRACTION, &info->info.h264.framerate,
|
||||
format_video.max_framerate, SPA_POD_TYPE_FRACTION, &info->info.h264.max_framerate,
|
||||
0);
|
||||
else if (info->media_subtype == media_subtype_video.mjpg)
|
||||
spa_format_query (format,
|
||||
format_video.size, SPA_POD_TYPE_RECTANGLE, &info->info.mjpg.size,
|
||||
format_video.framerate, SPA_POD_TYPE_FRACTION, &info->info.mjpg.framerate,
|
||||
format_video.max_framerate, SPA_POD_TYPE_FRACTION, &info->info.mjpg.max_framerate,
|
||||
0);
|
||||
else
|
||||
return SPA_RESULT_NOT_IMPLEMENTED;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
SpaResult
|
||||
spa_format_filter (const SpaFormat *format,
|
||||
const SpaFormat *filter,
|
||||
SpaPODBuilder *result)
|
||||
{
|
||||
SpaPODFrame f;
|
||||
SpaResult res;
|
||||
|
||||
if (format == NULL || result == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
if (filter == NULL) {
|
||||
spa_pod_builder_raw_padded (result, format, SPA_POD_SIZE (format));
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
if (filter->body.media_type.value != format->body.media_type.value ||
|
||||
filter->body.media_subtype.value != format->body.media_subtype.value)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
spa_pod_builder_push_format (result, &f, filter->body.obj_body.type,
|
||||
filter->body.media_type.value,
|
||||
filter->body.media_subtype.value);
|
||||
res = spa_props_filter (result,
|
||||
SPA_POD_CONTENTS (SpaFormat, format),
|
||||
SPA_POD_CONTENTS_SIZE (SpaFormat, format),
|
||||
SPA_POD_CONTENTS (SpaFormat, filter),
|
||||
SPA_POD_CONTENTS_SIZE (SpaFormat, filter));
|
||||
spa_pod_builder_pop (result, &f);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -349,7 +349,6 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
|
|||
const SpaFormat *format)
|
||||
{
|
||||
SpaALSASink *this;
|
||||
SpaResult res;
|
||||
SpaPODBuilder b = { NULL };
|
||||
SpaPODFrame f[2];
|
||||
|
||||
|
|
@ -367,46 +366,57 @@ spa_alsa_sink_node_port_set_format (SpaNode *node,
|
|||
spa_alsa_clear_buffers (this);
|
||||
spa_alsa_close (this);
|
||||
this->have_format = false;
|
||||
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
||||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.audio ||
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (spa_alsa_set_format (this, &info, flags) < 0)
|
||||
return SPA_RESULT_ERROR;
|
||||
|
||||
this->current_format = info;
|
||||
this->have_format = true;
|
||||
}
|
||||
|
||||
if ((res = spa_format_audio_parse (format, &this->current_format)) < 0)
|
||||
return res;
|
||||
if (this->have_format) {
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_LIVE;
|
||||
this->info.maxbuffering = this->buffer_frames * this->frame_size;
|
||||
this->info.latency = (this->period_frames * SPA_NSEC_PER_SEC) / this->rate;
|
||||
this->info.n_params = 3;
|
||||
this->info.params = this->params;
|
||||
|
||||
if (spa_alsa_set_format (this, &this->current_format, flags) < 0)
|
||||
return SPA_RESULT_ERROR;
|
||||
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_LIVE;
|
||||
this->info.maxbuffering = this->buffer_frames * this->frame_size;
|
||||
this->info.latency = (this->period_frames * SPA_NSEC_PER_SEC) / this->rate;
|
||||
this->info.n_params = 3;
|
||||
this->info.params = this->params;
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_RINGBUFFER),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferSize, SPA_POD_TYPE_INT, this->period_frames * this->frame_size * 32),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferStride, SPA_POD_TYPE_INT, 0),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferBlocks, SPA_POD_TYPE_INT, 1),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferAlign, SPA_POD_TYPE_INT, 16));
|
||||
this->params[2] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
this->info.extra = NULL;
|
||||
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_RINGBUFFER),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferSize, SPA_POD_TYPE_INT, this->period_frames * this->frame_size * 32),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferStride, SPA_POD_TYPE_INT, 0),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferBlocks, SPA_POD_TYPE_INT, 1),
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.ringbufferAlign, SPA_POD_TYPE_INT, 16));
|
||||
this->params[2] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
this->info.extra = NULL;
|
||||
|
||||
this->have_format = true;
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
}
|
||||
else
|
||||
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -399,7 +399,6 @@ spa_alsa_source_node_port_set_format (SpaNode *node,
|
|||
const SpaFormat *format)
|
||||
{
|
||||
SpaALSASource *this;
|
||||
SpaResult res;
|
||||
SpaPODBuilder b = { NULL };
|
||||
SpaPODFrame f[2];
|
||||
|
||||
|
|
@ -416,39 +415,50 @@ spa_alsa_source_node_port_set_format (SpaNode *node,
|
|||
spa_alsa_clear_buffers (this);
|
||||
spa_alsa_close (this);
|
||||
this->have_format = false;
|
||||
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
||||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.audio ||
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (spa_alsa_set_format (this, &info, flags) < 0)
|
||||
return SPA_RESULT_ERROR;
|
||||
|
||||
this->current_format = info;
|
||||
this->have_format = true;
|
||||
}
|
||||
|
||||
if ((res = spa_format_audio_parse (format, &this->current_format)) < 0)
|
||||
return res;
|
||||
if (this->have_format) {
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_LIVE;
|
||||
this->info.maxbuffering = this->buffer_frames * this->frame_size;
|
||||
this->info.latency = (this->period_frames * SPA_NSEC_PER_SEC) / this->rate;
|
||||
this->info.n_params = 2;
|
||||
this->info.params = this->params;
|
||||
|
||||
if (spa_alsa_set_format (this, &this->current_format, flags) < 0)
|
||||
return SPA_RESULT_ERROR;
|
||||
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||
SPA_PORT_INFO_FLAG_LIVE;
|
||||
this->info.maxbuffering = this->buffer_frames * this->frame_size;
|
||||
this->info.latency = (this->period_frames * SPA_NSEC_PER_SEC) / this->rate;
|
||||
this->info.n_params = 2;
|
||||
this->info.params = this->params;
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
|
||||
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, this->period_frames * this->frame_size),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
|
||||
PROP_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 1, 32),
|
||||
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
||||
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
this->info.extra = NULL;
|
||||
|
||||
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
||||
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
|
||||
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
||||
|
||||
this->info.extra = NULL;
|
||||
this->have_format = true;
|
||||
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
update_state (this, SPA_NODE_STATE_READY);
|
||||
} else {
|
||||
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
SpaTypeMediaType media_type;
|
||||
SpaTypeMediaSubtype media_subtype;
|
||||
SpaTypeFormatAudio format_audio;
|
||||
SpaTypeCommandNode command_node;
|
||||
} Type;
|
||||
|
||||
|
|
@ -65,6 +68,9 @@ static inline void
|
|||
init_type (Type *type, SpaTypeMap *map)
|
||||
{
|
||||
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
|
||||
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_command_node_map (map, &type->command_node);
|
||||
}
|
||||
|
||||
|
|
@ -295,7 +301,6 @@ spa_audiomixer_node_port_set_format (SpaNode *node,
|
|||
{
|
||||
SpaAudioMixer *this;
|
||||
SpaAudioMixerPort *port;
|
||||
SpaResult res;
|
||||
|
||||
if (node == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -309,14 +314,20 @@ spa_audiomixer_node_port_set_format (SpaNode *node,
|
|||
|
||||
if (format == NULL) {
|
||||
port->have_format = false;
|
||||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.audio ||
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
port->format = info;
|
||||
port->have_format = true;
|
||||
}
|
||||
|
||||
if ((res = spa_format_audio_parse (format, &port->format)) < 0)
|
||||
return res;
|
||||
|
||||
port->have_format = true;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -528,7 +528,6 @@ spa_audiotestsrc_node_port_set_format (SpaNode *node,
|
|||
const SpaFormat *format)
|
||||
{
|
||||
SpaAudioTestSrc *this;
|
||||
SpaResult res;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -542,9 +541,17 @@ spa_audiotestsrc_node_port_set_format (SpaNode *node,
|
|||
this->have_format = false;
|
||||
clear_buffers (this);
|
||||
} else {
|
||||
if ((res = spa_format_audio_parse (format, &this->current_format)) < 0)
|
||||
return res;
|
||||
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.audio ||
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
this->current_format = info;
|
||||
this->bpf = (2 * this->current_format.info.raw.channels);
|
||||
this->have_format = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint32_t node;
|
||||
SpaTypeMediaType media_type;
|
||||
SpaTypeMediaSubtype media_subtype;
|
||||
SpaTypeFormatVideo format_video;
|
||||
SpaTypeCommandNode command_node;
|
||||
} Type;
|
||||
|
||||
|
|
@ -59,6 +62,9 @@ static inline void
|
|||
init_type (Type *type, SpaTypeMap *map)
|
||||
{
|
||||
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -237,8 +243,6 @@ spa_ffmpeg_dec_node_port_set_format (SpaNode *node,
|
|||
{
|
||||
SpaFFMpegDec *this;
|
||||
SpaFFMpegPort *port;
|
||||
SpaResult res;
|
||||
SpaVideoInfo query_format;
|
||||
|
||||
if (node == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -253,16 +257,22 @@ spa_ffmpeg_dec_node_port_set_format (SpaNode *node,
|
|||
if (format == NULL) {
|
||||
port->have_format = false;
|
||||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
SpaVideoInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.video &&
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((res = spa_format_video_parse (format, &query_format) < 0))
|
||||
return res;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
memcpy (&port->current_format, &query_format, sizeof (SpaVideoInfo));
|
||||
port->have_format = true;
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ typedef struct {
|
|||
uint32_t node;
|
||||
SpaTypeMediaType media_type;
|
||||
SpaTypeMediaSubtype media_subtype;
|
||||
SpaTypeFormatVideo format_video;
|
||||
SpaTypeCommandNode command_node;
|
||||
} Type;
|
||||
|
||||
|
|
@ -68,6 +69,7 @@ init_type (Type *type, SpaTypeMap *map)
|
|||
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -249,8 +251,6 @@ spa_ffmpeg_enc_node_port_set_format (SpaNode *node,
|
|||
{
|
||||
SpaFFMpegEnc *this;
|
||||
SpaFFMpegPort *port;
|
||||
SpaResult res;
|
||||
SpaVideoInfo query_format;
|
||||
|
||||
if (node == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -265,20 +265,22 @@ spa_ffmpeg_enc_node_port_set_format (SpaNode *node,
|
|||
if (format == NULL) {
|
||||
port->have_format = false;
|
||||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
SpaVideoInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.video &&
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (format->body.media_type.value != this->type.media_type.video ||
|
||||
format->body.media_subtype.value != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if ((res = spa_format_video_parse (format, &query_format) < 0))
|
||||
return res;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
memcpy (&port->current_format, &query_format, sizeof (SpaVideoInfo));
|
||||
port->have_format = true;
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -509,7 +509,6 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
|
|||
{
|
||||
SpaV4l2Source *this;
|
||||
SpaV4l2State *state;
|
||||
SpaResult res;
|
||||
SpaVideoInfo info;
|
||||
|
||||
if (node == NULL)
|
||||
|
|
@ -529,23 +528,49 @@ spa_v4l2_source_node_port_set_format (SpaNode *node,
|
|||
state->have_format = false;
|
||||
update_state (this, SPA_NODE_STATE_CONFIGURE);
|
||||
return SPA_RESULT_OK;
|
||||
} else {
|
||||
info.media_type = SPA_FORMAT_MEDIA_TYPE (format);
|
||||
info.media_subtype = SPA_FORMAT_MEDIA_SUBTYPE (format);
|
||||
|
||||
if (info.media_type != this->type.media_type.video)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (info.media_subtype == this->type.media_subtype.raw) {
|
||||
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (state->have_format && info.media_type == state->current_format.media_type &&
|
||||
info.media_subtype == state->current_format.media_subtype &&
|
||||
info.info.raw.format == state->current_format.info.raw.format &&
|
||||
info.info.raw.size.width == state->current_format.info.raw.size.width &&
|
||||
info.info.raw.size.height == state->current_format.info.raw.size.height)
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
else if (info.media_subtype == this->type.media_subtype_video.mjpg) {
|
||||
if (!spa_format_video_mjpg_parse (format, &info.info.mjpg, &this->type.format_video))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (state->have_format && info.media_type == state->current_format.media_type &&
|
||||
info.media_subtype == state->current_format.media_subtype &&
|
||||
info.info.mjpg.size.width == state->current_format.info.mjpg.size.width &&
|
||||
info.info.mjpg.size.height == state->current_format.info.mjpg.size.height)
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
else if (info.media_subtype == this->type.media_subtype_video.h264) {
|
||||
if (!spa_format_video_h264_parse (format, &info.info.h264, &this->type.format_video))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (state->have_format && info.media_type == state->current_format.media_type &&
|
||||
info.media_subtype == state->current_format.media_subtype &&
|
||||
info.info.h264.size.width == state->current_format.info.h264.size.width &&
|
||||
info.info.h264.size.height == state->current_format.info.h264.size.height)
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if ((res = spa_format_video_parse (format, &info)) < 0)
|
||||
return res;
|
||||
|
||||
if (state->have_format) {
|
||||
if (info.media_type == state->current_format.media_type &&
|
||||
info.media_subtype == state->current_format.media_subtype &&
|
||||
info.info.raw.format == state->current_format.info.raw.format &&
|
||||
info.info.raw.size.width == state->current_format.info.raw.size.width &&
|
||||
info.info.raw.size.height == state->current_format.info.raw.size.height)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
spa_v4l2_use_buffers (this, NULL, 0);
|
||||
state->have_format = false;
|
||||
}
|
||||
if (state->have_format && !(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
spa_v4l2_use_buffers (this, NULL, 0);
|
||||
state->have_format = false;
|
||||
}
|
||||
|
||||
if (spa_v4l2_set_format (this, &info, flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY) < 0)
|
||||
|
|
|
|||
|
|
@ -517,7 +517,6 @@ spa_videotestsrc_node_port_set_format (SpaNode *node,
|
|||
const SpaFormat *format)
|
||||
{
|
||||
SpaVideoTestSrc *this;
|
||||
SpaResult res;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -531,9 +530,17 @@ spa_videotestsrc_node_port_set_format (SpaNode *node,
|
|||
this->have_format = false;
|
||||
clear_buffers (this);
|
||||
} else {
|
||||
if ((res = spa_format_video_parse (format, &this->current_format)) < 0)
|
||||
return res;
|
||||
SpaVideoInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.video &&
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
this->current_format = info;
|
||||
this->have_format = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -366,7 +366,6 @@ spa_volume_node_port_set_format (SpaNode *node,
|
|||
{
|
||||
SpaVolume *this;
|
||||
SpaVolumePort *port;
|
||||
SpaResult res;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -382,9 +381,17 @@ spa_volume_node_port_set_format (SpaNode *node,
|
|||
port->have_format = false;
|
||||
clear_buffers (this, port);
|
||||
} else {
|
||||
if ((res = spa_format_audio_parse (format, &this->current_format)) < 0)
|
||||
return res;
|
||||
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (info.media_type != this->type.media_type.audio ||
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
this->current_format = info;
|
||||
port->have_format = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ typedef struct {
|
|||
uint32_t prop_device_fd;
|
||||
SpaTypeMediaType media_type;
|
||||
SpaTypeMediaSubtype media_subtype;
|
||||
SpaTypeFormatVideo format_video;
|
||||
SpaTypeCommandNode command_node;
|
||||
} Type;
|
||||
|
||||
|
|
@ -90,6 +91,7 @@ init_type (Type *type, SpaTypeMap *map)
|
|||
type->prop_device_fd = spa_type_map_get_id (map, SPA_TYPE_PROPS__deviceFd);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -313,8 +315,6 @@ spa_xv_sink_node_port_set_format (SpaNode *node,
|
|||
const SpaFormat *format)
|
||||
{
|
||||
SpaXvSink *this;
|
||||
SpaResult res;
|
||||
SpaVideoInfo info;
|
||||
|
||||
if (node == NULL || format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -327,23 +327,25 @@ spa_xv_sink_node_port_set_format (SpaNode *node,
|
|||
if (format == NULL) {
|
||||
this->have_format = false;
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
} else {
|
||||
SpaVideoInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
||||
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
||||
|
||||
if (format->body.media_type.value == this->type.media_type.video) {
|
||||
if (format->body.media_subtype.value == this->type.media_subtype.raw) {
|
||||
if ((res = spa_format_video_parse (format, &info) < 0))
|
||||
return res;
|
||||
} else
|
||||
|
||||
if (info.media_type != this->type.media_type.video &&
|
||||
info.media_subtype != this->type.media_subtype.raw)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
} else
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (spa_xv_set_format (this, &info, flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY) < 0)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
if (!spa_format_video_raw_parse (format, &info.info.raw, &this->type.format_video))
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
this->current_format = info;
|
||||
this->have_format = true;
|
||||
if (spa_xv_set_format (this, &info, flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY) < 0)
|
||||
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
||||
|
||||
if (!(flags & SPA_PORT_FORMAT_FLAG_TEST_ONLY)) {
|
||||
this->current_format = info;
|
||||
this->have_format = true;
|
||||
}
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ type_init (SpaTypeMap *map)
|
|||
}
|
||||
|
||||
static void
|
||||
do_static_struct (void)
|
||||
do_static_struct (SpaTypeMap *map)
|
||||
{
|
||||
struct _test_format {
|
||||
SpaFormat fmt;
|
||||
|
|
@ -137,8 +137,8 @@ do_static_struct (void)
|
|||
}
|
||||
};
|
||||
|
||||
spa_debug_pod (&test_format.fmt.pod);
|
||||
spa_debug_format (&test_format.fmt);
|
||||
spa_debug_pod (&test_format.fmt.pod, map);
|
||||
spa_debug_format (&test_format.fmt, map);
|
||||
|
||||
{
|
||||
uint32_t format = 0, match;
|
||||
|
|
@ -161,8 +161,9 @@ main (int argc, char *argv[])
|
|||
SpaPODFrame frame[4];
|
||||
uint8_t buffer[1024];
|
||||
SpaFormat *fmt;
|
||||
SpaTypeMap *map = spa_type_map_get_default();
|
||||
|
||||
type_init (spa_type_map_get_default());
|
||||
type_init (map);
|
||||
|
||||
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
||||
|
||||
|
|
@ -195,7 +196,7 @@ main (int argc, char *argv[])
|
|||
|
||||
spa_pod_builder_pop (&b, &frame[0]);
|
||||
|
||||
spa_debug_pod (&fmt->pod);
|
||||
spa_debug_pod (&fmt->pod, map);
|
||||
|
||||
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
||||
|
||||
|
|
@ -227,8 +228,8 @@ main (int argc, char *argv[])
|
|||
-SPA_POD_TYPE_PROP, &frame[1]);
|
||||
|
||||
fmt = SPA_MEMBER (buffer, frame[0].ref, SpaFormat);
|
||||
spa_debug_pod (&fmt->pod);
|
||||
spa_debug_format (fmt);
|
||||
spa_debug_pod (&fmt->pod, map);
|
||||
spa_debug_format (fmt, map);
|
||||
|
||||
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
||||
|
||||
|
|
@ -264,10 +265,10 @@ main (int argc, char *argv[])
|
|||
0);
|
||||
|
||||
fmt = SPA_MEMBER (buffer, frame[0].ref, SpaFormat);
|
||||
spa_debug_pod (&fmt->pod);
|
||||
spa_debug_format (fmt);
|
||||
spa_debug_pod (&fmt->pod, map);
|
||||
spa_debug_format (fmt, map);
|
||||
|
||||
do_static_struct ();
|
||||
do_static_struct (map);
|
||||
|
||||
printf ("%d\n", spa_type_is_a (SPA_TYPE__MediaType, SPA_TYPE_ENUM_BASE));
|
||||
printf ("%d\n", spa_type_is_a (SPA_TYPE__MediaSubtype, SPA_TYPE_ENUM_BASE));
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ main (int argc, char *argv[])
|
|||
uint8_t buffer[1024];
|
||||
SpaPOD *obj;
|
||||
SpaPODIter i;
|
||||
SpaTypeMap *map = spa_type_map_get_default ();
|
||||
|
||||
b.data = buffer;
|
||||
b.size = 1024;
|
||||
|
|
@ -87,11 +88,11 @@ main (int argc, char *argv[])
|
|||
spa_pod_builder_pop (&b, &frame[0]);
|
||||
|
||||
obj = SPA_POD_BUILDER_DEREF (&b, frame[0].ref, SpaPOD);
|
||||
spa_debug_pod (obj);
|
||||
spa_debug_pod (obj, map);
|
||||
|
||||
SpaPODProp *p = spa_pod_object_find_prop ((SpaPODObject *)obj, 4);
|
||||
printf ("%d %d\n", p->body.key, p->body.flags);
|
||||
spa_debug_pod (&p->body.value);
|
||||
spa_debug_pod (&p->body.value, map);
|
||||
|
||||
obj = SPA_POD_BUILDER_DEREF (&b, frame[2].ref, SpaPOD);
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ typedef struct {
|
|||
} AppData;
|
||||
|
||||
static void
|
||||
inspect_port (SpaNode *node, SpaDirection direction, uint32_t port_id)
|
||||
inspect_port (AppData *data, SpaNode *node, SpaDirection direction, uint32_t port_id)
|
||||
{
|
||||
SpaResult res;
|
||||
SpaFormat *format;
|
||||
|
|
@ -61,17 +61,17 @@ inspect_port (SpaNode *node, SpaDirection direction, uint32_t port_id)
|
|||
break;
|
||||
}
|
||||
if (format)
|
||||
spa_debug_format (format);
|
||||
spa_debug_format (format, data->map);
|
||||
index++;
|
||||
}
|
||||
if ((res = spa_node_port_get_props (node, direction, port_id, &props)) < 0)
|
||||
printf ("port_get_props error: %d\n", res);
|
||||
else
|
||||
spa_debug_props (props, true);
|
||||
spa_debug_props (props, data->map);
|
||||
}
|
||||
|
||||
static void
|
||||
inspect_node (SpaNode *node)
|
||||
inspect_node (AppData *data, SpaNode *node)
|
||||
{
|
||||
SpaResult res;
|
||||
uint32_t i, n_input, max_input, n_output, max_output;
|
||||
|
|
@ -81,7 +81,7 @@ inspect_node (SpaNode *node)
|
|||
if ((res = spa_node_get_props (node, &props)) < 0)
|
||||
printf ("can't get properties: %d\n", res);
|
||||
else
|
||||
spa_debug_props (props, true);
|
||||
spa_debug_props (props, data->map);
|
||||
|
||||
if ((res = spa_node_get_n_ports (node, &n_input, &max_input, &n_output, &max_output)) < 0) {
|
||||
printf ("can't get n_ports: %d\n", res);
|
||||
|
|
@ -99,12 +99,12 @@ inspect_node (SpaNode *node)
|
|||
|
||||
for (i = 0; i < n_input; i++) {
|
||||
printf (" input port: %08x\n", in_ports[i]);
|
||||
inspect_port (node, SPA_DIRECTION_INPUT, in_ports[i]);
|
||||
inspect_port (data, node, SPA_DIRECTION_INPUT, in_ports[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < n_output; i++) {
|
||||
printf (" output port: %08x\n", out_ports[i]);
|
||||
inspect_port (node, SPA_DIRECTION_OUTPUT, out_ports[i]);
|
||||
inspect_port (data, node, SPA_DIRECTION_OUTPUT, out_ports[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ inspect_factory (AppData *data, const SpaHandleFactory *factory)
|
|||
}
|
||||
|
||||
if (interface_id == data->type.node)
|
||||
inspect_node (interface);
|
||||
inspect_node (data, interface);
|
||||
else
|
||||
printf ("skipping unknown interface\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ typedef struct {
|
|||
|
||||
|
||||
static void
|
||||
inspect_item (SpaMonitorItem *item)
|
||||
inspect_item (AppData *data, SpaMonitorItem *item)
|
||||
{
|
||||
spa_debug_pod (&item->pod);
|
||||
spa_debug_pod (&item->pod, data->map);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -70,15 +70,15 @@ on_monitor_event (SpaMonitor *monitor,
|
|||
|
||||
if (SPA_EVENT_TYPE (event) == data->type.monitor.Added) {
|
||||
fprintf (stderr, "added:\n");
|
||||
inspect_item ((SpaMonitorItem*)event);
|
||||
inspect_item (data, (SpaMonitorItem*)event);
|
||||
}
|
||||
else if (SPA_EVENT_TYPE (event) == data->type.monitor.Removed) {
|
||||
fprintf (stderr, "removed:\n");
|
||||
inspect_item ((SpaMonitorItem*)event);
|
||||
inspect_item (data, (SpaMonitorItem*)event);
|
||||
}
|
||||
else if (SPA_EVENT_TYPE (event) == data->type.monitor.Changed) {
|
||||
fprintf (stderr, "changed:\n");
|
||||
inspect_item ((SpaMonitorItem*)event);
|
||||
inspect_item (data, (SpaMonitorItem*)event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ handle_monitor (AppData *data, SpaMonitor *monitor)
|
|||
printf ("spa_monitor_enum_items: got error %d\n", res);
|
||||
break;
|
||||
}
|
||||
inspect_item (item);
|
||||
inspect_item (data, item);
|
||||
}
|
||||
|
||||
spa_monitor_set_event_callback (monitor, on_monitor_event, &data);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue