diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/ecore/src/examples/ecore_pipe_gstreamer_example.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/ecore/src/examples/ecore_pipe_gstreamer_example.c')
-rw-r--r-- | libraries/ecore/src/examples/ecore_pipe_gstreamer_example.c | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/libraries/ecore/src/examples/ecore_pipe_gstreamer_example.c b/libraries/ecore/src/examples/ecore_pipe_gstreamer_example.c new file mode 100644 index 0000000..590d957 --- /dev/null +++ b/libraries/ecore/src/examples/ecore_pipe_gstreamer_example.c | |||
@@ -0,0 +1,180 @@ | |||
1 | #include <gst/gst.h> | ||
2 | #include <Ecore.h> | ||
3 | |||
4 | static int nbr = 0; | ||
5 | |||
6 | static GstElement *_buid_pipeline (gchar *filename, Ecore_Pipe *pipe); | ||
7 | |||
8 | static void new_decoded_pad_cb (GstElement *demuxer, | ||
9 | GstPad *new_pad, | ||
10 | gpointer user_data); | ||
11 | |||
12 | static void handler(void *data, void *buf, unsigned int len) | ||
13 | { | ||
14 | GstBuffer *buffer = *((GstBuffer **)buf); | ||
15 | |||
16 | printf ("handler : %p\n", buffer); | ||
17 | printf ("frame : %d %p %lld %p\n", nbr++, data, (long long)GST_BUFFER_DURATION(buffer), buffer); | ||
18 | gst_buffer_unref (buffer); | ||
19 | } | ||
20 | |||
21 | |||
22 | static void handoff (GstElement* object, | ||
23 | GstBuffer* arg0, | ||
24 | GstPad* arg1, | ||
25 | gpointer user_data) | ||
26 | { | ||
27 | Ecore_Pipe *pipe; | ||
28 | |||
29 | pipe = (Ecore_Pipe *)user_data; | ||
30 | printf ("handoff : %p\n", arg0); | ||
31 | gst_buffer_ref (arg0); | ||
32 | ecore_pipe_write(pipe, &arg0, sizeof(arg0)); | ||
33 | } | ||
34 | |||
35 | int | ||
36 | main (int argc, char *argv[]) | ||
37 | { | ||
38 | GstElement *pipeline; | ||
39 | char *filename; | ||
40 | Ecore_Pipe *pipe; | ||
41 | |||
42 | gst_init (&argc, &argv); | ||
43 | |||
44 | if (!ecore_init ()) | ||
45 | { | ||
46 | gst_deinit (); | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | pipe = ecore_pipe_add (handler); | ||
51 | if (!pipe) | ||
52 | { | ||
53 | ecore_shutdown (); | ||
54 | gst_deinit (); | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | if (argc < 2) { | ||
59 | g_print ("usage: %s file.avi\n", argv[0]); | ||
60 | ecore_pipe_del (pipe); | ||
61 | ecore_shutdown (); | ||
62 | gst_deinit (); | ||
63 | return 0; | ||
64 | } | ||
65 | filename = argv[1]; | ||
66 | |||
67 | pipeline = _buid_pipeline (filename, pipe); | ||
68 | if (!pipeline) { | ||
69 | g_print ("Error during the pipeline building\n"); | ||
70 | ecore_pipe_del (pipe); | ||
71 | ecore_shutdown (); | ||
72 | gst_deinit (); | ||
73 | return -1; | ||
74 | } | ||
75 | |||
76 | gst_element_set_state (pipeline, GST_STATE_PLAYING); | ||
77 | |||
78 | ecore_main_loop_begin(); | ||
79 | |||
80 | ecore_pipe_del (pipe); | ||
81 | ecore_shutdown (); | ||
82 | gst_deinit (); | ||
83 | |||
84 | return 0; | ||
85 | } | ||
86 | |||
87 | static void | ||
88 | new_decoded_pad_cb (GstElement *demuxer, | ||
89 | GstPad *new_pad, | ||
90 | gpointer user_data) | ||
91 | { | ||
92 | GstElement *decoder; | ||
93 | GstPad *pad; | ||
94 | GstCaps *caps; | ||
95 | gchar *str; | ||
96 | |||
97 | caps = gst_pad_get_caps (new_pad); | ||
98 | str = gst_caps_to_string (caps); | ||
99 | |||
100 | if (g_str_has_prefix (str, "video/")) { | ||
101 | decoder = GST_ELEMENT (user_data); | ||
102 | |||
103 | pad = gst_element_get_pad (decoder, "sink"); | ||
104 | if (GST_PAD_LINK_FAILED (gst_pad_link (new_pad, pad))) { | ||
105 | g_warning ("Failed to link %s:%s to %s:%s", GST_DEBUG_PAD_NAME (new_pad), | ||
106 | GST_DEBUG_PAD_NAME (pad)); | ||
107 | } | ||
108 | } | ||
109 | g_free (str); | ||
110 | gst_caps_unref (caps); | ||
111 | } | ||
112 | |||
113 | static GstElement | ||
114 | _buid_pipeline (gchar *filename, Ecore_Pipe *pipe) | ||
115 | { | ||
116 | GstElement *pipeline; | ||
117 | GstElement *filesrc; | ||
118 | GstElement *demuxer; | ||
119 | GstElement *decoder; | ||
120 | GstElement *sink; | ||
121 | GstStateChangeReturn res; | ||
122 | |||
123 | pipeline = gst_pipeline_new ("pipeline"); | ||
124 | if (!pipeline) | ||
125 | return NULL; | ||
126 | |||
127 | filesrc = gst_element_factory_make ("filesrc", "filesrc"); | ||
128 | if (!filesrc) { | ||
129 | printf ("no filesrc"); | ||
130 | goto failure; | ||
131 | } | ||
132 | g_object_set (G_OBJECT (filesrc), "location", filename, NULL); | ||
133 | |||
134 | demuxer = gst_element_factory_make ("oggdemux", "demuxer"); | ||
135 | if (!demuxer) { | ||
136 | printf ("no demux"); | ||
137 | goto failure; | ||
138 | } | ||
139 | |||
140 | decoder = gst_element_factory_make ("theoradec", "decoder"); | ||
141 | if (!decoder) { | ||
142 | printf ("no dec"); | ||
143 | goto failure; | ||
144 | } | ||
145 | |||
146 | g_signal_connect (demuxer, "pad-added", | ||
147 | G_CALLBACK (new_decoded_pad_cb), decoder); | ||
148 | |||
149 | sink = gst_element_factory_make ("fakesink", "sink"); | ||
150 | if (!sink) { | ||
151 | printf ("no sink"); | ||
152 | goto failure; | ||
153 | } | ||
154 | g_object_set (G_OBJECT (sink), "sync", EINA_TRUE, NULL); | ||
155 | g_object_set (G_OBJECT (sink), "signal-handoffs", EINA_TRUE, NULL); | ||
156 | g_signal_connect (sink, "handoff", | ||
157 | G_CALLBACK (handoff), pipe); | ||
158 | |||
159 | gst_bin_add_many (GST_BIN (pipeline), | ||
160 | filesrc, demuxer, decoder, sink, NULL); | ||
161 | |||
162 | if (!gst_element_link (filesrc, demuxer)) | ||
163 | goto failure; | ||
164 | if (!gst_element_link (decoder, sink)) | ||
165 | goto failure; | ||
166 | |||
167 | res = gst_element_set_state (pipeline, GST_STATE_PAUSED); | ||
168 | if (res == GST_STATE_CHANGE_FAILURE) | ||
169 | goto failure; | ||
170 | |||
171 | res = gst_element_get_state( pipeline, NULL, NULL, GST_CLOCK_TIME_NONE ); | ||
172 | if (res != GST_STATE_CHANGE_SUCCESS) | ||
173 | goto failure; | ||
174 | |||
175 | return pipeline; | ||
176 | |||
177 | failure: | ||
178 | gst_object_unref (GST_OBJECT (pipeline)); | ||
179 | return NULL; | ||
180 | } | ||