14 #include "emotion_private.h"
15 #include "emotion_generic.h"
17 static Eina_Prefix *pfx = NULL;
19 static int _emotion_generic_log_domain = -1;
20 #define DBG(...) EINA_LOG_DOM_DBG(_emotion_generic_log_domain, __VA_ARGS__)
21 #define INF(...) EINA_LOG_DOM_INFO(_emotion_generic_log_domain, __VA_ARGS__)
22 #define WRN(...) EINA_LOG_DOM_WARN(_emotion_generic_log_domain, __VA_ARGS__)
23 #define ERR(...) EINA_LOG_DOM_ERR(_emotion_generic_log_domain, __VA_ARGS__)
24 #define CRITICAL(...) EINA_LOG_DOM_CRIT(_emotion_generic_log_domain, __VA_ARGS__)
27 struct _default_players {
32 static struct _default_players players[] = {
33 #ifdef EMOTION_BUILD_GENERIC_VLC
34 { "vlc", "em_generic_vlc" },
40 _get_player(const char *name)
42 const char *selected_name = NULL;
43 const char *libdir = eina_prefix_lib_get(pfx);
44 static char buf[PATH_MAX];
49 for (i = 0; players[i].name; i++)
51 if (!strcmp(players[i].name, name))
53 selected_name = players[i].cmdline;
59 if ((!selected_name) && (name))
66 if (selected_name[0] == '/') cmd = selected_name;
69 snprintf(buf, sizeof(buf), "%s/emotion/utils/%s",
70 libdir, selected_name);
74 DBG("Try generic player '%s'", cmd);
75 if (access(cmd, R_OK | X_OK) == 0)
77 INF("Using generic player '%s'", cmd);
82 for (i = 0; players[i].name; i++)
84 snprintf(buf, sizeof(buf), "%s/emotion/utils/%s",
85 libdir, players[i].cmdline);
86 DBG("Try generic player '%s'", buf);
87 if (access(buf, R_OK | X_OK) == 0)
89 INF("Using fallback player '%s'", buf);
94 ERR("no generic player found, given name='%s'", name ? name : "");
99 _player_send_cmd(Emotion_Generic_Video *ev, int cmd)
101 if (cmd >= EM_CMD_LAST)
103 ERR("invalid command to player.");
106 write(ev->fd_write, &cmd, sizeof(cmd));
110 _player_send_int(Emotion_Generic_Video *ev, int number)
112 write(ev->fd_write, &number, sizeof(number));
116 _player_send_float(Emotion_Generic_Video *ev, float number)
118 write(ev->fd_write, &number, sizeof(number));
122 _player_send_str(Emotion_Generic_Video *ev, const char *str, Eina_Bool stringshared)
127 len = eina_stringshare_strlen(str) + 1;
129 len = strlen(str) + 1;
130 write(ev->fd_write, &len, sizeof(len));
131 write(ev->fd_write, str, len);
135 _create_shm_data(Emotion_Generic_Video *ev, const char *shmname)
140 Emotion_Generic_Video_Shared *vs;
142 shmfd = shm_open(shmname, O_CREAT | O_RDWR | O_TRUNC, 0777);
145 ERR("player: could not open shm: %s", shmname);
146 ERR("player: %s", strerror(errno));
149 size = 3 * (ev->w * ev->h * DEFAULTPITCH) + sizeof(*vs);
151 npages = (int)(size / getpagesize()) + 1;
152 size = npages * getpagesize();
154 if (ftruncate(shmfd, size))
156 ERR("error when allocating shared memory (size = %zd): "
157 "%s", size, strerror(errno));
161 vs = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
162 if (vs == MAP_FAILED)
164 ERR("error when mapping shared memory.\n");
171 vs->pitch = DEFAULTPITCH;
172 vs->frame.emotion = 0;
173 vs->frame.player = 1;
177 sem_init(&vs->lock, 1, 1);
178 ev->frame.frames[0] = (unsigned char *)vs + sizeof(*vs);
179 ev->frame.frames[1] = (unsigned char *)vs + sizeof(*vs) + vs->height * vs->width * vs->pitch;
180 ev->frame.frames[2] = (unsigned char *)vs + sizeof(*vs) + 2 * vs->height * vs->width * vs->pitch;
183 munmap(ev->shared, ev->shared->size);
190 _player_new_frame(Emotion_Generic_Video *ev)
194 _emotion_frame_new(ev->obj);
198 _file_open(Emotion_Generic_Video *ev)
200 INF("Opening file: %s", ev->filename);
203 if (!ev->ready || !ev->filename)
205 _player_send_cmd(ev, EM_CMD_FILE_SET);
206 _player_send_str(ev, ev->filename, EINA_TRUE);
210 _player_file_set_done(Emotion_Generic_Video *ev)
212 if (ev->file_changed)
215 ev->file_changed = EINA_FALSE;
219 if (!_create_shm_data(ev, ev->shmname))
221 ERR("could not create shared memory.");
224 _player_send_cmd(ev, EM_CMD_FILE_SET_DONE);
228 _player_ready(Emotion_Generic_Video *ev)
230 INF("received: player ready.");
232 ev->initializing = EINA_FALSE;
233 ev->ready = EINA_TRUE;
242 _em_read_safe(int fd, void *buf, ssize_t size)
254 r = read(fd, p, todo);
264 if (errno == EINTR || errno == EAGAIN)
268 ERR("could not read from fd %d: %s", fd, strerror(errno));
278 _player_cmd_param_read(Emotion_Generic_Video *ev, void *param, size_t size)
280 ssize_t done, todo, i;
282 /* When a parameter must be read, we cannot make sure it will be entirely
283 * available. Thus we store the bytes that could be read in a temp buffer,
284 * and when more data is read we try to complete the buffer and finally use
289 ev->cmd.tmp = malloc(size);
291 ev->cmd.total = size;
294 todo = ev->cmd.total - ev->cmd.i;
296 done = read(ev->fd_read, &ev->cmd.tmp[i], todo);
298 if (done < 0 && errno != EINTR && errno != EAGAIN)
305 ERR("problem when reading parameter from pipe.");
312 memcpy(param, ev->cmd.tmp, size);
325 _player_int_read(Emotion_Generic_Video *ev, int *i)
328 n = _em_read_safe(ev->fd_read, i, sizeof(*i));
331 ERR("could not read int from fd_read %d\n", ev->fd_read);
339 _player_str_read(Emotion_Generic_Video *ev, char *str, int *len)
343 if (!_player_int_read(ev, len))
346 n = _em_read_safe(ev->fd_read, str, *len);
349 ERR("could not read string from fd_read %d\n", ev->fd_read);
357 _player_frame_resize(Emotion_Generic_Video *ev)
361 w = ev->cmd.param.size.width;
362 h = ev->cmd.param.size.height;
364 INF("received frame resize: %dx%d", w, h);
367 ev->ratio = (float)w / h;
372 _emotion_frame_resize(ev->obj, ev->w, ev->h, ev->ratio);
376 _player_length_changed(Emotion_Generic_Video *ev)
378 float length = ev->cmd.param.f_num;
380 INF("received length changed: %0.3f", length);
383 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
387 _player_position_changed(Emotion_Generic_Video *ev)
389 float position = ev->cmd.param.f_num;
391 INF("received position changed: %0.3f", position);
394 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
399 float progress = ev->pos / ev->len;
401 snprintf(buf, sizeof(buf), "%0.1f%%", progress * 100);
403 _emotion_progress_set(ev->obj, buf, progress);
407 _player_seekable_changed(Emotion_Generic_Video *ev)
409 int seekable = ev->cmd.param.i_num;
411 INF("received seekable changed: %d", seekable);
413 seekable = !!seekable;
415 ev->seekable = seekable;
419 _audio_channels_free(Emotion_Generic_Video *ev)
422 for (i = 0; i < ev->audio_channels_count; i++)
423 eina_stringshare_del(ev->audio_channels[i].name);
424 free(ev->audio_channels);
425 ev->audio_channels_count = 0;
429 _video_channels_free(Emotion_Generic_Video *ev)
432 for (i = 0; i < ev->video_channels_count; i++)
433 eina_stringshare_del(ev->video_channels[i].name);
434 free(ev->video_channels);
435 ev->video_channels_count = 0;
439 _spu_channels_free(Emotion_Generic_Video *ev)
442 for (i = 0; i < ev->spu_channels_count; i++)
443 eina_stringshare_del(ev->spu_channels[i].name);
444 free(ev->spu_channels);
445 ev->spu_channels_count = 0;
449 _player_tracks_info(Emotion_Generic_Video *ev, Emotion_Generic_Channel **channels, int *count, int *current)
451 Emotion_Generic_Channel *pchannels;
454 *count = ev->cmd.param.track.total;
455 *current = ev->cmd.param.track.current;
456 pchannels = ev->cmd.param.track.channels;
458 INF("number of tracks: %d (current = %d):", *count, *current);
459 for (i = 0; i < *count; i++)
461 INF("\tchannel %d: %s", pchannels[i].id, pchannels[i].name);
464 *channels = pchannels;
468 _player_audio_tracks_info(Emotion_Generic_Video *ev)
470 INF("Receiving audio channels:");
471 if (ev->audio_channels_count)
472 _audio_channels_free(ev);
474 _player_tracks_info(ev, &ev->audio_channels, &ev->audio_channels_count,
475 &ev->audio_channel_current);
479 _player_video_tracks_info(Emotion_Generic_Video *ev)
481 INF("Receiving video channels:");
482 if (ev->video_channels_count)
483 _video_channels_free(ev);
485 _player_tracks_info(ev, &ev->video_channels, &ev->video_channels_count,
486 &ev->video_channel_current);
490 _player_spu_tracks_info(Emotion_Generic_Video *ev)
492 INF("Receiving spu channels:");
493 if (ev->spu_channels_count)
494 _spu_channels_free(ev);
496 _player_tracks_info(ev, &ev->spu_channels, &ev->spu_channels_count,
497 &ev->spu_channel_current);
501 _player_helper_str_read(Emotion_Generic_Video *ev, const char **pstr)
505 if (_player_str_read(ev, buf, &len))
506 *pstr = eina_stringshare_add_length(buf, len);
510 _player_meta_info_free(Emotion_Generic_Video *ev)
512 eina_stringshare_replace(&ev->meta.title, NULL);
513 eina_stringshare_replace(&ev->meta.artist, NULL);
514 eina_stringshare_replace(&ev->meta.album, NULL);
515 eina_stringshare_replace(&ev->meta.year, NULL);
516 eina_stringshare_replace(&ev->meta.genre, NULL);
517 eina_stringshare_replace(&ev->meta.comment, NULL);
518 eina_stringshare_replace(&ev->meta.disc_id, NULL);
519 eina_stringshare_replace(&ev->meta.count, NULL);
523 _player_meta_info_read(Emotion_Generic_Video *ev)
525 INF("Receiving meta info:");
526 _player_meta_info_free(ev);
527 _player_helper_str_read(ev, &ev->meta.title);
528 _player_helper_str_read(ev, &ev->meta.artist);
529 _player_helper_str_read(ev, &ev->meta.album);
530 _player_helper_str_read(ev, &ev->meta.year);
531 _player_helper_str_read(ev, &ev->meta.genre);
532 _player_helper_str_read(ev, &ev->meta.comment);
533 _player_helper_str_read(ev, &ev->meta.disc_id);
534 _player_helper_str_read(ev, &ev->meta.count);
535 INF("title: '%s'", ev->meta.title);
536 INF("artist: '%s'", ev->meta.artist);
537 INF("album: '%s'", ev->meta.album);
538 INF("year: '%s'", ev->meta.year);
539 INF("genre: '%s'", ev->meta.genre);
540 INF("comment: '%s'", ev->meta.comment);
541 INF("disc_id: '%s'", ev->meta.disc_id);
542 INF("count: '%s'", ev->meta.count);
546 _player_file_closed(Emotion_Generic_Video *ev)
548 INF("Closed previous file.");
549 sem_destroy(&ev->shared->lock);
551 ev->closing = EINA_FALSE;
558 _player_open_done(Emotion_Generic_Video *ev)
562 success = ev->cmd.param.i_num;
563 shm_unlink(ev->shmname);
565 if (ev->file_changed)
568 ev->file_changed = EINA_FALSE;
572 ev->opening = EINA_FALSE;
575 ERR("Could not open file.");
579 ev->file_ready = EINA_TRUE;
581 _emotion_open_done(ev->obj);
585 _player_send_cmd(ev, EM_CMD_PLAY);
586 _player_send_float(ev, ev->pos);
589 _player_send_cmd(ev, EM_CMD_VOLUME_SET);
590 _player_send_float(ev, ev->volume);
592 _player_send_cmd(ev, EM_CMD_SPEED_SET);
593 _player_send_float(ev, ev->speed);
595 int mute = ev->audio_mute;
596 _player_send_cmd(ev, EM_CMD_AUDIO_MUTE_SET);
597 _player_send_int(ev, mute);
599 mute = ev->video_mute;
600 _player_send_cmd(ev, EM_CMD_VIDEO_MUTE_SET);
601 _player_send_int(ev, mute);
604 _player_send_cmd(ev, EM_CMD_SPU_MUTE_SET);
605 _player_send_int(ev, mute);
611 _player_cmd_process(Emotion_Generic_Video *ev)
613 switch (ev->cmd.type) {
617 case EM_RESULT_FRAME_NEW:
618 _player_new_frame(ev);
620 case EM_RESULT_FILE_SET:
621 _player_file_set_done(ev);
623 case EM_RESULT_FILE_SET_DONE:
624 _player_open_done(ev);
626 case EM_RESULT_FILE_CLOSE:
627 _player_file_closed(ev);
629 case EM_RESULT_PLAYBACK_STOPPED:
630 _emotion_playback_finished(ev->obj);
632 case EM_RESULT_FRAME_SIZE:
633 _player_frame_resize(ev);
635 case EM_RESULT_LENGTH_CHANGED:
636 _player_length_changed(ev);
638 case EM_RESULT_POSITION_CHANGED:
639 _player_position_changed(ev);
641 case EM_RESULT_SEEKABLE_CHANGED:
642 _player_seekable_changed(ev);
644 case EM_RESULT_AUDIO_TRACK_INFO:
645 _player_audio_tracks_info(ev);
647 case EM_RESULT_VIDEO_TRACK_INFO:
648 _player_video_tracks_info(ev);
650 case EM_RESULT_SPU_TRACK_INFO:
651 _player_spu_tracks_info(ev);
653 case EM_RESULT_META_INFO:
654 _player_meta_info_read(ev);
657 WRN("received wrong command: %d", ev->cmd.type);
664 _player_cmd_single_int_process(Emotion_Generic_Video *ev)
666 if (!_player_cmd_param_read(ev, &ev->cmd.param.i_num, sizeof(ev->cmd.param.i_num)))
669 _player_cmd_process(ev);
673 _player_cmd_single_float_process(Emotion_Generic_Video *ev)
675 if (!_player_cmd_param_read(ev, &ev->cmd.param.f_num, sizeof(ev->cmd.param.f_num)))
678 _player_cmd_process(ev);
682 _player_cmd_double_int_process(Emotion_Generic_Video *ev)
686 if (ev->cmd.num_params == 0)
688 ev->cmd.num_params = 2;
689 ev->cmd.cur_param = 0;
690 ev->cmd.param.size.width = 0;
691 ev->cmd.param.size.height = 0;
694 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
697 if (ev->cmd.cur_param == 0)
698 ev->cmd.param.size.width = param;
700 ev->cmd.param.size.height = param;
703 if (ev->cmd.cur_param == ev->cmd.num_params)
704 _player_cmd_process(ev);
708 _player_cmd_track_info(Emotion_Generic_Video *ev)
714 if (ev->cmd.num_params == 0)
716 ev->cmd.cur_param = 0;
717 ev->cmd.num_params = 2;
718 ev->cmd.param.track.channels = NULL;
722 while (ev->cmd.cur_param < 2)
724 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
727 if (ev->cmd.cur_param == 0)
728 ev->cmd.param.track.current = param;
731 ev->cmd.param.track.total = param;
732 ev->cmd.num_params += param * 2;
733 ev->cmd.param.track.channels =
734 calloc(param, sizeof(*ev->cmd.param.track.channels));
739 if (ev->cmd.cur_param == ev->cmd.num_params)
741 _player_cmd_process(ev);
745 i = (ev->cmd.cur_param - 2) / 2;
746 if ((ev->cmd.cur_param % 2) == 0) // reading track id
748 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
750 ev->cmd.param.track.channels[i].id = param;
753 else // reading track name
757 if (ev->cmd.s_len == -1)
759 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
761 ev->cmd.s_len = param;
764 if (!_player_cmd_param_read(ev, buf, ev->cmd.s_len))
766 ev->cmd.param.track.channels[i].name =
767 eina_stringshare_add_length(buf, ev->cmd.s_len);
772 if (ev->cmd.cur_param == ev->cmd.num_params)
773 _player_cmd_process(ev);
777 _player_cmd_read(Emotion_Generic_Video *ev)
779 if (ev->cmd.type < 0)
781 if (!_player_cmd_param_read(ev, &ev->cmd.type, sizeof(ev->cmd.type)))
783 ev->cmd.num_params = 0;
786 switch (ev->cmd.type) {
788 case EM_RESULT_FILE_SET:
789 case EM_RESULT_PLAYBACK_STOPPED:
790 case EM_RESULT_FILE_CLOSE:
791 case EM_RESULT_FRAME_NEW:
792 _player_cmd_process(ev);
794 case EM_RESULT_FILE_SET_DONE:
795 case EM_RESULT_SEEKABLE_CHANGED:
796 _player_cmd_single_int_process(ev);
798 case EM_RESULT_LENGTH_CHANGED:
799 case EM_RESULT_POSITION_CHANGED:
800 _player_cmd_single_float_process(ev);
802 case EM_RESULT_FRAME_SIZE:
803 _player_cmd_double_int_process(ev);
805 case EM_RESULT_AUDIO_TRACK_INFO:
806 case EM_RESULT_VIDEO_TRACK_INFO:
807 case EM_RESULT_SPU_TRACK_INFO:
808 _player_cmd_track_info(ev);
812 WRN("received wrong command: %d", ev->cmd.type);
818 _player_cmd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler)
820 Emotion_Generic_Video *ev = data;
822 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
824 ERR("an error occurred on fd_read %d.", ev->fd_read);
825 return ECORE_CALLBACK_CANCEL;
828 _player_cmd_read(ev);
830 return ECORE_CALLBACK_RENEW;
834 _player_data_cb(void *data, int type __UNUSED__, void *event)
836 Ecore_Exe_Event_Data *ev = event;
837 Emotion_Generic_Video *evideo = data;
840 if (ev->exe != evideo->player.exe)
842 ERR("slave != ev->exe");
843 return ECORE_CALLBACK_DONE;
846 for (i = 0; ev->lines[i].line; i++)
847 INF("received input from player: \"%s\"", ev->lines[i].line);
849 return ECORE_CALLBACK_DONE;
853 _player_add_cb(void *data, int type __UNUSED__, void *event)
855 Ecore_Exe_Event_Add *event_add = event;
856 Ecore_Exe *player = event_add->exe;
857 Emotion_Generic_Video *ev = data;
859 if (ev->player.exe != player)
861 ERR("ev->player != player.");
862 return ECORE_CALLBACK_DONE;
865 _player_send_cmd(ev, EM_CMD_INIT);
866 _player_send_str(ev, ev->shmname, EINA_TRUE);
868 return ECORE_CALLBACK_DONE;
872 _player_del_cb(void *data, int type __UNUSED__, void *event __UNUSED__)
874 Emotion_Generic_Video *ev = data;
877 ev->player.exe = NULL;
878 ev->ready = EINA_FALSE;
879 ev->file_ready = EINA_FALSE;
880 ecore_main_fd_handler_del(ev->fd_handler);
885 _emotion_decode_stop(ev->obj);
887 return ECORE_CALLBACK_DONE;
891 _player_exec(Emotion_Generic_Video *ev)
897 if (pipe(pipe_out) == -1)
899 ERR("could not create pipe for communication emotion -> player: %s", strerror(errno));
903 if (pipe(pipe_in) == -1)
905 ERR("could not create pipe for communication player -> emotion: %s", strerror(errno));
911 snprintf(buf, sizeof(buf), "%s %d %d\n", ev->cmdline, pipe_out[0], pipe_in[1]);
913 ev->player.exe = ecore_exe_pipe_run(
915 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE |
916 ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_NOT_LEADER,
919 INF("created pipe emotion -> player: %d -> %d\n", pipe_out[1], pipe_out[0]);
920 INF("created pipe player -> emotion: %d -> %d\n", pipe_in[1], pipe_in[0]);
932 ev->fd_read = pipe_in[0];
933 ev->fd_write = pipe_out[1];
935 ev->fd_handler = ecore_main_fd_handler_add(
936 ev->fd_read, ECORE_FD_READ | ECORE_FD_ERROR, _player_cmd_handler_cb, ev,
943 _fork_and_exec(Evas_Object *obj, Emotion_Generic_Video *ev)
948 gettimeofday(&tv, NULL);
949 snprintf(shmname, sizeof(shmname), "/em-generic-shm_%d_%d",
950 (int)tv.tv_sec, (int)tv.tv_usec);
952 ev->shmname = eina_stringshare_add(shmname);
954 ev->player_add = ecore_event_handler_add(
955 ECORE_EXE_EVENT_ADD, _player_add_cb, ev);
956 ev->player_del = ecore_event_handler_add(
957 ECORE_EXE_EVENT_DEL, _player_del_cb, ev);
958 ev->player_data = ecore_event_handler_add(
959 ECORE_EXE_EVENT_DATA, _player_data_cb, ev);
962 if (!_player_exec(ev))
964 ERR("could not start player.");
968 ev->initializing = EINA_TRUE;
974 em_init(Evas_Object *obj, void **emotion_video, Emotion_Module_Options *opt)
976 Emotion_Generic_Video *ev;
979 if (!emotion_video) return 0;
980 player = _get_player(opt ? opt->player : NULL);
981 if (!player) return 0;
983 ev = (Emotion_Generic_Video *)calloc(1, sizeof(*ev));
990 ev->audio_mute = EINA_FALSE;
994 ev->cmdline = eina_stringshare_add(player);
997 return _fork_and_exec(obj, ev);
1001 em_shutdown(void *data)
1003 Emotion_Generic_Video *ev = data;
1009 ecore_exe_terminate(ev->player.exe);
1010 ecore_exe_free(ev->player.exe);
1011 ev->player.exe = NULL;
1015 munmap(ev->shared, ev->shared->size);
1017 if (ev->fd_read >= 0)
1019 if (ev->fd_write >= 0)
1020 close(ev->fd_write);
1022 ecore_main_fd_handler_del(ev->fd_handler);
1024 eina_stringshare_del(ev->cmdline);
1025 eina_stringshare_del(ev->shmname);
1027 ecore_event_handler_del(ev->player_add);
1028 ecore_event_handler_del(ev->player_data);
1029 ecore_event_handler_del(ev->player_del);
1034 static unsigned char
1035 em_file_open(const char *file, Evas_Object *obj __UNUSED__, void *data)
1037 Emotion_Generic_Video *ev = data;
1038 INF("file set: %s", file);
1041 eina_stringshare_replace(&ev->filename, file);
1049 if (ev->ready && ev->opening)
1051 INF("file changed while opening.");
1052 ev->file_changed = EINA_TRUE;
1056 ev->opening = EINA_TRUE;
1065 em_file_close(void *data)
1067 Emotion_Generic_Video *ev = data;
1069 if (!ev || !ev->filename) return;
1071 INF("file close: %s", ev->filename);
1073 eina_stringshare_replace(&ev->filename, NULL);
1075 ev->file_ready = EINA_FALSE;
1076 _audio_channels_free(ev);
1077 _video_channels_free(ev);
1078 _spu_channels_free(ev);
1079 _player_meta_info_free(ev);
1084 _player_send_cmd(ev, EM_CMD_FILE_CLOSE);
1085 ev->closing = EINA_TRUE;
1088 static Emotion_Format
1089 em_format_get(void *ef __UNUSED__)
1091 return EMOTION_FORMAT_BGRA;
1095 em_video_data_size_get(void *data, int *w, int *h)
1097 Emotion_Generic_Video *ev = data;
1105 em_play(void *data, double pos)
1107 Emotion_Generic_Video *ev = data;
1112 ev->play = EINA_TRUE;
1113 INF("play: %0.3f", pos);
1115 if (ev->initializing || ev->opening)
1120 _player_send_cmd(ev, EM_CMD_PLAY);
1121 _player_send_float(ev, ev->pos);
1125 if (!_player_exec(ev))
1126 ERR("could not start player.");
1132 Emotion_Generic_Video *ev = data;
1137 ev->play = EINA_FALSE;
1139 if (!ev->file_ready)
1142 _player_send_cmd(ev, EM_CMD_STOP);
1143 _emotion_decode_stop(ev->obj);
1147 em_size_get(void *data, int *w, int *h)
1149 Emotion_Generic_Video *ev = data;
1155 em_pos_set(void *data, double pos)
1157 Emotion_Generic_Video *ev = data;
1158 float position = pos;
1160 if (!ev->file_ready)
1163 _player_send_cmd(ev, EM_CMD_POSITION_SET);
1164 _player_send_float(ev, position);
1165 _emotion_seek_done(ev->obj);
1169 em_len_get(void *data)
1171 Emotion_Generic_Video *ev = data;
1176 em_fps_num_get(void *data)
1178 Emotion_Generic_Video *ev = data;
1179 return (int)(ev->fps * 1000.0);
1183 em_fps_den_get(void *ef __UNUSED__)
1189 em_fps_get(void *data)
1191 Emotion_Generic_Video *ev = data;
1196 em_pos_get(void *data)
1198 Emotion_Generic_Video *ev = data;
1203 em_vis_set(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1208 em_vis_get(void *data)
1210 Emotion_Generic_Video *ev = data;
1215 em_vis_supported(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1221 em_ratio_get(void *data)
1223 Emotion_Generic_Video *ev = data;
1227 static int em_video_handled(void *ef __UNUSED__)
1229 fprintf(stderr, "video handled!\n");
1233 static int em_audio_handled(void *ef __UNUSED__)
1235 fprintf(stderr, "audio handled!\n");
1239 static int em_seekable(void *data)
1241 Emotion_Generic_Video *ev = data;
1242 return ev->seekable;
1245 static void em_frame_done(void *ef __UNUSED__)
1250 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__)
1256 em_bgra_data_get(void *data, unsigned char **bgra_data)
1258 Emotion_Generic_Video *ev = data;
1260 if (!ev || !ev->file_ready)
1264 sem_wait(&ev->shared->lock);
1266 // send current frame to emotion
1267 if (ev->shared->frame.emotion != ev->shared->frame.last)
1269 ev->shared->frame.next = ev->shared->frame.emotion;
1270 ev->shared->frame.emotion = ev->shared->frame.last;
1272 *bgra_data = ev->frame.frames[ev->shared->frame.emotion];
1274 if (ev->shared->frame_drop > 1)
1275 WRN("dropped frames: %d", ev->shared->frame_drop - 1);
1276 ev->shared->frame_drop = 0;
1278 // unlock frame here
1279 sem_post(&ev->shared->lock);
1286 em_event_feed(void *ef __UNUSED__, int event __UNUSED__)
1291 em_event_mouse_button_feed(void *ef __UNUSED__, int button __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1296 em_event_mouse_move_feed(void *ef __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1301 em_video_channel_count(void *data)
1303 Emotion_Generic_Video *ev = data;
1304 return ev->video_channels_count;
1308 em_video_channel_set(void *data, int channel)
1310 Emotion_Generic_Video *ev = data;
1312 if (channel < 0 || channel >= ev->video_channels_count)
1314 WRN("video channel out of range.");
1318 _player_send_cmd(ev, EM_CMD_VIDEO_TRACK_SET);
1319 _player_send_int(ev, ev->video_channels[channel].id);
1320 ev->video_channel_current = channel;
1324 em_video_channel_get(void *data)
1326 Emotion_Generic_Video *ev = data;
1327 return ev->video_channel_current;
1331 em_video_channel_name_get(void *data, int channel)
1333 Emotion_Generic_Video *ev = data;
1335 if (channel < 0 || channel >= ev->video_channels_count)
1337 WRN("video channel out of range.");
1341 return ev->video_channels[channel].name;
1345 em_video_channel_mute_set(void *data, int mute)
1347 Emotion_Generic_Video *ev = data;
1349 ev->video_mute = !!mute;
1351 if (!ev || !ev->file_ready)
1354 _player_send_cmd(ev, EM_CMD_VIDEO_MUTE_SET);
1355 _player_send_int(ev, mute);
1359 em_video_channel_mute_get(void *data)
1361 Emotion_Generic_Video *ev = data;
1362 return ev->video_mute;
1366 em_audio_channel_count(void *data)
1368 Emotion_Generic_Video *ev = data;
1369 return ev->audio_channels_count;
1373 em_audio_channel_set(void *data, int channel)
1375 Emotion_Generic_Video *ev = data;
1377 if (channel < 0 || channel >= ev->audio_channels_count)
1379 WRN("audio channel out of range.");
1383 _player_send_cmd(ev, EM_CMD_AUDIO_TRACK_SET);
1384 _player_send_int(ev, ev->audio_channels[channel].id);
1385 ev->audio_channel_current = channel;
1389 em_audio_channel_get(void *data)
1391 Emotion_Generic_Video *ev = data;
1392 return ev->audio_channel_current;
1396 em_audio_channel_name_get(void *data, int channel)
1398 Emotion_Generic_Video *ev = data;
1400 if (channel < 0 || channel >= ev->audio_channels_count)
1402 WRN("audio channel out of range.");
1406 return ev->audio_channels[channel].name;
1410 em_audio_channel_mute_set(void *data, int mute)
1412 Emotion_Generic_Video *ev = data;
1414 ev->audio_mute = !!mute;
1416 if (!ev || !ev->file_ready)
1419 _player_send_cmd(ev, EM_CMD_AUDIO_MUTE_SET);
1420 _player_send_int(ev, mute);
1424 em_audio_channel_mute_get(void *data)
1426 Emotion_Generic_Video *ev = data;
1427 return ev->audio_mute;
1431 em_audio_channel_volume_set(void *data, double vol)
1433 Emotion_Generic_Video *ev = data;
1435 if (vol > 1.0) vol = 1.0;
1436 if (vol < 0.0) vol = 0.0;
1440 if (!ev || !ev->file_ready)
1443 _player_send_cmd(ev, EM_CMD_VOLUME_SET);
1444 _player_send_float(ev, ev->volume);
1448 em_audio_channel_volume_get(void *data)
1450 Emotion_Generic_Video *ev = data;
1455 em_spu_channel_count(void *data)
1457 Emotion_Generic_Video *ev = data;
1458 return ev->spu_channels_count;
1462 em_spu_channel_set(void *data, int channel)
1464 Emotion_Generic_Video *ev = data;
1466 if (channel < 0 || channel >= ev->spu_channels_count)
1468 WRN("spu channel out of range.");
1472 _player_send_cmd(ev, EM_CMD_SPU_TRACK_SET);
1473 _player_send_int(ev, ev->spu_channels[channel].id);
1474 ev->spu_channel_current = channel;
1478 em_spu_channel_get(void *data)
1480 Emotion_Generic_Video *ev = data;
1481 return ev->spu_channel_current;
1485 em_spu_channel_name_get(void *data, int channel)
1487 Emotion_Generic_Video *ev = data;
1489 if (channel < 0 || channel >= ev->spu_channels_count)
1491 WRN("spu channel out of range.");
1495 return ev->spu_channels[channel].name;
1499 em_spu_channel_mute_set(void *data, int mute)
1501 Emotion_Generic_Video *ev = data;
1503 ev->spu_mute = !!mute;
1505 if (!ev || !ev->file_ready)
1508 _player_send_cmd(ev, EM_CMD_SPU_MUTE_SET);
1509 _player_send_int(ev, mute);
1513 em_spu_channel_mute_get(void *data)
1515 Emotion_Generic_Video *ev = data;
1516 return ev->spu_mute;
1520 em_chapter_count(void *ef __UNUSED__)
1527 em_chapter_set(void *ef __UNUSED__, int chapter __UNUSED__)
1532 em_chapter_get(void *ef __UNUSED__)
1539 em_chapter_name_get(void *ef __UNUSED__, int chapter __UNUSED__)
1545 em_speed_set(void *data, double speed)
1547 Emotion_Generic_Video *ev = data;
1551 if (!ev || !ev->file_ready)
1554 _player_send_cmd(ev, EM_CMD_SPEED_SET);
1555 _player_send_float(ev, rate);
1559 em_speed_get(void *data)
1561 Emotion_Generic_Video *ev = data;
1562 return (double)ev->speed;
1566 em_eject(void *ef __UNUSED__)
1572 em_meta_get(void *data, int meta)
1574 Emotion_Generic_Video *ev = data;
1577 case EMOTION_META_INFO_TRACK_TITLE:
1578 return ev->meta.title;
1579 case EMOTION_META_INFO_TRACK_ARTIST:
1580 return ev->meta.artist;
1581 case EMOTION_META_INFO_TRACK_ALBUM:
1582 return ev->meta.album;
1583 case EMOTION_META_INFO_TRACK_YEAR:
1584 return ev->meta.year;
1585 case EMOTION_META_INFO_TRACK_GENRE:
1586 return ev->meta.genre;
1587 case EMOTION_META_INFO_TRACK_COMMENT:
1588 return ev->meta.comment;
1589 case EMOTION_META_INFO_TRACK_DISC_ID:
1590 return ev->meta.disc_id;
1591 case EMOTION_META_INFO_TRACK_COUNT:
1592 return ev->meta.count;
1598 static Emotion_Video_Module em_module =
1601 em_shutdown, /* shutdown */
1602 em_file_open, /* file_open */
1603 em_file_close, /* file_close */
1606 em_size_get, /* size_get */
1607 em_pos_set, /* pos_set */
1608 em_len_get, /* len_get */
1609 em_fps_num_get, /* fps_num_get */
1610 em_fps_den_get, /* fps_den_get */
1611 em_fps_get, /* fps_get */
1612 em_pos_get, /* pos_get */
1613 em_vis_set, /* vis_set */
1614 em_vis_get, /* vis_get */
1615 em_vis_supported, /* vis_supported */
1616 em_ratio_get, /* ratio_get */
1617 em_video_handled, /* video_handled */
1618 em_audio_handled, /* audio_handled */
1619 em_seekable, /* seekable */
1620 em_frame_done, /* frame_done */
1621 em_format_get, /* format_get */
1622 em_video_data_size_get, /* video_data_size_get */
1623 em_yuv_rows_get, /* yuv_rows_get */
1624 em_bgra_data_get, /* bgra_data_get */
1625 em_event_feed, /* event_feed */
1626 em_event_mouse_button_feed, /* event_mouse_button_feed */
1627 em_event_mouse_move_feed, /* event_mouse_move_feed */
1628 em_video_channel_count, /* video_channel_count */
1629 em_video_channel_set, /* video_channel_set */
1630 em_video_channel_get, /* video_channel_get */
1631 em_video_channel_name_get, /* video_channel_name_get */
1632 em_video_channel_mute_set, /* video_channel_mute_set */
1633 em_video_channel_mute_get, /* video_channel_mute_get */
1634 em_audio_channel_count, /* audio_channel_count */
1635 em_audio_channel_set, /* audio_channel_set */
1636 em_audio_channel_get, /* audio_channel_get */
1637 em_audio_channel_name_get, /* audio_channel_name_get */
1638 em_audio_channel_mute_set, /* audio_channel_mute_set */
1639 em_audio_channel_mute_get, /* audio_channel_mute_get */
1640 em_audio_channel_volume_set, /* audio_channel_volume_set */
1641 em_audio_channel_volume_get, /* audio_channel_volume_get */
1642 em_spu_channel_count, /* spu_channel_count */
1643 em_spu_channel_set, /* spu_channel_set */
1644 em_spu_channel_get, /* spu_channel_get */
1645 em_spu_channel_name_get, /* spu_channel_name_get */
1646 em_spu_channel_mute_set, /* spu_channel_mute_set */
1647 em_spu_channel_mute_get, /* spu_channel_mute_get */
1648 em_chapter_count, /* chapter_count */
1649 em_chapter_set, /* chapter_set */
1650 em_chapter_get, /* chapter_get */
1651 em_chapter_name_get, /* chapter_name_get */
1652 em_speed_set, /* speed_set */
1653 em_speed_get, /* speed_get */
1654 em_eject, /* eject */
1655 em_meta_get, /* meta_get */
1660 module_open(Evas_Object *obj, const Emotion_Video_Module **module, void **video, Emotion_Module_Options *opt)
1666 if (_emotion_generic_log_domain < 0)
1668 eina_threads_init();
1669 eina_log_threads_enable();
1670 _emotion_generic_log_domain = eina_log_domain_register
1671 ("emotion-generic", EINA_COLOR_LIGHTCYAN);
1672 if (_emotion_generic_log_domain < 0)
1674 EINA_LOG_CRIT("Could not register log domain 'emotion-generic'");
1680 if (!em_module.init(obj, video, opt)) {
1684 *module = &em_module;
1689 static void module_close(Emotion_Video_Module *module __UNUSED__, void *video)
1691 em_module.shutdown(video);
1696 generic_module_init(void)
1700 pfx = eina_prefix_new(NULL, emotion_object_add,
1701 "EMOTION", "emotion", NULL,
1706 if (!pfx) return EINA_FALSE;
1708 return _emotion_module_register("generic", module_open, module_close);
1712 generic_module_shutdown(void)
1716 eina_prefix_free(pfx);
1719 _emotion_module_unregister("generic");
1722 #ifndef EMOTION_STATIC_BUILD_GENERIC
1724 EINA_MODULE_INIT(generic_module_init);
1725 EINA_MODULE_SHUTDOWN(generic_module_shutdown);