16d4d20d44d40cfd7a341aa9a06d1f93708166cb
[platform/core/api/camera.git] / src / camera_internal.c
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 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <mm.h>
22 #include <mm_types.h>
23 #include <camera_internal.h>
24 #include <camera_private.h>
25 #include <dlog.h>
26
27 #ifdef LOG_TAG
28 #undef LOG_TAG
29 #endif
30 #define LOG_TAG "TIZEN_N_CAMERA"
31
32 /* log level */
33 extern int g_mmcam_log_level;
34
35 //LCOV_EXCL_START
36 int camera_start_evas_rendering(camera_h camera)
37 {
38         return _camera_start_evas_rendering(camera);
39 }
40
41 int camera_stop_evas_rendering(camera_h camera, bool keep_screen)
42 {
43         return _camera_stop_evas_rendering(camera, keep_screen);
44 }
45
46 int camera_set_ecore_wl_display(camera_h camera, void *ecore_wl_window)
47 {
48         return _camera_set_display(camera, MM_DISPLAY_TYPE_OVERLAY_EXT, ecore_wl_window);
49 }
50 //LCOV_EXCL_STOP
51
52 void camera_create_preview_frame(camera_stream_data_s *stream, int num_buffer_fd,
53         tbm_bo_handle *buffer_bo_handle, tbm_bo_handle *data_bo_handle, camera_preview_data_s *frame)
54 {
55         int total_size = 0;
56         unsigned char *buf_pos = NULL;
57
58         if (!stream || !buffer_bo_handle || !frame) {
59                 CAM_LOG_ERROR("invalid param %p,%p,%p", stream, buffer_bo_handle, frame);
60                 return;
61         }
62
63         /* set frame info */
64         if (stream->format == MM_PIXEL_FORMAT_ITLV_JPEG_UYVY)
65                 frame->format = MM_PIXEL_FORMAT_UYVY;
66         else
67                 frame->format = stream->format;
68
69         frame->width = stream->width;
70         frame->height = stream->height;
71         frame->timestamp = stream->timestamp;
72         frame->num_of_planes = stream->num_planes;
73
74         if (num_buffer_fd == 0) {
75 //LCOV_EXCL_START
76                 /* non-zero copy */
77                 if (!data_bo_handle || !data_bo_handle->ptr) {
78                         CAM_LOG_ERROR("NULL pointer");
79                         return;
80                 }
81
82                 buf_pos = data_bo_handle->ptr;
83
84                 if (stream->format == MM_PIXEL_FORMAT_ENCODED_H264) {
85                         frame->data.encoded_plane.data = buf_pos;
86                         frame->data.encoded_plane.size = stream->data.encoded.length_data;
87                         frame->data.encoded_plane.is_delta_frame = (bool)stream->data.encoded.is_delta_frame;
88                         total_size = stream->data.encoded.length_data;
89                 } else if (stream->format == MM_PIXEL_FORMAT_ENCODED_MJPEG) {
90                         frame->data.encoded_plane.data = buf_pos;
91                         frame->data.encoded_plane.size = stream->data.encoded.length_data;
92                         total_size = stream->data.encoded.length_data;
93                 } else if (stream->format == MM_PIXEL_FORMAT_INVZ) {
94                         frame->data.depth_plane.data = buf_pos;
95                         frame->data.depth_plane.size = stream->data.depth.length_data;
96                         total_size = stream->data.depth.length_data;
97                 } else if (stream->format == MM_PIXEL_FORMAT_RGBA ||
98                         stream->format == MM_PIXEL_FORMAT_ARGB) {
99                         frame->data.rgb_plane.data = buf_pos;
100                         frame->data.rgb_plane.size = stream->data.rgb.length_data;
101                         total_size = stream->data.rgb.length_data;
102                 } else {
103                         switch (stream->num_planes) {
104                         case 1:
105                                 frame->data.single_plane.yuv = buf_pos;
106                                 frame->data.single_plane.size = stream->data.yuv420.length_yuv;
107                                 total_size = stream->data.yuv420.length_yuv;
108                                 break;
109                         case 2:
110                                 frame->data.double_plane.y = buf_pos;
111                                 frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
112                                 buf_pos += stream->data.yuv420sp.length_y;
113                                 frame->data.double_plane.uv = buf_pos;
114                                 frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
115                                 total_size = stream->data.yuv420sp.length_y + \
116                                         stream->data.yuv420sp.length_uv;
117                                 break;
118                         case 3:
119                                 frame->data.triple_plane.y = buf_pos;
120                                 frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
121                                 buf_pos += stream->data.yuv420p.length_y;
122                                 frame->data.triple_plane.u = buf_pos;
123                                 frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
124                                 buf_pos += stream->data.yuv420p.length_u;
125                                 frame->data.triple_plane.v = buf_pos;
126                                 frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
127                                 total_size = stream->data.yuv420p.length_y + \
128                                         stream->data.yuv420p.length_u + \
129                                         stream->data.yuv420p.length_v;
130                                 break;
131                         default:
132                                 break;
133                         }
134                 }
135 //LCOV_EXCL_STOP
136         } else {
137                 /* zero copy */
138                 switch (stream->num_planes) {
139 //LCOV_EXCL_START
140                 case 1:
141                         frame->data.single_plane.yuv = buffer_bo_handle[0].ptr;
142                         frame->data.single_plane.size = stream->data.yuv420.length_yuv;
143                         total_size = stream->data.yuv420.length_yuv;
144                         break;
145 //LCOV_EXCL_STOP
146                 case 2:
147                         frame->data.double_plane.y = buffer_bo_handle[0].ptr;
148                         if (stream->num_planes == (unsigned int)num_buffer_fd)
149                                 frame->data.double_plane.uv = buffer_bo_handle[1].ptr;
150                         else
151                                 frame->data.double_plane.uv = buffer_bo_handle[0].ptr + stream->data.yuv420sp.length_y;
152                         frame->data.double_plane.y_size = stream->data.yuv420sp.length_y;
153                         frame->data.double_plane.uv_size = stream->data.yuv420sp.length_uv;
154                         total_size = stream->data.yuv420sp.length_y + \
155                                 stream->data.yuv420sp.length_uv;
156                         break;
157                 case 3:
158 //LCOV_EXCL_START
159                         frame->data.triple_plane.y = buffer_bo_handle[0].ptr;
160                         if (stream->num_planes == (unsigned int)num_buffer_fd) {
161                                 frame->data.triple_plane.u = buffer_bo_handle[1].ptr;
162                                 frame->data.triple_plane.v = buffer_bo_handle[2].ptr;
163                         } else {
164                                 frame->data.triple_plane.u = buffer_bo_handle[0].ptr + stream->data.yuv420p.length_y;
165                                 frame->data.triple_plane.v = buffer_bo_handle[1].ptr + stream->data.yuv420p.length_u;
166                         }
167                         frame->data.triple_plane.y_size = stream->data.yuv420p.length_y;
168                         frame->data.triple_plane.u_size = stream->data.yuv420p.length_u;
169                         frame->data.triple_plane.v_size = stream->data.yuv420p.length_v;
170                         total_size = stream->data.yuv420p.length_y + \
171                                 stream->data.yuv420p.length_u + \
172                                 stream->data.yuv420p.length_v;
173                         break;
174 //LCOV_EXCL_STOP
175                 default:
176                         break;
177                 }
178         }
179
180         CAM_LOG_DEBUG("format[%d], res[%dx%d], size[%d], plane num[%d]",
181              frame->format, frame->width, frame->height, total_size, frame->num_of_planes);
182
183         return;
184 }