source: trunk/third/gstreamer/testsuite/caps/simplify.c @ 21005

Revision 21005, 4.2 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21004, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Copyright (C) 2004 Benjamin Otte <in7y118@public.uni-hamburg.de>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <gst/gst.h>
20#include <string.h>
21#include "caps.h"
22
23/* statistics junkie!!! */
24static guint size_before = 0, size_after = 0;
25static guint length_before = 0, length_after = 0;
26static guint impossible = 0, success = 0, failure = 0;
27
28static void
29check_caps (GstCaps * caps)
30{
31  gchar *before, *after;
32  GstCaps *old;
33
34  before = gst_caps_to_string (caps);
35  old = gst_caps_copy (caps);
36  gst_caps_do_simplify (caps);
37  after = gst_caps_to_string (caps);
38  g_assert (gst_caps_get_size (caps) <= gst_caps_get_size (old));
39  if (gst_caps_get_size (caps) == gst_caps_get_size (old))
40    g_assert (strlen (after) <= strlen (before));
41  g_assert (gst_caps_is_equal (caps, old));
42  g_print ("%s %2u/%-4u => %2u/%-4u\n",
43      gst_caps_get_size (caps) < gst_caps_get_size (old) ||
44      strlen (after) < strlen (before) ? "REDUCED" :
45      (gst_caps_get_size (old) < 2 ? "  ---  " : "       "),
46      gst_caps_get_size (old), strlen (before),
47      gst_caps_get_size (caps), strlen (after));
48
49  size_before += gst_caps_get_size (old);
50  size_after += gst_caps_get_size (caps);
51  length_before += strlen (before);
52  length_after += strlen (after);
53  if (gst_caps_get_size (old) < 2) {
54    impossible++;
55  } else if (gst_caps_get_size (caps) < gst_caps_get_size (old) ||
56      strlen (after) < strlen (before)) {
57    success++;
58  } else {
59    failure++;
60  }
61
62  g_free (before);
63  g_free (after);
64  gst_caps_free (old);
65}
66
67gint
68main (gint argc, gchar ** argv)
69{
70  guint i, j;
71
72  gst_init (&argc, &argv);
73
74  for (i = 0; i < G_N_ELEMENTS (caps_list); i++) {
75    GstCaps *caps = gst_caps_from_string (caps_list[i]);
76
77    g_print ("     %2u ", i);
78    check_caps (caps);
79    if (!gst_caps_is_any (caps)) {
80      for (j = 0; j < G_N_ELEMENTS (caps_list); j++) {
81        GstCaps *temp, *temp2;
82        GstCaps *caps2 = gst_caps_from_string (caps_list[j]);
83
84        /* subtraction */
85        temp = gst_caps_subtract (caps, caps2);
86
87        g_print ("%2u - %2u ", i, j);
88        check_caps (temp);
89        gst_caps_free (temp);
90        /* union */
91        temp = gst_caps_union (caps, caps2);
92        g_print ("%2u + %2u ", i, j);
93        check_caps (temp);
94        if (i == j)
95          g_assert (gst_caps_get_size (caps) == gst_caps_get_size (temp));
96        g_assert (gst_caps_is_subset (caps, temp));
97        g_assert (gst_caps_is_subset (caps2, temp));
98        /* appending (union without simplifying) */
99        temp2 = gst_caps_copy (caps);
100        gst_caps_append (temp2, caps2);
101        g_assert (gst_caps_is_equal (temp, temp2));
102        gst_caps_free (temp2);
103        gst_caps_free (temp);
104      }
105    }
106    gst_caps_free (caps);
107  }
108  g_print ("\n\nSTATISTICS:\n");
109  g_print ("\nOf all caps tried\n");
110  g_print ("%3u (%02.4g%%) caps were already at minimum size.\n", impossible,
111      100.0 * ((double) impossible) / (impossible + success + failure));
112  g_print ("%3u (%02.4g%%) caps were successfully reduced.\n", success,
113      100.0 * ((double) success) / (impossible + success + failure));
114  g_print ("%3u (%02.4g%%) caps could not be reduced.\n", failure,
115      100.0 * ((double) failure) / (impossible + success + failure));
116  g_print ("\nOf all caps that could possibly be reduced\n");
117  g_print ("%02.4g%% were reduced\n",
118      100.0 * ((double) success) / (success + failure));
119  g_print ("%02.4g%% average reduction in caps structure amount\n",
120      100.0 * (1.0 - ((double) size_after) / size_before));
121  g_print ("%02.4g%% average reduction in caps serialization length\n",
122      100.0 * (1.0 - ((double) length_after) / length_before));
123
124  return 0;
125}
Note: See TracBrowser for help on using the repository browser.