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