8 #include <Ecore_Evas.h>
19 typedef struct _Frame_Data Frame_Data;
29 static int main_start(int argc, char **argv);
30 static void main_stop(void);
31 static void main_resize(Ecore_Evas *ee);
32 static int main_signal_exit(void *data, int ev_type, void *ev);
33 static void main_delete_request(Ecore_Evas *ee);
36 void bg_resize(Evas_Coord w, Evas_Coord h);
37 static void bg_key_down(void *data, Evas * e, Evas_Object * obj, void *event_info);
39 static Evas_Object *o_bg = NULL;
41 double start_time = 0.0;
42 Ecore_Evas *ecore_evas = NULL;
47 Evas_List *video_objs = NULL;
50 main_start(int argc, char **argv)
54 start_time = ecore_time_get();
55 if (!ecore_init()) return -1;
56 ecore_app_args_set(argc, (const char **)argv);
57 ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, main_signal_exit, NULL);
58 if (!ecore_evas_init()) return -1;
63 for (i = 1; i < argc; i++)
65 if (((!strcmp(argv[i], "-g")) ||
66 (!strcmp(argv[i], "-geometry")) ||
67 (!strcmp(argv[i], "--geometry"))) && (i < (argc - 1)))
70 char buf[16], buf2[16];
72 n = sscanf(argv[i +1], "%10[^x]x%10s", buf, buf2);
82 else if (!strcmp(argv[i], "-gl"))
86 else if (!strcmp(argv[i], "-fb"))
94 ecore_evas = ecore_evas_software_x11_new(NULL, 0, 0, 0, startw, starth);
96 #if HAVE_ECORE_EVAS_GL
98 ecore_evas = ecore_evas_gl_x11_new(NULL, 0, 0, 0, startw, starth);
100 #if HAVE_ECORE_EVAS_FB
102 ecore_evas = ecore_evas_fb_new(NULL, 0, startw, starth);
108 ecore_evas = ecore_evas_fb_new(NULL, 270, startw, starth);
110 if (!ecore_evas) return -1;
111 ecore_evas_callback_delete_request_set(ecore_evas, main_delete_request);
112 ecore_evas_callback_resize_set(ecore_evas, main_resize);
113 ecore_evas_title_set(ecore_evas, "Evas Media Test Program");
114 ecore_evas_name_class_set(ecore_evas, "evas_media_test", "main");
115 ecore_evas_show(ecore_evas);
116 evas = ecore_evas_get(ecore_evas);
117 evas_image_cache_set(evas, 8 * 1024 * 1024);
118 evas_font_cache_set(evas, 1 * 1024 * 1024);
119 evas_font_path_append(evas, PACKAGE_DATA_DIR"/data/fonts");
122 edje_frametime_set(1.0 / 30.0);
129 ecore_evas_shutdown();
134 main_resize(Ecore_Evas *ee)
138 evas_output_viewport_get(evas, NULL, NULL, &w, &h);
143 main_signal_exit(void *data, int ev_type, void *ev)
145 ecore_main_loop_quit();
148 printf("del obj!\n");
149 evas_object_del(video_objs->data);
150 video_objs = evas_list_remove_list(video_objs, video_objs);
157 main_delete_request(Ecore_Evas *ee)
159 ecore_main_loop_quit();
167 o = edje_object_add(evas);
168 edje_object_file_set(o, PACKAGE_DATA_DIR"/data/theme.edj", "background");
169 evas_object_move(o, 0, 0);
170 evas_object_resize(o, startw, starth);
171 evas_object_layer_set(o, -999);
173 evas_object_focus_set(o, 1);
174 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN, bg_key_down, NULL);
179 bg_resize(Evas_Coord w, Evas_Coord h)
181 evas_object_resize(o_bg, w, h);
185 broadcast_event(Emotion_Event ev)
189 for (l = video_objs; l; l = l->next)
194 emotion_object_event_simple_send(obj, ev);
199 bg_key_down(void *data, Evas * e, Evas_Object * obj, void *event_info)
201 Evas_Event_Key_Down *ev;
203 ev = (Evas_Event_Key_Down *)event_info;
204 if (!strcmp(ev->keyname, "Escape"))
205 ecore_main_loop_quit();
206 else if (!strcmp(ev->keyname, "Up"))
207 broadcast_event(EMOTION_EVENT_UP);
208 else if (!strcmp(ev->keyname, "Down"))
209 broadcast_event(EMOTION_EVENT_DOWN);
210 else if (!strcmp(ev->keyname, "Left"))
211 broadcast_event(EMOTION_EVENT_LEFT);
212 else if (!strcmp(ev->keyname, "Right"))
213 broadcast_event(EMOTION_EVENT_RIGHT);
214 else if (!strcmp(ev->keyname, "Return"))
215 broadcast_event(EMOTION_EVENT_SELECT);
216 else if (!strcmp(ev->keyname, "m"))
217 broadcast_event(EMOTION_EVENT_MENU1);
218 else if (!strcmp(ev->keyname, "Prior"))
219 broadcast_event(EMOTION_EVENT_PREV);
220 else if (!strcmp(ev->keyname, "Next"))
221 broadcast_event(EMOTION_EVENT_NEXT);
222 else if (!strcmp(ev->keyname, "0"))
223 broadcast_event(EMOTION_EVENT_0);
224 else if (!strcmp(ev->keyname, "1"))
225 broadcast_event(EMOTION_EVENT_1);
226 else if (!strcmp(ev->keyname, "2"))
227 broadcast_event(EMOTION_EVENT_2);
228 else if (!strcmp(ev->keyname, "3"))
229 broadcast_event(EMOTION_EVENT_3);
230 else if (!strcmp(ev->keyname, "4"))
231 broadcast_event(EMOTION_EVENT_4);
232 else if (!strcmp(ev->keyname, "5"))
233 broadcast_event(EMOTION_EVENT_5);
234 else if (!strcmp(ev->keyname, "6"))
235 broadcast_event(EMOTION_EVENT_6);
236 else if (!strcmp(ev->keyname, "7"))
237 broadcast_event(EMOTION_EVENT_7);
238 else if (!strcmp(ev->keyname, "8"))
239 broadcast_event(EMOTION_EVENT_8);
240 else if (!strcmp(ev->keyname, "9"))
241 broadcast_event(EMOTION_EVENT_9);
242 else if (!strcmp(ev->keyname, "-"))
243 broadcast_event(EMOTION_EVENT_10);
244 else if (!strcmp(ev->keyname, "bracketleft"))
248 for (l = video_objs; l; l = l->next)
253 emotion_object_audio_volume_set(obj, emotion_object_audio_volume_get(obj) - 0.1);
256 else if (!strcmp(ev->keyname, "bracketright"))
260 for (l = video_objs; l; l = l->next)
265 emotion_object_audio_volume_set(obj, emotion_object_audio_volume_get(obj) + 0.1);
268 else if (!strcmp(ev->keyname, "v"))
272 for (l = video_objs; l; l = l->next)
277 if (emotion_object_video_mute_get(obj))
278 emotion_object_video_mute_set(obj, 0);
280 emotion_object_video_mute_set(obj, 1);
283 else if (!strcmp(ev->keyname, "a"))
287 for (l = video_objs; l; l = l->next)
292 if (emotion_object_audio_mute_get(obj))
294 emotion_object_audio_mute_set(obj, 0);
299 emotion_object_audio_mute_set(obj, 1);
304 else if (!strcmp(ev->keyname, "i"))
308 for (l = video_objs; l; l = l->next)
313 printf("audio channels: %i\n", emotion_object_audio_channel_count(obj));
314 printf("video channels: %i\n", emotion_object_video_channel_count(obj));
315 printf("spu channels: %i\n", emotion_object_spu_channel_count(obj));
316 printf("seekable: %i\n", emotion_object_seekable_get(obj));
319 else if (!strcmp(ev->keyname, "f"))
321 if (!ecore_evas_fullscreen_get(ecore_evas))
322 ecore_evas_fullscreen_set(ecore_evas, 1);
324 ecore_evas_fullscreen_set(ecore_evas, 0);
326 else if (!strcmp(ev->keyname, "d"))
328 if (!ecore_evas_avoid_damage_get(ecore_evas))
329 ecore_evas_avoid_damage_set(ecore_evas, 1);
331 ecore_evas_avoid_damage_set(ecore_evas, 0);
333 else if (!strcmp(ev->keyname, "s"))
335 if (!ecore_evas_shaped_get(ecore_evas))
337 ecore_evas_shaped_set(ecore_evas, 1);
338 evas_object_hide(o_bg);
342 ecore_evas_shaped_set(ecore_evas, 0);
343 evas_object_show(o_bg);
346 else if (!strcmp(ev->keyname, "b"))
348 if (!ecore_evas_borderless_get(ecore_evas))
349 ecore_evas_borderless_set(ecore_evas, 1);
351 ecore_evas_borderless_set(ecore_evas, 0);
353 else if (!strcmp(ev->keyname, "q"))
355 ecore_main_loop_quit();
358 printf("del obj!\n");
359 evas_object_del(video_objs->data);
360 video_objs = evas_list_remove_list(video_objs, video_objs);
366 printf("UNHANDLED: %s\n", ev->keyname);
371 video_obj_in_cb(void *data, Evas *ev, Evas_Object *obj, void *event_info)
373 // evas_object_color_set(obj, 255, 255, 255, 100);
377 video_obj_out_cb(void *data, Evas *ev, Evas_Object *obj, void *event_info)
379 // evas_object_color_set(obj, 255, 255, 255, 200);
383 video_obj_down_cb(void *data, Evas *ev, Evas_Object *obj, void *event_info)
385 Evas_Event_Mouse_Down *e;
388 evas_object_color_set(obj, 255, 50, 40, 200);
389 evas_object_raise(obj);
393 video_obj_up_cb(void *data, Evas *ev, Evas_Object *obj, void *event_info)
395 Evas_Event_Mouse_Up *e;
398 evas_object_color_set(obj, 255, 255, 255, 100);
402 video_obj_move_cb(void *data, Evas *ev, Evas_Object *obj, void *event_info)
404 Evas_Event_Mouse_Move *e;
407 if (e->buttons & 0x1)
411 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
412 x += e->cur.canvas.x - e->prev.canvas.x;
413 y += e->cur.canvas.y - e->prev.canvas.y;
414 evas_object_move(obj, x, y);
416 else if (e->buttons & 0x4)
420 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
421 w += e->cur.canvas.x - e->prev.canvas.x;
422 h += e->cur.canvas.y - e->prev.canvas.y;
423 evas_object_resize(obj, w, h);
428 video_obj_frame_decode_cb(void *data, Evas_Object *obj, void *event_info)
433 int ph, pm, ps, pf, lh, lm, ls;
436 pos = emotion_object_position_get(obj);
437 len = emotion_object_play_length_get(obj);
438 // printf("%3.3f, %3.3f\n", pos, len);
439 edje_object_part_drag_value_set(oe, "video_progress", pos / len, 0.0);
441 lm = len / 60 - (lh * 60);
442 ls = len - (lm * 60);
444 pm = pos / 60 - (ph * 60);
445 ps = pos - (pm * 60);
446 pf = pos * 100 - (ps * 100) - (pm * 60 * 100) - (ph * 60 * 60 * 100);
447 snprintf(buf, sizeof(buf), "%i:%02i:%02i.%02i / %i:%02i:%02i",
448 ph, pm, ps, pf, lh, lm, ls);
449 edje_object_part_text_set(oe, "video_progress_txt", buf);
454 static double pt = 0.0;
455 t = ecore_time_get();
456 printf("FPS: %3.3f\n", 1.0 / (t - pt));
462 video_obj_frame_resize_cb(void *data, Evas_Object *obj, void *event_info)
470 emotion_object_size_get(obj, &iw, &ih);
471 ratio = emotion_object_ratio_get(obj);
472 printf("HANDLE %ix%i @ %3.3f\n", iw, ih, ratio);
473 if (ratio > 0.0) iw = ih * ratio;
474 edje_extern_object_min_size_set(obj, iw, ih);
475 edje_object_part_swallow(oe, "video_swallow", obj);
476 edje_object_size_min_calc(oe, &w, &h);
477 evas_object_resize(oe, w, h);
478 edje_extern_object_min_size_set(obj, 0, 0);
479 edje_object_part_swallow(oe, "video_swallow", obj);
483 video_obj_length_change_cb(void *data, Evas_Object *obj, void *event_info)
488 int ph, pm, ps, pf, lh, lm, ls;
491 pos = emotion_object_position_get(obj);
492 len = emotion_object_play_length_get(obj);
493 edje_object_part_drag_value_set(oe, "video_progress", pos / len, 0.0);
495 lm = len / 60 - (lh * 60);
496 ls = len - (lm * 60);
498 pm = pos / 60 - (ph * 60);
499 ps = pos - (pm * 60);
500 pf = pos * 100 - (ps * 100) - (pm * 60 * 100) - (ph * 60 * 60 * 100);
501 snprintf(buf, sizeof(buf), "%i:%02i:%02i.%02i / %i:%02i:%02i",
502 ph, pm, ps, pf, lh, lm, ls);
503 edje_object_part_text_set(oe, "video_progress_txt", buf);
507 video_obj_stopped_cb(void *data, Evas_Object *obj, void *event_info)
512 printf("video stopped!\n");
513 emotion_object_position_set(obj, 0.0);
514 emotion_object_play_set(obj, 1);
518 video_obj_channels_cb(void *data, Evas_Object *obj, void *event_info)
523 printf("channels changed: [AUD %i][VID %i][SPU %i]\n",
524 emotion_object_audio_channel_count(obj),
525 emotion_object_video_channel_count(obj),
526 emotion_object_spu_channel_count(obj));
530 video_obj_title_cb(void *data, Evas_Object *obj, void *event_info)
535 printf("video title to: \"%s\"\n", emotion_object_title_get(obj));
539 video_obj_progress_cb(void *data, Evas_Object *obj, void *event_info)
544 printf("progress: \"%s\" %3.3f\n",
545 emotion_object_progress_info_get(obj),
546 emotion_object_progress_status_get(obj));
550 video_obj_ref_cb(void *data, Evas_Object *obj, void *event_info)
555 printf("video ref to: \"%s\" %i\n",
556 emotion_object_ref_file_get(obj),
557 emotion_object_ref_num_get(obj));
561 video_obj_button_num_cb(void *data, Evas_Object *obj, void *event_info)
566 printf("video spu buttons to: %i\n",
567 emotion_object_spu_button_count_get(obj));
571 video_obj_button_cb(void *data, Evas_Object *obj, void *event_info)
576 printf("video selected spu button: %i\n",
577 emotion_object_spu_button_get(obj));
583 video_obj_signal_play_cb(void *data, Evas_Object *o, const char *emission, const char *source)
588 emotion_object_play_set(ov, 1);
589 edje_object_signal_emit(o, "video_state", "play");
593 video_obj_signal_pause_cb(void *data, Evas_Object *o, const char *emission, const char *source)
598 emotion_object_play_set(ov, 0);
599 edje_object_signal_emit(o, "video_state", "pause");
603 video_obj_signal_stop_cb(void *data, Evas_Object *o, const char *emission, const char *source)
608 emotion_object_play_set(ov, 0);
609 emotion_object_position_set(ov, 0);
610 edje_object_signal_emit(o, "video_state", "stop");
614 video_obj_signal_jump_cb(void *data, Evas_Object *o, const char *emission, const char *source)
621 edje_object_part_drag_value_get(o, source, &x, &y);
622 len = emotion_object_play_length_get(ov);
623 emotion_object_position_set(ov, x * len);
627 video_obj_signal_speed_cb(void *data, Evas_Object *o, const char *emission, const char *source)
635 edje_object_part_drag_value_get(o, source, &x, &y);
637 evas_object_color_set(ov, 255, 255, 255, spd);
638 snprintf(buf, sizeof(buf), "%.0f", spd);
639 edje_object_part_text_set(o, "video_speed_txt", buf);
643 video_obj_signal_frame_move_start_cb(void *data, Evas_Object *o, const char *emission, const char *source)
648 fd = evas_object_data_get(o, "frame_data");
650 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
653 evas_object_raise(o);
657 video_obj_signal_frame_move_stop_cb(void *data, Evas_Object *o, const char *emission, const char *source)
661 fd = evas_object_data_get(o, "frame_data");
666 video_obj_signal_frame_resize_start_cb(void *data, Evas_Object *o, const char *emission, const char *source)
671 fd = evas_object_data_get(o, "frame_data");
673 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
676 evas_object_raise(o);
680 video_obj_signal_frame_resize_stop_cb(void *data, Evas_Object *o, const char *emission, const char *source)
684 fd = evas_object_data_get(o, "frame_data");
689 video_obj_signal_frame_move_cb(void *data, Evas_Object *o, const char *emission, const char *source)
693 fd = evas_object_data_get(o, "frame_data");
696 Evas_Coord x, y, ox, oy;
698 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
699 evas_object_geometry_get(o, &ox, &oy, NULL, NULL);
700 evas_object_move(o, ox + (x - fd->x), oy + (y - fd->y));
704 else if (fd->resizing)
706 Evas_Coord x, y, ow, oh;
708 evas_pointer_canvas_xy_get(evas_object_evas_get(o), &x, &y);
709 evas_object_geometry_get(o, NULL, NULL, &ow, &oh);
710 evas_object_resize(o, ow + (x - fd->x), oh + (y - fd->y));
718 init_video_object(char *module_filename, char *filename)
726 /* basic video object setup */
727 o = emotion_object_add(evas);
728 if (!emotion_object_init(o, module_filename))
730 emotion_object_file_set(o, filename);
731 emotion_object_play_set(o, 1);
732 evas_object_move(o, 0, 0);
733 evas_object_resize(o, 320, 240);
734 emotion_object_smooth_scale_set(o, 1);
736 /* end basic video setup. all the rest here is just to be fancy */
739 video_objs = evas_list_append(video_objs, o);
741 emotion_object_size_get(o, &iw, &ih);
744 fd = calloc(1, sizeof(Frame_Data));
746 oe = edje_object_add(evas);
747 evas_object_data_set(oe, "frame_data", fd);
748 edje_object_file_set(oe, PACKAGE_DATA_DIR"/data/theme.edj", "video_controller");
749 edje_extern_object_min_size_set(o, w, h);
750 edje_object_part_swallow(oe, "video_swallow", o);
751 edje_object_size_min_calc(oe, &w, &h);
752 // evas_object_move(oe, rand() % (int)(startw - w), rand() % (int)(starth - h));
753 evas_object_move(oe, 0, 0);
754 evas_object_resize(oe, w, h);
755 edje_extern_object_min_size_set(o, 0, 0);
756 edje_object_part_swallow(oe, "video_swallow", o);
758 evas_object_smart_callback_add(o, "frame_decode", video_obj_frame_decode_cb, oe);
759 evas_object_smart_callback_add(o, "frame_resize", video_obj_frame_resize_cb, oe);
760 evas_object_smart_callback_add(o, "length_change", video_obj_length_change_cb, oe);
762 evas_object_smart_callback_add(o, "decode_stop", video_obj_stopped_cb, oe);
763 evas_object_smart_callback_add(o, "channels_change", video_obj_channels_cb, oe);
764 evas_object_smart_callback_add(o, "title_change", video_obj_title_cb, oe);
765 evas_object_smart_callback_add(o, "progress_change", video_obj_progress_cb, oe);
766 evas_object_smart_callback_add(o, "ref_change", video_obj_ref_cb, oe);
767 evas_object_smart_callback_add(o, "button_num_change", video_obj_button_num_cb, oe);
768 evas_object_smart_callback_add(o, "button_change", video_obj_button_cb, oe);
770 edje_object_signal_callback_add(oe, "video_control", "play", video_obj_signal_play_cb, o);
771 edje_object_signal_callback_add(oe, "video_control", "pause", video_obj_signal_pause_cb, o);
772 edje_object_signal_callback_add(oe, "video_control", "stop", video_obj_signal_stop_cb, o);
773 edje_object_signal_callback_add(oe, "drag", "video_progress", video_obj_signal_jump_cb, o);
774 edje_object_signal_callback_add(oe, "drag", "video_speed", video_obj_signal_speed_cb, o);
776 edje_object_signal_callback_add(oe, "frame_move", "start", video_obj_signal_frame_move_start_cb, oe);
777 edje_object_signal_callback_add(oe, "frame_move", "stop", video_obj_signal_frame_move_stop_cb, oe);
778 edje_object_signal_callback_add(oe, "frame_resize", "start", video_obj_signal_frame_resize_start_cb, oe);
779 edje_object_signal_callback_add(oe, "frame_resize", "stop", video_obj_signal_frame_resize_stop_cb, oe);
780 edje_object_signal_callback_add(oe, "mouse,move", "*", video_obj_signal_frame_move_cb, oe);
782 edje_object_part_drag_value_set(oe, "video_speed", 0.0, 1.0);
783 edje_object_part_text_set(oe, "video_speed_txt", "1.0");
785 edje_object_signal_emit(o, "video_state", "play");
787 evas_object_show(oe);
791 enter_idle(void *data)
794 static double pt = 0.0;
795 static int frames = 0;
797 t = ecore_time_get();
798 if (frames == 0) pt = t;
802 // printf("FPS: %3.3f\n", frames / (t - pt));
809 main(int argc, char **argv)
811 char *module_filename;
814 if (main_start(argc, argv) < 1) return -1;
817 module_filename = "emotion_decoder_xine.so";
819 for (i = 1; i < argc; i++)
821 if (((!strcmp(argv[i], "-g")) ||
822 (!strcmp(argv[i], "-geometry")) ||
823 (!strcmp(argv[i], "--geometry"))) && (i < (argc - 1)))
825 else if (((!strcmp(argv[i], "-h")) ||
826 (!strcmp(argv[i], "-help")) ||
827 (!strcmp(argv[i], "--help"))))
830 printf(" %s [-gl] [-g WxH] [-xine] [-gstreamer] filename\n", argv[0]);
833 else if (!strcmp(argv[i], "-gl"))
836 else if (!strcmp(argv[i], "-fb"))
839 else if (!strcmp(argv[i], "-xine"))
841 module_filename = "emotion_decoder_xine.so";
843 else if (!strcmp(argv[i], "-gstreamer"))
845 module_filename = "emotion_decoder_gstreamer.so";
849 printf ("module : %s\n", module_filename);
850 init_video_object(module_filename, argv[i]);
854 ecore_idle_enterer_add(enter_idle, NULL);
856 ecore_main_loop_begin();