Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 // impossible to tell which JNI call broke). | 36 // impossible to tell which JNI call broke). |
| 37 | 37 |
| 38 #include <jni.h> | 38 #include <jni.h> |
| 39 #undef JNIEXPORT | 39 #undef JNIEXPORT |
| 40 #define JNIEXPORT __attribute__((visibility("default"))) | 40 #define JNIEXPORT __attribute__((visibility("default"))) |
| 41 | 41 |
| 42 #include <limits> | 42 #include <limits> |
| 43 #include <memory> | 43 #include <memory> |
| 44 #include <utility> | 44 #include <utility> |
| 45 | 45 |
| 46 #include "third_party/libyuv/include/libyuv/scale.h" | |
| 46 #include "webrtc/api/androidvideotracksource.h" | 47 #include "webrtc/api/androidvideotracksource.h" |
| 47 #include "webrtc/api/android/jni/androidmediadecoder_jni.h" | 48 #include "webrtc/api/android/jni/androidmediadecoder_jni.h" |
| 48 #include "webrtc/api/android/jni/androidmediaencoder_jni.h" | 49 #include "webrtc/api/android/jni/androidmediaencoder_jni.h" |
| 49 #include "webrtc/api/android/jni/androidnetworkmonitor_jni.h" | 50 #include "webrtc/api/android/jni/androidnetworkmonitor_jni.h" |
| 50 #include "webrtc/api/android/jni/classreferenceholder.h" | 51 #include "webrtc/api/android/jni/classreferenceholder.h" |
| 51 #include "webrtc/api/android/jni/jni_helpers.h" | 52 #include "webrtc/api/android/jni/jni_helpers.h" |
| 52 #include "webrtc/api/android/jni/native_handle_impl.h" | 53 #include "webrtc/api/android/jni/native_handle_impl.h" |
| 53 #include "webrtc/api/mediaconstraintsinterface.h" | 54 #include "webrtc/api/mediaconstraintsinterface.h" |
| 54 #include "webrtc/api/peerconnectioninterface.h" | 55 #include "webrtc/api/peerconnectioninterface.h" |
| 55 #include "webrtc/api/rtpreceiverinterface.h" | 56 #include "webrtc/api/rtpreceiverinterface.h" |
| (...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1996 memcpy(dst, src, src_stride * height); | 1997 memcpy(dst, src, src_stride * height); |
| 1997 } else { | 1998 } else { |
| 1998 for (int i = 0; i < height; i++) { | 1999 for (int i = 0; i < height; i++) { |
| 1999 memcpy(dst, src, width); | 2000 memcpy(dst, src, width); |
| 2000 src += src_stride; | 2001 src += src_stride; |
| 2001 dst += dst_stride; | 2002 dst += dst_stride; |
| 2002 } | 2003 } |
| 2003 } | 2004 } |
| 2004 } | 2005 } |
| 2005 | 2006 |
| 2007 JOW(void, FileVideoCapturer_nativeI420ToNV21)( | |
| 2008 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, | |
| 2009 jbyteArray j_dst_buffer) { | |
| 2010 //size_t src_size = jni->GetDirectBufferCapacity(j_src_buffer); | |
|
magjed_webrtc
2016/09/26 11:40:02
Clean up and remove unused code.
mandermo
2016/10/04 14:56:57
Done.
| |
| 2011 //size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); | |
| 2012 size_t src_size = jni->GetArrayLength(j_src_buffer); | |
| 2013 size_t dst_size = jni->GetArrayLength(j_dst_buffer); | |
| 2014 int src_stride = width; | |
| 2015 int dst_stride = width; | |
| 2016 RTC_CHECK(src_size >= src_stride * height * 3 / 2) | |
| 2017 << "Insufficient source buffer capacity " << src_size; | |
| 2018 RTC_CHECK(dst_size >= dst_stride * height * 3 / 2) | |
| 2019 << "Insufficient destination buffer capacity " << dst_size; | |
| 2020 //uint8_t *src = | |
| 2021 // reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer)); | |
| 2022 //uint8_t *dst = | |
| 2023 // reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); | |
| 2024 uint8_t *src = | |
| 2025 reinterpret_cast<uint8_t*>(jni->GetByteArrayElements(j_src_buffer, 0)); | |
| 2026 uint8_t *dst = | |
| 2027 reinterpret_cast<uint8_t*>(jni->GetByteArrayElements(j_dst_buffer, 0)); | |
| 2028 uint8_t *src_y = src; | |
| 2029 size_t src_stride_y = src_stride; | |
| 2030 uint8_t *src_u = src + src_stride * height; | |
| 2031 size_t src_stride_u = src_stride / 2; | |
| 2032 uint8_t *src_v = src + src_stride * height * 5/4; | |
| 2033 size_t src_stride_v = src_stride / 2; | |
| 2034 | |
| 2035 uint8_t *dst_y = dst; | |
| 2036 size_t dst_stride_y = dst_stride; | |
| 2037 size_t dst_stride_uv = dst_stride; | |
| 2038 uint8_t *dst_uv = dst + dst_stride * height; | |
| 2039 | |
| 2040 libyuv::I420ToNV21(src_y, src_stride_y, | |
| 2041 src_u, src_stride_u, | |
| 2042 src_v, src_stride_v, | |
| 2043 dst_y, dst_stride_y, | |
| 2044 dst_uv, dst_stride_uv, | |
| 2045 width, height); | |
| 2046 } | |
| 2047 | |
| 2048 JOW(void, GlVideoFileRenderer_nativeI420Scale)( | |
| 2049 JNIEnv *jni, jclass, | |
| 2050 jobject j_src_buffer_y, jint j_src_stride_y, | |
|
sakal
2016/09/27 07:54:28
These are also jbyteArrays, right? Can you use the
mandermo
2016/10/04 14:56:57
It is ByteBuffers not byte[].
| |
| 2051 jobject j_src_buffer_u, jint j_src_stride_u, | |
| 2052 jobject j_src_buffer_v, jint j_src_stride_v, | |
| 2053 jint width, jint height, | |
| 2054 jbyteArray j_dst_buffer, jint dstWidth, jint dstHeight) { | |
| 2055 size_t src_size_y = jni->GetDirectBufferCapacity(j_src_buffer_y); | |
| 2056 size_t src_size_u = jni->GetDirectBufferCapacity(j_src_buffer_u); | |
| 2057 size_t src_size_v = jni->GetDirectBufferCapacity(j_src_buffer_v); | |
| 2058 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); | |
| 2059 int dst_stride = dstWidth; | |
| 2060 RTC_CHECK(src_size_y >= j_src_stride_y * height) | |
| 2061 << "Insufficient source y buffer capacity " << src_size_y; | |
| 2062 RTC_CHECK(src_size_u >= j_src_stride_u * height / 4) | |
| 2063 << "Insufficient source u buffer capacity " << src_size_u; | |
| 2064 RTC_CHECK(src_size_v >= j_src_stride_v * height / 4) | |
| 2065 << "Insufficient source v buffer capacity " << src_size_v; | |
| 2066 RTC_CHECK(dst_size >= dst_stride * height * 3 / 2) | |
| 2067 << "Insufficient destination buffer capacity " << dst_size; | |
| 2068 uint8_t *src_y = | |
| 2069 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer_y)); | |
| 2070 uint8_t *src_u = | |
| 2071 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer_u)); | |
| 2072 uint8_t *src_v = | |
| 2073 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer_v)); | |
| 2074 uint8_t *dst = | |
| 2075 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); | |
| 2076 | |
| 2077 uint8_t *dst_y = dst; | |
| 2078 size_t dst_stride_y = dst_stride; | |
| 2079 uint8_t *dst_u = dst + dst_stride * dstHeight; | |
| 2080 size_t dst_stride_u = dst_stride / 2; | |
| 2081 uint8_t *dst_v = dst + dst_stride * dstHeight * 5/4; | |
| 2082 size_t dst_stride_v = dst_stride / 2; | |
| 2083 | |
| 2084 int ret = libyuv::I420Scale(src_y, j_src_stride_y, | |
| 2085 src_u, j_src_stride_u, | |
| 2086 src_v, j_src_stride_v, | |
| 2087 width, height, | |
| 2088 dst_y, dst_stride_y, | |
| 2089 dst_u, dst_stride_u, | |
| 2090 dst_v, dst_stride_v, | |
| 2091 dstWidth, dstHeight, | |
| 2092 libyuv::kFilterBilinear); | |
| 2093 if (ret) { | |
| 2094 LOG(LS_ERROR) << "Error scaling I420 frame: " << ret; | |
| 2095 } | |
| 2096 } | |
| 2097 | |
| 2006 JOW(jstring, MediaStreamTrack_nativeId)(JNIEnv* jni, jclass, jlong j_p) { | 2098 JOW(jstring, MediaStreamTrack_nativeId)(JNIEnv* jni, jclass, jlong j_p) { |
| 2007 return JavaStringFromStdString( | 2099 return JavaStringFromStdString( |
| 2008 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->id()); | 2100 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->id()); |
| 2009 } | 2101 } |
| 2010 | 2102 |
| 2011 JOW(jstring, MediaStreamTrack_nativeKind)(JNIEnv* jni, jclass, jlong j_p) { | 2103 JOW(jstring, MediaStreamTrack_nativeKind)(JNIEnv* jni, jclass, jlong j_p) { |
| 2012 return JavaStringFromStdString( | 2104 return JavaStringFromStdString( |
| 2013 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->kind()); | 2105 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->kind()); |
| 2014 } | 2106 } |
| 2015 | 2107 |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2318 return JavaStringFromStdString( | 2410 return JavaStringFromStdString( |
| 2319 jni, | 2411 jni, |
| 2320 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2412 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
| 2321 } | 2413 } |
| 2322 | 2414 |
| 2323 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2415 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
| 2324 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2416 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
| 2325 } | 2417 } |
| 2326 | 2418 |
| 2327 } // namespace webrtc_jni | 2419 } // namespace webrtc_jni |
| OLD | NEW |