2012-07-30 14:59:05 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DOM_CAMERA_GONKCAMERAHWMGR_H
|
|
|
|
#define DOM_CAMERA_GONKCAMERAHWMGR_H
|
|
|
|
|
|
|
|
#include "libcameraservice/CameraHardwareInterface.h"
|
|
|
|
#include "binder/IMemory.h"
|
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2012-09-28 22:30:52 -07:00
|
|
|
#include "GonkCameraListener.h"
|
|
|
|
#include <utils/threads.h>
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
#include "GonkCameraControl.h"
|
|
|
|
#include "CameraCommon.h"
|
|
|
|
|
2012-08-17 03:56:55 -07:00
|
|
|
#include "GonkNativeWindow.h"
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
// config
|
|
|
|
#define GIHM_TIMING_RECEIVEFRAME 0
|
|
|
|
#define GIHM_TIMING_OVERALL 1
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
typedef class nsGonkCameraControl GonkCamera;
|
|
|
|
|
2012-11-12 16:06:31 -08:00
|
|
|
class GonkCameraHardware : android::GonkNativeWindowNewFrameCallback
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
GonkCameraHardware(GonkCamera* aTarget, uint32_t aCamera);
|
2012-07-30 14:59:05 -07:00
|
|
|
~GonkCameraHardware();
|
2012-09-04 18:01:56 -07:00
|
|
|
void Init();
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-11-12 16:06:31 -08:00
|
|
|
static void DataCallback(int32_t aMsgType, const android::sp<android::IMemory> &aDataPtr, camera_frame_metadata_t* aMetadata, void* aUser);
|
2012-09-04 18:01:56 -07:00
|
|
|
static void NotifyCallback(int32_t aMsgType, int32_t ext1, int32_t ext2, void* aUser);
|
2012-11-12 16:06:31 -08:00
|
|
|
static void DataCallbackTimestamp(nsecs_t aTimestamp, int32_t aMsgType, const android::sp<android::IMemory>& aDataPtr, void* aUser);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
public:
|
2012-09-04 18:01:56 -07:00
|
|
|
virtual void OnNewFrame() MOZ_OVERRIDE;
|
|
|
|
|
2013-01-07 04:54:24 -08:00
|
|
|
static void ReleaseHandle(uint32_t aHwHandle, bool aUnregisterTarget);
|
2012-09-04 18:01:56 -07:00
|
|
|
static uint32_t GetHandle(GonkCamera* aTarget, uint32_t aCamera);
|
2012-10-24 17:23:01 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The physical orientation of the camera sensor: 0, 90, 180, or 270.
|
|
|
|
*
|
|
|
|
* For example, suppose a device has a naturally tall screen. The
|
|
|
|
* back-facing camera sensor is mounted in landscape. You are looking at
|
|
|
|
* the screen. If the top side of the camera sensor is aligned with the
|
|
|
|
* right edge of the screen in natural orientation, the value should be
|
|
|
|
* 90. If the top side of a front-facing camera sensor is aligned with the
|
|
|
|
* right of the screen, the value should be 270.
|
2012-11-06 19:32:01 -08:00
|
|
|
*
|
|
|
|
* RAW_SENSOR_ORIENTATION is the uncorrected orientation returned directly
|
|
|
|
* by get_camera_info(); OFFSET_SENSOR_ORIENTATION is the offset adjusted
|
|
|
|
* orientation.
|
2012-10-24 17:23:01 -07:00
|
|
|
*/
|
2012-11-06 19:32:01 -08:00
|
|
|
enum {
|
|
|
|
RAW_SENSOR_ORIENTATION,
|
|
|
|
OFFSET_SENSOR_ORIENTATION
|
|
|
|
};
|
|
|
|
static int GetSensorOrientation(uint32_t aHwHandle, uint32_t aType = OFFSET_SENSOR_ORIENTATION);
|
2012-10-24 17:23:01 -07:00
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
static int AutoFocus(uint32_t aHwHandle);
|
|
|
|
static void CancelAutoFocus(uint32_t aHwHandle);
|
|
|
|
static int TakePicture(uint32_t aHwHandle);
|
|
|
|
static void CancelTakePicture(uint32_t aHwHandle);
|
|
|
|
static int StartPreview(uint32_t aHwHandle);
|
|
|
|
static void StopPreview(uint32_t aHwHandle);
|
2012-11-12 16:06:31 -08:00
|
|
|
static int PushParameters(uint32_t aHwHandle, const android::CameraParameters& aParams);
|
|
|
|
static void PullParameters(uint32_t aHwHandle, android::CameraParameters& aParams);
|
2012-09-28 22:30:52 -07:00
|
|
|
static int StartRecording(uint32_t aHwHandle);
|
|
|
|
static int StopRecording(uint32_t aHwHandle);
|
2012-11-12 16:06:31 -08:00
|
|
|
static int SetListener(uint32_t aHwHandle, const android::sp<android::GonkCameraListener>& aListener);
|
|
|
|
static void ReleaseRecordingFrame(uint32_t aHwHandle, const android::sp<android::IMemory>& aFrame);
|
2012-09-28 22:30:52 -07:00
|
|
|
static int StoreMetaDataInBuffers(uint32_t aHwHandle, bool aEnabled);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static GonkCameraHardware* sHw;
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t sHwHandle;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static GonkCameraHardware* GetHardware(uint32_t aHwHandle)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
if (aHwHandle == sHwHandle) {
|
|
|
|
/**
|
|
|
|
* In the initial case, sHw will be null and sHwHandle will be 0,
|
|
|
|
* so even if this function is called with aHwHandle = 0, the
|
|
|
|
* result will still be null.
|
|
|
|
*/
|
|
|
|
return sHw;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
// Instance wrapper to make member function access easier.
|
2012-07-30 14:59:05 -07:00
|
|
|
int StartPreview();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCamera;
|
2012-07-30 14:59:05 -07:00
|
|
|
bool mClosing;
|
|
|
|
mozilla::ReentrantMonitor mMonitor;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mNumFrames;
|
2012-11-12 16:06:31 -08:00
|
|
|
android::sp<android::CameraHardwareInterface> mHardware;
|
2012-07-30 14:59:05 -07:00
|
|
|
GonkCamera* mTarget;
|
|
|
|
camera_module_t* mModule;
|
2012-11-12 16:06:31 -08:00
|
|
|
android::sp<ANativeWindow> mWindow;
|
2012-07-30 14:59:05 -07:00
|
|
|
#if GIHM_TIMING_OVERALL
|
|
|
|
struct timespec mStart;
|
|
|
|
struct timespec mAutoFocusStart;
|
|
|
|
#endif
|
2012-11-12 16:06:31 -08:00
|
|
|
android::sp<android::GonkCameraListener> mListener;
|
2012-07-30 14:59:05 -07:00
|
|
|
bool mInitialized;
|
2012-11-06 19:32:01 -08:00
|
|
|
int mRawSensorOrientation;
|
2012-10-24 17:23:01 -07:00
|
|
|
int mSensorOrientation;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
bool IsInitialized()
|
|
|
|
{
|
|
|
|
return mInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GonkCameraHardware(const GonkCameraHardware&) MOZ_DELETE;
|
|
|
|
GonkCameraHardware& operator=(const GonkCameraHardware&) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GONK_IMPL_HW_MGR_H
|