dom/camera/GonkCameraSource.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/camera/GonkCameraSource.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,164 @@
     1.4 +/*
     1.5 + * Copyright (C) 2009 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef GONK_CAMERA_SOURCE_H_
    1.21 +
    1.22 +#define GONK_CAMERA_SOURCE_H_
    1.23 +
    1.24 +#include <media/stagefright/MediaBuffer.h>
    1.25 +#include <media/stagefright/MediaSource.h>
    1.26 +#include <camera/CameraParameters.h>
    1.27 +#include <utils/List.h>
    1.28 +#include <utils/RefBase.h>
    1.29 +#include <utils/String16.h>
    1.30 +
    1.31 +#include "GonkCameraHwMgr.h"
    1.32 +
    1.33 +namespace android {
    1.34 +
    1.35 +class IMemory;
    1.36 +
    1.37 +class GonkCameraSource : public MediaSource, public MediaBufferObserver {
    1.38 +public:
    1.39 +
    1.40 +    static GonkCameraSource *Create(const sp<GonkCameraHardware>& aCameraHw,
    1.41 +                                    Size videoSize,
    1.42 +                                    int32_t frameRate,
    1.43 +                                    bool storeMetaDataInVideoBuffers = false);
    1.44 +
    1.45 +    virtual ~GonkCameraSource();
    1.46 +
    1.47 +    virtual status_t start(MetaData *params = NULL);
    1.48 +    virtual status_t stop() { return reset(); }
    1.49 +    virtual status_t read(
    1.50 +            MediaBuffer **buffer, const ReadOptions *options = NULL);
    1.51 +
    1.52 +    /**
    1.53 +     * Check whether a GonkCameraSource object is properly initialized.
    1.54 +     * Must call this method before stop().
    1.55 +     * @return OK if initialization has successfully completed.
    1.56 +     */
    1.57 +    virtual status_t initCheck() const;
    1.58 +
    1.59 +    /**
    1.60 +     * Returns the MetaData associated with the GonkCameraSource,
    1.61 +     * including:
    1.62 +     * kKeyColorFormat: YUV color format of the video frames
    1.63 +     * kKeyWidth, kKeyHeight: dimension (in pixels) of the video frames
    1.64 +     * kKeySampleRate: frame rate in frames per second
    1.65 +     * kKeyMIMEType: always fixed to be MEDIA_MIMETYPE_VIDEO_RAW
    1.66 +     */
    1.67 +    virtual sp<MetaData> getFormat();
    1.68 +
    1.69 +    /**
    1.70 +     * Tell whether this camera source stores meta data or real YUV
    1.71 +     * frame data in video buffers.
    1.72 +     *
    1.73 +     * @return true if meta data is stored in the video
    1.74 +     *      buffers; false if real YUV data is stored in
    1.75 +     *      the video buffers.
    1.76 +     */
    1.77 +    bool isMetaDataStoredInVideoBuffers() const;
    1.78 +
    1.79 +    virtual void signalBufferReturned(MediaBuffer* buffer);
    1.80 +
    1.81 +protected:
    1.82 +
    1.83 +    enum CameraFlags {
    1.84 +        FLAGS_SET_CAMERA = 1L << 0,
    1.85 +        FLAGS_HOT_CAMERA = 1L << 1,
    1.86 +    };
    1.87 +
    1.88 +    int32_t  mCameraFlags;
    1.89 +    Size     mVideoSize;
    1.90 +    int32_t  mNumInputBuffers;
    1.91 +    int32_t  mVideoFrameRate;
    1.92 +    int32_t  mColorFormat;
    1.93 +    status_t mInitCheck;
    1.94 +
    1.95 +    sp<MetaData> mMeta;
    1.96 +
    1.97 +    int64_t mStartTimeUs;
    1.98 +    int32_t mNumFramesReceived;
    1.99 +    int64_t mLastFrameTimestampUs;
   1.100 +    bool mStarted;
   1.101 +    int32_t mNumFramesEncoded;
   1.102 +
   1.103 +    // Time between capture of two frames.
   1.104 +    int64_t mTimeBetweenFrameCaptureUs;
   1.105 +
   1.106 +    GonkCameraSource(const sp<GonkCameraHardware>& aCameraHw,
   1.107 +                 Size videoSize, int32_t frameRate,
   1.108 +                 bool storeMetaDataInVideoBuffers = false);
   1.109 +
   1.110 +    virtual int startCameraRecording();
   1.111 +    virtual void stopCameraRecording();
   1.112 +    virtual void releaseRecordingFrame(const sp<IMemory>& frame);
   1.113 +
   1.114 +    // Returns true if need to skip the current frame.
   1.115 +    // Called from dataCallbackTimestamp.
   1.116 +    virtual bool skipCurrentFrame(int64_t timestampUs) {return false;}
   1.117 +
   1.118 +    friend class GonkCameraSourceListener;
   1.119 +    // Callback called when still camera raw data is available.
   1.120 +    virtual void dataCallback(int32_t msgType, const sp<IMemory> &data) {}
   1.121 +
   1.122 +    virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType,
   1.123 +            const sp<IMemory> &data);
   1.124 +
   1.125 +private:
   1.126 +
   1.127 +    Mutex mLock;
   1.128 +    Condition mFrameAvailableCondition;
   1.129 +    Condition mFrameCompleteCondition;
   1.130 +    List<sp<IMemory> > mFramesReceived;
   1.131 +    List<sp<IMemory> > mFramesBeingEncoded;
   1.132 +    List<int64_t> mFrameTimes;
   1.133 +
   1.134 +    int64_t mFirstFrameTimeUs;
   1.135 +    int32_t mNumFramesDropped;
   1.136 +    int32_t mNumGlitches;
   1.137 +    int64_t mGlitchDurationThresholdUs;
   1.138 +    bool mCollectStats;
   1.139 +    bool mIsMetaDataStoredInVideoBuffers;
   1.140 +    sp<GonkCameraHardware> mCameraHw;
   1.141 +
   1.142 +    void releaseQueuedFrames();
   1.143 +    void releaseOneRecordingFrame(const sp<IMemory>& frame);
   1.144 +
   1.145 +    status_t init(Size videoSize, int32_t frameRate,
   1.146 +                  bool storeMetaDataInVideoBuffers);
   1.147 +    status_t isCameraColorFormatSupported(const CameraParameters& params);
   1.148 +    status_t configureCamera(CameraParameters* params,
   1.149 +                    int32_t width, int32_t height,
   1.150 +                    int32_t frameRate);
   1.151 +
   1.152 +    status_t checkVideoSize(const CameraParameters& params,
   1.153 +                    int32_t width, int32_t height);
   1.154 +
   1.155 +    status_t checkFrameRate(const CameraParameters& params,
   1.156 +                    int32_t frameRate);
   1.157 +
   1.158 +    void releaseCamera();
   1.159 +    status_t reset();
   1.160 +
   1.161 +    GonkCameraSource(const GonkCameraSource &);
   1.162 +    GonkCameraSource &operator=(const GonkCameraSource &);
   1.163 +};
   1.164 +
   1.165 +}  // namespace android
   1.166 +
   1.167 +#endif  // GONK_CAMERA_SOURCE_H_

mercurial