1 | #ifdef HAVE_CONFIG_H |
---|
2 | # include "config.h" |
---|
3 | #endif |
---|
4 | |
---|
5 | #include <string.h> |
---|
6 | #include <stdlib.h> |
---|
7 | #include <locale.h> |
---|
8 | #include <gst/gst.h> |
---|
9 | |
---|
10 | /* |
---|
11 | * find the type of a media file and display it's properties |
---|
12 | **/ |
---|
13 | |
---|
14 | gboolean FOUND = FALSE; |
---|
15 | gchar *filename = NULL; |
---|
16 | |
---|
17 | void |
---|
18 | gst_caps_print (const char *filename, const GstCaps * caps) |
---|
19 | { |
---|
20 | gchar *caps_str = gst_caps_to_string (caps); |
---|
21 | |
---|
22 | g_print ("%s - %s\n", filename, caps_str); |
---|
23 | g_free (caps_str); |
---|
24 | } |
---|
25 | |
---|
26 | void |
---|
27 | have_type_handler (GstElement * typefind, guint probability, |
---|
28 | const GstCaps * caps, gpointer unused) |
---|
29 | { |
---|
30 | gst_caps_print (filename, caps); |
---|
31 | FOUND = TRUE; |
---|
32 | } |
---|
33 | |
---|
34 | int |
---|
35 | main (int argc, char *argv[]) |
---|
36 | { |
---|
37 | guint i = 1; |
---|
38 | GstElement *pipeline; |
---|
39 | GstElement *source, *typefind; |
---|
40 | |
---|
41 | setlocale (LC_ALL, ""); |
---|
42 | |
---|
43 | gst_init (&argc, &argv); |
---|
44 | |
---|
45 | if (argc < 2) { |
---|
46 | g_print ("Please give a filename to typefind\n\n"); |
---|
47 | return 1; |
---|
48 | } |
---|
49 | |
---|
50 | pipeline = gst_pipeline_new (NULL); |
---|
51 | source = gst_element_factory_make ("filesrc", "source"); |
---|
52 | g_assert (GST_IS_ELEMENT (source)); |
---|
53 | typefind = gst_element_factory_make ("typefind", "typefind"); |
---|
54 | g_assert (GST_IS_ELEMENT (typefind)); |
---|
55 | gst_bin_add_many (GST_BIN (pipeline), source, typefind, NULL); |
---|
56 | gst_element_link (source, typefind); |
---|
57 | g_signal_connect (G_OBJECT (typefind), "have-type", |
---|
58 | G_CALLBACK (have_type_handler), NULL); |
---|
59 | |
---|
60 | while (i < argc) { |
---|
61 | FOUND = FALSE; |
---|
62 | gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); |
---|
63 | filename = argv[i]; |
---|
64 | g_object_set (source, "location", filename, NULL); |
---|
65 | /* set to play */ |
---|
66 | gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); |
---|
67 | |
---|
68 | while (!FOUND) { |
---|
69 | if (!gst_bin_iterate (GST_BIN (pipeline))) |
---|
70 | break; |
---|
71 | } |
---|
72 | if (!FOUND) { |
---|
73 | g_print ("%s - No type found\n", argv[i]); |
---|
74 | } |
---|
75 | i++; |
---|
76 | } |
---|
77 | g_object_unref (pipeline); |
---|
78 | return 0; |
---|
79 | } |
---|