Bug 1059700 - AudioOffloadPlayer: Use wakelock to avoid suspend between pause and reset. r=roc

This commit is contained in:
Vasanthakumar Pandurangan 2014-09-24 01:22:57 -07:00
parent b9f20bedc6
commit a77fd9691a
2 changed files with 46 additions and 0 deletions

View File

@ -22,6 +22,8 @@
#include "nsITimer.h" #include "nsITimer.h"
#include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/dom/HTMLMediaElement.h"
#include "VideoUtils.h" #include "VideoUtils.h"
#include "mozilla/dom/power/PowerManagerService.h"
#include "mozilla/dom/WakeLock.h"
#include <binder/IPCThreadState.h> #include <binder/IPCThreadState.h>
#include <stagefright/foundation/ADebug.h> #include <stagefright/foundation/ADebug.h>
@ -215,6 +217,7 @@ status_t AudioOffloadPlayer::ChangeState(MediaDecoder::PlayState aState)
static void ResetCallback(nsITimer* aTimer, void* aClosure) static void ResetCallback(nsITimer* aTimer, void* aClosure)
{ {
AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("%s", __FUNCTION__));
AudioOffloadPlayer* player = static_cast<AudioOffloadPlayer*>(aClosure); AudioOffloadPlayer* player = static_cast<AudioOffloadPlayer*>(aClosure);
if (player) { if (player) {
player->Reset(); player->Reset();
@ -227,6 +230,8 @@ void AudioOffloadPlayer::Pause(bool aPlayPendingSamples)
if (mStarted) { if (mStarted) {
CHECK(mAudioSink.get()); CHECK(mAudioSink.get());
WakeLockCreate();
if (aPlayPendingSamples) { if (aPlayPendingSamples) {
mAudioSink->Stop(); mAudioSink->Stop();
} else { } else {
@ -252,6 +257,7 @@ status_t AudioOffloadPlayer::Play()
if (mResetTimer) { if (mResetTimer) {
mResetTimer->Cancel(); mResetTimer->Cancel();
mResetTimer = nullptr; mResetTimer = nullptr;
WakeLockRelease();
} }
status_t err = OK; status_t err = OK;
@ -281,6 +287,7 @@ status_t AudioOffloadPlayer::Play()
void AudioOffloadPlayer::Reset() void AudioOffloadPlayer::Reset()
{ {
MOZ_ASSERT(NS_IsMainThread());
if (!mStarted) { if (!mStarted) {
return; return;
} }
@ -323,6 +330,8 @@ void AudioOffloadPlayer::Reset()
mStarted = false; mStarted = false;
mPlaying = false; mPlaying = false;
mStartPosUs = 0; mStartPosUs = 0;
WakeLockRelease();
} }
status_t AudioOffloadPlayer::SeekTo(int64_t aTimeUs, bool aDispatchSeekEvents) status_t AudioOffloadPlayer::SeekTo(int64_t aTimeUs, bool aDispatchSeekEvents)
@ -711,4 +720,30 @@ void AudioOffloadPlayer::SetVolume(double aVolume)
mAudioSink->SetVolume((float) aVolume); mAudioSink->SetVolume((float) aVolume);
} }
void AudioOffloadPlayer::WakeLockCreate()
{
MOZ_ASSERT(NS_IsMainThread());
AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("%s", __FUNCTION__));
if (!mWakeLock) {
nsRefPtr<dom::power::PowerManagerService> pmService =
dom::power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE_VOID(pmService);
ErrorResult rv;
mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("cpu"), nullptr, rv);
}
}
void AudioOffloadPlayer::WakeLockRelease()
{
MOZ_ASSERT(NS_IsMainThread());
AUDIO_OFFLOAD_LOG(PR_LOG_DEBUG, ("%s", __FUNCTION__));
if (mWakeLock) {
ErrorResult rv;
mWakeLock->Unlock(rv);
NS_WARN_IF_FALSE(!rv.Failed(), "Failed to unlock the wakelock.");
mWakeLock = nullptr;
}
}
} // namespace mozilla } // namespace mozilla

View File

@ -33,6 +33,10 @@
namespace mozilla { namespace mozilla {
namespace dom {
class WakeLock;
}
/** /**
* AudioOffloadPlayer adds support for audio tunneling to a digital signal * AudioOffloadPlayer adds support for audio tunneling to a digital signal
* processor (DSP) in the device chipset. With tunneling, audio decoding is * processor (DSP) in the device chipset. With tunneling, audio decoding is
@ -193,6 +197,10 @@ private:
// OFFLOAD_PAUSE_MAX_USECS. Used only from main thread so no lock is needed. // OFFLOAD_PAUSE_MAX_USECS. Used only from main thread so no lock is needed.
nsCOMPtr<nsITimer> mResetTimer; nsCOMPtr<nsITimer> mResetTimer;
// To avoid device suspend when mResetTimer is going to be triggered.
// Used only from main thread so no lock is needed.
nsRefPtr<mozilla::dom::WakeLock> mWakeLock;
int64_t GetMediaTimeUs(); int64_t GetMediaTimeUs();
// Provide the playback position in microseconds from total number of // Provide the playback position in microseconds from total number of
@ -240,6 +248,9 @@ private:
nsresult StartTimeUpdate(); nsresult StartTimeUpdate();
nsresult StopTimeUpdate(); nsresult StopTimeUpdate();
void WakeLockCreate();
void WakeLockRelease();
// Notify end of stream by sending PlaybackEnded event to observer // Notify end of stream by sending PlaybackEnded event to observer
// (i.e.MediaDecoder) // (i.e.MediaDecoder)
void NotifyAudioEOS(); void NotifyAudioEOS();