Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1104)

Unified Diff: webrtc/api/java/jni/androidvideocapturer_jni.cc

Issue 1702603002: AndroidVideoCapturer getSupportedFormats(): Change interface from JSON string to List/vector (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove logging from C++. Remove json from api.gyp. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/api/java/jni/androidvideocapturer_jni.h ('k') | webrtc/api/java/src/org/webrtc/VideoCapturer.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/api/java/jni/androidvideocapturer_jni.cc
diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.cc b/webrtc/api/java/jni/androidvideocapturer_jni.cc
index 8588dc2139af38ef5266c5724a27ffa055f3b2cc..d22c8b16ba9b88781d54c2f04fbe751c41d68722 100644
--- a/webrtc/api/java/jni/androidvideocapturer_jni.cc
+++ b/webrtc/api/java/jni/androidvideocapturer_jni.cc
@@ -114,14 +114,40 @@ void AndroidVideoCapturerJni::AsyncCapturerInvoke(
invoker_->AsyncInvoke<void>(rtc::Bind(method, capturer_, args...));
}
-std::string AndroidVideoCapturerJni::GetSupportedFormats() {
- jmethodID m =
- GetMethodID(jni(), *j_video_capturer_class_,
- "getSupportedFormatsAsJson", "()Ljava/lang/String;");
- jstring j_json_caps =
- (jstring) jni()->CallObjectMethod(*j_video_capturer_, m);
- CHECK_EXCEPTION(jni()) << "error during supportedFormatsAsJson";
- return JavaToStdString(jni(), j_json_caps);
+std::vector<cricket::VideoFormat>
+AndroidVideoCapturerJni::GetSupportedFormats() {
+ JNIEnv* jni = AttachCurrentThreadIfNeeded();
+ jobject j_list_of_formats = jni->CallObjectMethod(
+ *j_video_capturer_,
+ GetMethodID(jni, *j_video_capturer_class_, "getSupportedFormats",
+ "()Ljava/util/List;"));
+ CHECK_EXCEPTION(jni) << "error during getSupportedFormats";
+
+ // Extract Java List<CaptureFormat> to std::vector<cricket::VideoFormat>.
+ jclass j_list_class = jni->FindClass("java/util/List");
+ jclass j_format_class =
+ jni->FindClass("org/webrtc/CameraEnumerationAndroid$CaptureFormat");
+ const int size = jni->CallIntMethod(
+ j_list_of_formats, GetMethodID(jni, j_list_class, "size", "()I"));
+ jmethodID j_get =
+ GetMethodID(jni, j_list_class, "get", "(I)Ljava/lang/Object;");
+ jfieldID j_width_field = GetFieldID(jni, j_format_class, "width", "I");
+ jfieldID j_height_field = GetFieldID(jni, j_format_class, "height", "I");
+ jfieldID j_max_framerate_field =
+ GetFieldID(jni, j_format_class, "maxFramerate", "I");
+
+ std::vector<cricket::VideoFormat> formats;
+ formats.reserve(size);
+ for (int i = 0; i < size; ++i) {
+ jobject j_format = jni->CallObjectMethod(j_list_of_formats, j_get, i);
+ const int frame_interval = cricket::VideoFormat::FpsToInterval(
+ (GetIntField(jni, j_format, j_max_framerate_field) + 999) / 1000);
+ formats.emplace_back(GetIntField(jni, j_format, j_width_field),
+ GetIntField(jni, j_format, j_height_field),
+ frame_interval, cricket::FOURCC_NV21);
+ }
+ CHECK_EXCEPTION(jni) << "error while extracting formats";
+ return formats;
}
void AndroidVideoCapturerJni::OnCapturerStarted(bool success) {
« no previous file with comments | « webrtc/api/java/jni/androidvideocapturer_jni.h ('k') | webrtc/api/java/src/org/webrtc/VideoCapturer.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698