diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/camera/camera2/ICameraDeviceUser.h | 6 | ||||
| -rw-r--r-- | include/media/stagefright/MediaSync.h | 17 | ||||
| -rw-r--r-- | include/media/stagefright/VideoFrameScheduler.h | 103 | 
3 files changed, 121 insertions, 5 deletions
diff --git a/include/camera/camera2/ICameraDeviceUser.h b/include/camera/camera2/ICameraDeviceUser.h index b3dd140..a7bf8ab 100644 --- a/include/camera/camera2/ICameraDeviceUser.h +++ b/include/camera/camera2/ICameraDeviceUser.h @@ -138,6 +138,12 @@ public:       * Preallocate buffers for a given output stream asynchronously.       */      virtual status_t        prepare(int streamId) = 0; + +    /** +     * Free all unused buffers for a given output stream. +     */ +    virtual status_t        tearDown(int streamId) = 0; +  };  // ---------------------------------------------------------------------------- diff --git a/include/media/stagefright/MediaSync.h b/include/media/stagefright/MediaSync.h index 1eef211..4b5cd05 100644 --- a/include/media/stagefright/MediaSync.h +++ b/include/media/stagefright/MediaSync.h @@ -37,6 +37,7 @@ class GraphicBuffer;  class IGraphicBufferConsumer;  class IGraphicBufferProducer;  struct MediaClock; +struct VideoFrameScheduler;  // MediaSync manages media playback and its synchronization to a media clock  // source. It can be also used for video-only playback. @@ -103,6 +104,9 @@ public:      // MediaClock::getMediaTime() and MediaClock::getRealTimeFor().      sp<const MediaClock> getMediaClock(); +    // Flush mediasync +    void flush(); +      // Set the video frame rate hint - this is used by the video FrameScheduler      status_t setVideoFrameRateHint(float rate); @@ -131,11 +135,10 @@ protected:  private:      enum { -        kWhatDrainVideo = 'dVid', +        kWhatDrainVideo          = 'dVid', +        kWhatCheckFrameAvailable = 'cFrA',      }; -    static const int MAX_OUTSTANDING_BUFFERS = 2; -      // This is a thin wrapper class that lets us listen to      // IConsumerListener::onFrameAvailable from mInput.      class InputListener : public BnConsumerListener, @@ -194,6 +197,8 @@ private:      sp<IGraphicBufferConsumer> mInput;      sp<IGraphicBufferProducer> mOutput;      int mUsageFlagsFromOutput; +    uint32_t mMaxAcquiredBufferCount; // max acquired buffer count +    bool mReturnPendingInputFrame;    // set while we are pending before acquiring an input frame      sp<AudioTrack> mAudioTrack;      uint32_t mNativeSampleRateInHz; @@ -202,6 +207,7 @@ private:      int64_t mNextBufferItemMediaUs;      List<BufferItem> mBufferItems; +    sp<VideoFrameScheduler> mFrameScheduler;      // Keep track of buffers received from |mInput|. This is needed because      // it's possible the consumer of |mOutput| could return a different @@ -242,8 +248,9 @@ private:      // onBufferReleasedByOutput releases a buffer back to the input.      void onFrameAvailableFromInput(); -    // Send |bufferItem| to the output for rendering. -    void renderOneBufferItem_l(const BufferItem &bufferItem); +    // Send |bufferItem| to the output for rendering. If this is not the only +    // buffer sent for rendering, check for any dropped frames in |checkInUs| us. +    void renderOneBufferItem_l(const BufferItem &bufferItem, int64_t checkInUs);      // This implements the onBufferReleased callback from IProducerListener.      // It gets called from an OutputListener. diff --git a/include/media/stagefright/VideoFrameScheduler.h b/include/media/stagefright/VideoFrameScheduler.h new file mode 100644 index 0000000..9d97dfd --- /dev/null +++ b/include/media/stagefright/VideoFrameScheduler.h @@ -0,0 +1,103 @@ +/* + * Copyright 2014, 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 VIDEO_FRAME_SCHEDULER_H_ +#define VIDEO_FRAME_SCHEDULER_H_ + +#include <utils/RefBase.h> +#include <utils/Timers.h> + +#include <media/stagefright/foundation/ABase.h> + +namespace android { + +class ISurfaceComposer; + +struct VideoFrameScheduler : public RefBase { +    VideoFrameScheduler(); + +    // (re)initialize scheduler +    void init(float videoFps = -1); +    // use in case of video render-time discontinuity, e.g. seek +    void restart(); +    // get adjusted nanotime for a video frame render at renderTime +    nsecs_t schedule(nsecs_t renderTime); + +    // returns the vsync period for the main display +    nsecs_t getVsyncPeriod(); + +    // returns the current frames-per-second, or 0.f if not primed +    float getFrameRate(); + +    void release(); + +    static const size_t kHistorySize = 8; + +protected: +    virtual ~VideoFrameScheduler(); + +private: +    struct PLL { +        PLL(); + +        // reset PLL to new PLL +        void reset(float fps = -1); +        // keep current estimate, but restart phase +        void restart(); +        // returns period or 0 if not yet primed +        nsecs_t addSample(nsecs_t time); +        nsecs_t getPeriod() const; + +    private: +        nsecs_t mPeriod; +        nsecs_t mPhase; + +        bool    mPrimed;        // have an estimate for the period +        size_t  mSamplesUsedForPriming; + +        nsecs_t mLastTime;      // last input time +        nsecs_t mRefitAt;       // next input time to fit at + +        size_t  mNumSamples;    // can go past kHistorySize +        nsecs_t mTimes[kHistorySize]; + +        void test(); +        // returns whether fit was successful +        bool fit(nsecs_t phase, nsecs_t period, size_t numSamples, +                int64_t *a, int64_t *b, int64_t *err); +        void prime(size_t numSamples); +    }; + +    void updateVsync(); + +    nsecs_t mVsyncTime;        // vsync timing from display +    nsecs_t mVsyncPeriod; +    nsecs_t mVsyncRefreshAt;   // next time to refresh timing info + +    nsecs_t mLastVsyncTime;    // estimated vsync time for last frame +    nsecs_t mTimeCorrection;   // running adjustment + +    PLL mPll;                  // PLL for video frame rate based on render time + +    sp<ISurfaceComposer> mComposer; + +    DISALLOW_EVIL_CONSTRUCTORS(VideoFrameScheduler); +}; + +}  // namespace android + +#endif  // VIDEO_FRAME_SCHEDULER_H_ +  | 
