am 45cb3cfa: Merge "Handle large audio lost" into gingerbread
Merge commit '45cb3cfacf3b07ae3c5f15eba9bbbcd060cee261' into gingerbread-plus-aosp * commit '45cb3cfacf3b07ae3c5f15eba9bbbcd060cee261': Handle large audio lost
This commit is contained in:
@@ -60,7 +60,8 @@ private:
|
|||||||
int64_t mStartTimeUs;
|
int64_t mStartTimeUs;
|
||||||
int16_t mMaxAmplitude;
|
int16_t mMaxAmplitude;
|
||||||
int64_t mPrevSampleTimeUs;
|
int64_t mPrevSampleTimeUs;
|
||||||
int64_t mNumLostFrames;
|
int64_t mTotalLostFrames;
|
||||||
|
int64_t mPrevLostBytes;
|
||||||
|
|
||||||
MediaBufferGroup *mGroup;
|
MediaBufferGroup *mGroup;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ AudioSource::AudioSource(
|
|||||||
: mStarted(false),
|
: mStarted(false),
|
||||||
mCollectStats(false),
|
mCollectStats(false),
|
||||||
mPrevSampleTimeUs(0),
|
mPrevSampleTimeUs(0),
|
||||||
mNumLostFrames(0),
|
mTotalLostFrames(0),
|
||||||
|
mPrevLostBytes(0),
|
||||||
mGroup(NULL) {
|
mGroup(NULL) {
|
||||||
|
|
||||||
LOGV("sampleRate: %d, channels: %d", sampleRate, channels);
|
LOGV("sampleRate: %d, channels: %d", sampleRate, channels);
|
||||||
@@ -108,7 +109,8 @@ status_t AudioSource::stop() {
|
|||||||
mStarted = false;
|
mStarted = false;
|
||||||
|
|
||||||
if (mCollectStats) {
|
if (mCollectStats) {
|
||||||
LOGI("Total lost audio frames: %lld", mNumLostFrames);
|
LOGI("Total lost audio frames: %lld",
|
||||||
|
mTotalLostFrames + (mPrevLostBytes >> 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
@@ -186,10 +188,11 @@ status_t AudioSource::read(
|
|||||||
// Insert null frames when lost frames are detected.
|
// Insert null frames when lost frames are detected.
|
||||||
int64_t timestampUs = mPrevSampleTimeUs;
|
int64_t timestampUs = mPrevSampleTimeUs;
|
||||||
uint32_t numLostBytes = mRecord->getInputFramesLost() << 1;
|
uint32_t numLostBytes = mRecord->getInputFramesLost() << 1;
|
||||||
|
numLostBytes += mPrevLostBytes;
|
||||||
#if 0
|
#if 0
|
||||||
// Simulate lost frames
|
// Simulate lost frames
|
||||||
numLostBytes = ((rand() * 1.0 / RAND_MAX)) * kMaxBufferSize;
|
numLostBytes = ((rand() * 1.0 / RAND_MAX)) * 2 * kMaxBufferSize;
|
||||||
numLostBytes &= 0xFFFFFFFE; // Alignment request
|
numLostBytes &= 0xFFFFFFFE; // Alignment requirement
|
||||||
|
|
||||||
// Reduce the chance to lose
|
// Reduce the chance to lose
|
||||||
if (rand() * 1.0 / RAND_MAX >= 0.05) {
|
if (rand() * 1.0 / RAND_MAX >= 0.05) {
|
||||||
@@ -197,13 +200,18 @@ status_t AudioSource::read(
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (numLostBytes > 0) {
|
if (numLostBytes > 0) {
|
||||||
// Not expect too many lost frames!
|
if (numLostBytes > kMaxBufferSize) {
|
||||||
CHECK(numLostBytes <= kMaxBufferSize);
|
mPrevLostBytes = numLostBytes - kMaxBufferSize;
|
||||||
|
numLostBytes = kMaxBufferSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_EQ(numLostBytes & 1, 0);
|
||||||
|
timestampUs += ((1000000LL * (numLostBytes >> 1)) +
|
||||||
|
(sampleRate >> 1)) / sampleRate;
|
||||||
|
|
||||||
timestampUs += (1000000LL * numLostBytes >> 1) / sampleRate;
|
|
||||||
CHECK(timestampUs > mPrevSampleTimeUs);
|
CHECK(timestampUs > mPrevSampleTimeUs);
|
||||||
if (mCollectStats) {
|
if (mCollectStats) {
|
||||||
mNumLostFrames += (numLostBytes >> 1);
|
mTotalLostFrames += (numLostBytes >> 1);
|
||||||
}
|
}
|
||||||
if ((err = skipFrame(timestampUs, options)) == -1) {
|
if ((err = skipFrame(timestampUs, options)) == -1) {
|
||||||
buffer->release();
|
buffer->release();
|
||||||
@@ -240,7 +248,7 @@ status_t AudioSource::read(
|
|||||||
|
|
||||||
buffer->meta_data()->setInt64(kKeyTime, mPrevSampleTimeUs);
|
buffer->meta_data()->setInt64(kKeyTime, mPrevSampleTimeUs);
|
||||||
CHECK(timestampUs > mPrevSampleTimeUs);
|
CHECK(timestampUs > mPrevSampleTimeUs);
|
||||||
if (mNumLostFrames == 0) {
|
if (mTotalLostFrames == 0) {
|
||||||
CHECK_EQ(mPrevSampleTimeUs,
|
CHECK_EQ(mPrevSampleTimeUs,
|
||||||
mStartTimeUs + (1000000LL * numFramesRecorded) / sampleRate);
|
mStartTimeUs + (1000000LL * numFramesRecorded) / sampleRate);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user