diff --git a/webrtc/api/androidvideocapturer.cc b/webrtc/api/androidvideocapturer.cc index 69278db3bd..a24d55c168 100644 --- a/webrtc/api/androidvideocapturer.cc +++ b/webrtc/api/androidvideocapturer.cc @@ -12,7 +12,6 @@ #include "webrtc/api/java/jni/native_handle_impl.h" #include "webrtc/base/common.h" -#include "webrtc/base/json.h" #include "webrtc/base/timeutils.h" #include "webrtc/media/engine/webrtcvideoframe.h" @@ -119,29 +118,7 @@ AndroidVideoCapturer::AndroidVideoCapturer( frame_factory_(NULL), current_state_(cricket::CS_STOPPED) { thread_checker_.DetachFromThread(); - std::string json_string = delegate_->GetSupportedFormats(); - LOG(LS_INFO) << json_string; - - Json::Value json_values; - Json::Reader reader(Json::Features::strictMode()); - if (!reader.parse(json_string, json_values)) { - LOG(LS_ERROR) << "Failed to parse formats."; - } - - std::vector formats; - for (Json::ArrayIndex i = 0; i < json_values.size(); ++i) { - const Json::Value& json_value = json_values[i]; - RTC_CHECK(!json_value["width"].isNull() && - !json_value["height"].isNull() && - !json_value["framerate"].isNull()); - cricket::VideoFormat format( - json_value["width"].asInt(), - json_value["height"].asInt(), - cricket::VideoFormat::FpsToInterval(json_value["framerate"].asInt()), - cricket::FOURCC_YV12); - formats.push_back(format); - } - SetSupportedFormats(formats); + SetSupportedFormats(delegate_->GetSupportedFormats()); } AndroidVideoCapturer::~AndroidVideoCapturer() { diff --git a/webrtc/api/androidvideocapturer.h b/webrtc/api/androidvideocapturer.h index a3295e1ff3..4c73f31598 100644 --- a/webrtc/api/androidvideocapturer.h +++ b/webrtc/api/androidvideocapturer.h @@ -34,8 +34,7 @@ class AndroidVideoCapturerDelegate : public rtc::RefCountInterface { // The delegate may not call into AndroidVideoCapturer after this call. virtual void Stop() = 0; - // Must returns a JSON string "{{width=xxx, height=xxx, framerate = xxx}}" - virtual std::string GetSupportedFormats() = 0; + virtual std::vector GetSupportedFormats() = 0; }; // Android implementation of cricket::VideoCapturer for use with WebRtc diff --git a/webrtc/api/api.gyp b/webrtc/api/api.gyp index 061d9c1554..c9add179fe 100644 --- a/webrtc/api/api.gyp +++ b/webrtc/api/api.gyp @@ -74,16 +74,6 @@ 4267, # conversion from 'size_t' to 'int', possible loss of data. 4389, # signed/unsigned mismatch. ], - 'conditions': [ - ['build_json==1', { - 'dependencies': [ - '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp', - ], - 'export_dependent_settings': [ - '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp', - ], - }], - ], }, { 'target_name': 'libjingle_peerconnection_so', diff --git a/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java b/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java index f465ce74be..02328385ad 100644 --- a/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java +++ b/webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java @@ -14,10 +14,6 @@ import static java.lang.Math.abs; import static java.lang.Math.ceil; import android.graphics.ImageFormat; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - import org.webrtc.Logging; import java.util.Collections; @@ -42,7 +38,9 @@ public class CameraEnumerationAndroid { } public static synchronized List getSupportedFormats(int cameraId) { - return enumerator.getSupportedFormats(cameraId); + final List formats = enumerator.getSupportedFormats(cameraId); + Logging.d(TAG, "Supported formats for camera " + cameraId + ": " + formats); + return formats; } public static class CaptureFormat { @@ -137,21 +135,6 @@ public class CameraEnumerationAndroid { return getNameOfDevice(android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK); } - public static String getSupportedFormatsAsJson(int id) throws JSONException { - List formats = getSupportedFormats(id); - JSONArray json_formats = new JSONArray(); - for (CaptureFormat format : formats) { - JSONObject json_format = new JSONObject(); - json_format.put("width", format.width); - json_format.put("height", format.height); - json_format.put("framerate", (format.maxFramerate + 999) / 1000); - json_formats.put(json_format); - } - Logging.d(TAG, "Supported formats for camera " + id + ": " - + json_formats.toString(2)); - return json_formats.toString(); - } - // Helper class for finding the closest supported format for the two functions below. private static abstract class ClosestComparator implements Comparator { // Difference between supported and requested parameter. diff --git a/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java b/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java index 0ae03cab8e..feff652c46 100644 --- a/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java +++ b/webrtc/api/java/android/org/webrtc/VideoCapturerAndroid.java @@ -17,7 +17,6 @@ import android.os.SystemClock; import android.view.Surface; import android.view.WindowManager; -import org.json.JSONException; import org.webrtc.CameraEnumerationAndroid.CaptureFormat; import org.webrtc.Logging; @@ -284,6 +283,7 @@ public class VideoCapturerAndroid implements } } + @Override public List getSupportedFormats() { return CameraEnumerationAndroid.getSupportedFormats(getCurrentCameraId()); } @@ -293,11 +293,6 @@ public class VideoCapturerAndroid implements return isCapturingToTexture; } - @Override - public String getSupportedFormatsAsJson() throws JSONException { - return CameraEnumerationAndroid.getSupportedFormatsAsJson(getCurrentCameraId()); - } - @Override public SurfaceTextureHelper getSurfaceTextureHelper() { return surfaceHelper; diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.cc b/webrtc/api/java/jni/androidvideocapturer_jni.cc index 8588dc2139..d22c8b16ba 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(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 +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 to std::vector. + 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 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) { diff --git a/webrtc/api/java/jni/androidvideocapturer_jni.h b/webrtc/api/java/jni/androidvideocapturer_jni.h index 9b3bb4f65b..7fe6f826e2 100644 --- a/webrtc/api/java/jni/androidvideocapturer_jni.h +++ b/webrtc/api/java/jni/androidvideocapturer_jni.h @@ -40,7 +40,7 @@ class AndroidVideoCapturerJni : public webrtc::AndroidVideoCapturerDelegate { webrtc::AndroidVideoCapturer* capturer) override; void Stop() override; - std::string GetSupportedFormats() override; + std::vector GetSupportedFormats() override; // Called from VideoCapturer::NativeObserver on a Java thread. void OnCapturerStarted(bool success); diff --git a/webrtc/api/java/src/org/webrtc/VideoCapturer.java b/webrtc/api/java/src/org/webrtc/VideoCapturer.java index 21bfafaf96..8db8b21180 100644 --- a/webrtc/api/java/src/org/webrtc/VideoCapturer.java +++ b/webrtc/api/java/src/org/webrtc/VideoCapturer.java @@ -12,7 +12,7 @@ package org.webrtc; import android.content.Context; -import org.json.JSONException; +import java.util.List; // Base interface for all VideoCapturers to implement. // TODO(magjed): Simplify and improve this interface. @@ -83,7 +83,7 @@ public interface VideoCapturer { int width, int height, int framerate); } - String getSupportedFormatsAsJson() throws JSONException; + List getSupportedFormats(); SurfaceTextureHelper getSurfaceTextureHelper();