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