PLDHashOperator
AudioChannelService::WindowDestroyedEnumerator(AudioChannelAgent* aAgent,
                                               nsAutoPtr<AudioChannelAgentData>& aData,
                                               void* aPtr)
{
  auto* data = static_cast<WindowDestroyedEnumeratorData*>(aPtr);
  MOZ_ASSERT(data);

  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aAgent->Window());
  if (window && !window->IsInnerWindow()) {
    window = window->GetCurrentInnerWindow();
  }

  if (!window || window->WindowID() != data->mInnerID) {
    return PL_DHASH_NEXT;
  }

  AudioChannelService* service = AudioChannelService::GetAudioChannelService();
  MOZ_ASSERT(service);

  service->UnregisterType(aData->mChannel, aData->mElementHidden,
                          CONTENT_PROCESS_ID_MAIN, aData->mWithVideo);
  data->mAgents.AppendElement(aAgent);

  return PL_DHASH_REMOVE;
}
void AudioChannelAgent::NotifyAudioChannelStateChanged()
{
    if (mCallback != nullptr) {
        AudioChannelService *service = AudioChannelService::GetAudioChannelService();
        mCallback->CanPlayChanged(!service->GetMuted(this, !mVisible));
    }
}
Esempio n. 3
0
void
AudioManager::HandleAudioChannelProcessChanged()
{
  // Note: If the user answers a VoIP call (e.g. WebRTC calls) during the
  // telephony call (GSM/CDMA calls) the audio manager won't set the
  // PHONE_STATE_IN_COMMUNICATION audio state. Once the telephony call finishes
  // the RIL plumbing sets the PHONE_STATE_NORMAL audio state. This seems to be
  // an issue for the VoIP call but it is not. Once the RIL plumbing sets the
  // the PHONE_STATE_NORMAL audio state the AudioManager::mPhoneAudioAgent
  // member will call the StopPlaying() method causing that this function will
  // be called again and therefore the audio manager sets the
  // PHONE_STATE_IN_COMMUNICATION audio state.

  if ((mPhoneState == PHONE_STATE_IN_CALL) ||
      (mPhoneState == PHONE_STATE_RINGTONE)) {
    return;
  }

  AudioChannelService *service = AudioChannelService::GetOrCreateAudioChannelService();
  MOZ_ASSERT(service);

  bool telephonyChannelIsActive = service->TelephonyChannelIsActive();
  telephonyChannelIsActive ? SetPhoneState(PHONE_STATE_IN_COMMUNICATION) :
                             SetPhoneState(PHONE_STATE_NORMAL);
}
Esempio n. 4
0
SpeakerManagerService::~SpeakerManagerService()
{
  MOZ_COUNT_DTOR(SpeakerManagerService);
  AudioChannelService* audioChannelService =
    AudioChannelService::GetOrCreateAudioChannelService();
  if (audioChannelService)
    audioChannelService->UnregisterSpeakerManager(this);
}
void AudioChannelAgent::NotifyAudioChannelStateChanged()
{
  nsCOMPtr<nsIAudioChannelAgentCallback> callback = GetCallback();
  if (callback) {
    AudioChannelService *service = AudioChannelService::GetAudioChannelService();
    callback->CanPlayChanged(service->GetState(this, !mVisible));
  }
}
SpeakerManagerServiceChild::SpeakerManagerServiceChild()
{
  MOZ_ASSERT(NS_IsMainThread());
  AudioChannelService* audioChannelService = AudioChannelService::GetOrCreateAudioChannelService();
  if (audioChannelService) {
    audioChannelService->RegisterSpeakerManager(this);
  }
  MOZ_COUNT_CTOR(SpeakerManagerServiceChild);
}
/* void setVisibilityState (in boolean visible); */
NS_IMETHODIMP AudioChannelAgent::SetVisibilityState(bool visible)
{
    bool oldVisibility = mVisible;

    mVisible = visible;
    if (mIsRegToService && oldVisibility != mVisible && mCallback != nullptr) {
        AudioChannelService *service = AudioChannelService::GetAudioChannelService();
        mCallback->CanPlayChanged(!service->GetMuted(this, !mVisible));
    }
    return NS_OK;
}
/* void stopPlaying (); */
NS_IMETHODIMP AudioChannelAgent::StopPlaying(void)
{
    if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
            mIsRegToService == false) {
        return NS_ERROR_FAILURE;
    }

    AudioChannelService *service = AudioChannelService::GetAudioChannelService();
    service->UnregisterAudioChannelAgent(this);
    mIsRegToService = false;
    return NS_OK;
}
/* void setVisibilityState (in boolean visible); */
NS_IMETHODIMP AudioChannelAgent::SetVisibilityState(bool visible)
{
  bool oldVisibility = mVisible;

  nsCOMPtr<nsIAudioChannelAgentCallback> callback = GetCallback();

  mVisible = visible;
  if (mIsRegToService && oldVisibility != mVisible && callback) {
    AudioChannelService *service = AudioChannelService::GetAudioChannelService();
    callback->CanPlayChanged(service->GetState(this, !mVisible));
  }
  return NS_OK;
}
Esempio n. 10
0
/* boolean startPlaying (); */
NS_IMETHODIMP AudioChannelAgent::StartPlaying(bool *_retval)
{
    AudioChannelService *service = AudioChannelService::GetAudioChannelService();
    if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
            service == nullptr) {
        return NS_ERROR_FAILURE;
    }

    service->RegisterAudioChannelAgent(this,
                                       static_cast<AudioChannelType>(mAudioChannelType));
    *_retval = !service->GetMuted(this, !mVisible);
    mIsRegToService = true;
    return NS_OK;
}
/* boolean startPlaying (); */
NS_IMETHODIMP AudioChannelAgent::StartPlaying(int32_t *_retval)
{
  AudioChannelService *service = AudioChannelService::GetAudioChannelService();
  if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
      service == nullptr || mIsRegToService) {
    return NS_ERROR_FAILURE;
  }

  service->RegisterAudioChannelAgent(this,
    static_cast<AudioChannel>(mAudioChannelType), mWithVideo);
  *_retval = service->GetState(this, !mVisible);
  mIsRegToService = true;
  return NS_OK;
}
Esempio n. 12
0
SpeakerManagerService::SpeakerManagerService()
  : mOrgSpeakerStatus(false),
    mVisible(false)
{
  MOZ_COUNT_CTOR(SpeakerManagerService);
  if (XRE_IsParentProcess()) {
    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
    if (obs) {
      obs->AddObserver(this, "ipc:content-shutdown", false);
    }
  }
  AudioChannelService* audioChannelService =
    AudioChannelService::GetOrCreateAudioChannelService();
  if (audioChannelService) {
    audioChannelService->RegisterSpeakerManager(this);
  }
}
PLDHashOperator
AudioChannelService::WindowDestroyedEnumerator(AudioChannelAgent* aAgent,
                                               nsAutoPtr<AudioChannelAgentData>& aData,
                                               void* aPtr)
{
  uint64_t* innerID = static_cast<uint64_t*>(aPtr);
  MOZ_ASSERT(innerID);

  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aAgent->Window());
  if (!window || window->WindowID() != *innerID) {
    return PL_DHASH_NEXT;
  }

  AudioChannelService* service = AudioChannelService::GetAudioChannelService();
  MOZ_ASSERT(service);

  service->UnregisterType(aData->mChannel, aData->mElementHidden,
                          CONTENT_PROCESS_ID_MAIN, aData->mWithVideo);

  return PL_DHASH_REMOVE;
}
Esempio n. 14
0
NS_IMETHODIMP
SpeakerManager::HandleEvent(nsIDOMEvent* aEvent)
{
  nsAutoString type;
  aEvent->GetType(type);

  if (!type.EqualsLiteral("visibilitychange")) {
    return NS_ERROR_FAILURE;
  }

  nsCOMPtr<nsIDocShell> docshell = do_GetInterface(GetOwner());
  NS_ENSURE_TRUE(docshell, NS_ERROR_FAILURE);
  docshell->GetIsActive(&mVisible);

  // If an app that has called forcespeaker=true is switched
  // from the background to the foreground 'speakerforced'
  // switches to true in all apps. I.e. the app doesn't have to
  // call forcespeaker=true again when it comes into foreground.
  SpeakerManagerService *service =
    SpeakerManagerService::GetOrCreateSpeakerManagerService();
  MOZ_ASSERT(service);

  if (mVisible && mForcespeaker) {
    service->ForceSpeaker(mForcespeaker, mVisible);
  }
  // If an application that has called forcespeaker=true, but no audio is
  // currently playing in the app itself, if application switch to
  // the background, we switch 'speakerforced' to false.
  if (!mVisible && mForcespeaker) {
    AudioChannelService* audioChannelService =
      AudioChannelService::GetOrCreateAudioChannelService();
    if (audioChannelService && !audioChannelService->AnyAudioChannelIsActive()) {
      service->ForceSpeaker(false, mVisible);
    }
  }
  return NS_OK;
}