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

Commit d1c8d9c5 authored by Ray Essick's avatar Ray Essick
Browse files

Fix seek handling in AAC and AMR extractors

AAC and AMR encoders were treating all seek operations as SEEK_PREVIOUS_SYNC

Bug: 179062958
Test: atest ExtractorUnitTest -- --enable-module-dynamic-download=true
Change-Id: Ic0dc0824ffa9998d72c750ca0d0a24c8dcc3c8a8
parent 17fc564a
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#define LOG_TAG "AACExtractor"
#include <utils/Log.h>

#include <inttypes.h>

#include "AACExtractor.h"
#include <media/MediaExtractorPluginApi.h>
#include <media/stagefright/foundation/ABuffer.h>
@@ -277,7 +279,22 @@ media_status_t AACSource::read(
    ReadOptions::SeekMode mode;
    if (options && options->getSeekTo(&seekTimeUs, &mode)) {
        if (mFrameDurationUs > 0) {
            int64_t seekFrame = seekTimeUs / mFrameDurationUs;
            int64_t seekFrame = 0;
            switch(mode & 0x7) {
                case ReadOptions::SEEK_NEXT_SYNC:
                    // "at or after"
                    seekFrame = (seekTimeUs + mFrameDurationUs - 1) / mFrameDurationUs;
                    break;
                case ReadOptions::SEEK_CLOSEST_SYNC:
                case ReadOptions::SEEK_CLOSEST:
                    seekFrame = (seekTimeUs + mFrameDurationUs/2) / mFrameDurationUs;
                    break;
                case ReadOptions::SEEK_PREVIOUS_SYNC:
                default:
                    // 'at or before'
                    seekFrame = seekTimeUs / mFrameDurationUs;
                    break;
            }
            if (seekFrame < 0 || seekFrame >= (int64_t)mOffsetVector.size()) {
                android_errorWriteLog(0x534e4554, "70239507");
                return AMEDIA_ERROR_MALFORMED;
+18 −2
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@
#define LOG_TAG "AMRExtractor"
#include <utils/Log.h>

#include <inttypes.h>

#include "AMRExtractor.h"

#include <media/stagefright/foundation/ADebug.h>
@@ -283,8 +285,22 @@ media_status_t AMRSource::read(
    ReadOptions::SeekMode mode;
    if (mOffsetTableLength > 0 && options && options->getSeekTo(&seekTimeUs, &mode)) {
        size_t size;
        int64_t seekFrame = seekTimeUs / 20000LL;  // 20ms per frame.
        mCurrentTimeUs = seekFrame * 20000LL;
        const int64_t frameDurationUs = 20000LL;  // 20ms per frame.
        int64_t seekFrame = 0;
        switch(mode & 0x7) {
            case ReadOptions::SEEK_NEXT_SYNC:
                seekFrame = (seekTimeUs + frameDurationUs - 1) / frameDurationUs;
                break;
            case ReadOptions::SEEK_CLOSEST_SYNC:
            case ReadOptions::SEEK_CLOSEST:
                seekFrame = (seekTimeUs + frameDurationUs/2) / frameDurationUs;
                break;
            case ReadOptions::SEEK_PREVIOUS_SYNC:
            default:
                seekFrame = seekTimeUs / frameDurationUs;
                break;
        }
        mCurrentTimeUs = seekFrame * frameDurationUs;

        size_t index = seekFrame < 0 ? 0 : seekFrame / 50;
        if (index >= mOffsetTableLength) {