2 * Copyright (C) 2012 Mozilla Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef DOM_CAMERA_GONKCAMERACONTROL_H
18 #define DOM_CAMERA_GONKCAMERACONTROL_H
20 #include "base/basictypes.h"
22 #include <media/MediaProfiles.h>
23 #include "nsIDOMCameraManager.h"
24 #include "DOMCameraControl.h"
25 #include "CameraControlImpl.h"
26 #include "CameraCommon.h"
27 #include "GonkRecorder.h"
33 class GraphicBufferLocked
;
36 class GonkRecorderProfile
;
37 class GonkRecorderProfileManager
;
39 class nsGonkCameraControl
: public CameraControlImpl
42 nsGonkCameraControl(uint32_t aCameraId
, nsIThread
* aCameraThread
, nsDOMCameraControl
* aDOMCameraControl
, nsICameraGetCameraCallback
* onSuccess
, nsICameraErrorCallback
* onError
, uint64_t aWindowId
);
45 const char* GetParameter(const char* aKey
);
46 const char* GetParameterConstChar(uint32_t aKey
);
47 double GetParameterDouble(uint32_t aKey
);
48 void GetParameter(uint32_t aKey
, nsTArray
<dom::CameraRegion
>& aRegions
);
49 void GetParameter(uint32_t aKey
, nsTArray
<dom::CameraSize
>& aSizes
);
50 void SetParameter(const char* aKey
, const char* aValue
);
51 void SetParameter(uint32_t aKey
, const char* aValue
);
52 void SetParameter(uint32_t aKey
, double aValue
);
53 void SetParameter(uint32_t aKey
, const nsTArray
<dom::CameraRegion
>& aRegions
);
54 void SetParameter(uint32_t aKey
, int aValue
);
55 nsresult
GetVideoSizes(nsTArray
<dom::CameraSize
>& aVideoSizes
);
56 nsresult
PushParameters();
58 nsresult
SetupRecording(int aFd
, int aRotation
, int64_t aMaxFileSizeBytes
, int64_t aMaxVideoLengthMs
);
59 nsresult
SetupVideoMode(const nsAString
& aProfile
);
61 void AutoFocusComplete(bool aSuccess
);
62 void TakePictureComplete(uint8_t* aData
, uint32_t aLength
);
63 void HandleRecorderEvent(int msg
, int ext1
, int ext2
);
66 ~nsGonkCameraControl();
68 nsresult
GetPreviewStreamImpl(GetPreviewStreamTask
* aGetPreviewStream
);
69 nsresult
StartPreviewImpl(StartPreviewTask
* aStartPreview
);
70 nsresult
StopPreviewImpl(StopPreviewTask
* aStopPreview
);
71 nsresult
StopPreviewInternal(bool aForced
= false);
72 nsresult
AutoFocusImpl(AutoFocusTask
* aAutoFocus
);
73 nsresult
TakePictureImpl(TakePictureTask
* aTakePicture
);
74 nsresult
StartRecordingImpl(StartRecordingTask
* aStartRecording
);
75 nsresult
StopRecordingImpl(StopRecordingTask
* aStopRecording
);
76 nsresult
PushParametersImpl();
77 nsresult
PullParametersImpl();
78 nsresult
GetPreviewStreamVideoModeImpl(GetPreviewStreamVideoModeTask
* aGetPreviewStreamVideoMode
);
79 already_AddRefed
<RecorderProfileManager
> GetRecorderProfileManagerImpl();
80 already_AddRefed
<GonkRecorderProfileManager
> GetGonkRecorderProfileManager();
82 void SetPreviewSize(uint32_t aWidth
, uint32_t aHeight
);
83 void SetupThumbnail(uint32_t aPictureWidth
, uint32_t aPictureHeight
, uint32_t aPercentQuality
);
86 double mExposureCompensationMin
;
87 double mExposureCompensationStep
;
88 bool mDeferConfigUpdate
;
90 android::CameraParameters mParams
;
93 uint32_t mLastPictureWidth
;
94 uint32_t mLastPictureHeight
;
97 PREVIEW_FORMAT_UNKNOWN
,
98 PREVIEW_FORMAT_YUV420P
,
99 PREVIEW_FORMAT_YUV420SP
104 uint32_t mDiscardedFrameCount
;
106 android::MediaProfiles
* mMediaProfiles
;
107 android::GonkRecorder
* mRecorder
;
111 // camcorder profile settings for the desired quality level
112 nsRefPtr
<GonkRecorderProfileManager
> mProfileManager
;
113 nsRefPtr
<GonkRecorderProfile
> mRecorderProfile
;
116 nsGonkCameraControl(const nsGonkCameraControl
&) MOZ_DELETE
;
117 nsGonkCameraControl
& operator=(const nsGonkCameraControl
&) MOZ_DELETE
;
120 // camera driver callbacks
121 void ReceiveImage(nsGonkCameraControl
* gc
, uint8_t* aData
, uint32_t aLength
);
122 void AutoFocusComplete(nsGonkCameraControl
* gc
, bool aSuccess
);
123 void ReceiveFrame(nsGonkCameraControl
* gc
, layers::GraphicBufferLocked
* aBuffer
);
124 void OnShutter(nsGonkCameraControl
* gc
);
125 void OnClosed(nsGonkCameraControl
* gc
);
127 } // namespace mozilla
129 #endif // DOM_CAMERA_GONKCAMERACONTROL_H