audio encoders: fix initial timestamp
Use timestamp from the first non-empty work, not the very first one
which may be empty with an invalid timestamp.
Bug: 123428627
Test: atest CtsMediaTestCases:MediaRecorderTest
Change-Id: I50f68765355b1fd3af4241adad0c6199fd7b4de8
diff --git a/media/codec2/components/aac/C2SoftAacEnc.cpp b/media/codec2/components/aac/C2SoftAacEnc.cpp
index 87730ae..d1bdf0d 100644
--- a/media/codec2/components/aac/C2SoftAacEnc.cpp
+++ b/media/codec2/components/aac/C2SoftAacEnc.cpp
@@ -151,6 +151,7 @@
mNumBytesPerInputFrame(0u),
mOutBufferSize(0u),
mSentCodecSpecificData(false),
+ mInputTimeSet(false),
mInputSize(0),
mInputTimeUs(-1ll),
mSignalledError(false),
@@ -176,6 +177,7 @@
c2_status_t C2SoftAacEnc::onStop() {
mSentCodecSpecificData = false;
+ mInputTimeSet = false;
mInputSize = 0u;
mInputTimeUs = -1ll;
mSignalledError = false;
@@ -193,6 +195,7 @@
c2_status_t C2SoftAacEnc::onFlush_sm() {
mSentCodecSpecificData = false;
+ mInputTimeSet = false;
mInputSize = 0u;
return C2_OK;
}
@@ -337,7 +340,6 @@
mOutBufferSize = encInfo.maxOutBufBytes;
mNumBytesPerInputFrame = encInfo.frameLength * channelCount * sizeof(int16_t);
- mInputTimeUs = work->input.ordinal.timestamp;
mSentCodecSpecificData = true;
}
@@ -351,6 +353,10 @@
data = view.data();
capacity = view.capacity();
}
+ if (!mInputTimeSet && capacity > 0) {
+ mInputTimeUs = work->input.ordinal.timestamp;
+ mInputTimeSet = true;
+ }
size_t numFrames = (capacity + mInputSize + (eos ? mNumBytesPerInputFrame - 1 : 0))
/ mNumBytesPerInputFrame;
@@ -550,6 +556,7 @@
(void)pool;
mSentCodecSpecificData = false;
+ mInputTimeSet = false;
mInputSize = 0u;
// TODO: we don't have any pending work at this time to drain.
diff --git a/media/codec2/components/aac/C2SoftAacEnc.h b/media/codec2/components/aac/C2SoftAacEnc.h
index 82fb438..779365b 100644
--- a/media/codec2/components/aac/C2SoftAacEnc.h
+++ b/media/codec2/components/aac/C2SoftAacEnc.h
@@ -57,6 +57,7 @@
UINT mOutBufferSize;
bool mSentCodecSpecificData;
+ bool mInputTimeSet;
size_t mInputSize;
c2_cntr64_t mInputTimeUs;
diff --git a/media/codec2/components/amr_nb_wb/C2SoftAmrNbEnc.cpp b/media/codec2/components/amr_nb_wb/C2SoftAmrNbEnc.cpp
index ca21480..8c03257 100644
--- a/media/codec2/components/amr_nb_wb/C2SoftAmrNbEnc.cpp
+++ b/media/codec2/components/amr_nb_wb/C2SoftAmrNbEnc.cpp
@@ -271,7 +271,7 @@
mFilledLen = 0;
}
ALOGV("causal sample size %d", mFilledLen);
- if (mIsFirst) {
+ if (mIsFirst && outPos != 0) {
mIsFirst = false;
mAnchorTimeStamp = work->input.ordinal.timestamp.peekull();
}
diff --git a/media/codec2/components/amr_nb_wb/C2SoftAmrWbEnc.cpp b/media/codec2/components/amr_nb_wb/C2SoftAmrWbEnc.cpp
index be3892f..074493c 100644
--- a/media/codec2/components/amr_nb_wb/C2SoftAmrWbEnc.cpp
+++ b/media/codec2/components/amr_nb_wb/C2SoftAmrWbEnc.cpp
@@ -347,7 +347,7 @@
mFilledLen = 0;
}
ALOGV("causal sample size %d", mFilledLen);
- if (mIsFirst) {
+ if (mIsFirst && outPos != 0) {
mIsFirst = false;
mAnchorTimeStamp = work->input.ordinal.timestamp.peekull();
}
diff --git a/media/codec2/components/opus/C2SoftOpusEnc.cpp b/media/codec2/components/opus/C2SoftOpusEnc.cpp
index d6ed5ff..68fcea1 100644
--- a/media/codec2/components/opus/C2SoftOpusEnc.cpp
+++ b/media/codec2/components/opus/C2SoftOpusEnc.cpp
@@ -350,7 +350,7 @@
return;
}
}
- if (mIsFirstFrame) {
+ if (mIsFirstFrame && inSize > 0) {
mAnchorTimeStamp = work->input.ordinal.timestamp.peekull();
mIsFirstFrame = false;
}