summaryrefslogtreecommitdiff
path: root/src/generic/evas/gst/main_0_10.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-25 15:21:45 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-07-25 15:21:45 +0900
commit287c543ea3622c0929b2f9f1fb93414623e515d6 (patch)
treed78bf8f0be367b3950bc9c8581ea282d2a15bdb7 /src/generic/evas/gst/main_0_10.c
parent892c126cf47d02724d4ce2d6e3e972ab6363eae3 (diff)
efl - when evas generic loaders merged the gst loader was missed. fix
this fixes the missing gst loader from generic loaders.
Diffstat (limited to '')
-rw-r--r--src/generic/evas/gst/main_0_10.c278
1 files changed, 278 insertions, 0 deletions
diff --git a/src/generic/evas/gst/main_0_10.c b/src/generic/evas/gst/main_0_10.c
new file mode 100644
index 0000000000..3e0c02b823
--- /dev/null
+++ b/src/generic/evas/gst/main_0_10.c
@@ -0,0 +1,278 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <sys/mman.h>
6#include <fcntl.h>
7#include <unistd.h>
8
9#include <gst/gst.h>
10
11#include <Eina.h>
12
13#include "shmfile.h"
14#include "timeout.h"
15
16#define DATA32 unsigned int
17
18//#define GST_DBG
19
20#ifdef GST_DBG
21#define D(fmt, args...) fprintf(stderr, fmt, ## args)
22#else
23#define D(fmt, args...)
24#endif
25
26#define CAPS "video/x-raw-rgb,bpp=(int)32,depth=(int)32,endianness=(int)4321,red_mask=(int)0x0000ff00, green_mask=(int)0x00ff0000, blue_mask=(int)0xff000000"
27
28static GstElement *pipeline = NULL;
29static GstElement *sink = NULL;
30static gint64 duration = -1;
31
32int width = 0;
33int height = 0;
34void *data = NULL;
35
36
37static Eina_Bool
38_gst_init(const char *filename)
39{
40 GstPad *pad;
41 GstCaps *caps;
42 GstStructure *structure;
43 gchar *descr;
44 gchar *uri;
45 GError *error = NULL;
46 GstFormat format;
47 GstStateChangeReturn ret;
48// int vidstr = 0;
49
50 if (!filename || !*filename)
51 return EINA_FALSE;
52
53 if (!gst_init_check(NULL, NULL, &error))
54 return EINA_FALSE;
55
56 if ((*filename == '/') || (*filename == '~'))
57 {
58 uri = g_filename_to_uri(filename, NULL, NULL);
59 if (!uri)
60 {
61 D("could not create new uri from %s", filename);
62 goto unref_pipeline;
63 }
64 }
65 else
66 uri = strdup(filename);
67
68 D("Setting file %s\n", uri);
69
70 descr = g_strdup_printf("uridecodebin uri=%s ! typefind ! ffmpegcolorspace ! "
71 " appsink name=sink caps=\"" CAPS "\"", uri);
72 pipeline = gst_parse_launch(descr, &error);
73 free(uri);
74
75 if (error != NULL)
76 {
77 D("could not construct pipeline: %s\n", error->message);
78 g_error_free (error);
79 goto gst_shutdown;
80 }
81/* needs gst 1.0+
82 * also only works on playbin objects!!! this is a uridecodebin!
83 g_object_get(G_OBJECT(pipeline),
84 "n-video", &vidstr,
85 NULL);
86 if (vidstr <= 0)
87 {
88 D("no video stream\n");
89 goto gst_shutdown;
90 }
91*/
92 sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
93
94 ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
95 switch (ret)
96 {
97 case GST_STATE_CHANGE_FAILURE:
98 D("failed to play the file\n");
99 goto unref_pipeline;
100 case GST_STATE_CHANGE_NO_PREROLL:
101 D("live sources not supported yet\n");
102 goto unref_pipeline;
103 default:
104 break;
105 }
106
107 ret = gst_element_get_state((pipeline), NULL, NULL, GST_CLOCK_TIME_NONE);
108 if (ret == GST_STATE_CHANGE_FAILURE)
109 {
110 D("could not complete pause\n");
111 goto unref_pipeline;
112 }
113
114 format = GST_FORMAT_TIME;
115 gst_element_query_duration (pipeline, &format, &duration);
116 if (duration == -1)
117 {
118 D("could not retrieve the duration, set it to 1s\n");
119 duration = 1 * GST_SECOND;
120 }
121
122 pad = gst_element_get_static_pad(sink, "sink");
123 if (!pad)
124 {
125 D("could not retrieve the sink pad\n");
126 goto unref_pipeline;
127 }
128
129 caps = gst_pad_get_negotiated_caps(pad);
130 if (!caps)
131 goto unref_pad;
132
133 structure = gst_caps_get_structure(caps, 0);
134
135 if (!gst_structure_get_int(structure, "width", &width))
136 goto unref_caps;
137 if (!gst_structure_get_int(structure, "height", &height))
138 goto unref_caps;
139
140 gst_caps_unref(caps);
141 gst_object_unref(pad);
142
143 return EINA_TRUE;
144
145 unref_caps:
146 gst_caps_unref(caps);
147 unref_pad:
148 gst_object_unref(pad);
149 unref_pipeline:
150 gst_element_set_state (pipeline, GST_STATE_NULL);
151 gst_object_unref(pipeline);
152 gst_shutdown:
153 gst_deinit();
154
155 return EINA_FALSE;
156}
157
158static void
159_gst_shutdown()
160{
161 gst_element_set_state (pipeline, GST_STATE_NULL);
162 gst_object_unref(pipeline);
163 gst_deinit();
164}
165
166static void
167_gst_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED, double pos)
168{
169 GstBuffer *buffer;
170
171 D("load image\n");
172 if (pos >= 0.0)
173 gst_element_seek_simple(pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
174 pos * 1000000000.0);
175 else
176 gst_element_seek_simple(pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
177 duration / 2);
178 g_signal_emit_by_name(sink, "pull-preroll", &buffer, NULL);
179 D("load image : %p %d\n", GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
180
181 shm_alloc(width * height * sizeof(DATA32));
182 if (!shm_addr) return;
183 data = shm_addr;
184
185 memcpy(data, GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
186}
187
188int
189main(int argc, char **argv)
190{
191 char *file, *p;
192 int i, numonly;
193 int size_w = 0, size_h = 0;
194 int head_only = 0;
195 long long pos = -1.0;
196
197 if (argc < 2) return -1;
198 // file is ALWAYS first arg, other options come after
199 file = argv[1];
200 for (i = 2; i < argc; i++)
201 {
202 if (!strcmp(argv[i], "-head"))
203 // asked to only load header, not body/data
204 head_only = 1;
205 else if (!strcmp(argv[i], "-key"))
206 {
207 i++;
208 numonly = 1;
209 for (p = argv[i]; *p; p++)
210 {
211 if ((!*p < '0') || (*p > 9))
212 {
213 numonly = 0;
214 break;
215 }
216 }
217 if (numonly) pos = (double)(atoll(argv[i])) / 1000.0;
218 i++;
219 }
220 else if (!strcmp(argv[i], "-opt-scale-down-by"))
221 { // not used by ps loader
222 i++;
223 // int scale_down = atoi(argv[i]);
224 }
225 else if (!strcmp(argv[i], "-opt-dpi"))
226 {
227 i++;
228 }
229 else if (!strcmp(argv[i], "-opt-size"))
230 { // not used by ps loader
231 i++;
232 size_w = atoi(argv[i]);
233 i++;
234 size_h = atoi(argv[i]);
235 }
236 }
237
238 timeout_init(10);
239
240 D("_gst_init_file\n");
241
242 if (!_gst_init(file))
243 return -1;
244 D("_gst_init done\n");
245
246 if (!head_only)
247 {
248 _gst_load_image(size_w, size_h, pos);
249 }
250
251 D("size...: %ix%i\n", width, height);
252 D("alpha..: 0\n");
253
254 printf("size %i %i\n", width, height);
255 printf("alpha 0\n");
256
257 if (!head_only)
258 {
259 if (shm_fd >= 0)
260 {
261 printf("shmfile %s\n", shmfile);
262 }
263 else
264 {
265 // could also to "tmpfile %s\n" like shmfile but just
266 // a mmaped tmp file on the system
267 printf("data\n");
268 fwrite(data, width * height * sizeof(DATA32), 1, stdout);
269 }
270 shm_free();
271 }
272 else
273 printf("done\n");
274
275 _gst_shutdown();
276 fflush(stdout);
277 return 0;
278}