summaryrefslogtreecommitdiff
path: root/gst-libs/gst/media-info/media-info-test.c
blob: 67a16cdc2377684f57039902881fd1b7e5eb105a (plain)
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
/* media-info test app */

#include <gst/gst.h>
#include <string.h>
#include "media-info.h"

static void
print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
{
  gint i, count;

  count = gst_tag_list_get_tag_size (list, tag);

  for (i = 0; i < count; i++) {
    gchar *str;

    if (gst_tag_get_type (tag) == G_TYPE_STRING) {
      g_assert (gst_tag_list_get_string_index (list, tag, i, &str));
    } else {
      str =
	  g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i));
    }

    if (i == 0) {
      g_print ("%15s: %s\n", gst_tag_get_nick (tag), str);
    } else {
      g_print ("               : %s\n", str);
    }

    g_free (str);
  }
}

static void
info_print (GstMediaInfoStream * stream)
{
  int i;
  GList *p;
  GstMediaInfoTrack *track;

  g_print ("- mime type: %s\n", stream->mime);
  g_print ("- length: %.3f seconds\n",
      (gdouble) stream->length_time / GST_SECOND);
  g_print ("- bitrate: %.3f kbps\n", stream->bitrate / 1000.0);
  g_print ("- number of tracks: %ld\n", stream->length_tracks);
  p = stream->tracks;
  if (p == NULL) {
    g_print ("- no track information, probably an error\n");
    return;
  }
  for (i = 0; i < stream->length_tracks; ++i) {
    g_print ("- track %d\n", i);
    track = (GstMediaInfoTrack *) p->data;
    g_print ("  - metadata:\n");
    if (track->metadata)
      gst_tag_list_foreach (track->metadata, print_tag, NULL);
    else
      g_print ("  (none found)\n");
    g_print ("  - streaminfo:\n");
    gst_tag_list_foreach (track->streaminfo, print_tag, NULL);
    g_print ("  - format:\n");
    g_print ("%s\n", gst_caps_to_string (track->format));
    p = p->next;
  }
}

int
main (int argc, char *argv[])
{
  GstMediaInfo *info;
  GstMediaInfoStream *stream = NULL;
  GError *error = NULL;
  gint i;

  g_assert (argc > 1);

  gst_media_info_init ();
  gst_init (&argc, &argv);

  info = gst_media_info_new (&error);
  if (error != NULL) {
    g_print ("Error creating media-info object: %s\n", error->message);
    g_error_free (error);
    return -1;
  }

  g_assert (G_IS_OBJECT (info));
  if (!gst_media_info_set_source (info, "gnomevfssrc", &error)) {
    g_print ("Could not set gnomevfssrc as a source\n");
    g_print ("reason: %s\n", error->message);
    g_error_free (error);
    return -1;
  }

  g_print ("stream: %p, &stream: %p\n", stream, &stream);
  for (i = 1; i < argc; ++i) {

    /*
       stream = gst_media_info_read (info, argv[i], GST_MEDIA_INFO_ALL);
     */
    gst_media_info_read_with_idler (info, argv[i], GST_MEDIA_INFO_ALL, &error);
    while (gst_media_info_read_idler (info, &stream, &error) && stream == NULL)
      /* keep idling */
      g_print ("+");
    g_print ("\nFILE: %s\n", argv[i]);
    g_print ("stream: %p, &stream: %p\n", stream, &stream);
    if (error) {
      g_print ("Error reading media info: %s\n", error->message);
      g_error_free (error);
    }
    if (stream)
      info_print (stream);
    else
      g_print ("no media info found.\n");
    stream = NULL;
  }

  return 0;
}