From 89455b710629e5c842512ad5d93cff6b771d0d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Zanelli?= Date: Wed, 1 Oct 2014 16:17:46 +0200 Subject: [PATCH] vc1parse: select caps according to wmv format at negotiation Some VC1 decoder can have different caps according to wmv format, ie WMV3 or WVC1. So instead of keeping the first available caps, we interserct with current WMV format. https://bugzilla.gnome.org/show_bug.cgi?id=738532 --- gst/videoparsers/gstvc1parse.c | 41 +++++++++++++++++++++++++++++++--- gst/videoparsers/gstvc1parse.h | 2 +- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/gst/videoparsers/gstvc1parse.c b/gst/videoparsers/gstvc1parse.c index b00727348e..a93e2d6114 100644 --- a/gst/videoparsers/gstvc1parse.c +++ b/gst/videoparsers/gstvc1parse.c @@ -115,6 +115,16 @@ static const struct "frame-layer", VC1_STREAM_FORMAT_FRAME_LAYER} }; +static const struct +{ + gchar str[5]; + GstVC1ParseFormat en; +} parse_formats[] = { + { + "WMV3", GST_VC1_PARSE_FORMAT_WMV3}, { + "WVC1", GST_VC1_PARSE_FORMAT_WVC1} +}; + static const gchar * stream_format_to_string (VC1StreamFormat stream_format) { @@ -151,6 +161,12 @@ header_format_from_string (const gchar * header_format) return -1; } +static const gchar * +parse_format_to_string (GstVC1ParseFormat format) +{ + return parse_formats[format].str; +} + static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, @@ -300,7 +316,9 @@ gst_vc1_parse_stop (GstBaseParse * parse) static gboolean gst_vc1_parse_renegotiate (GstVC1Parse * vc1parse) { + GstCaps *in_caps; GstCaps *allowed_caps; + GstCaps *tmp; /* Negotiate with downstream here */ GST_DEBUG_OBJECT (vc1parse, "Renegotiating"); @@ -314,9 +332,25 @@ gst_vc1_parse_renegotiate (GstVC1Parse * vc1parse) GST_DEBUG_OBJECT (vc1parse, "Downstream allowed caps: %" GST_PTR_FORMAT, allowed_caps); - allowed_caps = gst_caps_make_writable (allowed_caps); - allowed_caps = gst_caps_truncate (allowed_caps); - s = gst_caps_get_structure (allowed_caps, 0); + /* Downstream element can have differents caps according to wmv format + * so intersect to select the good caps */ + in_caps = gst_caps_new_simple ("video/x-wmv", + "format", G_TYPE_STRING, parse_format_to_string (vc1parse->format), + NULL); + + tmp = gst_caps_intersect_full (allowed_caps, in_caps, + GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (in_caps); + + if (gst_caps_is_empty (tmp)) { + GST_ERROR_OBJECT (vc1parse, "Empty caps, downstream doesn't support %s", + parse_format_to_string (vc1parse->format)); + gst_caps_unref (tmp); + return FALSE; + } + + tmp = gst_caps_make_writable (tmp); + s = gst_caps_get_structure (tmp, 0); /* If already fixed this does nothing */ gst_structure_fixate_field_string (s, "header-format", "asf"); @@ -343,6 +377,7 @@ gst_vc1_parse_renegotiate (GstVC1Parse * vc1parse) vc1parse->output_stream_format = stream_format_from_string (stream_format); } + gst_caps_unref (tmp); } else if (gst_caps_is_empty (allowed_caps)) { GST_ERROR_OBJECT (vc1parse, "Empty caps"); gst_caps_unref (allowed_caps); diff --git a/gst/videoparsers/gstvc1parse.h b/gst/videoparsers/gstvc1parse.h index 6241e42412..3b49f51bbf 100644 --- a/gst/videoparsers/gstvc1parse.h +++ b/gst/videoparsers/gstvc1parse.h @@ -56,7 +56,7 @@ typedef enum { } VC1StreamFormat; typedef enum { - GST_VC1_PARSE_FORMAT_WMV3, + GST_VC1_PARSE_FORMAT_WMV3 = 0, GST_VC1_PARSE_FORMAT_WVC1 } GstVC1ParseFormat;