summaryrefslogtreecommitdiff
path: root/gstreamer-sharp/TagList.custom
blob: f8ebd5afe581102c75cd9387efde510c31538fd3 (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
120
121
122
[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_structure_to_string (IntPtr handle);

public override string ToString () {
  IntPtr raw_ret = gst_structure_to_string (Handle);
  string ret = GLib.Marshaller.PtrToStringGFree (raw_ret);
  return ret;
}

[DllImport ("gstreamer-0.10.dll") ]
static extern int gst_structure_n_fields (IntPtr raw);

public int Size {
  get {
    int raw_ret = gst_structure_n_fields (Handle);
    int ret = raw_ret;
    return ret;
  }
}

[DllImport ("gstreamer-0.10.dll") ]
static extern bool gst_tag_list_copy_value (ref GLib.Value dest, IntPtr list, IntPtr tag);
[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_tag_list_get_value_index (IntPtr raw, IntPtr tag, uint index);

public object this[string tag, uint index] {
  get {
    IntPtr raw_string = GLib.Marshaller.StringToPtrGStrdup (tag);
    IntPtr raw_ret = gst_tag_list_get_value_index (Handle, raw_string, index);
    GLib.Marshaller.Free (raw_string);

    if (raw_ret == IntPtr.Zero)
      return null;

    GLib.Value v = (GLib.Value) Marshal.PtrToStructure (raw_ret, typeof (GLib.Value));

    return (object) v.Val;
  }
}

public object this[string tag] {
  get {
    GLib.Value v = GLib.Value.Empty;
    bool success;

    IntPtr raw_string = GLib.Marshaller.StringToPtrGStrdup (tag);
    success = gst_tag_list_copy_value (ref v, Handle, raw_string);
    GLib.Marshaller.Free (raw_string);

    if (!success)
      return null;

    object ret = (object) v.Val;
    v.Dispose ();

    return ret;
  }
}

[DllImport ("gstreamersharpglue-0.10") ]
static extern void gstsharp_gst_tag_list_add_value (IntPtr list, Gst.TagMergeMode mode, IntPtr tag, ref GLib.Value v);

public void Add (Gst.TagMergeMode mode, string tag, object value) {
  if (!Tag.Exists (tag))
    throw new ArgumentException (String.Format ("Invalid tag name '{0}'", tag));

  GLib.Value v = new GLib.Value (value);

  IntPtr raw_string = GLib.Marshaller.StringToPtrGStrdup (tag);
  gstsharp_gst_tag_list_add_value (Handle, mode, raw_string, ref v);
  v.Dispose ();
  GLib.Marshaller.Free (raw_string);
}

public void Add (Gst.TagMergeMode mode, params object[] parameters) {
  if (parameters.Length % 2 != 0)
    throw new ArgumentException ();

  for (int i = 0; i < parameters.Length; i += 2) {
    if (parameters[i].GetType () != typeof (string))
      throw new ArgumentException ();

    Add (mode, parameters[i] as string, parameters[i+1]);
  }
}

[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_structure_nth_field_name (IntPtr raw, uint index);

private string NthFieldName (uint index) {
  IntPtr raw_ret = gst_structure_nth_field_name (Handle, index);
  string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
  return ret;
}

public string[] Tags {
  get {
    string[] tags = new string[Size];
    for (uint i = 0; i < Size; i++)
      tags[i] = NthFieldName (i);

    return tags;
  }
}

[DllImport ("gstreamer-0.10.dll") ]
static extern IntPtr gst_structure_get_value (IntPtr raw, IntPtr fieldname);

public Gst.List GetTag (string tag) {
  IntPtr raw_string = GLib.Marshaller.StringToPtrGStrdup (tag);
  IntPtr raw_ret = gst_structure_get_value (Handle, raw_string);
  GLib.Marshaller.Free (raw_string);
  GLib.Value ret = (GLib.Value) Marshal.PtrToStructure (raw_ret, typeof (GLib.Value));

  object o = ret.Val;

  if (o.GetType () == typeof (Gst.List))
    return (Gst.List) o;

  return new Gst.List (new object[] { o });
}