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

Commit 93cf3dfb authored by Iris Chang's avatar Iris Chang Committed by Marco Nelissen
Browse files

Handle mp4 file with abnormal pcm audio playback stuck

When we play the mp4 file whose pcm audio's sample size of stsz box
is not correct, it will stuck. The root cause is it may take wrong
buffer to pcm decoder, and AudioTrack might not be able to play the
decoded pcm data and cannot get right timestamp, so video will stuck
by audio.

Bug: 132042434
Test: test with the mp4 file whose pcm audio sampleSize is abnormal
and check if the video can be played normally.
Change-Id: I06c69e43922512f43d996fafcbe8b9c23ce3e7dd
parent efb76892
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -1972,6 +1972,8 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) {
                return err;
                return err;
            }
            }


            adjustRawDefaultFrameSize();

            size_t max_size;
            size_t max_size;
            err = mLastTrack->sampleTable->getMaxSampleSize(&max_size);
            err = mLastTrack->sampleTable->getMaxSampleSize(&max_size);


@@ -4606,6 +4608,20 @@ status_t MPEG4Extractor::updateAudioTrackInfoFromESDS_MPEG4Audio(
    return OK;
    return OK;
}
}


void MPEG4Extractor::adjustRawDefaultFrameSize() {
    int32_t chanCount = 0;
    int32_t bitWidth = 0;
    const char *mimeStr = NULL;

    if(AMediaFormat_getString(mLastTrack->meta, AMEDIAFORMAT_KEY_MIME, &mimeStr) &&
        !strcasecmp(mimeStr, MEDIA_MIMETYPE_AUDIO_RAW) &&
        AMediaFormat_getInt32(mLastTrack->meta, AMEDIAFORMAT_KEY_CHANNEL_COUNT, &chanCount) &&
        AMediaFormat_getInt32(mLastTrack->meta, AMEDIAFORMAT_KEY_BITS_PER_SAMPLE, &bitWidth)) {
        // samplesize in stsz may not right , so updade default samplesize
        mLastTrack->sampleTable->setPredictSampleSize(chanCount * bitWidth / 8);
    }
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////


MPEG4Source::MPEG4Source(
MPEG4Source::MPEG4Source(
+1 −0
Original line number Original line Diff line number Diff line
@@ -179,6 +179,7 @@ private:
    status_t parseAC3SpecificBox(off64_t offset);
    status_t parseAC3SpecificBox(off64_t offset);
    status_t parseEAC3SpecificBox(off64_t offset);
    status_t parseEAC3SpecificBox(off64_t offset);
    status_t parseAC4SpecificBox(off64_t offset);
    status_t parseAC4SpecificBox(off64_t offset);
    void adjustRawDefaultFrameSize();


    MPEG4Extractor(const MPEG4Extractor &);
    MPEG4Extractor(const MPEG4Extractor &);
    MPEG4Extractor &operator=(const MPEG4Extractor &);
    MPEG4Extractor &operator=(const MPEG4Extractor &);
+4 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,10 @@ public:


    status_t findThumbnailSample(uint32_t *sample_index);
    status_t findThumbnailSample(uint32_t *sample_index);


    void setPredictSampleSize(uint32_t sampleSize) {
        mDefaultSampleSize = sampleSize;
    }

protected:
protected:
    ~SampleTable();
    ~SampleTable();