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

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: Rebased 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 15 matching lines...) Expand all
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 "talk/app/webrtc/java/jni/jni_helpers.h" 30 #include "talk/app/webrtc/java/jni/jni_helpers.h"
31 #include "webrtc/base/bind.h" 31 #include "webrtc/base/bind.h"
32 #include "webrtc/base/checks.h" 32 #include "webrtc/base/checks.h"
33 #include "webrtc/base/keep_ref_until_done.h" 33 #include "webrtc/base/keep_ref_until_done.h"
34 #include "webrtc/base/scoped_ptr.h" 34 #include "webrtc/base/scoped_ptr.h"
35 #include "webrtc/base/scoped_ref_ptr.h" 35 #include "webrtc/base/scoped_ref_ptr.h"
36 #include "webrtc/base/logging.h"
36 37
37 using webrtc::NativeHandleBuffer; 38 using webrtc::NativeHandleBuffer;
38 39
40 namespace {
41
42 void RotateMatrix(float a[16], webrtc::VideoRotation rotation) {
43 // Texture coordinates are in the range 0 to 1. The transformation of the last
44 // row in each rotation matrix is needed for proper translation, e.g, to
45 // mirror x, we don't replace x by -x, but by 1-x.
46 switch (rotation) {
47 case webrtc::kVideoRotation_0:
48 break;
49 case webrtc::kVideoRotation_90: {
50 const float ROTATE_90[16] =
51 { a[4], a[5], a[6], a[7],
52 -a[0], -a[1], -a[2], -a[3],
53 a[8], a[9], a[10], a[11],
54 a[0] + a[12], a[1] + a[13], a[2] + a[14], a[3] + a[15]};
55 memcpy(a, ROTATE_90, sizeof(ROTATE_90));
56 } break;
57 case webrtc::kVideoRotation_180: {
58 const float ROTATE_180[16] =
59 { -a[0], -a[1], -a[2], -a[3],
60 -a[4], -a[5], -a[6], -a[7],
61 a[8], a[9], a[10], a[11],
62 a[0] + a[4] + a[12], a[1] +a[5] + a[13], a[2] + a[6] + a[14],
63 a[3] + a[11]+ a[15]};
64 memcpy(a, ROTATE_180, sizeof(ROTATE_180));
65 }
66 break;
67 case webrtc::kVideoRotation_270: {
68 const float ROTATE_270[16] =
69 { -a[4], -a[5], -a[6], -a[7],
70 a[0], a[1], a[2], a[3],
71 a[8], a[9], a[10], a[11],
72 a[4] + a[12], a[5] + a[13], a[6] + a[14], a[7] + a[15]};
73 memcpy(a, ROTATE_270, sizeof(ROTATE_270));
74 } break;
75 }
76 }
77
78 } // anonymouse namespace
79
39 namespace webrtc_jni { 80 namespace webrtc_jni {
40 81
41 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. 82 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
42 static const int kBufferAlignment = 64; 83 static const int kBufferAlignment = 64;
43 84
44 NativeHandleImpl::NativeHandleImpl(JNIEnv* jni, 85 NativeHandleImpl::NativeHandleImpl(JNIEnv* jni,
45 jint j_oes_texture_id, 86 jint j_oes_texture_id,
46 jfloatArray j_transform_matrix) 87 jfloatArray j_transform_matrix)
47 : oes_texture_id(j_oes_texture_id) { 88 : oes_texture_id(j_oes_texture_id) {
48 RTC_CHECK_EQ(16, jni->GetArrayLength(j_transform_matrix)); 89 RTC_CHECK_EQ(16, jni->GetArrayLength(j_transform_matrix));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 154
114 jni->CallVoidMethod(surface_texture_helper_, 155 jni->CallVoidMethod(surface_texture_helper_,
115 transform_mid, 156 transform_mid,
116 byte_buffer, width(), height(), stride, 157 byte_buffer, width(), height(), stride,
117 native_handle_.oes_texture_id, sampling_matrix); 158 native_handle_.oes_texture_id, sampling_matrix);
118 CHECK_EXCEPTION(jni) << "textureToYUV throwed an exception"; 159 CHECK_EXCEPTION(jni) << "textureToYUV throwed an exception";
119 160
120 return copy; 161 return copy;
121 } 162 }
122 163
123 rtc::scoped_refptr<AndroidTextureBuffer> AndroidTextureBuffer::CropAndScale( 164 rtc::scoped_refptr<AndroidTextureBuffer>
124 int cropped_input_width, 165 AndroidTextureBuffer::ScaleAndRotate(int dst_widht,
125 int cropped_input_height, 166 int dst_height,
126 int dst_widht, 167 webrtc::VideoRotation rotation) {
127 int dst_height) { 168 if (width() == dst_widht && height() == dst_height &&
128 // TODO(perkj) Implement cropping. 169 rotation == webrtc::kVideoRotation_0) {
129 RTC_CHECK_EQ(cropped_input_width, width_); 170 return this;
130 RTC_CHECK_EQ(cropped_input_height, height_); 171 }
172 int rotated_width = (rotation % 180 == 0) ? dst_widht : dst_height;
173 int rotated_height = (rotation % 180 == 0) ? dst_height : dst_widht;
131 174
132 // Here we use Bind magic to add a reference count to |this| until the newly 175 // Here we use Bind magic to add a reference count to |this| until the newly
133 // created AndroidTextureBuffer is destructed. ScaledFrameNotInUse will be 176 // created AndroidTextureBuffer is destructed
134 // called that happens and when it finishes, the reference count to |this| 177 rtc::scoped_refptr<AndroidTextureBuffer> buffer(
135 // will be decreased by one. 178 new rtc::RefCountedObject<AndroidTextureBuffer>(
136 return new rtc::RefCountedObject<AndroidTextureBuffer>( 179 rotated_width, rotated_height, native_handle_,
137 dst_widht, dst_height, native_handle_, surface_texture_helper_, 180 surface_texture_helper_, rtc::KeepRefUntilDone(this)));
138 rtc::KeepRefUntilDone(this)); 181
182 RotateMatrix(buffer->native_handle_.sampling_matrix, rotation);
183 return buffer;
139 } 184 }
140 185
141 } // namespace webrtc_jni 186 } // 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