Backout a74bd5095902, Bug 959405 - Please update the Buri Moz-central, 1.3, 1.2 with...
[gecko.git] / dom / camera / GonkCameraHwMgr.h
blobee1724f61221ccc2560ae39bff1b4d012f8e2a15
1 /*
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 <binder/IMemory.h>
21 #include <camera/Camera.h>
22 #include <camera/CameraParameters.h>
23 #include <utils/threads.h>
25 #include "GonkCameraControl.h"
26 #include "CameraCommon.h"
28 #include "GonkCameraListener.h"
29 #include "GonkNativeWindow.h"
30 #include "mozilla/ReentrantMonitor.h"
32 // config
33 #define GIHM_TIMING_RECEIVEFRAME 0
34 #define GIHM_TIMING_OVERALL 1
37 namespace mozilla {
38 class nsGonkCameraControl;
41 namespace android {
43 class GonkCameraHardware : public GonkNativeWindowNewFrameCallback
44 , public CameraListener
46 protected:
47 GonkCameraHardware(mozilla::nsGonkCameraControl* aTarget, uint32_t aCameraId, const sp<Camera>& aCamera);
48 virtual ~GonkCameraHardware();
49 void Init();
51 public:
52 static sp<GonkCameraHardware> Connect(mozilla::nsGonkCameraControl* aTarget, uint32_t aCameraId);
53 void Close();
55 // derived from GonkNativeWindowNewFrameCallback
56 virtual void OnNewFrame() MOZ_OVERRIDE;
58 // derived from CameraListener
59 virtual void notify(int32_t aMsgType, int32_t ext1, int32_t ext2);
60 virtual void postData(int32_t aMsgType, const sp<IMemory>& aDataPtr, camera_frame_metadata_t* metadata);
61 virtual void postDataTimestamp(nsecs_t aTimestamp, int32_t aMsgType, const sp<IMemory>& aDataPtr);
63 /**
64 * The physical orientation of the camera sensor: 0, 90, 180, or 270.
66 * For example, suppose a device has a naturally tall screen. The
67 * back-facing camera sensor is mounted in landscape. You are looking at
68 * the screen. If the top side of the camera sensor is aligned with the
69 * right edge of the screen in natural orientation, the value should be
70 * 90. If the top side of a front-facing camera sensor is aligned with the
71 * right of the screen, the value should be 270.
73 * RAW_SENSOR_ORIENTATION is the uncorrected orientation returned directly
74 * by get_camera_info(); OFFSET_SENSOR_ORIENTATION is the offset adjusted
75 * orientation.
77 enum {
78 RAW_SENSOR_ORIENTATION,
79 OFFSET_SENSOR_ORIENTATION
81 int GetSensorOrientation(uint32_t aType = RAW_SENSOR_ORIENTATION);
83 int AutoFocus();
84 void CancelAutoFocus();
85 int TakePicture();
86 void CancelTakePicture();
87 int StartPreview();
88 void StopPreview();
89 int PushParameters(const CameraParameters& aParams);
90 void PullParameters(CameraParameters& aParams);
91 int StartRecording();
92 int StopRecording();
93 int SetListener(const sp<GonkCameraListener>& aListener);
94 void ReleaseRecordingFrame(const sp<IMemory>& aFrame);
95 int StoreMetaDataInBuffers(bool aEnabled);
97 protected:
99 uint32_t mCameraId;
100 bool mClosing;
101 mozilla::ReentrantMonitor mMonitor;
102 uint32_t mNumFrames;
103 sp<Camera> mCamera;
104 mozilla::nsGonkCameraControl* mTarget;
105 sp<GonkNativeWindow> mNativeWindow;
106 #if GIHM_TIMING_OVERALL
107 struct timespec mStart;
108 struct timespec mAutoFocusStart;
109 #endif
110 sp<GonkCameraListener> mListener;
111 bool mInitialized;
112 int mRawSensorOrientation;
113 int mSensorOrientation;
115 bool IsInitialized()
117 return mInitialized;
120 private:
121 GonkCameraHardware(const GonkCameraHardware&) MOZ_DELETE;
122 GonkCameraHardware& operator=(const GonkCameraHardware&) MOZ_DELETE;
125 } // namespace android
127 #endif // GONK_IMPL_HW_MGR_H