CameraCapturer在调用startCapture之前必须初始化

huangapple go评论98阅读模式
英文:

CameraCapturer must be initialized before calling startCapture

问题

在在Android中实现WebRTC时遇到以下问题:

> Caused by: java.lang.RuntimeException: 在调用startCapture之前,必须初始化CameraCapturer。

build.gradle(:app)

dependencies {
  ......
  implementation 'org.webrtc:google-webrtc:1.0.+'
  ......
}

// 导致问题的代码块:

private void getVideoSource() {
    // isScreenCast = false
    videoSource = peerConnectionFactory.createVideoSource(false);
    surfaceTextureHelper = SurfaceTextureHelper.create(Thread.currentThread().getName(), rootEglBase.getEglBaseContext());
    VideoCapturer videoCapturer = createCameraCapturer(new Camera1Enumerator(false));
    localVideoTrack = peerConnectionFactory.createVideoTrack("200", videoSource);
    localVideoTrack.addSink(local_renderer);
    if(videoCapturer != null)
        videoCapturer.startCapture(1000, 1000, 30); // <- 异常出现在这里
    
}

CameraCapturer已被弃用。现在有Camera1Capturer可用。

英文:

Facing this issue while implementing WebRTC in Android:

> Caused by: java.lang.RuntimeException: CameraCapturer must be initialized before calling startCapture.

build.gradle(:app)

dependencies {
  ......
  implementation 'org.webrtc:google-webrtc:1.0.+'
  ......
}

// Chunk causing problem:

private void getVideoSource() {
    // isScreenCast = false
    videoSource = peerConnectionFactory.createVideoSource(false);
    surfaceTextureHelper = SurfaceTextureHelper.create(Thread.currentThread().getName(), rootEglBase.getEglBaseContext());
    VideoCapturer videoCapturer = createCameraCapturer(new Camera1Enumerator(false));
    localVideoTrack = peerConnectionFactory.createVideoTrack("200", videoSource);
    localVideoTrack.addSink(local_renderer);
    if(videoCapturer != null)
        videoCapturer.startCapture(1000,1000,30); // <- Here is the Exception
    
}

CameraCapturer is deprecated. There is Camera1Capturer now available.

答案1

得分: 3

> 在使用之前您需要进行初始化

private void getVideoSource() {
    VideoCapturer videoCapturer = createVideoCapturer();
    VideoSource videoSource;
    // 创建一个VideoSource实例
    if (videoCapturer != null) {
        SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
        videoSource = factory.createVideoSource(videoCapturer.isScreencast());
        videoCapturer.initialize(surfaceTextureHelper, this, videoSource.getCapturerObserver());
    }
   
    localVideoTrack = factory.createVideoTrack("100", videoSource);

    // 创建MediaConstraints - 用于指定视频和音频约束
    audioConstraints = new MediaConstraints();
    videoConstraints = new MediaConstraints();

    // 创建一个AudioSource实例
    audioSource = factory.createAudioSource(audioConstraints);
    localAudioTrack = factory.createAudioTrack("101", audioSource);

    if (videoCapturer != null) {
        videoCapturer.startCapture(1024, 720, 30);
    }
    binding.localGlSurfaceView.setVisibility(View.VISIBLE);
    // 最后,当我们的VideoRenderer准备好后,
    // 可以将我们的渲染器添加到VideoTrack中。
    localVideoTrack.addSink(binding.localGlSurfaceView);
}
英文:

> You need to initialise before you use it

 private void getVideoSource() {
    VideoCapturer videoCapturer = createVideoCapturer();
    VideoSource videoSource;
    //Create a VideoSource instance
    if (videoCapturer != null) {
        SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
        videoSource = factory.createVideoSource(videoCapturer.isScreencast());
        videoCapturer.initialize(surfaceTextureHelper, this, videoSource.getCapturerObserver());
    }
   

    localVideoTrack = factory.createVideoTrack("100", videoSource);

    //Create MediaConstraints - Will be useful for specifying video and audio constraints.
    audioConstraints = new MediaConstraints();
    videoConstraints = new MediaConstraints();

    //create an AudioSource instance
    audioSource = factory.createAudioSource(audioConstraints);
    localAudioTrack = factory.createAudioTrack("101", audioSource);

    if (videoCapturer != null) {
        videoCapturer.startCapture(1024, 720, 30);
    }
    binding.localGlSurfaceView.setVisibility(View.VISIBLE);
    // And finally, with our VideoRenderer ready, we
    // can add our renderer to the VideoTrack.
    localVideoTrack.addSink(binding.localGlSurfaceView);
}

huangapple
  • 本文由 发表于 2020年4月10日 17:14:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/61137244.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定