-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtk-recur.c
169 lines (138 loc) · 4.59 KB
/
gtk-recur.c
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*Copyright 2014 Douglas Bagnall <[email protected]> LGPL
This is a gtk app that runs the recur plugin. Try --help.
*/
#include "player-common.h"
#define WIDTH 800
#define HEIGHT 600
#define VID_LAGOS "movies/louis-theroux-lagos/louis.theroux.law.and.disorder.in.lagos.ws.pdtv.xvid-waters.avi"
#define VID_TEARS "F30275.mov"
static const char *PIPELINE_TEMPLATE = ("uridecodebin name=src "
" ! videoscale method=nearest-neighbour ! videoconvert"
" ! video/x-raw, format=I420, width=" QUOTE(WIDTH) ", height=" QUOTE(HEIGHT)
" ! recur_manager name=recur osdebug=0 ! videoconvert"
" ! xvimagesink name=videosink force-aspect-ratio=false"
" recur. ! audio/x-raw ! fakesink"
" src. ! audioconvert ! audioresample ! recur.");
static gboolean option_fullscreen = FALSE;
static gint option_width = WIDTH;
static gint option_height = HEIGHT;
static char *option_uri = URI_PREFIX VID_LAGOS;
static GOptionEntry entries[] =
{
{ "full-screen", 'f', 0, G_OPTION_ARG_NONE, &option_fullscreen,
"run full screen", NULL },
{ "width", 'w', 0, G_OPTION_ARG_INT, &option_width, "width of each screen", NULL },
{ "height", 'h', 0, G_OPTION_ARG_INT, &option_height, "height of screen", NULL },
{ "uri", 'u', 0, G_OPTION_ARG_FILENAME, &option_uri, "URI to play", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
static gboolean
key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
switch (event->keyval){
case 'f':
toggle_fullscreen(widget);
break;
case 'q':
g_signal_emit_by_name(widget, "destroy");
break;
default:
break;
}
return TRUE;
}
static void
video_widget_realize_cb (GtkWidget * widget, gpointer data)
{
gulong xid = GDK_WINDOW_XID (gtk_widget_get_window (widget));
video_window_handle = xid;
//static const GdkColor black = {0, 0, 0, 0};
gtk_window_set_default_size(GTK_WINDOW(widget), option_width, option_height);
hide_mouse(widget);
if (option_fullscreen){
gtk_window_fullscreen(GTK_WINDOW(widget));
}
}
gboolean bus_callback(GstBus *bus, GstMessage *msg, GMainLoop *loop)
{
switch (GST_MESSAGE_TYPE(msg))
{
case GST_MESSAGE_EOS:
g_main_loop_quit(loop);
gtk_main_quit();
break;
default:
break;
}
return TRUE;
}
static void
src_drained_cb(GstElement *src, GMainLoop *loop)
{
g_main_loop_quit(loop);
gtk_main_quit();
}
static GstElement *
make_pipeline(GError **parse_error, GMainLoop *loop){
GstElement *pipeline = gst_parse_launch(PIPELINE_TEMPLATE,
parse_error);
GstElement *src = gst_bin_get_by_name(GST_BIN(pipeline), "src");
g_object_set(G_OBJECT(src),
"uri", option_uri,
NULL);
DEBUG("uri is %s", option_uri);
g_signal_connect(src, "drained",
G_CALLBACK(src_drained_cb), loop);
return pipeline;
}
static void
options(int argc, char *argv[]){
GOptionGroup *gst_opts = gst_init_get_option_group();
GOptionGroup *gtk_opts = gtk_get_option_group(TRUE);
GOptionContext *ctx = g_option_context_new("...!");
g_option_context_add_main_entries(ctx, entries, NULL);
g_option_context_add_group(ctx, gst_opts);
g_option_context_add_group(ctx, gtk_opts);
GError *error = NULL;
if (!g_option_context_parse(ctx, &argc, &argv, &error)){
g_print ("Error initializing: %s\n", GST_STR_NULL(error->message));
exit (1);
}
g_option_context_free(ctx);
}
void destroy_cb(GtkWidget * widget, GMainLoop *loop)
{
g_main_loop_quit(loop);
gtk_main_quit();
}
gint main (int argc, char *argv[])
{
options(argc, argv);
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/*Tell gstreamer to look locally for the plugin*/
GstRegistry *registry;
registry = gst_registry_get();
gst_registry_scan_path(registry, "plugins");
GError *parse_error = NULL;
GstElement *pipeline = make_pipeline(&parse_error, loop);
DEBUG("pipeline is %p", pipeline);
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
gst_bus_set_sync_handler(bus, (GstBusSyncHandler)sync_bus_call, NULL, NULL);
gst_bus_add_watch(bus, (GstBusFunc)bus_callback, loop);
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_signal_connect(G_OBJECT(window), "key-press-event",
G_CALLBACK(key_press_event_cb), NULL);
DEBUG("pipeline is %p", pipeline);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(destroy_cb), loop);
g_signal_connect(window, "realize",
G_CALLBACK(video_widget_realize_cb), NULL);
gtk_widget_show_all(window);
//hide_mouse(window);
g_main_loop_run(loop);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}