summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Bisson <martin.bisson@gmail.com>2010-06-11 22:56:13 +0000
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2010-06-12 08:07:34 +0200
commitab0763f0e8461c569dfbff8a0f049454070d14b5 (patch)
tree4761a2aa723e9c6b45fff71fd83496aae198bc13
parentad9f5e11d0d2866cd8db94edf2d07383ce2954cf (diff)
value: Fixed serialization for short fourccs.
"Y16 " and "Y8 " were not displayed properly because the space character is not alnum. A unit test is also included. Fixes bug #621282.
-rw-r--r--gst/gstvalue.c28
-rw-r--r--tests/check/gst/gstvalue.c43
2 files changed, 63 insertions, 8 deletions
diff --git a/gst/gstvalue.c b/gst/gstvalue.c
index c4b55f3e90..3934e39d03 100644
--- a/gst/gstvalue.c
+++ b/gst/gstvalue.c
@@ -683,10 +683,16 @@ gst_value_transform_fourcc_string (const GValue * src_value,
{
guint32 fourcc = src_value->data[0].v_int;
- if (g_ascii_isprint ((fourcc >> 0) & 0xff) &&
- g_ascii_isprint ((fourcc >> 8) & 0xff) &&
- g_ascii_isprint ((fourcc >> 16) & 0xff) &&
- g_ascii_isprint ((fourcc >> 24) & 0xff)) {
+ gchar fourcc_char[4] = {
+ (fourcc >> 0) & 0xff,
+ (fourcc >> 8) & 0xff,
+ (fourcc >> 16) & 0xff,
+ (fourcc >> 24) & 0xff
+ };
+ if ((g_ascii_isalnum (fourcc_char[0]) || fourcc_char[0] == ' ') &&
+ (g_ascii_isalnum (fourcc_char[1]) || fourcc_char[1] == ' ') &&
+ (g_ascii_isalnum (fourcc_char[2]) || fourcc_char[2] == ' ') &&
+ (g_ascii_isalnum (fourcc_char[3]) || fourcc_char[3] == ' ')) {
dest_value->data[0].v_pointer =
g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
} else {
@@ -707,10 +713,16 @@ gst_value_serialize_fourcc (const GValue * value)
{
guint32 fourcc = value->data[0].v_int;
- if (g_ascii_isalnum ((fourcc >> 0) & 0xff) &&
- g_ascii_isalnum ((fourcc >> 8) & 0xff) &&
- g_ascii_isalnum ((fourcc >> 16) & 0xff) &&
- g_ascii_isalnum ((fourcc >> 24) & 0xff)) {
+ gchar fourcc_char[4] = {
+ (fourcc >> 0) & 0xff,
+ (fourcc >> 8) & 0xff,
+ (fourcc >> 16) & 0xff,
+ (fourcc >> 24) & 0xff
+ };
+ if ((g_ascii_isalnum (fourcc_char[0]) || fourcc_char[0] == ' ') &&
+ (g_ascii_isalnum (fourcc_char[1]) || fourcc_char[1] == ' ') &&
+ (g_ascii_isalnum (fourcc_char[2]) || fourcc_char[2] == ' ') &&
+ (g_ascii_isalnum (fourcc_char[3]) || fourcc_char[3] == ' ')) {
return g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
} else {
return g_strdup_printf ("0x%08x", fourcc);
diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c
index cde2a122d5..7f47c97496 100644
--- a/tests/check/gst/gstvalue.c
+++ b/tests/check/gst/gstvalue.c
@@ -24,6 +24,48 @@
#include <gst/check/gstcheck.h>
+GST_START_TEST (test_serialize_fourcc)
+{
+ int i;
+
+ guint32 fourccs[] = {
+ GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'),
+ GST_MAKE_FOURCC ('Y', '8', '0', '0'),
+ GST_MAKE_FOURCC ('Y', '8', ' ', ' '),
+ GST_MAKE_FOURCC ('Y', '1', '6', ' '),
+ GST_MAKE_FOURCC ('Y', 'U', 'Y', '_'),
+ GST_MAKE_FOURCC ('Y', 'U', 'Y', '#'),
+ };
+ gint fourccs_size = sizeof (fourccs) / sizeof (fourccs[0]);
+ const gchar *fourcc_strings[] = {
+ "YUY2",
+ "Y800",
+ "Y8 ",
+ "Y16 ",
+ "0x5f595559", /* Ascii values of YUY_ */
+ "0x23595559", /* Ascii values of YUY# */
+ };
+ gint fourcc_strings_size =
+ sizeof (fourcc_strings) / sizeof (fourcc_strings[0]);
+
+ fail_unless (fourccs_size == fourcc_strings_size);
+
+ for (i = 0; i < fourccs_size; ++i) {
+ gchar *str;
+ GValue value = { 0 };
+ g_value_init (&value, GST_TYPE_FOURCC);
+
+ gst_value_set_fourcc (&value, fourccs[i]);
+ str = gst_value_serialize (&value);
+
+ fail_unless (strcmp (str, fourcc_strings[i]) == 0);
+
+ g_free (str);
+ }
+}
+
+GST_END_TEST;
+
GST_START_TEST (test_deserialize_buffer)
{
GValue value = { 0 };
@@ -1762,6 +1804,7 @@ gst_value_suite (void)
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
+ tcase_add_test (tc_chain, test_serialize_fourcc);
tcase_add_test (tc_chain, test_deserialize_buffer);
tcase_add_test (tc_chain, test_serialize_buffer);
tcase_add_test (tc_chain, test_deserialize_gint);