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"
|
2012-10-23 15:30:28 -07:00
|
|
|
#include <media/MediaProfiles.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"
|
2012-09-28 22:30:52 -07:00
|
|
|
#include "GonkRecorder.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
|
|
|
|
|
|
|
namespace android {
|
2014-02-14 14:41:07 -08:00
|
|
|
class GonkCameraHardware;
|
|
|
|
class MediaProfiles;
|
|
|
|
class GonkRecorder;
|
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-02-14 14:41:07 -08:00
|
|
|
class GraphicBufferLocked;
|
|
|
|
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);
|
|
|
|
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength);
|
|
|
|
void OnTakePictureError();
|
|
|
|
void OnNewPreviewFrame(layers::GraphicBufferLocked* aBuffer);
|
|
|
|
void OnRecorderEvent(int msg, int ext1, int ext2);
|
|
|
|
void OnError(CameraControlListener::CameraErrorContext aWhere,
|
|
|
|
CameraControlListener::CameraError aError);
|
|
|
|
|
|
|
|
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 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult PushParameters();
|
|
|
|
nsresult PullParameters();
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~nsGonkCameraControl();
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
using CameraControlImpl::OnNewPreviewFrame;
|
|
|
|
using CameraControlImpl::OnAutoFocusComplete;
|
|
|
|
using CameraControlImpl::OnTakePictureComplete;
|
|
|
|
using CameraControlImpl::OnConfigurationChange;
|
|
|
|
using CameraControlImpl::OnError;
|
|
|
|
|
|
|
|
virtual void BeginBatchParameterSet() MOZ_OVERRIDE;
|
|
|
|
virtual void EndBatchParameterSet() MOZ_OVERRIDE;
|
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopImpl() MOZ_OVERRIDE;
|
|
|
|
nsresult Initialize();
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE;
|
|
|
|
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);
|
|
|
|
|
|
|
|
virtual nsresult StartPreviewImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopPreviewImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult AutoFocusImpl(bool aCancelExistingCall) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult TakePictureImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult StopRecordingImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult PushParametersImpl() MOZ_OVERRIDE;
|
|
|
|
virtual nsresult PullParametersImpl() MOZ_OVERRIDE;
|
|
|
|
virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() MOZ_OVERRIDE;
|
2012-10-23 15:30:28 -07:00
|
|
|
already_AddRefed<GonkRecorderProfileManager> GetGonkRecorderProfileManager();
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2012-12-23 07:56:59 -08:00
|
|
|
nsresult SetupRecording(int aFd, int aRotation, int64_t aMaxFileSizeBytes, int64_t aMaxVideoLengthMs);
|
|
|
|
nsresult SetupVideoMode(const nsAString& aProfile);
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult SetPreviewSize(const Size& aSize);
|
2014-02-19 20:18:55 -08:00
|
|
|
nsresult PausePreview();
|
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-01-23 16:10:23 -08:00
|
|
|
int32_t RationalizeRotation(int32_t aRotation);
|
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
android::sp<android::GonkCameraHardware> mCameraHw;
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
Size mLastPictureSize;
|
|
|
|
Size mLastThumbnailSize;
|
|
|
|
Size mLastRecorderSize;
|
|
|
|
uint32_t mPreviewFps;
|
|
|
|
bool mResumePreviewAfterTakingPicture;
|
|
|
|
|
|
|
|
Atomic<uint32_t> mDeferConfigUpdate;
|
|
|
|
GonkCameraParameters mParams;
|
|
|
|
|
|
|
|
nsRefPtr<mozilla::layers::ImageContainer> mImageContainer;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
android::MediaProfiles* mMediaProfiles;
|
2013-01-08 01:11:32 -08:00
|
|
|
nsRefPtr<android::GonkRecorder> mRecorder;
|
2012-09-28 22:30:52 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Camcorder profile settings for the desired quality level
|
2012-10-23 15:30:28 -07:00
|
|
|
nsRefPtr<GonkRecorderProfileManager> mProfileManager;
|
|
|
|
nsRefPtr<GonkRecorderProfile> mRecorderProfile;
|
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:
|
|
|
|
nsGonkCameraControl(const nsGonkCameraControl&) MOZ_DELETE;
|
|
|
|
nsGonkCameraControl& operator=(const nsGonkCameraControl&) MOZ_DELETE;
|
|
|
|
};
|
|
|
|
|
|
|
|
// camera driver callbacks
|
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);
|
|
|
|
void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::GraphicBufferLocked* aBuffer);
|
2012-09-30 17:37:47 -07:00
|
|
|
void OnShutter(nsGonkCameraControl* gc);
|
|
|
|
void OnClosed(nsGonkCameraControl* gc);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnError(nsGonkCameraControl* gc, CameraControlListener::CameraError aError,
|
|
|
|
int32_t aArg1, int32_t aArg2);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_GONKCAMERACONTROL_H
|