OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 void (webrtc::AndroidVideoCapturer::*method)(Args...), | 107 void (webrtc::AndroidVideoCapturer::*method)(Args...), |
108 typename Identity<Args>::type... args) { | 108 typename Identity<Args>::type... args) { |
109 rtc::CritScope cs(&capturer_lock_); | 109 rtc::CritScope cs(&capturer_lock_); |
110 if (!invoker_) { | 110 if (!invoker_) { |
111 LOG(LS_WARNING) << method_name << "() called for closed capturer."; | 111 LOG(LS_WARNING) << method_name << "() called for closed capturer."; |
112 return; | 112 return; |
113 } | 113 } |
114 invoker_->AsyncInvoke<void>(rtc::Bind(method, capturer_, args...)); | 114 invoker_->AsyncInvoke<void>(rtc::Bind(method, capturer_, args...)); |
115 } | 115 } |
116 | 116 |
117 std::string AndroidVideoCapturerJni::GetSupportedFormats() { | 117 std::vector<cricket::VideoFormat> |
118 jmethodID m = | 118 AndroidVideoCapturerJni::GetSupportedFormats() { |
119 GetMethodID(jni(), *j_video_capturer_class_, | 119 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
120 "getSupportedFormatsAsJson", "()Ljava/lang/String;"); | 120 jobject j_list_of_formats = jni->CallObjectMethod( |
121 jstring j_json_caps = | 121 *j_video_capturer_, |
122 (jstring) jni()->CallObjectMethod(*j_video_capturer_, m); | 122 GetMethodID(jni, *j_video_capturer_class_, "getSupportedFormats", |
123 CHECK_EXCEPTION(jni()) << "error during supportedFormatsAsJson"; | 123 "()Ljava/util/List;")); |
124 return JavaToStdString(jni(), j_json_caps); | 124 CHECK_EXCEPTION(jni) << "error during getSupportedFormats"; |
| 125 |
| 126 // Extract Java List<CaptureFormat> to std::vector<cricket::VideoFormat>. |
| 127 jclass j_list_class = jni->FindClass("java/util/List"); |
| 128 jclass j_format_class = |
| 129 jni->FindClass("org/webrtc/CameraEnumerationAndroid$CaptureFormat"); |
| 130 const int size = jni->CallIntMethod( |
| 131 j_list_of_formats, GetMethodID(jni, j_list_class, "size", "()I")); |
| 132 jmethodID j_get = |
| 133 GetMethodID(jni, j_list_class, "get", "(I)Ljava/lang/Object;"); |
| 134 jfieldID j_width_field = GetFieldID(jni, j_format_class, "width", "I"); |
| 135 jfieldID j_height_field = GetFieldID(jni, j_format_class, "height", "I"); |
| 136 jfieldID j_max_framerate_field = |
| 137 GetFieldID(jni, j_format_class, "maxFramerate", "I"); |
| 138 |
| 139 std::vector<cricket::VideoFormat> formats; |
| 140 formats.reserve(size); |
| 141 for (int i = 0; i < size; ++i) { |
| 142 jobject j_format = jni->CallObjectMethod(j_list_of_formats, j_get, i); |
| 143 const int frame_interval = cricket::VideoFormat::FpsToInterval( |
| 144 (GetIntField(jni, j_format, j_max_framerate_field) + 999) / 1000); |
| 145 formats.emplace_back(GetIntField(jni, j_format, j_width_field), |
| 146 GetIntField(jni, j_format, j_height_field), |
| 147 frame_interval, cricket::FOURCC_NV21); |
| 148 } |
| 149 CHECK_EXCEPTION(jni) << "error while extracting formats"; |
| 150 return formats; |
125 } | 151 } |
126 | 152 |
127 void AndroidVideoCapturerJni::OnCapturerStarted(bool success) { | 153 void AndroidVideoCapturerJni::OnCapturerStarted(bool success) { |
128 LOG(LS_INFO) << "AndroidVideoCapturerJni capture started: " << success; | 154 LOG(LS_INFO) << "AndroidVideoCapturerJni capture started: " << success; |
129 AsyncCapturerInvoke("OnCapturerStarted", | 155 AsyncCapturerInvoke("OnCapturerStarted", |
130 &webrtc::AndroidVideoCapturer::OnCapturerStarted, | 156 &webrtc::AndroidVideoCapturer::OnCapturerStarted, |
131 success); | 157 success); |
132 } | 158 } |
133 | 159 |
134 void AndroidVideoCapturerJni::OnMemoryBufferFrame(void* video_frame, | 160 void AndroidVideoCapturerJni::OnMemoryBufferFrame(void* video_frame, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 233 |
208 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) | 234 JOW(void, VideoCapturer_00024NativeObserver_nativeOnOutputFormatRequest) |
209 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, | 235 (JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height, |
210 jint j_fps) { | 236 jint j_fps) { |
211 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; | 237 LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest"; |
212 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( | 238 reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest( |
213 j_width, j_height, j_fps); | 239 j_width, j_height, j_fps); |
214 } | 240 } |
215 | 241 |
216 } // namespace webrtc_jni | 242 } // namespace webrtc_jni |
OLD | NEW |