diff options
-rw-r--r-- | samples/BasicTutorial7.cs | 80 | ||||
-rw-r--r-- | samples/Makefile.am | 8 |
2 files changed, 86 insertions, 2 deletions
diff --git a/samples/BasicTutorial7.cs b/samples/BasicTutorial7.cs new file mode 100644 index 0000000..7c4f5c1 --- /dev/null +++ b/samples/BasicTutorial7.cs @@ -0,0 +1,80 @@ +// Authors +// Copyright (C) 2014 Stephan Sundermann <stephansundermann@gmail.com> + +using System; +using Gst; +using System.Runtime.InteropServices; + +namespace GstreamerSharp +{ + class Playback + { + public static void Main (string[] args) + { + // Initialize Gstreamer + Gst.Application.Init(ref args); + + // Create the elements + var audioSource = ElementFactory.Make ("audiotestsrc", "audio_source"); + var tee = ElementFactory.Make ("tee", "tee"); + var audioQueue = ElementFactory.Make ("queue", "audio_queue"); + var audioConvert = ElementFactory.Make ("audioconvert", "audio_convert"); + var audioResample = ElementFactory.Make ("audioresample", "audio_resample"); + var audioSink = ElementFactory.Make ("autoaudiosink", "audio_sink"); + var videoQueue = ElementFactory.Make ("queue", "video_queue"); + var visual = ElementFactory.Make ("wavescope", "visual"); + var videoConvert = ElementFactory.Make ("videoconvert", "csp"); + var videoSink = ElementFactory.Make ("autovideosink", "video_sink"); + + // Create the empty pipeline + var pipeline = new Pipeline ("test-pipeline"); + + if (audioSource == null || tee == null || audioQueue == null || audioConvert == null || audioResample == null || + audioSink == null || videoQueue == null || visual == null || videoConvert == null || videoSink == null || pipeline == null) { + Console.WriteLine ("Not all elements could be created."); + return; + } + + + // Link all elements that can be automatically linked because they have "Always" pads + pipeline.Add (audioSource, tee, audioQueue, audioConvert, audioResample, audioSink, + videoQueue, visual, videoConvert, videoSink); + if (!audioSource.Link (tee) || + !Element.Link (audioQueue, audioConvert, audioResample, audioSink) || + !Element.Link (videoQueue, visual, videoConvert, videoSink)) { + Console.WriteLine ("Elements could not be linked."); + return; + } + + // Manually link the Tee, which has "Request" pads + var teeSrcPadTemplate = tee.GetPadTemplate ("src_%u"); + var teeAudioPad = tee.RequestPad (teeSrcPadTemplate, null, null); + Console.WriteLine ("Obtained request pad {0} for audio branch.", teeAudioPad.Name); + var queueAudioPad = audioQueue.GetStaticPad ("sink"); + var teeVideoPad = tee.RequestPad (teeSrcPadTemplate, null, null); + Console.WriteLine ("Obtained request pad {0} for video branch.", teeVideoPad.Name); + var queueVideoPad = videoQueue.GetStaticPad ("sink"); + if (teeAudioPad.Link (queueAudioPad) != PadLinkReturn.Ok || + teeVideoPad.Link(queueVideoPad) != PadLinkReturn.Ok) { + Console.WriteLine ("Tee could not be linked."); + return; + } + + // Start playing + var ret = pipeline.SetState (State.Playing); + if (ret == StateChangeReturn.Failure) { + Console.WriteLine ("Unable to set the pipeline to the playing state (check the bus for error messages)."); + } + + // Wait until error or EOS + pipeline.Bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.Error | MessageType.Eos); + + // Release the request pads from the Tee, and unref them + tee.ReleaseRequestPad (teeAudioPad); + tee.ReleaseRequestPad (teeVideoPad); + + // Free resources + pipeline.SetState (State.Null); + } + } +}
\ No newline at end of file diff --git a/samples/Makefile.am b/samples/Makefile.am index 090543c..8536b69 100644 --- a/samples/Makefile.am +++ b/samples/Makefile.am @@ -1,4 +1,4 @@ -TARGETS = playback.exe video-overlay.exe basic-tutorial-1.exe basic-tutorial-2.exe basic-tutorial-3.exe basic-tutorial-4.exe basic-tutorial-5.exe basic-tutorial-6.exe +TARGETS = playback.exe video-overlay.exe basic-tutorial-1.exe basic-tutorial-2.exe basic-tutorial-3.exe basic-tutorial-4.exe basic-tutorial-5.exe basic-tutorial-6.exe basic-tutorial-7.exe DEBUGS = $(addsuffix .mdb, $(TARGETS)) assemblies = \ @@ -33,6 +33,9 @@ basic-tutorial-5.exe: $(srcdir)/BasicTutorial5.cs $(assemblies) basic-tutorial-6.exe: $(srcdir)/BasicTutorial6.cs $(assemblies) $(CSC) $(CSFLAGS) -out:basic-tutorial-6.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/BasicTutorial6.cs +basic-tutorial-7.exe: $(srcdir)/BasicTutorial7.cs $(assemblies) + $(CSC) $(CSFLAGS) -out:basic-tutorial-7.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/BasicTutorial7.cs + EXTRA_DIST = \ Playback.cs \ VideoOverlay.cs \ @@ -41,4 +44,5 @@ EXTRA_DIST = \ BasicTutorial3.cs \ BasicTutorial4.cs \ BasicTutorial5.cs \ - BasicTutorial6.cs + BasicTutorial6.cs \ + BasicTutorial7.cs |