2 * Copyright (C) 2009 The Android Open Source Project
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 GONK_CAMERA_SOURCE_H_
19 #define GONK_CAMERA_SOURCE_H_
21 #include <media/stagefright/MediaBuffer.h>
22 #include <media/stagefright/MediaSource.h>
23 #include <camera/CameraParameters.h>
24 #include <utils/List.h>
25 #include <utils/RefBase.h>
26 #include <utils/String16.h>
28 #include "GonkCameraHwMgr.h"
34 class GonkCameraSource
: public MediaSource
, public MediaBufferObserver
{
37 static GonkCameraSource
*Create(const sp
<GonkCameraHardware
>& aCameraHw
,
40 bool storeMetaDataInVideoBuffers
= false);
42 virtual ~GonkCameraSource();
44 virtual status_t
start(MetaData
*params
= NULL
);
45 virtual status_t
stop() { return reset(); }
46 virtual status_t
read(
47 MediaBuffer
**buffer
, const ReadOptions
*options
= NULL
);
50 * Check whether a GonkCameraSource object is properly initialized.
51 * Must call this method before stop().
52 * @return OK if initialization has successfully completed.
54 virtual status_t
initCheck() const;
57 * Returns the MetaData associated with the GonkCameraSource,
59 * kKeyColorFormat: YUV color format of the video frames
60 * kKeyWidth, kKeyHeight: dimension (in pixels) of the video frames
61 * kKeySampleRate: frame rate in frames per second
62 * kKeyMIMEType: always fixed to be MEDIA_MIMETYPE_VIDEO_RAW
64 virtual sp
<MetaData
> getFormat();
67 * Tell whether this camera source stores meta data or real YUV
68 * frame data in video buffers.
70 * @return true if meta data is stored in the video
71 * buffers; false if real YUV data is stored in
74 bool isMetaDataStoredInVideoBuffers() const;
76 virtual void signalBufferReturned(MediaBuffer
* buffer
);
81 FLAGS_SET_CAMERA
= 1L << 0,
82 FLAGS_HOT_CAMERA
= 1L << 1,
87 int32_t mNumInputBuffers
;
88 int32_t mVideoFrameRate
;
95 int32_t mNumFramesReceived
;
96 int64_t mLastFrameTimestampUs
;
98 int32_t mNumFramesEncoded
;
100 // Time between capture of two frames.
101 int64_t mTimeBetweenFrameCaptureUs
;
103 GonkCameraSource(const sp
<GonkCameraHardware
>& aCameraHw
,
104 Size videoSize
, int32_t frameRate
,
105 bool storeMetaDataInVideoBuffers
= false);
107 virtual int startCameraRecording();
108 virtual void stopCameraRecording();
109 virtual void releaseRecordingFrame(const sp
<IMemory
>& frame
);
111 // Returns true if need to skip the current frame.
112 // Called from dataCallbackTimestamp.
113 virtual bool skipCurrentFrame(int64_t timestampUs
) {return false;}
115 friend class GonkCameraSourceListener
;
116 // Callback called when still camera raw data is available.
117 virtual void dataCallback(int32_t msgType
, const sp
<IMemory
> &data
) {}
119 virtual void dataCallbackTimestamp(int64_t timestampUs
, int32_t msgType
,
120 const sp
<IMemory
> &data
);
125 Condition mFrameAvailableCondition
;
126 Condition mFrameCompleteCondition
;
127 List
<sp
<IMemory
> > mFramesReceived
;
128 List
<sp
<IMemory
> > mFramesBeingEncoded
;
129 List
<int64_t> mFrameTimes
;
132 int64_t mFirstFrameTimeUs
;
133 int32_t mNumFramesDropped
;
134 int32_t mNumGlitches
;
135 int64_t mGlitchDurationThresholdUs
;
137 bool mIsMetaDataStoredInVideoBuffers
;
138 sp
<GonkCameraHardware
> mCameraHw
;
140 void releaseQueuedFrames();
141 void releaseOneRecordingFrame(const sp
<IMemory
>& frame
);
143 status_t
init(Size videoSize
, int32_t frameRate
,
144 bool storeMetaDataInVideoBuffers
);
145 status_t
isCameraColorFormatSupported(const CameraParameters
& params
);
146 status_t
configureCamera(CameraParameters
* params
,
147 int32_t width
, int32_t height
,
150 status_t
checkVideoSize(const CameraParameters
& params
,
151 int32_t width
, int32_t height
);
153 status_t
checkFrameRate(const CameraParameters
& params
,
156 void releaseCamera();
159 GonkCameraSource(const GonkCameraSource
&);
160 GonkCameraSource
&operator=(const GonkCameraSource
&);
163 } // namespace android
165 #endif // GONK_CAMERA_SOURCE_H_