Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: talk/app/webrtc/java/jni/native_handle_impl.cc

Issue 1493913007: VideoCapturerAndroid, handle cvo correctly (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « talk/app/webrtc/java/jni/native_handle_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: talk/app/webrtc/java/jni/native_handle_impl.cc
diff --git a/talk/app/webrtc/java/jni/native_handle_impl.cc b/talk/app/webrtc/java/jni/native_handle_impl.cc
index 583a0380263659096660934cae8699babd5c7511..1a3a92fbe7ff2253036cb5f6b088a21eb04b4721 100644
--- a/talk/app/webrtc/java/jni/native_handle_impl.cc
+++ b/talk/app/webrtc/java/jni/native_handle_impl.cc
@@ -30,9 +30,47 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/keep_ref_until_done.h"
#include "webrtc/base/scoped_ref_ptr.h"
+#include "webrtc/base/logging.h"
using webrtc::NativeHandleBuffer;
+namespace {
+
+void RotateMatrix(float a[16], webrtc::VideoRotation rotation) {
+ switch (rotation) {
+ case webrtc::kVideoRotation_0:
+ break;
+ case webrtc::kVideoRotation_90: {
+ const float ROTATE_90[16] =
+ { a[4], a[5], a[6], a[7],
+ -a[0], -a[1], -a[2], -a[3],
+ a[8], a[9], a[10], a[11],
+ a[0] + a[12], a[1] + a[13], a[2] + a[14], a[3] + a[15]};
+ memcpy(a, ROTATE_90, sizeof(ROTATE_90));
+ } break;
+ case webrtc::kVideoRotation_180: {
+ const float ROTATE_180[16] =
+ { -a[0], -a[1], -a[2], -a[3],
+ -a[4], -a[5], -a[6], -a[7],
+ a[8], a[9], a[10], a[11],
+ a[0] + a[4] + a[12], a[1] +a[5] + a[13], a[2] + a[6] + a[14],
+ a[3] + a[11]+ a[15]};
+ memcpy(a, ROTATE_180, sizeof(ROTATE_180));
+ }
+ break;
+ case webrtc::kVideoRotation_270: {
+ const float ROTATE_270[16] =
+ { -a[4], -a[5], -a[6], -a[7],
nisse-chromium (ooo August 14) 2015/12/10 09:04:57 I was surprised by the transformation of the last
perkj_chrome 2015/12/10 13:22:07 Acknowledged.
+ a[0], a[1], a[2], a[3],
+ a[8], a[9], a[10], a[11],
+ a[4] + a[12], a[5] + a[13], a[6] + a[14], a[7] + a[15]};
+ memcpy(a, ROTATE_270, sizeof(ROTATE_270));
+ } break;
+ }
+}
+
+} // anonymouse namespace
+
namespace webrtc_jni {
NativeHandleImpl::NativeHandleImpl(JNIEnv* jni,
@@ -68,22 +106,26 @@ AndroidTextureBuffer::NativeToI420Buffer() {
return nullptr;
}
-rtc::scoped_refptr<AndroidTextureBuffer> AndroidTextureBuffer::CropAndScale(
- int cropped_input_width,
- int cropped_input_height,
- int dst_widht,
- int dst_height) {
- // TODO(perkj) Implement cropping.
- RTC_CHECK_EQ(cropped_input_width, width_);
- RTC_CHECK_EQ(cropped_input_height, height_);
+rtc::scoped_refptr<AndroidTextureBuffer>
+AndroidTextureBuffer::ScaleAndRotate(int dst_widht,
+ int dst_height,
+ webrtc::VideoRotation rotation) {
+ if (width() == dst_widht && height() == dst_height &&
+ rotation == webrtc::kVideoRotation_0) {
+ return this;
+ }
+ int rotated_width = (rotation % 180 == 0) ? dst_widht : dst_height;
+ int rotated_height = (rotation % 180 == 0) ? dst_height : dst_widht;
// Here we use Bind magic to add a reference count to |this| until the newly
- // created AndroidTextureBuffer is destructed. ScaledFrameNotInUse will be
- // called that happens and when it finishes, the reference count to |this|
- // will be decreased by one.
- return new rtc::RefCountedObject<AndroidTextureBuffer>(
- dst_widht, dst_height, native_handle_,
- rtc::KeepRefUntilDone(this));
+ // created AndroidTextureBuffer is destructed
+ rtc::scoped_refptr<AndroidTextureBuffer> buffer(
+ new rtc::RefCountedObject<AndroidTextureBuffer>(
+ rotated_width, rotated_height, native_handle_,
+ rtc::KeepRefUntilDone(this)));
+
+ RotateMatrix(buffer->native_handle_.sampling_matrix, rotation);
+ return buffer;
}
} // namespace webrtc_jni
« no previous file with comments | « talk/app/webrtc/java/jni/native_handle_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698