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