From 8f33590566f7ead43785b5b4e1a3385183cd8ccb Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 11 Oct 2013 11:34:46 +0200 Subject: [PATCH] TagList: Added methods from gstreamer-sharp-0.10 --- configure.ac | 4 +- sources/custom/TagList.cs | 137 ++++++++++++++++++++++++++++++++++++++ sources/glue/gobject.c | 6 ++ 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 sources/custom/TagList.cs diff --git a/configure.ac b/configure.ac index bb67858c02..ae6898f415 100644 --- a/configure.ac +++ b/configure.ac @@ -73,14 +73,14 @@ AC_SUBST(LIB_PREFIX) AC_SUBST(LIB_SUFFIX) dnl Check for gtk-sharp -PKG_CHECK_MODULES(GLIB_SHARP, glib-sharp-3.0 >= 2.99.2) +PKG_CHECK_MODULES(GLIB_SHARP, glib-sharp-3.0 >= 2.99.1) AC_SUBST(GLIB_SHARP_CFLAGS) AC_SUBST(GLIB_SHARP_LIBS) gtksharp_prefix=`pkg-config --variable=prefix gtk-sharp-3.0` AC_SUBST(gtksharp_prefix) dnl Find GAPI -PKG_CHECK_MODULES(GAPI, gapi-3.0 >= 2.99.2) +PKG_CHECK_MODULES(GAPI, gapi-3.0 >= 2.99.1) dnl Check for gapi AC_PATH_PROG(GAPI_PARSER, gapi3-parser, no) diff --git a/sources/custom/TagList.cs b/sources/custom/TagList.cs new file mode 100644 index 0000000000..f59100ac30 --- /dev/null +++ b/sources/custom/TagList.cs @@ -0,0 +1,137 @@ +// Copyright (C) 2013 Stephan Sundermann +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +namespace Gst +{ + using System; + using System.Runtime.InteropServices; + + partial class TagList + { + [DllImport("libgstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + 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("libgstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern bool gst_tag_list_copy_value (ref GLib.Value dest, IntPtr list, IntPtr tag); + + 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; + } + } + + public void Add (Gst.TagMergeMode mode, string tag, object value) + { + if (!Tag.TagExists (tag)) + throw new ArgumentException (String.Format ("Invalid tag name '{0}'", tag)); + + GLib.Value v = new GLib.Value (value); + IntPtr raw_v = GLib.Marshaller.StructureToPtrAlloc (v); + + IntPtr raw_string = GLib.Marshaller.StringToPtrGStrdup (tag); + gst_tag_list_add_value (Handle, (int)mode, raw_string, raw_v); + Marshal.FreeHGlobal (raw_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("libgstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + 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("libgstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr gst_structure_get_value (IntPtr raw, IntPtr fieldname); + + public GLib.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(GLib.List)) + return (GLib.List)o; + + return new GLib.List (new object[] { o }, o.GetType(), true, true); + } + } +} \ No newline at end of file diff --git a/sources/glue/gobject.c b/sources/glue/gobject.c index ccec825455..9488f6933a 100644 --- a/sources/glue/gobject.c +++ b/sources/glue/gobject.c @@ -26,3 +26,9 @@ gstsharp_g_type_from_instance (GTypeInstance * instance) { return G_TYPE_FROM_INSTANCE (instance); } + +GObjectClass* +gstsharp_gobjectgetclass (gpointer ptr) +{ + return G_OBJECT_GET_CLASS (G_OBJECT(ptr)); +}