是否可以在没有对等连接的情况下使用webrtc VideoCapturer?
我们有一个运行中的androidapp应用程序(来自examples / androidapp)。我们将以下代码从工作应用程序中带入了一个单独的活动,在该活动中,我们直接使用Camera Capturer,而不创建对等连接。我们使用CapturerObserver实例创建一个视频捕获器(camera2),然后尝试将其渲染到org.webrtc.SurfaceViewRenderer。下面是代码。
按预期,使用有效的videoFrame对象多次调用CapturerObserver的onFrameCaptured。从那里,我们将其传递给SurfaceViewRenderer。但是,视频无法渲染,SurfaceViewRenderer保持黑色。
使用VideoCapturer和SurfaceViewRenderer是正确的方法吗?发送到SurfaceViewRenderer之前是否需要任何格式转换?
private class MyCapturerObserver implements CapturerObserver {
@Override
public void onCapturerStarted(boolean b) {
Log.e(TAG, "capture started: " + b);
}
@Override
public void onCapturerStopped() {
Log.e(TAG, "capture stopped");
}
@Override
public void onFrameCaptured(final VideoFrame videoFrame) {
//fullscreenRenderer.onFrame(videoFrame);
runOnUiThread(new Runnable() {
@Override
public void run() {
fullscreenRenderer.onFrame(videoFrame);
}
});
}
}
capturer = createVideoCapturer();
captureObserver = new MyCapturerObserver();
surfaceTextureHelper =
SurfaceTextureHelper.create("CaptureThread", eglBase.getEglBaseContext());
capturer.initialize(surfaceTextureHelper, getApplicationContext(), captureObserver);
capturer.startCapture(1280, 720, 30);
答案 0 :(得分:3)
使用factory.createVideoSource
。您可以在创建对等连接之前使用它。您可以在PeerConnectionClient.java
public VideoTrack createVideoTrack(VideoCapturer capturer) {
surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
videoSource = factory.createVideoSource(capturer.isScreencast());
capturer.initialize(surfaceTextureHelper, appContext, videoSource.getCapturerObserver());
capturer.startCapture(videoWidth, videoHeight, videoFps);
localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
localVideoTrack.setEnabled(renderVideo);
localVideoTrack.addSink(localRender);
return localVideoTrack;
}