michael@0: /* michael@0: * Copyright (C) 2009 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef GONK_CAMERA_SOURCE_H_ michael@0: michael@0: #define GONK_CAMERA_SOURCE_H_ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "GonkCameraHwMgr.h" michael@0: michael@0: namespace android { michael@0: michael@0: class IMemory; michael@0: michael@0: class GonkCameraSource : public MediaSource, public MediaBufferObserver { michael@0: public: michael@0: michael@0: static GonkCameraSource *Create(const sp& aCameraHw, michael@0: Size videoSize, michael@0: int32_t frameRate, michael@0: bool storeMetaDataInVideoBuffers = false); michael@0: michael@0: virtual ~GonkCameraSource(); michael@0: michael@0: virtual status_t start(MetaData *params = NULL); michael@0: virtual status_t stop() { return reset(); } michael@0: virtual status_t read( michael@0: MediaBuffer **buffer, const ReadOptions *options = NULL); michael@0: michael@0: /** michael@0: * Check whether a GonkCameraSource object is properly initialized. michael@0: * Must call this method before stop(). michael@0: * @return OK if initialization has successfully completed. michael@0: */ michael@0: virtual status_t initCheck() const; michael@0: michael@0: /** michael@0: * Returns the MetaData associated with the GonkCameraSource, michael@0: * including: michael@0: * kKeyColorFormat: YUV color format of the video frames michael@0: * kKeyWidth, kKeyHeight: dimension (in pixels) of the video frames michael@0: * kKeySampleRate: frame rate in frames per second michael@0: * kKeyMIMEType: always fixed to be MEDIA_MIMETYPE_VIDEO_RAW michael@0: */ michael@0: virtual sp getFormat(); michael@0: michael@0: /** michael@0: * Tell whether this camera source stores meta data or real YUV michael@0: * frame data in video buffers. michael@0: * michael@0: * @return true if meta data is stored in the video michael@0: * buffers; false if real YUV data is stored in michael@0: * the video buffers. michael@0: */ michael@0: bool isMetaDataStoredInVideoBuffers() const; michael@0: michael@0: virtual void signalBufferReturned(MediaBuffer* buffer); michael@0: michael@0: protected: michael@0: michael@0: enum CameraFlags { michael@0: FLAGS_SET_CAMERA = 1L << 0, michael@0: FLAGS_HOT_CAMERA = 1L << 1, michael@0: }; michael@0: michael@0: int32_t mCameraFlags; michael@0: Size mVideoSize; michael@0: int32_t mNumInputBuffers; michael@0: int32_t mVideoFrameRate; michael@0: int32_t mColorFormat; michael@0: status_t mInitCheck; michael@0: michael@0: sp mMeta; michael@0: michael@0: int64_t mStartTimeUs; michael@0: int32_t mNumFramesReceived; michael@0: int64_t mLastFrameTimestampUs; michael@0: bool mStarted; michael@0: int32_t mNumFramesEncoded; michael@0: michael@0: // Time between capture of two frames. michael@0: int64_t mTimeBetweenFrameCaptureUs; michael@0: michael@0: GonkCameraSource(const sp& aCameraHw, michael@0: Size videoSize, int32_t frameRate, michael@0: bool storeMetaDataInVideoBuffers = false); michael@0: michael@0: virtual int startCameraRecording(); michael@0: virtual void stopCameraRecording(); michael@0: virtual void releaseRecordingFrame(const sp& frame); michael@0: michael@0: // Returns true if need to skip the current frame. michael@0: // Called from dataCallbackTimestamp. michael@0: virtual bool skipCurrentFrame(int64_t timestampUs) {return false;} michael@0: michael@0: friend class GonkCameraSourceListener; michael@0: // Callback called when still camera raw data is available. michael@0: virtual void dataCallback(int32_t msgType, const sp &data) {} michael@0: michael@0: virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType, michael@0: const sp &data); michael@0: michael@0: private: michael@0: michael@0: Mutex mLock; michael@0: Condition mFrameAvailableCondition; michael@0: Condition mFrameCompleteCondition; michael@0: List > mFramesReceived; michael@0: List > mFramesBeingEncoded; michael@0: List mFrameTimes; michael@0: michael@0: int64_t mFirstFrameTimeUs; michael@0: int32_t mNumFramesDropped; michael@0: int32_t mNumGlitches; michael@0: int64_t mGlitchDurationThresholdUs; michael@0: bool mCollectStats; michael@0: bool mIsMetaDataStoredInVideoBuffers; michael@0: sp mCameraHw; michael@0: michael@0: void releaseQueuedFrames(); michael@0: void releaseOneRecordingFrame(const sp& frame); michael@0: michael@0: status_t init(Size videoSize, int32_t frameRate, michael@0: bool storeMetaDataInVideoBuffers); michael@0: status_t isCameraColorFormatSupported(const CameraParameters& params); michael@0: status_t configureCamera(CameraParameters* params, michael@0: int32_t width, int32_t height, michael@0: int32_t frameRate); michael@0: michael@0: status_t checkVideoSize(const CameraParameters& params, michael@0: int32_t width, int32_t height); michael@0: michael@0: status_t checkFrameRate(const CameraParameters& params, michael@0: int32_t frameRate); michael@0: michael@0: void releaseCamera(); michael@0: status_t reset(); michael@0: michael@0: GonkCameraSource(const GonkCameraSource &); michael@0: GonkCameraSource &operator=(const GonkCameraSource &); michael@0: }; michael@0: michael@0: } // namespace android michael@0: michael@0: #endif // GONK_CAMERA_SOURCE_H_