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;
182 /* FIXME: maximum count for the semaphore: 10. Is it sufficient ? */
183 vs->lock = CreateSemaphore(NULL, 1, 10, NULL);
186 ERR("can not create semaphore");
190 sem_init(&vs->lock, 1, 1);
192 ev->frame.frames[0] = (unsigned char *)vs + sizeof(*vs);
193 ev->frame.frames[1] = (unsigned char *)vs + sizeof(*vs) + vs->height * vs->width * vs->pitch;
194 ev->frame.frames[2] = (unsigned char *)vs + sizeof(*vs) + 2 * vs->height * vs->width * vs->pitch;
197 munmap(ev->shared, ev->shared->size);
204 _player_new_frame(Emotion_Generic_Video *ev)
208 _emotion_frame_new(ev->obj);
212 _file_open(Emotion_Generic_Video *ev)
214 INF("Opening file: %s", ev->filename);
217 if (!ev->ready || !ev->filename)
219 _player_send_cmd(ev, EM_CMD_FILE_SET);
220 _player_send_str(ev, ev->filename, EINA_TRUE);
224 _player_file_set_done(Emotion_Generic_Video *ev)
226 if (ev->file_changed)
229 ev->file_changed = EINA_FALSE;
233 if (!_create_shm_data(ev, ev->shmname))
235 ERR("could not create shared memory.");
238 _player_send_cmd(ev, EM_CMD_FILE_SET_DONE);
242 _player_ready(Emotion_Generic_Video *ev)
244 INF("received: player ready.");
246 ev->initializing = EINA_FALSE;
247 ev->ready = EINA_TRUE;
256 _player_cmd_param_read(Emotion_Generic_Video *ev, void *param, size_t size)
258 ssize_t done, todo, i;
260 /* When a parameter must be read, we cannot make sure it will be entirely
261 * available. Thus we store the bytes that could be read in a temp buffer,
262 * and when more data is read we try to complete the buffer and finally use
267 ev->cmd.tmp = malloc(size);
269 ev->cmd.total = size;
272 todo = ev->cmd.total - ev->cmd.i;
274 done = read(ev->fd_read, &ev->cmd.tmp[i], todo);
276 if (done < 0 && errno != EINTR && errno != EAGAIN)
283 ERR("problem when reading parameter from pipe.");
290 memcpy(param, ev->cmd.tmp, size);
303 _player_frame_resize(Emotion_Generic_Video *ev)
307 w = ev->cmd.param.size.width;
308 h = ev->cmd.param.size.height;
310 INF("received frame resize: %dx%d", w, h);
313 ev->ratio = (float)w / h;
318 _emotion_frame_resize(ev->obj, ev->w, ev->h, ev->ratio);
322 _player_length_changed(Emotion_Generic_Video *ev)
324 float length = ev->cmd.param.f_num;
326 INF("received length changed: %0.3f", length);
329 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
333 _player_position_changed(Emotion_Generic_Video *ev)
335 float position = ev->cmd.param.f_num;
337 INF("received position changed: %0.3f", position);
340 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
345 float progress = ev->pos / ev->len;
347 snprintf(buf, sizeof(buf), "%0.1f%%", progress * 100);
349 _emotion_progress_set(ev->obj, buf, progress);
353 _player_seekable_changed(Emotion_Generic_Video *ev)
355 int seekable = ev->cmd.param.i_num;
357 INF("received seekable changed: %d", seekable);
359 seekable = !!seekable;
361 ev->seekable = seekable;
365 _audio_channels_free(Emotion_Generic_Video *ev)
368 for (i = 0; i < ev->audio_channels_count; i++)
369 eina_stringshare_del(ev->audio_channels[i].name);
370 free(ev->audio_channels);
371 ev->audio_channels_count = 0;
375 _video_channels_free(Emotion_Generic_Video *ev)
378 for (i = 0; i < ev->video_channels_count; i++)
379 eina_stringshare_del(ev->video_channels[i].name);
380 free(ev->video_channels);
381 ev->video_channels_count = 0;
385 _spu_channels_free(Emotion_Generic_Video *ev)
388 for (i = 0; i < ev->spu_channels_count; i++)
389 eina_stringshare_del(ev->spu_channels[i].name);
390 free(ev->spu_channels);
391 ev->spu_channels_count = 0;
395 _player_tracks_info(Emotion_Generic_Video *ev, Emotion_Generic_Channel **channels, int *count, int *current)
397 Emotion_Generic_Channel *pchannels;
400 *count = ev->cmd.param.track.total;
401 *current = ev->cmd.param.track.current;
402 pchannels = ev->cmd.param.track.channels;
404 INF("number of tracks: %d (current = %d):", *count, *current);
405 for (i = 0; i < *count; i++)
407 INF("\tchannel %d: %s", pchannels[i].id, pchannels[i].name);
410 *channels = pchannels;
414 _player_audio_tracks_info(Emotion_Generic_Video *ev)
416 INF("Receiving audio channels:");
417 if (ev->audio_channels_count)
418 _audio_channels_free(ev);
420 _player_tracks_info(ev, &ev->audio_channels, &ev->audio_channels_count,
421 &ev->audio_channel_current);
425 _player_video_tracks_info(Emotion_Generic_Video *ev)
427 INF("Receiving video channels:");
428 if (ev->video_channels_count)
429 _video_channels_free(ev);
431 _player_tracks_info(ev, &ev->video_channels, &ev->video_channels_count,
432 &ev->video_channel_current);
436 _player_spu_tracks_info(Emotion_Generic_Video *ev)
438 INF("Receiving spu channels:");
439 if (ev->spu_channels_count)
440 _spu_channels_free(ev);
442 _player_tracks_info(ev, &ev->spu_channels, &ev->spu_channels_count,
443 &ev->spu_channel_current);
447 _player_meta_info_free(Emotion_Generic_Video *ev)
449 eina_stringshare_replace(&ev->meta.title, NULL);
450 eina_stringshare_replace(&ev->meta.artist, NULL);
451 eina_stringshare_replace(&ev->meta.album, NULL);
452 eina_stringshare_replace(&ev->meta.year, NULL);
453 eina_stringshare_replace(&ev->meta.genre, NULL);
454 eina_stringshare_replace(&ev->meta.comment, NULL);
455 eina_stringshare_replace(&ev->meta.disc_id, NULL);
456 eina_stringshare_replace(&ev->meta.count, NULL);
460 _player_meta_info_read(Emotion_Generic_Video *ev)
462 INF("Receiving meta info:");
463 _player_meta_info_free(ev);
464 ev->meta.title = ev->cmd.param.meta.title;
465 ev->meta.artist = ev->cmd.param.meta.artist;
466 ev->meta.album = ev->cmd.param.meta.album;
467 ev->meta.year = ev->cmd.param.meta.year;
468 ev->meta.genre = ev->cmd.param.meta.genre;
469 ev->meta.comment = ev->cmd.param.meta.comment;
470 ev->meta.disc_id = ev->cmd.param.meta.disc_id;
471 ev->meta.count = ev->cmd.param.meta.count;
472 INF("title: '%s'", ev->meta.title);
473 INF("artist: '%s'", ev->meta.artist);
474 INF("album: '%s'", ev->meta.album);
475 INF("year: '%s'", ev->meta.year);
476 INF("genre: '%s'", ev->meta.genre);
477 INF("comment: '%s'", ev->meta.comment);
478 INF("disc_id: '%s'", ev->meta.disc_id);
479 INF("count: '%s'", ev->meta.count);
483 _player_file_closed(Emotion_Generic_Video *ev)
485 INF("Closed previous file.");
487 CloseHandle(ev->shared->lock);
489 sem_destroy(&ev->shared->lock);
492 ev->closing = EINA_FALSE;
499 _player_open_done(Emotion_Generic_Video *ev)
503 success = ev->cmd.param.i_num;
504 shm_unlink(ev->shmname);
506 if (ev->file_changed)
509 ev->file_changed = EINA_FALSE;
513 ev->opening = EINA_FALSE;
516 ERR("Could not open file.");
520 ev->file_ready = EINA_TRUE;
522 _emotion_open_done(ev->obj);
526 _player_send_cmd(ev, EM_CMD_PLAY);
527 _player_send_float(ev, ev->pos);
530 _player_send_cmd(ev, EM_CMD_VOLUME_SET);
531 _player_send_float(ev, ev->volume);
533 _player_send_cmd(ev, EM_CMD_SPEED_SET);
534 _player_send_float(ev, ev->speed);
536 int mute = ev->audio_mute;
537 _player_send_cmd(ev, EM_CMD_AUDIO_MUTE_SET);
538 _player_send_int(ev, mute);
540 mute = ev->video_mute;
541 _player_send_cmd(ev, EM_CMD_VIDEO_MUTE_SET);
542 _player_send_int(ev, mute);
545 _player_send_cmd(ev, EM_CMD_SPU_MUTE_SET);
546 _player_send_int(ev, mute);
552 _player_cmd_process(Emotion_Generic_Video *ev)
554 switch (ev->cmd.type) {
558 case EM_RESULT_FRAME_NEW:
559 _player_new_frame(ev);
561 case EM_RESULT_FILE_SET:
562 _player_file_set_done(ev);
564 case EM_RESULT_FILE_SET_DONE:
565 _player_open_done(ev);
567 case EM_RESULT_FILE_CLOSE:
568 _player_file_closed(ev);
570 case EM_RESULT_PLAYBACK_STOPPED:
571 _emotion_playback_finished(ev->obj);
573 case EM_RESULT_FRAME_SIZE:
574 _player_frame_resize(ev);
576 case EM_RESULT_LENGTH_CHANGED:
577 _player_length_changed(ev);
579 case EM_RESULT_POSITION_CHANGED:
580 _player_position_changed(ev);
582 case EM_RESULT_SEEKABLE_CHANGED:
583 _player_seekable_changed(ev);
585 case EM_RESULT_AUDIO_TRACK_INFO:
586 _player_audio_tracks_info(ev);
588 case EM_RESULT_VIDEO_TRACK_INFO:
589 _player_video_tracks_info(ev);
591 case EM_RESULT_SPU_TRACK_INFO:
592 _player_spu_tracks_info(ev);
594 case EM_RESULT_META_INFO:
595 _player_meta_info_read(ev);
598 WRN("received wrong command: %d", ev->cmd.type);
605 _player_cmd_single_int_process(Emotion_Generic_Video *ev)
607 if (!_player_cmd_param_read(ev, &ev->cmd.param.i_num, sizeof(ev->cmd.param.i_num)))
610 _player_cmd_process(ev);
614 _player_cmd_single_float_process(Emotion_Generic_Video *ev)
616 if (!_player_cmd_param_read(ev, &ev->cmd.param.f_num, sizeof(ev->cmd.param.f_num)))
619 _player_cmd_process(ev);
623 _player_cmd_double_int_process(Emotion_Generic_Video *ev)
627 if (ev->cmd.num_params == 0)
629 ev->cmd.num_params = 2;
630 ev->cmd.cur_param = 0;
631 ev->cmd.param.size.width = 0;
632 ev->cmd.param.size.height = 0;
635 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
638 if (ev->cmd.cur_param == 0)
639 ev->cmd.param.size.width = param;
641 ev->cmd.param.size.height = param;
644 if (ev->cmd.cur_param == ev->cmd.num_params)
645 _player_cmd_process(ev);
649 _player_cmd_track_info(Emotion_Generic_Video *ev)
654 if (ev->cmd.num_params == 0)
656 ev->cmd.cur_param = 0;
657 ev->cmd.num_params = 2;
658 ev->cmd.param.track.channels = NULL;
662 while (ev->cmd.cur_param < 2)
664 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
667 if (ev->cmd.cur_param == 0)
668 ev->cmd.param.track.current = param;
671 ev->cmd.param.track.total = param;
672 ev->cmd.num_params += param * 2;
673 ev->cmd.param.track.channels =
674 calloc(param, sizeof(*ev->cmd.param.track.channels));
679 if (ev->cmd.cur_param == ev->cmd.num_params)
681 _player_cmd_process(ev);
685 i = (ev->cmd.cur_param - 2) / 2;
686 if ((ev->cmd.cur_param % 2) == 0) // reading track id
688 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
690 ev->cmd.param.track.channels[i].id = param;
693 else // reading track name
697 if (ev->cmd.s_len == -1)
699 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
701 ev->cmd.s_len = param;
704 if (!_player_cmd_param_read(ev, buf, ev->cmd.s_len))
706 ev->cmd.param.track.channels[i].name =
707 eina_stringshare_add_length(buf, ev->cmd.s_len);
712 if (ev->cmd.cur_param == ev->cmd.num_params)
713 _player_cmd_process(ev);
717 _player_cmd_meta_info(Emotion_Generic_Video *ev)
723 if (ev->cmd.num_params == 0)
725 ev->cmd.cur_param = 0;
726 ev->cmd.num_params = 8;
727 ev->cmd.param.meta.title = NULL;
728 ev->cmd.param.meta.artist = NULL;
729 ev->cmd.param.meta.album = NULL;
730 ev->cmd.param.meta.year = NULL;
731 ev->cmd.param.meta.genre = NULL;
732 ev->cmd.param.meta.comment = NULL;
733 ev->cmd.param.meta.disc_id = NULL;
734 ev->cmd.param.meta.count = NULL;
738 if (ev->cmd.s_len == -1)
740 if (!_player_cmd_param_read(ev, ¶m, sizeof(param)))
742 ev->cmd.s_len = param;
745 if (!_player_cmd_param_read(ev, buf, ev->cmd.s_len))
748 info = eina_stringshare_add_length(buf, ev->cmd.s_len);
751 if (ev->cmd.cur_param == 0)
752 ev->cmd.param.meta.title = info;
753 else if (ev->cmd.cur_param == 1)
754 ev->cmd.param.meta.artist = info;
755 else if (ev->cmd.cur_param == 2)
756 ev->cmd.param.meta.album = info;
757 else if (ev->cmd.cur_param == 3)
758 ev->cmd.param.meta.year = info;
759 else if (ev->cmd.cur_param == 4)
760 ev->cmd.param.meta.genre = info;
761 else if (ev->cmd.cur_param == 5)
762 ev->cmd.param.meta.comment = info;
763 else if (ev->cmd.cur_param == 6)
764 ev->cmd.param.meta.disc_id = info;
765 else if (ev->cmd.cur_param == 7)
766 ev->cmd.param.meta.count = info;
770 if (ev->cmd.cur_param == 8)
771 _player_cmd_process(ev);
775 _player_cmd_read(Emotion_Generic_Video *ev)
777 if (ev->cmd.type < 0)
779 if (!_player_cmd_param_read(ev, &ev->cmd.type, sizeof(ev->cmd.type)))
781 ev->cmd.num_params = 0;
784 switch (ev->cmd.type) {
786 case EM_RESULT_FILE_SET:
787 case EM_RESULT_PLAYBACK_STOPPED:
788 case EM_RESULT_FILE_CLOSE:
789 case EM_RESULT_FRAME_NEW:
790 _player_cmd_process(ev);
792 case EM_RESULT_FILE_SET_DONE:
793 case EM_RESULT_SEEKABLE_CHANGED:
794 _player_cmd_single_int_process(ev);
796 case EM_RESULT_LENGTH_CHANGED:
797 case EM_RESULT_POSITION_CHANGED:
798 _player_cmd_single_float_process(ev);
800 case EM_RESULT_FRAME_SIZE:
801 _player_cmd_double_int_process(ev);
803 case EM_RESULT_AUDIO_TRACK_INFO:
804 case EM_RESULT_VIDEO_TRACK_INFO:
805 case EM_RESULT_SPU_TRACK_INFO:
806 _player_cmd_track_info(ev);
808 case EM_RESULT_META_INFO:
809 _player_cmd_meta_info(ev);
813 WRN("received wrong command: %d", ev->cmd.type);
819 _player_cmd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler)
821 Emotion_Generic_Video *ev = data;
823 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
825 ERR("an error occurred on fd_read %d.", ev->fd_read);
826 return ECORE_CALLBACK_CANCEL;
829 _player_cmd_read(ev);
831 return ECORE_CALLBACK_RENEW;
835 _player_data_cb(void *data, int type __UNUSED__, void *event)
837 Ecore_Exe_Event_Data *ev = event;
838 Emotion_Generic_Video *evideo = data;
841 if (ev->exe != evideo->player.exe)
843 ERR("slave != ev->exe");
844 return ECORE_CALLBACK_DONE;
847 for (i = 0; ev->lines[i].line; i++)
848 INF("received input from player: \"%s\"", ev->lines[i].line);
850 return ECORE_CALLBACK_DONE;
854 _player_add_cb(void *data, int type __UNUSED__, void *event)
856 Ecore_Exe_Event_Add *event_add = event;
857 Ecore_Exe *player = event_add->exe;
858 Emotion_Generic_Video *ev = data;
860 if (ev->player.exe != player)
862 ERR("ev->player != player.");
863 return ECORE_CALLBACK_DONE;
866 _player_send_cmd(ev, EM_CMD_INIT);
867 _player_send_str(ev, ev->shmname, EINA_TRUE);
869 return ECORE_CALLBACK_DONE;
873 _player_del_cb(void *data, int type __UNUSED__, void *event __UNUSED__)
875 Emotion_Generic_Video *ev = data;
878 ev->player.exe = NULL;
879 ev->ready = EINA_FALSE;
880 ev->file_ready = EINA_FALSE;
881 ecore_main_fd_handler_del(ev->fd_handler);
886 _emotion_decode_stop(ev->obj);
888 return ECORE_CALLBACK_DONE;
892 _player_exec(Emotion_Generic_Video *ev)
898 if (pipe(pipe_out) == -1)
900 ERR("could not create pipe for communication emotion -> player: %s", strerror(errno));
904 if (pipe(pipe_in) == -1)
906 ERR("could not create pipe for communication player -> emotion: %s", strerror(errno));
912 snprintf(buf, sizeof(buf), "%s %d %d\n", ev->cmdline, pipe_out[0], pipe_in[1]);
914 ev->player.exe = ecore_exe_pipe_run(
916 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE |
917 ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_NOT_LEADER,
920 INF("created pipe emotion -> player: %d -> %d", pipe_out[1], pipe_out[0]);
921 INF("created pipe player -> emotion: %d -> %d", pipe_in[1], pipe_in[0]);
933 ev->fd_read = pipe_in[0];
934 ev->fd_write = pipe_out[1];
936 ev->fd_handler = ecore_main_fd_handler_add(
937 ev->fd_read, ECORE_FD_READ | ECORE_FD_ERROR, _player_cmd_handler_cb, ev,
944 _fork_and_exec(Evas_Object *obj __UNUSED__, Emotion_Generic_Video *ev)
949 gettimeofday(&tv, NULL);
950 snprintf(shmname, sizeof(shmname), "/em-generic-shm_%d_%d",
951 (int)tv.tv_sec, (int)tv.tv_usec);
953 ev->shmname = eina_stringshare_add(shmname);
955 ev->player_add = ecore_event_handler_add(
956 ECORE_EXE_EVENT_ADD, _player_add_cb, ev);
957 ev->player_del = ecore_event_handler_add(
958 ECORE_EXE_EVENT_DEL, _player_del_cb, ev);
959 ev->player_data = ecore_event_handler_add(
960 ECORE_EXE_EVENT_DATA, _player_data_cb, ev);
963 if (!_player_exec(ev))
965 ERR("could not start player.");
969 ev->initializing = EINA_TRUE;
975 em_init(Evas_Object *obj, void **emotion_video, Emotion_Module_Options *opt)
977 Emotion_Generic_Video *ev;
980 if (!emotion_video) return 0;
981 player = _get_player(opt ? opt->player : NULL);
982 if (!player) return 0;
984 ev = (Emotion_Generic_Video *)calloc(1, sizeof(*ev));
991 ev->audio_mute = EINA_FALSE;
995 ev->cmdline = eina_stringshare_add(player);
998 return _fork_and_exec(obj, ev);
1002 em_shutdown(void *data)
1004 Emotion_Generic_Video *ev = data;
1010 ecore_exe_terminate(ev->player.exe);
1011 ecore_exe_free(ev->player.exe);
1012 ev->player.exe = NULL;
1016 munmap(ev->shared, ev->shared->size);
1018 if (ev->fd_read >= 0)
1020 if (ev->fd_write >= 0)
1021 close(ev->fd_write);
1023 ecore_main_fd_handler_del(ev->fd_handler);
1025 eina_stringshare_del(ev->cmdline);
1026 eina_stringshare_del(ev->shmname);
1028 ecore_event_handler_del(ev->player_add);
1029 ecore_event_handler_del(ev->player_data);
1030 ecore_event_handler_del(ev->player_del);
1035 static unsigned char
1036 em_file_open(const char *file, Evas_Object *obj __UNUSED__, void *data)
1038 Emotion_Generic_Video *ev = data;
1039 INF("file set: %s", file);
1042 eina_stringshare_replace(&ev->filename, file);
1050 if (ev->ready && ev->opening)
1052 INF("file changed while opening.");
1053 ev->file_changed = EINA_TRUE;
1057 ev->opening = EINA_TRUE;
1066 em_file_close(void *data)
1068 Emotion_Generic_Video *ev = data;
1070 if (!ev || !ev->filename) return;
1072 INF("file close: %s", ev->filename);
1074 eina_stringshare_replace(&ev->filename, NULL);
1076 ev->file_ready = EINA_FALSE;
1077 _audio_channels_free(ev);
1078 _video_channels_free(ev);
1079 _spu_channels_free(ev);
1080 _player_meta_info_free(ev);
1085 _player_send_cmd(ev, EM_CMD_FILE_CLOSE);
1086 ev->closing = EINA_TRUE;
1089 static Emotion_Format
1090 em_format_get(void *ef __UNUSED__)
1092 return EMOTION_FORMAT_BGRA;
1096 em_video_data_size_get(void *data, int *w, int *h)
1098 Emotion_Generic_Video *ev = data;
1106 em_play(void *data, double pos)
1108 Emotion_Generic_Video *ev = data;
1113 ev->play = EINA_TRUE;
1114 INF("play: %0.3f", pos);
1116 if (ev->initializing || ev->opening)
1121 _player_send_cmd(ev, EM_CMD_PLAY);
1122 _player_send_float(ev, ev->pos);
1126 if (!_player_exec(ev))
1127 ERR("could not start player.");
1133 Emotion_Generic_Video *ev = data;
1138 ev->play = EINA_FALSE;
1140 if (!ev->file_ready)
1143 _player_send_cmd(ev, EM_CMD_STOP);
1144 _emotion_decode_stop(ev->obj);
1148 em_size_get(void *data, int *w, int *h)
1150 Emotion_Generic_Video *ev = data;
1156 em_pos_set(void *data, double pos)
1158 Emotion_Generic_Video *ev = data;
1159 float position = pos;
1161 if (!ev->file_ready)
1164 _player_send_cmd(ev, EM_CMD_POSITION_SET);
1165 _player_send_float(ev, position);
1166 _emotion_seek_done(ev->obj);
1170 em_len_get(void *data)
1172 Emotion_Generic_Video *ev = data;
1177 em_fps_num_get(void *data)
1179 Emotion_Generic_Video *ev = data;
1180 return (int)(ev->fps * 1000.0);
1184 em_fps_den_get(void *ef __UNUSED__)
1190 em_fps_get(void *data)
1192 Emotion_Generic_Video *ev = data;
1197 em_pos_get(void *data)
1199 Emotion_Generic_Video *ev = data;
1204 em_vis_set(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1209 em_vis_get(void *data)
1211 Emotion_Generic_Video *ev = data;
1216 em_vis_supported(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1222 em_ratio_get(void *data)
1224 Emotion_Generic_Video *ev = data;
1228 static int em_video_handled(void *ef __UNUSED__)
1230 fprintf(stderr, "video handled!\n");
1234 static int em_audio_handled(void *ef __UNUSED__)
1236 fprintf(stderr, "audio handled!\n");
1240 static int em_seekable(void *data)
1242 Emotion_Generic_Video *ev = data;
1243 return ev->seekable;
1246 static void em_frame_done(void *ef __UNUSED__)
1251 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__)
1257 em_bgra_data_get(void *data, unsigned char **bgra_data)
1259 Emotion_Generic_Video *ev = data;
1264 if (!ev || !ev->file_ready)
1269 res = WaitForSingleObject(ev->shared->lock, 0L);
1270 if (res != WAIT_OBJECT_0)
1273 sem_wait(&ev->shared->lock);
1276 // send current frame to emotion
1277 if (ev->shared->frame.emotion != ev->shared->frame.last)
1279 ev->shared->frame.next = ev->shared->frame.emotion;
1280 ev->shared->frame.emotion = ev->shared->frame.last;
1282 *bgra_data = ev->frame.frames[ev->shared->frame.emotion];
1284 if (ev->shared->frame_drop > 1)
1285 WRN("dropped frames: %d", ev->shared->frame_drop - 1);
1286 ev->shared->frame_drop = 0;
1288 // unlock frame here
1290 ReleaseSemaphore(ev->shared->lock, 1, NULL);
1292 sem_post(&ev->shared->lock);
1300 em_event_feed(void *ef __UNUSED__, int event __UNUSED__)
1305 em_event_mouse_button_feed(void *ef __UNUSED__, int button __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1310 em_event_mouse_move_feed(void *ef __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1315 em_video_channel_count(void *data)
1317 Emotion_Generic_Video *ev = data;
1318 return ev->video_channels_count;
1322 em_video_channel_set(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 _player_send_cmd(ev, EM_CMD_VIDEO_TRACK_SET);
1333 _player_send_int(ev, ev->video_channels[channel].id);
1334 ev->video_channel_current = channel;
1338 em_video_channel_get(void *data)
1340 Emotion_Generic_Video *ev = data;
1341 return ev->video_channel_current;
1345 em_video_channel_name_get(void *data, int channel)
1347 Emotion_Generic_Video *ev = data;
1349 if (channel < 0 || channel >= ev->video_channels_count)
1351 WRN("video channel out of range.");
1355 return ev->video_channels[channel].name;
1359 em_video_channel_mute_set(void *data, int mute)
1361 Emotion_Generic_Video *ev = data;
1363 ev->video_mute = !!mute;
1365 if (!ev || !ev->file_ready)
1368 _player_send_cmd(ev, EM_CMD_VIDEO_MUTE_SET);
1369 _player_send_int(ev, mute);
1373 em_video_channel_mute_get(void *data)
1375 Emotion_Generic_Video *ev = data;
1376 return ev->video_mute;
1380 em_audio_channel_count(void *data)
1382 Emotion_Generic_Video *ev = data;
1383 return ev->audio_channels_count;
1387 em_audio_channel_set(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 _player_send_cmd(ev, EM_CMD_AUDIO_TRACK_SET);
1398 _player_send_int(ev, ev->audio_channels[channel].id);
1399 ev->audio_channel_current = channel;
1403 em_audio_channel_get(void *data)
1405 Emotion_Generic_Video *ev = data;
1406 return ev->audio_channel_current;
1410 em_audio_channel_name_get(void *data, int channel)
1412 Emotion_Generic_Video *ev = data;
1414 if (channel < 0 || channel >= ev->audio_channels_count)
1416 WRN("audio channel out of range.");
1420 return ev->audio_channels[channel].name;
1424 em_audio_channel_mute_set(void *data, int mute)
1426 Emotion_Generic_Video *ev = data;
1428 ev->audio_mute = !!mute;
1430 if (!ev || !ev->file_ready)
1433 _player_send_cmd(ev, EM_CMD_AUDIO_MUTE_SET);
1434 _player_send_int(ev, mute);
1438 em_audio_channel_mute_get(void *data)
1440 Emotion_Generic_Video *ev = data;
1441 return ev->audio_mute;
1445 em_audio_channel_volume_set(void *data, double vol)
1447 Emotion_Generic_Video *ev = data;
1449 if (vol > 1.0) vol = 1.0;
1450 if (vol < 0.0) vol = 0.0;
1454 if (!ev || !ev->file_ready)
1457 _player_send_cmd(ev, EM_CMD_VOLUME_SET);
1458 _player_send_float(ev, ev->volume);
1462 em_audio_channel_volume_get(void *data)
1464 Emotion_Generic_Video *ev = data;
1469 em_spu_channel_count(void *data)
1471 Emotion_Generic_Video *ev = data;
1472 return ev->spu_channels_count;
1476 em_spu_channel_set(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 _player_send_cmd(ev, EM_CMD_SPU_TRACK_SET);
1487 _player_send_int(ev, ev->spu_channels[channel].id);
1488 ev->spu_channel_current = channel;
1492 em_spu_channel_get(void *data)
1494 Emotion_Generic_Video *ev = data;
1495 return ev->spu_channel_current;
1499 em_spu_channel_name_get(void *data, int channel)
1501 Emotion_Generic_Video *ev = data;
1503 if (channel < 0 || channel >= ev->spu_channels_count)
1505 WRN("spu channel out of range.");
1509 return ev->spu_channels[channel].name;
1513 em_spu_channel_mute_set(void *data, int mute)
1515 Emotion_Generic_Video *ev = data;
1517 ev->spu_mute = !!mute;
1519 if (!ev || !ev->file_ready)
1522 _player_send_cmd(ev, EM_CMD_SPU_MUTE_SET);
1523 _player_send_int(ev, mute);
1527 em_spu_channel_mute_get(void *data)
1529 Emotion_Generic_Video *ev = data;
1530 return ev->spu_mute;
1534 em_chapter_count(void *ef __UNUSED__)
1541 em_chapter_set(void *ef __UNUSED__, int chapter __UNUSED__)
1546 em_chapter_get(void *ef __UNUSED__)
1553 em_chapter_name_get(void *ef __UNUSED__, int chapter __UNUSED__)
1559 em_speed_set(void *data, double speed)
1561 Emotion_Generic_Video *ev = data;
1565 if (!ev || !ev->file_ready)
1568 _player_send_cmd(ev, EM_CMD_SPEED_SET);
1569 _player_send_float(ev, rate);
1573 em_speed_get(void *data)
1575 Emotion_Generic_Video *ev = data;
1576 return (double)ev->speed;
1580 em_eject(void *ef __UNUSED__)
1586 em_meta_get(void *data, int meta)
1588 Emotion_Generic_Video *ev = data;
1591 case EMOTION_META_INFO_TRACK_TITLE:
1592 return ev->meta.title;
1593 case EMOTION_META_INFO_TRACK_ARTIST:
1594 return ev->meta.artist;
1595 case EMOTION_META_INFO_TRACK_ALBUM:
1596 return ev->meta.album;
1597 case EMOTION_META_INFO_TRACK_YEAR:
1598 return ev->meta.year;
1599 case EMOTION_META_INFO_TRACK_GENRE:
1600 return ev->meta.genre;
1601 case EMOTION_META_INFO_TRACK_COMMENT:
1602 return ev->meta.comment;
1603 case EMOTION_META_INFO_TRACK_DISC_ID:
1604 return ev->meta.disc_id;
1605 case EMOTION_META_INFO_TRACK_COUNT:
1606 return ev->meta.count;
1612 static Emotion_Video_Module em_module =
1615 em_shutdown, /* shutdown */
1616 em_file_open, /* file_open */
1617 em_file_close, /* file_close */
1620 em_size_get, /* size_get */
1621 em_pos_set, /* pos_set */
1622 em_len_get, /* len_get */
1623 em_fps_num_get, /* fps_num_get */
1624 em_fps_den_get, /* fps_den_get */
1625 em_fps_get, /* fps_get */
1626 em_pos_get, /* pos_get */
1627 em_vis_set, /* vis_set */
1628 em_vis_get, /* vis_get */
1629 em_vis_supported, /* vis_supported */
1630 em_ratio_get, /* ratio_get */
1631 em_video_handled, /* video_handled */
1632 em_audio_handled, /* audio_handled */
1633 em_seekable, /* seekable */
1634 em_frame_done, /* frame_done */
1635 em_format_get, /* format_get */
1636 em_video_data_size_get, /* video_data_size_get */
1637 em_yuv_rows_get, /* yuv_rows_get */
1638 em_bgra_data_get, /* bgra_data_get */
1639 em_event_feed, /* event_feed */
1640 em_event_mouse_button_feed, /* event_mouse_button_feed */
1641 em_event_mouse_move_feed, /* event_mouse_move_feed */
1642 em_video_channel_count, /* video_channel_count */
1643 em_video_channel_set, /* video_channel_set */
1644 em_video_channel_get, /* video_channel_get */
1645 em_video_channel_name_get, /* video_channel_name_get */
1646 em_video_channel_mute_set, /* video_channel_mute_set */
1647 em_video_channel_mute_get, /* video_channel_mute_get */
1648 em_audio_channel_count, /* audio_channel_count */
1649 em_audio_channel_set, /* audio_channel_set */
1650 em_audio_channel_get, /* audio_channel_get */
1651 em_audio_channel_name_get, /* audio_channel_name_get */
1652 em_audio_channel_mute_set, /* audio_channel_mute_set */
1653 em_audio_channel_mute_get, /* audio_channel_mute_get */
1654 em_audio_channel_volume_set, /* audio_channel_volume_set */
1655 em_audio_channel_volume_get, /* audio_channel_volume_get */
1656 em_spu_channel_count, /* spu_channel_count */
1657 em_spu_channel_set, /* spu_channel_set */
1658 em_spu_channel_get, /* spu_channel_get */
1659 em_spu_channel_name_get, /* spu_channel_name_get */
1660 em_spu_channel_mute_set, /* spu_channel_mute_set */
1661 em_spu_channel_mute_get, /* spu_channel_mute_get */
1662 em_chapter_count, /* chapter_count */
1663 em_chapter_set, /* chapter_set */
1664 em_chapter_get, /* chapter_get */
1665 em_chapter_name_get, /* chapter_name_get */
1666 em_speed_set, /* speed_set */
1667 em_speed_get, /* speed_get */
1668 em_eject, /* eject */
1669 em_meta_get, /* meta_get */
1670 NULL, /* priority_set */
1671 NULL, /* priority_get */
1676 module_open(Evas_Object *obj, const Emotion_Video_Module **module, void **video, Emotion_Module_Options *opt)
1682 if (_emotion_generic_log_domain < 0)
1684 eina_threads_init();
1685 eina_log_threads_enable();
1686 _emotion_generic_log_domain = eina_log_domain_register
1687 ("emotion-generic", EINA_COLOR_LIGHTCYAN);
1688 if (_emotion_generic_log_domain < 0)
1690 EINA_LOG_CRIT("Could not register log domain 'emotion-generic'");
1696 if (!em_module.init(obj, video, opt)) {
1700 *module = &em_module;
1705 static void module_close(Emotion_Video_Module *module __UNUSED__, void *video)
1707 em_module.shutdown(video);
1712 generic_module_init(void)
1716 pfx = eina_prefix_new(NULL, emotion_object_add,
1717 "EMOTION", "emotion", NULL,
1722 if (!pfx) return EINA_FALSE;
1724 return _emotion_module_register("generic", module_open, module_close);
1728 generic_module_shutdown(void)
1732 eina_prefix_free(pfx);
1735 _emotion_module_unregister("generic");
1738 #ifndef EMOTION_STATIC_BUILD_GENERIC
1740 EINA_MODULE_INIT(generic_module_init);
1741 EINA_MODULE_SHUTDOWN(generic_module_shutdown);