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

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

CameraCapturer must be initialized before calling startCapture

问题

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

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

build.gradle(:app)

  1. dependencies {
  2. ......
  3. implementation 'org.webrtc:google-webrtc:1.0.+'
  4. ......
  5. }

// 导致问题的代码块:

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

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)

  1. dependencies {
  2. ......
  3. implementation 'org.webrtc:google-webrtc:1.0.+'
  4. ......
  5. }

// Chunk causing problem:

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

CameraCapturer is deprecated. There is Camera1Capturer now available.

答案1

得分: 3

  1. > 在使用之前您需要进行初始化
  2. private void getVideoSource() {
  3. VideoCapturer videoCapturer = createVideoCapturer();
  4. VideoSource videoSource;
  5. // 创建一个VideoSource实例
  6. if (videoCapturer != null) {
  7. SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
  8. videoSource = factory.createVideoSource(videoCapturer.isScreencast());
  9. videoCapturer.initialize(surfaceTextureHelper, this, videoSource.getCapturerObserver());
  10. }
  11. localVideoTrack = factory.createVideoTrack("100", videoSource);
  12. // 创建MediaConstraints - 用于指定视频和音频约束
  13. audioConstraints = new MediaConstraints();
  14. videoConstraints = new MediaConstraints();
  15. // 创建一个AudioSource实例
  16. audioSource = factory.createAudioSource(audioConstraints);
  17. localAudioTrack = factory.createAudioTrack("101", audioSource);
  18. if (videoCapturer != null) {
  19. videoCapturer.startCapture(1024, 720, 30);
  20. }
  21. binding.localGlSurfaceView.setVisibility(View.VISIBLE);
  22. // 最后,当我们的VideoRenderer准备好后,
  23. // 可以将我们的渲染器添加到VideoTrack中。
  24. localVideoTrack.addSink(binding.localGlSurfaceView);
  25. }
英文:

> You need to initialise before you use it

  1. private void getVideoSource() {
  2. VideoCapturer videoCapturer = createVideoCapturer();
  3. VideoSource videoSource;
  4. //Create a VideoSource instance
  5. if (videoCapturer != null) {
  6. SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
  7. videoSource = factory.createVideoSource(videoCapturer.isScreencast());
  8. videoCapturer.initialize(surfaceTextureHelper, this, videoSource.getCapturerObserver());
  9. }
  10. localVideoTrack = factory.createVideoTrack("100", videoSource);
  11. //Create MediaConstraints - Will be useful for specifying video and audio constraints.
  12. audioConstraints = new MediaConstraints();
  13. videoConstraints = new MediaConstraints();
  14. //create an AudioSource instance
  15. audioSource = factory.createAudioSource(audioConstraints);
  16. localAudioTrack = factory.createAudioTrack("101", audioSource);
  17. if (videoCapturer != null) {
  18. videoCapturer.startCapture(1024, 720, 30);
  19. }
  20. binding.localGlSurfaceView.setVisibility(View.VISIBLE);
  21. // And finally, with our VideoRenderer ready, we
  22. // can add our renderer to the VideoTrack.
  23. localVideoTrack.addSink(binding.localGlSurfaceView);
  24. }

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:

确定