aac: 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: 122218114
Test: bug repro steps
Change-Id: I50f68765355b1fd3af4241adad0c6199fd7b4de8
(cherry picked from commit e09b69b1c49c2f4e4db6e03f71e99c4153c28456)
diff --git a/media/codecs/aac/C2SoftAacEnc.cpp b/media/codecs/aac/C2SoftAacEnc.cpp
index 112578a..3380686 100644
--- a/media/codecs/aac/C2SoftAacEnc.cpp
+++ b/media/codecs/aac/C2SoftAacEnc.cpp
@@ -151,6 +151,7 @@
mNumBytesPerInputFrame(0u),
mOutBufferSize(0u),
mSentCodecSpecificData(false),
+ mInputTimeSet(false),
mInputSize(0),
mInputTimeUs(-1ll),
mSignalledError(false) {
@@ -175,6 +176,7 @@
c2_status_t C2SoftAacEnc::onStop() {
mSentCodecSpecificData = false;
+ mInputTimeSet = false;
mInputSize = 0u;
mInputTimeUs = -1ll;
mSignalledError = false;
@@ -192,6 +194,7 @@
c2_status_t C2SoftAacEnc::onFlush_sm() {
mSentCodecSpecificData = false;
+ mInputTimeSet = false;
mInputSize = 0u;
return C2_OK;
}
@@ -329,7 +332,6 @@
mOutBufferSize = encInfo.maxOutBufBytes;
mNumBytesPerInputFrame = encInfo.frameLength * channelCount * sizeof(int16_t);
- mInputTimeUs = work->input.ordinal.timestamp;
mSentCodecSpecificData = true;
}
@@ -343,6 +345,10 @@
data = view.data();
capacity = view.capacity();
}
+ if (!mInputTimeSet && capacity > 0) {
+ mInputTimeUs = work->input.ordinal.timestamp;
+ mInputTimeSet = true;
+ }
uint64_t timestamp = mInputTimeUs.peeku();
size_t numFrames = (capacity + mInputSize + (eos ? mNumBytesPerInputFrame - 1 : 0))
@@ -492,6 +498,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/codecs/aac/C2SoftAacEnc.h b/media/codecs/aac/C2SoftAacEnc.h
index 1e54638..e6e7cf0 100644
--- a/media/codecs/aac/C2SoftAacEnc.h
+++ b/media/codecs/aac/C2SoftAacEnc.h
@@ -55,6 +55,7 @@
UINT mOutBufferSize;
bool mSentCodecSpecificData;
+ bool mInputTimeSet;
size_t mInputSize;
c2_cntr64_t mInputTimeUs;