|
1 /* |
|
2 * Copyright (C) 2009 The Android Open Source Project |
|
3 * |
|
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 |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
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. |
|
15 */ |
|
16 |
|
17 #ifndef GONK_CAMERA_SOURCE_H_ |
|
18 |
|
19 #define GONK_CAMERA_SOURCE_H_ |
|
20 |
|
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> |
|
27 |
|
28 #include "GonkCameraHwMgr.h" |
|
29 |
|
30 namespace android { |
|
31 |
|
32 class IMemory; |
|
33 |
|
34 class GonkCameraSource : public MediaSource, public MediaBufferObserver { |
|
35 public: |
|
36 |
|
37 static GonkCameraSource *Create(const sp<GonkCameraHardware>& aCameraHw, |
|
38 Size videoSize, |
|
39 int32_t frameRate, |
|
40 bool storeMetaDataInVideoBuffers = false); |
|
41 |
|
42 virtual ~GonkCameraSource(); |
|
43 |
|
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); |
|
48 |
|
49 /** |
|
50 * Check whether a GonkCameraSource object is properly initialized. |
|
51 * Must call this method before stop(). |
|
52 * @return OK if initialization has successfully completed. |
|
53 */ |
|
54 virtual status_t initCheck() const; |
|
55 |
|
56 /** |
|
57 * Returns the MetaData associated with the GonkCameraSource, |
|
58 * including: |
|
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 |
|
63 */ |
|
64 virtual sp<MetaData> getFormat(); |
|
65 |
|
66 /** |
|
67 * Tell whether this camera source stores meta data or real YUV |
|
68 * frame data in video buffers. |
|
69 * |
|
70 * @return true if meta data is stored in the video |
|
71 * buffers; false if real YUV data is stored in |
|
72 * the video buffers. |
|
73 */ |
|
74 bool isMetaDataStoredInVideoBuffers() const; |
|
75 |
|
76 virtual void signalBufferReturned(MediaBuffer* buffer); |
|
77 |
|
78 protected: |
|
79 |
|
80 enum CameraFlags { |
|
81 FLAGS_SET_CAMERA = 1L << 0, |
|
82 FLAGS_HOT_CAMERA = 1L << 1, |
|
83 }; |
|
84 |
|
85 int32_t mCameraFlags; |
|
86 Size mVideoSize; |
|
87 int32_t mNumInputBuffers; |
|
88 int32_t mVideoFrameRate; |
|
89 int32_t mColorFormat; |
|
90 status_t mInitCheck; |
|
91 |
|
92 sp<MetaData> mMeta; |
|
93 |
|
94 int64_t mStartTimeUs; |
|
95 int32_t mNumFramesReceived; |
|
96 int64_t mLastFrameTimestampUs; |
|
97 bool mStarted; |
|
98 int32_t mNumFramesEncoded; |
|
99 |
|
100 // Time between capture of two frames. |
|
101 int64_t mTimeBetweenFrameCaptureUs; |
|
102 |
|
103 GonkCameraSource(const sp<GonkCameraHardware>& aCameraHw, |
|
104 Size videoSize, int32_t frameRate, |
|
105 bool storeMetaDataInVideoBuffers = false); |
|
106 |
|
107 virtual int startCameraRecording(); |
|
108 virtual void stopCameraRecording(); |
|
109 virtual void releaseRecordingFrame(const sp<IMemory>& frame); |
|
110 |
|
111 // Returns true if need to skip the current frame. |
|
112 // Called from dataCallbackTimestamp. |
|
113 virtual bool skipCurrentFrame(int64_t timestampUs) {return false;} |
|
114 |
|
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) {} |
|
118 |
|
119 virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType, |
|
120 const sp<IMemory> &data); |
|
121 |
|
122 private: |
|
123 |
|
124 Mutex mLock; |
|
125 Condition mFrameAvailableCondition; |
|
126 Condition mFrameCompleteCondition; |
|
127 List<sp<IMemory> > mFramesReceived; |
|
128 List<sp<IMemory> > mFramesBeingEncoded; |
|
129 List<int64_t> mFrameTimes; |
|
130 |
|
131 int64_t mFirstFrameTimeUs; |
|
132 int32_t mNumFramesDropped; |
|
133 int32_t mNumGlitches; |
|
134 int64_t mGlitchDurationThresholdUs; |
|
135 bool mCollectStats; |
|
136 bool mIsMetaDataStoredInVideoBuffers; |
|
137 sp<GonkCameraHardware> mCameraHw; |
|
138 |
|
139 void releaseQueuedFrames(); |
|
140 void releaseOneRecordingFrame(const sp<IMemory>& frame); |
|
141 |
|
142 status_t init(Size videoSize, int32_t frameRate, |
|
143 bool storeMetaDataInVideoBuffers); |
|
144 status_t isCameraColorFormatSupported(const CameraParameters& params); |
|
145 status_t configureCamera(CameraParameters* params, |
|
146 int32_t width, int32_t height, |
|
147 int32_t frameRate); |
|
148 |
|
149 status_t checkVideoSize(const CameraParameters& params, |
|
150 int32_t width, int32_t height); |
|
151 |
|
152 status_t checkFrameRate(const CameraParameters& params, |
|
153 int32_t frameRate); |
|
154 |
|
155 void releaseCamera(); |
|
156 status_t reset(); |
|
157 |
|
158 GonkCameraSource(const GonkCameraSource &); |
|
159 GonkCameraSource &operator=(const GonkCameraSource &); |
|
160 }; |
|
161 |
|
162 } // namespace android |
|
163 |
|
164 #endif // GONK_CAMERA_SOURCE_H_ |