10 static GMainLoop *mainloop = NULL;
12 static gint64 gap = 10;
16 MY_STREAM_TYPE_AUDIO = 0,
17 MY_STREAM_TYPE_VIDEO = 1
20 typedef struct _StreamData StreamData;
28 _stream_decode_pad_added_cb(GstElement * decode,
29 GstPad * pad, gboolean arg1, gpointer user_data)
31 StreamData *data = (StreamData *) user_data;
34 GstCaps *caps = gst_pad_get_caps(pad);
35 gchar *str_caps = gst_caps_to_string(caps);
37 g_debug("decode caps: [%d] [%s]", data->type, str_caps);
41 case MY_STREAM_TYPE_AUDIO:
43 if (strstr(str_caps, "audio") == NULL)
46 case MY_STREAM_TYPE_VIDEO:
48 if (strstr(str_caps, "video") == NULL)
53 queue = gst_bin_get_by_name(GST_BIN(data->bin), "queue");
54 sink_pad = gst_element_get_pad(queue, "sink");
56 if (gst_pad_link(pad, sink_pad) != GST_PAD_LINK_OK)
58 g_warning("Failed to link decode");
61 gst_object_unref(queue);
62 gst_object_unref(sink_pad);
73 _create_src_element(const gchar * name,
74 const gchar * uri, MyStreamType type, guint priority)
85 g_debug("element from uri: %s", uri);
87 bin = gst_bin_new("bin");
88 src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
89 g_return_val_if_fail(src != NULL, NULL);
91 decode = gst_element_factory_make("decodebin", NULL);
92 g_return_val_if_fail(decode != NULL, NULL);
94 queue = gst_element_factory_make("queue", "queue");
95 g_return_val_if_fail(queue != NULL, NULL);
97 gst_bin_add_many(GST_BIN(bin), src, decode, queue, NULL);
98 gst_element_link(src, decode);
100 data = g_new0(StreamData, 1);
103 g_debug("Type : %d = %d", type, data->type);
105 g_signal_connect(G_OBJECT(decode), "new-decoded-pad",
106 G_CALLBACK(_stream_decode_pad_added_cb), data);
109 src_pad = gst_element_get_pad(queue, "src");
110 g_return_val_if_fail(src_pad != NULL, NULL);
112 gst_element_add_pad(bin, gst_ghost_pad_new("src", src_pad));
114 gst_object_unref(src_pad);
116 gnl_src = gst_element_factory_make("gnlsource", name);
117 g_return_val_if_fail(gnl_src != NULL, NULL);
118 gst_bin_add(GST_BIN(gnl_src), bin);
120 g_debug("ADDING WITH: START [%lli] DUR [%lli]", d, gap);
123 g_object_set(G_OBJECT(gnl_src),
125 "duration", 10 * GST_SECOND,
127 //"media-duration", 10 * GST_SECOND,
128 "priority", priority, NULL);
133 g_object_set(G_OBJECT(gnl_src),
134 "start", 10 * GST_SECOND, "duration", 10 * GST_SECOND,
135 ///"media-start", 10 * GST_SECOND,
136 //"media-duration", 10 * GST_SECOND,
137 "priority", priority, NULL);
146 _composition_pad_added_cb(GstElement * composition,
147 GstPad * pad, gpointer data)
149 GstPad *sink_pad = gst_element_get_pad(GST_ELEMENT(data), "sink");
150 g_debug("compose pad added");
152 if (gst_pad_link(pad, sink_pad) != GST_PAD_LINK_OK)
154 g_warning("Failed to link decode");
157 g_debug("Linked ok");
161 _compose_add_file(GstElement * compose,
162 const gchar * e_name,
163 const gchar * uri, MyStreamType type, guint priority)
167 src = _create_src_element(e_name, uri, type, priority);
168 gst_bin_add(GST_BIN(compose), src);
173 main(int argc, char **argv)
176 GstElement *gnl_compose_a;
177 GstElement *gnl_compose_v;
184 gst_init(&argc, &argv);
186 mainloop = g_main_loop_new(NULL, FALSE);
188 pipe = gst_pipeline_new("test_pipeline");
190 gnl_compose_a = gst_element_factory_make("gnlcomposition", "acompose");
191 g_return_val_if_fail(gnl_compose_a != NULL, 1);
193 gnl_compose_v = gst_element_factory_make("gnlcomposition", "vcompose");
194 g_return_val_if_fail(gnl_compose_v != NULL, 1);
197 //_compose_add_file (gnl_compose_a, "src0", argv[1], MY_STREAM_TYPE_AUDIO, 1);
198 //_compose_add_file (gnl_compose_a, "src1", argv[2], MY_STREAM_TYPE_AUDIO, 1);
202 _compose_add_file(gnl_compose_v, "src2", argv[1], MY_STREAM_TYPE_VIDEO, 1);
203 _compose_add_file(gnl_compose_v, "src3", argv[2], MY_STREAM_TYPE_VIDEO, 1);
206 //aqueue = gst_element_factory_make ("queue", "aqueue");
207 //asink = gst_element_factory_make ("alsasink", "asink");
209 vqueue = gst_element_factory_make("queue", "vqueue");
210 vsink = gst_element_factory_make("xvimagesink", "vsink");
212 gst_bin_add_many(GST_BIN(pipe), gnl_compose_a, gnl_compose_v, vqueue, vsink,
216 gst_element_link(vqueue, vsink);
217 //gst_element_link (aqueue, asink);
219 //g_signal_connect (G_OBJECT (gnl_compose_a), "pad-added",
220 // G_CALLBACK (_composition_pad_added_cb), aqueue);
222 g_signal_connect(G_OBJECT(gnl_compose_v), "pad-added",
223 G_CALLBACK(_composition_pad_added_cb), vqueue);
226 //g_idle_add (_play, pipe);
227 gst_element_set_state(GST_ELEMENT(pipe), GST_STATE_PLAYING);
228 g_main_loop_run(mainloop);