2012-07-30 14:59:05 -07:00
|
|
|
/*
|
2014-02-19 20:18:52 -08:00
|
|
|
* Copyright (C) 2012-2014 Mozilla Foundation
|
2012-07-30 14:59:05 -07:00
|
|
|
*
|
|
|
|
* 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_GONKCAMERACONTROL_H
|
|
|
|
#define DOM_CAMERA_GONKCAMERACONTROL_H
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "base/basictypes.h"
|
2014-10-31 10:19:06 -07:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2012-12-04 18:00:39 -08:00
|
|
|
#include "DeviceStorage.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "CameraControlImpl.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "CameraCommon.h"
|
2013-03-08 11:43:33 -08:00
|
|
|
#include "GonkCameraHwMgr.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "GonkCameraParameters.h"
|
2013-03-08 11:43:33 -08:00
|
|
|
|
2015-03-10 16:39:49 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include <media/MediaProfiles.h>
|
|
|
|
#include <camera/Camera.h>
|
|
|
|
#include "GonkRecorder.h"
|
|
|
|
#else
|
|
|
|
#include "FallbackCameraPlatform.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
namespace android {
|
2014-02-14 14:41:07 -08:00
|
|
|
class GonkCameraHardware;
|
|
|
|
class GonkRecorder;
|
2014-12-17 22:00:00 -08:00
|
|
|
class GonkCameraSource;
|
2013-03-08 11:43:33 -08:00
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-08-17 03:56:55 -07:00
|
|
|
namespace layers {
|
2014-03-31 08:24:28 -07:00
|
|
|
class TextureClient;
|
2014-02-14 14:41:07 -08:00
|
|
|
class ImageContainer;
|
2012-08-17 03:56:55 -07:00
|
|
|
}
|
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
class GonkRecorderProfile;
|
|
|
|
class GonkRecorderProfileManager;
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
class nsGonkCameraControl : public CameraControlImpl
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl(uint32_t aCameraId);
|
|
|
|
|
|
|
|
void OnAutoFocusComplete(bool aSuccess);
|
2014-04-09 08:52:10 -07:00
|
|
|
void OnFacesDetected(camera_frame_metadata_t* aMetaData);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength);
|
|
|
|
void OnTakePictureError();
|
2014-07-02 16:55:00 -07:00
|
|
|
void OnRateLimitPreview(bool aLimit);
|
2014-03-31 08:24:28 -07:00
|
|
|
void OnNewPreviewFrame(layers::TextureClient* aBuffer);
|
2015-03-10 16:39:49 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnRecorderEvent(int msg, int ext1, int ext2);
|
2015-03-10 16:39:49 -07:00
|
|
|
#endif
|
2014-04-25 13:28:15 -07:00
|
|
|
void OnSystemError(CameraControlListener::SystemContext aWhere, nsresult aError);
|
2014-07-02 16:55:00 -07:00
|
|
|
|
2014-04-25 13:28:15 -07:00
|
|
|
// See ICameraControl.h for getter/setter return values.
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, double& aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Set(uint32_t aKey, int32_t aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, int32_t& aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Set(uint32_t aKey, int64_t aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, int64_t& aValue) MOZ_OVERRIDE;
|
2014-06-30 03:33:00 -07:00
|
|
|
virtual nsresult Set(uint32_t aKey, bool aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, bool& aValue) MOZ_OVERRIDE;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult Set(uint32_t aKey, const Size& aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, Size& aValue) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual nsresult SetLocation(const Position& aLocation) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) MOZ_OVERRIDE;
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-10-31 10:19:06 -07:00
|
|
|
virtual nsresult GetRecorderProfiles(nsTArray<nsString>& aProfiles) MOZ_OVERRIDE;
|
|
|
|
virtual ICameraControl::RecorderProfile*
|
|
|
|
GetProfileInfo(const nsAString& aProfile) MOZ_OVERRIDE;
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult PushParameters();
|
|
|
|
nsresult PullParameters();
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~nsGonkCameraControl();
|
|
|
|
|
2014-07-02 16:55:00 -07:00
|
|
|
using CameraControlImpl::OnRateLimitPreview;
|
2014-02-14 14:41:07 -08:00
|
|
|
using CameraControlImpl::OnNewPreviewFrame;
|
|
|
|
using CameraControlImpl::OnAutoFocusComplete;
|
2014-04-09 08:52:10 -07:00
|
|
|
using CameraControlImpl::OnFacesDetected;
|
2014-02-14 14:41:07 -08:00
|
|
|
using CameraControlImpl::OnTakePictureComplete;
|
|
|
|
using CameraControlImpl::OnConfigurationChange;
|
2014-04-25 13:28:15 -07:00
|
|
|
using CameraControlImpl::OnUserError;
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-11-14 17:56:59 -08:00
|
|
|
typedef nsTArray<Size>::index_type SizeIndex;
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual void BeginBatchParameterSet() MOZ_OVERRIDE;
|
|
|
|
virtual void EndBatchParameterSet() MOZ_OVERRIDE;
|
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
nsresult Initialize();
|
|
|
|
|
2014-12-12 19:51:29 -08:00
|
|
|
nsresult ValidateConfiguration(const Configuration& aConfig, Configuration& aValidatedConfig);
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult SetConfigurationInternal(const Configuration& aConfig);
|
|
|
|
nsresult SetPictureConfiguration(const Configuration& aConfig);
|
|
|
|
nsresult SetVideoConfiguration(const Configuration& aConfig);
|
2014-11-12 10:54:48 -08:00
|
|
|
nsresult StartInternal(const Configuration* aInitialConfig);
|
2014-12-12 19:51:29 -08:00
|
|
|
nsresult StartPreviewInternal();
|
2014-11-25 11:45:00 -08:00
|
|
|
nsresult StopInternal();
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
template<class T> nsresult SetAndPush(uint32_t aKey, const T& aValue);
|
|
|
|
|
2014-04-25 13:28:15 -07:00
|
|
|
// See CameraControlImpl.h for these methods' return values.
|
|
|
|
virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopImpl() MOZ_OVERRIDE;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult StartPreviewImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopPreviewImpl() MOZ_OVERRIDE;
|
2014-04-15 12:46:40 -07:00
|
|
|
virtual nsresult AutoFocusImpl() MOZ_OVERRIDE;
|
2014-04-09 08:52:10 -07:00
|
|
|
virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult TakePictureImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopRecordingImpl() MOZ_OVERRIDE;
|
2014-04-15 12:46:40 -07:00
|
|
|
virtual nsresult ResumeContinuousFocusImpl() MOZ_OVERRIDE;
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult PushParametersImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult PullParametersImpl() MOZ_OVERRIDE;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-05-14 14:33:00 -07:00
|
|
|
nsresult SetupRecording(int aFd, int aRotation, uint64_t aMaxFileSizeBytes,
|
|
|
|
uint64_t aMaxVideoLengthMs);
|
2014-04-09 08:53:41 -07:00
|
|
|
nsresult SetupRecordingFlash(bool aAutoEnableLowLightTorch);
|
2014-12-12 19:51:29 -08:00
|
|
|
nsresult SelectCaptureAndPreviewSize(const Size& aPreviewSize, const Size& aCaptureSize,
|
|
|
|
const Size& aMaxSize, uint32_t aCaptureSizeKey);
|
2014-11-14 17:56:59 -08:00
|
|
|
nsresult MaybeAdjustVideoSize();
|
2014-02-19 20:18:55 -08:00
|
|
|
nsresult PausePreview();
|
2014-04-07 15:21:00 -07:00
|
|
|
nsresult GetSupportedSize(const Size& aSize, const nsTArray<Size>& supportedSizes, Size& best);
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-10-31 10:19:06 -07:00
|
|
|
nsresult LoadRecorderProfiles();
|
|
|
|
static PLDHashOperator Enumerate(const nsAString& aProfileName,
|
|
|
|
RecorderProfile* aProfile,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
friend class SetPictureSize;
|
|
|
|
friend class SetThumbnailSize;
|
|
|
|
nsresult SetPictureSize(const Size& aSize);
|
|
|
|
nsresult SetPictureSizeImpl(const Size& aSize);
|
|
|
|
nsresult SetThumbnailSize(const Size& aSize);
|
|
|
|
nsresult UpdateThumbnailSize();
|
|
|
|
nsresult SetThumbnailSizeImpl(const Size& aSize);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-12-17 22:00:00 -08:00
|
|
|
friend class android::GonkCameraSource;
|
|
|
|
android::sp<android::GonkCameraHardware> GetCameraHw();
|
|
|
|
|
2014-01-23 16:10:23 -08:00
|
|
|
int32_t RationalizeRotation(int32_t aRotation);
|
|
|
|
|
2014-12-12 18:18:03 -08:00
|
|
|
uint32_t mCameraId;
|
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
android::sp<android::GonkCameraHardware> mCameraHw;
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
Size mLastThumbnailSize;
|
|
|
|
Size mLastRecorderSize;
|
|
|
|
uint32_t mPreviewFps;
|
|
|
|
bool mResumePreviewAfterTakingPicture;
|
2014-04-09 08:53:41 -07:00
|
|
|
bool mFlashSupported;
|
|
|
|
bool mLuminanceSupported;
|
|
|
|
bool mAutoFlashModeOverridden;
|
2014-09-16 12:36:48 -07:00
|
|
|
bool mSeparateVideoAndPreviewSizesSupported;
|
2014-02-14 14:41:07 -08:00
|
|
|
Atomic<uint32_t> mDeferConfigUpdate;
|
|
|
|
GonkCameraParameters mParams;
|
|
|
|
|
|
|
|
nsRefPtr<mozilla::layers::ImageContainer> mImageContainer;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2015-03-10 16:39:49 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-01-08 01:11:32 -08:00
|
|
|
nsRefPtr<android::GonkRecorder> mRecorder;
|
2015-03-10 16:39:49 -07:00
|
|
|
#endif
|
2014-06-10 06:52:22 -07:00
|
|
|
// Touching mRecorder happens inside this monitor because the destructor
|
|
|
|
// can run on any thread, and we need to be able to clean up properly if
|
|
|
|
// GonkCameraControl goes away.
|
|
|
|
ReentrantMonitor mRecorderMonitor;
|
2012-09-28 22:30:52 -07:00
|
|
|
|
2014-10-31 10:19:06 -07:00
|
|
|
// Supported recorder profiles
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, RecorderProfile> mRecorderProfiles;
|
2012-09-28 22:30:52 -07:00
|
|
|
|
2012-12-04 18:00:39 -08:00
|
|
|
nsRefPtr<DeviceStorageFile> mVideoFile;
|
2014-02-14 14:41:07 -08:00
|
|
|
nsString mFileFormat;
|
|
|
|
|
|
|
|
// Guards against calling StartPreviewImpl() while in OnTakePictureComplete().
|
|
|
|
ReentrantMonitor mReentrantMonitor;
|
2012-12-04 18:00:39 -08:00
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
private:
|
2015-01-06 15:35:02 -08:00
|
|
|
nsGonkCameraControl(const nsGonkCameraControl&) = delete;
|
|
|
|
nsGonkCameraControl& operator=(const nsGonkCameraControl&) = delete;
|
2012-07-30 14:59:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// camera driver callbacks
|
2014-07-02 16:55:00 -07:00
|
|
|
void OnRateLimitPreview(nsGonkCameraControl* gc, bool aLimit);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnTakePictureComplete(nsGonkCameraControl* gc, uint8_t* aData, uint32_t aLength);
|
|
|
|
void OnTakePictureError(nsGonkCameraControl* gc);
|
|
|
|
void OnAutoFocusComplete(nsGonkCameraControl* gc, bool aSuccess);
|
2014-04-09 08:12:25 -07:00
|
|
|
void OnAutoFocusMoving(nsGonkCameraControl* gc, bool aIsMoving);
|
2014-04-09 08:52:10 -07:00
|
|
|
void OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData);
|
2014-03-31 08:24:28 -07:00
|
|
|
void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer);
|
2012-09-30 17:37:47 -07:00
|
|
|
void OnShutter(nsGonkCameraControl* gc);
|
2014-04-25 13:28:15 -07:00
|
|
|
void OnSystemError(nsGonkCameraControl* gc,
|
|
|
|
CameraControlListener::SystemContext aWhere,
|
|
|
|
int32_t aArg1, int32_t aArg2);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_GONKCAMERACONTROL_H
|