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/convert_from.h" | |
47 #include "third_party/libyuv/include/libyuv/scale.h" | |
48 #include "webrtc/api/androidvideotracksource.h" | 46 #include "webrtc/api/androidvideotracksource.h" |
49 #include "webrtc/api/android/jni/androidmediadecoder_jni.h" | 47 #include "webrtc/api/android/jni/androidmediadecoder_jni.h" |
50 #include "webrtc/api/android/jni/androidmediaencoder_jni.h" | 48 #include "webrtc/api/android/jni/androidmediaencoder_jni.h" |
51 #include "webrtc/api/android/jni/androidnetworkmonitor_jni.h" | 49 #include "webrtc/api/android/jni/androidnetworkmonitor_jni.h" |
52 #include "webrtc/api/android/jni/classreferenceholder.h" | 50 #include "webrtc/api/android/jni/classreferenceholder.h" |
53 #include "webrtc/api/android/jni/jni_helpers.h" | 51 #include "webrtc/api/android/jni/jni_helpers.h" |
54 #include "webrtc/api/android/jni/native_handle_impl.h" | 52 #include "webrtc/api/android/jni/native_handle_impl.h" |
55 #include "webrtc/api/mediaconstraintsinterface.h" | 53 #include "webrtc/api/mediaconstraintsinterface.h" |
56 #include "webrtc/api/peerconnectioninterface.h" | 54 #include "webrtc/api/peerconnectioninterface.h" |
57 #include "webrtc/api/rtpreceiverinterface.h" | 55 #include "webrtc/api/rtpreceiverinterface.h" |
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1998 memcpy(dst, src, src_stride * height); | 1996 memcpy(dst, src, src_stride * height); |
1999 } else { | 1997 } else { |
2000 for (int i = 0; i < height; i++) { | 1998 for (int i = 0; i < height; i++) { |
2001 memcpy(dst, src, width); | 1999 memcpy(dst, src, width); |
2002 src += src_stride; | 2000 src += src_stride; |
2003 dst += dst_stride; | 2001 dst += dst_stride; |
2004 } | 2002 } |
2005 } | 2003 } |
2006 } | 2004 } |
2007 | 2005 |
2008 JOW(void, FileVideoCapturer_nativeI420ToNV21)( | |
2009 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, | |
2010 jbyteArray j_dst_buffer) { | |
2011 size_t src_size = jni->GetArrayLength(j_src_buffer); | |
2012 size_t dst_size = jni->GetArrayLength(j_dst_buffer); | |
2013 int src_stride = width; | |
2014 int dst_stride = width; | |
2015 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); | |
2016 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); | |
2017 uint8_t* src = | |
2018 reinterpret_cast<uint8_t*>(jni->GetByteArrayElements(j_src_buffer, 0)); | |
2019 uint8_t* dst = | |
2020 reinterpret_cast<uint8_t*>(jni->GetByteArrayElements(j_dst_buffer, 0)); | |
2021 uint8_t* src_y = src; | |
2022 size_t src_stride_y = src_stride; | |
2023 uint8_t* src_u = src + src_stride * height; | |
2024 size_t src_stride_u = src_stride / 2; | |
2025 uint8_t* src_v = src + src_stride * height * 5 / 4; | |
2026 size_t src_stride_v = src_stride / 2; | |
2027 | |
2028 uint8_t* dst_y = dst; | |
2029 size_t dst_stride_y = dst_stride; | |
2030 size_t dst_stride_uv = dst_stride; | |
2031 uint8_t* dst_uv = dst + dst_stride * height; | |
2032 | |
2033 libyuv::I420ToNV21(src_y, src_stride_y, src_u, src_stride_u, src_v, | |
2034 src_stride_v, dst_y, dst_stride_y, dst_uv, dst_stride_uv, | |
2035 width, height); | |
2036 } | |
2037 | |
2038 JOW(void, VideoFileRenderer_nativeI420Scale)( | |
2039 JNIEnv *jni, jclass, | |
2040 jobject j_src_buffer_y, jint j_src_stride_y, | |
2041 jobject j_src_buffer_u, jint j_src_stride_u, | |
2042 jobject j_src_buffer_v, jint j_src_stride_v, | |
2043 jint width, jint height, | |
2044 jbyteArray j_dst_buffer, jint dstWidth, jint dstHeight) { | |
2045 size_t src_size_y = jni->GetDirectBufferCapacity(j_src_buffer_y); | |
2046 size_t src_size_u = jni->GetDirectBufferCapacity(j_src_buffer_u); | |
2047 size_t src_size_v = jni->GetDirectBufferCapacity(j_src_buffer_v); | |
2048 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); | |
2049 int dst_stride = dstWidth; | |
2050 RTC_CHECK_GE(src_size_y, j_src_stride_y * height); | |
2051 RTC_CHECK_GE(src_size_u, j_src_stride_u * height / 4); | |
2052 RTC_CHECK_GE(src_size_v, j_src_stride_v * height / 4); | |
2053 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); | |
2054 uint8_t* src_y = | |
2055 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer_y)); | |
2056 uint8_t* src_u = | |
2057 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer_u)); | |
2058 uint8_t* src_v = | |
2059 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer_v)); | |
2060 uint8_t* dst = | |
2061 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); | |
2062 | |
2063 uint8_t* dst_y = dst; | |
2064 size_t dst_stride_y = dst_stride; | |
2065 uint8_t* dst_u = dst + dst_stride * dstHeight; | |
2066 size_t dst_stride_u = dst_stride / 2; | |
2067 uint8_t* dst_v = dst + dst_stride * dstHeight * 5 / 4; | |
2068 size_t dst_stride_v = dst_stride / 2; | |
2069 | |
2070 int ret = libyuv::I420Scale( | |
2071 src_y, j_src_stride_y, src_u, j_src_stride_u, src_v, j_src_stride_v, | |
2072 width, height, dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, | |
2073 dst_stride_v, dstWidth, dstHeight, libyuv::kFilterBilinear); | |
2074 if (ret) { | |
2075 LOG(LS_ERROR) << "Error scaling I420 frame: " << ret; | |
2076 } | |
2077 } | |
2078 | |
2079 JOW(jstring, MediaStreamTrack_nativeId)(JNIEnv* jni, jclass, jlong j_p) { | 2006 JOW(jstring, MediaStreamTrack_nativeId)(JNIEnv* jni, jclass, jlong j_p) { |
2080 return JavaStringFromStdString( | 2007 return JavaStringFromStdString( |
2081 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->id()); | 2008 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->id()); |
2082 } | 2009 } |
2083 | 2010 |
2084 JOW(jstring, MediaStreamTrack_nativeKind)(JNIEnv* jni, jclass, jlong j_p) { | 2011 JOW(jstring, MediaStreamTrack_nativeKind)(JNIEnv* jni, jclass, jlong j_p) { |
2085 return JavaStringFromStdString( | 2012 return JavaStringFromStdString( |
2086 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->kind()); | 2013 jni, reinterpret_cast<MediaStreamTrackInterface*>(j_p)->kind()); |
2087 } | 2014 } |
2088 | 2015 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2392 return JavaStringFromStdString( | 2319 return JavaStringFromStdString( |
2393 jni, | 2320 jni, |
2394 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2321 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
2395 } | 2322 } |
2396 | 2323 |
2397 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2324 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
2398 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2325 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
2399 } | 2326 } |
2400 | 2327 |
2401 } // namespace webrtc_jni | 2328 } // namespace webrtc_jni |
OLD | NEW |