1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <ECamOrientationCustomInterface2.h> |
|
18 #include <ecamfacetrackingcustomapi.h> |
|
19 #include <ecamusecasehintcustomapi.h> |
|
20 |
|
21 #include "cxecameradevice.h" |
|
22 #include "cxeerrormappingsymbian.h" |
|
23 #include "cxutils.h" |
|
24 #include "cxedummycamera.h" |
|
25 |
|
26 #include "OstTraceDefinitions.h" |
|
27 #ifdef OST_TRACE_COMPILER_IN_USE |
|
28 #include "cxecameradeviceTraces.h" |
|
29 #endif |
|
30 |
|
31 |
|
32 |
|
33 CxeCameraDevice::CxeCameraDevice() : |
|
34 mCamera(NULL), |
|
35 mAdvancedSettings(NULL), |
|
36 mImageProcessor(NULL), |
|
37 mCameraSnapshot(NULL), |
|
38 mCameraOrientation(NULL), |
|
39 mFaceTracking(NULL) |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 CxeCameraDevice::~CxeCameraDevice() |
|
45 { |
|
46 CX_DEBUG_ENTER_FUNCTION(); |
|
47 // Exiting, release all resources |
|
48 releaseResources(); |
|
49 CX_DEBUG_EXIT_FUNCTION(); |
|
50 } |
|
51 |
|
52 void CxeCameraDevice::deleteCamera() |
|
53 { |
|
54 CX_DEBUG_ENTER_FUNCTION(); |
|
55 |
|
56 emit prepareForCameraDelete(); |
|
57 |
|
58 // preparing for new camera, release old resources |
|
59 releaseResources(); |
|
60 |
|
61 CX_DEBUG_EXIT_FUNCTION(); |
|
62 } |
|
63 |
|
64 void CxeCameraDevice::releaseCamera() |
|
65 { |
|
66 CX_DEBUG_ENTER_FUNCTION(); |
|
67 |
|
68 if (mCamera) { |
|
69 emit prepareForRelease(); |
|
70 mCamera->Release(); |
|
71 } |
|
72 |
|
73 CX_DEBUG_EXIT_FUNCTION(); |
|
74 } |
|
75 |
|
76 void CxeCameraDevice::reserveCamera() |
|
77 { |
|
78 CX_DEBUG_ENTER_FUNCTION(); |
|
79 |
|
80 if (mCamera) { |
|
81 emit aboutToReserve(); |
|
82 mCamera->Reserve(); |
|
83 } |
|
84 |
|
85 CX_DEBUG_EXIT_FUNCTION(); |
|
86 } |
|
87 |
|
88 void CxeCameraDevice::setCamera( CCamera *camera ) |
|
89 { |
|
90 CX_DEBUG_ENTER_FUNCTION(); |
|
91 |
|
92 if (mCamera != camera) { |
|
93 |
|
94 // new camera, delete old resources |
|
95 releaseResources(); |
|
96 |
|
97 mCamera = camera; |
|
98 |
|
99 // initialize resources |
|
100 CxeError::Id err = initResources(); |
|
101 |
|
102 emit cameraAllocated(err); |
|
103 } |
|
104 |
|
105 CX_DEBUG_EXIT_FUNCTION(); |
|
106 } |
|
107 |
|
108 CCamera* CxeCameraDevice::camera() |
|
109 { |
|
110 return mCamera; |
|
111 } |
|
112 |
|
113 CCamera::CCameraAdvancedSettings* CxeCameraDevice::advancedSettings() |
|
114 { |
|
115 return mAdvancedSettings; |
|
116 } |
|
117 |
|
118 CCamera::CCameraImageProcessing* CxeCameraDevice::imageProcessor() |
|
119 { |
|
120 return mImageProcessor; |
|
121 } |
|
122 |
|
123 |
|
124 CCamera::CCameraSnapshot* CxeCameraDevice::cameraSnapshot() |
|
125 { |
|
126 return mCameraSnapshot; |
|
127 } |
|
128 |
|
129 |
|
130 MCameraOrientation* CxeCameraDevice::cameraOrientation() |
|
131 { |
|
132 return mCameraOrientation; |
|
133 } |
|
134 |
|
135 MCameraFaceTracking* CxeCameraDevice::faceTracking() |
|
136 { |
|
137 return mFaceTracking; |
|
138 } |
|
139 |
|
140 MCameraUseCaseHint *CxeCameraDevice::useCaseHintApi() |
|
141 { |
|
142 return mUseCaseHintApi; |
|
143 } |
|
144 |
|
145 CxeError::Id CxeCameraDevice::initResources() |
|
146 { |
|
147 CX_DEBUG_ENTER_FUNCTION(); |
|
148 |
|
149 TInt status = KErrNone; |
|
150 |
|
151 if (mCamera) { |
|
152 OstTrace0(camerax_performance, CXECAMERADEVICE_EXTENSIONS_1, "msg: e_CX_GET_CCAMERA_EXTENSIONS 1"); |
|
153 |
|
154 CX_DEBUG(("Get CCamera extensions..")); |
|
155 |
|
156 mCameraOrientation = static_cast<MCameraOrientation*>( |
|
157 mCamera->CustomInterface(KCameraOrientationUid)); |
|
158 CX_DEBUG(("MCameraOrientation interface 0x%08x", mCameraOrientation)); |
|
159 |
|
160 mFaceTracking = static_cast<MCameraFaceTracking*>( |
|
161 mCamera->CustomInterface(KCameraFaceTrackingUid)); |
|
162 CX_DEBUG(("MCameraFaceTracking interface 0x%08x", mFaceTracking)); |
|
163 |
|
164 mUseCaseHintApi = static_cast<MCameraUseCaseHint*>( |
|
165 mCamera->CustomInterface(KCameraUseCaseHintUid)); |
|
166 CX_DEBUG(("MCameraUseCaseHint interface 0x%08x", mUseCaseHintApi)); |
|
167 |
|
168 TRAPD(errorAdvSet, mAdvancedSettings = |
|
169 CCamera::CCameraAdvancedSettings::NewL(*mCamera)); |
|
170 CX_DEBUG(("CCameraAdvancedSettings status: %d", errorAdvSet)); |
|
171 |
|
172 TRAPD(errorImgPr, mImageProcessor = |
|
173 CCamera::CCameraImageProcessing::NewL(*mCamera)); |
|
174 CX_DEBUG(("CCameraImageProcessing status: %d", errorImgPr)); |
|
175 Q_UNUSED(errorImgPr); // Avoid release build unused variable warning. |
|
176 |
|
177 TRAPD(errorSnap, mCameraSnapshot = |
|
178 CCamera::CCameraSnapshot::NewL(*mCamera)); |
|
179 CX_DEBUG(("CCameraSnapshot status: %d", errorSnap)); |
|
180 |
|
181 // Check all statuses and set first error code encountered. |
|
182 // Imageprocessing is not supported by 2nd camera so we just ignore the error. |
|
183 status = errorAdvSet != KErrNone |
|
184 ? errorAdvSet : errorSnap; |
|
185 CX_DEBUG(("Total status: %d", status)); |
|
186 |
|
187 OstTrace0(camerax_performance, CXECAMERADEVICE_EXTENSIONS_2, "msg: e_CX_GET_CCAMERA_EXTENSIONS 0"); |
|
188 } |
|
189 |
|
190 CX_DEBUG_EXIT_FUNCTION(); |
|
191 return CxeErrorHandlingSymbian::map(status); |
|
192 } |
|
193 |
|
194 void CxeCameraDevice::releaseResources() |
|
195 { |
|
196 CX_DEBUG_ENTER_FUNCTION(); |
|
197 |
|
198 // not owned. |
|
199 mCameraOrientation = NULL; |
|
200 mFaceTracking = NULL; |
|
201 mUseCaseHintApi = NULL; |
|
202 |
|
203 delete mCameraSnapshot; |
|
204 mCameraSnapshot = NULL; |
|
205 |
|
206 delete mAdvancedSettings; |
|
207 mAdvancedSettings = NULL; |
|
208 |
|
209 delete mImageProcessor; |
|
210 mImageProcessor = NULL; |
|
211 |
|
212 delete mCamera; |
|
213 mCamera = NULL; |
|
214 |
|
215 CX_DEBUG_EXIT_FUNCTION(); |
|
216 } |
|
217 |
|
218 CxeError::Id CxeCameraDevice::newCamera( Cxe::CameraIndex cameraIndex, MCameraObserver2 *observer ) |
|
219 { |
|
220 CX_DEBUG_ENTER_FUNCTION(); |
|
221 OstTrace0(camerax_performance, CXECAMERADEVICE_NEWCAMERA_IN, "msg: e_CX_CREATE_CCAMERA 1"); |
|
222 |
|
223 CX_DEBUG(("Cxe: using camera index %d", cameraIndex)); |
|
224 |
|
225 CX_DEBUG_ASSERT(cameraIndex == Cxe::PrimaryCameraIndex || cameraIndex == Cxe::SecondaryCameraIndex); |
|
226 |
|
227 CCamera* camera = NULL; |
|
228 |
|
229 #if defined(CXE_USE_DUMMY_CAMERA) || defined(__WINSCW__) |
|
230 TRAPD(err, camera = CxeDummyCamera::NewL(*observer, cameraIndex, 100, 2)); |
|
231 CX_DEBUG(("CxeCameraDevice::newCamera <> new CxeDummyCamera")); |
|
232 #else |
|
233 TRAPD(err, camera = CCamera::New2L(*observer, cameraIndex, 100 /*KCameraClientPriority*/)); |
|
234 CX_DEBUG(("CxeCameraDevice::newCamera <> new CCamera")); |
|
235 #endif |
|
236 |
|
237 OstTrace0(camerax_performance, CXECAMERADEVICE_NEWCAMERA_OUT, "msg: e_CX_CREATE_CCAMERA 0"); |
|
238 |
|
239 if (!err) { |
|
240 setCamera(camera); |
|
241 } |
|
242 |
|
243 CX_DEBUG_EXIT_FUNCTION(); |
|
244 return CxeErrorHandlingSymbian::map(err); |
|
245 } |
|
246 |
|
247 // end of file |
|