mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-08 18:39:54 +00:00
sample: Add playback tutorial 5 sample
This commit is contained in:
parent
531c90cde2
commit
41af361d89
2 changed files with 132 additions and 2 deletions
|
@ -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 basic-tutorial-7.exe basic-tutorial-8.exe basic-tutorial-9.exe basic-tutorial-12.exe basic-tutorial-13.exe playback-tutorial-1.exe playback-tutorial-2.exe playback-tutorial-3.exe playback-tutorial-4.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 basic-tutorial-8.exe basic-tutorial-9.exe basic-tutorial-12.exe basic-tutorial-13.exe playback-tutorial-1.exe playback-tutorial-2.exe playback-tutorial-3.exe playback-tutorial-4.exe playback-tutorial-5.exe
|
||||
|
||||
DEBUGS = $(addsuffix .mdb, $(TARGETS))
|
||||
assemblies = \
|
||||
|
@ -60,6 +60,9 @@ playback-tutorial-3.exe: $(srcdir)/PlaybackTutorial3.cs $(assemblies)
|
|||
playback-tutorial-4.exe: $(srcdir)/PlaybackTutorial4.cs $(assemblies)
|
||||
$(CSC) $(CSFLAGS) -out:playback-tutorial-4.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/PlaybackTutorial4.cs
|
||||
|
||||
playback-tutorial-5.exe: $(srcdir)/PlaybackTutorial5.cs $(assemblies)
|
||||
$(CSC) $(CSFLAGS) -out:playback-tutorial-5.exe $(references) $(GLIB_SHARP_LIBS) $(srcdir)/PlaybackTutorial5.cs
|
||||
|
||||
EXTRA_DIST = \
|
||||
Playback.cs \
|
||||
VideoOverlay.cs \
|
||||
|
@ -77,4 +80,5 @@ EXTRA_DIST = \
|
|||
PlaybackTutorial1.cs \
|
||||
PlaybackTutorial2.cs \
|
||||
PlaybackTutorial3.cs \
|
||||
PlaybackTutorial4.cs
|
||||
PlaybackTutorial4.cs \
|
||||
PlaybackTutorial5.cs
|
||||
|
|
126
samples/PlaybackTutorial5.cs
Normal file
126
samples/PlaybackTutorial5.cs
Normal file
|
@ -0,0 +1,126 @@
|
|||
// Authors
|
||||
// Copyright (C) 2014 Stephan Sundermann <stephansundermann@gmail.com>
|
||||
|
||||
using System;
|
||||
using Gst;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace GstreamerSharp
|
||||
{
|
||||
class Playback
|
||||
{
|
||||
static Element Pipeline;
|
||||
static GLib.MainLoop MainLoop;
|
||||
|
||||
// Process a color balance command
|
||||
static void UpdateColorChannel (string channelName, bool increase, Gst.Video.IColorBalance cb) {
|
||||
|
||||
// Retrieve the list of channels and locate the requested one
|
||||
var channels = cb.ListChannels ();
|
||||
Gst.Video.ColorBalanceChannel channel = null;
|
||||
foreach (var ch in channels) {
|
||||
var label = ch.Label;
|
||||
|
||||
if (label.Contains (channelName)) {
|
||||
channel = ch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (channel == null)
|
||||
return;
|
||||
|
||||
// Change the channel's value
|
||||
var step = 0.1 * (channel.MaxValue - channel.MinValue);
|
||||
var value = cb.GetValue (channel);
|
||||
if (increase) {
|
||||
value = (int)(value + step);
|
||||
if (value > channel.MaxValue)
|
||||
value = channel.MaxValue;
|
||||
} else {
|
||||
value = (int)(value - step);
|
||||
if (value < channel.MinValue)
|
||||
value = channel.MinValue;
|
||||
}
|
||||
cb.SetValue (channel, value);
|
||||
}
|
||||
|
||||
// Process keyboard input
|
||||
static bool HandleKeyboard () {
|
||||
if (Console.KeyAvailable) {
|
||||
var key = Console.ReadKey (false);
|
||||
var cb = new Gst.Video.ColorBalanceAdapter (Pipeline.Handle);
|
||||
|
||||
switch (key.Key) {
|
||||
case ConsoleKey.C:
|
||||
UpdateColorChannel ("CONTRAST", key.Modifiers == ConsoleModifiers.Shift, cb);
|
||||
break;
|
||||
case ConsoleKey.B:
|
||||
UpdateColorChannel ("BRIGHTNESS", key.Modifiers == ConsoleModifiers.Shift, cb);
|
||||
break;
|
||||
case ConsoleKey.H:
|
||||
UpdateColorChannel ("HUE", key.Modifiers == ConsoleModifiers.Shift, cb);
|
||||
break;
|
||||
case ConsoleKey.S:
|
||||
UpdateColorChannel ("SATURATION", key.Modifiers == ConsoleModifiers.Shift, cb);
|
||||
break;
|
||||
case ConsoleKey.Q:
|
||||
MainLoop.Quit ();
|
||||
break;
|
||||
}
|
||||
PrintCurrentValues ();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Output the current values of all Color Balance channels
|
||||
static void PrintCurrentValues () {
|
||||
// Output Color Balance value
|
||||
var cb = new Gst.Video.ColorBalanceAdapter (Pipeline.Handle);
|
||||
var channels = cb.ListChannels ();
|
||||
|
||||
foreach (var ch in channels) {
|
||||
var value = cb.GetValue (ch);
|
||||
Console.WriteLine ("{0}: {1}", ch.Label, 100 * (value - ch.MinValue) / (ch.MaxValue - ch.MinValue));
|
||||
}
|
||||
Console.WriteLine ();
|
||||
}
|
||||
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
// Initialize GStreamer
|
||||
Application.Init (ref args);
|
||||
GtkSharp.GstreamerSharp.ObjectManager.Initialize ();
|
||||
|
||||
// Print usage map
|
||||
Console.WriteLine ("USAGE: Choose one of the following options, then press enter:");
|
||||
Console.WriteLine (" 'C' to increase contrast, 'c' to decrease contrast");
|
||||
Console.WriteLine (" 'B' to increase brightness, 'b' to decrease brightness");
|
||||
Console.WriteLine (" 'H' to increase hue, 'h' to decrease hue");
|
||||
Console.WriteLine (" 'S' to increase saturation, 's' to decrease saturation");
|
||||
Console.WriteLine (" 'Q' to quit");
|
||||
|
||||
// Build the pipeline
|
||||
Pipeline = Parse.Launch ("playbin uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm");
|
||||
|
||||
// Add a keyboard watch so we get notified of keystrokes
|
||||
|
||||
// Start playing
|
||||
var ret = Pipeline.SetState (State.Playing);
|
||||
if (ret == StateChangeReturn.Failure) {
|
||||
Console.WriteLine ("Unable to set the pipeline to the playing state.");
|
||||
return;
|
||||
}
|
||||
PrintCurrentValues ();
|
||||
|
||||
// Create a GLib Main Loop and set it to run
|
||||
MainLoop = new GLib.MainLoop ();
|
||||
GLib.Timeout.Add (50, HandleKeyboard);
|
||||
MainLoop.Run ();
|
||||
|
||||
// Free resources
|
||||
Pipeline.SetState (State.Null);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue