|
1 /* |
|
2 * Name : Camera.cpp |
|
3 * Description : Camera helper class |
|
4 * Project : This file is part of OpenMAR, an Open Mobile Augmented Reality browser |
|
5 * Website : http://OpenMAR.org |
|
6 * |
|
7 * Copyright (c) 2010 David Caabeiro |
|
8 * |
|
9 * All rights reserved. This program and the accompanying materials are made available |
|
10 * under the terms of the Eclipse Public License v1.0 which accompanies this |
|
11 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html |
|
12 * |
|
13 */ |
|
14 |
|
15 #include "Camera.h" |
|
16 |
|
17 #include <ecamadvsettings.h> |
|
18 #include <fbs.h> |
|
19 |
|
20 #include "Logger.h" |
|
21 |
|
22 CDigitalCamera* CDigitalCamera::NewL(MObserver& aObserver) |
|
23 { |
|
24 CDigitalCamera* self = new(ELeave) CDigitalCamera(aObserver); |
|
25 CleanupStack::PushL(self); |
|
26 self->ConstructL(); |
|
27 CleanupStack::Pop(self); |
|
28 |
|
29 return self; |
|
30 } |
|
31 |
|
32 CDigitalCamera::~CDigitalCamera() |
|
33 { |
|
34 delete iCameraSetting; |
|
35 delete iCamera; |
|
36 } |
|
37 |
|
38 CDigitalCamera::CDigitalCamera(MObserver& aObserver) |
|
39 : iObserver(aObserver), iViewportSize(KMaxTInt, KMaxTInt) |
|
40 {} |
|
41 |
|
42 void CDigitalCamera::ConstructL() |
|
43 { |
|
44 TInt cameraCount = CCamera::CamerasAvailable(); |
|
45 |
|
46 LOGARG("Camera count is %d", cameraCount); |
|
47 |
|
48 // Use main camera (index 0) |
|
49 iCamera = CCamera::New2L(*this, 0, 0); |
|
50 iCameraSetting = CCamera::CCameraAdvancedSettings::NewL(*iCamera); |
|
51 |
|
52 TCameraInfo cameraInfo; |
|
53 iCamera->CameraInfo(cameraInfo); |
|
54 |
|
55 LOGTXT("Camera capture sizes supported:"); |
|
56 |
|
57 for (TInt i = 0; i < cameraInfo.iNumImageSizesSupported; ++i) |
|
58 { |
|
59 TSize size; |
|
60 iCamera->EnumerateCaptureSizes(size, i, CCamera::EFormatExif); |
|
61 |
|
62 if (iViewportSize.iWidth > size.iWidth && iViewportSize.iHeight > size.iHeight) |
|
63 iViewportSize = size; |
|
64 |
|
65 LOGARG("Index %d Size %d x %d", i, size.iWidth, size.iHeight); |
|
66 } |
|
67 |
|
68 LOGARG("Using smallest viewport: %d x %d", iViewportSize.iWidth, iViewportSize.iHeight); |
|
69 } |
|
70 |
|
71 void CDigitalCamera::Start() |
|
72 { |
|
73 iCamera->Reserve(); |
|
74 } |
|
75 |
|
76 void CDigitalCamera::Stop() |
|
77 { |
|
78 iCamera->Release(); |
|
79 } |
|
80 |
|
81 void CDigitalCamera::StartFocus() |
|
82 { |
|
83 iCameraSetting->SetAutoFocusType(CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle); |
|
84 } |
|
85 |
|
86 void CDigitalCamera::ReserveComplete(TInt aError) |
|
87 { |
|
88 if (aError) |
|
89 { |
|
90 LOGARG("Camera reserve complete error %d", aError); |
|
91 iObserver.CameraReady(aError); |
|
92 } |
|
93 else |
|
94 iCamera->PowerOn(); |
|
95 } |
|
96 |
|
97 void CDigitalCamera::PowerOnComplete(TInt aError) |
|
98 { |
|
99 TCameraInfo cameraInfo; |
|
100 iCamera->CameraInfo(cameraInfo); |
|
101 |
|
102 if ((aError == KErrNone) && |
|
103 (cameraInfo.iOptionsSupported & TCameraInfo::EViewFinderBitmapsSupported) && |
|
104 (cameraInfo.iOrientation == TCameraInfo::EOrientationOutwards)) |
|
105 { |
|
106 TSize requestSize(iViewportSize); |
|
107 |
|
108 LOGARG("Requesting viewfinder size %d x %d", requestSize.iWidth, requestSize.iHeight); |
|
109 TRAPD(error, iCamera->StartViewFinderL(CCamera::EFormatFbsBitmapColor16MU, requestSize)); |
|
110 LOGARG("Obtaining viewfinder size %d x %d", requestSize.iWidth, requestSize.iHeight); |
|
111 |
|
112 iObserver.CameraReady(error); |
|
113 } |
|
114 else |
|
115 { |
|
116 // Either power complete error or viewfinder bitmap unsupported |
|
117 iObserver.CameraReady(KErrNotSupported); |
|
118 } |
|
119 } |
|
120 |
|
121 void CDigitalCamera::ViewFinderFrameReady(CFbsBitmap& aFrame) |
|
122 { |
|
123 iObserver.CameraFrame(aFrame); |
|
124 } |
|
125 |
|
126 void CDigitalCamera::ImageReady(CFbsBitmap* /*aBitmap*/, HBufC8* /*aData*/, TInt /*aError*/) |
|
127 {} |
|
128 |
|
129 void CDigitalCamera::FrameBufferReady(MFrameBuffer* /*aFrameBuffer*/, TInt /*aError*/) |
|
130 {} |
|
131 |
|
132 void CDigitalCamera::HandleEvent(const TECAMEvent& aEvent) |
|
133 { |
|
134 if (aEvent.iEventType == KUidECamEventReserveComplete) |
|
135 ReserveComplete(aEvent.iErrorCode); |
|
136 else if (aEvent.iEventType == KUidECamEventPowerOnComplete) |
|
137 PowerOnComplete(aEvent.iErrorCode); |
|
138 else if (aEvent.iEventType == KUidECamEventCameraSettingFocusRange || |
|
139 aEvent.iEventType == KUidECamEventCameraSettingFocusRange2) |
|
140 ; |
|
141 else if (aEvent.iEventType == KUidECamEventCameraSettingAutoFocusType || |
|
142 aEvent.iEventType == KUidECamEventCameraSettingAutoFocusType2) |
|
143 ; |
|
144 else if (aEvent.iEventType == KUidECamEventCameraSettingsOptimalFocus) |
|
145 iObserver.FocusReady(aEvent.iErrorCode); |
|
146 |
|
147 LOGARG("Camera event %x (error %d)", aEvent.iEventType, aEvent.iErrorCode); |
|
148 } |
|
149 |
|
150 void CDigitalCamera::ViewFinderReady(MCameraBuffer& aCameraBuffer, TInt /*aError*/) |
|
151 { |
|
152 CFbsBitmap& bitmap = aCameraBuffer.BitmapL(0); |
|
153 ViewFinderFrameReady(bitmap); |
|
154 aCameraBuffer.Release(); |
|
155 } |
|
156 |
|
157 void CDigitalCamera::ImageBufferReady(MCameraBuffer& /*aCameraBuffer*/, TInt /*aError*/) |
|
158 {} |
|
159 |
|
160 void CDigitalCamera::VideoBufferReady(MCameraBuffer& /*aCameraBuffer*/, TInt /*aError*/) |
|
161 {} |