2012-07-30 21:59:05 +00: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
|
|
|
|
|
2013-03-08 19:43:33 +00:00
|
|
|
#include <binder/IMemory.h>
|
|
|
|
#include <camera/Camera.h>
|
|
|
|
#include <camera/CameraParameters.h>
|
2012-09-29 05:30:52 +00:00
|
|
|
#include <utils/threads.h>
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
#include "GonkCameraControl.h"
|
|
|
|
#include "CameraCommon.h"
|
|
|
|
|
2013-03-08 19:43:33 +00:00
|
|
|
#include "GonkCameraListener.h"
|
2012-08-17 10:56:55 +00:00
|
|
|
#include "GonkNativeWindow.h"
|
2013-03-08 19:43:33 +00:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2012-08-17 10:56:55 +00:00
|
|
|
|
2012-07-30 21:59:05 +00:00
|
|
|
// config
|
|
|
|
#define GIHM_TIMING_RECEIVEFRAME 0
|
|
|
|
#define GIHM_TIMING_OVERALL 1
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-03-08 19:43:33 +00:00
|
|
|
class nsGonkCameraControl;
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-03-08 19:43:33 +00:00
|
|
|
namespace android {
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2013-03-08 19:43:33 +00:00
|
|
|
class GonkCameraHardware : public GonkNativeWindowNewFrameCallback
|
|
|
|
, public CameraListener
|
2012-07-30 21:59:05 +00:00
|
|
|
{
|
|
|
|
protected:
|
2013-03-08 19:43:33 +00:00
|
|
|
GonkCameraHardware(mozilla::nsGonkCameraControl* aTarget, uint32_t aCameraId, const sp<Camera>& aCamera);
|
|
|
|
virtual ~GonkCameraHardware();
|
2012-09-05 01:01:56 +00:00
|
|
|
void Init();
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
public:
|
2013-03-08 19:43:33 +00:00
|
|
|
static sp<GonkCameraHardware> Connect(mozilla::nsGonkCameraControl* aTarget, uint32_t aCameraId);
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
// derived from GonkNativeWindowNewFrameCallback
|
2012-09-05 01:01:56 +00:00
|
|
|
virtual void OnNewFrame() MOZ_OVERRIDE;
|
|
|
|
|
2013-03-08 19:43:33 +00:00
|
|
|
// derived from CameraListener
|
|
|
|
virtual void notify(int32_t aMsgType, int32_t ext1, int32_t ext2);
|
|
|
|
virtual void postData(int32_t aMsgType, const sp<IMemory>& aDataPtr, camera_frame_metadata_t* metadata);
|
|
|
|
virtual void postDataTimestamp(nsecs_t aTimestamp, int32_t aMsgType, const sp<IMemory>& aDataPtr);
|
2012-10-25 00:23:01 +00: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-07 03:32:01 +00:00
|
|
|
*
|
|
|
|
* RAW_SENSOR_ORIENTATION is the uncorrected orientation returned directly
|
|
|
|
* by get_camera_info(); OFFSET_SENSOR_ORIENTATION is the offset adjusted
|
|
|
|
* orientation.
|
2012-10-25 00:23:01 +00:00
|
|
|
*/
|
2012-11-07 03:32:01 +00:00
|
|
|
enum {
|
|
|
|
RAW_SENSOR_ORIENTATION,
|
|
|
|
OFFSET_SENSOR_ORIENTATION
|
|
|
|
};
|
2013-03-08 19:43:33 +00:00
|
|
|
int GetSensorOrientation(uint32_t aType = OFFSET_SENSOR_ORIENTATION);
|
|
|
|
|
|
|
|
int AutoFocus();
|
|
|
|
void CancelAutoFocus();
|
|
|
|
int TakePicture();
|
|
|
|
void CancelTakePicture();
|
|
|
|
int StartPreview();
|
|
|
|
void StopPreview();
|
|
|
|
int PushParameters(const CameraParameters& aParams);
|
|
|
|
void PullParameters(CameraParameters& aParams);
|
|
|
|
int StartRecording();
|
|
|
|
int StopRecording();
|
|
|
|
int SetListener(const sp<GonkCameraListener>& aListener);
|
|
|
|
void ReleaseRecordingFrame(const sp<IMemory>& aFrame);
|
|
|
|
int StoreMetaDataInBuffers(bool aEnabled);
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2013-03-08 19:43:33 +00:00
|
|
|
uint32_t mCameraId;
|
2012-07-30 21:59:05 +00:00
|
|
|
bool mClosing;
|
|
|
|
mozilla::ReentrantMonitor mMonitor;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mNumFrames;
|
2013-03-08 19:43:33 +00:00
|
|
|
sp<Camera> mCamera;
|
|
|
|
mozilla::nsGonkCameraControl* mTarget;
|
|
|
|
sp<GonkNativeWindow> mNativeWindow;
|
2012-07-30 21:59:05 +00:00
|
|
|
#if GIHM_TIMING_OVERALL
|
|
|
|
struct timespec mStart;
|
|
|
|
struct timespec mAutoFocusStart;
|
|
|
|
#endif
|
2013-03-08 19:43:33 +00:00
|
|
|
sp<GonkCameraListener> mListener;
|
2012-07-30 21:59:05 +00:00
|
|
|
bool mInitialized;
|
2012-11-07 03:32:01 +00:00
|
|
|
int mRawSensorOrientation;
|
2012-10-25 00:23:01 +00:00
|
|
|
int mSensorOrientation;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
bool IsInitialized()
|
|
|
|
{
|
|
|
|
return mInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GonkCameraHardware(const GonkCameraHardware&) MOZ_DELETE;
|
|
|
|
GonkCameraHardware& operator=(const GonkCameraHardware&) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
2013-03-08 19:43:33 +00:00
|
|
|
} // namespace android
|
2012-07-30 21:59:05 +00:00
|
|
|
|
|
|
|
#endif // GONK_IMPL_HW_MGR_H
|