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

Commit d44ade92 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "Fix timestretch AV sync" into nyc-mr1-dev

parents 6da0f8d1 3da7f05a
Loading
Loading
Loading
Loading
+10 −10
Original line number Original line Diff line number Diff line
@@ -474,18 +474,18 @@ void TimestretchBufferProvider::processFrames(void *dstBuffer, size_t *dstFrames
    ALOGV("processFrames(%zu %zu)  remaining(%zu)", *dstFrames, *srcFrames, mRemaining);
    ALOGV("processFrames(%zu %zu)  remaining(%zu)", *dstFrames, *srcFrames, mRemaining);
    // Note dstFrames is the required number of frames.
    // Note dstFrames is the required number of frames.


    if (!mAudioPlaybackRateValid) {
        //fallback mode
        // Ensure consumption from src is as expected.
        // Ensure consumption from src is as expected.
        // TODO: add logic to track "very accurate" consumption related to speed, original sampling
        // TODO: add logic to track "very accurate" consumption related to speed, original sampling
        // rate, actual frames processed.
        // rate, actual frames processed.

        const size_t targetSrc = *dstFrames * mPlaybackRate.mSpeed;
        const size_t targetSrc = *dstFrames * mPlaybackRate.mSpeed;
        if (*srcFrames < targetSrc) { // limit dst frames to that possible
        if (*srcFrames < targetSrc) { // limit dst frames to that possible
            *dstFrames = *srcFrames / mPlaybackRate.mSpeed;
            *dstFrames = *srcFrames / mPlaybackRate.mSpeed;
        } else if (*srcFrames > targetSrc + 1) {
        } else if (*srcFrames > targetSrc + 1) {
            *srcFrames = targetSrc + 1;
            *srcFrames = targetSrc + 1;
        }
        }

    if (!mAudioPlaybackRateValid) {
        //fallback mode
        if (*dstFrames > 0) {
        if (*dstFrames > 0) {
            switch(mPlaybackRate.mFallbackMode) {
            switch(mPlaybackRate.mFallbackMode) {
            case AUDIO_TIMESTRETCH_FALLBACK_CUT_REPEAT:
            case AUDIO_TIMESTRETCH_FALLBACK_CUT_REPEAT: