1a6565d1342e3482ccd6ead8ba21c3cb5d544d17
[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_camcorder.h>
23 #ifdef HAVE_WAYLAND
24 #include <mm_camcorder_mused.h>
25 #endif /* HAVE_WAYLAND */
26 #include <mm_types.h>
27 #include <camera.h>
28 #include <camera_internal.h>
29 #include <camera_private.h>
30 #include <glib.h>
31 #include <dlog.h>
32
33 #ifdef LOG_TAG
34 #undef LOG_TAG
35 #endif
36 #define LOG_TAG "TIZEN_N_CAMERA"
37
38
39 int camera_set_x11_display_rotation(camera_h camera, camera_rotation_e rotation)
40 {
41         return camera_set_display_rotation(camera, rotation);
42 }
43
44
45 int camera_get_x11_display_rotation(camera_h camera, camera_rotation_e *rotation)
46 {
47         return camera_get_display_rotation(camera, rotation);
48 }
49
50
51 int camera_set_x11_display_flip(camera_h camera, camera_flip_e flip)
52 {
53         return camera_set_display_flip(camera, flip);
54 }
55
56
57 int camera_get_x11_display_flip(camera_h camera, camera_flip_e *flip)
58 {
59         return camera_get_display_flip(camera, flip);
60 }
61
62
63 int camera_set_x11_display_visible(camera_h camera, bool visible)
64 {
65         return camera_set_display_visible(camera, visible);
66 }
67
68
69 int camera_is_x11_display_visible(camera_h camera, bool *visible)
70 {
71         return camera_is_display_visible(camera, visible);
72 }
73
74
75 int camera_set_x11_display_mode(camera_h camera, camera_display_mode_e mode)
76 {
77         return camera_set_display_mode(camera, mode);
78 }
79
80
81 int camera_get_x11_display_mode(camera_h camera, camera_display_mode_e *mode)
82 {
83         return camera_get_display_mode(camera, mode);
84 }
85
86
87 int camera_set_x11_display_pixmap(camera_h camera, camera_x11_pixmap_updated_cb callback, void *user_data)
88 {
89         int ret = MM_ERROR_NONE;
90         camera_s *handle = (camera_s *)camera;
91         camera_state_e capi_state = CAMERA_STATE_NONE;
92
93         if (handle == NULL || callback == NULL) {
94                 LOGE("INVALID_PARAMETER(handle:%p,callback:%p,user_data:%p)", handle, callback, user_data);
95                 return CAMERA_ERROR_INVALID_PARAMETER;
96         }
97
98         camera_get_state(camera, &capi_state);
99         if (capi_state > CAMERA_STATE_CREATED) {
100                 LOGE("INVALID STATE(state:%d)", capi_state);
101                 return CAMERA_ERROR_INVALID_STATE;
102         }
103
104         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
105                                           MMCAM_DISPLAY_SURFACE, MM_DISPLAY_SURFACE_X_EXT,
106                                           MMCAM_DISPLAY_HANDLE, callback, sizeof(void *),
107                                           NULL);
108
109         return __convert_camera_error_code(__func__, ret);
110 }
111
112 int camera_set_mused_display(camera_h camera, camera_display_type_e type, void *display_handle)
113 {
114         int ret = MM_ERROR_NONE;
115         int set_surface = MM_DISPLAY_SURFACE_X;
116         camera_s *handle = NULL;
117         void *set_handle = NULL;
118
119         if (camera == NULL) {
120                 LOGE("INVALID_PARAMETER(0x%08x)", CAMERA_ERROR_INVALID_PARAMETER);
121                 return CAMERA_ERROR_INVALID_PARAMETER;
122         }
123
124         if (type != CAMERA_DISPLAY_TYPE_NONE && display_handle == NULL) {
125                 LOGE("display type[%d] is not NONE, but display handle is NULL", type);
126                 return CAMERA_ERROR_INVALID_PARAMETER;
127         }
128
129         handle = (camera_s *)camera;
130         handle->display_type = type;
131         handle->display_handle = display_handle;
132
133         switch(type) {
134                 case CAMERA_DISPLAY_TYPE_OVERLAY:
135                         set_surface = MM_DISPLAY_SURFACE_X;
136                         set_handle = &(handle->display_handle);
137                         LOGD("display type OVERLAY : handle %p", (int)handle->display_handle);
138                         break;
139                 case CAMERA_DISPLAY_TYPE_EVAS:
140                         set_surface = MM_DISPLAY_SURFACE_EVAS;
141                         set_handle = display_handle;
142                         break;
143                 case CAMERA_DISPLAY_TYPE_NONE:
144                 default:
145                         set_surface = MM_DISPLAY_SURFACE_NULL;
146                         handle->display_handle = NULL;
147                         break;
148         }
149
150         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
151                                           MMCAM_DISPLAY_DEVICE, MM_DISPLAY_DEVICE_MAINLCD,
152                                           MMCAM_DISPLAY_SURFACE, set_surface,
153                                           NULL);
154
155         if (ret == MM_ERROR_NONE && type != CAMERA_DISPLAY_TYPE_NONE) {
156                 ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
157                                                   MMCAM_DISPLAY_HANDLE, set_handle, sizeof(void *),
158                                                   NULL);
159         }
160
161         return __convert_camera_error_code(__func__, ret);
162 }
163
164 int camera_get_video_caps(camera_h camera, char **caps)
165 {
166         int ret;
167         camera_s *handle = (camera_s *)camera;
168
169 #ifdef HAVE_WAYLAND
170         ret = mm_camcorder_mused_get_video_caps(handle->mm_handle, caps);
171         if(ret != MM_ERROR_NONE) {
172                 return __convert_camera_error_code(__func__, ret);
173         }
174 #endif /* HAVE_WAYLAND */
175
176         return CAMERA_ERROR_NONE;
177 }
178
179 int camera_set_shm_socket_path_for_mused(camera_h camera, char *socket_path)
180 {
181         int ret = MM_ERROR_NONE;
182         camera_s *handle = (camera_s *)camera;
183
184         if (camera == NULL) {
185                 LOGE("NULL handle");
186                 return CAMERA_ERROR_INVALID_PARAMETER;
187         }
188
189         if (socket_path == NULL) {
190                 LOGE("NULL pointer for socket_path");
191                 return CAMERA_ERROR_INVALID_PARAMETER;
192         }
193
194         LOGD("var : %s", socket_path);
195
196         ret = mm_camcorder_set_attributes(handle->mm_handle, NULL,
197                                           MMCAM_DISPLAY_SHM_SOCKET_PATH, socket_path, strlen(socket_path),
198                                           NULL);
199         if (ret != MM_ERROR_NONE) {
200                 LOGE("error set shm socket path attribute 0x%x", ret);
201                 return __convert_camera_error_code(__func__, ret);
202         }
203
204         return CAMERA_ERROR_NONE;
205 }
206
207