/** * Peforms intialization of the MANDATORY components of the Video Engine */ MediaConduitErrorCode WebrtcVideoConduit::Init() { CSFLogDebug(logTag, "%s ", __FUNCTION__); #ifdef MOZ_WIDGET_ANDROID jobject context = jsjni_GetGlobalContextRef(); // get the JVM JavaVM *jvm = jsjni_GetVM(); JNIEnv* env; if (jvm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) { CSFLogError(logTag, "%s: could not get Java environment", __FUNCTION__); return kMediaConduitSessionNotInited; } jvm->AttachCurrentThread(&env, nullptr); if (webrtc::VideoEngine::SetAndroidObjects(jvm, (void*)context) != 0) { CSFLogError(logTag, "%s: could not set Android objects", __FUNCTION__); return kMediaConduitSessionNotInited; } env->DeleteGlobalRef(context); #endif if( !(mVideoEngine = webrtc::VideoEngine::Create()) ) { CSFLogError(logTag, "%s Unable to create video engine ", __FUNCTION__); return kMediaConduitSessionNotInited; } 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"; } CSFLogDebug(logTag, "%s Logging webrtc to %s level %d", __FUNCTION__, file, logs->level); mVideoEngine->SetTraceFilter(logs->level); mVideoEngine->SetTraceFile(file); } if( !(mPtrViEBase = ViEBase::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video base interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViECapture = ViECapture::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video capture interface", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViECodec = ViECodec::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video codec interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViENetwork = ViENetwork::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video network interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViERender = ViERender::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video render interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrRTP = webrtc::ViERTP_RTCP::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video RTCP interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } CSFLogDebug(logTag, "%s Engine Created: Init'ng the interfaces ",__FUNCTION__); if(mPtrViEBase->Init() == -1) { CSFLogError(logTag, " %s Video Engine Init Failed %d ",__FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitSessionNotInited; } if(mPtrViEBase->CreateChannel(mChannel) == -1) { CSFLogError(logTag, " %s Channel creation Failed %d ",__FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitChannelError; } if(mPtrViENetwork->RegisterSendTransport(mChannel, *this) == -1) { CSFLogError(logTag, "%s ViENetwork Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitTransportRegistrationFail; } mPtrExtCapture = 0; if(mPtrViECapture->AllocateExternalCaptureDevice(mCapId, mPtrExtCapture) == -1) { CSFLogError(logTag, "%s Unable to Allocate capture module: %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitCaptureError; } if(mPtrViECapture->ConnectCaptureDevice(mCapId,mChannel) == -1) { CSFLogError(logTag, "%s Unable to Connect capture module: %d ", __FUNCTION__,mPtrViEBase->LastError()); return kMediaConduitCaptureError; } if(mPtrViERender->AddRenderer(mChannel, webrtc::kVideoI420, (webrtc::ExternalRenderer*) this) == -1) { CSFLogError(logTag, "%s Failed to added external renderer ", __FUNCTION__); return kMediaConduitInvalidRenderer; } // Set up some parameters, per juberti. Set MTU. if(mPtrViENetwork->SetMTU(mChannel, 1200) != 0) { CSFLogError(logTag, "%s MTU Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitMTUError; } // Turn on RTCP and loss feedback reporting. if(mPtrRTP->SetRTCPStatus(mChannel, webrtc::kRtcpCompound_RFC4585) != 0) { CSFLogError(logTag, "%s RTCPStatus Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitRTCPStatusError; } // Enable pli as key frame request method. if(mPtrRTP->SetKeyFrameRequestMethod(mChannel, webrtc::kViEKeyFrameRequestPliRtcp) != 0) { CSFLogError(logTag, "%s KeyFrameRequest Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitKeyFrameRequestError; } // Enable lossless transport // XXX Note: We may want to disable this or limit it if (mPtrRTP->SetNACKStatus(mChannel, true) != 0) { CSFLogError(logTag, "%s NACKStatus Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitNACKStatusError; } CSFLogError(logTag, "%s Initialization Done", __FUNCTION__); return kMediaConduitNoError; }
void MediaEngineWebRTC::EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >* aVSources) { #ifdef MOZ_B2G_CAMERA MutexAutoLock lock(mMutex); /** * We still enumerate every time, in case a new device was plugged in since * the last call. TODO: Verify that WebRTC actually does deal with hotplugging * new devices (with or without new engine creation) and accordingly adjust. * Enumeration is not neccessary if GIPS reports the same set of devices * for a given instance of the engine. Likewise, if a device was plugged out, * mVideoSources must be updated. */ int num = 0; nsresult result; result = ICameraControl::GetNumberOfCameras(num); if (num <= 0 || result != NS_OK) { return; } for (int i = 0; i < num; i++) { nsCString cameraName; result = ICameraControl::GetCameraName(i, cameraName); if (result != NS_OK) { continue; } nsRefPtr<MediaEngineWebRTCVideoSource> vSource; NS_ConvertUTF8toUTF16 uuid(cameraName); if (mVideoSources.Get(uuid, getter_AddRefs(vSource))) { // We've already seen this device, just append. aVSources->AppendElement(vSource.get()); } else { vSource = new MediaEngineWebRTCVideoSource(i); mVideoSources.Put(uuid, vSource); // Hashtable takes ownership. aVSources->AppendElement(vSource); } } return; #else webrtc::ViEBase* ptrViEBase; webrtc::ViECapture* ptrViECapture; // 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(); if (webrtc::VideoEngine::SetAndroidObjects(jvm, (void*)context) != 0) { LOG(("VieCapture:SetAndroidObjects Failed")); return; } #endif if (mHasTabVideoSource) aVSources->AppendElement(new MediaEngineTabVideoSource()); if (!mVideoEngine) { if (!(mVideoEngine = webrtc::VideoEngine::Create())) { 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(("%s Logging webrtc to %s level %d", __FUNCTION__, file, logs->level)); mVideoEngine->SetTraceFilter(logs->level); mVideoEngine->SetTraceFile(file); } ptrViEBase = webrtc::ViEBase::GetInterface(mVideoEngine); if (!ptrViEBase) { return; } if (!mVideoEngineInit) { if (ptrViEBase->Init() < 0) { return; } mVideoEngineInit = true; } ptrViECapture = webrtc::ViECapture::GetInterface(mVideoEngine); if (!ptrViECapture) { return; } /** * We still enumerate every time, in case a new device was plugged in since * the last call. TODO: Verify that WebRTC actually does deal with hotplugging * new devices (with or without new engine creation) and accordingly adjust. * Enumeration is not neccessary if GIPS reports the same set of devices * for a given instance of the engine. Likewise, if a device was plugged out, * mVideoSources must be updated. */ int num = ptrViECapture->NumberOfCaptureDevices(); if (num <= 0) { return; } for (int i = 0; i < num; i++) { const unsigned int kMaxDeviceNameLength = 128; // XXX FIX! const unsigned int kMaxUniqueIdLength = 256; char deviceName[kMaxDeviceNameLength]; char uniqueId[kMaxUniqueIdLength]; // paranoia deviceName[0] = '\0'; uniqueId[0] = '\0'; int error = ptrViECapture->GetCaptureDevice(i, deviceName, sizeof(deviceName), uniqueId, sizeof(uniqueId)); if (error) { LOG((" VieCapture:GetCaptureDevice: Failed %d", ptrViEBase->LastError() )); continue; } #ifdef DEBUG LOG((" Capture Device Index %d, Name %s", i, deviceName)); webrtc::CaptureCapability cap; int numCaps = ptrViECapture->NumberOfCapabilities(uniqueId, kMaxUniqueIdLength); LOG(("Number of Capabilities %d", numCaps)); for (int j = 0; j < numCaps; j++) { if (ptrViECapture->GetCaptureCapability(uniqueId, kMaxUniqueIdLength, j, cap ) != 0 ) { break; } LOG(("type=%d width=%d height=%d maxFPS=%d", cap.rawType, cap.width, cap.height, cap.maxFPS )); } #endif if (uniqueId[0] == '\0') { // In case a device doesn't set uniqueId! strncpy(uniqueId, deviceName, sizeof(uniqueId)); uniqueId[sizeof(uniqueId)-1] = '\0'; // strncpy isn't safe } nsRefPtr<MediaEngineWebRTCVideoSource> vSource; NS_ConvertUTF8toUTF16 uuid(uniqueId); if (mVideoSources.Get(uuid, getter_AddRefs(vSource))) { // We've already seen this device, just append. aVSources->AppendElement(vSource.get()); } else { vSource = new MediaEngineWebRTCVideoSource(mVideoEngine, i); mVideoSources.Put(uuid, vSource); // Hashtable takes ownership. aVSources->AppendElement(vSource); } } ptrViEBase->Release(); ptrViECapture->Release(); return; #endif }
void MediaEngineWebRTC::EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >* aASources) { webrtc::VoEBase* ptrVoEBase = nullptr; webrtc::VoEHardware* ptrVoEHw = nullptr; // 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); } } ptrVoEHw->Release(); ptrVoEBase->Release(); }
/* * WebRTCAudioConduit Implementation */ MediaConduitErrorCode WebrtcAudioConduit::Init(WebrtcAudioConduit *other) { CSFLogDebug(logTag, "%s this=%p other=%p", __FUNCTION__, this, other); if (other) { MOZ_ASSERT(!other->mOtherDirection); other->mOtherDirection = this; mOtherDirection = other; // only one can call ::Create()/GetVoiceEngine() MOZ_ASSERT(other->mVoiceEngine); mVoiceEngine = other->mVoiceEngine; } else { //Per WebRTC APIs below function calls return NULL on failure if(!(mVoiceEngine = webrtc::VoiceEngine::Create())) { CSFLogError(logTag, "%s Unable to create voice engine", __FUNCTION__); return kMediaConduitSessionNotInited; } 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"; } CSFLogDebug(logTag, "%s Logging webrtc to %s level %d", __FUNCTION__, file, logs->level); mVoiceEngine->SetTraceFilter(logs->level); mVoiceEngine->SetTraceFile(file); } } if(!(mPtrVoEBase = VoEBase::GetInterface(mVoiceEngine))) { CSFLogError(logTag, "%s Unable to initialize VoEBase", __FUNCTION__); return kMediaConduitSessionNotInited; } if(!(mPtrVoENetwork = VoENetwork::GetInterface(mVoiceEngine))) { CSFLogError(logTag, "%s Unable to initialize VoENetwork", __FUNCTION__); return kMediaConduitSessionNotInited; } if(!(mPtrVoECodec = VoECodec::GetInterface(mVoiceEngine))) { CSFLogError(logTag, "%s Unable to initialize VoEBCodec", __FUNCTION__); return kMediaConduitSessionNotInited; } if(!(mPtrVoEProcessing = VoEAudioProcessing::GetInterface(mVoiceEngine))) { CSFLogError(logTag, "%s Unable to initialize VoEProcessing", __FUNCTION__); return kMediaConduitSessionNotInited; } if(!(mPtrVoEXmedia = VoEExternalMedia::GetInterface(mVoiceEngine))) { CSFLogError(logTag, "%s Unable to initialize VoEExternalMedia", __FUNCTION__); return kMediaConduitSessionNotInited; } if (other) { mChannel = other->mChannel; } else { // init the engine with our audio device layer if(mPtrVoEBase->Init() == -1) { CSFLogError(logTag, "%s VoiceEngine Base Not Initialized", __FUNCTION__); return kMediaConduitSessionNotInited; } if( (mChannel = mPtrVoEBase->CreateChannel()) == -1) { CSFLogError(logTag, "%s VoiceEngine Channel creation failed",__FUNCTION__); return kMediaConduitChannelError; } CSFLogDebug(logTag, "%s Channel Created %d ",__FUNCTION__, mChannel); if(mPtrVoENetwork->RegisterExternalTransport(mChannel, *this) == -1) { CSFLogError(logTag, "%s VoiceEngine, External Transport Failed",__FUNCTION__); return kMediaConduitTransportRegistrationFail; } if(mPtrVoEXmedia->SetExternalRecordingStatus(true) == -1) { CSFLogError(logTag, "%s SetExternalRecordingStatus Failed %d",__FUNCTION__, mPtrVoEBase->LastError()); return kMediaConduitExternalPlayoutError; } if(mPtrVoEXmedia->SetExternalPlayoutStatus(true) == -1) { CSFLogError(logTag, "%s SetExternalPlayoutStatus Failed %d ",__FUNCTION__, mPtrVoEBase->LastError()); return kMediaConduitExternalRecordingError; } CSFLogDebug(logTag , "%s AudioSessionConduit Initialization Done (%p)",__FUNCTION__, this); } return kMediaConduitNoError; }
/** * Peforms intialization of the MANDATORY components of the Video Engine */ MediaConduitErrorCode WebrtcVideoConduit::Init(WebrtcVideoConduit *other) { CSFLogDebug(logTag, "%s this=%p other=%p", __FUNCTION__, this, other); if (other) { MOZ_ASSERT(!other->mOtherDirection); other->mOtherDirection = this; mOtherDirection = other; // only one can call ::Create()/GetVideoEngine() MOZ_ASSERT(other->mVideoEngine); mVideoEngine = other->mVideoEngine; } else { #ifdef MOZ_WIDGET_ANDROID jobject context = jsjni_GetGlobalContextRef(); // get the JVM JavaVM *jvm = jsjni_GetVM(); if (webrtc::VideoEngine::SetAndroidObjects(jvm, (void*)context) != 0) { CSFLogError(logTag, "%s: could not set Android objects", __FUNCTION__); return kMediaConduitSessionNotInited; } #endif // Per WebRTC APIs below function calls return nullptr on failure if( !(mVideoEngine = webrtc::VideoEngine::Create()) ) { CSFLogError(logTag, "%s Unable to create video engine ", __FUNCTION__); return kMediaConduitSessionNotInited; } 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"; } CSFLogDebug(logTag, "%s Logging webrtc to %s level %d", __FUNCTION__, file, logs->level); mVideoEngine->SetTraceFilter(logs->level); mVideoEngine->SetTraceFile(file); } } if( !(mPtrViEBase = ViEBase::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video base interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViECapture = ViECapture::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video capture interface", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViECodec = ViECodec::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video codec interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViENetwork = ViENetwork::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video network interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViERender = ViERender::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video render interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } mPtrExtCodec = webrtc::ViEExternalCodec::GetInterface(mVideoEngine); if (!mPtrExtCodec) { CSFLogError(logTag, "%s Unable to get external codec interface: %d ", __FUNCTION__,mPtrViEBase->LastError()); return kMediaConduitSessionNotInited; } if( !(mPtrRTP = webrtc::ViERTP_RTCP::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video RTCP interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if (other) { mChannel = other->mChannel; mPtrExtCapture = other->mPtrExtCapture; mCapId = other->mCapId; } else { CSFLogDebug(logTag, "%s Engine Created: Init'ng the interfaces ",__FUNCTION__); if(mPtrViEBase->Init() == -1) { CSFLogError(logTag, " %s Video Engine Init Failed %d ",__FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitSessionNotInited; } if(mPtrViEBase->CreateChannel(mChannel) == -1) { CSFLogError(logTag, " %s Channel creation Failed %d ",__FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitChannelError; } if(mPtrViENetwork->RegisterSendTransport(mChannel, *this) == -1) { CSFLogError(logTag, "%s ViENetwork Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitTransportRegistrationFail; } if(mPtrViECapture->AllocateExternalCaptureDevice(mCapId, mPtrExtCapture) == -1) { CSFLogError(logTag, "%s Unable to Allocate capture module: %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitCaptureError; } if(mPtrViECapture->ConnectCaptureDevice(mCapId,mChannel) == -1) { CSFLogError(logTag, "%s Unable to Connect capture module: %d ", __FUNCTION__,mPtrViEBase->LastError()); return kMediaConduitCaptureError; } if(mPtrViERender->AddRenderer(mChannel, webrtc::kVideoI420, (webrtc::ExternalRenderer*) this) == -1) { CSFLogError(logTag, "%s Failed to added external renderer ", __FUNCTION__); return kMediaConduitInvalidRenderer; } // Set up some parameters, per juberti. Set MTU. if(mPtrViENetwork->SetMTU(mChannel, 1200) != 0) { CSFLogError(logTag, "%s MTU Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitMTUError; } // Turn on RTCP and loss feedback reporting. if(mPtrRTP->SetRTCPStatus(mChannel, webrtc::kRtcpCompound_RFC4585) != 0) { CSFLogError(logTag, "%s RTCPStatus Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitRTCPStatusError; } } #ifdef VIDEOCONDUIT_INSERT_TIMESTAMP mStartTime = PR_IntervalNow(); mSentFrames = 0; #endif CSFLogError(logTag, "%s Initialization Done", __FUNCTION__); return kMediaConduitNoError; }
/** * Performs initialization of the MANDATORY components of the Video Engine */ MediaConduitErrorCode WebrtcVideoConduit::Init(WebrtcVideoConduit *other) { CSFLogDebug(logTag, "%s this=%p other=%p", __FUNCTION__, this, other); #ifdef MOZILLA_INTERNAL_API // already know we must be on MainThread barring unit test weirdness MOZ_ASSERT(NS_IsMainThread()); nsresult rv; nsCOMPtr<nsIPrefService> prefs = do_GetService("@mozilla.org/preferences-service;1", &rv); if (!NS_WARN_IF(NS_FAILED(rv))) { nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs); if (branch) { int32_t temp; NS_WARN_IF(NS_FAILED(branch->GetBoolPref("media.video.test_latency", &mVideoLatencyTestEnable))); NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.min_bitrate", &temp))); if (temp >= 0) { mMinBitrate = temp; } NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.start_bitrate", &temp))); if (temp >= 0) { mStartBitrate = temp; } NS_WARN_IF(NS_FAILED(branch->GetIntPref("media.peerconnection.video.max_bitrate", &temp))); if (temp >= 0) { mMaxBitrate = temp; } } } #endif if (other) { MOZ_ASSERT(!other->mOtherDirection); other->mOtherDirection = this; mOtherDirection = other; // only one can call ::Create()/GetVideoEngine() MOZ_ASSERT(other->mVideoEngine); mVideoEngine = other->mVideoEngine; } else { #ifdef MOZ_WIDGET_ANDROID // get the JVM JavaVM *jvm = jsjni_GetVM(); if (webrtc::VideoEngine::SetAndroidObjects(jvm) != 0) { CSFLogError(logTag, "%s: could not set Android objects", __FUNCTION__); return kMediaConduitSessionNotInited; } #endif // Per WebRTC APIs below function calls return nullptr on failure if( !(mVideoEngine = webrtc::VideoEngine::Create()) ) { CSFLogError(logTag, "%s Unable to create video engine ", __FUNCTION__); return kMediaConduitSessionNotInited; } 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"; } CSFLogDebug(logTag, "%s Logging webrtc to %s level %d", __FUNCTION__, file, logs->level); mVideoEngine->SetTraceFilter(logs->level); mVideoEngine->SetTraceFile(file); } } if( !(mPtrViEBase = ViEBase::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video base interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViECapture = ViECapture::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video capture interface", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViECodec = ViECodec::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video codec interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViENetwork = ViENetwork::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video network interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrViERender = ViERender::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video render interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if( !(mPtrRTP = webrtc::ViERTP_RTCP::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get video RTCP interface ", __FUNCTION__); return kMediaConduitSessionNotInited; } if ( !(mPtrExtCodec = webrtc::ViEExternalCodec::GetInterface(mVideoEngine))) { CSFLogError(logTag, "%s Unable to get external codec interface %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitSessionNotInited; } if (other) { mChannel = other->mChannel; mPtrExtCapture = other->mPtrExtCapture; mCapId = other->mCapId; } else { CSFLogDebug(logTag, "%s Engine Created: Init'ng the interfaces ",__FUNCTION__); if(mPtrViEBase->Init() == -1) { CSFLogError(logTag, " %s Video Engine Init Failed %d ",__FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitSessionNotInited; } if(mPtrViEBase->CreateChannel(mChannel) == -1) { CSFLogError(logTag, " %s Channel creation Failed %d ",__FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitChannelError; } if(mPtrViENetwork->RegisterSendTransport(mChannel, *this) == -1) { CSFLogError(logTag, "%s ViENetwork Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitTransportRegistrationFail; } if(mPtrViECapture->AllocateExternalCaptureDevice(mCapId, mPtrExtCapture) == -1) { CSFLogError(logTag, "%s Unable to Allocate capture module: %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitCaptureError; } if(mPtrViECapture->ConnectCaptureDevice(mCapId,mChannel) == -1) { CSFLogError(logTag, "%s Unable to Connect capture module: %d ", __FUNCTION__,mPtrViEBase->LastError()); return kMediaConduitCaptureError; } if(mPtrViERender->AddRenderer(mChannel, webrtc::kVideoI420, (webrtc::ExternalRenderer*) this) == -1) { CSFLogError(logTag, "%s Failed to added external renderer ", __FUNCTION__); return kMediaConduitInvalidRenderer; } // Set up some parameters, per juberti. Set MTU. if(mPtrViENetwork->SetMTU(mChannel, 1200) != 0) { CSFLogError(logTag, "%s MTU Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitMTUError; } // Turn on RTCP and loss feedback reporting. if(mPtrRTP->SetRTCPStatus(mChannel, webrtc::kRtcpCompound_RFC4585) != 0) { CSFLogError(logTag, "%s RTCPStatus Failed %d ", __FUNCTION__, mPtrViEBase->LastError()); return kMediaConduitRTCPStatusError; } } CSFLogError(logTag, "%s Initialization Done", __FUNCTION__); return kMediaConduitNoError; }