Merge "Fix MediaMuxerTest#testWebmOutput failure bug" into qt-dev
diff --git a/media/libstagefright/webm/WebmFrame.cpp b/media/libstagefright/webm/WebmFrame.cpp
index 4b0d47c..52c30ec 100644
--- a/media/libstagefright/webm/WebmFrame.cpp
+++ b/media/libstagefright/webm/WebmFrame.cpp
@@ -62,6 +62,14 @@
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;
diff --git a/media/libstagefright/webm/WebmFrame.h b/media/libstagefright/webm/WebmFrame.h
index a410a87..47f2523 100644
--- a/media/libstagefright/webm/WebmFrame.h
+++ b/media/libstagefright/webm/WebmFrame.h
@@ -25,7 +25,7 @@
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 @@
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;
diff --git a/media/libstagefright/webm/WebmFrameThread.cpp b/media/libstagefright/webm/WebmFrameThread.cpp
index 4b6f928..631a2ab 100644
--- a/media/libstagefright/webm/WebmFrameThread.cpp
+++ b/media/libstagefright/webm/WebmFrameThread.cpp
@@ -78,6 +78,7 @@
mVideoFrames(videoThread->mSink),
mAudioFrames(audioThread->mSink),
mCues(cues),
+ mStartOffsetTimecode(UINT64_MAX),
mDone(true) {
}
@@ -92,6 +93,7 @@
mVideoFrames(videoSource),
mAudioFrames(audioSource),
mCues(cues),
+ mStartOffsetTimecode(UINT64_MAX),
mDone(true) {
}
@@ -213,6 +215,11 @@
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 @@
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 @@
if (mStartTimeUs == kUninitialized) {
mStartTimeUs = timestampUs;
}
- timestampUs -= mStartTimeUs;
if (mPaused && !mResumed) {
lastDurationUs = timestampUs - lastTimestampUs;
diff --git a/media/libstagefright/webm/WebmFrameThread.h b/media/libstagefright/webm/WebmFrameThread.h
index 76c91f1..1ddaf9a 100644
--- a/media/libstagefright/webm/WebmFrameThread.h
+++ b/media/libstagefright/webm/WebmFrameThread.h
@@ -83,6 +83,7 @@
LinkedBlockingQueue<const sp<WebmFrame> >& mVideoFrames;
LinkedBlockingQueue<const sp<WebmFrame> >& mAudioFrames;
List<sp<WebmElement> >& mCues;
+ uint64_t mStartOffsetTimecode;
volatile bool mDone;