From 3fffd66dfa83494294de1b6ccd4c775f554e3be2 Mon Sep 17 00:00:00 2001 From: "guoweis@webrtc.org" Date: Wed, 18 Mar 2015 04:20:03 +0000 Subject: [PATCH] Revert "Implement Rotation in Android Renderer." This reverts commit 835ec63d8a64bbc8a573a5e0b7a09659188122d2. TBR=guoweis@webrtc.org BUG= Review URL: https://webrtc-codereview.appspot.com/51399004 Cr-Commit-Position: refs/heads/master@{#8771} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8771 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../org/webrtc/VideoCapturerAndroidTest.java | 6 -- .../android/org/webrtc/VideoRendererGui.java | 67 +++---------------- .../app/webrtc/java/jni/peerconnection_jni.cc | 48 +++---------- .../java/src/org/webrtc/VideoRenderer.java | 19 +----- .../src/org/webrtc/PeerConnectionTest.java | 12 ---- .../apprtc/test/PeerConnectionClientTest.java | 6 -- 6 files changed, 20 insertions(+), 138 deletions(-) diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java index 24294ab8f7..688ce96e84 100644 --- a/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java +++ b/talk/app/webrtc/androidtests/src/org/webrtc/VideoCapturerAndroidTest.java @@ -52,12 +52,6 @@ public class VideoCapturerAndroidTest extends ActivityTestCase { } } - // TODO(guoweis): Remove this once chrome code base is updated. - @Override - public boolean canApplyRotation() { - return false; - } - public int WaitForNextFrameToRender() throws InterruptedException { synchronized (frameLock) { frameLock.wait(); diff --git a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java index 4ad8ccca18..ef0fbc68a5 100644 --- a/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java +++ b/talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java @@ -37,7 +37,6 @@ import java.util.concurrent.LinkedBlockingQueue; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; -import android.annotation.SuppressLint; import android.graphics.SurfaceTexture; import android.opengl.EGL14; import android.opengl.EGLContext; @@ -265,22 +264,6 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { private int videoWidth; private int videoHeight; - // This is the degree that the frame should be rotated clockwisely to have - // it rendered up right. - private int rotationDegree; - - // Mapping array from original UV mapping to the rotated mapping. The number - // is the position where the original UV coordination should be mapped - // to. (0,1) is the left top coord. (2,3) is the top bottom. (4,5) is the - // right top. (6,7) is the right bottom. Note that this is the coordination - // that got rotated. For example, using the original left bottom (2,3) as - // the top left (0,1) means 90 degree clockwise rotation. - private static int rotation_matrix[][] = - { {0, 1, 2, 3, 4, 5, 6, 7}, // 0 degree - {2, 3, 6, 7, 0, 1, 4, 5}, // 90 degree (clockwise) - {6, 7, 4, 5, 2, 3, 0, 1}, // 180 degree (clockwise) - {4, 5, 0, 1, 6, 7, 2, 3} };// 270 degree (clockwise) - private YuvImageRenderer( GLSurfaceView surface, int id, int x, int y, int width, int height, @@ -309,7 +292,6 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { }; textureCoords = directNativeFloatBuffer(textureCoordinatesFloat); updateTextureProperties = false; - rotationDegree = 0; } private void createTextures(int yuvProgram, int oesProgram) { @@ -358,13 +340,7 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { if (displayWidth > 1 && displayHeight > 1 && videoWidth > 1 && videoHeight > 1) { float displayAspectRatio = displayWidth / displayHeight; - // videoAspectRatio should be the one after rotation applied. - float videoAspectRatio = 0; - if (rotationDegree == 90 || rotationDegree == 270) { - videoAspectRatio = (float)videoHeight / videoWidth; - } else { - videoAspectRatio = (float)videoWidth / videoHeight; - } + float videoAspectRatio = (float)videoWidth / videoHeight; if (scalingType == ScalingType.SCALE_ASPECT_FIT) { // Need to re-adjust vertices width or height to match video AR. if (displayAspectRatio > videoAspectRatio) { @@ -413,21 +389,7 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { uRight, texOffsetV, // right top uRight, 1.0f - texOffsetV // right bottom }; - - float textureCoordinatesRotatedFloat[]; - if (rotationDegree == 0) { - textureCoordinatesRotatedFloat = textureCoordinatesFloat; - } else { - textureCoordinatesRotatedFloat = - new float[textureCoordinatesFloat.length]; - int index = rotationDegree / 90; - for(int i = 0; i < textureCoordinatesFloat.length; i++) { - textureCoordinatesRotatedFloat[rotation_matrix[index][i]] = - textureCoordinatesFloat[i]; - } - } - textureCoords = - directNativeFloatBuffer(textureCoordinatesRotatedFloat); + textureCoords = directNativeFloatBuffer(textureCoordinatesFloat); } updateTextureProperties = false; } @@ -566,19 +528,16 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { } } - private void setSize(final int width, final int height, - final int rotation) { - if (width == videoWidth && height == videoHeight && - rotation == rotationDegree) { - return; + private void setSize(final int width, final int height) { + if (width == videoWidth && height == videoHeight) { + return; } Log.d(TAG, "ID: " + id + ". YuvImageRenderer.setSize: " + - width + " x " + height + " rotation " + rotation); + width + " x " + height); videoWidth = width; videoHeight = height; - rotationDegree = rotation; int[] strides = { width, width / 2, width / 2 }; // Frame re-allocation need to be synchronized with copying // frame to textures in draw() function to avoid re-allocating @@ -587,17 +546,15 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { // Clear rendering queue. frameToRenderQueue.poll(); // Re-allocate / allocate the frame. - yuvFrameToRender = new I420Frame(width, height, rotationDegree, - strides, null); - textureFrameToRender = new I420Frame(width, height, rotationDegree, - null, -1); + yuvFrameToRender = new I420Frame(width, height, strides, null); + textureFrameToRender = new I420Frame(width, height, null, -1); updateTextureProperties = true; } } @Override public synchronized void renderFrame(I420Frame frame) { - setSize(frame.width, frame.height, frame.rotationDegree); + setSize(frame.width, frame.height); long now = System.nanoTime(); framesReceived++; // Skip rendering of this frame if setSize() was not called. @@ -645,11 +602,6 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { surface.requestRender(); } - // TODO(guoweis): Remove this once chrome code base is updated. - @Override - public boolean canApplyRotation() { - return true; - } } /** Passes GLSurfaceView to video renderer. */ @@ -760,7 +712,6 @@ public class VideoRendererGui implements GLSurfaceView.Renderer { } } - @SuppressLint("NewApi") @Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { Log.d(TAG, "VideoRendererGui.onSurfaceCreated"); diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc index 7b4228bfc8..6403a9e1c1 100644 --- a/talk/app/webrtc/java/jni/peerconnection_jni.cc +++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc @@ -709,9 +709,6 @@ class VideoRendererWrapper : public VideoRendererInterface { renderer_->RenderFrame(frame); } - // TODO(guoweis): Remove this once chrome code base is updated. - bool CanApplyRotation() override { return true; } - private: explicit VideoRendererWrapper(cricket::VideoRenderer* renderer) : renderer_(renderer), width_(0), height_(0) {} @@ -728,19 +725,14 @@ class JavaVideoRendererWrapper : public VideoRendererInterface { j_render_frame_id_(GetMethodID( jni, GetObjectClass(jni, j_callbacks), "renderFrame", "(Lorg/webrtc/VideoRenderer$I420Frame;)V")), - j_can_apply_rotation_id_(GetMethodID( - jni, GetObjectClass(jni, j_callbacks), - "canApplyRotation", "()Z")), j_frame_class_(jni, FindClass(jni, "org/webrtc/VideoRenderer$I420Frame")), j_i420_frame_ctor_id_(GetMethodID( - jni, *j_frame_class_, "", "(III[I[Ljava/nio/ByteBuffer;)V")), + jni, *j_frame_class_, "", "(II[I[Ljava/nio/ByteBuffer;)V")), j_texture_frame_ctor_id_(GetMethodID( jni, *j_frame_class_, "", - "(IIILjava/lang/Object;I)V")), - j_byte_buffer_class_(jni, FindClass(jni, "java/nio/ByteBuffer")), - can_apply_rotation_set_(false), - can_apply_rotation_(false) { + "(IILjava/lang/Object;I)V")), + j_byte_buffer_class_(jni, FindClass(jni, "java/nio/ByteBuffer")) { CHECK_EXCEPTION(jni); } @@ -749,12 +741,10 @@ class JavaVideoRendererWrapper : public VideoRendererInterface { void RenderFrame(const cricket::VideoFrame* video_frame) override { ScopedLocalRefFrame local_ref_frame(jni()); - // Calling CanApplyRotation here to ensure can_apply_rotation_ is set. - CanApplyRotation(); - + // TODO(guoweis): Remove once the java implementation supports rotation. const cricket::VideoFrame* frame = - can_apply_rotation_ ? video_frame - : video_frame->GetCopyWithRotationApplied(); + video_frame->GetCopyWithRotationApplied(); + if (frame->GetNativeHandle() != NULL) { jobject j_frame = CricketToJavaTextureFrame(frame); jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame); @@ -766,21 +756,6 @@ class JavaVideoRendererWrapper : public VideoRendererInterface { } } - // TODO(guoweis): Report that rotation is supported as RenderFrame calls - // GetCopyWithRotationApplied. - virtual bool CanApplyRotation() override { - if (can_apply_rotation_set_) { - return can_apply_rotation_; - } - ScopedLocalRefFrame local_ref_frame(jni()); - jboolean ret = - jni()->CallBooleanMethod(*j_callbacks_, j_can_apply_rotation_id_); - CHECK_EXCEPTION(jni()); - can_apply_rotation_ = ret; - can_apply_rotation_set_ = true; - return ret; - } - private: // Return a VideoRenderer.I420Frame referring to the data in |frame|. jobject CricketToJavaI420Frame(const cricket::VideoFrame* frame) { @@ -803,9 +778,7 @@ class JavaVideoRendererWrapper : public VideoRendererInterface { jni()->SetObjectArrayElement(planes, 2, v_buffer); return jni()->NewObject( *j_frame_class_, j_i420_frame_ctor_id_, - frame->GetWidth(), frame->GetHeight(), - static_cast(frame->GetVideoRotation()), - strides, planes); + frame->GetWidth(), frame->GetHeight(), strides, planes); } // Return a VideoRenderer.I420Frame referring texture object in |frame|. @@ -816,9 +789,7 @@ class JavaVideoRendererWrapper : public VideoRendererInterface { int texture_id = handle->GetTextureId(); return jni()->NewObject( *j_frame_class_, j_texture_frame_ctor_id_, - frame->GetWidth(), frame->GetHeight(), - static_cast(frame->GetVideoRotation()), - texture_object, texture_id); + frame->GetWidth(), frame->GetHeight(), texture_object, texture_id); } JNIEnv* jni() { @@ -827,13 +798,10 @@ class JavaVideoRendererWrapper : public VideoRendererInterface { ScopedGlobalRef j_callbacks_; jmethodID j_render_frame_id_; - jmethodID j_can_apply_rotation_id_; ScopedGlobalRef j_frame_class_; jmethodID j_i420_frame_ctor_id_; jmethodID j_texture_frame_ctor_id_; ScopedGlobalRef j_byte_buffer_class_; - bool can_apply_rotation_set_; - bool can_apply_rotation_; }; diff --git a/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java b/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java index 29b3743c5b..45fafa51f3 100644 --- a/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java +++ b/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java @@ -47,18 +47,13 @@ public class VideoRenderer { public Object textureObject; public int textureId; - // rotationDegree is the degree that the frame must be rotated clockwisely - // to be rendered correctly. - public int rotationDegree; - /** * Construct a frame of the given dimensions with the specified planar * data. If |yuvPlanes| is null, new planes of the appropriate sizes are * allocated. */ public I420Frame( - int width, int height, int rotationDegree, - int[] yuvStrides, ByteBuffer[] yuvPlanes) { + int width, int height, int[] yuvStrides, ByteBuffer[] yuvPlanes) { this.width = width; this.height = height; this.yuvStrides = yuvStrides; @@ -70,15 +65,13 @@ public class VideoRenderer { } this.yuvPlanes = yuvPlanes; this.yuvFrame = true; - this.rotationDegree = rotationDegree; } /** * Construct a texture frame of the given dimensions with data in SurfaceTexture */ public I420Frame( - int width, int height, int rotationDegree, - Object textureObject, int textureId) { + int width, int height, Object textureObject, int textureId) { this.width = width; this.height = height; this.yuvStrides = null; @@ -86,7 +79,6 @@ public class VideoRenderer { this.textureObject = textureObject; this.textureId = textureId; this.yuvFrame = false; - this.rotationDegree = rotationDegree; } /** @@ -106,12 +98,10 @@ public class VideoRenderer { source.yuvStrides[1], yuvPlanes[1], yuvStrides[1]); nativeCopyPlane(source.yuvPlanes[2], width / 2, height / 2, source.yuvStrides[2], yuvPlanes[2], yuvStrides[2]); - rotationDegree = source.rotationDegree; return this; } else if (!source.yuvFrame && !yuvFrame) { textureObject = source.textureObject; textureId = source.textureId; - rotationDegree = source.rotationDegree; return this; } else { throw new RuntimeException("Mismatched frame types! Source: " + @@ -119,7 +109,7 @@ public class VideoRenderer { } } - public I420Frame copyFrom(byte[] yuvData, int rotationDegree) { + public I420Frame copyFrom(byte[] yuvData) { if (yuvData.length < width * height * 3 / 2) { throw new RuntimeException("Wrong arrays size: " + yuvData.length); } @@ -138,7 +128,6 @@ public class VideoRenderer { yuvPlanes[i].position(0); yuvPlanes[i].limit(yuvPlanes[i].capacity()); } - this.rotationDegree = rotationDegree; return this; } @@ -158,8 +147,6 @@ public class VideoRenderer { // |frame| might have pending rotation and implementation of Callbacks // should handle that by applying rotation during rendering. public void renderFrame(I420Frame frame); - // TODO(guoweis): Remove this once chrome code base is updated. - public boolean canApplyRotation(); } // |this| either wraps a native (GUI) renderer or a client-supplied Callbacks diff --git a/talk/app/webrtc/java/testcommon/src/org/webrtc/PeerConnectionTest.java b/talk/app/webrtc/java/testcommon/src/org/webrtc/PeerConnectionTest.java index 224225cdc7..81100b2433 100644 --- a/talk/app/webrtc/java/testcommon/src/org/webrtc/PeerConnectionTest.java +++ b/talk/app/webrtc/java/testcommon/src/org/webrtc/PeerConnectionTest.java @@ -138,12 +138,6 @@ public class PeerConnectionTest { --expectedFramesDelivered; } - // TODO(guoweis): Remove this once chrome code base is updated. - @Override - public boolean canApplyRotation() { - return false; - } - public synchronized void expectSignalingChange(SignalingState newState) { expectedSignalingChanges.add(newState); } @@ -444,12 +438,6 @@ public class PeerConnectionTest { public void renderFrame(VideoRenderer.I420Frame frame) { ++numFramesDelivered; } - - // TODO(guoweis): Remove this once chrome code base is updated. - @Override - public boolean canApplyRotation() { - return false; - } } private static VideoRenderer createVideoRenderer( diff --git a/talk/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java b/talk/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java index f7dadbaefc..55e8bdf125 100644 --- a/talk/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java +++ b/talk/examples/androidtests/src/org/appspot/apprtc/test/PeerConnectionClientTest.java @@ -101,12 +101,6 @@ public class PeerConnectionClientTest extends InstrumentationTestCase doneRendering = new CountDownLatch(expectedFrames); } - // TODO(guoweis): Remove this once chrome code base is updated. - @Override - public boolean canApplyRotation() { - return false; - } - @Override public synchronized void renderFrame(VideoRenderer.I420Frame frame) { if (!renderFrameCalled) {