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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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://freedesktop.org/software/gstreamer-sdk/data/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);
}
}
}
|