655201a9eefc79c3b941f6b7af1553dd5aa942d7
[framework/uifw/emotion.git] / src / modules / generic / Emotion_Generic_Plugin.h
1 #ifndef EMOTION_GENERIC_PLUGIN_H
2 #define EMOTION_GENERIC_PLUGIN_H
3
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <sys/mman.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9
10 #ifdef _WIN32
11 # include <windows.h>
12 #else
13 #include <semaphore.h>
14 #endif
15
16 #define DEFAULTWIDTH            320
17 #define DEFAULTHEIGHT           240
18 #define DEFAULTPITCH            4
19
20 typedef enum _Emotion_Generic_Cmd Emotion_Generic_Cmd;
21 typedef enum _Emotion_Generic_Result Emotion_Generic_Result;
22 typedef struct _Emotion_Generic_Video_Frame Emotion_Generic_Video_Frame;
23 typedef struct _Emotion_Generic_Video_Shared Emotion_Generic_Video_Shared;
24
25 enum _Emotion_Generic_Cmd
26 {
27    EM_CMD_INIT = 0, // param: shared memory identifier (string)
28    EM_CMD_PLAY, // param: position (float)
29    EM_CMD_STOP, // param: none
30    EM_CMD_FILE_SET, // param: filename (string)
31    EM_CMD_FILE_SET_DONE, // param: success (int)
32    EM_CMD_FILE_CLOSE, // param: none
33    EM_CMD_POSITION_SET, // param: position (float)
34    EM_CMD_SPEED_SET, // param: speed (float)
35    EM_CMD_AUDIO_MUTE_SET, // param: muted (int)
36    EM_CMD_VIDEO_MUTE_SET, // param: muted (int)
37    EM_CMD_SPU_MUTE_SET, // param: muted (int)
38    EM_CMD_VOLUME_SET, // param: volume (float)
39    EM_CMD_AUDIO_TRACK_SET, // param: track id (int)
40    EM_CMD_VIDEO_TRACK_SET, // param: track id (int)
41    EM_CMD_SPU_TRACK_SET, // param: track id (int)
42    EM_CMD_LAST
43 };
44
45 enum _Emotion_Generic_Result
46 {
47    EM_RESULT_INIT = 0, // param: none
48    EM_RESULT_FILE_SET, // param: none
49    EM_RESULT_FILE_SET_DONE, // param: success (int)
50    EM_RESULT_PLAYBACK_STOPPED, // param: none
51    EM_RESULT_FILE_CLOSE, // param: none
52    EM_RESULT_FRAME_NEW, // param: none
53    EM_RESULT_FRAME_SIZE, // param: int, int (width, height)
54    EM_RESULT_LENGTH_CHANGED, // param: float
55    EM_RESULT_POSITION_CHANGED, // param: float
56    EM_RESULT_SEEKABLE_CHANGED, // param: int
57    EM_RESULT_AUDIO_TRACK_INFO, // param: current track, track count, track_id, track_name, track_id2, track_name2, ...
58    EM_RESULT_VIDEO_TRACK_INFO, // param: current track, track count, track_id, track_name, track_id2, track_name2, ...
59    EM_RESULT_SPU_TRACK_INFO, // param: current spu, spu count, spu_id, spu_name, spu_id2, spu_name2, ...
60                                // (int, int, int, string, int, string, ...)
61    EM_RESULT_META_INFO, // param: title, artist, album, year, genre, comments, disc id, count (all int)
62    EM_RESULT_LAST
63 };
64
65 /* structure for frames 2 buffers to keep integrity */
66 struct _Emotion_Generic_Video_Frame
67 {
68    unsigned char *frames[3];
69 };
70
71 /* structure for frames 2 buffers to keep integrity */
72 struct _Emotion_Generic_Video_Shared
73 {
74    int size;
75    int width;
76    int height;
77    int pitch;
78    /**
79     * - "emotion" is the frame from where the Emotion process is reading pixels.
80     *   The player shouldn't touch this frame.
81     * - "player" is the frame where the slayer process is writing pixels.
82     *   The emotion process shouldn't touch this frame.
83     * - "last" is the last frame that was rendered by the player. Emotion will
84     *   use this frame the next time it will fetch pixels to Evas.
85     * - "next" is the unused frame. The player currently using the "player"
86     *   should, after finishing this frame, set "last" to "player", and "player"
87     *   to "next", and finally "next" to "last" so this operation can be done
88     *   many times in case that Emotion does not request pixels fast enough.
89     */
90    struct {
91         int emotion;
92         int player;
93         int last;
94         int next;
95    } frame;
96    Eina_Semaphore lock;
97    int frame_drop;
98 };
99
100 static inline int
101 emotion_generic_shm_get(const char *shmname, Emotion_Generic_Video_Shared **vs, Emotion_Generic_Video_Frame *vf)
102 {
103    int shmfd = -1;
104    int size;
105    Emotion_Generic_Video_Shared *t_vs;
106
107    shmfd = shm_open(shmname, O_RDWR, 0777);
108    if (shmfd == -1)
109      {
110         fprintf(stderr, "player: could not open shm: %s\n", shmname);
111         fprintf(stderr, "player: %s\n", strerror(errno));
112         return 0;
113      }
114
115    t_vs = mmap(NULL, sizeof(*t_vs), PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
116    if (t_vs == MAP_FAILED)
117      {
118         fprintf(stderr, "player: could not map shared memory.\n");
119         fprintf(stderr, "player: %s\n", strerror(errno));
120         return 0;
121      }
122    size = t_vs->size;
123    munmap(t_vs, sizeof(*t_vs));
124    t_vs = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
125    if (t_vs == MAP_FAILED)
126      {
127         fprintf(stderr, "player: could not map shared memory.\n");
128         fprintf(stderr, "player: %s\n", strerror(errno));
129         return 0;
130      }
131
132    vf->frames[0] = (unsigned char *)t_vs + sizeof(*t_vs);
133    vf->frames[1] = (unsigned char *)t_vs + sizeof(*t_vs) + t_vs->height * t_vs->width * t_vs->pitch;
134    vf->frames[2] = (unsigned char *)t_vs + sizeof(*t_vs) + 2 * t_vs->height * t_vs->width * t_vs->pitch;
135
136    *vs = t_vs;
137
138    return 1;
139 }
140
141 static inline void
142 emotion_generic_shm_free(Emotion_Generic_Video_Shared *vs)
143 {
144    munmap(vs, vs->size);
145 }
146
147 #endif // EMOTION_GENERIC_PLUGIN_H