Don't post position updates too frequently
i.e. don't hog my message queue.
related-to-bug: 5284760
Change-Id: I8e2d36a11dbee1567b18ed13dc5257a65c6eeda7
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
index 8f213da..bf83849 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
@@ -26,6 +26,9 @@
namespace android {
+// static
+const int64_t NuPlayer::Renderer::kMinPositionUpdateDelayUs = 100000ll;
+
NuPlayer::Renderer::Renderer(
const sp<MediaPlayerBase::AudioSink> &sink,
const sp<AMessage> ¬ify)
@@ -43,7 +46,8 @@
mHasAudio(false),
mHasVideo(false),
mSyncQueues(false),
- mPaused(false) {
+ mPaused(false),
+ mLastPositionUpdateUs(-1ll) {
}
NuPlayer::Renderer::~Renderer() {
@@ -190,7 +194,7 @@
mDrainAudioQueuePending = true;
sp<AMessage> msg = new AMessage(kWhatDrainAudioQueue, id());
msg->setInt32("generation", mAudioQueueGeneration);
- msg->post(10000);
+ msg->post();
}
void NuPlayer::Renderer::signalAudioSinkChanged() {
@@ -198,7 +202,6 @@
}
void NuPlayer::Renderer::onDrainAudioQueue() {
-
for (;;) {
if (mAudioQueue.empty()) {
break;
@@ -562,6 +565,13 @@
}
int64_t nowUs = ALooper::GetNowUs();
+
+ if (mLastPositionUpdateUs >= 0
+ && nowUs < mLastPositionUpdateUs + kMinPositionUpdateDelayUs) {
+ return;
+ }
+ mLastPositionUpdateUs = nowUs;
+
int64_t positionUs = (nowUs - mAnchorTimeRealUs) + mAnchorTimeMediaUs;
sp<AMessage> notify = mNotify->dup();
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h
index 2713031..3a641a2 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h
@@ -74,6 +74,8 @@
status_t mFinalResult;
};
+ static const int64_t kMinPositionUpdateDelayUs;
+
sp<MediaPlayerBase::AudioSink> mAudioSink;
sp<AMessage> mNotify;
List<QueueEntry> mAudioQueue;
@@ -98,6 +100,8 @@
bool mPaused;
+ int64_t mLastPositionUpdateUs;
+
void onDrainAudioQueue();
void postDrainAudioQueue();