[ACR-1487] Add new preview format and update camera_preview_data_s
[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                         int is_delta_frame;
91                 } encoded, depth, rgb;
92         } data;                         /**< pointer of captured stream */
93         int data_type;                  /**< data type */
94         unsigned int length_total;      /**< total length of stream buffer (in byte)*/
95         unsigned int num_planes;        /**< number of planes */
96         MMPixelFormatType format;       /**< image format */
97         int width;                      /**< width of video buffer */
98         int height;                     /**< height of video buffer */
99         unsigned int timestamp;         /**< timestamp of stream buffer (msec)*/
100         void *bo[BUFFER_MAX_PLANE_NUM]; /**< TBM buffer object */
101         void *internal_buffer;          /**< Internal buffer pointer */
102         int stride[BUFFER_MAX_PLANE_NUM];    /**< Stride of each plane */
103         int elevation[BUFFER_MAX_PLANE_NUM]; /**< Elevation of each plane */
104 } camera_stream_data_s;
105
106 typedef struct _camera_msg_handler_info_s {
107         int type;
108         void *cb_info;
109         int running;
110         GCond cond;
111         GMutex mutex;
112         GQueue *queue;
113         GThread *thread;
114 } camera_msg_handler_info_s;
115
116 typedef struct _camera_cb_info_s {
117         /* server connection */
118         gint fd;
119         GMutex fd_lock;
120         gboolean is_server_connected;
121
122         /* message receive thread */
123         GThread *msg_recv_thread;
124         gint msg_recv_running;
125         gchar recv_msg[MUSE_MSG_MAX_LENGTH + 1];
126         GCond api_cond[MUSE_CAMERA_API_MAX];
127         GMutex api_mutex[MUSE_CAMERA_API_MAX];
128         gint api_activating[MUSE_CAMERA_API_MAX];
129         gint api_waiting[MUSE_CAMERA_API_MAX];
130         gint api_ret[MUSE_CAMERA_API_MAX];
131
132         /* general message handler info */
133         camera_msg_handler_info_s msg_handler_info;
134
135         /* preview cb message handler info */
136         camera_msg_handler_info_s preview_cb_info;
137
138         /* capture cb message handler info */
139         camera_msg_handler_info_s capture_cb_info;
140
141         /* idle event */
142         GList *idle_event_list;
143
144         /* user callback */
145         gpointer user_cb[MUSE_CAMERA_EVENT_TYPE_NUM];
146         gpointer user_data[MUSE_CAMERA_EVENT_TYPE_NUM];
147         GMutex user_cb_mutex[MUSE_CAMERA_EVENT_TYPE_NUM];
148
149         /* tbm */
150         tbm_bufmgr bufmgr;
151         gboolean user_buffer_supported;
152         tbm_bo bos[MUSE_NUM_FD];
153         tbm_fd fds[MUSE_NUM_FD];
154
155         /* media packet */
156         media_format_h pkt_fmt;
157         GMutex mp_data_mutex;
158
159         /* preview callback flag */
160         int preview_cb_flag;
161         camera_pixel_format_e preview_format;
162
163         /* display */
164         muse_camera_display_info_s dp_info;
165         mm_display_interface_h dp_interface;
166         gboolean run_evas_render;
167
168         /* get values */
169         gint get_int[MUSE_CAMERA_GET_INT_NUM];
170         gint get_int_pair[MUSE_CAMERA_GET_INT_PAIR_NUM][2];
171         gchar get_string[MUSE_CAMERA_GET_STRING_NUM][MUSE_CAMERA_MSG_MAX_LENGTH];
172         gdouble get_geotag[3];
173         gint get_display_roi_area[4];
174 } camera_cb_info_s;
175
176 typedef struct _camera_message_s {
177         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH + 1];
178         muse_camera_api_e api;
179         muse_camera_event_e event;
180         muse_camera_event_class_e event_class;
181         int tfd[MUSE_NUM_FD];
182 } camera_message_s;
183
184 typedef struct _camera_idle_event_s {
185         camera_cb_info_s *cb_info;
186         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH + 1];
187         muse_camera_event_e event;
188         int tfd[MUSE_NUM_FD];
189 } camera_idle_event_s;
190
191 typedef struct _camera_cli_s {
192         intptr_t remote_handle;
193         camera_cb_info_s *cb_info;
194 } camera_cli_s;
195
196 typedef struct _camera_media_packet_data {
197         int ret_fd;
198         tbm_fd fd;
199         tbm_fd data_fd;
200         tbm_fd buffer_fd[MUSE_NUM_FD];
201         tbm_bo bo;
202         tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM];
203         int num_buffer_fd;
204         tbm_bo data_bo;
205         int ref_cnt;
206 } camera_media_packet_data;
207
208 typedef struct _camera_msg_param {
209         int type;
210         const char *name;
211         union {
212                 int value_INT;
213                 const char *value_STRING;
214                 void *value_ARRAY;
215         } value;
216         int value_size;
217 } camera_msg_param;
218
219 typedef struct _camera_cb_info {
220         int id;
221         void *callback;
222         void *user_data;
223 } camera_cb_info;
224
225
226 int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format);
227 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype);
228 int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data);
229 int _camera_start_evas_rendering(camera_h camera);
230 int _camera_stop_evas_rendering(camera_h camera, bool keep_screen);
231 int _camera_independent_request(int api, int device_type, const char *key, int *value);
232
233 typedef bool (*camera_supported_cb_param1)(int param, void *user_data);
234 typedef bool (*camera_supported_cb_param2)(int param1, int param2, void *user_data);
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif /* __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__ */
241