Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1e03968 authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "Revert "Allows the authoring engine to skip frame.""

parents 7400be47 2144f631
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -78,31 +78,18 @@ struct MediaSource : public RefBase {
        void clearSeekTo();
        bool getSeekTo(int64_t *time_us, SeekMode *mode) const;

        // Option allows encoder to skip some frames until the specified
        // time stamp.
        // To prevent from being abused, when the skipFrame timestamp is
        // found to be more than 1 second later than the current timestamp,
        // an error will be returned from read().
        void clearSkipFrame();
        bool getSkipFrame(int64_t *timeUs) const;
        void setSkipFrame(int64_t timeUs);

        void setLateBy(int64_t lateness_us);
        int64_t getLateBy() const;

    private:
        enum Options {
            // Bit map
            kSeekTo_Option      = 1,
            kSkipFrame_Option   = 2,
        };

        uint32_t mOptions;
        int64_t mSeekTimeUs;
        SeekMode mSeekMode;
        int64_t mLatenessUs;

        int64_t mSkipFrameUntilTimeUs;
    };

    // Causes this source to suspend pulling data from its upstream source
+0 −1
Original line number Diff line number Diff line
@@ -167,7 +167,6 @@ private:
    int64_t mSeekTimeUs;
    ReadOptions::SeekMode mSeekMode;
    int64_t mTargetTimeUs;
    int64_t mSkipTimeUs;

    MediaBuffer *mLeftOverBuffer;

+1 −45
Original line number Diff line number Diff line
@@ -140,38 +140,6 @@ sp<MetaData> AudioSource::getFormat() {
    return meta;
}

/*
 * Returns -1 if frame skipping request is too long.
 * Returns  0 if there is no need to skip frames.
 * Returns  1 if we need to skip frames.
 */
static int skipFrame(int64_t timestampUs,
        const MediaSource::ReadOptions *options) {

    int64_t skipFrameUs;
    if (!options || !options->getSkipFrame(&skipFrameUs)) {
        return 0;
    }

    if (skipFrameUs <= timestampUs) {
        return 0;
    }

    // Safe guard against the abuse of the kSkipFrame_Option.
    if (skipFrameUs - timestampUs >= 1E6) {
        LOGE("Frame skipping requested is way too long: %lld us",
            skipFrameUs - timestampUs);

        return -1;
    }

    LOGV("skipFrame: %lld us > timestamp: %lld us",
        skipFrameUs, timestampUs);

    return 1;

}

void AudioSource::rampVolume(
        int32_t startFrame, int32_t rampDurationFrames,
        uint8_t *data,   size_t bytes) {
@@ -218,7 +186,7 @@ status_t AudioSource::read(
    CHECK_EQ(mGroup->acquire_buffer(&buffer), OK);

    int err = 0;
    while (mStarted) {
    if (mStarted) {

        uint32_t numFramesRecorded;
        mRecord->getPosition(&numFramesRecorded);
@@ -268,12 +236,6 @@ status_t AudioSource::read(
            if (mCollectStats) {
                mTotalLostFrames += (numLostBytes >> 1);
            }
            if ((err = skipFrame(timestampUs, options)) == -1) {
                buffer->release();
                return UNKNOWN_ERROR;
            } else if (err != 0) {
                continue;
            }
            memset(buffer->data(), 0, numLostBytes);
            buffer->set_range(0, numLostBytes);
            if (numFramesRecorded == 0) {
@@ -294,12 +256,6 @@ status_t AudioSource::read(

        int64_t recordDurationUs = (1000000LL * n >> 1) / sampleRate;
        timestampUs += recordDurationUs;
        if ((err = skipFrame(timestampUs, options)) == -1) {
            buffer->release();
            return UNKNOWN_ERROR;
        } else if (err != 0) {
            continue;
        }

        if (mPrevSampleTimeUs - mStartTimeUs < kAutoRampStartUs) {
            // Mute the initial video recording signal
+16 −39
Original line number Diff line number Diff line
@@ -665,45 +665,22 @@ status_t CameraSource::read(

    {
        Mutex::Autolock autoLock(mLock);
        while (mStarted) {
            while(mFramesReceived.empty()) {
        while (mStarted && mFramesReceived.empty()) {
            mFrameAvailableCondition.wait(mLock);
        }

        if (!mStarted) {
            return OK;
        }

        frame = *mFramesReceived.begin();
        mFramesReceived.erase(mFramesReceived.begin());

        frameTime = *mFrameTimes.begin();
        mFrameTimes.erase(mFrameTimes.begin());
            int64_t skipTimeUs;
            if (!options || !options->getSkipFrame(&skipTimeUs)) {
                skipTimeUs = frameTime;
            }
            if (skipTimeUs > frameTime) {
                LOGV("skipTimeUs: %lld us > frameTime: %lld us",
                    skipTimeUs, frameTime);
                releaseOneRecordingFrame(frame);
                ++mNumFramesDropped;
                // Safeguard against the abuse of the kSkipFrame_Option.
                if (skipTimeUs - frameTime >= 1E6) {
                    LOGE("Frame skipping requested is way too long: %lld us",
                        skipTimeUs - frameTime);
                    return UNKNOWN_ERROR;
                }
            } else {
        mFramesBeingEncoded.push_back(frame);
        *buffer = new MediaBuffer(frame->pointer(), frame->size());
        (*buffer)->setObserver(this);
        (*buffer)->add_ref();
        (*buffer)->meta_data()->setInt64(kKeyTime, frameTime);

                return OK;
            }
        }
    }
    return OK;
}
+0 −16
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ void MediaSource::ReadOptions::reset() {
    mOptions = 0;
    mSeekTimeUs = 0;
    mLatenessUs = 0;
    mSkipFrameUntilTimeUs = 0;
}

void MediaSource::ReadOptions::setSeekTo(int64_t time_us, SeekMode mode) {
@@ -54,21 +53,6 @@ bool MediaSource::ReadOptions::getSeekTo(
    return (mOptions & kSeekTo_Option) != 0;
}

void MediaSource::ReadOptions::clearSkipFrame() {
    mOptions &= ~kSkipFrame_Option;
    mSkipFrameUntilTimeUs = 0;
}

void MediaSource::ReadOptions::setSkipFrame(int64_t timeUs) {
    mOptions |= kSkipFrame_Option;
    mSkipFrameUntilTimeUs = timeUs;
}

bool MediaSource::ReadOptions::getSkipFrame(int64_t *timeUs) const {
    *timeUs = mSkipFrameUntilTimeUs;
    return (mOptions & kSkipFrame_Option) != 0;
}

void MediaSource::ReadOptions::setLateBy(int64_t lateness_us) {
    mLatenessUs = lateness_us;
}
Loading