OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
11 #include "webrtc/api/video/video_rotation.h" | 11 #include "webrtc/api/video/video_rotation.h" |
12 #include "webrtc/api/videosourceproxy.h" | 12 #include "webrtc/api/videosourceproxy.h" |
13 #include "webrtc/rtc_base/logging.h" | 13 #include "webrtc/rtc_base/logging.h" |
14 #include "webrtc/sdk/android/src/jni/androidvideotracksource.h" | 14 #include "webrtc/sdk/android/src/jni/androidvideotracksource.h" |
15 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" | 15 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" |
16 | 16 |
17 static webrtc::VideoRotation jintToVideoRotation(jint rotation) { | 17 namespace webrtc { |
| 18 |
| 19 namespace { |
| 20 |
| 21 static VideoRotation jintToVideoRotation(jint rotation) { |
18 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || | 22 RTC_DCHECK(rotation == 0 || rotation == 90 || rotation == 180 || |
19 rotation == 270); | 23 rotation == 270); |
20 return static_cast<webrtc::VideoRotation>(rotation); | 24 return static_cast<VideoRotation>(rotation); |
21 } | 25 } |
22 | 26 |
23 namespace webrtc_jni { | 27 } // namespace |
24 | 28 |
25 static webrtc::AndroidVideoTrackSource* AndroidVideoTrackSourceFromJavaProxy( | 29 namespace jni { |
| 30 |
| 31 static AndroidVideoTrackSource* AndroidVideoTrackSourceFromJavaProxy( |
26 jlong j_proxy) { | 32 jlong j_proxy) { |
27 auto proxy_source = reinterpret_cast<webrtc::VideoTrackSourceProxy*>(j_proxy); | 33 auto proxy_source = reinterpret_cast<VideoTrackSourceProxy*>(j_proxy); |
28 return reinterpret_cast<webrtc::AndroidVideoTrackSource*>( | 34 return reinterpret_cast<AndroidVideoTrackSource*>(proxy_source->internal()); |
29 proxy_source->internal()); | |
30 } | 35 } |
31 | 36 |
32 JNI_FUNCTION_DECLARATION( | 37 JNI_FUNCTION_DECLARATION( |
33 void, | 38 void, |
34 AndroidVideoTrackSourceObserver_nativeOnByteBufferFrameCaptured, | 39 AndroidVideoTrackSourceObserver_nativeOnByteBufferFrameCaptured, |
35 JNIEnv* jni, | 40 JNIEnv* jni, |
36 jclass, | 41 jclass, |
37 jlong j_source, | 42 jlong j_source, |
38 jbyteArray j_frame, | 43 jbyteArray j_frame, |
39 jint length, | 44 jint length, |
40 jint width, | 45 jint width, |
41 jint height, | 46 jint height, |
42 jint rotation, | 47 jint rotation, |
43 jlong timestamp) { | 48 jlong timestamp) { |
44 webrtc::AndroidVideoTrackSource* source = | 49 AndroidVideoTrackSource* source = |
45 AndroidVideoTrackSourceFromJavaProxy(j_source); | 50 AndroidVideoTrackSourceFromJavaProxy(j_source); |
46 jbyte* bytes = jni->GetByteArrayElements(j_frame, nullptr); | 51 jbyte* bytes = jni->GetByteArrayElements(j_frame, nullptr); |
47 source->OnByteBufferFrameCaptured(bytes, length, width, height, | 52 source->OnByteBufferFrameCaptured(bytes, length, width, height, |
48 jintToVideoRotation(rotation), timestamp); | 53 jintToVideoRotation(rotation), timestamp); |
49 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); | 54 jni->ReleaseByteArrayElements(j_frame, bytes, JNI_ABORT); |
50 } | 55 } |
51 | 56 |
52 JNI_FUNCTION_DECLARATION( | 57 JNI_FUNCTION_DECLARATION( |
53 void, | 58 void, |
54 AndroidVideoTrackSourceObserver_nativeOnTextureFrameCaptured, | 59 AndroidVideoTrackSourceObserver_nativeOnTextureFrameCaptured, |
55 JNIEnv* jni, | 60 JNIEnv* jni, |
56 jclass, | 61 jclass, |
57 jlong j_source, | 62 jlong j_source, |
58 jint j_width, | 63 jint j_width, |
59 jint j_height, | 64 jint j_height, |
60 jint j_oes_texture_id, | 65 jint j_oes_texture_id, |
61 jfloatArray j_transform_matrix, | 66 jfloatArray j_transform_matrix, |
62 jint j_rotation, | 67 jint j_rotation, |
63 jlong j_timestamp) { | 68 jlong j_timestamp) { |
64 webrtc::AndroidVideoTrackSource* source = | 69 AndroidVideoTrackSource* source = |
65 AndroidVideoTrackSourceFromJavaProxy(j_source); | 70 AndroidVideoTrackSourceFromJavaProxy(j_source); |
66 source->OnTextureFrameCaptured( | 71 source->OnTextureFrameCaptured( |
67 j_width, j_height, jintToVideoRotation(j_rotation), j_timestamp, | 72 j_width, j_height, jintToVideoRotation(j_rotation), j_timestamp, |
68 NativeHandleImpl(jni, j_oes_texture_id, j_transform_matrix)); | 73 NativeHandleImpl(jni, j_oes_texture_id, j_transform_matrix)); |
69 } | 74 } |
70 | 75 |
71 JNI_FUNCTION_DECLARATION(void, | 76 JNI_FUNCTION_DECLARATION(void, |
72 AndroidVideoTrackSourceObserver_nativeOnFrameCaptured, | 77 AndroidVideoTrackSourceObserver_nativeOnFrameCaptured, |
73 JNIEnv* jni, | 78 JNIEnv* jni, |
74 jclass, | 79 jclass, |
75 jlong j_source, | 80 jlong j_source, |
76 jint j_width, | 81 jint j_width, |
77 jint j_height, | 82 jint j_height, |
78 jint j_rotation, | 83 jint j_rotation, |
79 jlong j_timestamp_ns, | 84 jlong j_timestamp_ns, |
80 jobject j_video_frame_buffer) { | 85 jobject j_video_frame_buffer) { |
81 webrtc::AndroidVideoTrackSource* source = | 86 AndroidVideoTrackSource* source = |
82 AndroidVideoTrackSourceFromJavaProxy(j_source); | 87 AndroidVideoTrackSourceFromJavaProxy(j_source); |
83 source->OnFrameCaptured(jni, j_width, j_height, j_timestamp_ns, | 88 source->OnFrameCaptured(jni, j_width, j_height, j_timestamp_ns, |
84 jintToVideoRotation(j_rotation), | 89 jintToVideoRotation(j_rotation), |
85 j_video_frame_buffer); | 90 j_video_frame_buffer); |
86 } | 91 } |
87 | 92 |
88 JNI_FUNCTION_DECLARATION(void, | 93 JNI_FUNCTION_DECLARATION(void, |
89 AndroidVideoTrackSourceObserver_nativeCapturerStarted, | 94 AndroidVideoTrackSourceObserver_nativeCapturerStarted, |
90 JNIEnv* jni, | 95 JNIEnv* jni, |
91 jclass, | 96 jclass, |
92 jlong j_source, | 97 jlong j_source, |
93 jboolean j_success) { | 98 jboolean j_success) { |
94 LOG(LS_INFO) << "AndroidVideoTrackSourceObserve_nativeCapturerStarted"; | 99 LOG(LS_INFO) << "AndroidVideoTrackSourceObserve_nativeCapturerStarted"; |
95 webrtc::AndroidVideoTrackSource* source = | 100 AndroidVideoTrackSource* source = |
96 AndroidVideoTrackSourceFromJavaProxy(j_source); | 101 AndroidVideoTrackSourceFromJavaProxy(j_source); |
97 source->SetState(j_success | 102 source->SetState(j_success ? AndroidVideoTrackSource::SourceState::kLive |
98 ? webrtc::AndroidVideoTrackSource::SourceState::kLive | 103 : AndroidVideoTrackSource::SourceState::kEnded); |
99 : webrtc::AndroidVideoTrackSource::SourceState::kEnded); | |
100 } | 104 } |
101 | 105 |
102 JNI_FUNCTION_DECLARATION(void, | 106 JNI_FUNCTION_DECLARATION(void, |
103 AndroidVideoTrackSourceObserver_nativeCapturerStopped, | 107 AndroidVideoTrackSourceObserver_nativeCapturerStopped, |
104 JNIEnv* jni, | 108 JNIEnv* jni, |
105 jclass, | 109 jclass, |
106 jlong j_source) { | 110 jlong j_source) { |
107 LOG(LS_INFO) << "AndroidVideoTrackSourceObserve_nativeCapturerStopped"; | 111 LOG(LS_INFO) << "AndroidVideoTrackSourceObserve_nativeCapturerStopped"; |
108 webrtc::AndroidVideoTrackSource* source = | 112 AndroidVideoTrackSource* source = |
109 AndroidVideoTrackSourceFromJavaProxy(j_source); | 113 AndroidVideoTrackSourceFromJavaProxy(j_source); |
110 source->SetState(webrtc::AndroidVideoTrackSource::SourceState::kEnded); | 114 source->SetState(AndroidVideoTrackSource::SourceState::kEnded); |
111 } | 115 } |
112 | 116 |
113 JNI_FUNCTION_DECLARATION(void, | 117 JNI_FUNCTION_DECLARATION(void, |
114 VideoSource_nativeAdaptOutputFormat, | 118 VideoSource_nativeAdaptOutputFormat, |
115 JNIEnv* jni, | 119 JNIEnv* jni, |
116 jclass, | 120 jclass, |
117 jlong j_source, | 121 jlong j_source, |
118 jint j_width, | 122 jint j_width, |
119 jint j_height, | 123 jint j_height, |
120 jint j_fps) { | 124 jint j_fps) { |
121 LOG(LS_INFO) << "VideoSource_nativeAdaptOutputFormat"; | 125 LOG(LS_INFO) << "VideoSource_nativeAdaptOutputFormat"; |
122 webrtc::AndroidVideoTrackSource* source = | 126 AndroidVideoTrackSource* source = |
123 AndroidVideoTrackSourceFromJavaProxy(j_source); | 127 AndroidVideoTrackSourceFromJavaProxy(j_source); |
124 source->OnOutputFormatRequest(j_width, j_height, j_fps); | 128 source->OnOutputFormatRequest(j_width, j_height, j_fps); |
125 } | 129 } |
126 | 130 |
127 } // namespace webrtc_jni | 131 } // namespace jni |
| 132 } // namespace webrtc |
OLD | NEW |