summaryrefslogtreecommitdiff
path: root/sources/custom/Application.cs
blob: 2cbf40d61ec1449cc30467f01ba3d0d78f673baa (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
// Copyright (C) 2013  Stephan Sundermann <stephansundermann@gmail.com>
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301  USA

namespace Gst {
	using System;
	using System.Runtime.InteropServices;

	partial class Application 
	{
		// Because of: https://bugzilla.gnome.org/show_bug.cgi?id=743062#c30
		private static uint MIN_GSTREAMER_MINOR = 14;

		static Application () {
			GLib.GType.Register (List.GType, typeof(List));
			GLib.GType.Register (Fraction.GType, typeof(Fraction));
			GLib.GType.Register (DoubleRange.GType, typeof(DoubleRange));
			GLib.GType.Register (IntRange.GType, typeof(IntRange));
			GLib.GType.Register (FractionRange.GType, typeof(FractionRange));
			GLib.GType.Register (DateTime.GType, typeof(DateTime));
			GLib.GType.Register (Gst.Array.GType, typeof(Gst.Array));
			GLib.GType.Register(Promise.GType, typeof(Promise));
			GLib.GType.Register(Gst.WebRTC.WebRTCSessionDescription.GType, typeof(Gst.WebRTC.WebRTCSessionDescription));
		}

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern void gst_init(ref int argc, ref IntPtr[] argv);

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern void gst_init(IntPtr argc, IntPtr argv);

		private static void CheckVersion() {
			if (Gst.Version.Minor < MIN_GSTREAMER_MINOR)
				throw new Exception(Gst.Version.Description + " found but GStreamer 1." +
					MIN_GSTREAMER_MINOR + " required.");
		}

		public static void Init() {
			gst_init (IntPtr.Zero, IntPtr.Zero);
			CheckVersion();
		}
			
		public static void Init(ref string[] argv) {
			int cnt_argv = argv == null ? 0 : argv.Length;
			System.Collections.Generic.List<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>();
			for (int i = 0; i < cnt_argv; i++)
				native_arg_list.Add (GLib.Marshaller.StringToPtrGStrdup(argv[i]));
			IntPtr[] native_argv = native_arg_list.ToArray();
			gst_init(ref cnt_argv, ref native_argv);
			foreach (var native_arg in native_arg_list)
				GLib.Marshaller.Free (native_arg);

			CheckVersion();
		}

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern bool gst_init_check(ref int argc, ref IntPtr[] argv, out IntPtr error);

		[DllImport("gstreamer-1.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
		static extern bool gst_init_check(IntPtr argc, IntPtr argv, out IntPtr error);

		public static bool InitCheck() {
			IntPtr error = IntPtr.Zero;
			bool ret = gst_init_check (IntPtr.Zero, IntPtr.Zero, out error);

			CheckVersion();
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

		public static bool InitCheck(ref string[] argv) {
			int cnt_argv = argv == null ? 0 : argv.Length;
			System.Collections.Generic.List<IntPtr> native_arg_list = new System.Collections.Generic.List<IntPtr>();
			for (int i = 0; i < cnt_argv; i++)
				native_arg_list.Add (GLib.Marshaller.StringToPtrGStrdup(argv[i]));
			IntPtr[] native_argv = native_arg_list.ToArray();
			IntPtr error = IntPtr.Zero;
			bool ret = gst_init_check(ref cnt_argv, ref native_argv, out error);
			foreach (var native_arg in native_arg_list)
				GLib.Marshaller.Free (native_arg);
			if (error != IntPtr.Zero) throw new GLib.GException (error);

			CheckVersion();
			return ret;
		}
	}
}