diff --git a/talk/app/webrtc/videosource.cc b/talk/app/webrtc/videosource.cc index 8770e6dfc5..589341d447 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 4a80fe2722..82a3a95f9a 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; } } }