Use mirror image for Android AppRTCDemo local preview.

Similar to Chrome apprtc using mirror image for camera
local preview provides better experience when device
is rotated.

R=jiayl@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/25209004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7741 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
glaznev@webrtc.org 2014-11-24 17:31:01 +00:00
parent 03499a0e95
commit dab5d92df6
2 changed files with 26 additions and 16 deletions

View File

@ -227,6 +227,7 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
private static enum RendererType { RENDERER_YUV, RENDERER_TEXTURE }; private static enum RendererType { RENDERER_YUV, RENDERER_TEXTURE };
private RendererType rendererType; private RendererType rendererType;
private ScalingType scalingType; private ScalingType scalingType;
private boolean mirror;
// Flag if renderFrame() was ever called. // Flag if renderFrame() was ever called.
boolean seenFrame; boolean seenFrame;
// Total number of video frames received in renderFrame() call. // Total number of video frames received in renderFrame() call.
@ -265,11 +266,12 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
private YuvImageRenderer( private YuvImageRenderer(
GLSurfaceView surface, int id, GLSurfaceView surface, int id,
int x, int y, int width, int height, int x, int y, int width, int height,
ScalingType scalingType) { ScalingType scalingType, boolean mirror) {
Log.d(TAG, "YuvImageRenderer.Create id: " + id); Log.d(TAG, "YuvImageRenderer.Create id: " + id);
this.surface = surface; this.surface = surface;
this.id = id; this.id = id;
this.scalingType = scalingType; this.scalingType = scalingType;
this.mirror = mirror;
frameToRenderQueue = new LinkedBlockingQueue<I420Frame>(1); frameToRenderQueue = new LinkedBlockingQueue<I420Frame>(1);
// Create texture vertices. // Create texture vertices.
texLeft = (x - 50) / 50.0f; texLeft = (x - 50) / 50.0f;
@ -373,11 +375,18 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
textureVertices = directNativeFloatBuffer(textureVeticesFloat); textureVertices = directNativeFloatBuffer(textureVeticesFloat);
Log.d(TAG, " Texture UV offsets: " + texOffsetU + ", " + texOffsetV); Log.d(TAG, " Texture UV offsets: " + texOffsetU + ", " + texOffsetV);
float uLeft = texOffsetU;
float uRight = 1.0f - texOffsetU;
if (mirror) {
// Swap U coordinates for mirror image.
uLeft = 1.0f - texOffsetU;
uRight = texOffsetU;
}
float textureCoordinatesFloat[] = new float[] { float textureCoordinatesFloat[] = new float[] {
texOffsetU, texOffsetV, // left top uLeft, texOffsetV, // left top
texOffsetU, 1.0f - texOffsetV, // left bottom uLeft, 1.0f - texOffsetV, // left bottom
1.0f - texOffsetU, texOffsetV, // right top uRight, texOffsetV, // right top
1.0f - texOffsetU, 1.0f - texOffsetV // right bottom uRight, 1.0f - texOffsetV // right bottom
}; };
textureCoords = directNativeFloatBuffer(textureCoordinatesFloat); textureCoords = directNativeFloatBuffer(textureCoordinatesFloat);
} }
@ -599,16 +608,17 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
* Creates VideoRenderer with top left corner at (x, y) and resolution * Creates VideoRenderer with top left corner at (x, y) and resolution
* (width, height). All parameters are in percentage of screen resolution. * (width, height). All parameters are in percentage of screen resolution.
*/ */
public static VideoRenderer createGui( public static VideoRenderer createGui(int x, int y, int width, int height,
int x, int y, int width, int height, ScalingType scalingType) ScalingType scalingType, boolean mirror) throws Exception {
throws Exception { YuvImageRenderer javaGuiRenderer = create(
YuvImageRenderer javaGuiRenderer = create(x, y, width, height, scalingType); x, y, width, height, scalingType, mirror);
return new VideoRenderer(javaGuiRenderer); return new VideoRenderer(javaGuiRenderer);
} }
public static VideoRenderer.Callbacks createGuiRenderer( public static VideoRenderer.Callbacks createGuiRenderer(
int x, int y, int width, int height, ScalingType scalingType) { int x, int y, int width, int height,
return create(x, y, width, height, scalingType); ScalingType scalingType, boolean mirror) {
return create(x, y, width, height, scalingType, mirror);
} }
/** /**
@ -616,8 +626,8 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
* resolution (width, height). All parameters are in percentage of * resolution (width, height). All parameters are in percentage of
* screen resolution. * screen resolution.
*/ */
public static YuvImageRenderer create( public static YuvImageRenderer create(int x, int y, int width, int height,
int x, int y, int width, int height, ScalingType scalingType) { ScalingType scalingType, boolean mirror) {
// Check display region parameters. // Check display region parameters.
if (x < 0 || x > 100 || y < 0 || y > 100 || if (x < 0 || x > 100 || y < 0 || y > 100 ||
width < 0 || width > 100 || height < 0 || height > 100 || width < 0 || width > 100 || height < 0 || height > 100 ||
@ -631,7 +641,7 @@ public class VideoRendererGui implements GLSurfaceView.Renderer {
} }
final YuvImageRenderer yuvImageRenderer = new YuvImageRenderer( final YuvImageRenderer yuvImageRenderer = new YuvImageRenderer(
instance.surface, instance.yuvImageRenderers.size(), instance.surface, instance.yuvImageRenderers.size(),
x, y, width, height, scalingType); x, y, width, height, scalingType, mirror);
synchronized (instance.yuvImageRenderers) { synchronized (instance.yuvImageRenderers) {
if (instance.onSurfaceCreatedCalled) { if (instance.onSurfaceCreatedCalled) {
// onSurfaceCreated has already been called for VideoRendererGui - // onSurfaceCreated has already been called for VideoRendererGui -

View File

@ -117,8 +117,8 @@ public class AppRTCDemoActivity extends Activity
VideoRendererGui.setView(videoView); VideoRendererGui.setView(videoView);
scalingType = ScalingType.SCALE_ASPECT_FILL; scalingType = ScalingType.SCALE_ASPECT_FILL;
remoteRender = VideoRendererGui.create(0, 0, 100, 100, scalingType); remoteRender = VideoRendererGui.create(0, 0, 100, 100, scalingType, false);
localRender = VideoRendererGui.create(0, 0, 100, 100, scalingType); localRender = VideoRendererGui.create(0, 0, 100, 100, scalingType, true);
videoView.setOnClickListener( videoView.setOnClickListener(
new View.OnClickListener() { new View.OnClickListener() {