Android: Add FramerateRange class

The Camera1 and Camera2 API use different framerate range types. Camera1
uses int[2] and Camera2 uses Range<Integer>. Range<Integer> is
unfortunately only available on Lollipop and later, so this CL adds a
similar FramerateRange class in CaptureFormat.

The purpose with this CL is to have a common framerate range type that can
be reused from both Camera1 and Camera2 in helper functions such as
CameraEnumerationAndroid.getClosestSupportedFramerateRange().

BUG=webrtc:5519
R=sakal@webrtc.org

Review URL: https://codereview.webrtc.org/2010763003 .

Cr-Commit-Position: refs/heads/master@{#12942}
This commit is contained in:
Magnus Jedvert
2016-05-27 10:35:51 +02:00
parent a44e72c44f
commit 94cb67d6df
6 changed files with 101 additions and 47 deletions

View File

@ -127,21 +127,27 @@ AndroidVideoCapturerJni::GetSupportedFormats() {
jclass j_list_class = jni->FindClass("java/util/List");
jclass j_format_class =
jni->FindClass("org/webrtc/CameraEnumerationAndroid$CaptureFormat");
jclass j_framerate_class = jni->FindClass(
"org/webrtc/CameraEnumerationAndroid$CaptureFormat$FramerateRange");
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_framerate_field = GetFieldID(
jni, j_format_class, "framerate",
"org/webrtc/CameraEnumerationAndroid$CaptureFormat$FramerateRange");
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");
GetFieldID(jni, j_framerate_class, "max", "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);
jobject j_framerate = GetObjectField(jni, j_format, j_framerate_field);
const int frame_interval = cricket::VideoFormat::FpsToInterval(
(GetIntField(jni, j_format, j_max_framerate_field) + 999) / 1000);
(GetIntField(jni, j_framerate, 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);