Add new routine to check waiting count
[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_CB_TIMEOUT        4
38
39 #define CAMERA_MSG_PARAM_SET(param, msg_type, set_value) { \
40         param.type = MUSE_TYPE_##msg_type; \
41         param.name = #set_value; \
42         param.value.value_##msg_type = set_value; \
43 }
44
45 #define PREVIEW_CB_TYPE_USER 0x0000000F
46 #define PREVIEW_CB_TYPE_EVAS 0x000000F0
47
48 #define CHECK_PREVIEW_CB(cb_info, cb_type) ((cb_info)->preview_cb_flag & cb_type)
49 #define SET_PREVIEW_CB_TYPE(cb_info, cb_type) ((cb_info)->preview_cb_flag |= cb_type)
50 #define UNSET_PREVIEW_CB_TYPE(cb_info, cb_type) ((cb_info)->preview_cb_flag &= ~cb_type)
51
52 enum {
53         CAMERA_MESSAGE_HANDLER_TYPE_GENERAL,
54         CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB,
55         CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB
56 };
57
58 typedef struct _camera_stream_data_s {
59         union {
60                 struct {
61                         unsigned char *yuv;
62                         unsigned int length_yuv;
63                 } yuv420, yuv422;
64                 struct {
65                         unsigned char *y;
66                         unsigned int length_y;
67                         unsigned char *uv;
68                         unsigned int length_uv;
69                 } yuv420sp;
70                 struct {
71                         unsigned char *y;
72                         unsigned int length_y;
73                         unsigned char *u;
74                         unsigned int length_u;
75                         unsigned char *v;
76                         unsigned int length_v;
77                 } yuv420p, yuv422p;
78                 struct {
79                         unsigned char *data;
80                         unsigned int length_data;
81                 } encoded;
82         } data;                         /**< pointer of captured stream */
83         int data_type;                  /**< data type */
84         unsigned int length_total;      /**< total length of stream buffer (in byte)*/
85         unsigned int num_planes;        /**< number of planes */
86         MMPixelFormatType format;       /**< image format */
87         int width;                      /**< width of video buffer */
88         int height;                     /**< height of video buffer */
89         unsigned int timestamp;         /**< timestamp of stream buffer (msec)*/
90         void *bo[BUFFER_MAX_PLANE_NUM]; /**< TBM buffer object */
91         void *internal_buffer;          /**< Internal buffer pointer */
92         int stride[BUFFER_MAX_PLANE_NUM];    /**< Stride of each plane */
93         int elevation[BUFFER_MAX_PLANE_NUM]; /**< Elevation of each plane */
94 } camera_stream_data_s;
95
96 typedef struct _camera_msg_handler_info_s {
97         int type;
98         void *cb_info;
99         int running;
100         GCond cond;
101         GMutex mutex;
102         GQueue *queue;
103         GThread *thread;
104 } camera_msg_handler_info_s;
105
106 typedef struct _camera_cb_info_s {
107         /* server connection */
108         gint fd;
109         GMutex fd_lock;
110         gboolean is_server_connected;
111
112         /* message receive thread */
113         GThread *msg_recv_thread;
114         gint msg_recv_running;
115         gchar recv_msg[MUSE_MSG_MAX_LENGTH + 1];
116         GCond api_cond[MUSE_CAMERA_API_MAX];
117         GMutex api_mutex[MUSE_CAMERA_API_MAX];
118         gint api_activating[MUSE_CAMERA_API_MAX];
119         gint api_waiting[MUSE_CAMERA_API_MAX];
120         gint api_ret[MUSE_CAMERA_API_MAX];
121
122         /* general message handler info */
123         camera_msg_handler_info_s msg_handler_info;
124
125         /* preview cb message handler info */
126         camera_msg_handler_info_s preview_cb_info;
127
128         /* capture cb message handler info */
129         camera_msg_handler_info_s capture_cb_info;
130
131         /* idle event */
132         GList *idle_event_list;
133         GCond idle_event_cond;
134         GMutex idle_event_mutex;
135
136         /* user callback */
137         gpointer user_cb[MUSE_CAMERA_EVENT_TYPE_NUM];
138         gpointer user_data[MUSE_CAMERA_EVENT_TYPE_NUM];
139
140         /* tbm */
141         tbm_bufmgr bufmgr;
142
143         /* media packet */
144         media_format_h pkt_fmt;
145         GMutex mp_data_mutex;
146
147         /* preview callback flag */
148         int preview_cb_flag;
149
150         /* evas surface */
151 #ifdef TIZEN_FEATURE_EVAS_RENDERER
152         void *evas_info;
153         GMutex evas_mutex;
154 #endif /* TIZEN_FEATURE_EVAS_RENDERER */
155         gboolean run_evas_render;
156
157         /* get values */
158         gint get_int[MUSE_CAMERA_GET_INT_NUM];
159         gint get_int_pair[MUSE_CAMERA_GET_INT_PAIR_NUM][2];
160         gchar get_string[MUSE_CAMERA_GET_STRING_NUM][MUSE_CAMERA_MSG_MAX_LENGTH];
161         gdouble get_geotag[3];
162         gint get_display_roi_area[4];
163 } camera_cb_info_s;
164
165 typedef struct _camera_message_s {
166         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH + 1];
167         muse_camera_api_e api;
168         muse_camera_event_e event;
169         muse_camera_event_class_e event_class;
170 } camera_message_s;
171
172 typedef struct _camera_idle_event_s {
173         camera_cb_info_s *cb_info;
174         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH + 1];
175         muse_camera_event_e event;
176         GMutex event_mutex;
177 } camera_idle_event_s;
178
179 typedef struct _camera_wl_info_s {
180         int parent_id;
181         int window_x;
182         int window_y;
183         int window_width;
184         int window_height;
185         void *evas_obj;
186 } camera_wl_info_s;
187
188 typedef struct _camera_cli_s {
189         intptr_t remote_handle;
190         intptr_t display_handle;
191         camera_cb_info_s *cb_info;
192         camera_wl_info_s wl_info;
193 } camera_cli_s;
194
195 typedef struct _camera_media_packet_data {
196         int tbm_key;
197         tbm_bo bo;
198         tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM];
199         int num_buffer_key;
200         tbm_bo data_bo;
201         int ref_cnt;
202 } camera_media_packet_data;
203
204 typedef struct _camera_msg_param {
205         int type;
206         const char *name;
207         union {
208                 int value_INT;
209                 const char *value_STRING;
210         } value;
211 } camera_msg_param;
212
213 typedef struct _camera_cb_info {
214         int id;
215         void *callback;
216         void *user_data;
217 } camera_cb_info;
218
219
220 int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format);
221 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype);
222 int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data);
223 int _camera_start_evas_rendering(camera_h camera);
224 int _camera_stop_evas_rendering(camera_h camera, bool keep_screen);
225 int _camera_independent_request(int api, int device_type, const char *key, int *value);
226
227 typedef bool (*camera_supported_cb_param1)(int param, void *user_data);
228 typedef bool (*camera_supported_cb_param2)(int param1, int param2, void *user_data);
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif /* __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__ */
235