2017-04-12 25 views
1

我正在使用webrtc實現調用功能。我成功地能夠撥打語音電話。但視頻通話提供錯誤。即使我無法通過VideoCapturerAndroid添加本地流。我搜查了所有通過Google搜索找到的參考資料,但沒有一個爲我的案例工作。我根據支持格式更改了媒體限制(視頻),但沒有運氣。請幫我解決問題。android webrtc VideoCapturerAndroid由於未設置applicationContext而崩潰

它顯示運行時異常未設置applicationContext。

W/System.err: java.lang.RuntimeException: applicationContext not set. 
W/System.err:  at org.webrtc.VideoCapturerAndroid.startCapture(VideoCapturerAndroid.java:499) 

完整日誌在下面給出。

04-12 15:08:03.657 23560-24939/com.example.messenger D/VideoCapturerAndroid: VideoCapturerAndroid 
04-12 15:08:03.657 23560-24939/com.example.messenger D/VideoCapturerAndroid: init: Camera 1, Facing front, Orientation 270 
04-12 15:08:03.657 23560-24939/com.example.messenger D/VideoCapturerAndroid: Get supported formats. 
04-12 15:08:03.657 23560-24939/com.example.messenger D/VideoCapturerAndroid: Opening camera 1 
04-12 15:08:03.842 23560-23560/com.example.messenger V/ActivityThread: updateVisibility : ActivityRecord{152a65d3 [email protected] {com.example.messenger/com.example.messenger.activity.ChatActivity}} show : false 
04-12 15:08:04.007 23560-24939/com.example.messenger D/VideoCapturerAndroid: Opening camera 0 
04-12 15:08:04.192 23560-24939/com.example.messenger D/VideoCapturerAndroid: Get supported formats done. 
04-12 15:08:04.197 23560-24939/com.example.messenger D/VideoCapturerAndroid: Supported formats for camera 1: [ 
                          { 
                           "width": 1920, 
                           "height": 1080, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 1440, 
                           "height": 1080, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 1280, 
                           "height": 960, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 1280, 
                           "height": 720, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 1056, 
                           "height": 864, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 1024, 
                           "height": 768, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 1008, 
                           "height": 566, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 800, 
                           "height": 600, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 800, 
                           "height": 480, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 800, 
                           "height": 450, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 720, 
                           "height": 480, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 640, 
                           "height": 480, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 528, 
                           "height": 432, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 480, 
                           "height": 320, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 480, 
                           "height": 270, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 352, 
                           "height": 288, 
                           "framerate": 30 
                          }, 
                          { 
                           "width": 320, 
                           "height": 240, 
                           "framerate": 30 
                          } 
                          ] 
04-12 15:08:04.202 23560-24946/com.example.messenger D/VideoCapturerAndroid: startCapture requested: [email protected] 
04-12 15:08:04.202 23560-24946/com.example.messenger W/System.err: java.lang.RuntimeException: applicationContext not set. 
04-12 15:08:04.202 23560-24946/com.example.messenger W/System.err:  at org.webrtc.VideoCapturerAndroid.startCapture(VideoCapturerAndroid.java:499) 
04-12 15:08:04.202 23560-24946/com.example.messenger E/rtc: # 
                     # Fatal error in ../../talk/app/webrtc/java/jni/androidvideocapturer_jni.cc, line 126 
                     # Check failed: !jni()->ExceptionCheck() 
                     # error during VideoCapturerAndroid.startCapture 
                     # 
04-12 15:08:04.202 23560-24946/com.example.messenger A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 24946 (Thread-64952) 

在此先感謝。

回答

1

如果您提供了您正在使用的代碼段,很容易找到問題。

以下是從相機生成本地視頻軌道的步驟。

private VideoCapturer createCameraCapturer(CameraEnumerator enumerator) { 
    final String[] deviceNames = enumerator.getDeviceNames(); 
    // First, try to find front facing camera 
    Log.d(TAG, "Looking for front facing cameras."); 
    for (String deviceName : deviceNames) { 
    if (enumerator.isFrontFacing(deviceName)) { 
     Log.d(TAG, "Creating front facing camera capturer."); 
     VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null); 
     if (videoCapturer != null) { 
     return videoCapturer; 
     } 
    } 
    } 
    // Front facing camera not found, try something else 
    Log.d(TAG, "Looking for other cameras."); 
    for (String deviceName : deviceNames) { 
    if (!enumerator.isFrontFacing(deviceName)) { 
     Log.d(TAG, "Creating other camera capturer."); 
     VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null); 
     if (videoCapturer != null) { 
     return videoCapturer; 
     } 
    } 
    } 
    return null; 
} 

VideoCapturer videoCapturer = createCameraCapturer(new Camera1Enumerator(captureToTexture())); 
VideoSource videoSource = factory.createVideoSource(videoCapturer); 
videoCapturer.startCapture(1200/*width*/, 720/*height*/, 25/*fps*/); 

VideoTrack localVideoTrack = factory.createVideoTrack("NameYourTrack", videoSource); 

下面的代碼是呈現本地視頻

EglBase rootEglBase = EglBase.create(); 
SurfaceViewRenderer pipRenderer = (SurfaceViewRenderer) findViewById(R.id.pip_video_view); //You need define your UI element to render video 
pipRenderer.init(rootEglBase.getEglBaseContext(), null); 
pipRenderer.setScalingType(ScalingType.SCALE_ASPECT_FIT); 
localVideoTrack.setEnabled(true); 
localVideoTrack.addRenderer(new VideoRenderer(pipRenderer)); 

注:該代碼將與最新的WebRTC的代碼基礎工作,如果你使用的是舊機庫,您可能需要更新或尋找相應的AppRTCMobile例子。

+0

謝謝你的回答。你能告訴我你使用的WebRTC版本嗎?目前我正在使用'io.pristine:libjingle:9694 @ aar'for android。 – Tamal

+0

原始.aar已過年,您可以通過以下說明在https://webrtc.org/native-code/android/上構建最新版本的Ubuntu機器 – Ajay

+1

我在以下git repo中上傳了我的框架https://github.com/AjayChoudary/WebRTCFramework/ – Ajay

相關問題