aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/test_gstreamer.c
blob: bba9b7534eefa8905abda8a84b55ca617ba3bab4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
     This file is part of libextractor.
     (C) 2012 Vidyut Samanta and Christian Grothoff

     libextractor is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     libextractor is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with libextractor; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/
/**
 * @file plugins/test_gstreamer.c
 * @brief testcase for gstreamer plugin
 * @author LRN
 */
#include "platform.h"
#include "test_lib.h"

#include <glib.h>
#include <gst/gst.h>
#include <gst/pbutils/pbutils.h>

/* This is a miniaturized version of gst-discoverer, its only purpose is
 * to detect missing plugins situations and skip a test in such cases.
 */
GstDiscovererResult
discoverer_main (GstDiscoverer *dc, char *filename)
{
  GError *err = NULL;
  GDir *dir;
  gchar *uri, *path;
  GstDiscovererInfo *info;

  GstDiscovererResult result;

  if (!gst_uri_is_valid (filename)) {
    if (!g_path_is_absolute (filename)) {
      gchar *cur_dir;

      cur_dir = g_get_current_dir ();
      path = g_build_filename (cur_dir, filename, NULL);
      g_free (cur_dir);
    } else {
      path = g_strdup (filename);
    }

    uri = g_filename_to_uri (path, NULL, &err);
    g_free (path);
    path = NULL;

    if (err) {
      g_warning ("Couldn't convert filename %s to URI: %s\n", filename, err->message);
      g_error_free (err);
      return;
    }
  } else {
    uri = g_strdup (filename);
  }

  info = gst_discoverer_discover_uri (dc, uri, &err);

  result = gst_discoverer_info_get_result (info);

  switch (result) {
    case GST_DISCOVERER_OK:
    {
      break;
    }
    case GST_DISCOVERER_URI_INVALID:
    {
      g_print ("URI %s is not valid\n", uri);
      break;
    }
    case GST_DISCOVERER_ERROR:
    {
      g_print ("An error was encountered while discovering the file %s\n", filename);
      g_print (" %s\n", err->message);
      break;
    }
    case GST_DISCOVERER_TIMEOUT:
    {
      g_print ("Analyzing URI %s timed out\n", uri);
      break;
    }
    case GST_DISCOVERER_BUSY:
    {
      g_print ("Discoverer was busy\n");
      break;
    }
    case GST_DISCOVERER_MISSING_PLUGINS:
    {
      g_print ("Will skip %s: missing plugins\n", filename);
      break;
    }
  }

  if (err)
    g_error_free (err);
  gst_discoverer_info_unref (info);

  g_free (uri);

  return result;
}

/**
 * Main function for the GStreamer testcase.
 *
 * @param argc number of arguments (ignored)
 * @param argv arguments (ignored)
 * @return 0 on success
 */
int
main (int argc, char *argv[])
{
  GError *err = NULL;
  gint timeout = 10;
  GstDiscoverer *dc;

  int result = 0;
  GstDiscovererResult pre_test;

  gst_init (&argc, &argv);

  dc = gst_discoverer_new (timeout * GST_SECOND, &err);
  if (G_UNLIKELY (dc == NULL)) {
    g_print ("Error initializing: %s\n", err->message);
    exit (1);
  }
  if (err)
    g_error_free (err);

  pre_test = discoverer_main (dc, "testdata/30_and_33.asf");
  if (pre_test != GST_DISCOVERER_MISSING_PLUGINS)
  {
    struct SolutionData thirty_and_thirtythree_sol[] =
      {
        { 
	EXTRACTOR_METATYPE_DURATION,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"0:00:05.061000000",
	strlen ("0:00:05.061000000") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_TRACK_NUMBER,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"21",
	strlen ("21") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_ALBUM,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"Zee Album",
	strlen ("Zee Album") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_CREATION_TIME,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"9999",
	strlen ("9999") + 1,
	0 
        },
        /* Suggest a fix to gst devs; "performed by" and "contributors" should
         * be separate.
         */
        { 
	EXTRACTOR_METATYPE_ARTIST,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"All performed by Nobody, This Artist Contributed",
	strlen ("All performed by Nobody, This Artist Contributed") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_TITLE,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"Some title",
	strlen ("Some title") + 1,
	0 
        },
        /* Suggest a fix to gst devs; should be a comment, not description */
        { 
	EXTRACTOR_METATYPE_DESCRIPTION,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"A witty comment",
	strlen ("A witty comment") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_CONTAINER_FORMAT,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"ASF",
	strlen ("ASF") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_AUDIO_CODEC,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"WMA Version 8",
	strlen ("WMA Version 8") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_MIMETYPE,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"video/x-ms-asf",
	strlen ("video/x-ms-asf") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_MIMETYPE,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"audio/x-wma",
	strlen ("audio/x-wma") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_UNKNOWN,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"wmaversion=2",
	strlen ("wmaversion=2") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_UNKNOWN,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"bitrate=96024",
	strlen ("bitrate=96024") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_UNKNOWN,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"depth=16",
	strlen ("depth=16") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_UNKNOWN,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"rate=44100",
	strlen ("rate=44100") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_UNKNOWN,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"channels=2",
	strlen ("channels=2") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_UNKNOWN,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"block_align=4459",
	strlen ("block_align=4459") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_AUDIO_LANGUAGE,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"en",
	strlen ("en") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_CHANNELS,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"2",
	strlen ("2") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_SAMPLE_RATE,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"44100",
	strlen ("44100") + 1,
	0 
        },
        { 
	EXTRACTOR_METATYPE_AUDIO_DEPTH,
	EXTRACTOR_METAFORMAT_UTF8,
	"text/plain",
	"16",
	strlen ("16") + 1,
	0 
        },
        { 0, 0, NULL, NULL, 0, -1 }
      };
    struct ProblemSet ps[] =
      {
        { "testdata/30_and_33.asf",
	thirty_and_thirtythree_sol },
        { NULL, NULL }
      };
    result += (0 == ET_main ("gstreamer", ps) ? 0 : 1);
  }
  g_object_unref (dc);
  return result;
}

/* end of test_gstreamer.c */