我正在Android项目中实现webrtc,并且基于此示例in github。
本示例使用libjingle库。这是创建视频渲染 View 的方式:
// Create video renderers.
VideoRendererGui.setView((GLSurfaceView)videoView, new Runnable() {
@Override
public void run() {
createPeerConnectionFactory();
}
});
remoteRender = VideoRendererGui.create(
REMOTE_X, REMOTE_Y,
REMOTE_WIDTH, REMOTE_HEIGHT, scalingType, false);
localRender = VideoRendererGui.create(
LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true);
我的问题是如何管理自定义
remoteRender
和localRender
,以便可以在position
及其宽度和高度中更改它GLSurfaceView
。编辑:
我已经做了一个听众,我已经尝试过了:
@Override
public void onWidthHeightChange(int width, int height) {
VideoRendererGui.update(remoteRender,
REMOTE_X-width, REMOTE_X-height,
REMOTE_WIDTH-width, REMOTE_HEIGHT-height, scalingType, false);
if (iceConnected) {
VideoRendererGui.update(localRender,
LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED,
LOCAL_WIDTH_CONNECTED, LOCAL_HEIGHT_CONNECTED,
ScalingType.SCALE_ASPECT_FIT, true);
} else {
VideoRendererGui.update(localRender,
LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING, scalingType, true);
}
}
当我将宽度和高度的值都设置为150时,会出现以下错误:
08-21 14:34:01.621 7636-7636/org.appspot.apprtc E/AppRTCDemoActivity﹕ Fatal error: glUseProgram: GLES20 error: 1281
java.lang.RuntimeException: glUseProgram: GLES20 error: 1281
at org.webrtc.GlUtil.checkNoGLES2Error(GlUtil.java:48)
at org.webrtc.GlShader.useProgram(GlShader.java:123)
at org.webrtc.GlRectDrawer.drawOes(GlRectDrawer.java:132)
at org.webrtc.VideoRendererGui$YuvImageRenderer.draw(VideoRendererGui.java:371)
at org.webrtc.VideoRendererGui$YuvImageRenderer.access$800(VideoRendererGui.java:131)
at org.webrtc.VideoRendererGui.onDrawFrame(VideoRendererGui.java:722)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
解决方案2:
当我查看
mattm
答案时,我知道他是正确的。在搜索异常时,我发现它是
libjingle
库引发的异常。我在368、347行的VideoRendererGui.java处找到了这段代码,为我的问题找到了解决方案。添加 View 高度和宽度时,根据以下代码,它必须在以下范围内:
/**
* Creates VideoRenderer.Callbacks with top left corner at (x, y) and
* resolution (width, height). All parameters are in percentage of
* screen resolution.
*/
public static YuvImageRenderer create(
int x, int y, int width, int height) {
// Check display region parameters.
if (x < 0 || x > 100 || y < 0 || y > 100 ||
width < 0 || width > 100 || height < 0 || height > 100 ||
x + width > 100 || y + height > 100) {
throw new RuntimeException("Incorrect window parameters.");
}
因此,只要遵循这些规则,调用
VideoRendererGui.update(...
方法就可以正常工作谢谢
最佳答案
就像更改字段一样简单
REMOTE_X
,REMOTE_Y
或LOCAL_X_CONNECTING
,LOCAL_Y_CONNECTING
,REMOTE_WIDTH
,REMOTE_HEIGHT
或LOCAL_WIDTH_CONNECTING
,LOCAL_HEIGHT_CONNECTING
如果要在创建对象后更改渲染,请调用
VideoRendererGui.update(remoteRender, ...)
。