我正在Android项目中实施webrtc,我基于此示例in github。
此示例使用libjingle库。这就是视频渲染视图的创建方式:
// 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,我找到了解决问题的方法。
添加视图高度和宽度时,必须根据以下代码在这些范围内:
/**
* 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(...
就能完美地运作
由于
答案 0 :(得分:3)
它就像更改字段一样简单
REMOTE_X
,REMOTE_Y
或LOCAL_X_CONNECTING
,LOCAL_Y_CONNECTING
,REMOTE_WIDTH
,REMOTE_HEIGHT
或LOCAL_WIDTH_CONNECTING
,LOCAL_HEIGHT_CONNECTING
如果要在创建对象后更改渲染,请调用VideoRendererGui.update(remoteRender, ...)
。