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

Commit 7a2cc2b5 authored by Dichen Zhang's avatar Dichen Zhang
Browse files

Fix MediaMuxerTest#testWebmOutput failure bug

Change audio/video synchronization method for webm file. Previous method shifts
audio/video separately to 0. This change will get the smallest starting time
among all tracks and shifts them together.
i.e. audio starts at 15 and video starts at 10, old method will shift both of them
to 0 separately, which is not right. New method will shift both of them by 10 (the
smaller of them) where after shifting, audio starts at 5 and video starts at 0.

Bug: 130363039
Test: MediaMuxerTest#testWebmOutput
Change-Id: I97addc72c9e13df649ae65716dc63243dad3849d
parent a8cc6d41
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -62,6 +62,14 @@ sp<WebmElement> WebmFrame::SimpleBlock(uint64_t baseTimecode) const {
            mData);
}

uint64_t WebmFrame::getAbsTimecode() {
    return mAbsTimecode;
}

void WebmFrame::updateAbsTimecode(uint64_t newAbsTimecode) {
    mAbsTimecode = newAbsTimecode;
}

bool WebmFrame::operator<(const WebmFrame &other) const {
    if (this->mEos) {
        return false;
+3 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ struct WebmFrame : LightRefBase<WebmFrame> {
public:
    const int mType;
    const bool mKey;
    const uint64_t mAbsTimecode;
    uint64_t mAbsTimecode;
    const sp<ABuffer> mData;
    const bool mEos;

@@ -33,6 +33,8 @@ public:
    WebmFrame(int type, bool key, uint64_t absTimecode, MediaBufferBase *buf);
    ~WebmFrame() {}

    uint64_t getAbsTimecode();
    void updateAbsTimecode(uint64_t newAbsTimecode);
    sp<WebmElement> SimpleBlock(uint64_t baseTimecode) const;

    bool operator<(const WebmFrame &other) const;
+9 −1
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ WebmFrameSinkThread::WebmFrameSinkThread(
      mVideoFrames(videoThread->mSink),
      mAudioFrames(audioThread->mSink),
      mCues(cues),
      mStartOffsetTimecode(UINT64_MAX),
      mDone(true) {
}

@@ -92,6 +93,7 @@ WebmFrameSinkThread::WebmFrameSinkThread(
      mVideoFrames(videoSource),
      mAudioFrames(audioSource),
      mCues(cues),
      mStartOffsetTimecode(UINT64_MAX),
      mDone(true) {
}

@@ -213,6 +215,11 @@ void WebmFrameSinkThread::run() {
        const sp<WebmFrame> audioFrame = mAudioFrames.peek();
        ALOGV("a frame: %p", audioFrame.get());

        if (mStartOffsetTimecode == UINT64_MAX) {
            mStartOffsetTimecode =
                    std::min(audioFrame->getAbsTimecode(), videoFrame->getAbsTimecode());
        }

        if (videoFrame->mEos && audioFrame->mEos) {
            break;
        }
@@ -220,10 +227,12 @@ void WebmFrameSinkThread::run() {
        if (*audioFrame < *videoFrame) {
            ALOGV("take a frame");
            mAudioFrames.take();
            audioFrame->updateAbsTimecode(audioFrame->getAbsTimecode() - mStartOffsetTimecode);
            outstandingFrames.push_back(audioFrame);
        } else {
            ALOGV("take v frame");
            mVideoFrames.take();
            videoFrame->updateAbsTimecode(videoFrame->getAbsTimecode() - mStartOffsetTimecode);
            outstandingFrames.push_back(videoFrame);
            if (videoFrame->mKey)
                numVideoKeyFrames++;
@@ -350,7 +359,6 @@ void WebmFrameMediaSourceThread::run() {
        if (mStartTimeUs == kUninitialized) {
            mStartTimeUs = timestampUs;
        }
        timestampUs -= mStartTimeUs;

        if (mPaused && !mResumed) {
            lastDurationUs = timestampUs - lastTimestampUs;
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ private:
    LinkedBlockingQueue<const sp<WebmFrame> >& mVideoFrames;
    LinkedBlockingQueue<const sp<WebmFrame> >& mAudioFrames;
    List<sp<WebmElement> >& mCues;
    uint64_t mStartOffsetTimecode;

    volatile bool mDone;