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_int_read(Emotion_Generic_Video *ev, int *i)
281 n = _em_read_safe(ev->fd_read, i, sizeof(*i));
284 ERR("could not read int from fd_read %d\n", ev->fd_read);
292 _player_float_read(Emotion_Generic_Video *ev, float *f)
295 n = _em_read_safe(ev->fd_read, f, sizeof(*f));
298 ERR("could not read float from fd_read %d\n", ev->fd_read);
306 _player_str_read(Emotion_Generic_Video *ev, char *str, int *len)
310 if (!_player_int_read(ev, len))
313 n = _em_read_safe(ev->fd_read, str, *len);
316 ERR("could not read string from fd_read %d\n", ev->fd_read);
324 _player_frame_resize(Emotion_Generic_Video *ev)
327 _player_int_read(ev, &w);
328 _player_int_read(ev, &h);
330 INF("received frame resize: %dx%d", w, h);
333 ev->ratio = (float)w / h;
338 _emotion_frame_resize(ev->obj, ev->w, ev->h, ev->ratio);
342 _player_length_changed(Emotion_Generic_Video *ev)
345 _player_float_read(ev, &length);
347 INF("received length changed: %0.3f", length);
350 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
354 _player_position_changed(Emotion_Generic_Video *ev)
357 _player_float_read(ev, &position);
359 INF("received position changed: %0.3f", position);
362 _emotion_video_pos_update(ev->obj, ev->pos, ev->len);
367 float progress = ev->pos / ev->len;
369 snprintf(buf, sizeof(buf), "%0.1f%%", progress * 100);
371 _emotion_progress_set(ev->obj, buf, progress);
375 _player_seekable_changed(Emotion_Generic_Video *ev)
378 _player_int_read(ev, &seekable);
380 INF("received seekable changed: %d", seekable);
382 seekable = !!seekable;
384 ev->seekable = seekable;
388 _player_volume(Emotion_Generic_Video *ev)
391 _player_float_read(ev, &vol);
393 INF("received volume: %0.3f", vol);
397 if (vol != oldvol && !ev->opening)
398 _emotion_audio_level_change(ev->obj);
402 _player_audio_mute(Emotion_Generic_Video *ev)
405 _player_int_read(ev, &mute);
407 INF("received audio mute: %d", mute);
409 ev->audio_mute = !!mute;
413 _audio_channels_free(Emotion_Generic_Video *ev)
416 for (i = 0; i < ev->audio_channels_count; i++)
417 eina_stringshare_del(ev->audio_channels[i].name);
418 free(ev->audio_channels);
419 ev->audio_channels_count = 0;
423 _video_channels_free(Emotion_Generic_Video *ev)
426 for (i = 0; i < ev->video_channels_count; i++)
427 eina_stringshare_del(ev->video_channels[i].name);
428 free(ev->video_channels);
429 ev->video_channels_count = 0;
433 _spu_channels_free(Emotion_Generic_Video *ev)
436 for (i = 0; i < ev->spu_channels_count; i++)
437 eina_stringshare_del(ev->spu_channels[i].name);
438 free(ev->spu_channels);
439 ev->spu_channels_count = 0;
443 _player_tracks_info(Emotion_Generic_Video *ev, Emotion_Generic_Channel **channels, int *count, int *current)
445 Emotion_Generic_Channel *pchannels;
448 _player_int_read(ev, current);
449 _player_int_read(ev, count);
451 INF("number of tracks: %d (current = %d):", *count, *current);
452 pchannels = calloc(*count, sizeof(Emotion_Generic_Channel));
453 for (i = 0; i < *count; i++)
457 _player_int_read(ev, &tid);
458 _player_str_read(ev, buf, &len);
459 pchannels[i].id = tid;
460 pchannels[i].name = eina_stringshare_add_length(buf, len);
461 INF("\tchannel %d: %s", tid, buf);
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 _player_int_read(ev, &success);
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_read_cmd(Emotion_Generic_Video *ev)
615 if (!_player_int_read(ev, &type))
617 ERR("could not read command\n");
625 case EM_RESULT_FRAME_NEW:
626 _player_new_frame(ev);
628 case EM_RESULT_FILE_SET:
629 _player_file_set_done(ev);
631 case EM_RESULT_FILE_SET_DONE:
632 _player_open_done(ev);
634 case EM_RESULT_FILE_CLOSE:
635 _player_file_closed(ev);
637 case EM_RESULT_PLAYBACK_STOPPED:
638 _emotion_playback_finished(ev->obj);
640 case EM_RESULT_FRAME_SIZE:
641 _player_frame_resize(ev);
643 case EM_RESULT_LENGTH_CHANGED:
644 _player_length_changed(ev);
646 case EM_RESULT_POSITION_CHANGED:
647 _player_position_changed(ev);
649 case EM_RESULT_SEEKABLE_CHANGED:
650 _player_seekable_changed(ev);
652 case EM_RESULT_AUDIO_TRACK_INFO:
653 _player_audio_tracks_info(ev);
655 case EM_RESULT_VIDEO_TRACK_INFO:
656 _player_video_tracks_info(ev);
658 case EM_RESULT_SPU_TRACK_INFO:
659 _player_spu_tracks_info(ev);
661 case EM_RESULT_META_INFO:
662 _player_meta_info_read(ev);
665 WRN("received wrong command: %d", type);
670 _player_cmd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler)
672 Emotion_Generic_Video *ev = data;
674 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR))
676 ERR("an error occurred on fd_read %d.", ev->fd_read);
677 return ECORE_CALLBACK_CANCEL;
680 _player_read_cmd(ev);
682 return ECORE_CALLBACK_RENEW;
686 _player_data_cb(void *data, int type __UNUSED__, void *event)
688 Ecore_Exe_Event_Data *ev = event;
689 Emotion_Generic_Video *evideo = data;
692 if (ev->exe != evideo->player.exe)
694 ERR("slave != ev->exe");
695 return ECORE_CALLBACK_DONE;
698 for (i = 0; ev->lines[i].line; i++)
699 INF("received input from player: \"%s\"", ev->lines[i].line);
701 return ECORE_CALLBACK_DONE;
705 _player_add_cb(void *data, int type __UNUSED__, void *event)
707 Ecore_Exe_Event_Add *event_add = event;
708 Ecore_Exe *player = event_add->exe;
709 Emotion_Generic_Video *ev = data;
711 if (ev->player.exe != player)
713 ERR("ev->player != player.");
714 return ECORE_CALLBACK_DONE;
717 _player_send_cmd(ev, EM_CMD_INIT);
718 _player_send_str(ev, ev->shmname, EINA_TRUE);
720 return ECORE_CALLBACK_DONE;
724 _player_del_cb(void *data, int type __UNUSED__, void *event __UNUSED__)
726 Emotion_Generic_Video *ev = data;
729 ev->player.exe = NULL;
730 ev->ready = EINA_FALSE;
731 ev->file_ready = EINA_FALSE;
732 ecore_main_fd_handler_del(ev->fd_handler);
737 _emotion_decode_stop(ev->obj);
739 return ECORE_CALLBACK_DONE;
743 _player_exec(Emotion_Generic_Video *ev)
749 if (pipe(pipe_out) == -1)
751 ERR("could not create pipe for communication emotion -> player: %s", strerror(errno));
755 if (pipe(pipe_in) == -1)
757 ERR("could not create pipe for communication player -> emotion: %s", strerror(errno));
763 snprintf(buf, sizeof(buf), "%s %d %d\n", ev->cmdline, pipe_out[0], pipe_in[1]);
765 ev->player.exe = ecore_exe_pipe_run(
767 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE |
768 ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_NOT_LEADER,
771 INF("created pipe emotion -> player: %d -> %d\n", pipe_out[1], pipe_out[0]);
772 INF("created pipe player -> emotion: %d -> %d\n", pipe_in[1], pipe_in[0]);
784 ev->fd_read = pipe_in[0];
785 ev->fd_write = pipe_out[1];
787 ev->fd_handler = ecore_main_fd_handler_add(
788 ev->fd_read, ECORE_FD_READ | ECORE_FD_ERROR, _player_cmd_handler_cb, ev,
795 _fork_and_exec(Evas_Object *obj, Emotion_Generic_Video *ev)
800 gettimeofday(&tv, NULL);
801 snprintf(shmname, sizeof(shmname), "/em-generic-shm_%d_%d",
802 (int)tv.tv_sec, (int)tv.tv_usec);
804 ev->shmname = eina_stringshare_add(shmname);
806 ev->player_add = ecore_event_handler_add(
807 ECORE_EXE_EVENT_ADD, _player_add_cb, ev);
808 ev->player_del = ecore_event_handler_add(
809 ECORE_EXE_EVENT_DEL, _player_del_cb, ev);
810 ev->player_data = ecore_event_handler_add(
811 ECORE_EXE_EVENT_DATA, _player_data_cb, ev);
814 if (!_player_exec(ev))
816 ERR("could not start player.");
820 ev->initializing = EINA_TRUE;
826 em_init(Evas_Object *obj, void **emotion_video, Emotion_Module_Options *opt)
828 Emotion_Generic_Video *ev;
831 if (!emotion_video) return 0;
832 player = _get_player(opt ? opt->player : NULL);
833 if (!player) return 0;
835 ev = (Emotion_Generic_Video *)calloc(1, sizeof(*ev));
842 ev->audio_mute = EINA_FALSE;
845 ev->cmdline = eina_stringshare_add(player);
848 return _fork_and_exec(obj, ev);
852 em_shutdown(void *data)
854 Emotion_Generic_Video *ev = data;
860 ecore_exe_terminate(ev->player.exe);
861 ecore_exe_free(ev->player.exe);
862 ev->player.exe = NULL;
866 munmap(ev->shared, ev->shared->size);
868 if (ev->fd_read >= 0)
870 if (ev->fd_write >= 0)
873 ecore_main_fd_handler_del(ev->fd_handler);
875 eina_stringshare_del(ev->cmdline);
876 eina_stringshare_del(ev->shmname);
878 ecore_event_handler_del(ev->player_add);
879 ecore_event_handler_del(ev->player_data);
880 ecore_event_handler_del(ev->player_del);
886 em_file_open(const char *file, Evas_Object *obj __UNUSED__, void *data)
888 Emotion_Generic_Video *ev = data;
889 INF("file set: %s", file);
892 eina_stringshare_replace(&ev->filename, file);
900 if (ev->ready && ev->opening)
902 INF("file changed while opening.");
903 ev->file_changed = EINA_TRUE;
907 ev->opening = EINA_TRUE;
916 em_file_close(void *data)
918 Emotion_Generic_Video *ev = data;
920 if (!ev || !ev->filename) return;
922 INF("file close: %s", ev->filename);
924 eina_stringshare_replace(&ev->filename, NULL);
926 ev->file_ready = EINA_FALSE;
927 _audio_channels_free(ev);
928 _video_channels_free(ev);
929 _spu_channels_free(ev);
930 _player_meta_info_free(ev);
935 _player_send_cmd(ev, EM_CMD_FILE_CLOSE);
936 ev->closing = EINA_TRUE;
939 static Emotion_Format
940 em_format_get(void *ef __UNUSED__)
942 return EMOTION_FORMAT_BGRA;
946 em_video_data_size_get(void *data, int *w, int *h)
948 Emotion_Generic_Video *ev = data;
956 em_play(void *data, double pos)
958 Emotion_Generic_Video *ev = data;
963 ev->play = EINA_TRUE;
964 INF("play: %0.3f", pos);
966 if (ev->initializing || ev->opening)
971 _player_send_cmd(ev, EM_CMD_PLAY);
972 _player_send_float(ev, ev->pos);
976 if (!_player_exec(ev))
977 ERR("could not start player.");
983 Emotion_Generic_Video *ev = data;
988 ev->play = EINA_FALSE;
993 _player_send_cmd(ev, EM_CMD_STOP);
994 _emotion_decode_stop(ev->obj);
998 em_size_get(void *data, int *w, int *h)
1000 Emotion_Generic_Video *ev = data;
1006 em_pos_set(void *data, double pos)
1008 Emotion_Generic_Video *ev = data;
1009 float position = pos;
1011 if (!ev->file_ready)
1014 _player_send_cmd(ev, EM_CMD_POSITION_SET);
1015 _player_send_float(ev, position);
1016 _emotion_seek_done(ev->obj);
1020 em_len_get(void *data)
1022 Emotion_Generic_Video *ev = data;
1027 em_fps_num_get(void *data)
1029 Emotion_Generic_Video *ev = data;
1030 return (int)(ev->fps * 1000.0);
1034 em_fps_den_get(void *ef __UNUSED__)
1040 em_fps_get(void *data)
1042 Emotion_Generic_Video *ev = data;
1047 em_pos_get(void *data)
1049 Emotion_Generic_Video *ev = data;
1054 em_vis_set(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1059 em_vis_get(void *data)
1061 Emotion_Generic_Video *ev = data;
1066 em_vis_supported(void *ef __UNUSED__, Emotion_Vis vis __UNUSED__)
1072 em_ratio_get(void *data)
1074 Emotion_Generic_Video *ev = data;
1078 static int em_video_handled(void *ef __UNUSED__)
1080 fprintf(stderr, "video handled!\n");
1084 static int em_audio_handled(void *ef __UNUSED__)
1086 fprintf(stderr, "audio handled!\n");
1090 static int em_seekable(void *data)
1092 Emotion_Generic_Video *ev = data;
1093 return ev->seekable;
1096 static void em_frame_done(void *ef __UNUSED__)
1101 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__)
1107 em_bgra_data_get(void *data, unsigned char **bgra_data)
1109 Emotion_Generic_Video *ev = data;
1111 if (!ev || !ev->file_ready)
1115 sem_wait(&ev->shared->lock);
1117 // send current frame to emotion
1118 if (ev->shared->frame.emotion != ev->shared->frame.last)
1120 ev->shared->frame.next = ev->shared->frame.emotion;
1121 ev->shared->frame.emotion = ev->shared->frame.last;
1123 *bgra_data = ev->frame.frames[ev->shared->frame.emotion];
1125 if (ev->shared->frame_drop > 1)
1126 WRN("dropped frames: %d", ev->shared->frame_drop - 1);
1127 ev->shared->frame_drop = 0;
1129 // unlock frame here
1130 sem_post(&ev->shared->lock);
1137 em_event_feed(void *ef __UNUSED__, int event __UNUSED__)
1142 em_event_mouse_button_feed(void *ef __UNUSED__, int button __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1147 em_event_mouse_move_feed(void *ef __UNUSED__, int x __UNUSED__, int y __UNUSED__)
1152 em_video_channel_count(void *data)
1154 Emotion_Generic_Video *ev = data;
1155 return ev->video_channels_count;
1159 em_video_channel_set(void *data, int channel)
1161 Emotion_Generic_Video *ev = data;
1163 if (channel < 0 || channel >= ev->video_channels_count)
1165 WRN("video channel out of range.");
1169 _player_send_cmd(ev, EM_CMD_VIDEO_TRACK_SET);
1170 _player_send_int(ev, ev->video_channels[channel].id);
1171 ev->video_channel_current = channel;
1175 em_video_channel_get(void *data)
1177 Emotion_Generic_Video *ev = data;
1178 return ev->video_channel_current;
1182 em_video_channel_name_get(void *data, int channel)
1184 Emotion_Generic_Video *ev = data;
1186 if (channel < 0 || channel >= ev->video_channels_count)
1188 WRN("video channel out of range.");
1192 return ev->video_channels[channel].name;
1196 em_video_channel_mute_set(void *data, int mute)
1198 Emotion_Generic_Video *ev = data;
1200 ev->video_mute = !!mute;
1202 if (!ev || !ev->file_ready)
1205 _player_send_cmd(ev, EM_CMD_VIDEO_MUTE_SET);
1206 _player_send_int(ev, mute);
1210 em_video_channel_mute_get(void *data)
1212 Emotion_Generic_Video *ev = data;
1213 return ev->video_mute;
1217 em_audio_channel_count(void *data)
1219 Emotion_Generic_Video *ev = data;
1220 return ev->audio_channels_count;
1224 em_audio_channel_set(void *data, int channel)
1226 Emotion_Generic_Video *ev = data;
1228 if (channel < 0 || channel >= ev->audio_channels_count)
1230 WRN("audio channel out of range.");
1234 _player_send_cmd(ev, EM_CMD_AUDIO_TRACK_SET);
1235 _player_send_int(ev, ev->audio_channels[channel].id);
1236 ev->audio_channel_current = channel;
1240 em_audio_channel_get(void *data)
1242 Emotion_Generic_Video *ev = data;
1243 return ev->audio_channel_current;
1247 em_audio_channel_name_get(void *data, int channel)
1249 Emotion_Generic_Video *ev = data;
1251 if (channel < 0 || channel >= ev->audio_channels_count)
1253 WRN("audio channel out of range.");
1257 return ev->audio_channels[channel].name;
1261 em_audio_channel_mute_set(void *data, int mute)
1263 Emotion_Generic_Video *ev = data;
1265 ev->audio_mute = !!mute;
1267 if (!ev || !ev->file_ready)
1270 _player_send_cmd(ev, EM_CMD_AUDIO_MUTE_SET);
1271 _player_send_int(ev, mute);
1275 em_audio_channel_mute_get(void *data)
1277 Emotion_Generic_Video *ev = data;
1278 return ev->audio_mute;
1282 em_audio_channel_volume_set(void *data, double vol)
1284 Emotion_Generic_Video *ev = data;
1286 if (vol > 1.0) vol = 1.0;
1287 if (vol < 0.0) vol = 0.0;
1291 if (!ev || !ev->file_ready)
1294 _player_send_cmd(ev, EM_CMD_VOLUME_SET);
1295 _player_send_float(ev, ev->volume);
1299 em_audio_channel_volume_get(void *data)
1301 Emotion_Generic_Video *ev = data;
1306 em_spu_channel_count(void *data)
1308 Emotion_Generic_Video *ev = data;
1309 return ev->spu_channels_count;
1313 em_spu_channel_set(void *data, int channel)
1315 Emotion_Generic_Video *ev = data;
1317 if (channel < 0 || channel >= ev->spu_channels_count)
1319 WRN("spu channel out of range.");
1323 _player_send_cmd(ev, EM_CMD_SPU_TRACK_SET);
1324 _player_send_int(ev, ev->spu_channels[channel].id);
1325 ev->spu_channel_current = channel;
1329 em_spu_channel_get(void *data)
1331 Emotion_Generic_Video *ev = data;
1332 return ev->spu_channel_current;
1336 em_spu_channel_name_get(void *data, int channel)
1338 Emotion_Generic_Video *ev = data;
1340 if (channel < 0 || channel >= ev->spu_channels_count)
1342 WRN("spu channel out of range.");
1346 return ev->spu_channels[channel].name;
1350 em_spu_channel_mute_set(void *data, int mute)
1352 Emotion_Generic_Video *ev = data;
1354 ev->spu_mute = !!mute;
1356 if (!ev || !ev->file_ready)
1359 _player_send_cmd(ev, EM_CMD_SPU_MUTE_SET);
1360 _player_send_int(ev, mute);
1364 em_spu_channel_mute_get(void *data)
1366 Emotion_Generic_Video *ev = data;
1367 return ev->spu_mute;
1371 em_chapter_count(void *ef __UNUSED__)
1378 em_chapter_set(void *ef __UNUSED__, int chapter __UNUSED__)
1383 em_chapter_get(void *ef __UNUSED__)
1390 em_chapter_name_get(void *ef __UNUSED__, int chapter __UNUSED__)
1396 em_speed_set(void *data, double speed)
1398 Emotion_Generic_Video *ev = data;
1402 if (!ev || !ev->file_ready)
1405 _player_send_cmd(ev, EM_CMD_SPEED_SET);
1406 _player_send_float(ev, rate);
1410 em_speed_get(void *data)
1412 Emotion_Generic_Video *ev = data;
1413 return (double)ev->speed;
1417 em_eject(void *ef __UNUSED__)
1423 em_meta_get(void *data, int meta)
1425 Emotion_Generic_Video *ev = data;
1428 case EMOTION_META_INFO_TRACK_TITLE:
1429 return ev->meta.title;
1430 case EMOTION_META_INFO_TRACK_ARTIST:
1431 return ev->meta.artist;
1432 case EMOTION_META_INFO_TRACK_ALBUM:
1433 return ev->meta.album;
1434 case EMOTION_META_INFO_TRACK_YEAR:
1435 return ev->meta.year;
1436 case EMOTION_META_INFO_TRACK_GENRE:
1437 return ev->meta.genre;
1438 case EMOTION_META_INFO_TRACK_COMMENT:
1439 return ev->meta.comment;
1440 case EMOTION_META_INFO_TRACK_DISC_ID:
1441 return ev->meta.disc_id;
1442 case EMOTION_META_INFO_TRACK_COUNT:
1443 return ev->meta.count;
1449 static Emotion_Video_Module em_module =
1452 em_shutdown, /* shutdown */
1453 em_file_open, /* file_open */
1454 em_file_close, /* file_close */
1457 em_size_get, /* size_get */
1458 em_pos_set, /* pos_set */
1459 em_len_get, /* len_get */
1460 em_fps_num_get, /* fps_num_get */
1461 em_fps_den_get, /* fps_den_get */
1462 em_fps_get, /* fps_get */
1463 em_pos_get, /* pos_get */
1464 em_vis_set, /* vis_set */
1465 em_vis_get, /* vis_get */
1466 em_vis_supported, /* vis_supported */
1467 em_ratio_get, /* ratio_get */
1468 em_video_handled, /* video_handled */
1469 em_audio_handled, /* audio_handled */
1470 em_seekable, /* seekable */
1471 em_frame_done, /* frame_done */
1472 em_format_get, /* format_get */
1473 em_video_data_size_get, /* video_data_size_get */
1474 em_yuv_rows_get, /* yuv_rows_get */
1475 em_bgra_data_get, /* bgra_data_get */
1476 em_event_feed, /* event_feed */
1477 em_event_mouse_button_feed, /* event_mouse_button_feed */
1478 em_event_mouse_move_feed, /* event_mouse_move_feed */
1479 em_video_channel_count, /* video_channel_count */
1480 em_video_channel_set, /* video_channel_set */
1481 em_video_channel_get, /* video_channel_get */
1482 em_video_channel_name_get, /* video_channel_name_get */
1483 em_video_channel_mute_set, /* video_channel_mute_set */
1484 em_video_channel_mute_get, /* video_channel_mute_get */
1485 em_audio_channel_count, /* audio_channel_count */
1486 em_audio_channel_set, /* audio_channel_set */
1487 em_audio_channel_get, /* audio_channel_get */
1488 em_audio_channel_name_get, /* audio_channel_name_get */
1489 em_audio_channel_mute_set, /* audio_channel_mute_set */
1490 em_audio_channel_mute_get, /* audio_channel_mute_get */
1491 em_audio_channel_volume_set, /* audio_channel_volume_set */
1492 em_audio_channel_volume_get, /* audio_channel_volume_get */
1493 em_spu_channel_count, /* spu_channel_count */
1494 em_spu_channel_set, /* spu_channel_set */
1495 em_spu_channel_get, /* spu_channel_get */
1496 em_spu_channel_name_get, /* spu_channel_name_get */
1497 em_spu_channel_mute_set, /* spu_channel_mute_set */
1498 em_spu_channel_mute_get, /* spu_channel_mute_get */
1499 em_chapter_count, /* chapter_count */
1500 em_chapter_set, /* chapter_set */
1501 em_chapter_get, /* chapter_get */
1502 em_chapter_name_get, /* chapter_name_get */
1503 em_speed_set, /* speed_set */
1504 em_speed_get, /* speed_get */
1505 em_eject, /* eject */
1506 em_meta_get, /* meta_get */
1511 module_open(Evas_Object *obj, const Emotion_Video_Module **module, void **video, Emotion_Module_Options *opt)
1517 if (_emotion_generic_log_domain < 0)
1519 eina_threads_init();
1520 eina_log_threads_enable();
1521 _emotion_generic_log_domain = eina_log_domain_register
1522 ("emotion-generic", EINA_COLOR_LIGHTCYAN);
1523 if (_emotion_generic_log_domain < 0)
1525 EINA_LOG_CRIT("Could not register log domain 'emotion-generic'");
1531 if (!em_module.init(obj, video, opt)) {
1535 *module = &em_module;
1540 static void module_close(Emotion_Video_Module *module __UNUSED__, void *video)
1542 em_module.shutdown(video);
1547 generic_module_init(void)
1551 pfx = eina_prefix_new(NULL, emotion_object_add,
1552 "EMOTION", "emotion", NULL,
1557 if (!pfx) return EINA_FALSE;
1559 return _emotion_module_register("generic", module_open, module_close);
1563 generic_module_shutdown(void)
1567 eina_prefix_free(pfx);
1570 _emotion_module_unregister("generic");
1573 #ifndef EMOTION_STATIC_BUILD_GENERIC
1575 EINA_MODULE_INIT(generic_module_init);
1576 EINA_MODULE_SHUTDOWN(generic_module_shutdown);