Bumping manifests a=b2g-bump
[gecko.git] / dom / camera / GonkCameraSource.h
blobf7b17c2755d5e2db5cada5e14671ab3162313ec9
1 /*
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"
30 namespace android {
32 class IMemory;
34 class GonkCameraSource : public MediaSource, public MediaBufferObserver {
35 public:
37 static GonkCameraSource *Create(const sp<GonkCameraHardware>& aCameraHw,
38 Size videoSize,
39 int32_t frameRate,
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);
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.
54 virtual status_t initCheck() const;
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
64 virtual sp<MetaData> getFormat();
66 /**
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
72 * the video buffers.
74 bool isMetaDataStoredInVideoBuffers() const;
76 virtual void signalBufferReturned(MediaBuffer* buffer);
78 protected:
80 enum CameraFlags {
81 FLAGS_SET_CAMERA = 1L << 0,
82 FLAGS_HOT_CAMERA = 1L << 1,
85 int32_t mCameraFlags;
86 Size mVideoSize;
87 int32_t mNumInputBuffers;
88 int32_t mVideoFrameRate;
89 int32_t mColorFormat;
90 status_t mInitCheck;
92 sp<MetaData> mMeta;
94 int64_t mStartTimeUs;
95 int32_t mNumFramesReceived;
96 int64_t mLastFrameTimestampUs;
97 bool mStarted;
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);
122 private:
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 bool mRateLimit;
132 int64_t mFirstFrameTimeUs;
133 int32_t mNumFramesDropped;
134 int32_t mNumGlitches;
135 int64_t mGlitchDurationThresholdUs;
136 bool mCollectStats;
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,
148 int32_t frameRate);
150 status_t checkVideoSize(const CameraParameters& params,
151 int32_t width, int32_t height);
153 status_t checkFrameRate(const CameraParameters& params,
154 int32_t frameRate);
156 void releaseCamera();
157 status_t reset();
159 GonkCameraSource(const GonkCameraSource &);
160 GonkCameraSource &operator=(const GonkCameraSource &);
163 } // namespace android
165 #endif // GONK_CAMERA_SOURCE_H_