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

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

static void
caps_print (GstCaps *caps)
{
  if (caps == NULL) return;
  /*
  if (!strcmp (gst_caps_get_mime (caps), "application/x-gst-metadata") ||
      !strcmp (gst_caps_get_mime (caps), "application/x-gst-streaminfo"))
      */
  if (TRUE)
  {
    GstProps *props = caps->properties;
    GList *walk;

    if (props == NULL)
    {
      g_print ("    none\n");
      return;
    }
    walk = props->properties;

    while (walk) {
      GstPropsEntry *entry = (GstPropsEntry *) walk->data;
      const gchar *name;
      const gchar *str_val;
      gint int_val;
      GstPropsType type;

      name = gst_props_entry_get_name (entry);
      type = gst_props_entry_get_type (entry);
      switch (type) {
        case GST_PROPS_STRING_TYPE:
          gst_props_entry_get_string (entry, &str_val);
          g_print ("      %s='%s'\n", name, str_val);
          break;
        case GST_PROPS_INT_TYPE:
          gst_props_entry_get_int (entry, &int_val);
          g_print ("      %s=%d\n", name, int_val);
          break;
        default:
          break;
      }

      walk = g_list_next (walk);
    }
  }
  else {
    g_print (" unkown caps type\n");
  }
}

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;
  for (i = 0; i < stream->length_tracks; ++i)
  {
    g_print ("- track %d\n", i);
    track = (GstMediaInfoTrack *) p->data;
    g_print ("  - metadata:\n");
    caps_print (track->metadata);
    g_print ("  - streaminfo:\n");
    caps_print (track->streaminfo);
    g_print ("  - format:\n");
    caps_print (track->format);
    p = p->next;
  }
}

int
main (int argc, char *argv[])
{
  GstMediaInfo *info;
  GstMediaInfoStream *stream;
  gint i;
	
  g_assert (argc > 1);

  gst_init (&argc, &argv);

  info = g_object_new (GST_MEDIA_INFO_TYPE, NULL);
  for (i = 1; i < argc; ++i)
  {
    stream = gst_media_info_read (info, argv[i], GST_MEDIA_INFO_ALL);
    g_print ("\nFILE: %s\n", argv[i]);
    if (stream)
      info_print (stream);
    else
      g_print ("no media info found.\n");
  }
  
  return 0;	
}