format: improve format parsing

This commit is contained in:
Wim Taymans 2017-03-24 18:11:11 +01:00
parent 94019fb1f5
commit 29cb7bf39a
30 changed files with 459 additions and 406 deletions

View file

@ -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);

View file

@ -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,

View file

@ -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 {

View file

@ -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;

View file

@ -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)