mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-13 12:51:16 +00:00
sample: Add basic tutorial 2 sample
This commit is contained in:
parent
2e8045d2dc
commit
27d42dfd3f
2 changed files with 83 additions and 2 deletions
77
samples/BasicTutorial2.cs
Normal file
77
samples/BasicTutorial2.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
// 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)) {
|
||||
pipeline.Dispose ();
|
||||
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");
|
||||
pipeline.Dispose ();
|
||||
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;
|
||||
}
|
||||
msg.Dispose ();
|
||||
}
|
||||
|
||||
bus.Dispose ();
|
||||
pipeline.SetState (State.Null);
|
||||
pipeline.Dispose ();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
TARGETS = playback.exe video-overlay.exe basic-tutorial-1.exe
|
||||
TARGETS = playback.exe video-overlay.exe basic-tutorial-1.exe basic-tutorial-2.exe
|
||||
|
||||
DEBUGS = $(addsuffix .mdb, $(TARGETS))
|
||||
assemblies = \
|
||||
|
@ -18,7 +18,11 @@ video-overlay.exe: $(srcdir)/VideoOverlay.cs $(assemblies)
|
|||
basic-tutorial-1.exe: $(srcdir)/BasicTutorial1.cs $(assemblies)
|
||||
$(CSC) $(CSFLAGS) -out:basic-tutorial-1.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/BasicTutorial1.cs
|
||||
|
||||
basic-tutorial-2.exe: $(srcdir)/BasicTutorial2.cs $(assemblies)
|
||||
$(CSC) $(CSFLAGS) -out:basic-tutorial-2.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/BasicTutorial2.cs
|
||||
|
||||
EXTRA_DIST = \
|
||||
Playback.cs \
|
||||
VideoOverlay.cs \
|
||||
BasicTutorial1.cs
|
||||
BasicTutorial1.cs \
|
||||
BasicTutorial2.cs
|
||||
|
|
Loading…
Reference in a new issue