1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8
9 #include <Evas.h>
10 #include <Ecore.h>
11 #include <Ecore_Getopt.h>
12 #include <Ecore_Evas.h>
13 #include <Edje.h>
14
15 #include "Emotion.h"
16
17 static const Ecore_Getopt options = {
18 "emotion_test",
19 "%prog [options] <filename>",
20 "1.0.0",
21 "(C) 2011-2014 Enlightenment",
22 "BSD\nThis is a 3 clause bsd bla bla",
23 "a simple test program for emotion.",
24 1,
25 {
26 ECORE_GETOPT_STORE_STR('e', "engine", "ecore-evas engine to use"),
27 ECORE_GETOPT_CALLBACK_NOARGS('E', "list-engines", "list ecore-evas engines",
28 ecore_getopt_callback_ecore_evas_list_engines, NULL),
29 ECORE_GETOPT_CALLBACK_ARGS('g', "geometry", "geometry to use in x:y:w:h form.", "X:Y:W:H",
30 ecore_getopt_callback_geometry_parse, NULL),
31 ECORE_GETOPT_STORE_STR('b', "backend", "backend to use"),
32 ECORE_GETOPT_STORE_INT('v', "vis", "visualization type"),
33 ECORE_GETOPT_STORE_TRUE('w', "webcams", "show all the available v4l streams"),
34 ECORE_GETOPT_STORE_TRUE('r', "reflex", "show video reflex effect"),
35 ECORE_GETOPT_STORE_TRUE('l', "loop", "restart the video when end reached"),
36 ECORE_GETOPT_STORE_TRUE('p', "position", "start the video from last know position"),
37 ECORE_GETOPT_VERSION('V', "version"),
38 ECORE_GETOPT_COPYRIGHT('R', "copyright"),
39 ECORE_GETOPT_LICENSE('L', "license"),
40 ECORE_GETOPT_HELP('h', "help"),
41 ECORE_GETOPT_SENTINEL
42 }
43 };
44
45 typedef struct _Frame_Data Frame_Data;
46
47 struct _Frame_Data
48 {
49 unsigned char moving : 1;
50 unsigned char resizing : 1;
51 int button;
52 Evas_Coord x, y;
53 };
54
55 static void main_resize(Ecore_Evas *ee);
56 static Eina_Bool main_signal_exit(void *data, int ev_type, void *ev);
57 static void main_delete_request(Ecore_Evas *ee);
58
59 static void bg_setup(void);
60 static void bg_resize(Evas_Coord w, Evas_Coord h);
61 static void bg_key_down(void *data, Evas * e, Evas_Object * obj, void *event_info);
62
63 static Evas_Object *o_bg = NULL;
64
65 static Ecore_Evas *ecore_evas = NULL;
66 static Evas *evas = NULL;
67 static int startw = 800;
68 static int starth = 600;
69
70 static Eina_List *video_objs = NULL;
71 static Emotion_Vis vis = EMOTION_VIS_NONE;
72 static unsigned char reflex = 0;
73 static unsigned char loop = 0;
74 static unsigned char last_position_load = 0;
75 static const char *theme_file = NULL;
76
77 static void
main_resize(Ecore_Evas * ee)78 main_resize(Ecore_Evas *ee)
79 {
80 Evas_Coord w, h;
81
82 evas_output_viewport_get(ecore_evas_get(ee), NULL, NULL, &w, &h);
83 bg_resize(w, h);
84 }
85
86 static Eina_Bool
main_signal_exit(void * data EINA_UNUSED,int ev_type EINA_UNUSED,void * ev EINA_UNUSED)87 main_signal_exit(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
88 {
89 Evas_Object *o;
90
91 ecore_main_loop_quit();
92 EINA_LIST_FREE(video_objs, o)
93 {
94 emotion_object_last_position_save(o);
95 evas_object_del(o);
96 }
97 return EINA_TRUE;
98 }
99
100 static void
main_delete_request(Ecore_Evas * ee EINA_UNUSED)101 main_delete_request(Ecore_Evas *ee EINA_UNUSED)
102 {
103 ecore_main_loop_quit();
104 }
105
106 void
bg_setup(void)107 bg_setup(void)
108 {
109 Evas_Object *o;
110
111 o = edje_object_add(evas);
112 edje_object_file_set(o, theme_file, "background");
113 evas_object_move(o, 0, 0);
114 evas_object_resize(o, startw, starth);
115 evas_object_layer_set(o, -999);
116 evas_object_show(o);
117 evas_object_focus_set(o, 1);
118 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, bg_key_down, NULL);
119 o_bg = o;
120 }
121
122 void
bg_resize(Evas_Coord w,Evas_Coord h)123 bg_resize(Evas_Coord w, Evas_Coord h)
124 {
125 evas_object_resize(o_bg, w, h);
126 }
127
128 static void
broadcast_event(Emotion_Event ev)129 broadcast_event(Emotion_Event ev)
130 {
131 Eina_List *l;
132 Evas_Object *obj;
133
134 EINA_LIST_FOREACH(video_objs, l, obj)
135 emotion_object_event_simple_send(obj, ev);
136 }
137
138 static void
bg_key_down(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)139 bg_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
140 {
141 Evas_Event_Key_Down *ev = event_info;
142 Eina_List *l;
143 Evas_Object *o;
144
145 if (!strcmp(ev->keyname, "Escape"))
146 ecore_main_loop_quit();
147 else if (!strcmp(ev->keyname, "Up"))
148 broadcast_event(EMOTION_EVENT_UP);
149 else if (!strcmp(ev->keyname, "Down"))
150 broadcast_event(EMOTION_EVENT_DOWN);
151 else if (!strcmp(ev->keyname, "Left"))
152 broadcast_event(EMOTION_EVENT_LEFT);
153 else if (!strcmp(ev->keyname, "Right"))
154 broadcast_event(EMOTION_EVENT_RIGHT);
155 else if (!strcmp(ev->keyname, "Return"))
156 broadcast_event(EMOTION_EVENT_SELECT);
157 else if (!strcmp(ev->keyname, "m"))
158 broadcast_event(EMOTION_EVENT_MENU1);
159 else if (!strcmp(ev->keyname, "Prior"))
160 broadcast_event(EMOTION_EVENT_PREV);
161 else if (!strcmp(ev->keyname, "Next"))
162 broadcast_event(EMOTION_EVENT_NEXT);
163 else if (!strcmp(ev->keyname, "0"))
164 broadcast_event(EMOTION_EVENT_0);
165 else if (!strcmp(ev->keyname, "1"))
166 broadcast_event(EMOTION_EVENT_1);
167 else if (!strcmp(ev->keyname, "2"))
168 broadcast_event(EMOTION_EVENT_2);
169 else if (!strcmp(ev->keyname, "3"))
170 broadcast_event(EMOTION_EVENT_3);
171 else if (!strcmp(ev->keyname, "4"))
172 broadcast_event(EMOTION_EVENT_4);
173 else if (!strcmp(ev->keyname, "5"))
174 broadcast_event(EMOTION_EVENT_5);
175 else if (!strcmp(ev->keyname, "6"))
176 broadcast_event(EMOTION_EVENT_6);
177 else if (!strcmp(ev->keyname, "7"))
178 broadcast_event(EMOTION_EVENT_7);
179 else if (!strcmp(ev->keyname, "8"))
180 broadcast_event(EMOTION_EVENT_8);
181 else if (!strcmp(ev->keyname, "9"))
182 broadcast_event(EMOTION_EVENT_9);
183 else if (!strcmp(ev->keyname, "-"))
184 broadcast_event(EMOTION_EVENT_10);
185 else if (!strcmp(ev->keyname, "v"))
186 {
187 EINA_LIST_FOREACH(video_objs, l, o)
188 {
189 if (emotion_object_video_mute_get(o))
190 emotion_object_video_mute_set(o, 0);
191 else
192 emotion_object_video_mute_set(o, 1);
193 }
194 }
195 else if (!strcmp(ev->keyname, "a"))
196 {
197 EINA_LIST_FOREACH(video_objs, l, o)
198 {
199 if (emotion_object_audio_mute_get(o))
200 {
201 emotion_object_audio_mute_set(o, 0);
202 printf("unmute\n");
203 }
204 else
205 {
206 emotion_object_audio_mute_set(o, 1);
207 printf("mute\n");
208 }
209 }
210 }
211 else if (!strcmp(ev->keyname, "i"))
212 {
213 EINA_LIST_FOREACH(video_objs, l, o)
214 {
215 printf("audio channels: %i\n", emotion_object_audio_channel_count(o));
216 printf("video channels: %i\n", emotion_object_video_channel_count(o));
217 printf("spu channels: %i\n", emotion_object_spu_channel_count(o));
218 printf("seekable: %i\n", emotion_object_seekable_get(o));
219 }
220 }
221 else if (!strcmp(ev->keyname, "f"))
222 {
223 if (!ecore_evas_fullscreen_get(ecore_evas))
224 ecore_evas_fullscreen_set(ecore_evas, 1);
225 else
226 ecore_evas_fullscreen_set(ecore_evas, 0);
227 }
228 else if (!strcmp(ev->keyname, "d"))
229 {
230 if (!ecore_evas_avoid_damage_get(ecore_evas))
231 ecore_evas_avoid_damage_set(ecore_evas, 1);
232 else
233 ecore_evas_avoid_damage_set(ecore_evas, 0);
234 }
235 else if (!strcmp(ev->keyname, "s"))
236 {
237 if (!ecore_evas_shaped_get(ecore_evas))
238 {
239 ecore_evas_shaped_set(ecore_evas, 1);
240 evas_object_hide(o_bg);
241 }
242 else
243 {
244 ecore_evas_shaped_set(ecore_evas, 0);
245 evas_object_show(o_bg);
246 }
247 }
248 else if (!strcmp(ev->keyname, "b"))
249 {
250 if (!ecore_evas_borderless_get(ecore_evas))
251 ecore_evas_borderless_set(ecore_evas, 1);
252 else
253 ecore_evas_borderless_set(ecore_evas, 0);
254 }
255 else if (!strcmp(ev->keyname, "q"))
256 {
257 ecore_main_loop_quit();
258 while (video_objs)
259 {
260 printf("del obj!\n");
261 evas_object_del(video_objs->data);
262 video_objs = eina_list_remove_list(video_objs, video_objs);
263 printf("done\n");
264 }
265 }
266 else if (!strcmp(ev->keyname, "z"))
267 {
268 vis = (vis + 1) % EMOTION_VIS_LAST;
269 printf("new visualization: %d\n", vis);
270
271 EINA_LIST_FOREACH(video_objs, l, o)
272 {
273 Eina_Bool supported;
274
275 supported = emotion_object_vis_supported(o, vis);
276 if (supported)
277 emotion_object_vis_set(o, vis);
278 else
279 {
280 const char *file;
281
282 file = emotion_object_file_get(o);
283 printf("object %p (%s) does not support visualization %d\n",
284 o, file, vis);
285 }
286 }
287 }
288 else
289 {
290 printf("UNHANDLED: %s\n", ev->keyname);
291 }
292 }
293
294 static void
_oe_free_cb(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)295 _oe_free_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
296 void *event_info EINA_UNUSED)
297 {
298 free(data);
299 }
300
301 static void
video_obj_time_changed(Evas_Object * obj,Evas_Object * edje)302 video_obj_time_changed(Evas_Object *obj, Evas_Object *edje)
303 {
304 double pos, len, scale;
305 char buf[256];
306 int ph, pm, ps, pf, lh, lm, ls;
307
308 pos = emotion_object_position_get(obj);
309 len = emotion_object_play_length_get(obj);
310 scale = (len > 0.0) ? pos / len : 0.0;
311 edje_object_part_drag_value_set(edje, "video_progress", scale, 0.0);
312
313 lh = len / 3600;
314 lm = len / 60 - (lh * 60);
315 ls = len - (lh * 3600) - (lm * 60);
316
317 ph = pos / 3600;
318 pm = pos / 60 - (ph * 60);
319 ps = pos - (ph * 3600) - (pm * 60);
320
321 pf = pos * 100 - (ps * 100) - (pm * 60 * 100) - (ph * 60 * 60 * 100);
322
323 snprintf(buf, sizeof(buf), "%i:%02i:%02i.%02i / %i:%02i:%02i",
324 ph, pm, ps, pf, lh, lm, ls);
325 edje_object_part_text_set(edje, "video_progress_txt", buf);
326 }
327
328 static void
video_obj_frame_decode_cb(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)329 video_obj_frame_decode_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
330 {
331 video_obj_time_changed(obj, data);
332
333 if (0)
334 {
335 double t;
336 static double pt = 0.0;
337 t = ecore_time_get();
338 printf("FPS: %3.3f\n", 1.0 / (t - pt));
339 pt = t;
340 }
341 }
342
343 static void
video_obj_frame_resize_cb(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)344 video_obj_frame_resize_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
345 {
346 Evas_Object *oe;
347 int iw, ih;
348 Evas_Coord w, h;
349 double ratio;
350
351 oe = data;
352 emotion_object_size_get(obj, &iw, &ih);
353 ratio = emotion_object_ratio_get(obj);
354 printf("HANDLE %ix%i @ %3.3f\n", iw, ih, ratio);
355 if (ratio > 0.0) iw = (ih * ratio) + 0.5;
356 evas_object_size_hint_min_set(obj, iw, ih);
357 edje_object_part_swallow(oe, "video_swallow", obj);
358 edje_object_size_min_calc(oe, &w, &h);
359 evas_object_resize(oe, w, h);
360 evas_object_size_hint_min_set(obj, 0, 0);
361 edje_object_part_swallow(oe, "video_swallow", obj);
362 }
363
364 static void
video_obj_length_change_cb(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)365 video_obj_length_change_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
366 {
367 printf("len change!\n");
368 video_obj_time_changed(obj, data);
369 }
370
371 static void
video_obj_position_update_cb(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)372 video_obj_position_update_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
373 {
374 printf("pos up!\n");
375 video_obj_time_changed(obj, data);
376 }
377
378 static void
video_obj_stopped_cb(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)379 video_obj_stopped_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
380 {
381 printf("video stopped!!!\n");
382 if (loop)
383 {
384 emotion_object_position_set(obj, 0.0);
385 emotion_object_play_set(obj, 1);
386 }
387 }
388
389 static void
video_obj_channels_cb(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)390 video_obj_channels_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
391 {
392 printf("channels changed: [AUD %i][VID %i][SPU %i]\n",
393 emotion_object_audio_channel_count(obj),
394 emotion_object_video_channel_count(obj),
395 emotion_object_spu_channel_count(obj));
396 }
397
398 static void
video_obj_title_cb(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)399 video_obj_title_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
400 {
401 printf("video title to: \"%s\"\n", emotion_object_title_get(obj));
402 }
403
404 static void
video_obj_progress_cb(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)405 video_obj_progress_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
406 {
407 printf("progress: \"%s\" %3.3f\n",
408 emotion_object_progress_info_get(obj),
409 emotion_object_progress_status_get(obj));
410 }
411
412 static void
video_obj_ref_cb(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)413 video_obj_ref_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
414 {
415 printf("video ref to: \"%s\" %i\n",
416 emotion_object_ref_file_get(obj),
417 emotion_object_ref_num_get(obj));
418 }
419
420 static void
video_obj_button_num_cb(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)421 video_obj_button_num_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
422 {
423 printf("video spu buttons to: %i\n",
424 emotion_object_spu_button_count_get(obj));
425 }
426
427 static void
video_obj_button_cb(void * data EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)428 video_obj_button_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
429 {
430 printf("video selected spu button: %i\n",
431 emotion_object_spu_button_get(obj));
432 }
433
434
435 static void
video_obj_signal_play_cb(void * data,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)436 video_obj_signal_play_cb(void *data, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
437 {
438 Evas_Object *ov = data;
439 emotion_object_play_set(ov, 1);
440 edje_object_signal_emit(o, "video_state", "play");
441 }
442
443 static void
video_obj_signal_pause_cb(void * data,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)444 video_obj_signal_pause_cb(void *data, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
445 {
446 Evas_Object *ov = data;
447 emotion_object_play_set(ov, 0);
448 edje_object_signal_emit(o, "video_state", "pause");
449 }
450
451 static void
video_obj_signal_stop_cb(void * data,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)452 video_obj_signal_stop_cb(void *data, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
453 {
454 Evas_Object *ov = data;
455 emotion_object_play_set(ov, 0);
456 emotion_object_position_set(ov, 0);
457 edje_object_signal_emit(o, "video_state", "stop");
458 }
459
460 static void
video_obj_signal_jump_cb(void * data,Evas_Object * o,const char * emission EINA_UNUSED,const char * source)461 video_obj_signal_jump_cb(void *data, Evas_Object *o, const char *emission EINA_UNUSED, const char *source)
462 {
463 Evas_Object *ov = data;
464 double len;
465 double x, y;
466
467 edje_object_part_drag_value_get(o, source, &x, &y);
468 len = emotion_object_play_length_get(ov);
469 emotion_object_position_set(ov, x * len);
470 }
471
472 static void
video_obj_signal_alpha_cb(void * data,Evas_Object * o,const char * emission EINA_UNUSED,const char * source)473 video_obj_signal_alpha_cb(void *data, Evas_Object *o, const char *emission EINA_UNUSED, const char *source)
474 {
475 Evas_Object *ov = data;
476 double alpha;
477 double x, y;
478 char buf[256];
479
480 edje_object_part_drag_value_get(o, source, &x, &y);
481 alpha = 255 * y;
482 evas_object_color_set(ov, alpha, alpha, alpha, alpha);
483 snprintf(buf, sizeof(buf), "alpha %.0f", alpha);
484 edje_object_part_text_set(o, "video_alpha_txt", buf);
485 }
486
487 static void
video_obj_signal_vol_cb(void * data,Evas_Object * o,const char * emission EINA_UNUSED,const char * source)488 video_obj_signal_vol_cb(void *data, Evas_Object *o, const char *emission EINA_UNUSED, const char *source)
489 {
490 Evas_Object *ov = data;
491 double vol;
492 char buf[256];
493
494 edje_object_part_drag_value_get(o, source, NULL, &vol);
495 emotion_object_audio_volume_set(ov, vol);
496 snprintf(buf, sizeof(buf), "vol %.2f", vol);
497 edje_object_part_text_set(o, "video_volume_txt", buf);
498 }
499
500 static void
video_obj_signal_frame_move_start_cb(void * data EINA_UNUSED,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)501 video_obj_signal_frame_move_start_cb(void *data EINA_UNUSED, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
502 {
503 Frame_Data *fd;
504 Evas_Coord x, y;
505
506 fd = evas_object_data_get(o, "frame_data");
507 if (!fd) return;
508 fd->moving = 1;
509 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
510 fd->x = x;
511 fd->y = y;
512 evas_object_raise(o);
513 }
514
515 static void
video_obj_signal_frame_move_stop_cb(void * data EINA_UNUSED,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)516 video_obj_signal_frame_move_stop_cb(void *data EINA_UNUSED, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
517 {
518 Frame_Data *fd;
519
520 fd = evas_object_data_get(o, "frame_data");
521 if (!fd) return;
522 fd->moving = 0;
523 }
524
525 static void
video_obj_signal_frame_resize_start_cb(void * data EINA_UNUSED,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)526 video_obj_signal_frame_resize_start_cb(void *data EINA_UNUSED, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
527 {
528 Frame_Data *fd;
529 Evas_Coord x, y;
530
531 fd = evas_object_data_get(o, "frame_data");
532 if (!fd) return;
533 fd->resizing = 1;
534 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
535 fd->x = x;
536 fd->y = y;
537 evas_object_raise(o);
538 }
539
540 static void
video_obj_signal_frame_resize_stop_cb(void * data EINA_UNUSED,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)541 video_obj_signal_frame_resize_stop_cb(void *data EINA_UNUSED, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
542 {
543 Frame_Data *fd;
544
545 fd = evas_object_data_get(o, "frame_data");
546 if (!fd) return;
547 fd->resizing = 0;
548 }
549
550 static void
video_obj_signal_frame_move_cb(void * data EINA_UNUSED,Evas_Object * o,const char * emission EINA_UNUSED,const char * source EINA_UNUSED)551 video_obj_signal_frame_move_cb(void *data EINA_UNUSED, Evas_Object *o, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
552 {
553 Frame_Data *fd;
554
555 fd = evas_object_data_get(o, "frame_data");
556 if (!fd) return;
557 if (fd->moving)
558 {
559 Evas_Coord x, y, ox, oy;
560
561 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
562 evas_object_geometry_get(o, &ox, &oy, NULL, NULL);
563 evas_object_move(o, ox + (x - fd->x), oy + (y - fd->y));
564 fd->x = x;
565 fd->y = y;
566 }
567 else if (fd->resizing)
568 {
569 Evas_Coord x, y, ow, oh;
570
571 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
572 evas_object_geometry_get(o, NULL, NULL, &ow, &oh);
573 evas_object_resize(o, ow + (x - fd->x), oh + (y - fd->y));
574 fd->x = x;
575 fd->y = y;
576 }
577 }
578
579
580 static void
init_video_object(const char * module_filename,const char * filename)581 init_video_object(const char *module_filename, const char *filename)
582 {
583 Evas_Object *o, *oe;
584 Evas_Coord w, h, offset;
585 Frame_Data *fd;
586
587 /* basic video object setup */
588 o = emotion_object_add(evas);
589 if ((module_filename) && (!emotion_object_init(o, module_filename)))
590 return;
591 emotion_object_vis_set(o, vis);
592 if (!emotion_object_file_set(o, filename))
593 return;
594 if (last_position_load)
595 emotion_object_last_position_load(o);
596 emotion_object_play_set(o, 1);
597 emotion_object_audio_volume_set(o, 0.5);
598 evas_object_move(o, 0, 0);
599 evas_object_resize(o, 320, 240);
600 emotion_object_smooth_scale_set(o, 1);
601 evas_object_show(o);
602
603 video_objs = eina_list_append(video_objs, o);
604 /* end basic video setup. all the rest here is just to be fancy */
605
606
607 fd = calloc(1, sizeof(Frame_Data));
608 if (!fd) exit(1);
609
610 oe = edje_object_add(evas);
611 evas_object_event_callback_add(oe, EVAS_CALLBACK_FREE, _oe_free_cb, fd);
612 evas_object_data_set(oe, "frame_data", fd);
613 if (reflex)
614 edje_object_file_set(oe, theme_file, "video_controller/reflex");
615 else
616 edje_object_file_set(oe, theme_file, "video_controller");
617 edje_object_part_swallow(oe, "video_swallow", o);
618
619 offset = 20 * (eina_list_count(video_objs) - 1);
620 evas_object_move(oe, offset, offset);
621 edje_object_size_min_calc(oe, &w, &h);
622 evas_object_resize(oe, w, h);
623
624 evas_object_smart_callback_add(o, "frame_decode", video_obj_frame_decode_cb, oe);
625 evas_object_smart_callback_add(o, "frame_resize", video_obj_frame_resize_cb, oe);
626 evas_object_smart_callback_add(o, "length_change", video_obj_length_change_cb, oe);
627 evas_object_smart_callback_add(o, "position_update", video_obj_position_update_cb, oe);
628
629 evas_object_smart_callback_add(o, "decode_stop", video_obj_stopped_cb, oe);
630 evas_object_smart_callback_add(o, "channels_change", video_obj_channels_cb, oe);
631 evas_object_smart_callback_add(o, "title_change", video_obj_title_cb, oe);
632 evas_object_smart_callback_add(o, "progress_change", video_obj_progress_cb, oe);
633 evas_object_smart_callback_add(o, "ref_change", video_obj_ref_cb, oe);
634 evas_object_smart_callback_add(o, "button_num_change", video_obj_button_num_cb, oe);
635 evas_object_smart_callback_add(o, "button_change", video_obj_button_cb, oe);
636
637 edje_object_signal_callback_add(oe, "video_control", "play", video_obj_signal_play_cb, o);
638 edje_object_signal_callback_add(oe, "video_control", "pause", video_obj_signal_pause_cb, o);
639 edje_object_signal_callback_add(oe, "video_control", "stop", video_obj_signal_stop_cb, o);
640 edje_object_signal_callback_add(oe, "drag", "video_progress", video_obj_signal_jump_cb, o);
641 edje_object_signal_callback_add(oe, "drag", "video_alpha", video_obj_signal_alpha_cb, o);
642 edje_object_signal_callback_add(oe, "drag", "video_volume", video_obj_signal_vol_cb, o);
643
644 edje_object_signal_callback_add(oe, "frame_move", "start", video_obj_signal_frame_move_start_cb, oe);
645 edje_object_signal_callback_add(oe, "frame_move", "stop", video_obj_signal_frame_move_stop_cb, oe);
646 edje_object_signal_callback_add(oe, "frame_resize", "start", video_obj_signal_frame_resize_start_cb, oe);
647 edje_object_signal_callback_add(oe, "frame_resize", "stop", video_obj_signal_frame_resize_stop_cb, oe);
648 edje_object_signal_callback_add(oe, "mouse,move", "*", video_obj_signal_frame_move_cb, oe);
649
650 edje_object_part_drag_value_set(oe, "video_alpha", 0.0, 1.0);
651 edje_object_part_text_set(oe, "video_alpha_txt", "alpha 255");
652
653 edje_object_part_drag_value_set(oe, "video_volume", 0.0, 0.5);
654 edje_object_part_text_set(oe, "video_volume_txt", "vol 0.50");
655
656 edje_object_signal_emit(oe, "video_state", "play");
657
658 evas_object_show(oe);
659 }
660
661 int
main(int argc,char ** argv)662 main(int argc, char **argv)
663 {
664 int args;
665 Eina_Rectangle geometry = {0, 0, startw, starth};
666 char *engine = NULL;
667 char *backend = NULL;
668 Eina_Bool webcams = EINA_FALSE;
669 int visual = EMOTION_VIS_NONE;
670 unsigned char help = 0;
671 unsigned char engines_listed = 0;
672 Ecore_Getopt_Value values[] = {
673 ECORE_GETOPT_VALUE_STR(engine),
674 ECORE_GETOPT_VALUE_BOOL(engines_listed),
675 ECORE_GETOPT_VALUE_PTR_CAST(geometry),
676 ECORE_GETOPT_VALUE_STR(backend),
677 ECORE_GETOPT_VALUE_INT(visual),
678 ECORE_GETOPT_VALUE_BOOL(webcams),
679 ECORE_GETOPT_VALUE_BOOL(reflex),
680 ECORE_GETOPT_VALUE_BOOL(loop),
681 ECORE_GETOPT_VALUE_BOOL(last_position_load),
682 ECORE_GETOPT_VALUE_NONE,
683 ECORE_GETOPT_VALUE_NONE,
684 ECORE_GETOPT_VALUE_NONE,
685 ECORE_GETOPT_VALUE_BOOL(help),
686 ECORE_GETOPT_VALUE_NONE
687 };
688
689 // init ecore_evas
690 if (!ecore_evas_init())
691 return -1;
692
693 // init edje
694 if (!edje_init())
695 goto shutdown_ecore_evas;
696
697 // search the theme file
698 struct stat st;
699 if (stat(PACKAGE_BUILD_DIR"/src/tests/emotion/data/theme.edj", &st) == 0)
700 theme_file = PACKAGE_BUILD_DIR"/src/tests/emotion/data/theme.edj";
701 else if (stat(PACKAGE_DATA_DIR"/data/theme.edj", &st) == 0)
702 theme_file = PACKAGE_DATA_DIR"/data/theme.edj";
703 else
704 {
705 printf("Cannot find the theme file\n");
706 goto shutdown_edje;
707 }
708 printf("theme file: %s\n", theme_file);
709
710 // parse command line arguments
711 ecore_app_args_set(argc, (const char **)argv);
712 args = ecore_getopt_parse(&options, values, argc, argv);
713 if (args < 0) goto shutdown_edje;
714 else if (help) goto shutdown_edje;
715 else if (engines_listed) goto shutdown_edje;
716 else if ((args == argc) && (!webcams))
717 {
718 printf("must provide at least one file to play!\n");
719 goto shutdown_edje;
720 }
721 if (geometry.w == 0) geometry.w = 320;
722 if (geometry.h == 0) geometry.h = 240;
723 vis = visual;
724
725 printf("evas engine: %s\n", engine ? engine : "<auto>");
726 printf("emotion backend: %s\n", backend ? backend : "<auto>");
727 printf("vis: %d\n", vis);
728 printf("geometry: %d %d %dx%d\n", geometry.x, geometry.y, geometry.w, geometry.h);
729
730 ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, main_signal_exit, NULL);
731
732 // create the ecore_evas window
733 ecore_evas = ecore_evas_new(engine, geometry.x, geometry.y,
734 geometry.w, geometry.h, NULL);
735 if (!ecore_evas) goto shutdown_edje;
736 ecore_evas_callback_delete_request_set(ecore_evas, main_delete_request);
737 ecore_evas_callback_resize_set(ecore_evas, main_resize);
738 ecore_evas_title_set(ecore_evas, "Evas Media Test Program");
739 ecore_evas_name_class_set(ecore_evas, "evas_media_test", "main");
740 ecore_evas_show(ecore_evas);
741 evas = ecore_evas_get(ecore_evas);
742 evas_image_cache_set(evas, 8 * 1024 * 1024);
743 evas_font_cache_set(evas, 1 * 1024 * 1024);
744
745 // init emotion
746 emotion_init();
747
748 // create the checkboard background edje object
749 bg_setup();
750
751 // open files and webcams
752 for (; args < argc; args++)
753 init_video_object(backend, argv[args]);
754
755 if (webcams)
756 {
757 const Eina_List *wl, *l;
758 Emotion_Webcam *webcam;
759
760 wl = emotion_webcams_get();
761 EINA_LIST_FOREACH(wl, l, webcam)
762 {
763 printf("Playing stream: '%s' url: '%s'\n",
764 emotion_webcam_name_get(webcam),
765 emotion_webcam_device_get(webcam));
766 init_video_object(backend, emotion_webcam_device_get(webcam));
767 }
768 }
769
770 // start the main loop
771 ecore_main_loop_begin();
772
773 // shutdown
774 main_signal_exit(NULL, 0, NULL);
775
776 emotion_shutdown();
777 ecore_evas_free(ecore_evas);
778 ecore_evas_shutdown();
779 edje_shutdown();
780
781 return 0;
782
783 shutdown_edje:
784 edje_shutdown();
785 shutdown_ecore_evas:
786 ecore_evas_shutdown();
787
788 return -1;
789 }
790