jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-08 04:46:45 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-08 04:46:45 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "media/base/videoadapter.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 12 | |
andresp@webrtc.org | ff689be | 2015-02-12 11:54:26 | [diff] [blame] | 13 | #include <algorithm> |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 14 | #include <cmath> |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 15 | #include <cstdlib> |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 16 | #include <limits> |
Steve Anton | e78bcb9 | 2017-10-31 16:53:08 | [diff] [blame] | 17 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 18 | |
Danil Chapovalov | 00c71836 | 2018-06-15 13:58:38 | [diff] [blame] | 19 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 20 | #include "media/base/mediaconstants.h" |
| 21 | #include "media/base/videocommon.h" |
| 22 | #include "rtc_base/arraysize.h" |
| 23 | #include "rtc_base/checks.h" |
| 24 | #include "rtc_base/logging.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 25 | |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 26 | namespace { |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 27 | struct Fraction { |
| 28 | int numerator; |
| 29 | int denominator; |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 30 | |
| 31 | // Determines number of output pixels if both width and height of an input of |
| 32 | // |input_pixels| pixels is scaled with the fraction numerator / denominator. |
| 33 | int scale_pixel_count(int input_pixels) { |
| 34 | return (numerator * numerator * input_pixels) / (denominator * denominator); |
| 35 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 36 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 37 | |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 38 | // Round |value_to_round| to a multiple of |multiple|. Prefer rounding upwards, |
| 39 | // but never more than |max_value|. |
| 40 | int roundUp(int value_to_round, int multiple, int max_value) { |
| 41 | const int rounded_value = |
| 42 | (value_to_round + multiple - 1) / multiple * multiple; |
| 43 | return rounded_value <= max_value ? rounded_value |
| 44 | : (max_value / multiple * multiple); |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 45 | } |
| 46 | |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 47 | // Generates a scale factor that makes |input_pixels| close to |target_pixels|, |
| 48 | // but no higher than |max_pixels|. |
| 49 | Fraction FindScale(int input_pixels, int target_pixels, int max_pixels) { |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 50 | // This function only makes sense for a positive target. |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 51 | RTC_DCHECK_GT(target_pixels, 0); |
| 52 | RTC_DCHECK_GT(max_pixels, 0); |
| 53 | RTC_DCHECK_GE(max_pixels, target_pixels); |
| 54 | |
| 55 | // Don't scale up original. |
| 56 | if (target_pixels >= input_pixels) |
| 57 | return Fraction{1, 1}; |
| 58 | |
| 59 | Fraction current_scale = Fraction{1, 1}; |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 60 | Fraction best_scale = Fraction{1, 1}; |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 61 | // The minimum (absolute) difference between the number of output pixels and |
| 62 | // the target pixel count. |
| 63 | int min_pixel_diff = std::numeric_limits<int>::max(); |
Magnus Jedvert | 6d230d7 | 2017-02-22 17:30:27 | [diff] [blame] | 64 | if (input_pixels <= max_pixels) { |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 65 | // Start condition for 1/1 case, if it is less than max. |
| 66 | min_pixel_diff = std::abs(input_pixels - target_pixels); |
| 67 | } |
| 68 | |
| 69 | // Alternately scale down by 2/3 and 3/4. This results in fractions which are |
| 70 | // effectively scalable. For instance, starting at 1280x720 will result in |
| 71 | // the series (3/4) => 960x540, (1/2) => 640x360, (3/8) => 480x270, |
| 72 | // (1/4) => 320x180, (3/16) => 240x125, (1/8) => 160x90. |
| 73 | while (current_scale.scale_pixel_count(input_pixels) > target_pixels) { |
| 74 | if (current_scale.numerator % 3 == 0 && |
| 75 | current_scale.denominator % 2 == 0) { |
| 76 | // Multiply by 2/3. |
| 77 | current_scale.numerator /= 3; |
| 78 | current_scale.denominator /= 2; |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 79 | } else { |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 80 | // Multiply by 3/4. |
| 81 | current_scale.numerator *= 3; |
| 82 | current_scale.denominator *= 4; |
| 83 | } |
| 84 | |
| 85 | int output_pixels = current_scale.scale_pixel_count(input_pixels); |
| 86 | if (output_pixels <= max_pixels) { |
| 87 | int diff = std::abs(target_pixels - output_pixels); |
| 88 | if (diff < min_pixel_diff) { |
| 89 | min_pixel_diff = diff; |
| 90 | best_scale = current_scale; |
| 91 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 92 | } |
| 93 | } |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 94 | |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 95 | return best_scale; |
| 96 | } |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 97 | } // namespace |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 98 | |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 99 | namespace cricket { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 100 | |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 101 | VideoAdapter::VideoAdapter(int required_resolution_alignment) |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 102 | : frames_in_(0), |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 103 | frames_out_(0), |
| 104 | frames_scaled_(0), |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 105 | adaption_changes_(0), |
magjed@webrtc.org | a73d746 | 2014-11-14 13:25:25 | [diff] [blame] | 106 | previous_width_(0), |
| 107 | previous_height_(0), |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 108 | required_resolution_alignment_(required_resolution_alignment), |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 109 | resolution_request_target_pixel_count_(std::numeric_limits<int>::max()), |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 110 | resolution_request_max_pixel_count_(std::numeric_limits<int>::max()), |
| 111 | max_framerate_request_(std::numeric_limits<int>::max()) {} |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 112 | |
| 113 | VideoAdapter::VideoAdapter() : VideoAdapter(1) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 114 | |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 115 | VideoAdapter::~VideoAdapter() {} |
| 116 | |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 117 | bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 118 | rtc::CritScope cs(&critical_section_); |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 119 | |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 120 | int max_fps = max_framerate_request_; |
| 121 | if (max_fps_) |
| 122 | max_fps = std::min(max_fps, *max_fps_); |
| 123 | |
| 124 | if (max_fps <= 0) |
| 125 | return false; |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 126 | |
| 127 | // If |max_framerate_request_| is not set, it will default to maxint, which |
| 128 | // will lead to a frame_interval_ns rounded to 0. |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 129 | int64_t frame_interval_ns = rtc::kNumNanosecsPerSec / max_fps; |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 130 | if (frame_interval_ns <= 0) { |
| 131 | // Frame rate throttling not enabled. |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 132 | return true; |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 133 | } |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 134 | |
| 135 | if (next_frame_timestamp_ns_) { |
| 136 | // Time until next frame should be outputted. |
| 137 | const int64_t time_until_next_frame_ns = |
| 138 | (*next_frame_timestamp_ns_ - in_timestamp_ns); |
| 139 | |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 140 | // Continue if timestamp is within expected range. |
| 141 | if (std::abs(time_until_next_frame_ns) < 2 * frame_interval_ns) { |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 142 | // Drop if a frame shouldn't be outputted yet. |
| 143 | if (time_until_next_frame_ns > 0) |
| 144 | return false; |
| 145 | // Time to output new frame. |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 146 | *next_frame_timestamp_ns_ += frame_interval_ns; |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 147 | return true; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | // First timestamp received or timestamp is way outside expected range, so |
| 152 | // reset. Set first timestamp target to just half the interval to prefer |
| 153 | // keeping frames in case of jitter. |
Oskar Sundbom | 7880758 | 2017-11-16 10:09:55 | [diff] [blame] | 154 | next_frame_timestamp_ns_ = in_timestamp_ns + frame_interval_ns / 2; |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 155 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 156 | } |
| 157 | |
nisse | 47ac462 | 2016-05-25 15:47:01 | [diff] [blame] | 158 | bool VideoAdapter::AdaptFrameResolution(int in_width, |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 159 | int in_height, |
magjed | 604abe0 | 2016-05-19 13:05:40 | [diff] [blame] | 160 | int64_t in_timestamp_ns, |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 161 | int* cropped_width, |
| 162 | int* cropped_height, |
| 163 | int* out_width, |
| 164 | int* out_height) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 165 | rtc::CritScope cs(&critical_section_); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 166 | ++frames_in_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 167 | |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 168 | // The max output pixel count is the minimum of the requests from |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 169 | // OnOutputFormatRequest and OnResolutionFramerateRequest. |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 170 | int max_pixel_count = resolution_request_max_pixel_count_; |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 171 | |
| 172 | if (max_pixel_count_) |
| 173 | max_pixel_count = std::min(max_pixel_count, *max_pixel_count_); |
| 174 | |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 175 | int target_pixel_count = |
| 176 | std::min(resolution_request_target_pixel_count_, max_pixel_count); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 177 | |
| 178 | // Drop the input frame if necessary. |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 179 | if (max_pixel_count <= 0 || !KeepFrame(in_timestamp_ns)) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 180 | // Show VAdapt log every 90 frames dropped. (3 seconds) |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 | [diff] [blame] | 181 | if ((frames_in_ - frames_out_) % 90 == 0) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 182 | // TODO(fbarchard): Reduce to LS_VERBOSE when adapter info is not needed |
| 183 | // in default calls. |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 184 | RTC_LOG(LS_INFO) << "VAdapt Drop Frame: scaled " << frames_scaled_ |
| 185 | << " / out " << frames_out_ << " / in " << frames_in_ |
| 186 | << " Changes: " << adaption_changes_ |
| 187 | << " Input: " << in_width << "x" << in_height |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 188 | << " timestamp: " << in_timestamp_ns |
| 189 | << " Output fps: " << max_framerate_request_ << "/" |
| 190 | << max_fps_.value_or(-1); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 191 | } |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 | [diff] [blame] | 192 | |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 193 | // Drop frame. |
nisse | 47ac462 | 2016-05-25 15:47:01 | [diff] [blame] | 194 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 195 | } |
| 196 | |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 197 | // Calculate how the input should be cropped. |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 198 | if (!target_aspect_ratio_ || target_aspect_ratio_->first <= 0 || |
| 199 | target_aspect_ratio_->second <= 0) { |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 200 | *cropped_width = in_width; |
| 201 | *cropped_height = in_height; |
| 202 | } else { |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 203 | // Adjust |target_aspect_ratio_| orientation to match input. |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 204 | if ((in_width > in_height) != |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 205 | (target_aspect_ratio_->first > target_aspect_ratio_->second)) { |
| 206 | std::swap(target_aspect_ratio_->first, target_aspect_ratio_->second); |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 207 | } |
| 208 | const float requested_aspect = |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 209 | target_aspect_ratio_->first / |
| 210 | static_cast<float>(target_aspect_ratio_->second); |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 211 | *cropped_width = |
| 212 | std::min(in_width, static_cast<int>(in_height * requested_aspect)); |
| 213 | *cropped_height = |
| 214 | std::min(in_height, static_cast<int>(in_width / requested_aspect)); |
| 215 | } |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 216 | const Fraction scale = FindScale((*cropped_width) * (*cropped_height), |
| 217 | target_pixel_count, max_pixel_count); |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 218 | // Adjust cropping slightly to get even integer output size and a perfect |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 219 | // scale factor. Make sure the resulting dimensions are aligned correctly |
| 220 | // to be nice to hardware encoders. |
| 221 | *cropped_width = |
| 222 | roundUp(*cropped_width, |
| 223 | scale.denominator * required_resolution_alignment_, in_width); |
| 224 | *cropped_height = |
| 225 | roundUp(*cropped_height, |
| 226 | scale.denominator * required_resolution_alignment_, in_height); |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 227 | RTC_DCHECK_EQ(0, *cropped_width % scale.denominator); |
| 228 | RTC_DCHECK_EQ(0, *cropped_height % scale.denominator); |
| 229 | |
| 230 | // Calculate final output size. |
| 231 | *out_width = *cropped_width / scale.denominator * scale.numerator; |
| 232 | *out_height = *cropped_height / scale.denominator * scale.numerator; |
magjed | 4e83682 | 2017-02-28 14:30:59 | [diff] [blame] | 233 | RTC_DCHECK_EQ(0, *out_width % required_resolution_alignment_); |
kthelgason | c847417 | 2016-12-08 16:04:51 | [diff] [blame] | 234 | RTC_DCHECK_EQ(0, *out_height % required_resolution_alignment_); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 235 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 236 | ++frames_out_; |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 237 | if (scale.numerator != scale.denominator) |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 238 | ++frames_scaled_; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 239 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 240 | if (previous_width_ && |
| 241 | (previous_width_ != *out_width || previous_height_ != *out_height)) { |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 242 | ++adaption_changes_; |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 243 | RTC_LOG(LS_INFO) << "Frame size changed: scaled " << frames_scaled_ |
| 244 | << " / out " << frames_out_ << " / in " << frames_in_ |
| 245 | << " Changes: " << adaption_changes_ |
| 246 | << " Input: " << in_width << "x" << in_height |
| 247 | << " Scale: " << scale.numerator << "/" |
| 248 | << scale.denominator << " Output: " << *out_width << "x" |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 249 | << *out_height << " fps: " << max_framerate_request_ << "/" |
| 250 | << max_fps_.value_or(-1); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 | [diff] [blame] | 251 | } |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 | [diff] [blame] | 252 | |
magjed | 709f73c | 2016-05-13 17:26:00 | [diff] [blame] | 253 | previous_width_ = *out_width; |
| 254 | previous_height_ = *out_height; |
nisse | 47ac462 | 2016-05-25 15:47:01 | [diff] [blame] | 255 | |
| 256 | return true; |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 | [diff] [blame] | 257 | } |
| 258 | |
Chris Dziemborowicz | 048805e | 2018-03-02 01:55:53 | [diff] [blame] | 259 | void VideoAdapter::OnOutputFormatRequest( |
Danil Chapovalov | 00c71836 | 2018-06-15 13:58:38 | [diff] [blame] | 260 | const absl::optional<VideoFormat>& format) { |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 261 | absl::optional<std::pair<int, int>> target_aspect_ratio; |
| 262 | absl::optional<int> max_pixel_count; |
| 263 | absl::optional<int> max_fps; |
| 264 | if (format) { |
| 265 | target_aspect_ratio = std::make_pair(format->width, format->height); |
| 266 | max_pixel_count = format->width * format->height; |
| 267 | if (format->interval > 0) |
| 268 | max_fps = rtc::kNumNanosecsPerSec / format->interval; |
| 269 | } |
| 270 | OnOutputFormatRequest(target_aspect_ratio, max_pixel_count, max_fps); |
| 271 | } |
| 272 | |
| 273 | void VideoAdapter::OnOutputFormatRequest( |
| 274 | const absl::optional<std::pair<int, int>>& target_aspect_ratio, |
| 275 | const absl::optional<int>& max_pixel_count, |
| 276 | const absl::optional<int>& max_fps) { |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 277 | rtc::CritScope cs(&critical_section_); |
Åsa Persson | 2e4419e | 2018-09-06 13:02:55 | [diff] [blame] | 278 | target_aspect_ratio_ = target_aspect_ratio; |
| 279 | max_pixel_count_ = max_pixel_count; |
| 280 | max_fps_ = max_fps; |
Danil Chapovalov | 00c71836 | 2018-06-15 13:58:38 | [diff] [blame] | 281 | next_frame_timestamp_ns_ = absl::nullopt; |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 | [diff] [blame] | 282 | } |
| 283 | |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 284 | void VideoAdapter::OnResolutionFramerateRequest( |
Danil Chapovalov | 00c71836 | 2018-06-15 13:58:38 | [diff] [blame] | 285 | const absl::optional<int>& target_pixel_count, |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 286 | int max_pixel_count, |
| 287 | int max_framerate_fps) { |
Per | 766ad3b9 | 2016-04-05 13:23:49 | [diff] [blame] | 288 | rtc::CritScope cs(&critical_section_); |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 289 | resolution_request_max_pixel_count_ = max_pixel_count; |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 290 | resolution_request_target_pixel_count_ = |
| 291 | target_pixel_count.value_or(resolution_request_max_pixel_count_); |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 292 | max_framerate_request_ = max_framerate_fps; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | } // namespace cricket |