summaryrefslogtreecommitdiff
path: root/src/modules/emotion/generic
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@samsung.com>2013-02-25 09:32:58 +0900
committerCedric BAIL <cedric.bail@samsung.com>2013-02-27 21:10:28 +0900
commit1121103ecb584fb81c26e48e29f16572b4d6736e (patch)
tree17d4fb0c45ab47fe0bbf914064e02dd8770502f7 /src/modules/emotion/generic
parent762163bb45e819f7a8668e51b6fbb7977896874f (diff)
emotion: improve portability of Emotion Generic by using EFL more.
Diffstat (limited to 'src/modules/emotion/generic')
-rw-r--r--src/modules/emotion/generic/emotion_generic.c176
-rw-r--r--src/modules/emotion/generic/emotion_generic.h7
2 files changed, 112 insertions, 71 deletions
diff --git a/src/modules/emotion/generic/emotion_generic.c b/src/modules/emotion/generic/emotion_generic.c
index b30faa61f7..466f946a3c 100644
--- a/src/modules/emotion/generic/emotion_generic.c
+++ b/src/modules/emotion/generic/emotion_generic.c
@@ -69,34 +69,34 @@ _player_send_cmd(Emotion_Generic_Video *ev, int cmd)
69 ERR("invalid command to player."); 69 ERR("invalid command to player.");
70 return; 70 return;
71 } 71 }
72 if (ev->fd_write == -1) 72 if (!ev->fd_write)
73 { 73 {
74 ERR("you should wait for emotion to be ready to take action."); 74 ERR("you should wait for emotion to be ready to take action.");
75 return ; 75 return ;
76 } 76 }
77 if (write(ev->fd_write, &cmd, sizeof(cmd)) < 0) perror("write"); 77 ecore_pipe_write(ev->fd_write, &cmd, sizeof(cmd));
78} 78}
79 79
80static void 80static void
81_player_send_int(Emotion_Generic_Video *ev, int number) 81_player_send_int(Emotion_Generic_Video *ev, int number)
82{ 82{
83 if (ev->fd_write == -1) 83 if (!ev->fd_write)
84 { 84 {
85 ERR("you should wait for emotion to be ready to take action."); 85 ERR("you should wait for emotion to be ready to take action.");
86 return ; 86 return ;
87 } 87 }
88 if (write(ev->fd_write, &number, sizeof(number)) < 0) perror("write"); 88 ecore_pipe_write(ev->fd_write, &number, sizeof(number));
89} 89}
90 90
91static void 91static void
92_player_send_float(Emotion_Generic_Video *ev, float number) 92_player_send_float(Emotion_Generic_Video *ev, float number)
93{ 93{
94 if (ev->fd_write == -1) 94 if (!ev->fd_write)
95 { 95 {
96 ERR("you should wait for emotion to be ready to take action."); 96 ERR("you should wait for emotion to be ready to take action.");
97 return ; 97 return ;
98 } 98 }
99 if (write(ev->fd_write, &number, sizeof(number)) < 0) perror("write"); 99 ecore_pipe_write(ev->fd_write, &number, sizeof(number));
100} 100}
101 101
102static void 102static void
@@ -105,11 +105,10 @@ _player_send_str(Emotion_Generic_Video *ev, const char *str, Eina_Bool stringsha
105 int len; 105 int len;
106 106
107 if (stringshared) 107 if (stringshared)
108 len = eina_stringshare_strlen(str) + 1; 108 len = str ? eina_stringshare_strlen(str) + 1 : 0;
109 else 109 else
110 len = strlen(str) + 1; 110 len = str ? strlen(str) + 1 : 0;
111 if (write(ev->fd_write, &len, sizeof(len)) < 0) perror("write"); 111 ecore_pipe_write(ev->fd_write, str, len);
112 if (write(ev->fd_write, str, len) < 0) perror("write");
113} 112}
114 113
115static Eina_Bool 114static Eina_Bool
@@ -242,19 +241,10 @@ _player_cmd_param_read(Emotion_Generic_Video *ev, void *param, size_t size)
242 241
243 todo = ev->cmd.total - ev->cmd.i; 242 todo = ev->cmd.total - ev->cmd.i;
244 i = ev->cmd.i; 243 i = ev->cmd.i;
245 done = read(ev->fd_read, &ev->cmd.tmp[i], todo);
246 244
247 if (done < 0 && errno != EINTR && errno != EAGAIN) 245 done = (ev->offset + todo > ev->length) ? ev->length - ev->offset : todo;
248 { 246 memcpy(&ev->cmd.tmp[i], &ev->buffer[ev->offset], done);
249 if (ev->cmd.tmp) 247 ev->offset += done;
250 {
251 free(ev->cmd.tmp);
252 ev->cmd.tmp = NULL;
253 }
254 ERR("problem when reading parameter from pipe.");
255 ev->cmd.type = -1;
256 return EINA_FALSE;
257 }
258 248
259 if (done == todo) 249 if (done == todo)
260 { 250 {
@@ -794,20 +784,19 @@ _player_cmd_read(Emotion_Generic_Video *ev)
794 } 784 }
795} 785}
796 786
797static Eina_Bool 787static void
798_player_cmd_handler_cb(void *data, Ecore_Fd_Handler *fd_handler) 788_player_cmd_handler_cb(void *data, void *buffer, unsigned int nbyte)
799{ 789{
800 Emotion_Generic_Video *ev = data; 790 Emotion_Generic_Video *ev = data;
801 791
802 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_ERROR)) 792 ev->buffer = buffer;
803 { 793 ev->length = nbyte;
804 ERR("an error occurred on fd_read %d.", ev->fd_read); 794 ev->offset = 0;
805 return ECORE_CALLBACK_CANCEL;
806 }
807 795
808 _player_cmd_read(ev); 796 _player_cmd_read(ev);
809 797
810 return ECORE_CALLBACK_RENEW; 798 ev->buffer = NULL;
799 ev->length = 0;
811} 800}
812 801
813static Eina_Bool 802static Eina_Bool
@@ -866,64 +855,73 @@ _player_del_cb(void *data, int type EINA_UNUSED, void *event EINA_UNUSED)
866 ev->player.exe = NULL; 855 ev->player.exe = NULL;
867 ev->ready = EINA_FALSE; 856 ev->ready = EINA_FALSE;
868 ev->file_ready = EINA_FALSE; 857 ev->file_ready = EINA_FALSE;
869 ecore_main_fd_handler_del(ev->fd_handler); 858 ecore_pipe_del(ev->fd_read);
870 close(ev->fd_read); 859 ecore_pipe_del(ev->fd_write);
871 close(ev->fd_write); 860 ev->fd_read = NULL;
872 ev->fd_read = -1; 861 ev->fd_write = NULL;
873 ev->fd_write = -1;
874 _emotion_decode_stop(ev->obj); 862 _emotion_decode_stop(ev->obj);
875 863
876 return ECORE_CALLBACK_DONE; 864 return ECORE_CALLBACK_DONE;
877} 865}
878 866
867static void
868_player_dummy(void *data EINA_UNUSED,
869 void *buffer EINA_UNUSED,
870 unsigned int nbyte EINA_UNUSED)
871{
872}
873
879static Eina_Bool 874static Eina_Bool
880_player_exec(Emotion_Generic_Video *ev) 875_player_exec(Emotion_Generic_Video *ev)
881{ 876{
882 int pipe_out[2]; 877 Ecore_Pipe *in;
883 int pipe_in[2]; 878 Ecore_Pipe *out;
884 char buf[PATH_MAX]; 879 char buf[PATH_MAX];
885 880
886 if (pipe(pipe_out) == -1) 881 out = ecore_pipe_full_add(_player_dummy, NULL, -1, -1, EINA_TRUE, EINA_FALSE);
882 if (!out)
887 { 883 {
888 ERR("could not create pipe for communication emotion -> player: %s", strerror(errno)); 884 ERR("could not create pipe for communication emotion -> player: %s", strerror(errno));
889 return EINA_FALSE; 885 return EINA_FALSE;
890 } 886 }
891 887
892 if (pipe(pipe_in) == -1) 888 in = ecore_pipe_full_add(_player_cmd_handler_cb, ev, -1, -1, EINA_FALSE, EINA_TRUE);
889 if (!in)
893 { 890 {
894 ERR("could not create pipe for communication player -> emotion: %s", strerror(errno)); 891 ERR("could not create pipe for communication player -> emotion: %s", strerror(errno));
895 close(pipe_out[0]); 892 ecore_pipe_del(in);
896 close(pipe_out[1]); 893 ecore_pipe_del(out);
897 return EINA_FALSE; 894 return EINA_FALSE;
898 } 895 }
899 896
900 snprintf(buf, sizeof(buf), "%s %d %d\n", ev->engine->path, pipe_out[0], pipe_in[1]); 897 snprintf(buf, sizeof(buf), "%s %d %d\n", ev->engine->path,
898 ecore_pipe_read_fd(out),
899 ecore_pipe_write_fd(in));
901 900
902 ev->player.exe = ecore_exe_pipe_run( 901 ev->player.exe = ecore_exe_pipe_run(
903 buf, 902 buf,
904 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE | 903 ECORE_EXE_PIPE_READ | ECORE_EXE_PIPE_WRITE |
905 ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_NOT_LEADER, 904 ECORE_EXE_PIPE_READ_LINE_BUFFERED | ECORE_EXE_NOT_LEADER |
905 ECORE_EXE_TERM_WITH_PARENT,
906 ev); 906 ev);
907 907
908 INF("created pipe emotion -> player: %d -> %d", pipe_out[1], pipe_out[0]); 908 INF("created pipe emotion -> player: %d -> %d",
909 INF("created pipe player -> emotion: %d -> %d", pipe_in[1], pipe_in[0]); 909 ecore_pipe_write_fd(out), ecore_pipe_read_fd(out));
910 INF("created pipe player -> emotion: %d -> %d",
911 ecore_pipe_write_fd(in), ecore_pipe_read_fd(in));
910 912
911 close(pipe_in[1]); 913 ecore_pipe_write_close(in);
912 close(pipe_out[0]); 914 ecore_pipe_read_close(out);
913 915
914 if (!ev->player.exe) 916 if (!ev->player.exe)
915 { 917 {
916 close(pipe_in[0]); 918 ecore_pipe_del(in);
917 close(pipe_out[1]); 919 ecore_pipe_del(out);
918 return EINA_FALSE; 920 return EINA_FALSE;
919 } 921 }
920 922
921 ev->fd_read = pipe_in[0]; 923 ev->fd_read = in;
922 ev->fd_write = pipe_out[1]; 924 ev->fd_write = out;
923
924 ev->fd_handler = ecore_main_fd_handler_add(
925 ev->fd_read, ECORE_FD_READ | ECORE_FD_ERROR, _player_cmd_handler_cb, ev,
926 NULL, NULL);
927 925
928 return EINA_TRUE; 926 return EINA_TRUE;
929} 927}
@@ -966,8 +964,8 @@ em_add(const Emotion_Engine *api, Evas_Object *obj, const Emotion_Module_Options
966 ev = calloc(1, sizeof(*ev)); 964 ev = calloc(1, sizeof(*ev));
967 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL); 965 EINA_SAFETY_ON_NULL_RETURN_VAL(ev, NULL);
968 966
969 ev->fd_read = -1; 967 ev->fd_read = NULL;
970 ev->fd_write = -1; 968 ev->fd_write = NULL;
971 ev->speed = 1.0; 969 ev->speed = 1.0;
972 ev->volume = 0.5; 970 ev->volume = 0.5;
973 ev->audio_mute = EINA_FALSE; 971 ev->audio_mute = EINA_FALSE;
@@ -985,11 +983,35 @@ em_add(const Emotion_Engine *api, Evas_Object *obj, const Emotion_Module_Options
985 return ev; 983 return ev;
986} 984}
987 985
986typedef struct _Delay_Munmap Delay_Munmap;
987struct _Delay_Munmap
988{
989 void *map;
990 size_t size;
991};
992
988static void 993static void
989em_partial_shutdown(Emotion_Generic_Video *ev) 994_delayed_munmap(void *data, Evas *e, void *event_info EINA_UNUSED)
990{ 995{
991 _emotion_image_reset(ev->obj); 996 Delay_Munmap *dm = data;
992 997
998 fprintf(stderr, "munmapping !\n");
999 munmap(dm->map, dm->size);
1000 free(dm);
1001
1002 evas_event_callback_del_full(e, EVAS_CALLBACK_RENDER_POST, _delayed_munmap, data);
1003}
1004
1005static void
1006_delayed_next_frame(void *data, Evas *e, void *event_info EINA_UNUSED)
1007{
1008 evas_event_callback_add(e, EVAS_CALLBACK_RENDER_POST, _delayed_munmap, data);
1009 evas_event_callback_del_full(e, EVAS_CALLBACK_RENDER_PRE, _delayed_next_frame, data);
1010}
1011
1012static void
1013em_partial_shutdown(Emotion_Generic_Video *ev)
1014{
993 if (ev->player.exe) 1015 if (ev->player.exe)
994 { 1016 {
995 ecore_exe_terminate(ev->player.exe); 1017 ecore_exe_terminate(ev->player.exe);
@@ -1000,18 +1022,34 @@ em_partial_shutdown(Emotion_Generic_Video *ev)
1000 ev->file_ready = EINA_FALSE; 1022 ev->file_ready = EINA_FALSE;
1001 1023
1002 if (ev->shared) 1024 if (ev->shared)
1003 munmap(ev->shared, ev->shared->size); 1025 {
1026 Evas_Object *o;
1027 Delay_Munmap *dm;
1028
1029 dm = malloc(sizeof (Delay_Munmap));
1030 if (dm)
1031 {
1032 dm->map = ev->shared;
1033 dm->size = ev->shared->size;
1034 evas_event_callback_add(evas_object_evas_get(ev->obj),
1035 EVAS_CALLBACK_RENDER_PRE,
1036 _delayed_next_frame, dm);
1037 }
1038
1039 o = emotion_object_image_get(ev->obj);
1040 evas_object_image_data_set(o, NULL);
1041 evas_object_image_size_set(o, 1, 1);
1042 }
1004 ev->shared = NULL; 1043 ev->shared = NULL;
1005 1044
1006 if (ev->fd_read >= 0) 1045 _emotion_image_reset(ev->obj);
1007 close(ev->fd_read); 1046
1008 ev->fd_read = -1; 1047 if (ev->fd_read)
1009 if (ev->fd_write >= 0) 1048 ecore_pipe_del(ev->fd_read);
1010 close(ev->fd_write); 1049 ev->fd_read = NULL;
1011 ev->fd_write = -1; 1050 if (ev->fd_write)
1012 if (ev->fd_handler) 1051 ecore_pipe_del(ev->fd_write);
1013 ecore_main_fd_handler_del(ev->fd_handler); 1052 ev->fd_write = NULL;
1014 ev->fd_handler = NULL;
1015 1053
1016 if (ev->player_add) ecore_event_handler_del(ev->player_add); 1054 if (ev->player_add) ecore_event_handler_del(ev->player_add);
1017 ev->player_add = NULL; 1055 ev->player_add = NULL;
diff --git a/src/modules/emotion/generic/emotion_generic.h b/src/modules/emotion/generic/emotion_generic.h
index 1536a0e9f9..b86092bedd 100644
--- a/src/modules/emotion/generic/emotion_generic.h
+++ b/src/modules/emotion/generic/emotion_generic.h
@@ -75,8 +75,11 @@ struct _Emotion_Generic_Video
75 Ecore_Event_Handler *player_add, *player_del, *player_data; 75 Ecore_Event_Handler *player_add, *player_del, *player_data;
76 Ecore_Idler *player_restart; 76 Ecore_Idler *player_restart;
77 int drop; 77 int drop;
78 int fd_read, fd_write; 78 Ecore_Pipe *fd_read;
79 Ecore_Fd_Handler *fd_handler; 79 Ecore_Pipe *fd_write;
80 const unsigned char *buffer;
81 ssize_t length;
82 ssize_t offset;
80 83
81 const char *filename; 84 const char *filename;
82 volatile double len; 85 volatile double len;