[Release version 0.2.66] Add sub threads for 2.4 API compatibility
[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 <camera.h>
24 #include <muse_core.h>
25 #include <muse_camera.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #ifdef BUFFER_MAX_PLANE_NUM
32 #undef BUFFER_MAX_PLANE_NUM
33 #endif /* BUFFER_MAX_PLANE_NUM */
34
35 #define BUFFER_MAX_PLANE_NUM    4
36 #define CAMERA_PARSE_STRING_SIZE 20
37
38 #define PREVIEW_CB_TYPE_USER 0x0000000F
39 #define PREVIEW_CB_TYPE_EVAS 0x000000F0
40
41 #define CHECK_PREVIEW_CB(cb_info, cb_type) ((cb_info)->preview_cb_flag & cb_type)
42 #define SET_PREVIEW_CB_TYPE(cb_info, cb_type) ((cb_info)->preview_cb_flag |= cb_type)
43 #define UNSET_PREVIEW_CB_TYPE(cb_info, cb_type) ((cb_info)->preview_cb_flag &= ~cb_type)
44
45 enum {
46         CAMERA_MESSAGE_HANDLER_TYPE_GENERAL,
47         CAMERA_MESSAGE_HANDLER_TYPE_PREVIEW_CB,
48         CAMERA_MESSAGE_HANDLER_TYPE_CAPTURE_CB
49 };
50
51 typedef struct _camera_stream_data_s {
52         union {
53                 struct {
54                         unsigned char *yuv;
55                         unsigned int length_yuv;
56                 } yuv420, yuv422;
57                 struct {
58                         unsigned char *y;
59                         unsigned int length_y;
60                         unsigned char *uv;
61                         unsigned int length_uv;
62                 } yuv420sp;
63                 struct {
64                         unsigned char *y;
65                         unsigned int length_y;
66                         unsigned char *u;
67                         unsigned int length_u;
68                         unsigned char *v;
69                         unsigned int length_v;
70                 } yuv420p, yuv422p;
71                 struct {
72                         unsigned char *data;
73                         unsigned int length_data;
74                 } encoded;
75         } data;                         /**< pointer of captured stream */
76         int data_type;                  /**< data type */
77         unsigned int length_total;      /**< total length of stream buffer (in byte)*/
78         unsigned int num_planes;        /**< number of planes */
79         MMPixelFormatType format;       /**< image format */
80         int width;                      /**< width of video buffer */
81         int height;                     /**< height of video buffer */
82         unsigned int timestamp;         /**< timestamp of stream buffer (msec)*/
83         void *bo[BUFFER_MAX_PLANE_NUM]; /**< TBM buffer object */
84         void *internal_buffer;          /**< Internal buffer pointer */
85         int stride[BUFFER_MAX_PLANE_NUM];    /**< Stride of each plane */
86         int elevation[BUFFER_MAX_PLANE_NUM]; /**< Elevation of each plane */
87 } camera_stream_data_s;
88
89 typedef struct _camera_msg_handler_info_s {
90         int type;
91         void *cb_info;
92         int running;
93         GCond cond;
94         GMutex mutex;
95         GQueue *queue;
96         GThread *thread;
97 } camera_msg_handler_info_s;
98
99 typedef struct _camera_cb_info_s {
100         gint fd;
101
102         /* message receive thread */
103         GThread *msg_recv_thread;
104         gint msg_recv_running;
105
106         /* general message handler info */
107         camera_msg_handler_info_s msg_handler_info;
108
109         /* preview cb message handler info */
110         camera_msg_handler_info_s preview_cb_info;
111
112         /* capture cb message handler info */
113         camera_msg_handler_info_s capture_cb_info;
114
115         GList *idle_event_list;
116         GCond idle_event_cond;
117         GMutex idle_event_mutex;
118         gpointer user_cb[MUSE_CAMERA_EVENT_TYPE_NUM];
119         gpointer user_data[MUSE_CAMERA_EVENT_TYPE_NUM];
120         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH];
121         GCond api_cond[MUSE_CAMERA_API_MAX];
122         GMutex api_mutex[MUSE_CAMERA_API_MAX];
123         gint api_activating[MUSE_CAMERA_API_MAX];
124         gint api_ret[MUSE_CAMERA_API_MAX];
125         tbm_bufmgr bufmgr;
126         media_format_h pkt_fmt;
127         int preview_cb_flag;
128         GMutex mp_data_mutex;
129 #ifdef TIZEN_FEATURE_EVAS_RENDERER
130         void *evas_info;
131         GMutex evas_mutex;
132 #endif /* TIZEN_FEATURE_EVAS_RENDERER */
133         gboolean run_evas_render;
134 } camera_cb_info_s;
135
136 typedef struct _camera_message_s {
137         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH];
138         muse_camera_api_e api;
139         muse_camera_event_e event;
140         muse_camera_event_class_e event_class;
141 } camera_message_s;
142
143 typedef struct _camera_idle_event_s {
144         camera_cb_info_s *cb_info;
145         gchar recv_msg[MUSE_CAMERA_MSG_MAX_LENGTH];
146         muse_camera_event_e event;
147         GMutex event_mutex;
148 } camera_idle_event_s;
149
150 typedef struct _camera_wl_info_s {
151         int parent_id;
152         int window_x;
153         int window_y;
154         int window_width;
155         int window_height;
156         void *evas_obj;
157 } camera_wl_info_s;
158
159 typedef struct _camera_cli_s {
160         intptr_t remote_handle;
161         intptr_t display_handle;
162         camera_cb_info_s *cb_info;
163         camera_wl_info_s wl_info;
164 } camera_cli_s;
165
166 typedef struct _camera_media_packet_data {
167         int tbm_key;
168         tbm_bo bo;
169         tbm_bo buffer_bo[BUFFER_MAX_PLANE_NUM];
170         int num_buffer_key;
171         tbm_bo data_bo;
172         int ref_cnt;
173 } camera_media_packet_data;
174
175
176 int _camera_get_tbm_surface_format(int in_format, uint32_t *out_format);
177 int _camera_get_media_packet_mimetype(int in_format, media_format_mimetype_e *mimetype);
178 int _camera_media_packet_finalize(media_packet_h pkt, int error_code, void *user_data);
179 int _camera_start_evas_rendering(camera_h camera);
180 int _camera_stop_evas_rendering(camera_h camera, bool keep_screen);
181
182 #ifdef __cplusplus
183 }
184 #endif
185
186 #endif /* __TIZEN_MULTIMEDIA_CAMERA_PRIVATE_H__ */
187