2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
4 #include "emotion_gstreamer.h"
5 #include "emotion_gstreamer_pipeline.h"
8 static void dvd_pad_added_cb (GstElement *dvddemuxer,
12 static void dvd_no_more_pads_cb (GstElement *dvddemuxer,
15 static int no_more_pads = 0;
19 emotion_pipeline_dvd_build(void *video, const char *device)
21 GstElement *dvdreadsrc;
23 Emotion_Gstreamer_Video *ev;
27 ev = (Emotion_Gstreamer_Video *)video;
30 dvdreadsrc = gst_element_factory_make("dvdreadsrc", "src");
32 goto failure_dvdreadsrc;
34 g_object_set(G_OBJECT(dvdreadsrc), "device", device, NULL);
36 dvddemux = gst_element_factory_make("dvddemux", "dvddemux");
38 goto failure_dvddemux;
39 g_signal_connect(dvddemux, "pad-added",
40 G_CALLBACK(dvd_pad_added_cb), ev);
41 g_signal_connect(dvddemux, "no-more-pads",
42 G_CALLBACK(dvd_no_more_pads_cb), ev);
44 gst_bin_add_many(GST_BIN(ev->pipeline), dvdreadsrc, dvddemux, NULL);
45 if (!gst_element_link(dvdreadsrc, dvddemux))
48 if (!emotion_pipeline_pause(ev->pipeline))
49 goto failure_gstreamer_pause;
51 while (no_more_pads == 0)
57 /* We get the informations of streams */
58 alist = ev->audio_sinks;
59 vlist = ev->video_sinks;
65 it = gst_element_iterate_src_pads(dvddemux);
66 while (gst_iterator_next(it, &data) == GST_ITERATOR_OK)
74 caps = gst_pad_get_caps(pad);
75 str = gst_caps_to_string(caps);
76 g_print("caps !! %s\n", str);
78 if (g_str_has_prefix(str, "video/mpeg"))
80 Emotion_Video_Sink *vsink;
84 vsink = (Emotion_Video_Sink *)eina_list_data_get(vlist);
85 vlist = eina_list_next(vlist);
86 sink_pad = gst_element_get_pad(gst_bin_get_by_name(GST_BIN(ev->pipeline), "mpeg2dec"), "src");
87 sink_caps = gst_pad_get_caps(sink_pad);
88 str = gst_caps_to_string(sink_caps);
89 g_print(" ** caps v !! %s\n", str);
91 emotion_video_sink_fill(vsink, sink_pad, sink_caps);
93 gst_caps_unref(sink_caps);
94 gst_object_unref(sink_pad);
97 else if (g_str_has_prefix(str, "audio/"))
99 Emotion_Audio_Sink *asink;
103 asink = (Emotion_Audio_Sink *)eina_list_data_get(alist);
104 alist = eina_list_next(alist);
105 sink_pad = gst_element_get_pad(gst_bin_get_by_name(GST_BIN(ev->pipeline), "a52dec"), "src");
106 sink_caps = gst_pad_get_caps(sink_pad);
108 emotion_audio_sink_fill(asink, sink_pad, sink_caps);
110 gst_caps_unref(caps);
112 gst_object_unref(pad);
114 gst_iterator_free(it);
117 /* The first vsink is a valid Emotion_Video_Sink * */
118 /* If no video stream is found, it's a visualisation sink */
120 Emotion_Video_Sink *vsink;
122 vsink = (Emotion_Video_Sink *)eina_list_data_get(ev->video_sinks);
123 if (vsink && vsink->sink)
125 g_object_set(G_OBJECT(vsink->sink), "sync", TRUE, NULL);
126 g_object_set(G_OBJECT(vsink->sink), "signal-handoffs", TRUE, NULL);
127 g_signal_connect(G_OBJECT(vsink->sink),
129 G_CALLBACK(cb_handoff), ev);
135 failure_gstreamer_pause:
137 gst_element_set_state(ev->pipeline, GST_STATE_NULL);
138 gst_bin_remove(GST_BIN(ev->pipeline), dvddemux);
140 gst_bin_remove(GST_BIN(ev->pipeline), dvdreadsrc);
147 dvd_pad_added_cb(GstElement *dvddemuxer,
151 Emotion_Gstreamer_Video *ev;
155 ev = (Emotion_Gstreamer_Video *)user_data;
156 caps = gst_pad_get_caps(GST_PAD(new_pad));
157 str = gst_caps_to_string(caps);
159 if (g_str_has_prefix(str, "video/mpeg"))
161 Emotion_Video_Sink *vsink;
166 vsink = (Emotion_Video_Sink *)malloc(sizeof(Emotion_Video_Sink));
168 ev->video_sinks = eina_list_append(ev->video_sinks, vsink);
169 if (eina_error_get())
175 queue = gst_element_factory_make("queue", NULL);
176 decoder = gst_element_factory_make("mpeg2dec", "mpeg2dec");
177 vsink->sink = gst_element_factory_make("fakesink", "videosink");
178 gst_bin_add_many(GST_BIN(ev->pipeline), queue, decoder, vsink->sink, NULL);
179 gst_element_link(queue, decoder);
180 gst_element_link(decoder, vsink->sink);
181 videopad = gst_element_get_pad(queue, "sink");
182 gst_pad_link(GST_PAD(new_pad), videopad);
183 gst_object_unref(videopad);
184 if (eina_list_count(ev->video_sinks) == 1)
186 ev->ratio = (double)vsink->width / (double)vsink->height;
188 gst_element_set_state(queue, GST_STATE_PAUSED);
189 gst_element_set_state(decoder, GST_STATE_PAUSED);
190 gst_element_set_state(vsink->sink, GST_STATE_PAUSED);
193 else if (g_str_has_prefix(str, "audio/"))
195 Emotion_Audio_Sink *asink;
199 GstElement *resample;
204 asink = (Emotion_Audio_Sink *)malloc(sizeof(Emotion_Audio_Sink));
206 ev->audio_sinks = eina_list_append(ev->audio_sinks, asink);
207 if (eina_error_get())
213 queue = gst_element_factory_make("queue", NULL);
214 decoder = gst_element_factory_make("a52dec", "a52dec");
215 conv = gst_element_factory_make("audioconvert", NULL);
216 resample = gst_element_factory_make("audioresample", NULL);
217 volume = gst_element_factory_make("volume", "volume");
218 g_object_get(G_OBJECT(volume), "volume", &vol, NULL);
219 ev->volume = vol / 10.0;
221 /* FIXME: must manage several audio streams */
222 asink->sink = gst_element_factory_make("fakesink", NULL);
224 gst_bin_add_many(GST_BIN(ev->pipeline),
225 queue, decoder, conv, resample, volume, asink->sink, NULL);
226 gst_element_link_many(queue, decoder, conv, resample, volume, asink->sink, NULL);
228 audiopad = gst_element_get_pad(queue, "sink");
229 gst_pad_link(GST_PAD(new_pad), audiopad);
230 gst_object_unref(audiopad);
232 gst_element_set_state(queue, GST_STATE_PAUSED);
233 gst_element_set_state(decoder, GST_STATE_PAUSED);
234 gst_element_set_state(conv, GST_STATE_PAUSED);
235 gst_element_set_state(resample, GST_STATE_PAUSED);
236 gst_element_set_state(volume, GST_STATE_PAUSED);
237 gst_element_set_state(asink->sink, GST_STATE_PAUSED);
242 dvd_no_more_pads_cb(GstElement *dvddemuxer,