nsresult MediaEngineWebRTCMicrophoneSource::Allocate(const dom::MediaTrackConstraints &aConstraints, const MediaEnginePrefs &aPrefs, const nsString& aDeviceId) { AssertIsOnOwningThread(); if (mState == kReleased) { if (mInitDone) { ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw(webrtc::VoEHardware::GetInterface(mVoiceEngine)); if (!ptrVoEHw || ptrVoEHw->SetRecordingDevice(mCapIndex)) { return NS_ERROR_FAILURE; } mState = kAllocated; LOG(("Audio device %d allocated", mCapIndex)); } else { LOG(("Audio device is not initalized")); return NS_ERROR_FAILURE; } } else if (MOZ_LOG_TEST(GetMediaManagerLog(), LogLevel::Debug)) { MonitorAutoLock lock(mMonitor); if (mSources.IsEmpty()) { LOG(("Audio device %d reallocated", mCapIndex)); } else { LOG(("Audio device %d allocated shared", mCapIndex)); } } ++mNrAllocations; return NS_OK; }
nsresult MediaEngineWebRTCAudioSource::Allocate(const AudioTrackConstraintsN &aConstraints, const MediaEnginePrefs &aPrefs) { if (mState == kReleased) { if (mInitDone) { ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw(webrtc::VoEHardware::GetInterface(mVoiceEngine)); if (!ptrVoEHw || ptrVoEHw->SetRecordingDevice(mCapIndex)) { return NS_ERROR_FAILURE; } mState = kAllocated; LOG(("Audio device %d allocated", mCapIndex)); } else { LOG(("Audio device is not initalized")); return NS_ERROR_FAILURE; } } else { #ifdef PR_LOGGING MonitorAutoLock lock(mMonitor); if (mSources.IsEmpty()) { LOG(("Audio device %d reallocated", mCapIndex)); } else { LOG(("Audio device %d allocated shared", mCapIndex)); } #endif } return NS_OK; }
void MediaEngineWebRTCAudioSource::Init() { mVoEBase = webrtc::VoEBase::GetInterface(mVoiceEngine); mVoEBase->Init(); mVoERender = webrtc::VoEExternalMedia::GetInterface(mVoiceEngine); if (!mVoERender) { return; } mVoENetwork = webrtc::VoENetwork::GetInterface(mVoiceEngine); if (!mVoENetwork) { return; } mVoEProcessing = webrtc::VoEAudioProcessing::GetInterface(mVoiceEngine); if (!mVoEProcessing) { return; } mChannel = mVoEBase->CreateChannel(); if (mChannel < 0) { return; } mNullTransport = new NullTransport(); if (mVoENetwork->RegisterExternalTransport(mChannel, *mNullTransport)) { return; } // Check for availability. ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw(webrtc::VoEHardware::GetInterface(mVoiceEngine)); if (!ptrVoEHw || ptrVoEHw->SetRecordingDevice(mCapIndex)) { return; } #ifndef MOZ_B2G // Because of the permission mechanism of B2G, we need to skip the status // check here. bool avail = false; ptrVoEHw->GetRecordingDeviceStatus(avail); if (!avail) { return; } #endif // MOZ_B2G // Set "codec" to PCM, 32kHz on 1 channel ScopedCustomReleasePtr<webrtc::VoECodec> ptrVoECodec(webrtc::VoECodec::GetInterface(mVoiceEngine)); if (!ptrVoECodec) { return; } webrtc::CodecInst codec; strcpy(codec.plname, ENCODING); codec.channels = CHANNELS; codec.rate = SAMPLE_RATE; codec.plfreq = SAMPLE_FREQUENCY; codec.pacsize = SAMPLE_LENGTH; codec.pltype = 0; // Default payload type if (!ptrVoECodec->SetSendCodec(mChannel, codec)) { mInitDone = true; } }