dom/camera/GonkCameraSource.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * Copyright (C) 2009 The Android Open Source Project
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #ifndef GONK_CAMERA_SOURCE_H_
michael@0 18
michael@0 19 #define GONK_CAMERA_SOURCE_H_
michael@0 20
michael@0 21 #include <media/stagefright/MediaBuffer.h>
michael@0 22 #include <media/stagefright/MediaSource.h>
michael@0 23 #include <camera/CameraParameters.h>
michael@0 24 #include <utils/List.h>
michael@0 25 #include <utils/RefBase.h>
michael@0 26 #include <utils/String16.h>
michael@0 27
michael@0 28 #include "GonkCameraHwMgr.h"
michael@0 29
michael@0 30 namespace android {
michael@0 31
michael@0 32 class IMemory;
michael@0 33
michael@0 34 class GonkCameraSource : public MediaSource, public MediaBufferObserver {
michael@0 35 public:
michael@0 36
michael@0 37 static GonkCameraSource *Create(const sp<GonkCameraHardware>& aCameraHw,
michael@0 38 Size videoSize,
michael@0 39 int32_t frameRate,
michael@0 40 bool storeMetaDataInVideoBuffers = false);
michael@0 41
michael@0 42 virtual ~GonkCameraSource();
michael@0 43
michael@0 44 virtual status_t start(MetaData *params = NULL);
michael@0 45 virtual status_t stop() { return reset(); }
michael@0 46 virtual status_t read(
michael@0 47 MediaBuffer **buffer, const ReadOptions *options = NULL);
michael@0 48
michael@0 49 /**
michael@0 50 * Check whether a GonkCameraSource object is properly initialized.
michael@0 51 * Must call this method before stop().
michael@0 52 * @return OK if initialization has successfully completed.
michael@0 53 */
michael@0 54 virtual status_t initCheck() const;
michael@0 55
michael@0 56 /**
michael@0 57 * Returns the MetaData associated with the GonkCameraSource,
michael@0 58 * including:
michael@0 59 * kKeyColorFormat: YUV color format of the video frames
michael@0 60 * kKeyWidth, kKeyHeight: dimension (in pixels) of the video frames
michael@0 61 * kKeySampleRate: frame rate in frames per second
michael@0 62 * kKeyMIMEType: always fixed to be MEDIA_MIMETYPE_VIDEO_RAW
michael@0 63 */
michael@0 64 virtual sp<MetaData> getFormat();
michael@0 65
michael@0 66 /**
michael@0 67 * Tell whether this camera source stores meta data or real YUV
michael@0 68 * frame data in video buffers.
michael@0 69 *
michael@0 70 * @return true if meta data is stored in the video
michael@0 71 * buffers; false if real YUV data is stored in
michael@0 72 * the video buffers.
michael@0 73 */
michael@0 74 bool isMetaDataStoredInVideoBuffers() const;
michael@0 75
michael@0 76 virtual void signalBufferReturned(MediaBuffer* buffer);
michael@0 77
michael@0 78 protected:
michael@0 79
michael@0 80 enum CameraFlags {
michael@0 81 FLAGS_SET_CAMERA = 1L << 0,
michael@0 82 FLAGS_HOT_CAMERA = 1L << 1,
michael@0 83 };
michael@0 84
michael@0 85 int32_t mCameraFlags;
michael@0 86 Size mVideoSize;
michael@0 87 int32_t mNumInputBuffers;
michael@0 88 int32_t mVideoFrameRate;
michael@0 89 int32_t mColorFormat;
michael@0 90 status_t mInitCheck;
michael@0 91
michael@0 92 sp<MetaData> mMeta;
michael@0 93
michael@0 94 int64_t mStartTimeUs;
michael@0 95 int32_t mNumFramesReceived;
michael@0 96 int64_t mLastFrameTimestampUs;
michael@0 97 bool mStarted;
michael@0 98 int32_t mNumFramesEncoded;
michael@0 99
michael@0 100 // Time between capture of two frames.
michael@0 101 int64_t mTimeBetweenFrameCaptureUs;
michael@0 102
michael@0 103 GonkCameraSource(const sp<GonkCameraHardware>& aCameraHw,
michael@0 104 Size videoSize, int32_t frameRate,
michael@0 105 bool storeMetaDataInVideoBuffers = false);
michael@0 106
michael@0 107 virtual int startCameraRecording();
michael@0 108 virtual void stopCameraRecording();
michael@0 109 virtual void releaseRecordingFrame(const sp<IMemory>& frame);
michael@0 110
michael@0 111 // Returns true if need to skip the current frame.
michael@0 112 // Called from dataCallbackTimestamp.
michael@0 113 virtual bool skipCurrentFrame(int64_t timestampUs) {return false;}
michael@0 114
michael@0 115 friend class GonkCameraSourceListener;
michael@0 116 // Callback called when still camera raw data is available.
michael@0 117 virtual void dataCallback(int32_t msgType, const sp<IMemory> &data) {}
michael@0 118
michael@0 119 virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType,
michael@0 120 const sp<IMemory> &data);
michael@0 121
michael@0 122 private:
michael@0 123
michael@0 124 Mutex mLock;
michael@0 125 Condition mFrameAvailableCondition;
michael@0 126 Condition mFrameCompleteCondition;
michael@0 127 List<sp<IMemory> > mFramesReceived;
michael@0 128 List<sp<IMemory> > mFramesBeingEncoded;
michael@0 129 List<int64_t> mFrameTimes;
michael@0 130
michael@0 131 int64_t mFirstFrameTimeUs;
michael@0 132 int32_t mNumFramesDropped;
michael@0 133 int32_t mNumGlitches;
michael@0 134 int64_t mGlitchDurationThresholdUs;
michael@0 135 bool mCollectStats;
michael@0 136 bool mIsMetaDataStoredInVideoBuffers;
michael@0 137 sp<GonkCameraHardware> mCameraHw;
michael@0 138
michael@0 139 void releaseQueuedFrames();
michael@0 140 void releaseOneRecordingFrame(const sp<IMemory>& frame);
michael@0 141
michael@0 142 status_t init(Size videoSize, int32_t frameRate,
michael@0 143 bool storeMetaDataInVideoBuffers);
michael@0 144 status_t isCameraColorFormatSupported(const CameraParameters& params);
michael@0 145 status_t configureCamera(CameraParameters* params,
michael@0 146 int32_t width, int32_t height,
michael@0 147 int32_t frameRate);
michael@0 148
michael@0 149 status_t checkVideoSize(const CameraParameters& params,
michael@0 150 int32_t width, int32_t height);
michael@0 151
michael@0 152 status_t checkFrameRate(const CameraParameters& params,
michael@0 153 int32_t frameRate);
michael@0 154
michael@0 155 void releaseCamera();
michael@0 156 status_t reset();
michael@0 157
michael@0 158 GonkCameraSource(const GonkCameraSource &);
michael@0 159 GonkCameraSource &operator=(const GonkCameraSource &);
michael@0 160 };
michael@0 161
michael@0 162 } // namespace android
michael@0 163
michael@0 164 #endif // GONK_CAMERA_SOURCE_H_

mercurial