-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti-src.c
175 lines (141 loc) · 6.05 KB
/
multi-src.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
170
171
172
173
174
175
#include <stdio.h>
#include <stdlib.h>
#include <gst/gst.h>
int main(int argc, char *argv[])
{
GstElement *pipeline, *source0, *source1, *source2, *sink, *mixer;
GstBus *bus;
GstMessage *msg;
GstStateChangeReturn ret;
if (argc < 3) {
printf("need pattern indices\n");
return -1;
}
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Create the elements */
source0 = gst_element_factory_make ("videotestsrc", "source0");
source1 = gst_element_factory_make ("videotestsrc", "source1");
source2 = gst_element_factory_make ("videotestsrc", "source2");
mixer = gst_element_factory_make ("videomixer", "mixer");
sink = gst_element_factory_make ("autovideosink", "sink");
/* Create the empty pipeline */
pipeline = gst_pipeline_new ("test-pipeline");
if (!pipeline || !source0 || !source1 || !source2 || !sink) {
g_printerr ("Not all elements could be created.\n");
return -1;
}
/* Build the pipeline */
gst_bin_add_many (GST_BIN (pipeline), source0, source1, source2, mixer, sink, NULL);
if (gst_element_link (mixer, sink) != TRUE) {
g_printerr ("Elements could not be linked.\n");
gst_object_unref (pipeline);
return -1;
}
/* source0 */
{
GstPad *vmix_pad, *src_pad;
GstCaps *caps = gst_caps_new_simple(
"video/x-raw",
"framerate", GST_TYPE_FRACTION, 10, 1,
"width", G_TYPE_INT, 40,
"height", G_TYPE_INT, 80,
NULL);
g_object_set (source0, "pattern", atoi(argv[1]), NULL);
/* connect the sources to a requested pad on the mixer */
vmix_pad = gst_element_get_request_pad(mixer, "sink_%u");
g_print("Obtained request pad %s for mixer\n", gst_pad_get_name(vmix_pad));
src_pad = gst_element_get_static_pad(source0, "src");
g_object_set(vmix_pad, "xpos", 0, NULL);
g_object_set(vmix_pad, "ypos", 0, NULL);
g_object_set(vmix_pad, "zorder", 2, NULL);
gst_element_link_filtered(gst_pad_get_parent_element(src_pad),
gst_pad_get_parent_element(vmix_pad),
caps);
gst_caps_unref(caps);
gst_object_unref(src_pad);
}
/* source1 */
{
GstPad *vmix_pad, *src_pad;
GstCaps *caps = gst_caps_new_simple(
"video/x-raw",
"framerate", GST_TYPE_FRACTION, 10, 1,
"width", G_TYPE_INT, 200,
"height", G_TYPE_INT, 150,
NULL);
g_object_set (source1, "pattern", atoi(argv[2]), NULL);
/* connect the sources to a requested pad on the mixer */
vmix_pad = gst_element_get_request_pad(mixer, "sink_%u");
g_print("Obtained request pad %s for mixer\n", gst_pad_get_name(vmix_pad));
src_pad = gst_element_get_static_pad(source1, "src");
g_object_set(vmix_pad, "xpos", 20, NULL);
g_object_set(vmix_pad, "ypos", 20, NULL);
g_object_set(vmix_pad, "zorder", 1, NULL);
gst_element_link_filtered(gst_pad_get_parent_element(src_pad),
gst_pad_get_parent_element(vmix_pad),
caps);
gst_caps_unref(caps);
gst_object_unref(src_pad);
}
/* source2 */
{
GstPad *vmix_pad, *src_pad;
GstCaps *caps = gst_caps_new_simple(
"video/x-raw",
"framerate", GST_TYPE_FRACTION, 10, 1,
"width", G_TYPE_INT, 640,
"height", G_TYPE_INT, 360,
NULL);
g_object_set (source2, "pattern", atoi(argv[3]), NULL);
/* connect the sources to a requested pad on the mixer */
vmix_pad = gst_element_get_request_pad(mixer, "sink_%u");
g_print("Obtained request pad %s for mixer\n", gst_pad_get_name(vmix_pad));
src_pad = gst_element_get_static_pad(source2, "src");
g_object_set(vmix_pad, "xpos", 0, NULL);
g_object_set(vmix_pad, "ypos", 0, NULL);
g_object_set(vmix_pad, "zorder", 0, NULL);
gst_element_link_filtered(gst_pad_get_parent_element(src_pad),
gst_pad_get_parent_element(vmix_pad),
caps);
gst_caps_unref(caps);
gst_object_unref(src_pad);
}
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE) {
g_printerr ("Unable to set the pipeline to the playing state.\n");
gst_object_unref (pipeline);
return -1;
}
/* Wait until error or EOS */
bus = gst_element_get_bus (pipeline);
msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "multi-src");
/* Parse message */
if (msg != NULL) {
GError *err;
gchar *debug_info;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (msg, &err, &debug_info);
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
g_clear_error (&err);
g_free (debug_info);
break;
case GST_MESSAGE_EOS:
g_print ("End-Of-Stream reached.\n");
break;
default:
/* We should not reach here because we only asked for ERRORs and EOS */
g_printerr ("Unexpected message received.\n");
break;
}
gst_message_unref (msg);
}
/* Free resources */
gst_object_unref (bus);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
return 0;
}