Update for wayland API usage and etc
[platform/core/api/camera.git] / include / camera_private.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19
20
21 #ifndef __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__
22 #define __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__
23 #include <glib.h>
24 #include <camera.h>
25 #include <muse_core.h>
26 #include <muse_camera.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #ifdef BUFFER_MAX_PLANE_NUM
33 #undef BUFFER_MAX_PLANE_NUM
34 #endif /* BUFFER_MAX_PLANE_NUM */
35
36 #define BUFFER_MAX_PLANE_NUM     4
37 #define CAMERA_PARSED_STRING_NUM_MAX 20
38 #define CAMERA_CB_TIMEOUT        5
39 #define CAMERA_CB_TIMEOUT_LONG   8
40
41 #define CAMERA_MSG_PARAM_SET(param, msg_type, set_value) { \
42         param.type = MUSE_TYPE_##msg_type; \
43         param.name = #set_value; \
44         param.value.value_##msg_type = set_value; \
45 }
46
47 #define PREVIEW_CB_TYPE_USER 0x0000000F
48 #define PREVIEW_CB_TYPE_EVAS 0x000000F0
49
50 #define CHECK_PREVIEW_CB(cb_info, cb_type) ((cb_info)->preview_cb_flag & cb_type)
51 #define SET_PREVIEW_CB_TYPE(cb_info, cb_type) ((cb_info)->preview_cb_flag |= cb_type)
52 #define UNSET_PREVIEW_CB_TYPE(cb_info, cb_type) ((cb_info)->preview_cb_flag &= ~cb_type)
53
54 enum {
55         CAMERA_MESSAGE_HANDLER_TYPE_GENERAL,
56         CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB,
57         CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB
58 };
59
60 typedef struct _camera_stream_data_s {
61         union {
62                 struct {
63                         unsigned char *yuv;
64                         unsigned int length_yuv;
65                 } yuv420, yuv422;
66                 struct {
67                         unsigned char *y;
68                         unsigned int length_y;
69                         unsigned char *uv;
70                         unsigned int length_uv;
71                 } yuv420sp;
72                 struct {
73                         unsigned char *y;
74                         unsigned int length_y;
75                         unsigned char *u;
76                         unsigned int length_u;
77                         unsigned char *v;
78                         unsigned int length_v;
79                 } yuv420p, yuv422p;
80                 struct {
81                         unsigned char *data;
82                         unsigned int length_data;
83                 } encoded;
84         } data;                         /**< pointer of captured stream */
85         int data_type;                  /**< data type */
86         unsigned int length_total;      /**< total length of stream buffer (in byte)*/
87         unsigned int num_planes;        /**< number of planes */
88         MMPixelFormatType format;       /**< image format */
89         int width;                      /**< width of video buffer */
90         int height;                     /**< height of video buffer */
91         unsigned int timestamp;         /**< timestamp of stream buffer (msec)*/
92         void *bo[BUFFER_MAX_PLANE_NUM]; /**< TBM buffer object */
93         void *internal_buffer;          /**< Internal buffer pointer */
94         int stride[BUFFER_MAX_PLANE_NUM];    /**< Stride of each plane */
95         int elevation[BUFFER_MAX_PLANE_NUM]; /**< Elevation of each plane */
96 } camera_stream_data_s;
97
98 typedef struct _camera_msg_handler_info_s {
99         int type;
100         void *cb_info;
101         int running;
102         GCond cond;
103         GMutex mutex;
104         GQueue *queue;
105         GThread *thread;
106 } camera_msg_handler_info_s;
107
108 typedef struct _camera_cb_info_s {
109         /* server connection */
110         gint fd;
111         GMutex fd_lock;
112         gboolean is_server_connected;
113
114         /* message receive thread */
115         GThread *msg_recv_thread;
116         gint msg_recv_running;
117         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH * CAMERA_PARSED_STRING_NUM_MAX];
118         GCond api_cond[MUSE_CAMERA_API_MAX];
119         GMutex api_mutex[MUSE_CAMERA_API_MAX];
120         gint api_activating[MUSE_CAMERA_API_MAX];
121         gint api_ret[MUSE_CAMERA_API_MAX];
122
123         /* general message handler info */
124         camera_msg_handler_info_s msg_handler_info;
125
126         /* preview cb message handler info */
127         camera_msg_handler_info_s preview_cb_info;
128
129         /* capture cb message handler info */
130         camera_msg_handler_info_s capture_cb_info;
131
132         /* idle event */
133         GList *idle_event_list;
134         GCond idle_event_cond;
135         GMutex idle_event_mutex;
136
137         /* user callback */
138         gpointer user_cb[MUSE_CAMERA_EVENT_TYPE_NUM];
139         gpointer user_data[MUSE_CAMERA_EVENT_TYPE_NUM];
140
141         /* tbm */
142         tbm_bufmgr bufmgr;
143
144         /* media packet */
145         media_format_h pkt_fmt;
146         GMutex mp_data_mutex;
147
148         /* preview callback flag */
149         int preview_cb_flag;
150
151         /* evas surface */
152 #ifdef TIZEN_FEATURE_EVAS_RENDERER
153         void *evas_info;
154         GMutex evas_mutex;
155 #endif /* TIZEN_FEATURE_EVAS_RENDERER */
156         gboolean run_evas_render;
157 } camera_cb_info_s;
158
159 typedef struct _camera_message_s {
160         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH];
161         muse_camera_api_e api;
162         muse_camera_event_e event;
163         muse_camera_event_class_e event_class;
164 } camera_message_s;
165
166 typedef struct _camera_idle_event_s {
167         camera_cb_info_s *cb_info;
168         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH];
169         muse_camera_event_e event;
170         GMutex event_mutex;
171 } camera_idle_event_s;
172
173 typedef struct _camera_wl_info_s {
174         int parent_id;
175         int window_x;
176         int window_y;
177         int window_width;
178         int window_height;
179         void *evas_obj;
180 } camera_wl_info_s;
181
182 typedef struct _camera_cli_s {
183         intptr_t remote_handle;
184         intptr_t display_handle;
185         camera_cb_info_s *cb_info;
186         camera_wl_info_s wl_info;
187 } camera_cli_s;
188
189 typedef struct _camera_media_packet_data {
190         int tbm_key;
191         tbm_bo bo;
192         tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM];
193         int num_buffer_key;
194         tbm_bo data_bo;
195         int ref_cnt;
196 } camera_media_packet_data;
197
198 typedef struct _camera_msg_param {
199         int type;
200         const char *name;
201         union {
202                 int value_INT;
203                 const char *value_STRING;
204         } value;
205 } camera_msg_param;
206
207 typedef struct _camera_cb_info {
208         int id;
209         void *callback;
210         void *user_data;
211 } camera_cb_info;
212
213
214 int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format);
215 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype);
216 int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data);
217 int _camera_start_evas_rendering(camera_h camera);
218 int _camera_stop_evas_rendering(camera_h camera, bool keep_screen);
219 int _camera_independent_request(int api, int device_type, const char *key, int *value);
220
221 typedef bool (*camera_supported_cb_param1)(int param, void *user_data);
222 typedef bool (*camera_supported_cb_param2)(int param1, int param2, void *user_data);
223
224 #ifdef __cplusplus
225 }
226 #endif
227
228 #endif /* __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__ */
229