From 3472dcd7b07f8e8fa4b0ac72a3821e4581e41ebb Mon Sep 17 00:00:00 2001 From: "glaznev@webrtc.org" Date: Wed, 10 Sep 2014 19:24:57 +0000 Subject: [PATCH] Fix frame rate selection for Android camera. - Android camera supports multiple fps values for a single video resolution - change video source default video format selection to pick up best available fps. - Change fps range calculation to better match target fps value. BUG=2622 R=tkchin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/15339004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7142 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/app/webrtc/videosource.cc | 13 +++++++++---- .../video_capture/android/device_info_android.cc | 16 +++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/talk/app/webrtc/videosource.cc b/talk/app/webrtc/videosource.cc index 8770e6dfc..589341d44 100644 --- a/talk/app/webrtc/videosource.cc +++ b/talk/app/webrtc/videosource.cc @@ -28,6 +28,7 @@ #include "talk/app/webrtc/videosource.h" #include +#include #include "talk/app/webrtc/mediaconstraintsinterface.h" #include "talk/session/media/channelmanager.h" @@ -254,11 +255,15 @@ const cricket::VideoFormat& GetBestCaptureFormat( std::vector::const_iterator it = formats.begin(); std::vector::const_iterator best_it = formats.begin(); - int best_diff = abs(default_area - it->width* it->height); + int best_diff_area = std::abs(default_area - it->width * it->height); + int64 best_diff_interval = kDefaultFormat.interval; for (; it != formats.end(); ++it) { - int diff = abs(default_area - it->width* it->height); - if (diff < best_diff) { - best_diff = diff; + int diff_area = std::abs(default_area - it->width * it->height); + int64 diff_interval = std::abs(kDefaultFormat.interval - it->interval); + if (diff_area < best_diff_area || + (diff_area == best_diff_area && diff_interval < best_diff_interval)) { + best_diff_area = diff_area; + best_diff_interval = diff_interval; best_it = it; } } diff --git a/webrtc/modules/video_capture/android/device_info_android.cc b/webrtc/modules/video_capture/android/device_info_android.cc index 4a80fe272..82a3a95f9 100644 --- a/webrtc/modules/video_capture/android/device_info_android.cc +++ b/webrtc/modules/video_capture/android/device_info_android.cc @@ -234,14 +234,20 @@ void DeviceInfoAndroid::GetMFpsRange(const char* deviceUniqueIdUTF8, const AndroidCameraInfo* info = FindCameraInfoByName(deviceUniqueIdUTF8); if (info == NULL) return; - // Rely on CameraParameters.getSupportedPreviewFpsRange() to sort its return - // value (per its documentation) and return the first (most flexible) range - // whose high end is at least as high as that requested. + int desired_mfps = max_fps_to_match * 1000; + int best_diff_mfps = 0; + LOG(LS_INFO) << "Search for best target mfps " << desired_mfps; + // Search for best fps range with preference shifted to constant fps modes. for (size_t i = 0; i < info->mfpsRanges.size(); ++i) { - if (info->mfpsRanges[i].second / 1000 >= max_fps_to_match) { + int diff_mfps = abs(info->mfpsRanges[i].first - desired_mfps) + + abs(info->mfpsRanges[i].second - desired_mfps) + + (info->mfpsRanges[i].second - info->mfpsRanges[i].first) / 2; + LOG(LS_INFO) << "Fps range " << info->mfpsRanges[i].first << ":" << + info->mfpsRanges[i].second << ". Distance: " << diff_mfps; + if (i == 0 || diff_mfps < best_diff_mfps) { + best_diff_mfps = diff_mfps; *min_mfps = info->mfpsRanges[i].first; *max_mfps = info->mfpsRanges[i].second; - return; } } }