|
1 /* |
|
2 * Copyright (C) 2012-2014 Mozilla Foundation |
|
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 #ifndef DOM_CAMERA_GONKCAMERAHWMGR_H |
|
18 #define DOM_CAMERA_GONKCAMERAHWMGR_H |
|
19 |
|
20 #include <binder/IMemory.h> |
|
21 #include <camera/Camera.h> |
|
22 #include <camera/CameraParameters.h> |
|
23 #include <utils/threads.h> |
|
24 |
|
25 #include "GonkCameraControl.h" |
|
26 #include "CameraCommon.h" |
|
27 |
|
28 #include "GonkCameraListener.h" |
|
29 #include "GonkNativeWindow.h" |
|
30 #include "GonkCameraParameters.h" |
|
31 #include "mozilla/ReentrantMonitor.h" |
|
32 |
|
33 namespace mozilla { |
|
34 class nsGonkCameraControl; |
|
35 class GonkCameraParameters; |
|
36 } |
|
37 |
|
38 namespace android { |
|
39 |
|
40 class GonkCameraHardware : public GonkNativeWindowNewFrameCallback |
|
41 , public CameraListener |
|
42 { |
|
43 protected: |
|
44 GonkCameraHardware(mozilla::nsGonkCameraControl* aTarget, uint32_t aCameraId, const sp<Camera>& aCamera); |
|
45 virtual ~GonkCameraHardware(); |
|
46 virtual nsresult Init(); |
|
47 |
|
48 public: |
|
49 static sp<GonkCameraHardware> Connect(mozilla::nsGonkCameraControl* aTarget, uint32_t aCameraId); |
|
50 virtual void Close(); |
|
51 |
|
52 // derived from GonkNativeWindowNewFrameCallback |
|
53 virtual void OnNewFrame() MOZ_OVERRIDE; |
|
54 |
|
55 // derived from CameraListener |
|
56 virtual void notify(int32_t aMsgType, int32_t ext1, int32_t ext2); |
|
57 virtual void postData(int32_t aMsgType, const sp<IMemory>& aDataPtr, camera_frame_metadata_t* metadata); |
|
58 virtual void postDataTimestamp(nsecs_t aTimestamp, int32_t aMsgType, const sp<IMemory>& aDataPtr); |
|
59 |
|
60 /** |
|
61 * The physical orientation of the camera sensor: 0, 90, 180, or 270. |
|
62 * |
|
63 * For example, suppose a device has a naturally tall screen. The |
|
64 * back-facing camera sensor is mounted in landscape. You are looking at |
|
65 * the screen. If the top side of the camera sensor is aligned with the |
|
66 * right edge of the screen in natural orientation, the value should be |
|
67 * 90. If the top side of a front-facing camera sensor is aligned with the |
|
68 * right of the screen, the value should be 270. |
|
69 * |
|
70 * RAW_SENSOR_ORIENTATION is the uncorrected orientation returned directly |
|
71 * by get_camera_info(); OFFSET_SENSOR_ORIENTATION is the offset adjusted |
|
72 * orientation. |
|
73 */ |
|
74 enum { |
|
75 RAW_SENSOR_ORIENTATION, |
|
76 OFFSET_SENSOR_ORIENTATION |
|
77 }; |
|
78 virtual int GetSensorOrientation(uint32_t aType = RAW_SENSOR_ORIENTATION); |
|
79 |
|
80 virtual int AutoFocus(); |
|
81 virtual int CancelAutoFocus(); |
|
82 virtual int StartFaceDetection(); |
|
83 virtual int StopFaceDetection(); |
|
84 virtual int TakePicture(); |
|
85 virtual void CancelTakePicture(); |
|
86 virtual int StartPreview(); |
|
87 virtual void StopPreview(); |
|
88 virtual int PushParameters(const mozilla::GonkCameraParameters& aParams); |
|
89 virtual int PushParameters(const CameraParameters& aParams); |
|
90 virtual nsresult PullParameters(mozilla::GonkCameraParameters& aParams); |
|
91 virtual void PullParameters(CameraParameters& aParams); |
|
92 virtual int StartRecording(); |
|
93 virtual int StopRecording(); |
|
94 virtual int SetListener(const sp<GonkCameraListener>& aListener); |
|
95 virtual void ReleaseRecordingFrame(const sp<IMemory>& aFrame); |
|
96 virtual int StoreMetaDataInBuffers(bool aEnabled); |
|
97 |
|
98 protected: |
|
99 uint32_t mCameraId; |
|
100 bool mClosing; |
|
101 uint32_t mNumFrames; |
|
102 sp<Camera> mCamera; |
|
103 mozilla::nsGonkCameraControl* mTarget; |
|
104 sp<GonkNativeWindow> mNativeWindow; |
|
105 sp<GonkCameraListener> mListener; |
|
106 int mRawSensorOrientation; |
|
107 int mSensorOrientation; |
|
108 |
|
109 private: |
|
110 GonkCameraHardware(const GonkCameraHardware&) MOZ_DELETE; |
|
111 GonkCameraHardware& operator=(const GonkCameraHardware&) MOZ_DELETE; |
|
112 }; |
|
113 |
|
114 } // namespace android |
|
115 |
|
116 #endif // GONK_IMPL_HW_MGR_H |