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

Revision 21005, 4.4 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/* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library 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 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19/* Element-Checklist-Version: 5 */
20
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25#include <string.h>
26#include <math.h>
27
28#include <gst/gst.h>
29
30
31static void
32gst_audioscale_expand_value (GValue * dest, const GValue * src)
33{
34  int rate_min, rate_max;
35
36  if (G_VALUE_TYPE (src) == G_TYPE_INT ||
37      G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
38    if (G_VALUE_TYPE (src) == G_TYPE_INT) {
39      rate_min = g_value_get_int (src);
40      rate_max = rate_min;
41    } else {
42      rate_min = gst_value_get_int_range_min (src);
43      rate_max = gst_value_get_int_range_max (src);
44    }
45
46    rate_min /= 2;
47    if (rate_min < 1)
48      rate_min = 1;
49    if (rate_max < G_MAXINT / 2) {
50      rate_max *= 2;
51    } else {
52      rate_max = G_MAXINT;
53    }
54
55    g_value_init (dest, GST_TYPE_INT_RANGE);
56    gst_value_set_int_range (dest, rate_min, rate_max);
57    return;
58  }
59
60  if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
61    int i;
62
63    g_value_init (dest, GST_TYPE_LIST);
64    for (i = 0; i < gst_value_list_get_size (src); i++) {
65      const GValue *s = gst_value_list_get_value (src, i);
66      GValue d = { 0 };
67      int j;
68
69      gst_audioscale_expand_value (&d, s);
70
71      for (j = 0; j < gst_value_list_get_size (dest); j++) {
72        const GValue *s2 = gst_value_list_get_value (dest, j);
73        GValue d2 = { 0 };
74
75        gst_value_union (&d2, &d, s2);
76        if (G_VALUE_TYPE (&d2) == GST_TYPE_INT_RANGE) {
77          g_value_unset ((GValue *) s2);
78          gst_value_init_and_copy ((GValue *) s2, &d2);
79          break;
80        }
81        g_value_unset (&d2);
82      }
83      if (j == gst_value_list_get_size (dest)) {
84        gst_value_list_append_value (dest, &d);
85      }
86      g_value_unset (&d);
87    }
88
89    if (gst_value_list_get_size (dest) == 1) {
90      const GValue *s = gst_value_list_get_value (dest, 0);
91      GValue d = { 0 };
92
93      gst_value_init_and_copy (&d, s);
94      g_value_unset (dest);
95      gst_value_init_and_copy (dest, &d);
96      g_value_unset (&d);
97    }
98
99    return;
100  }
101
102  GST_ERROR ("unexpected value type");
103}
104
105static GstCaps *
106gst_audioscale_getcaps (const GstCaps * othercaps)
107{
108  GstCaps *caps;
109  int i;
110
111  caps = gst_caps_copy (othercaps);
112
113  /* we do this hack, because the audioscale lib doesn't handle
114   * rate conversions larger than a factor of 2 */
115  for (i = 0; i < gst_caps_get_size (caps); i++) {
116    GstStructure *structure = gst_caps_get_structure (caps, i);
117    const GValue *value;
118    GValue dest = { 0 };
119
120    value = gst_structure_get_value (structure, "rate");
121    if (value == NULL) {
122      GST_ERROR ("caps structure doesn't have required rate field");
123      return NULL;
124    }
125
126    gst_audioscale_expand_value (&dest, value);
127
128    gst_structure_set_value (structure, "rate", &dest);
129  }
130
131  return caps;
132}
133
134
135void
136test_caps (const char *s)
137{
138  GstCaps *caps;
139  GstCaps *caps2;
140  char *s2;
141
142  caps = gst_caps_from_string (s);
143  caps2 = gst_audioscale_getcaps (caps);
144  s2 = gst_caps_to_string (caps2);
145
146  g_print ("original: %s\nfiltered: %s\n\n", s, s2);
147
148  g_free (s2);
149  gst_caps_free (caps);
150  gst_caps_free (caps2);
151}
152
153
154int
155main (int argc, char *argv[])
156{
157
158  gst_init (&argc, &argv);
159
160  test_caps ("audio/x-raw-int, rate=(int)1");
161  test_caps ("audio/x-raw-int, rate=(int)10");
162  test_caps ("audio/x-raw-int, rate=(int)100");
163  test_caps ("audio/x-raw-int, rate=(int)10000");
164  test_caps ("audio/x-raw-int, rate=(int)2000000000");
165
166  test_caps ("audio/x-raw-int, rate=(int)[1,100]");
167  test_caps ("audio/x-raw-int, rate=(int)[1000,40000]");
168
169  test_caps ("audio/x-raw-int, rate=(int){1,100}");
170  test_caps ("audio/x-raw-int, rate=(int){100,200,300}");
171  test_caps ("audio/x-raw-int, rate=(int){[100,200],1000}");
172
173  return 0;
174}
Note: See TracBrowser for help on using the repository browser.