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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 12 matching lines...) Expand all
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/java/jni/native_handle_impl.h" 28 #include "talk/app/webrtc/java/jni/native_handle_impl.h"
29 29
30 #include "webrtc/base/checks.h" 30 #include "webrtc/base/checks.h"
31 #include "webrtc/base/keep_ref_until_done.h" 31 #include "webrtc/base/keep_ref_until_done.h"
32 #include "webrtc/base/scoped_ref_ptr.h" 32 #include "webrtc/base/scoped_ref_ptr.h"
33 #include "webrtc/base/logging.h"
33 34
34 using webrtc::NativeHandleBuffer; 35 using webrtc::NativeHandleBuffer;
35 36
37 namespace {
38
39 void RotateMatrix(float a[16], webrtc::VideoRotation rotation) {
40 switch (rotation) {
41 case webrtc::kVideoRotation_0:
42 break;
43 case webrtc::kVideoRotation_90: {
44 const float ROTATE_90[16] =
45 { a[4], a[5], a[6], a[7],
46 -a[0], -a[1], -a[2], -a[3],
47 a[8], a[9], a[10], a[11],
48 a[0] + a[12], a[1] + a[13], a[2] + a[14], a[3] + a[15]};
49 memcpy(a, ROTATE_90, sizeof(ROTATE_90));
50 } break;
51 case webrtc::kVideoRotation_180: {
52 const float ROTATE_180[16] =
53 { -a[0], -a[1], -a[2], -a[3],
54 -a[4], -a[5], -a[6], -a[7],
55 a[8], a[9], a[10], a[11],
56 a[0] + a[4] + a[12], a[1] +a[5] + a[13], a[2] + a[6] + a[14],
57 a[3] + a[11]+ a[15]};
58 memcpy(a, ROTATE_180, sizeof(ROTATE_180));
59 }
60 break;
61 case webrtc::kVideoRotation_270: {
62 const float ROTATE_270[16] =
63 { -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.
64 a[0], a[1], a[2], a[3],
65 a[8], a[9], a[10], a[11],
66 a[4] + a[12], a[5] + a[13], a[6] + a[14], a[7] + a[15]};
67 memcpy(a, ROTATE_270, sizeof(ROTATE_270));
68 } break;
69 }
70 }
71
72 } // anonymouse namespace
73
36 namespace webrtc_jni { 74 namespace webrtc_jni {
37 75
38 NativeHandleImpl::NativeHandleImpl(JNIEnv* jni, 76 NativeHandleImpl::NativeHandleImpl(JNIEnv* jni,
39 jint j_oes_texture_id, 77 jint j_oes_texture_id,
40 jfloatArray j_transform_matrix) 78 jfloatArray j_transform_matrix)
41 : oes_texture_id(j_oes_texture_id) { 79 : oes_texture_id(j_oes_texture_id) {
42 RTC_CHECK_EQ(16, jni->GetArrayLength(j_transform_matrix)); 80 RTC_CHECK_EQ(16, jni->GetArrayLength(j_transform_matrix));
43 jfloat* transform_matrix_ptr = 81 jfloat* transform_matrix_ptr =
44 jni->GetFloatArrayElements(j_transform_matrix, nullptr); 82 jni->GetFloatArrayElements(j_transform_matrix, nullptr);
45 for (int i = 0; i < 16; ++i) { 83 for (int i = 0; i < 16; ++i) {
(...skipping 15 matching lines...) Expand all
61 no_longer_used_cb_(); 99 no_longer_used_cb_();
62 } 100 }
63 101
64 rtc::scoped_refptr<webrtc::VideoFrameBuffer> 102 rtc::scoped_refptr<webrtc::VideoFrameBuffer>
65 AndroidTextureBuffer::NativeToI420Buffer() { 103 AndroidTextureBuffer::NativeToI420Buffer() {
66 RTC_NOTREACHED() 104 RTC_NOTREACHED()
67 << "AndroidTextureBuffer::NativeToI420Buffer not implemented."; 105 << "AndroidTextureBuffer::NativeToI420Buffer not implemented.";
68 return nullptr; 106 return nullptr;
69 } 107 }
70 108
71 rtc::scoped_refptr<AndroidTextureBuffer> AndroidTextureBuffer::CropAndScale( 109 rtc::scoped_refptr<AndroidTextureBuffer>
72 int cropped_input_width, 110 AndroidTextureBuffer::ScaleAndRotate(int dst_widht,
73 int cropped_input_height, 111 int dst_height,
74 int dst_widht, 112 webrtc::VideoRotation rotation) {
75 int dst_height) { 113 if (width() == dst_widht && height() == dst_height &&
76 // TODO(perkj) Implement cropping. 114 rotation == webrtc::kVideoRotation_0) {
77 RTC_CHECK_EQ(cropped_input_width, width_); 115 return this;
78 RTC_CHECK_EQ(cropped_input_height, height_); 116 }
117 int rotated_width = (rotation % 180 == 0) ? dst_widht : dst_height;
118 int rotated_height = (rotation % 180 == 0) ? dst_height : dst_widht;
79 119
80 // Here we use Bind magic to add a reference count to |this| until the newly 120 // Here we use Bind magic to add a reference count to |this| until the newly
81 // created AndroidTextureBuffer is destructed. ScaledFrameNotInUse will be 121 // created AndroidTextureBuffer is destructed
82 // called that happens and when it finishes, the reference count to |this| 122 rtc::scoped_refptr<AndroidTextureBuffer> buffer(
83 // will be decreased by one. 123 new rtc::RefCountedObject<AndroidTextureBuffer>(
84 return new rtc::RefCountedObject<AndroidTextureBuffer>( 124 rotated_width, rotated_height, native_handle_,
85 dst_widht, dst_height, native_handle_, 125 rtc::KeepRefUntilDone(this)));
86 rtc::KeepRefUntilDone(this)); 126
127 RotateMatrix(buffer->native_handle_.sampling_matrix, rotation);
128 return buffer;
87 } 129 }
88 130
89 } // namespace webrtc_jni 131 } // namespace webrtc_jni
OLDNEW
« 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