2012-07-31 01:59:05 +04:00
|
|
|
/*
|
2014-02-20 08:18:52 +04:00
|
|
|
* Copyright (C) 2012-2014 Mozilla Foundation
|
2012-07-31 01:59:05 +04: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-05 05:01:56 +04:00
|
|
|
#include "base/basictypes.h"
|
2012-10-24 02:30:28 +04:00
|
|
|
#include <media/MediaProfiles.h>
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2012-12-05 06:00:39 +04:00
|
|
|
#include "DeviceStorage.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
#include "CameraControlImpl.h"
|
2012-07-31 01:59:05 +04:00
|
|
|
#include "CameraCommon.h"
|
2012-09-29 09:30:52 +04:00
|
|
|
#include "GonkRecorder.h"
|
2013-03-08 23:43:33 +04:00
|
|
|
#include "GonkCameraHwMgr.h"
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "GonkCameraParameters.h"
|
2013-03-08 23:43:33 +04:00
|
|
|
|
|
|
|
namespace android {
|
2014-02-15 02:41:07 +04:00
|
|
|
class GonkCameraHardware;
|
|
|
|
class MediaProfiles;
|
|
|
|
class GonkRecorder;
|
2013-03-08 23:43:33 +04:00
|
|
|
}
|
2012-07-31 01:59:05 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-08-17 14:56:55 +04:00
|
|
|
namespace layers {
|
2014-03-31 19:24:28 +04:00
|
|
|
class TextureClient;
|
2014-02-15 02:41:07 +04:00
|
|
|
class ImageContainer;
|
2012-08-17 14:56:55 +04:00
|
|
|
}
|
|
|
|
|
2012-10-24 02:30:28 +04:00
|
|
|
class GonkRecorderProfile;
|
|
|
|
class GonkRecorderProfileManager;
|
|
|
|
|
2012-09-05 05:01:56 +04:00
|
|
|
class nsGonkCameraControl : public CameraControlImpl
|
2012-07-31 01:59:05 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-02-15 02:41:07 +04:00
|
|
|
nsGonkCameraControl(uint32_t aCameraId);
|
|
|
|
|
|
|
|
void OnAutoFocusComplete(bool aSuccess);
|
2014-04-09 19:52:10 +04:00
|
|
|
void OnFacesDetected(camera_frame_metadata_t* aMetaData);
|
2014-02-15 02:41:07 +04:00
|
|
|
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength);
|
|
|
|
void OnTakePictureError();
|
2014-03-31 19:24:28 +04:00
|
|
|
void OnNewPreviewFrame(layers::TextureClient* aBuffer);
|
2014-02-15 02:41:07 +04:00
|
|
|
void OnRecorderEvent(int msg, int ext1, int ext2);
|
2014-04-26 00:28:15 +04:00
|
|
|
void OnSystemError(CameraControlListener::SystemContext aWhere, nsresult aError);
|
|
|
|
|
|
|
|
// See ICameraControl.h for getter/setter return values.
|
2014-02-15 02:41:07 +04: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;
|
|
|
|
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 17:27:44 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
nsresult PushParameters();
|
|
|
|
nsresult PullParameters();
|
2012-07-31 01:59:05 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~nsGonkCameraControl();
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
using CameraControlImpl::OnNewPreviewFrame;
|
|
|
|
using CameraControlImpl::OnAutoFocusComplete;
|
2014-04-09 19:52:10 +04:00
|
|
|
using CameraControlImpl::OnFacesDetected;
|
2014-02-15 02:41:07 +04:00
|
|
|
using CameraControlImpl::OnTakePictureComplete;
|
|
|
|
using CameraControlImpl::OnConfigurationChange;
|
2014-04-26 00:28:15 +04:00
|
|
|
using CameraControlImpl::OnUserError;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
virtual void BeginBatchParameterSet() MOZ_OVERRIDE;
|
|
|
|
virtual void EndBatchParameterSet() MOZ_OVERRIDE;
|
|
|
|
|
2014-02-20 08:18:52 +04:00
|
|
|
nsresult Initialize();
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
nsresult SetConfigurationInternal(const Configuration& aConfig);
|
|
|
|
nsresult SetPictureConfiguration(const Configuration& aConfig);
|
|
|
|
nsresult SetVideoConfiguration(const Configuration& aConfig);
|
|
|
|
|
|
|
|
template<class T> nsresult SetAndPush(uint32_t aKey, const T& aValue);
|
|
|
|
|
2014-04-26 00:28:15 +04: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-15 02:41:07 +04:00
|
|
|
virtual nsresult StartPreviewImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopPreviewImpl() MOZ_OVERRIDE;
|
2014-04-15 23:46:40 +04:00
|
|
|
virtual nsresult AutoFocusImpl() MOZ_OVERRIDE;
|
2014-04-09 19:52:10 +04:00
|
|
|
virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE;
|
2014-02-15 02:41:07 +04: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 23:46:40 +04:00
|
|
|
virtual nsresult ResumeContinuousFocusImpl() MOZ_OVERRIDE;
|
2014-02-15 02:41:07 +04:00
|
|
|
virtual nsresult PushParametersImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult PullParametersImpl() MOZ_OVERRIDE;
|
|
|
|
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() MOZ_OVERRIDE;
|
2012-10-24 02:30:28 +04:00
|
|
|
already_AddRefed<GonkRecorderProfileManager> GetGonkRecorderProfileManager();
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-05-15 01:33:00 +04:00
|
|
|
nsresult SetupRecording(int aFd, int aRotation, uint64_t aMaxFileSizeBytes,
|
|
|
|
uint64_t aMaxVideoLengthMs);
|
2014-04-09 19:53:41 +04:00
|
|
|
nsresult SetupRecordingFlash(bool aAutoEnableLowLightTorch);
|
2012-12-23 19:56:59 +04:00
|
|
|
nsresult SetupVideoMode(const nsAString& aProfile);
|
2014-02-15 02:41:07 +04:00
|
|
|
nsresult SetPreviewSize(const Size& aSize);
|
2014-04-08 02:21:00 +04:00
|
|
|
nsresult SetVideoSize(const Size& aSize);
|
2014-02-20 08:18:55 +04:00
|
|
|
nsresult PausePreview();
|
2014-04-08 02:21:00 +04:00
|
|
|
nsresult GetSupportedSize(const Size& aSize, const nsTArray<Size>& supportedSizes, Size& best);
|
2014-02-15 02:41:07 +04: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-31 01:59:05 +04:00
|
|
|
|
2014-01-24 04:10:23 +04:00
|
|
|
int32_t RationalizeRotation(int32_t aRotation);
|
|
|
|
|
2013-03-08 23:43:33 +04:00
|
|
|
android::sp<android::GonkCameraHardware> mCameraHw;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
Size mLastPictureSize;
|
|
|
|
Size mLastThumbnailSize;
|
|
|
|
Size mLastRecorderSize;
|
|
|
|
uint32_t mPreviewFps;
|
|
|
|
bool mResumePreviewAfterTakingPicture;
|
2014-04-09 19:53:41 +04:00
|
|
|
bool mFlashSupported;
|
|
|
|
bool mLuminanceSupported;
|
|
|
|
bool mAutoFlashModeOverridden;
|
2014-02-15 02:41:07 +04:00
|
|
|
Atomic<uint32_t> mDeferConfigUpdate;
|
|
|
|
GonkCameraParameters mParams;
|
|
|
|
|
|
|
|
nsRefPtr<mozilla::layers::ImageContainer> mImageContainer;
|
2012-07-31 01:59:05 +04:00
|
|
|
|
2012-09-29 09:30:52 +04:00
|
|
|
android::MediaProfiles* mMediaProfiles;
|
2013-01-08 13:11:32 +04:00
|
|
|
nsRefPtr<android::GonkRecorder> mRecorder;
|
2014-06-10 17:52:22 +04: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-29 09:30:52 +04:00
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
// Camcorder profile settings for the desired quality level
|
2012-10-24 02:30:28 +04:00
|
|
|
nsRefPtr<GonkRecorderProfileManager> mProfileManager;
|
|
|
|
nsRefPtr<GonkRecorderProfile> mRecorderProfile;
|
2012-09-29 09:30:52 +04:00
|
|
|
|
2012-12-05 06:00:39 +04:00
|
|
|
nsRefPtr<DeviceStorageFile> mVideoFile;
|
2014-02-15 02:41:07 +04:00
|
|
|
nsString mFileFormat;
|
|
|
|
|
|
|
|
// Guards against calling StartPreviewImpl() while in OnTakePictureComplete().
|
|
|
|
ReentrantMonitor mReentrantMonitor;
|
2012-12-05 06:00:39 +04:00
|
|
|
|
2012-07-31 01:59:05 +04:00
|
|
|
private:
|
|
|
|
nsGonkCameraControl(const nsGonkCameraControl&) MOZ_DELETE;
|
|
|
|
nsGonkCameraControl& operator=(const nsGonkCameraControl&) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
|
|
|
// camera driver callbacks
|
2014-02-15 02:41:07 +04:00
|
|
|
void OnTakePictureComplete(nsGonkCameraControl* gc, uint8_t* aData, uint32_t aLength);
|
|
|
|
void OnTakePictureError(nsGonkCameraControl* gc);
|
|
|
|
void OnAutoFocusComplete(nsGonkCameraControl* gc, bool aSuccess);
|
2014-04-09 19:12:25 +04:00
|
|
|
void OnAutoFocusMoving(nsGonkCameraControl* gc, bool aIsMoving);
|
2014-04-09 19:52:10 +04:00
|
|
|
void OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData);
|
2014-03-31 19:24:28 +04:00
|
|
|
void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer);
|
2012-10-01 04:37:47 +04:00
|
|
|
void OnShutter(nsGonkCameraControl* gc);
|
|
|
|
void OnClosed(nsGonkCameraControl* gc);
|
2014-04-26 00:28:15 +04:00
|
|
|
void OnSystemError(nsGonkCameraControl* gc,
|
|
|
|
CameraControlListener::SystemContext aWhere,
|
|
|
|
int32_t aArg1, int32_t aArg2);
|
2012-07-31 01:59:05 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_GONKCAMERACONTROL_H
|