1 #include "emotion_private.h"
4 #define E_SMART_OBJ_GET(smart, o, type) \
9 smart = evas_object_smart_data_get(o); \
11 _e_smart_str = (char *)evas_object_type_get(o); \
12 if (!_e_smart_str) return; \
13 if (strcmp(_e_smart_str, type)) return; \
16 #define E_SMART_OBJ_GET_RETURN(smart, o, type, ret) \
21 smart = evas_object_smart_data_get(o); \
22 if (!smart) return ret; \
23 _e_smart_str = (char *)evas_object_type_get(o); \
24 if (!_e_smart_str) return ret; \
25 if (strcmp(_e_smart_str, type)) return ret; \
28 #define DBG(...) EINA_LOG_DOM_DBG(_log_domain, __VA_ARGS__)
29 #define INF(...) EINA_LOG_DOM_INFO(_log_domain, __VA_ARGS__)
30 #define WRN(...) EINA_LOG_DOM_WARN(_log_domain, __VA_ARGS__)
31 #define ERR(...) EINA_LOG_DOM_ERR(_log_domain, __VA_ARGS__)
32 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_log_domain, __VA_ARGS__)
34 #define E_OBJ_NAME "emotion_object"
36 typedef struct _Smart_Data Smart_Data;
40 Emotion_Video_Module *module;
54 unsigned char play : 1;
55 unsigned char seek : 1;
56 unsigned char seeking : 1;
72 Emotion_Module_Options module_options;
75 static void _mouse_move(void *data, Evas *ev, Evas_Object *obj, void *event_info);
76 static void _mouse_down(void *data, Evas *ev, Evas_Object *obj, void *event_info);
77 static void _pos_set_job(void *data);
78 static void _pixels_get(void *data, Evas_Object *obj);
80 static void _smart_init(void);
81 static void _smart_add(Evas_Object * obj);
82 static void _smart_del(Evas_Object * obj);
83 static void _smart_move(Evas_Object * obj, Evas_Coord x, Evas_Coord y);
84 static void _smart_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h);
85 static void _smart_show(Evas_Object * obj);
86 static void _smart_hide(Evas_Object * obj);
87 static void _smart_color_set(Evas_Object * obj, int r, int g, int b, int a);
88 static void _smart_clip_set(Evas_Object * obj, Evas_Object * clip);
89 static void _smart_clip_unset(Evas_Object * obj);
91 /**********************************/
92 /* Globals for the E Video Object */
93 /**********************************/
94 static Evas_Smart *smart = NULL;
95 static Eina_Hash *_backends = NULL;
96 static Eina_Array *_modules = NULL;
97 static int _log_domain = -1;
99 static const char *_backend_priority[] = {
105 static const char SIG_FRAME_DECODE[] = "frame_decode";
106 static const char SIG_POSITION_UPDATE[] = "position_update";
107 static const char SIG_LENGTH_CHANGE[] = "length_change";
108 static const char SIG_FRAME_RESIZE[] = "frame_resize";
109 static const char SIG_DECODE_STOP[] = "decode_stop";
110 static const char SIG_PLAYBACK_STARTED[] = "playback_started";
111 static const char SIG_PLAYBACK_FINISHED[] = "playback_finished";
112 static const char SIG_AUDIO_LEVEL_CHANGE[] = "audio_level_change";
113 static const char SIG_CHANNELS_CHANGE[] = "channels_change";
114 static const char SIG_TITLE_CHANGE[] = "title_change";
115 static const char SIG_PROGRESS_CHANGE[] = "progress_change";
116 static const char SIG_REF_CHANGE[] = "ref_change";
117 static const char SIG_BUTTON_NUM_CHANGE[] = "button_num_change";
118 static const char SIG_BUTTON_CHANGE[] = "button_change";
119 static const char SIG_OPEN_DONE[] = "open_done";
120 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
121 {SIG_FRAME_DECODE, ""},
122 {SIG_POSITION_UPDATE, ""},
123 {SIG_LENGTH_CHANGE, ""},
124 {SIG_FRAME_RESIZE, ""},
125 {SIG_DECODE_STOP, ""},
126 {SIG_PLAYBACK_STARTED, ""},
127 {SIG_PLAYBACK_FINISHED, ""},
128 {SIG_AUDIO_LEVEL_CHANGE, ""},
129 {SIG_CHANNELS_CHANGE, ""},
130 {SIG_TITLE_CHANGE, ""},
131 {SIG_PROGRESS_CHANGE, ""},
132 {SIG_REF_CHANGE, ""},
133 {SIG_BUTTON_NUM_CHANGE, ""},
134 {SIG_BUTTON_CHANGE, ""},
141 _emotion_module_register(const char *name, Emotion_Module_Open open, Emotion_Module_Close close)
143 Eina_Emotion_Plugins *plugin;
145 plugin = malloc(sizeof (Eina_Emotion_Plugins));
146 if (!plugin) return EINA_FALSE;
149 plugin->close = close;
151 return eina_hash_add(_backends, name, plugin);
155 _emotion_module_unregister(const char *name)
157 return eina_hash_del(_backends, name, NULL);
161 _emotion_module_open(const char *name, Evas_Object *obj, Emotion_Video_Module **mod, void **video)
163 Eina_Emotion_Plugins *plugin;
165 unsigned int index = 0;
167 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
170 ERR("No backend loaded");
174 /* FIXME: Always look for a working backend. */
176 if (!name || index > 0)
177 name = _backend_priority[index++];
179 plugin = eina_hash_find(_backends, name);
182 if (index != 0 && index < (sizeof (_backend_priority) / sizeof (char*)))
185 ERR("No backend loaded");
189 if (plugin->open(obj, (const Emotion_Video_Module **) mod, video, &(sd->module_options)))
193 (*mod)->plugin = plugin;
198 if (index != 0 && index < (sizeof (_backend_priority) / sizeof (char*)))
201 ERR("Unable to load module: %s", name);
207 _emotion_module_close(Emotion_Video_Module *mod, void *video)
210 if (mod->plugin->close && video)
211 mod->plugin->close(mod, video);
212 /* FIXME: we can't go dlclosing here as a thread still may be running from
213 * the module - this in theory will leak- but it shouldnt be too bad and
214 * mean that once a module is dlopened() it cant be closed - its refcount
215 * will just keep going up
219 /*******************************/
220 /* Externally accessible calls */
221 /*******************************/
226 emotion_object_add(Evas *evas)
229 return evas_object_smart_add(evas, smart);
233 emotion_object_module_option_set(Evas_Object *obj, const char *opt, const char *val)
237 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
238 if ((!opt) || (!val)) return;
239 if (!strcmp(opt, "video"))
241 if (!strcmp(val, "off")) sd->module_options.no_video = EINA_TRUE;
243 else if (!strcmp(opt, "audio"))
245 if (!strcmp(val, "off")) sd->module_options.no_audio = EINA_TRUE;
250 emotion_object_init(Evas_Object *obj, const char *module_filename)
255 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
257 if ((sd->module_name) && module_filename && (!strcmp(sd->module_name, module_filename)))
259 free(sd->module_name);
260 sd->module_name = NULL;
267 free(sd->progress.info);
268 sd->progress.info = NULL;
269 sd->progress.stat = 0.0;
273 sd->spu.button_num = 0;
282 _emotion_module_close(sd->module, sd->video);
286 module_filename = _emotion_module_open(module_filename, obj, &sd->module, &sd->video);
287 if (!module_filename)
290 sd->module_name = strdup(module_filename);
294 emotion_object_file_set(obj, file);
302 emotion_object_file_set(Evas_Object *obj, const char *file)
306 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
308 DBG("file=%s", file);
309 if (!sd->module) return;
311 if ((file) && (sd->file) && (!strcmp(file, sd->file))) return;
312 if ((file) && (file[0] != 0))
317 sd->file = strdup(file);
318 sd->module->file_close(sd->video);
319 evas_object_image_size_set(sd->obj, 0, 0);
320 if (!sd->module->file_open(sd->file, obj, sd->video))
322 sd->module->size_get(sd->video, &w, &h);
323 evas_object_image_size_set(sd->obj, w, h);
324 sd->ratio = sd->module->ratio_get(sd->video);
326 if (sd->play) sd->module->play(sd->video, 0.0);
330 if (sd->video && sd->module)
332 sd->module->file_close(sd->video);
333 evas_object_image_size_set(sd->obj, 0, 0);
341 emotion_object_file_get(const Evas_Object *obj)
345 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
350 emotion_object_play_set(Evas_Object *obj, Eina_Bool play)
354 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
355 DBG("play=%hhu, was=%hhu", play, sd->play);
356 if (play == sd->play) return;
357 if (!sd->module) return;
358 if (!sd->video) return;
360 if (sd->play) sd->module->play(sd->video, sd->pos);
361 else sd->module->stop(sd->video);
365 emotion_object_play_get(const Evas_Object *obj)
369 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
370 if (!sd->video) return EINA_FALSE;
376 emotion_object_position_set(Evas_Object *obj, double sec)
380 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
382 if (!sd->module) return;
383 if (!sd->video) return;
386 sd->pos = sd->seek_pos;
387 if (sd->job) ecore_job_del(sd->job);
388 sd->job = ecore_job_add(_pos_set_job, obj);
392 emotion_object_position_get(const Evas_Object *obj)
396 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0.0);
397 if (!sd->module) return 0.0;
398 if (!sd->video) return 0.0;
399 if (!sd->module->pos_get) return 0.0;
400 sd->pos = sd->module->pos_get(sd->video);
405 emotion_object_seekable_get(const Evas_Object *obj)
409 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
410 if (!sd->module) return EINA_FALSE;
411 if (!sd->video) return EINA_FALSE;
412 return sd->module->seekable(sd->video);
416 emotion_object_video_handled_get(const Evas_Object *obj)
420 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
421 if (!sd->module) return EINA_FALSE;
422 if (!sd->video) return EINA_FALSE;
423 return sd->module->video_handled(sd->video);
427 emotion_object_audio_handled_get(const Evas_Object *obj)
431 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
432 if (!sd->module) return EINA_FALSE;
433 if (!sd->video) return EINA_FALSE;
434 return sd->module->audio_handled(sd->video);
438 emotion_object_play_length_get(const Evas_Object *obj)
442 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0.0);
443 if (!sd->module) return 0.0;
444 if (!sd->video) return 0.0;
445 sd->len = sd->module->len_get(sd->video);
450 emotion_object_size_get(const Evas_Object *obj, int *iw, int *ih)
456 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
457 evas_object_image_size_get(sd->obj, iw, ih);
461 * Sets whether to use of high-quality image scaling algorithm
462 * of the given video object.
464 * When enabled, a higher quality video scaling algorithm is used when
465 * scaling videos to sizes other than the source video. This gives
466 * better results but is more computationally expensive.
468 * @param obj The given video object.
469 * @param smooth Whether to use smooth scale or not.
472 emotion_object_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
476 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
477 evas_object_image_smooth_scale_set(sd->obj, smooth);
481 * Gets whether the high-quality image scaling algorithm
482 * of the given video object is used.
484 * @return Whether the smooth scale is used or not.
487 emotion_object_smooth_scale_get(const Evas_Object *obj)
491 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
492 return evas_object_image_smooth_scale_get(sd->obj);
496 emotion_object_ratio_get(const Evas_Object *obj)
500 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 1.0);
501 if (!sd->module) return 0.0;
502 if (!sd->video) return 0.0;
507 * Send a control event to the DVD.
510 emotion_object_event_simple_send(Evas_Object *obj, Emotion_Event ev)
514 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
515 if (!sd->module) return;
516 if (!sd->video) return;
517 sd->module->event_feed(sd->video, ev);
521 emotion_object_audio_volume_set(Evas_Object *obj, double vol)
525 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
527 if (!sd->module) return;
528 if (!sd->video) return;
529 sd->module->audio_channel_volume_set(sd->video, vol);
533 emotion_object_audio_volume_get(const Evas_Object *obj)
537 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 1.0);
538 if (!sd->module) return 0.0;
539 if (!sd->video) return 0.0;
540 return sd->module->audio_channel_volume_get(sd->video);
544 emotion_object_audio_mute_set(Evas_Object *obj, Eina_Bool mute)
548 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
549 DBG("mute=%hhu", mute);
550 if (!sd->module) return;
551 if (!sd->video) return;
552 sd->module->audio_channel_mute_set(sd->video, mute);
556 emotion_object_audio_mute_get(const Evas_Object *obj)
560 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
561 if (!sd->module) return EINA_FALSE;
562 if (!sd->video) return EINA_FALSE;
563 return sd->module->audio_channel_mute_get(sd->video);
567 emotion_object_audio_channel_count(const Evas_Object *obj)
571 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
572 if (!sd->module) return 0;
573 if (!sd->video) return 0;
574 return sd->module->audio_channel_count(sd->video);
578 emotion_object_audio_channel_name_get(const Evas_Object *obj, int channel)
582 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
583 if (!sd->module) return NULL;
584 if (!sd->video) return NULL;
585 return sd->module->audio_channel_name_get(sd->video, channel);
589 emotion_object_audio_channel_set(Evas_Object *obj, int channel)
593 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
594 DBG("channel=%d", channel);
595 if (!sd->module) return;
596 if (!sd->video) return;
597 sd->module->audio_channel_set(sd->video, channel);
601 emotion_object_audio_channel_get(const Evas_Object *obj)
605 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
606 if (!sd->module) return 0;
607 if (!sd->video) return 0;
608 return sd->module->audio_channel_get(sd->video);
612 emotion_object_video_mute_set(Evas_Object *obj, Eina_Bool mute)
616 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
617 DBG("mute=%hhu", mute);
618 if (!sd->module) return;
619 if (!sd->video) return;
620 sd->module->video_channel_mute_set(sd->video, mute);
624 emotion_object_video_mute_get(const Evas_Object *obj)
628 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
629 if (!sd->module) return EINA_FALSE;
630 if (!sd->video) return EINA_FALSE;
631 return sd->module->video_channel_mute_get(sd->video);
635 emotion_object_video_channel_count(const Evas_Object *obj)
639 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
640 if (!sd->module) return EINA_FALSE;
641 if (!sd->video) return EINA_FALSE;
642 return sd->module->video_channel_count(sd->video);
646 emotion_object_video_channel_name_get(const Evas_Object *obj, int channel)
650 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
651 if (!sd->module) return NULL;
652 if (!sd->video) return NULL;
653 return sd->module->video_channel_name_get(sd->video, channel);
657 emotion_object_video_channel_set(Evas_Object *obj, int channel)
661 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
662 DBG("channel=%d", channel);
663 if (!sd->module) return;
664 if (!sd->video) return;
665 sd->module->video_channel_set(sd->video, channel);
669 emotion_object_video_channel_get(const Evas_Object *obj)
673 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
674 if (!sd->module) return 0;
675 if (!sd->video) return 0;
676 return sd->module->video_channel_get(sd->video);
680 emotion_object_spu_mute_set(Evas_Object *obj, Eina_Bool mute)
684 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
685 DBG("mute=%hhu", mute);
686 if (!sd->module) return;
687 if (!sd->video) return;
688 sd->module->spu_channel_mute_set(sd->video, mute);
692 emotion_object_spu_mute_get(const Evas_Object *obj)
696 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
697 if (!sd->module) return EINA_FALSE;
698 if (!sd->video) return EINA_FALSE;
699 return sd->module->spu_channel_mute_get(sd->video);
703 emotion_object_spu_channel_count(const Evas_Object *obj)
707 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
708 if (!sd->module) return 0;
709 if (!sd->video) return 0;
710 return sd->module->spu_channel_count(sd->video);
714 emotion_object_spu_channel_name_get(const Evas_Object *obj, int channel)
718 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
719 if (!sd->module) return NULL;
720 if (!sd->video) return NULL;
721 return sd->module->spu_channel_name_get(sd->video, channel);
725 emotion_object_spu_channel_set(Evas_Object *obj, int channel)
729 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
730 DBG("channel=%d", channel);
731 if (!sd->module) return;
732 if (!sd->video) return;
733 sd->module->spu_channel_set(sd->video, channel);
737 emotion_object_spu_channel_get(const Evas_Object *obj)
741 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
742 if (!sd->module) return 0;
743 if (!sd->video) return 0;
744 return sd->module->spu_channel_get(sd->video);
748 emotion_object_chapter_count(const Evas_Object *obj)
752 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
753 if (!sd->module) return 0;
754 if (!sd->video) return 0;
755 return sd->module->chapter_count(sd->video);
759 emotion_object_chapter_set(Evas_Object *obj, int chapter)
763 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
764 DBG("chapter=%d", chapter);
765 if (!sd->module) return;
766 if (!sd->video) return;
767 sd->module->chapter_set(sd->video, chapter);
771 emotion_object_chapter_get(const Evas_Object *obj)
775 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
776 if (!sd->module) return 0;
777 if (!sd->video) return 0;
778 return sd->module->chapter_get(sd->video);
782 emotion_object_chapter_name_get(const Evas_Object *obj, int chapter)
786 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
787 if (!sd->module) return NULL;
788 if (!sd->video) return NULL;
789 return sd->module->chapter_name_get(sd->video, chapter);
793 emotion_object_play_speed_set(Evas_Object *obj, double speed)
797 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
798 DBG("speed=%f", speed);
799 if (!sd->module) return;
800 if (!sd->video) return;
801 sd->module->speed_set(sd->video, speed);
805 emotion_object_play_speed_get(const Evas_Object *obj)
809 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0.0);
810 if (!sd->module) return 0.0;
811 if (!sd->video) return 0.0;
812 return sd->module->speed_get(sd->video);
816 emotion_object_eject(Evas_Object *obj)
820 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
821 if (!sd->module) return;
822 if (!sd->video) return;
823 sd->module->eject(sd->video);
827 emotion_object_title_get(const Evas_Object *obj)
831 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
836 emotion_object_progress_info_get(const Evas_Object *obj)
840 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
841 return sd->progress.info;
845 emotion_object_progress_status_get(const Evas_Object *obj)
849 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0.0);
850 return sd->progress.stat;
854 emotion_object_ref_file_get(const Evas_Object *obj)
858 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
863 emotion_object_ref_num_get(const Evas_Object *obj)
867 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
872 emotion_object_spu_button_count_get(const Evas_Object *obj)
876 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
877 return sd->spu.button_num;
881 emotion_object_spu_button_get(const Evas_Object *obj)
885 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
886 return sd->spu.button;
890 emotion_object_meta_info_get(const Evas_Object *obj, Emotion_Meta_Info meta)
894 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
895 if (!sd->module) return NULL;
896 if (!sd->video) return NULL;
899 case EMOTION_META_INFO_TRACK_TITLE:
900 return sd->module->meta_get(sd->video, META_TRACK_TITLE);
902 case EMOTION_META_INFO_TRACK_ARTIST:
903 return sd->module->meta_get(sd->video, META_TRACK_ARTIST);
905 case EMOTION_META_INFO_TRACK_ALBUM:
906 return sd->module->meta_get(sd->video, META_TRACK_ALBUM);
908 case EMOTION_META_INFO_TRACK_YEAR:
909 return sd->module->meta_get(sd->video, META_TRACK_YEAR);
911 case EMOTION_META_INFO_TRACK_GENRE:
912 return sd->module->meta_get(sd->video, META_TRACK_GENRE);
914 case EMOTION_META_INFO_TRACK_COMMENT:
915 return sd->module->meta_get(sd->video, META_TRACK_COMMENT);
917 case EMOTION_META_INFO_TRACK_DISC_ID:
918 return sd->module->meta_get(sd->video, META_TRACK_DISCID);
927 emotion_object_vis_set(Evas_Object *obj, Emotion_Vis visualization)
931 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
932 DBG("visualization=%d", visualization);
933 if (!sd->module) return;
934 if (!sd->video) return;
935 if (!sd->module->vis_set) return;
936 sd->module->vis_set(sd->video, visualization);
940 emotion_object_vis_get(const Evas_Object *obj)
944 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, EMOTION_VIS_NONE);
945 if (!sd->module) return EMOTION_VIS_NONE;
946 if (!sd->video) return EMOTION_VIS_NONE;
947 if (!sd->module->vis_get) return EMOTION_VIS_NONE;
948 return sd->module->vis_get(sd->video);
952 emotion_object_vis_supported(const Evas_Object *obj, Emotion_Vis visualization)
956 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0);
957 if (!sd->module) return EINA_FALSE;
958 if (!sd->video) return EINA_FALSE;
959 if (!sd->module->vis_supported) return EINA_FALSE;
960 return sd->module->vis_supported(sd->video, visualization);
965 /*****************************/
966 /* Utility calls for modules */
967 /*****************************/
970 _emotion_video_get(const Evas_Object *obj)
974 E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, NULL);
979 _emotion_frame_new(Evas_Object *obj)
983 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
984 // printf("pix get set 1 %p\n", sd->obj);
985 evas_object_image_pixels_dirty_set(sd->obj, 1);
986 evas_object_smart_callback_call(obj, SIG_FRAME_DECODE, NULL);
990 _emotion_video_pos_update(Evas_Object *obj, double pos, double len)
993 int npos = 0, nlen = 0;
995 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
996 if (pos != sd->pos) npos = 1;
997 if (len != sd->len) nlen = 1;
1000 if (npos) evas_object_smart_callback_call(obj, SIG_POSITION_UPDATE, NULL);
1001 if (nlen) evas_object_smart_callback_call(obj, SIG_LENGTH_CHANGE, NULL);
1005 _emotion_frame_resize(Evas_Object *obj, int w, int h, double ratio)
1011 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1012 evas_object_image_size_get(sd->obj, &iw, &ih);
1013 if ((w != iw) || (h != ih))
1015 if (h > 0) sd->ratio = (double)w / (double)h;
1016 else sd->ratio = 1.0;
1017 evas_object_image_size_set(sd->obj, w, h);
1020 if (ratio != sd->ratio)
1025 if (changed) evas_object_smart_callback_call(obj, SIG_FRAME_RESIZE, NULL);
1029 _emotion_decode_stop(Evas_Object *obj)
1033 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1037 evas_object_smart_callback_call(obj, SIG_DECODE_STOP, NULL);
1042 _emotion_open_done(Evas_Object *obj)
1044 evas_object_smart_callback_call(obj, SIG_OPEN_DONE, NULL);
1048 _emotion_playback_started(Evas_Object *obj)
1050 evas_object_smart_callback_call(obj, SIG_PLAYBACK_STARTED, NULL);
1054 _emotion_playback_finished(Evas_Object *obj)
1056 evas_object_smart_callback_call(obj, SIG_PLAYBACK_FINISHED, NULL);
1060 _emotion_audio_level_change(Evas_Object *obj)
1062 evas_object_smart_callback_call(obj, SIG_AUDIO_LEVEL_CHANGE, NULL);
1066 _emotion_channels_change(Evas_Object *obj)
1070 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1071 evas_object_smart_callback_call(obj, SIG_CHANNELS_CHANGE, NULL);
1075 _emotion_title_set(Evas_Object *obj, char *title)
1079 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1081 sd->title = strdup(title);
1082 evas_object_smart_callback_call(obj, SIG_TITLE_CHANGE, NULL);
1086 _emotion_progress_set(Evas_Object *obj, char *info, double stat)
1090 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1091 free(sd->progress.info);
1092 sd->progress.info = strdup(info);
1093 sd->progress.stat = stat;
1094 evas_object_smart_callback_call(obj, SIG_PROGRESS_CHANGE, NULL);
1098 _emotion_file_ref_set(Evas_Object *obj, const char *file, int num)
1102 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1104 sd->ref.file = strdup(file);
1106 evas_object_smart_callback_call(obj, SIG_REF_CHANGE, NULL);
1110 _emotion_spu_button_num_set(Evas_Object *obj, int num)
1114 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1115 sd->spu.button_num = num;
1116 evas_object_smart_callback_call(obj, SIG_BUTTON_NUM_CHANGE, NULL);
1120 _emotion_spu_button_set(Evas_Object *obj, int button)
1124 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1125 sd->spu.button = button;
1126 evas_object_smart_callback_call(obj, SIG_BUTTON_CHANGE, NULL);
1130 _emotion_seek_done(Evas_Object *obj)
1134 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1138 if (sd->seek) emotion_object_position_set(obj, sd->seek_pos);
1144 /****************************/
1145 /* Internal object routines */
1146 /****************************/
1149 _mouse_move(void *data, Evas *ev __UNUSED__, Evas_Object *obj, void *event_info)
1151 Evas_Event_Mouse_Move *e;
1154 Evas_Coord ox, oy, ow, oh;
1158 if (!sd->module) return;
1159 if (!sd->video) return;
1160 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
1161 evas_object_image_size_get(obj, &iw, &ih);
1162 if ((iw < 1) || (ih < 1)) return;
1163 x = (((int)e->cur.canvas.x - ox) * iw) / ow;
1164 y = (((int)e->cur.canvas.y - oy) * ih) / oh;
1165 sd->module->event_mouse_move_feed(sd->video, x, y);
1169 _mouse_down(void *data, Evas *ev __UNUSED__, Evas_Object *obj, void *event_info)
1171 Evas_Event_Mouse_Down *e;
1174 Evas_Coord ox, oy, ow, oh;
1178 if (!sd->module) return;
1179 if (!sd->video) return;
1180 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
1181 evas_object_image_size_get(obj, &iw, &ih);
1182 if ((iw < 1) || (ih < 1)) return;
1183 x = (((int)e->canvas.x - ox) * iw) / ow;
1184 y = (((int)e->canvas.y - oy) * ih) / oh;
1185 sd->module->event_mouse_button_feed(sd->video, 1, x, y);
1189 _pos_set_job(void *data)
1195 E_SMART_OBJ_GET(sd, obj, E_OBJ_NAME);
1197 if (sd->seeking) return;
1201 sd->module->pos_set(sd->video, sd->seek_pos);
1206 /* called by evas when it needs pixels for the image object */
1208 _pixels_get(void *data, Evas_Object *obj)
1212 Emotion_Format format;
1213 unsigned char *bgra_data;
1216 evas_object_image_size_get(obj, &iw, &ih);
1217 sd->module->video_data_size_get(sd->video, &w, &h);
1220 if ((w != iw) || (h != ih))
1222 evas_object_image_colorspace_set(obj, EVAS_COLORSPACE_YCBCR422P601_PL);
1223 evas_object_image_alpha_set(obj, 0);
1224 evas_object_image_size_set(obj, w, h);
1228 if ((iw < 1) || (ih < 1))
1230 // printf("pix get set 0 (1)\n");
1231 evas_object_image_pixels_dirty_set(obj, 0);
1235 format = sd->module->format_get(sd->video);
1236 if ((format == EMOTION_FORMAT_YV12) || (format == EMOTION_FORMAT_I420))
1238 unsigned char **rows;
1240 evas_object_image_colorspace_set(obj, EVAS_COLORSPACE_YCBCR422P601_PL);
1241 rows = evas_object_image_data_get(obj, 1);
1244 if (sd->module->yuv_rows_get(sd->video, iw, ih,
1247 &rows[ih + (ih / 2)]))
1248 evas_object_image_data_update_add(obj, 0, 0, iw, ih);
1250 evas_object_image_data_set(obj, rows);
1251 // printf("pix get set 0 (2)\n");
1252 evas_object_image_pixels_dirty_set(obj, 0);
1254 else if (format == EMOTION_FORMAT_BGRA)
1256 if (sd->module->bgra_data_get(sd->video, &bgra_data))
1258 evas_object_image_data_set(obj, bgra_data);
1259 // printf("pix get set 0 (3)\n");
1260 evas_object_image_pixels_dirty_set(obj, 0);
1264 // no need for this because on any new frame decode info from the decoder
1265 // module, the previous "current frame" is released (done) for us anyway
1266 // sd->module->frame_done(sd->video);
1269 evas_object_image_size_get(obj, &iw, &ih);
1270 sd->module->video_data_size_get(sd->video, &w, &h);
1271 if ((w != iw) || (h != ih))
1273 evas_object_image_size_set(obj, w, h);
1277 format = sd->module->format_get(sd->video);
1278 if ((format == EMOTION_FORMAT_YV12) || (format == EMOTION_FORMAT_I420))
1280 unsigned char **rows;
1281 Evas_Pixel_Import_Source ps;
1283 ps.format = EVAS_PIXEL_FORMAT_YUV420P_601;
1287 ps.rows = malloc(ps.h * 2 * sizeof(void *));
1290 sd->module->frame_done(sd->video);
1294 rows = (unsigned char **)ps.rows;
1296 if (sd->module->yuv_rows_get(sd->video, iw, ih,
1299 &rows[ps.h + (ps.h / 2)]))
1300 evas_object_image_pixels_import(obj, &ps);
1301 evas_object_image_pixels_dirty_set(obj, 0);
1304 else if (format == EMOTION_FORMAT_BGRA)
1306 if (sd->module->bgra_data_get(sd->video, &bgra_data));
1308 evas_object_image_data_set(obj, bgra_data);
1309 evas_object_image_pixels_dirty_set(obj, 0);
1312 sd->module->frame_done(sd->video);
1316 /*******************************************/
1317 /* Internal smart object required routines */
1318 /*******************************************/
1319 #ifdef EMOTION_STATIC_BUILD_XINE
1320 Eina_Bool xine_module_init(void);
1322 #ifdef EMOTION_STATIC_BUILD_VLC
1323 Eina_Bool vlc_module_init(void);
1325 #ifdef EMOTION_STATIC_BUILD_GSTREAMER
1326 Eina_Bool gstreamer_module_init(void);
1338 _log_domain = eina_log_domain_register("emotion", EINA_COLOR_LIGHTCYAN);
1339 if (_log_domain < 0)
1341 EINA_LOG_CRIT("Could not register log domain 'emotion'");
1346 _backends = eina_hash_string_small_new(free);
1348 _modules = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/emotion/", 0, NULL, NULL);
1350 path = eina_module_environment_path_get("HOME", "/.emotion/");
1351 _modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
1352 if (path) free(path);
1354 path = eina_module_environment_path_get("EMOTION_MODULES_DIR", "/emotion/");
1355 _modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
1356 if (path) free(path);
1358 path = eina_module_symbol_path_get(emotion_object_add, "/emotion/");
1359 _modules = eina_module_list_get(_modules, path, 0, NULL, NULL);
1360 if (path) free(path);
1364 ERR("No module found!");
1368 eina_module_list_load(_modules);
1370 /* Init static module */
1371 #ifdef EMOTION_STATIC_BUILD_XINE
1374 #ifdef EMOTION_STATIC_BUILD_VLC
1377 #ifdef EMOTION_STATIC_BUILD_GSTREAMER
1378 gstreamer_module_init();
1381 static Evas_Smart_Class sc =
1382 EVAS_SMART_CLASS_INIT_NAME_VERSION(E_OBJ_NAME);
1385 sc.add = _smart_add;
1386 sc.del = _smart_del;
1387 sc.move = _smart_move;
1388 sc.resize = _smart_resize;
1389 sc.show = _smart_show;
1390 sc.hide = _smart_hide;
1391 sc.color_set = _smart_color_set;
1392 sc.clip_set = _smart_clip_set;
1393 sc.clip_unset = _smart_clip_unset;
1394 sc.callbacks = _smart_callbacks;
1396 smart = evas_smart_class_new(&sc);
1401 _smart_add(Evas_Object * obj)
1404 unsigned int *pixel;
1406 sd = calloc(1, sizeof(Smart_Data));
1408 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
1409 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move, sd);
1410 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down, sd);
1411 evas_object_image_pixels_get_callback_set(sd->obj, _pixels_get, sd);
1412 evas_object_smart_member_add(sd->obj, obj);
1414 sd->spu.button = -1;
1415 evas_object_image_alpha_set(sd->obj, 0);
1416 pixel = evas_object_image_data_get(sd->obj, 1);
1419 *pixel = 0xff000000;
1420 evas_object_image_data_set(obj, pixel);
1422 evas_object_smart_data_set(obj, sd);
1426 _smart_del(Evas_Object * obj)
1430 sd = evas_object_smart_data_get(obj);
1432 if (sd->video) sd->module->file_close(sd->video);
1433 _emotion_module_close(sd->module, sd->video);
1434 evas_object_del(sd->obj);
1436 free(sd->module_name);
1437 if (sd->job) ecore_job_del(sd->job);
1438 free(sd->progress.info);
1446 _smart_move(Evas_Object * obj, Evas_Coord x, Evas_Coord y)
1450 sd = evas_object_smart_data_get(obj);
1452 evas_object_move(sd->obj, x, y);
1456 _smart_resize(Evas_Object * obj, Evas_Coord w, Evas_Coord h)
1460 sd = evas_object_smart_data_get(obj);
1462 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
1463 evas_object_resize(sd->obj, w, h);
1467 _smart_show(Evas_Object * obj)
1471 sd = evas_object_smart_data_get(obj);
1473 evas_object_show(sd->obj);
1478 _smart_hide(Evas_Object * obj)
1482 sd = evas_object_smart_data_get(obj);
1484 evas_object_hide(sd->obj);
1488 _smart_color_set(Evas_Object * obj, int r, int g, int b, int a)
1492 sd = evas_object_smart_data_get(obj);
1494 evas_object_color_set(sd->obj, r, g, b, a);
1498 _smart_clip_set(Evas_Object * obj, Evas_Object * clip)
1502 sd = evas_object_smart_data_get(obj);
1504 evas_object_clip_set(sd->obj, clip);
1508 _smart_clip_unset(Evas_Object * obj)
1512 sd = evas_object_smart_data_get(obj);
1514 evas_object_clip_unset(sd->obj);