2 * Copyright (C) 2012 Mozilla Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef DOM_CAMERA_GONKCAMERAHWMGR_H
18 #define DOM_CAMERA_GONKCAMERAHWMGR_H
20 #include "libcameraservice/CameraHardwareInterface.h"
21 #include "binder/IMemory.h"
22 #include "mozilla/ReentrantMonitor.h"
24 #include "GonkCameraControl.h"
26 #define DOM_CAMERA_LOG_LEVEL 3
27 #include "CameraCommon.h"
29 #include "GonkNativeWindow.h"
32 #define GIHM_TIMING_RECEIVEFRAME 0
33 #define GIHM_TIMING_OVERALL 1
35 using namespace mozilla
;
36 using namespace android
;
40 typedef class nsGonkCameraControl GonkCamera
;
42 class GonkCameraHardware
: GonkNativeWindowNewFrameCallback
45 GonkCameraHardware(GonkCamera
* aTarget
, PRUint32 aCamera
);
46 ~GonkCameraHardware();
49 static void DataCallback(int32_t aMsgType
, const sp
<IMemory
> &aDataPtr
, camera_frame_metadata_t
* aMetadata
, void* aUser
);
50 static void NotifyCallback(int32_t aMsgType
, int32_t ext1
, int32_t ext2
, void* aUser
);
53 virtual void OnNewFrame() MOZ_OVERRIDE
;
55 static void ReleaseHandle(PRUint32 aHwHandle
);
56 static PRUint32
GetHandle(GonkCamera
* aTarget
, PRUint32 aCamera
);
57 static PRUint32
GetFps(PRUint32 aHwHandle
);
58 static void GetPreviewSize(PRUint32 aHwHandle
, PRUint32
* aWidth
, PRUint32
* aHeight
);
59 static void SetPreviewSize(PRUint32 aHwHandle
, PRUint32 aWidth
, PRUint32 aHeight
);
60 static int AutoFocus(PRUint32 aHwHandle
);
61 static void CancelAutoFocus(PRUint32 aHwHandle
);
62 static int TakePicture(PRUint32 aHwHandle
);
63 static void CancelTakePicture(PRUint32 aHwHandle
);
64 static int StartPreview(PRUint32 aHwHandle
);
65 static void StopPreview(PRUint32 aHwHandle
);
66 static int PushParameters(PRUint32 aHwHandle
, const CameraParameters
& aParams
);
67 static void PullParameters(PRUint32 aHwHandle
, CameraParameters
& aParams
);
70 PREVIEW_FORMAT_UNKNOWN
,
71 PREVIEW_FORMAT_YUV420P
,
72 PREVIEW_FORMAT_YUV420SP
74 // GetPreviewFormat() MUST be called only after StartPreview().
75 static PRUint32
GetPreviewFormat(PRUint32 aHwHandle
);
78 static GonkCameraHardware
* sHw
;
79 static PRUint32 sHwHandle
;
81 static GonkCameraHardware
* GetHardware(PRUint32 aHwHandle
)
83 if (aHwHandle
== sHwHandle
) {
85 * In the initial case, sHw will be null and sHwHandle will be 0,
86 * so even if this function is called with aHwHandle = 0, the
87 * result will still be null.
94 // Instance wrappers to make member function access easier.
95 void SetPreviewSize(PRUint32 aWidth
, PRUint32 aHeight
);
102 PRUint32 mPreviewFormat
;
104 mozilla::ReentrantMonitor mMonitor
;
106 sp
<CameraHardwareInterface
> mHardware
;
108 camera_module_t
* mModule
;
109 sp
<ANativeWindow
> mWindow
;
110 CameraParameters mParams
;
111 #if GIHM_TIMING_OVERALL
112 struct timespec mStart
;
113 struct timespec mAutoFocusStart
;
123 GonkCameraHardware(const GonkCameraHardware
&) MOZ_DELETE
;
124 GonkCameraHardware
& operator=(const GonkCameraHardware
&) MOZ_DELETE
;
127 } // namespace mozilla
129 #endif // GONK_IMPL_HW_MGR_H