18 #include "emotion_private.h"
19 #include "emotion_generic.h"
21 static Eina_Prefix *pfx = NULL;
23 static int _emotion_generic_log_domain = -1;
24 #define DBG(...) EINA_LOG_DOM_DBG(_emotion_generic_log_domain, __VA_ARGS__)
25 #define INF(...) EINA_LOG_DOM_INFO(_emotion_generic_log_domain, __VA_ARGS__)
26 #define WRN(...) EINA_LOG_DOM_WARN(_emotion_generic_log_domain, __VA_ARGS__)
27 #define ERR(...) EINA_LOG_DOM_ERR(_emotion_generic_log_domain, __VA_ARGS__)
28 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_emotion_generic_log_domain, __VA_ARGS__)
31 struct _default_players {
36 static struct _default_players players[] = {
37 #ifdef EMOTION_BUILD_GENERIC_VLC
38 { "vlc", "em_generic_vlc" },
44 _get_player(const char *name)
46 const char *selected_name = NULL;
47 const char *libdir = eina_prefix_lib_get(pfx);
48 static char buf[PATH_MAX];
53 for (i = 0; players[i].name; i++)
55 if (!strcmp(players[i].name, name))
57 selected_name = players[i].cmdline;
63 if ((!selected_name) && (name))
70 if (selected_name[0] == '/') cmd = selected_name;
73 snprintf(buf, sizeof(buf), "%s/emotion/utils/%s",
74 libdir, selected_name);
78 DBG("Try generic player '%s'", cmd);
79 if (access(cmd, R_OK | X_OK) == 0)
81 INF("Using generic player '%s'", cmd);
86 for (i = 0; players[i].name; i++)
88 snprintf(buf, sizeof(buf), "%s/emotion/utils/%s",
89 libdir, players[i].cmdline);
90 DBG("Try generic player '%s'", buf);
91 if (access(buf, R_OK | X_OK) == 0)
93 INF("Using fallback player '%s'", buf);
98 ERR("no generic player found, given name='%s'", name ? name : "");
103 _player_send_cmd(Emotion_Generic_Video *ev, int cmd)
105 if (cmd >= EM_CMD_LAST)
107 ERR("invalid command to player.");
110 if (write(ev->fd_write, &cmd, sizeof(cmd)) < 0) perror("write");
114 _player_send_int(Emotion_Generic_Video *ev, int number)
116 if (write(ev->fd_write, &number, sizeof(number)) < 0) perror("write");
120 _player_send_float(Emotion_Generic_Video *ev, float number)
122 if (write(ev->fd_write, &number, sizeof(number)) < 0) perror("write");
126 _player_send_str(Emotion_Generic_Video *ev, const char *str, Eina_Bool stringshared)
131 len = eina_stringshare_strlen(str) + 1;
133 len = strlen(str) + 1;
134 if (write(ev->fd_write, &len, sizeof(len)) < 0) perror("write");
135 if (write(ev->fd_write, str, len) < 0) perror("write");
139 _create_shm_data(Emotion_Generic_Video *ev, const char *shmname)
144 Emotion_Generic_Video_Shared *vs;
146 shmfd = shm_open(shmname, O_CREAT | O_RDWR | O_TRUNC, 0777);
149 ERR("player: could not open shm: %s", shmname);
150 ERR("player: %s", strerror(errno));
153 size = 3 * (ev->w * ev->h * DEFAULTPITCH) + sizeof(*vs);
155 npages = (int)(size / getpagesize()) + 1;
156 size = npages * getpagesize();
158 if (ftruncate(shmfd, size))
160 ERR("error when allocating shared memory (size = %zd): "
161 "%s", size, strerror(errno));
165 vs = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
166 if (vs == MAP_FAILED)
168 ERR("error when mapping shared memory");
175 vs->pitch = DEFAULTPITCH;
176 vs->frame.emotion = 0;
177 vs->frame.player = 1;
181 if (!eina_semaphore_new(&vs->lock, 1))
183 ERR("can not create semaphore");
186 ev->frame.frames[0] = (unsigned char *)vs + sizeof(*vs);
187 ev->frame.frames[1] = (unsigned char *)vs + sizeof(*vs) + vs->height * vs->width * vs->pitch;
188 ev->frame.frames[2] = (unsigned char *)vs + sizeof(*vs) + 2 * vs->height * vs->width * vs->pitch;
191 munmap(ev->shared, ev->shared->size);
198 _player_new_frame(Emotion_Generic_Video *ev)
202 _emotion_frame_new(ev->obj);
206 _file_open(Emotion_Generic_Video *ev)
208 INF("Opening file: %s", ev->filename);
211 if (!ev->ready || !ev->filename)
213 _player_send_cmd(ev, EM_CMD_FILE_SET);
214 _player_send_str(ev, ev->filename, EINA_TRUE);
218 _player_file_set_done(Emotion_Generic_Video *ev)
220 if (ev->file_changed)
223 ev->file_changed = EINA_FALSE;
227 if (!_create_shm_data(ev, ev->shmname))
229 ERR("could not create shared memory.");
232 _player_send_cmd(ev, EM_CMD_FILE_SET_DONE);
236 _player_ready(Emotion_Generic_Video *ev)
238 INF("received: player ready.");
240 ev->initializing = EINA_FALSE;
241 ev->ready = EINA_TRUE;
250 _player_cmd_param_read(Emotion_Generic_Video *ev, void *param, size_t size)
252 ssize_t done, todo, i;
254 /* When a parameter must be read, we cannot make sure it will be entirely
255 * available. Thus we store the bytes that could be read in a temp buffer,
256 * and when more data is read we try to complete the buffer and finally use
261 ev->cmd.tmp = malloc(size);
263 ev->cmd.total = size;
266 todo = ev->cmd.total - ev->cmd.i;
268 done = read(ev->fd_read, &ev->cmd.tmp[i], todo);
270 if (done < 0 && errno != EINTR && errno != EAGAIN)
277 ERR("problem when reading parameter from pipe.");
284 memcpy(param, ev->cmd.tmp, size);
297 _player_frame_resize(Emotion_Generic_Video *ev)
301 w = ev->cmd.param.size.width;
302 h = ev->cmd.param.size.height;
304 INF("received frame resize: %dx%d", w, h);
307 ev->ratio = (float)w / h;
312 _emotion_frame_resize(ev->obj, ev->w, ev->h, ev->ratio);
316 _player_length_changed(Emotion_Generic_Video *ev)
318 float length = ev->cmd.param.f_num;
320 INF("received length changed: %0.3f", length);
323 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
327 _player_position_changed(Emotion_Generic_Video *ev)
329 float position = ev->cmd.param.f_num;
331 INF("received position changed: %0.3f", position);
334 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
339 float progress = ev->pos / ev->len;
341 snprintf(buf, sizeof(buf), "%0.1f%%", progress * 100);
343 _emotion_progress_set(ev->obj, buf, progress);
347 _player_seekable_changed(Emotion_Generic_Video *ev)
349 int seekable = ev->cmd.param.i_num;
351 INF("received seekable changed: %d", seekable);
353 seekable = !!seekable;
355 ev->seekable = seekable;
359 _audio_channels_free(Emotion_Generic_Video *ev)
362 for (i = 0; i < ev->audio_channels_count; i++)
363 eina_stringshare_del(ev->audio_channels[i].name);
364 free(ev->audio_channels);
365 ev->audio_channels_count = 0;
369 _video_channels_free(Emotion_Generic_Video *ev)
372 for (i = 0; i < ev->video_channels_count; i++)
373 eina_stringshare_del(ev->video_channels[i].name);
374 free(ev->video_channels);
375 ev->video_channels_count = 0;
379 _spu_channels_free(Emotion_Generic_Video *ev)
382 for (i = 0; i < ev->spu_channels_count; i++)
383 eina_stringshare_del(ev->spu_channels[i].name);
384 free(ev->spu_channels);
385 ev->spu_channels_count = 0;
389 _player_tracks_info(Emotion_Generic_Video *ev, Emotion_Generic_Channel **channels, int *count, int *current)
391 Emotion_Generic_Channel *pchannels;
394 *count = ev->cmd.param.track.total;
395 *current = ev->cmd.param.track.current;
396 pchannels = ev->cmd.param.track.channels;
398 INF("number of tracks: %d (current = %d):", *count, *current);
399 for (i = 0; i < *count; i++)
401 INF("\tchannel %d: %s", pchannels[i].id, pchannels[i].name);
404 *channels = pchannels;
408 _player_audio_tracks_info(Emotion_Generic_Video *ev)
410 INF("Receiving audio channels:");
411 if (ev->audio_channels_count)
412 _audio_channels_free(ev);
414 _player_tracks_info(ev, &ev->audio_channels, &ev->audio_channels_count,
415 &ev->audio_channel_current);
419 _player_video_tracks_info(Emotion_Generic_Video *ev)
421 INF("Receiving video channels:");
422 if (ev->video_channels_count)
423 _video_channels_free(ev);
425 _player_tracks_info(ev, &ev->video_channels, &ev->video_channels_count,
426 &ev->video_channel_current);
430 _player_spu_tracks_info(Emotion_Generic_Video *ev)
432 INF("Receiving spu channels:");
433 if (ev->spu_channels_count)
434 _spu_channels_free(ev);
436 _player_tracks_info(ev, &ev->spu_channels, &ev->spu_channels_count,
437 &ev->spu_channel_current);
441 _player_meta_info_free(Emotion_Generic_Video *ev)
443 eina_stringshare_replace(&ev->meta.title, NULL);
444 eina_stringshare_replace(&ev->meta.artist, NULL);
445 eina_stringshare_replace(&ev->meta.album, NULL);
446 eina_stringshare_replace(&ev->meta.year, NULL);
447 eina_stringshare_replace(&ev->meta.genre, NULL);
448 eina_stringshare_replace(&ev->meta.comment, NULL);
449 eina_stringshare_replace(&ev->meta.disc_id, NULL);
450 eina_stringshare_replace(&ev->meta.count, NULL);
454 _player_meta_info_read(Emotion_Generic_Video *ev)
456 INF("Receiving meta info:");
457 _player_meta_info_free(ev);
458 ev->meta.title = ev->cmd.param.meta.title;
459 ev->meta.artist = ev->cmd.param.meta.artist;
460 ev->meta.album = ev->cmd.param.meta.album;
461 ev->meta.year = ev->cmd.param.meta.year;
462 ev->meta.genre = ev->cmd.param.meta.genre;
463 ev->meta.comment = ev->cmd.param.meta.comment;
464 ev->meta.disc_id = ev->cmd.param.meta.disc_id;
465 ev->meta.count = ev->cmd.param.meta.count;
466 INF("title: '%s'", ev->meta.title);
467 INF("artist: '%s'", ev->meta.artist);
468 INF("album: '%s'", ev->meta.album);
469 INF("year: '%s'", ev->meta.year);
470 INF("genre: '%s'", ev->meta.genre);
471 INF("comment: '%s'", ev->meta.comment);
472 INF("disc_id: '%s'", ev->meta.disc_id);
473 INF("count: '%s'", ev->meta.count);
477 _player_file_closed(Emotion_Generic_Video *ev)
479 INF("Closed previous file.");
480 eina_semaphore_free(&ev->shared->lock);
481 ev->closing = EINA_FALSE;
488 _player_open_done(Emotion_Generic_Video *ev)
492 success = ev->cmd.param.i_num;
493 shm_unlink(ev->shmname);
495 if (ev->file_changed)
498 ev->file_changed = EINA_FALSE;
502 ev->opening = EINA_FALSE;
505 ERR("Could not open file.");
509 ev->file_ready = EINA_TRUE;
511 _emotion_open_done(ev->obj);
515 _player_send_cmd(ev, EM_CMD_PLAY);
516 _player_send_float(ev, ev->pos);
519 _player_send_cmd(ev, EM_CMD_VOLUME_SET);
520 _player_send_float(ev, ev->volume);
522 _player_send_cmd(ev, EM_CMD_SPEED_SET);
523 _player_send_float(ev, ev->speed);
525 int mute = ev->audio_mute;
526 _player_send_cmd(ev, EM_CMD_AUDIO_MUTE_SET);
527 _player_send_int(ev, mute);
529 mute = ev->video_mute;
530 _player_send_cmd(ev, EM_CMD_VIDEO_MUTE_SET);
531 _player_send_int(ev, mute);
534 _player_send_cmd(ev, EM_CMD_SPU_MUTE_SET);
535 _player_send_int(ev, mute);
541 _player_cmd_process(Emotion_Generic_Video *ev)
543 switch (ev->cmd.type) {
547 case EM_RESULT_FRAME_NEW:
548 _player_new_frame(ev);
550 case EM_RESULT_FILE_SET:
551 _player_file_set_done(ev);
553 case EM_RESULT_FILE_SET_DONE:
554 _player_open_done(ev);
556 case EM_RESULT_FILE_CLOSE:
557 _player_file_closed(ev);
559 case EM_RESULT_PLAYBACK_STOPPED:
560 _emotion_playback_finished(ev->obj);
562 case EM_RESULT_FRAME_SIZE:
563 _player_frame_resize(ev);
565 case EM_RESULT_LENGTH_CHANGED:
566 _player_length_changed(ev);
568 case EM_RESULT_POSITION_CHANGED:
569 _player_position_changed(ev);
571 case EM_RESULT_SEEKABLE_CHANGED:
572 _player_seekable_changed(ev);
574 case EM_RESULT_AUDIO_TRACK_INFO:
575 _player_audio_tracks_info(ev);
577 case EM_RESULT_VIDEO_TRACK_INFO:
578 _player_video_tracks_info(ev);
580 case EM_RESULT_SPU_TRACK_INFO:
581 _player_spu_tracks_info(ev);
583 case EM_RESULT_META_INFO:
584 _player_meta_info_read(ev);
587 WRN("received wrong command: %d", ev->cmd.type);
594 _player_cmd_single_int_process(Emotion_Generic_Video *ev)
596 if (!_player_cmd_param_read(ev, &ev->cmd.param.i_num, sizeof(ev->cmd.param.i_num)))
599 _player_cmd_process(ev);
603 _player_cmd_single_float_process(Emotion_Generic_Video *ev)
605 if (!_player_cmd_param_read(ev, &ev->cmd.param.f_num, sizeof(ev->cmd.param.f_num)))
608 _player_cmd_process(ev);
612 _player_cmd_double_int_process(Emotion_Generic_Video *ev)
616 if (ev->cmd.num_params == 0)
618 ev->cmd.num_params = 2;
619 ev->cmd.cur_param = 0;
620 ev->cmd.param.size.width = 0;
621 ev->cmd.param.size.height = 0;
624 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
627 if (ev->cmd.cur_param == 0)
628 ev->cmd.param.size.width = param;
630 ev->cmd.param.size.height = param;
633 if (ev->cmd.cur_param == ev->cmd.num_params)
634 _player_cmd_process(ev);
638 _player_cmd_track_info(Emotion_Generic_Video *ev)
643 if (ev->cmd.num_params == 0)
645 ev->cmd.cur_param = 0;
646 ev->cmd.num_params = 2;
647 ev->cmd.param.track.channels = NULL;
651 while (ev->cmd.cur_param < 2)
653 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
656 if (ev->cmd.cur_param == 0)
657 ev->cmd.param.track.current = param;
660 ev->cmd.param.track.total = param;
661 ev->cmd.num_params += param * 2;
662 ev->cmd.param.track.channels =
663 calloc(param, sizeof(*ev->cmd.param.track.channels));
668 if (ev->cmd.cur_param == ev->cmd.num_params)
670 _player_cmd_process(ev);
674 i = (ev->cmd.cur_param - 2) / 2;
675 if ((ev->cmd.cur_param % 2) == 0) // reading track id
677 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
679 ev->cmd.param.track.channels[i].id = param;
682 else // reading track name
686 if (ev->cmd.s_len == -1)
688 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
690 ev->cmd.s_len = param;
693 if (!_player_cmd_param_read(ev, buf, ev->cmd.s_len))
695 ev->cmd.param.track.channels[i].name =
696 eina_stringshare_add_length(buf, ev->cmd.s_len);
701 if (ev->cmd.cur_param == ev->cmd.num_params)
702 _player_cmd_process(ev);
706 _player_cmd_meta_info(Emotion_Generic_Video *ev)
712 if (ev->cmd.num_params == 0)
714 ev->cmd.cur_param = 0;
715 ev->cmd.num_params = 8;
716 ev->cmd.param.meta.title = NULL;
717 ev->cmd.param.meta.artist = NULL;
718 ev->cmd.param.meta.album = NULL;
719 ev->cmd.param.meta.year = NULL;
720 ev->cmd.param.meta.genre = NULL;
721 ev->cmd.param.meta.comment = NULL;
722 ev->cmd.param.meta.disc_id = NULL;
723 ev->cmd.param.meta.count = NULL;
727 if (ev->cmd.s_len == -1)
729 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
731 ev->cmd.s_len = param;
734 if (!_player_cmd_param_read(ev, buf, ev->cmd.s_len))
737 info = eina_stringshare_add_length(buf, ev->cmd.s_len);
740 if (ev->cmd.cur_param == 0)
741 ev->cmd.param.meta.title = info;
742 else if (ev->cmd.cur_param == 1)
743 ev->cmd.param.meta.artist = info;
744 else if (ev->cmd.cur_param == 2)
745 ev->cmd.param.meta.album = info;
746 else if (ev->cmd.cur_param == 3)
747 ev->cmd.param.meta.year = info;
748 else if (ev->cmd.cur_param == 4)
749 ev->cmd.param.meta.genre = info;
750 else if (ev->cmd.cur_param == 5)
751 ev->cmd.param.meta.comment = info;
752 else if (ev->cmd.cur_param == 6)
753 ev->cmd.param.meta.disc_id = info;
754 else if (ev->cmd.cur_param == 7)
755 ev->cmd.param.meta.count = info;
759 if (ev->cmd.cur_param == 8)
760 _player_cmd_process(ev);
764 _player_cmd_read(Emotion_Generic_Video *ev)
766 if (ev->cmd.type < 0)
768 if (!_player_cmd_param_read(ev, &ev->cmd.type, sizeof(ev->cmd.type)))
770 ev->cmd.num_params = 0;
773 switch (ev->cmd.type) {
775 case EM_RESULT_FILE_SET:
776 case EM_RESULT_PLAYBACK_STOPPED:
777 case EM_RESULT_FILE_CLOSE:
778 case EM_RESULT_FRAME_NEW:
779 _player_cmd_process(ev);
781 case EM_RESULT_FILE_SET_DONE:
782 case EM_RESULT_SEEKABLE_CHANGED:
783 _player_cmd_single_int_process(ev);
785 case EM_RESULT_LENGTH_CHANGED:
786 case EM_RESULT_POSITION_CHANGED:
787 _player_cmd_single_float_process(ev);
789 case EM_RESULT_FRAME_SIZE:
790 _player_cmd_double_int_process(ev);
792 case EM_RESULT_AUDIO_TRACK_INFO:
793 case EM_RESULT_VIDEO_TRACK_INFO:
794 case EM_RESULT_SPU_TRACK_INFO:
795 _player_cmd_track_info(ev);
797 case EM_RESULT_META_INFO:
798 _player_cmd_meta_info(ev);
802 WRN("received wrong command: %d", ev->cmd.type);
808 _player_cmd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler)
810 Emotion_Generic_Video *ev = data;
812 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
814 ERR("an error occurred on fd_read %d.", ev->fd_read);
815 return ECORE_CALLBACK_CANCEL;
818 _player_cmd_read(ev);
820 return ECORE_CALLBACK_RENEW;
824 _player_data_cb(void *data, int type __UNUSED__, void *event)
826 Ecore_Exe_Event_Data *ev = event;
827 Emotion_Generic_Video *evideo = data;
830 if (ev->exe != evideo->player.exe)
832 ERR("slave != ev->exe");
833 return ECORE_CALLBACK_DONE;
836 for (i = 0; ev->lines[i].line; i++)
837 INF("received input from player: \"%s\"", ev->lines[i].line);
839 return ECORE_CALLBACK_DONE;
843 _player_add_cb(void *data, int type __UNUSED__, void *event)
845 Ecore_Exe_Event_Add *event_add = event;
846 Ecore_Exe *player = event_add->exe;
847 Emotion_Generic_Video *ev = data;
849 if (ev->player.exe != player)
851 ERR("ev->player != player.");
852 return ECORE_CALLBACK_DONE;
855 _player_send_cmd(ev, EM_CMD_INIT);
856 _player_send_str(ev, ev->shmname, EINA_TRUE);
858 return ECORE_CALLBACK_DONE;
862 _player_del_cb(void *data, int type __UNUSED__, void *event __UNUSED__)
864 Emotion_Generic_Video *ev = data;
867 ev->player.exe = NULL;
868 ev->ready = EINA_FALSE;
869 ev->file_ready = EINA_FALSE;
870 ecore_main_fd_handler_del(ev->fd_handler);
875 _emotion_decode_stop(ev->obj);
877 return ECORE_CALLBACK_DONE;
881 _player_exec(Emotion_Generic_Video *ev)
887 if (pipe(pipe_out) == -1)
889 ERR("could not create pipe for communication emotion -> player: %s", strerror(errno));
893 if (pipe(pipe_in) == -1)
895 ERR("could not create pipe for communication player -> emotion: %s", strerror(errno));
901 snprintf(buf, sizeof(buf), "%s %d %d\n", ev->cmdline, pipe_out[0], pipe_in[1]);
903 ev->player.exe = ecore_exe_pipe_run(
905 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE |
906 ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_NOT_LEADER,
909 INF("created pipe emotion -> player: %d -> %d", pipe_out[1], pipe_out[0]);
910 INF("created pipe player -> emotion: %d -> %d", pipe_in[1], pipe_in[0]);
922 ev->fd_read = pipe_in[0];
923 ev->fd_write = pipe_out[1];
925 ev->fd_handler = ecore_main_fd_handler_add(
926 ev->fd_read, ECORE_FD_READ | ECORE_FD_ERROR, _player_cmd_handler_cb, ev,
933 _fork_and_exec(Evas_Object *obj __UNUSED__, Emotion_Generic_Video *ev)
938 gettimeofday(&tv, NULL);
939 snprintf(shmname, sizeof(shmname), "/em-generic-shm_%d_%d",
940 (int)tv.tv_sec, (int)tv.tv_usec);
942 ev->shmname = eina_stringshare_add(shmname);
944 ev->player_add = ecore_event_handler_add(
945 ECORE_EXE_EVENT_ADD, _player_add_cb, ev);
946 ev->player_del = ecore_event_handler_add(
947 ECORE_EXE_EVENT_DEL, _player_del_cb, ev);
948 ev->player_data = ecore_event_handler_add(
949 ECORE_EXE_EVENT_DATA, _player_data_cb, ev);
952 if (!_player_exec(ev))
954 ERR("could not start player.");
958 ev->initializing = EINA_TRUE;
964 em_init(Evas_Object *obj, void **emotion_video, Emotion_Module_Options *opt)
966 Emotion_Generic_Video *ev;
969 if (!emotion_video) return 0;
970 player = _get_player(opt ? opt->player : NULL);
971 if (!player) return 0;
973 ev = (Emotion_Generic_Video *)calloc(1, sizeof(*ev));
980 ev->audio_mute = EINA_FALSE;
984 ev->cmdline = eina_stringshare_add(player);
987 return _fork_and_exec(obj, ev);
991 em_shutdown(void *data)
993 Emotion_Generic_Video *ev = data;
999 ecore_exe_terminate(ev->player.exe);
1000 ecore_exe_free(ev->player.exe);
1001 ev->player.exe = NULL;
1005 munmap(ev->shared, ev->shared->size);
1007 if (ev->fd_read >= 0)
1009 if (ev->fd_write >= 0)
1010 close(ev->fd_write);
1012 ecore_main_fd_handler_del(ev->fd_handler);
1014 eina_stringshare_del(ev->cmdline);
1015 eina_stringshare_del(ev->shmname);
1017 ecore_event_handler_del(ev->player_add);
1018 ecore_event_handler_del(ev->player_data);
1019 ecore_event_handler_del(ev->player_del);
1024 static unsigned char
1025 em_file_open(const char *file, Evas_Object *obj __UNUSED__, void *data)
1027 Emotion_Generic_Video *ev = data;
1028 INF("file set: %s", file);
1031 eina_stringshare_replace(&ev->filename, file);
1039 if (ev->ready && ev->opening)
1041 INF("file changed while opening.");
1042 ev->file_changed = EINA_TRUE;
1046 ev->opening = EINA_TRUE;
1055 em_file_close(void *data)
1057 Emotion_Generic_Video *ev = data;
1059 if (!ev || !ev->filename) return;
1061 INF("file close: %s", ev->filename);
1063 eina_stringshare_replace(&ev->filename, NULL);
1065 ev->file_ready = EINA_FALSE;
1066 _audio_channels_free(ev);
1067 _video_channels_free(ev);
1068 _spu_channels_free(ev);
1069 _player_meta_info_free(ev);
1074 _player_send_cmd(ev, EM_CMD_FILE_CLOSE);
1075 ev->closing = EINA_TRUE;
1078 static Emotion_Format
1079 em_format_get(void *ef __UNUSED__)
1081 return EMOTION_FORMAT_BGRA;
1085 em_video_data_size_get(void *data, int *w, int *h)
1087 Emotion_Generic_Video *ev = data;
1095 em_play(void *data, double pos)
1097 Emotion_Generic_Video *ev = data;
1102 ev->play = EINA_TRUE;
1103 INF("play: %0.3f", pos);
1105 if (ev->initializing || ev->opening)
1110 _player_send_cmd(ev, EM_CMD_PLAY);
1111 _player_send_float(ev, ev->pos);
1115 if (!_player_exec(ev))
1116 ERR("could not start player.");
1122 Emotion_Generic_Video *ev = data;
1127 ev->play = EINA_FALSE;
1129 if (!ev->file_ready)
1132 _player_send_cmd(ev, EM_CMD_STOP);
1133 _emotion_decode_stop(ev->obj);
1137 em_size_get(void *data, int *w, int *h)
1139 Emotion_Generic_Video *ev = data;
1145 em_pos_set(void *data, double pos)
1147 Emotion_Generic_Video *ev = data;
1148 float position = pos;
1150 if (!ev->file_ready)
1153 _player_send_cmd(ev, EM_CMD_POSITION_SET);
1154 _player_send_float(ev, position);
1155 _emotion_seek_done(ev->obj);
1159 em_len_get(void *data)
1161 Emotion_Generic_Video *ev = data;
1166 em_fps_num_get(void *data)
1168 Emotion_Generic_Video *ev = data;
1169 return (int)(ev->fps * 1000.0);
1173 em_fps_den_get(void *ef __UNUSED__)
1179 em_fps_get(void *data)
1181 Emotion_Generic_Video *ev = data;
1186 em_pos_get(void *data)
1188 Emotion_Generic_Video *ev = data;
1193 em_vis_set(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1198 em_vis_get(void *data)
1200 Emotion_Generic_Video *ev = data;
1205 em_vis_supported(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1211 em_ratio_get(void *data)
1213 Emotion_Generic_Video *ev = data;
1217 static int em_video_handled(void *ef __UNUSED__)
1219 fprintf(stderr, "video handled!\n");
1223 static int em_audio_handled(void *ef __UNUSED__)
1225 fprintf(stderr, "audio handled!\n");
1229 static int em_seekable(void *data)
1231 Emotion_Generic_Video *ev = data;
1232 return ev->seekable;
1235 static void em_frame_done(void *ef __UNUSED__)
1240 em_yuv_rows_get(void *data __UNUSED__, int w __UNUSED__, int h __UNUSED__, unsigned char **yrows __UNUSED__, unsigned char **urows __UNUSED__, unsigned char **vrows __UNUSED__)
1246 em_bgra_data_get(void *data, unsigned char **bgra_data)
1248 Emotion_Generic_Video *ev = data;
1250 if (!ev || !ev->file_ready)
1254 if (!eina_semaphore_lock(&ev->shared->lock))
1257 // send current frame to emotion
1258 if (ev->shared->frame.emotion != ev->shared->frame.last)
1260 ev->shared->frame.next = ev->shared->frame.emotion;
1261 ev->shared->frame.emotion = ev->shared->frame.last;
1263 *bgra_data = ev->frame.frames[ev->shared->frame.emotion];
1265 if (ev->shared->frame_drop > 1)
1266 WRN("dropped frames: %d", ev->shared->frame_drop - 1);
1267 ev->shared->frame_drop = 0;
1269 // unlock frame here
1270 eina_semaphore_release(&ev->shared->lock, 1);
1277 em_event_feed(void *ef __UNUSED__, int event __UNUSED__)
1282 em_event_mouse_button_feed(void *ef __UNUSED__, int button __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1287 em_event_mouse_move_feed(void *ef __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1292 em_video_channel_count(void *data)
1294 Emotion_Generic_Video *ev = data;
1295 return ev->video_channels_count;
1299 em_video_channel_set(void *data, int channel)
1301 Emotion_Generic_Video *ev = data;
1303 if (channel < 0 || channel >= ev->video_channels_count)
1305 WRN("video channel out of range.");
1309 _player_send_cmd(ev, EM_CMD_VIDEO_TRACK_SET);
1310 _player_send_int(ev, ev->video_channels[channel].id);
1311 ev->video_channel_current = channel;
1315 em_video_channel_get(void *data)
1317 Emotion_Generic_Video *ev = data;
1318 return ev->video_channel_current;
1322 em_video_channel_name_get(void *data, int channel)
1324 Emotion_Generic_Video *ev = data;
1326 if (channel < 0 || channel >= ev->video_channels_count)
1328 WRN("video channel out of range.");
1332 return ev->video_channels[channel].name;
1336 em_video_channel_mute_set(void *data, int mute)
1338 Emotion_Generic_Video *ev = data;
1340 ev->video_mute = !!mute;
1342 if (!ev || !ev->file_ready)
1345 _player_send_cmd(ev, EM_CMD_VIDEO_MUTE_SET);
1346 _player_send_int(ev, mute);
1350 em_video_channel_mute_get(void *data)
1352 Emotion_Generic_Video *ev = data;
1353 return ev->video_mute;
1357 em_audio_channel_count(void *data)
1359 Emotion_Generic_Video *ev = data;
1360 return ev->audio_channels_count;
1364 em_audio_channel_set(void *data, int channel)
1366 Emotion_Generic_Video *ev = data;
1368 if (channel < 0 || channel >= ev->audio_channels_count)
1370 WRN("audio channel out of range.");
1374 _player_send_cmd(ev, EM_CMD_AUDIO_TRACK_SET);
1375 _player_send_int(ev, ev->audio_channels[channel].id);
1376 ev->audio_channel_current = channel;
1380 em_audio_channel_get(void *data)
1382 Emotion_Generic_Video *ev = data;
1383 return ev->audio_channel_current;
1387 em_audio_channel_name_get(void *data, int channel)
1389 Emotion_Generic_Video *ev = data;
1391 if (channel < 0 || channel >= ev->audio_channels_count)
1393 WRN("audio channel out of range.");
1397 return ev->audio_channels[channel].name;
1401 em_audio_channel_mute_set(void *data, int mute)
1403 Emotion_Generic_Video *ev = data;
1405 ev->audio_mute = !!mute;
1407 if (!ev || !ev->file_ready)
1410 _player_send_cmd(ev, EM_CMD_AUDIO_MUTE_SET);
1411 _player_send_int(ev, mute);
1415 em_audio_channel_mute_get(void *data)
1417 Emotion_Generic_Video *ev = data;
1418 return ev->audio_mute;
1422 em_audio_channel_volume_set(void *data, double vol)
1424 Emotion_Generic_Video *ev = data;
1426 if (vol > 1.0) vol = 1.0;
1427 if (vol < 0.0) vol = 0.0;
1431 if (!ev || !ev->file_ready)
1434 _player_send_cmd(ev, EM_CMD_VOLUME_SET);
1435 _player_send_float(ev, ev->volume);
1439 em_audio_channel_volume_get(void *data)
1441 Emotion_Generic_Video *ev = data;
1446 em_spu_channel_count(void *data)
1448 Emotion_Generic_Video *ev = data;
1449 return ev->spu_channels_count;
1453 em_spu_channel_set(void *data, int channel)
1455 Emotion_Generic_Video *ev = data;
1457 if (channel < 0 || channel >= ev->spu_channels_count)
1459 WRN("spu channel out of range.");
1463 _player_send_cmd(ev, EM_CMD_SPU_TRACK_SET);
1464 _player_send_int(ev, ev->spu_channels[channel].id);
1465 ev->spu_channel_current = channel;
1469 em_spu_channel_get(void *data)
1471 Emotion_Generic_Video *ev = data;
1472 return ev->spu_channel_current;
1476 em_spu_channel_name_get(void *data, int channel)
1478 Emotion_Generic_Video *ev = data;
1480 if (channel < 0 || channel >= ev->spu_channels_count)
1482 WRN("spu channel out of range.");
1486 return ev->spu_channels[channel].name;
1490 em_spu_channel_mute_set(void *data, int mute)
1492 Emotion_Generic_Video *ev = data;
1494 ev->spu_mute = !!mute;
1496 if (!ev || !ev->file_ready)
1499 _player_send_cmd(ev, EM_CMD_SPU_MUTE_SET);
1500 _player_send_int(ev, mute);
1504 em_spu_channel_mute_get(void *data)
1506 Emotion_Generic_Video *ev = data;
1507 return ev->spu_mute;
1511 em_chapter_count(void *ef __UNUSED__)
1518 em_chapter_set(void *ef __UNUSED__, int chapter __UNUSED__)
1523 em_chapter_get(void *ef __UNUSED__)
1530 em_chapter_name_get(void *ef __UNUSED__, int chapter __UNUSED__)
1536 em_speed_set(void *data, double speed)
1538 Emotion_Generic_Video *ev = data;
1542 if (!ev || !ev->file_ready)
1545 _player_send_cmd(ev, EM_CMD_SPEED_SET);
1546 _player_send_float(ev, rate);
1550 em_speed_get(void *data)
1552 Emotion_Generic_Video *ev = data;
1553 return (double)ev->speed;
1557 em_eject(void *ef __UNUSED__)
1563 em_meta_get(void *data, int meta)
1565 Emotion_Generic_Video *ev = data;
1568 case EMOTION_META_INFO_TRACK_TITLE:
1569 return ev->meta.title;
1570 case EMOTION_META_INFO_TRACK_ARTIST:
1571 return ev->meta.artist;
1572 case EMOTION_META_INFO_TRACK_ALBUM:
1573 return ev->meta.album;
1574 case EMOTION_META_INFO_TRACK_YEAR:
1575 return ev->meta.year;
1576 case EMOTION_META_INFO_TRACK_GENRE:
1577 return ev->meta.genre;
1578 case EMOTION_META_INFO_TRACK_COMMENT:
1579 return ev->meta.comment;
1580 case EMOTION_META_INFO_TRACK_DISC_ID:
1581 return ev->meta.disc_id;
1582 case EMOTION_META_INFO_TRACK_COUNT:
1583 return ev->meta.count;
1589 static Emotion_Video_Module em_module =
1592 em_shutdown, /* shutdown */
1593 em_file_open, /* file_open */
1594 em_file_close, /* file_close */
1597 em_size_get, /* size_get */
1598 em_pos_set, /* pos_set */
1599 em_len_get, /* len_get */
1600 em_fps_num_get, /* fps_num_get */
1601 em_fps_den_get, /* fps_den_get */
1602 em_fps_get, /* fps_get */
1603 em_pos_get, /* pos_get */
1604 em_vis_set, /* vis_set */
1605 em_vis_get, /* vis_get */
1606 em_vis_supported, /* vis_supported */
1607 em_ratio_get, /* ratio_get */
1608 em_video_handled, /* video_handled */
1609 em_audio_handled, /* audio_handled */
1610 em_seekable, /* seekable */
1611 em_frame_done, /* frame_done */
1612 em_format_get, /* format_get */
1613 em_video_data_size_get, /* video_data_size_get */
1614 em_yuv_rows_get, /* yuv_rows_get */
1615 em_bgra_data_get, /* bgra_data_get */
1616 em_event_feed, /* event_feed */
1617 em_event_mouse_button_feed, /* event_mouse_button_feed */
1618 em_event_mouse_move_feed, /* event_mouse_move_feed */
1619 em_video_channel_count, /* video_channel_count */
1620 em_video_channel_set, /* video_channel_set */
1621 em_video_channel_get, /* video_channel_get */
1622 em_video_channel_name_get, /* video_channel_name_get */
1623 em_video_channel_mute_set, /* video_channel_mute_set */
1624 em_video_channel_mute_get, /* video_channel_mute_get */
1625 em_audio_channel_count, /* audio_channel_count */
1626 em_audio_channel_set, /* audio_channel_set */
1627 em_audio_channel_get, /* audio_channel_get */
1628 em_audio_channel_name_get, /* audio_channel_name_get */
1629 em_audio_channel_mute_set, /* audio_channel_mute_set */
1630 em_audio_channel_mute_get, /* audio_channel_mute_get */
1631 em_audio_channel_volume_set, /* audio_channel_volume_set */
1632 em_audio_channel_volume_get, /* audio_channel_volume_get */
1633 em_spu_channel_count, /* spu_channel_count */
1634 em_spu_channel_set, /* spu_channel_set */
1635 em_spu_channel_get, /* spu_channel_get */
1636 em_spu_channel_name_get, /* spu_channel_name_get */
1637 em_spu_channel_mute_set, /* spu_channel_mute_set */
1638 em_spu_channel_mute_get, /* spu_channel_mute_get */
1639 em_chapter_count, /* chapter_count */
1640 em_chapter_set, /* chapter_set */
1641 em_chapter_get, /* chapter_get */
1642 em_chapter_name_get, /* chapter_name_get */
1643 em_speed_set, /* speed_set */
1644 em_speed_get, /* speed_get */
1645 em_eject, /* eject */
1646 em_meta_get, /* meta_get */
1647 NULL, /* priority_set */
1648 NULL, /* priority_get */
1653 module_open(Evas_Object *obj, const Emotion_Video_Module **module, void **video, Emotion_Module_Options *opt)
1659 if (_emotion_generic_log_domain < 0)
1661 eina_threads_init();
1662 eina_log_threads_enable();
1663 _emotion_generic_log_domain = eina_log_domain_register
1664 ("emotion-generic", EINA_COLOR_LIGHTCYAN);
1665 if (_emotion_generic_log_domain < 0)
1667 EINA_LOG_CRIT("Could not register log domain 'emotion-generic'");
1673 if (!em_module.init(obj, video, opt)) {
1677 *module = &em_module;
1682 static void module_close(Emotion_Video_Module *module __UNUSED__, void *video)
1684 em_module.shutdown(video);
1689 generic_module_init(void)
1693 pfx = eina_prefix_new(NULL, emotion_object_add,
1694 "EMOTION", "emotion", NULL,
1699 if (!pfx) return EINA_FALSE;
1701 return _emotion_module_register("generic", module_open, module_close);
1705 generic_module_shutdown(void)
1709 eina_prefix_free(pfx);
1712 _emotion_module_unregister("generic");
1715 #ifndef EMOTION_STATIC_BUILD_GENERIC
1717 EINA_MODULE_INIT(generic_module_init);
1718 EINA_MODULE_SHUTDOWN(generic_module_shutdown);