Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 const float ROTATE_90[16] = | |
| 40 {0.0, 1.0, 0.0, 0.0, | |
| 41 -1.0, 0.0, 0.0, 0.0, | |
| 42 0.0, 0.0, 1.0, 0.0, | |
| 43 1.0, 0.0 , 0.0, 1.0}; | |
| 44 const float ROTATE_180[16] = | |
| 45 {-1.0, 0.0, 0.0, 0.0, | |
| 46 0.0, -1.0, 0.0, 0.0, | |
| 47 0.0, 0.0, 1.0, 0.0, | |
| 48 1.0, 1.0, 0.0, 1.0}; | |
| 49 const float ROTATE_270[16] = | |
| 50 {0.0, -1.0, 0.0, 0.0, | |
| 51 1.0, 0.0, 0.0, 0.0, | |
| 52 0.0, 0.0, 1.0, 0.0, | |
| 53 0.0, 1.0, 0.0, 1.0}; | |
| 54 | |
| 55 void InPlaceMultiplyMatrix(float a[16], const float b[16]) { | |
|
nisse-chromium (ooo August 14)
2015/12/08 08:46:34
Please explain operation. Is it A <-- A * B or A <
perkj_chrome
2015/12/09 21:00:40
not relevant now?
| |
| 56 float ab[16]; | |
| 57 int ab_ofs = 0; | |
| 58 int b_ofs = 0; | |
| 59 for (int i = 0; i < 4; i++) { | |
| 60 ab[ab_ofs + 0] = | |
| 61 (b[b_ofs + 0] * a[0]) + | |
| 62 (b[b_ofs + 1] * a[4]) + | |
| 63 (b[b_ofs + 2] * a[8]) + | |
| 64 (b[b_ofs + 3] * a[12]) ; | |
| 65 | |
| 66 ab[ab_ofs + 1] = | |
| 67 (b[b_ofs + 0] * a[1]) + | |
| 68 (b[b_ofs + 1] * a[5]) + | |
| 69 (b[b_ofs + 2] * a[9]) + | |
| 70 (b[b_ofs + 3] * a[13]) ; | |
| 71 | |
| 72 ab[ab_ofs + 2] = | |
| 73 (b[b_ofs + 0] * a[2]) + | |
| 74 (b[b_ofs + 1] * a[6]) + | |
| 75 (b[b_ofs + 2] * a[10]) + | |
| 76 (b[b_ofs + 3] * a[14]) ; | |
| 77 | |
| 78 ab[ab_ofs + 3] = | |
| 79 (b[b_ofs + 0] * a[3]) + | |
| 80 (b[b_ofs + 1] * a[7]) + | |
| 81 (b[b_ofs + 2] * a[11]) + | |
| 82 (b[b_ofs + 3] * a[15]) ; | |
| 83 ab_ofs += 4; | |
|
nisse-chromium (ooo August 14)
2015/12/08 08:46:34
Move these updates up to the for(;;...). Maybe ren
perkj_chrome
2015/12/09 21:00:40
Acknowledged.
| |
| 84 b_ofs += 4; | |
| 85 } | |
| 86 | |
| 87 memcpy(static_cast<void*>(a), static_cast<const void*>(ab), | |
| 88 16*sizeof(float)); | |
|
nisse-chromium (ooo August 14)
2015/12/08 08:46:34
Replace the size expression with sizeof(ab). (Unfo
perkj_chrome
2015/12/09 21:00:40
Done.
| |
| 89 } | |
| 90 | |
| 91 } // anonymouse namespace | |
| 92 | |
| 36 namespace webrtc_jni { | 93 namespace webrtc_jni { |
| 37 | 94 |
| 38 NativeHandleImpl::NativeHandleImpl(JNIEnv* jni, | 95 NativeHandleImpl::NativeHandleImpl(JNIEnv* jni, |
| 39 jint j_oes_texture_id, | 96 jint j_oes_texture_id, |
| 40 jfloatArray j_transform_matrix) | 97 jfloatArray j_transform_matrix) |
| 41 : oes_texture_id(j_oes_texture_id) { | 98 : oes_texture_id(j_oes_texture_id) { |
| 42 RTC_CHECK_EQ(16, jni->GetArrayLength(j_transform_matrix)); | 99 RTC_CHECK_EQ(16, jni->GetArrayLength(j_transform_matrix)); |
| 43 jfloat* transform_matrix_ptr = | 100 jfloat* transform_matrix_ptr = |
| 44 jni->GetFloatArrayElements(j_transform_matrix, nullptr); | 101 jni->GetFloatArrayElements(j_transform_matrix, nullptr); |
| 45 for (int i = 0; i < 16; ++i) { | 102 for (int i = 0; i < 16; ++i) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 61 no_longer_used_cb_(); | 118 no_longer_used_cb_(); |
| 62 } | 119 } |
| 63 | 120 |
| 64 rtc::scoped_refptr<webrtc::VideoFrameBuffer> | 121 rtc::scoped_refptr<webrtc::VideoFrameBuffer> |
| 65 AndroidTextureBuffer::NativeToI420Buffer() { | 122 AndroidTextureBuffer::NativeToI420Buffer() { |
| 66 RTC_NOTREACHED() | 123 RTC_NOTREACHED() |
| 67 << "AndroidTextureBuffer::NativeToI420Buffer not implemented."; | 124 << "AndroidTextureBuffer::NativeToI420Buffer not implemented."; |
| 68 return nullptr; | 125 return nullptr; |
| 69 } | 126 } |
| 70 | 127 |
| 71 rtc::scoped_refptr<AndroidTextureBuffer> AndroidTextureBuffer::CropAndScale( | 128 rtc::scoped_refptr<AndroidTextureBuffer> |
| 72 int cropped_input_width, | 129 AndroidTextureBuffer::CropScaleAndRotate(int cropped_input_width, |
|
nisse-chromium (ooo August 14)
2015/12/08 08:46:34
Maybe we could come up with a better name. Transfo
perkj_chrome
2015/12/09 21:00:40
If you don't object too much I will call this Scal
nisse-chromium (ooo August 14)
2015/12/10 09:04:57
Good enough.
| |
| 73 int cropped_input_height, | 130 int cropped_input_height, |
| 74 int dst_widht, | 131 int dst_widht, |
| 75 int dst_height) { | 132 int dst_height, |
| 133 webrtc::VideoRotation rotation) { | |
| 76 // TODO(perkj) Implement cropping. | 134 // TODO(perkj) Implement cropping. |
| 77 RTC_CHECK_EQ(cropped_input_width, width_); | 135 RTC_CHECK_EQ(cropped_input_width, width_); |
| 78 RTC_CHECK_EQ(cropped_input_height, height_); | 136 RTC_CHECK_EQ(cropped_input_height, height_); |
| 137 if (width() == dst_widht && height() == dst_height && | |
| 138 rotation == webrtc::kVideoRotation_0) { | |
| 139 return this; | |
| 140 } | |
| 79 | 141 |
| 80 // Here we use Bind magic to add a reference count to |this| until the newly | 142 int rotated_width = (rotation % 180 == 0) ? dst_widht : dst_height; |
| 81 // created AndroidTextureBuffer is destructed. ScaledFrameNotInUse will be | 143 int rotated_height = (rotation % 180 == 0) ? dst_height : dst_widht; |
| 82 // called that happens and when it finishes, the reference count to |this| | 144 |
|
nisse-chromium (ooo August 14)
2015/12/08 08:46:34
Keep this comment, if it is still relevant?
perkj_chrome
2015/12/09 21:00:40
Done.
| |
| 83 // will be decreased by one. | 145 rtc::scoped_refptr<AndroidTextureBuffer> buffer( |
| 84 return new rtc::RefCountedObject<AndroidTextureBuffer>( | 146 new rtc::RefCountedObject<AndroidTextureBuffer>( |
| 85 dst_widht, dst_height, native_handle_, | 147 rotated_width, rotated_height, native_handle_, |
| 86 rtc::KeepRefUntilDone(this)); | 148 rtc::KeepRefUntilDone(this))); |
| 149 | |
| 150 switch (rotation) { | |
| 151 case webrtc::kVideoRotation_0: | |
| 152 break; | |
| 153 case webrtc::kVideoRotation_90: | |
| 154 InPlaceMultiplyMatrix(buffer->native_handle_.sampling_matrix, ROTATE_90); | |
| 155 break; | |
| 156 case webrtc::kVideoRotation_180: | |
| 157 InPlaceMultiplyMatrix(buffer->native_handle_.sampling_matrix, | |
| 158 ROTATE_180); | |
| 159 break; | |
| 160 case webrtc::kVideoRotation_270: | |
| 161 InPlaceMultiplyMatrix(buffer->native_handle_.sampling_matrix, | |
| 162 ROTATE_270); | |
| 163 break; | |
| 164 } | |
| 165 | |
| 166 return buffer; | |
| 87 } | 167 } |
| 88 | 168 |
| 89 } // namespace webrtc_jni | 169 } // namespace webrtc_jni |
| OLD | NEW |