void MediaEngineWebRTC::EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >* aASources) { ScopedCustomReleasePtr<webrtc::VoEBase> ptrVoEBase; ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw; // We spawn threads to handle gUM runnables, so we must protect the member vars MutexAutoLock lock(mMutex); #ifdef MOZ_WIDGET_ANDROID jobject context = mozilla::AndroidBridge::Bridge()->GetGlobalContextRef(); // get the JVM JavaVM *jvm = mozilla::AndroidBridge::Bridge()->GetVM(); JNIEnv *env = GetJNIForThread(); if (webrtc::VoiceEngine::SetAndroidObjects(jvm, env, (void*)context) != 0) { LOG(("VoiceEngine:SetAndroidObjects Failed")); return; } #endif if (!mVoiceEngine) { mVoiceEngine = webrtc::VoiceEngine::Create(); if (!mVoiceEngine) { return; } } PRLogModuleInfo *logs = GetWebRTCLogInfo(); if (!gWebrtcTraceLoggingOn && logs && logs->level > 0) { // no need to a critical section or lock here gWebrtcTraceLoggingOn = 1; const char *file = PR_GetEnv("WEBRTC_TRACE_FILE"); if (!file) { file = "WebRTC.log"; } LOG(("Logging webrtc to %s level %d", __FUNCTION__, file, logs->level)); mVoiceEngine->SetTraceFilter(logs->level); mVoiceEngine->SetTraceFile(file); } ptrVoEBase = webrtc::VoEBase::GetInterface(mVoiceEngine); if (!ptrVoEBase) { return; } if (!mAudioEngineInit) { if (ptrVoEBase->Init() < 0) { return; } mAudioEngineInit = true; } ptrVoEHw = webrtc::VoEHardware::GetInterface(mVoiceEngine); if (!ptrVoEHw) { return; } int nDevices = 0; ptrVoEHw->GetNumOfRecordingDevices(nDevices); for (int i = 0; i < nDevices; i++) { // We use constants here because GetRecordingDeviceName takes char[128]. char deviceName[128]; char uniqueId[128]; // paranoia; jingle doesn't bother with this deviceName[0] = '\0'; uniqueId[0] = '\0'; int error = ptrVoEHw->GetRecordingDeviceName(i, deviceName, uniqueId); if (error) { LOG((" VoEHardware:GetRecordingDeviceName: Failed %d", ptrVoEBase->LastError() )); continue; } if (uniqueId[0] == '\0') { // Mac and Linux don't set uniqueId! MOZ_ASSERT(sizeof(deviceName) == sizeof(uniqueId)); // total paranoia strcpy(uniqueId,deviceName); // safe given assert and initialization/error-check } nsRefPtr<MediaEngineWebRTCAudioSource> aSource; NS_ConvertUTF8toUTF16 uuid(uniqueId); if (mAudioSources.Get(uuid, getter_AddRefs(aSource))) { // We've already seen this device, just append. aASources->AppendElement(aSource.get()); } else { aSource = new MediaEngineWebRTCAudioSource( mVoiceEngine, i, deviceName, uniqueId ); mAudioSources.Put(uuid, aSource); // Hashtable takes ownership. aASources->AppendElement(aSource); } } }
void MediaEngineWebRTC::EnumerateAudioDevices(MediaSourceType aMediaSource, nsTArray<nsRefPtr<MediaEngineAudioSource> >* aASources) { ScopedCustomReleasePtr<webrtc::VoEBase> ptrVoEBase; ScopedCustomReleasePtr<webrtc::VoEHardware> ptrVoEHw; // We spawn threads to handle gUM runnables, so we must protect the member vars MutexAutoLock lock(mMutex); #ifdef MOZ_WIDGET_ANDROID jobject context = mozilla::AndroidBridge::Bridge()->GetGlobalContextRef(); // get the JVM JavaVM *jvm = mozilla::AndroidBridge::Bridge()->GetVM(); JNIEnv *env = GetJNIForThread(); if (webrtc::VoiceEngine::SetAndroidObjects(jvm, env, (void*)context) != 0) { LOG(("VoiceEngine:SetAndroidObjects Failed")); return; } #endif if (!mVoiceEngine) { mVoiceEngine = webrtc::VoiceEngine::Create(); if (!mVoiceEngine) { return; } } ptrVoEBase = webrtc::VoEBase::GetInterface(mVoiceEngine); if (!ptrVoEBase) { return; } if (!mAudioEngineInit) { if (ptrVoEBase->Init() < 0) { return; } mAudioEngineInit = true; } ptrVoEHw = webrtc::VoEHardware::GetInterface(mVoiceEngine); if (!ptrVoEHw) { return; } int nDevices = 0; ptrVoEHw->GetNumOfRecordingDevices(nDevices); int i; #if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK) i = 0; // Bug 1037025 - let the OS handle defaulting for now on android/b2g #else // -1 is "default communications device" depending on OS in webrtc.org code i = -1; #endif for (; i < nDevices; i++) { // We use constants here because GetRecordingDeviceName takes char[128]. char deviceName[128]; char uniqueId[128]; // paranoia; jingle doesn't bother with this deviceName[0] = '\0'; uniqueId[0] = '\0'; int error = ptrVoEHw->GetRecordingDeviceName(i, deviceName, uniqueId); if (error) { LOG((" VoEHardware:GetRecordingDeviceName: Failed %d", ptrVoEBase->LastError() )); continue; } if (uniqueId[0] == '\0') { // Mac and Linux don't set uniqueId! MOZ_ASSERT(sizeof(deviceName) == sizeof(uniqueId)); // total paranoia strcpy(uniqueId,deviceName); // safe given assert and initialization/error-check } nsRefPtr<MediaEngineWebRTCAudioSource> aSource; NS_ConvertUTF8toUTF16 uuid(uniqueId); if (mAudioSources.Get(uuid, getter_AddRefs(aSource))) { // We've already seen this device, just append. aASources->AppendElement(aSource.get()); } else { aSource = new MediaEngineWebRTCAudioSource( mThread, mVoiceEngine, i, deviceName, uniqueId ); mAudioSources.Put(uuid, aSource); // Hashtable takes ownership. aASources->AppendElement(aSource); } } }