15
#define DATA32 unsigned int
20
#define D(fmt, args...) fprintf(stderr, fmt, ## args)
22
#define D(fmt, args...)
26
# define CAPS "video/x-raw,format=ARGB"
28
# define CAPS "video/x-raw,format=BGRA"
31
static GstElement *pipeline = NULL;
32
static GstElement *sink = NULL;
33
static gint64 duration = -1;
41
_gst_init(const char *filename)
45
GstStructure *structure;
50
GstStateChangeReturn ret;
53
if (!filename || !*filename)
56
if (!gst_init_check(NULL, NULL, &error))
59
if ((*filename == '/') || (*filename == '~'))
61
uri = g_filename_to_uri(filename, NULL, NULL);
64
D("could not create new uri from %s", filename);
69
uri = strdup(filename);
71
D("Setting file %s\n", uri);
73
descr = g_strdup_printf("uridecodebin uri=%s ! typefind ! videoconvert ! "
74
" appsink name=sink caps=\"" CAPS "\"", uri);
75
pipeline = gst_parse_launch(descr, &error);
80
D("could not construct pipeline: %s\n", error->message);
95
sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
97
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
100
case GST_STATE_CHANGE_FAILURE:
101
D("failed to play the file\n");
103
case GST_STATE_CHANGE_NO_PREROLL:
104
D("live sources not supported yet\n");
110
ret = gst_element_get_state((pipeline), NULL, NULL, GST_CLOCK_TIME_NONE);
111
if (ret == GST_STATE_CHANGE_FAILURE)
113
D("could not complete pause\n");
117
format = GST_FORMAT_TIME;
118
gst_element_query_duration (pipeline, format, &duration);
121
fprintf(stderr, "duration fetch err\n");
122
D("could not retrieve the duration, set it to 1s\n");
123
duration = 1 * GST_SECOND;
126
pad = gst_element_get_static_pad(sink, "sink");
129
D("could not retrieve the sink pad\n");
133
caps = gst_pad_get_current_caps(pad);
137
structure = gst_caps_get_structure(caps, 0);
139
if (!gst_structure_get_int(structure, "width", &width))
141
if (!gst_structure_get_int(structure, "height", &height))
144
gst_caps_unref(caps);
145
gst_object_unref(pad);
150
gst_caps_unref(caps);
152
gst_object_unref(pad);
154
gst_element_set_state (pipeline, GST_STATE_NULL);
155
gst_object_unref(pipeline);
165
gst_element_set_state (pipeline, GST_STATE_NULL);
166
gst_object_unref(pipeline);
171
_gst_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED, double pos)
179
gst_element_seek_simple(pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
182
gst_element_seek_simple(pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
184
g_signal_emit_by_name(sink, "pull-preroll", &sample, NULL);
186
shm_alloc(width * height * sizeof(DATA32));
187
if (!shm_addr) return;
190
buffer = gst_sample_get_buffer (sample);
191
gst_buffer_map (buffer, &info, GST_MAP_READ);
192
D("load image: %p %d\n", info.data, info.size);
194
memcpy(data, info.data, info.size);
196
gst_buffer_unmap(buffer, &info);
200
main(int argc, char **argv)
204
int size_w = 0, size_h = 0;
206
long long pos = -1.0;
208
if (argc < 2) return -1;
211
for (i = 2; i < argc; i++)
213
if (!strcmp(argv[i], "-head"))
216
else if (!strcmp(argv[i], "-key"))
220
for (p = argv[i]; *p; p++)
222
if ((*p < '0') || (*p > '9'))
228
if (numonly) pos = atoll(argv[i]) * 1000000;
231
else if (!strcmp(argv[i], "-opt-scale-down-by"))
236
else if (!strcmp(argv[i], "-opt-dpi"))
240
else if (!strcmp(argv[i], "-opt-size"))
243
size_w = atoi(argv[i]);
245
size_h = atoi(argv[i]);
251
D("_gst_init_file\n");
253
if (!_gst_init(file))
255
D("_gst_init done\n");
257
if ((pos >= 0) && (pos > duration)) return -1;
261
_gst_load_image(size_w, size_h, pos);
264
D("size...: %ix%i\n", width, height);
267
printf("size %i %i\n", width, height);
278
printf("shmfile %s\n", shmfile);
285
if (fwrite(data, width * height * sizeof(DATA32), 1, stdout) != 1)