Bug 938809 - Run seek/tune calls off the main thread, r=pzhang,khuey

This commit is contained in:
Michael Wu 2014-07-14 17:56:10 -04:00
parent 68f5b67b31
commit efbe89d0cf
2 changed files with 20 additions and 5 deletions

View File

@ -135,6 +135,13 @@ public:
EnableFMRadio(info);
FMRadioService* fmRadioService = FMRadioService::Singleton();
if (!fmRadioService->mTuneThread) {
// SeekRunnable and SetFrequencyRunnable run on this thread.
// These call ioctls that can stall the main thread, so we run them here.
NS_NewNamedThread("FM Tuning", getter_AddRefs(fmRadioService->mTuneThread));
}
return NS_OK;
}
@ -214,10 +221,15 @@ public:
NS_IMETHOD Run()
{
FMRadioService* fmRadioService = FMRadioService::Singleton();
if (fmRadioService->mTuneThread) {
fmRadioService->mTuneThread->Shutdown();
fmRadioService->mTuneThread = nullptr;
}
// Fix Bug 796733. DisableFMRadio should be called before
// SetFmRadioAudioEnabled to prevent the annoying beep sound.
DisableFMRadio();
IFMRadioService::Singleton()->EnableAudio(false);
fmRadioService->EnableAudio(false);
return NS_OK;
}
@ -298,7 +310,7 @@ FMRadioService::RemoveObserver(FMRadioEventObserver* aObserver)
{
// Turning off the FM radio HW because observer list is empty.
if (IsFMRadioOn()) {
NS_DispatchToMainThread(new DisableRunnable());
DoDisable();
}
}
}
@ -595,7 +607,8 @@ FMRadioService::SetFrequency(double aFrequencyInMHz,
return;
}
NS_DispatchToMainThread(new SetFrequencyRunnable(roundedFrequency));
mTuneThread->Dispatch(new SetFrequencyRunnable(roundedFrequency),
nsIThread::DISPATCH_NORMAL);
aReplyRunnable->SetReply(SuccessResponse());
NS_DispatchToMainThread(aReplyRunnable);
@ -636,7 +649,7 @@ FMRadioService::Seek(FMRadioSeekDirection aDirection,
SetState(Seeking);
mPendingRequest = aReplyRunnable;
NS_DispatchToMainThread(new SeekRunnable(aDirection));
mTuneThread->Dispatch(new SeekRunnable(aDirection), nsIThread::DISPATCH_NORMAL);
}
void

View File

@ -141,7 +141,8 @@ class FMRadioService MOZ_FINAL : public IFMRadioService
, public nsIObserver
{
friend class ReadAirplaneModeSettingTask;
friend class SetFrequencyRunnable;
friend class EnableRunnable;
friend class DisableRunnable;
public:
static FMRadioService* Singleton();
@ -202,6 +203,7 @@ private:
uint32_t mChannelWidthInKHz;
uint32_t mPreemphasis;
nsCOMPtr<nsIThread> mTuneThread;
nsRefPtr<FMRadioReplyRunnable> mPendingRequest;
FMRadioEventObserverList mObserverList;