summaryrefslogtreecommitdiff
path: root/samples/BasicTutorial2.cs
blob: b6b29c30805dc177fd0a595d02860b96c8721ec6 (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
// Authors
//   Copyright (C) 2014 Stephan Sundermann <stephansundermann@gmail.com>

using System;
using Gst; 

namespace GstreamerSharp
{
	class Playback
	{
		public static void Main (string[] args)
		{
			// Initialize Gstreamer
			Application.Init(ref args);

			// Build the pipeline
			var source = ElementFactory.Make ("videotestsrc", "source");
			var sink = ElementFactory.Make ("autovideosink", "sink");

			// Create the empty pipeline
			var pipeline = new Pipeline ("test-pipeline");

			if (pipeline == null || source == null || sink == null) {
				Console.WriteLine ("Not all elements could be created");
				return;
			}

			// Build the pipeline
			pipeline.Add (source, sink);
			if (!source.Link (sink)) {
				Console.WriteLine ("Elements could not be linked");
				return;
			}

			// Modify the source's properties
			source ["pattern"] = 0;

			// Start playing
			var ret = pipeline.SetState(State.Playing);
			if (ret == StateChangeReturn.Failure) {
				Console.WriteLine ("Unable to set the pipeline to the playing state");
				return;
			}

			// Wait until error or EOS
			var bus = pipeline.Bus;
			var msg = bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error);

			// Free resources
			if (msg != null) {
				switch (msg.Type) {
				case MessageType.Error:
					GLib.GException exc;
					string debug;
					msg.ParseError (out exc, out debug);
					Console.WriteLine (String.Format ("Error received from element {0}: {1}", msg.Src.Name, exc.Message));
					Console.WriteLine (String.Format ("Debugging information {0}", debug));
					break;
				case MessageType.Eos:
					Console.WriteLine ("End-Of-Stream reached");
					break;
				default:
					// We should not reach here because we only asked for ERRORs and EOS
					Console.WriteLine ("Unexpected messag received");
					break;
				}
			}

			pipeline.SetState (State.Null);
		}
	}
}