jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [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 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 11 | #include "webrtc/media/base/videoadapter.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
andresp@webrtc.org | ff689be | 2015-02-12 11:54:26 +0000 | [diff] [blame] | 13 | #include <algorithm> |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 14 | #include <cmath> |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 15 | #include <cstdlib> |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 16 | #include <limits> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 18 | #include "webrtc/base/arraysize.h" |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 19 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 20 | #include "webrtc/base/logging.h" |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 21 | #include "webrtc/base/optional.h" |
kjellander | f475277 | 2016-03-02 05:42:30 -0800 | [diff] [blame] | 22 | #include "webrtc/media/base/mediaconstants.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 23 | #include "webrtc/media/base/videocommon.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 24 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 25 | namespace { |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 26 | struct Fraction { |
| 27 | int numerator; |
| 28 | int denominator; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 31 | // Scale factors optimized for in libYUV that we accept. |
| 32 | // Must be sorted in decreasing scale factors for FindScaleLargerThan to work. |
| 33 | const Fraction kScaleFractions[] = { |
| 34 | {1, 1}, |
| 35 | {3, 4}, |
| 36 | {1, 2}, |
| 37 | {3, 8}, |
| 38 | {1, 4}, |
| 39 | {3, 16}, |
| 40 | }; |
| 41 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 42 | // Round |value_to_round| to a multiple of |multiple|. Prefer rounding upwards, |
| 43 | // but never more than |max_value|. |
| 44 | int roundUp(int value_to_round, int multiple, int max_value) { |
| 45 | const int rounded_value = |
| 46 | (value_to_round + multiple - 1) / multiple * multiple; |
| 47 | return rounded_value <= max_value ? rounded_value |
| 48 | : (max_value / multiple * multiple); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 49 | } |
| 50 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 51 | // Generates a scale factor that makes |input_num_pixels| smaller than |
| 52 | // |target_num_pixels|. This should only be used after making sure none |
| 53 | // of the optimized factors are small enough. |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 54 | Fraction FindScaleLessThanOrEqual(int input_num_pixels, int target_num_pixels) { |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 55 | // Start searching from the last of the optimal fractions; |
| 56 | Fraction best_scale = kScaleFractions[arraysize(kScaleFractions) - 1]; |
| 57 | const float target_scale = |
| 58 | sqrt(target_num_pixels / static_cast<float>(input_num_pixels)); |
| 59 | do { |
| 60 | if (best_scale.numerator % 3 == 0 && best_scale.denominator % 2 == 0) { |
| 61 | // Multiply by 2/3 |
| 62 | best_scale.numerator /= 3; |
| 63 | best_scale.denominator /= 2; |
| 64 | } else { |
| 65 | // Multiply by 3/4 |
| 66 | best_scale.numerator *= 3; |
| 67 | best_scale.denominator *= 4; |
| 68 | } |
| 69 | } while (best_scale.numerator > (target_scale * best_scale.denominator)); |
| 70 | return best_scale; |
| 71 | } |
| 72 | |
| 73 | rtc::Optional<Fraction> FindOptimizedScaleLessThanOrEqual( |
| 74 | int input_num_pixels, |
| 75 | int target_num_pixels) { |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 76 | float best_distance = std::numeric_limits<float>::max(); |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 77 | rtc::Optional<Fraction> best_scale; |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 78 | for (const auto& fraction : kScaleFractions) { |
| 79 | const float scale = |
| 80 | fraction.numerator / static_cast<float>(fraction.denominator); |
| 81 | float test_num_pixels = input_num_pixels * scale * scale; |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 82 | float diff = target_num_pixels - test_num_pixels; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | if (diff < 0) { |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 84 | continue; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | } |
| 86 | if (diff < best_distance) { |
| 87 | best_distance = diff; |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 88 | best_scale = rtc::Optional<Fraction>(fraction); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | if (best_distance == 0) { // Found exact match. |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | } |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 94 | return best_scale; |
| 95 | } |
| 96 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 97 | Fraction FindOptimizedScaleLargerThan(int input_num_pixels, |
| 98 | int target_num_pixels, |
| 99 | int* resulting_number_of_pixels) { |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 100 | float best_distance = std::numeric_limits<float>::max(); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 101 | Fraction best_scale = {1, 1}; // Default to unscaled if nothing matches. |
| 102 | // Default to input number of pixels. |
| 103 | float best_number_of_pixels = input_num_pixels; |
| 104 | for (const auto& fraction : kScaleFractions) { |
| 105 | const float scale = |
| 106 | fraction.numerator / static_cast<float>(fraction.denominator); |
| 107 | float test_num_pixels = input_num_pixels * scale * scale; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 108 | float diff = test_num_pixels - target_num_pixels; |
| 109 | if (diff <= 0) { |
| 110 | break; |
| 111 | } |
| 112 | if (diff < best_distance) { |
| 113 | best_distance = diff; |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 114 | best_scale = fraction; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 115 | best_number_of_pixels = test_num_pixels; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | *resulting_number_of_pixels = static_cast<int>(best_number_of_pixels + .5f); |
| 120 | return best_scale; |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 121 | } |
| 122 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 123 | rtc::Optional<Fraction> FindOptimizedScale(int input_num_pixels, |
| 124 | int max_pixel_count_step_up, |
| 125 | int max_pixel_count) { |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 126 | // Try scale just above |max_pixel_count_step_up_|. |
| 127 | if (max_pixel_count_step_up > 0) { |
| 128 | int resulting_pixel_count; |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 129 | const Fraction scale = FindOptimizedScaleLargerThan( |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 130 | input_num_pixels, max_pixel_count_step_up, &resulting_pixel_count); |
| 131 | if (resulting_pixel_count <= max_pixel_count) |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 132 | return rtc::Optional<Fraction>(scale); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 133 | } |
| 134 | // Return largest scale below |max_pixel_count|. |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 135 | return FindOptimizedScaleLessThanOrEqual(input_num_pixels, max_pixel_count); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 136 | } |
| 137 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 138 | Fraction FindScale(int input_num_pixels, |
| 139 | int max_pixel_count_step_up, |
| 140 | int max_pixel_count) { |
| 141 | const rtc::Optional<Fraction> optimized_scale = FindOptimizedScale( |
| 142 | input_num_pixels, max_pixel_count_step_up, max_pixel_count); |
| 143 | if (optimized_scale) |
| 144 | return *optimized_scale; |
| 145 | return FindScaleLessThanOrEqual(input_num_pixels, max_pixel_count); |
| 146 | } |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 147 | } // namespace |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 148 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 149 | namespace cricket { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 151 | VideoAdapter::VideoAdapter(int required_resolution_alignment) |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 152 | : frames_in_(0), |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 153 | frames_out_(0), |
| 154 | frames_scaled_(0), |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 155 | adaption_changes_(0), |
magjed@webrtc.org | a73d746 | 2014-11-14 13:25:25 +0000 | [diff] [blame] | 156 | previous_width_(0), |
| 157 | previous_height_(0), |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 158 | required_resolution_alignment_(required_resolution_alignment), |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 159 | resolution_request_max_pixel_count_(std::numeric_limits<int>::max()), |
| 160 | resolution_request_max_pixel_count_step_up_(0) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 161 | |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 162 | VideoAdapter::VideoAdapter() : VideoAdapter(1) {} |
| 163 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 164 | VideoAdapter::~VideoAdapter() {} |
| 165 | |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 166 | bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 167 | rtc::CritScope cs(&critical_section_); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 168 | if (!requested_format_ || requested_format_->interval == 0) |
| 169 | return true; |
| 170 | |
| 171 | if (next_frame_timestamp_ns_) { |
| 172 | // Time until next frame should be outputted. |
| 173 | const int64_t time_until_next_frame_ns = |
| 174 | (*next_frame_timestamp_ns_ - in_timestamp_ns); |
| 175 | |
| 176 | // Continue if timestamp is withing expected range. |
| 177 | if (std::abs(time_until_next_frame_ns) < 2 * requested_format_->interval) { |
| 178 | // Drop if a frame shouldn't be outputted yet. |
| 179 | if (time_until_next_frame_ns > 0) |
| 180 | return false; |
| 181 | // Time to output new frame. |
| 182 | *next_frame_timestamp_ns_ += requested_format_->interval; |
| 183 | return true; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // First timestamp received or timestamp is way outside expected range, so |
| 188 | // reset. Set first timestamp target to just half the interval to prefer |
| 189 | // keeping frames in case of jitter. |
| 190 | next_frame_timestamp_ns_ = |
| 191 | rtc::Optional<int64_t>(in_timestamp_ns + requested_format_->interval / 2); |
| 192 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 193 | } |
| 194 | |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 195 | bool VideoAdapter::AdaptFrameResolution(int in_width, |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 196 | int in_height, |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 197 | int64_t in_timestamp_ns, |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 198 | int* cropped_width, |
| 199 | int* cropped_height, |
| 200 | int* out_width, |
| 201 | int* out_height) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 202 | rtc::CritScope cs(&critical_section_); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 203 | ++frames_in_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 204 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 205 | // The max output pixel count is the minimum of the requests from |
| 206 | // OnOutputFormatRequest and OnResolutionRequest. |
| 207 | int max_pixel_count = resolution_request_max_pixel_count_; |
| 208 | if (requested_format_) { |
| 209 | max_pixel_count = std::min( |
| 210 | max_pixel_count, requested_format_->width * requested_format_->height); |
| 211 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | |
| 213 | // Drop the input frame if necessary. |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 214 | if (max_pixel_count == 0 || !KeepFrame(in_timestamp_ns)) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 215 | // Show VAdapt log every 90 frames dropped. (3 seconds) |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 216 | if ((frames_in_ - frames_out_) % 90 == 0) { |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 217 | // TODO(fbarchard): Reduce to LS_VERBOSE when adapter info is not needed |
| 218 | // in default calls. |
wu@webrtc.org | b9a088b | 2014-02-13 23:18:49 +0000 | [diff] [blame] | 219 | LOG(LS_INFO) << "VAdapt Drop Frame: scaled " << frames_scaled_ |
| 220 | << " / out " << frames_out_ |
| 221 | << " / in " << frames_in_ |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 222 | << " Changes: " << adaption_changes_ |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 223 | << " Input: " << in_width |
| 224 | << "x" << in_height |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 225 | << " timestamp: " << in_timestamp_ns |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 226 | << " Output: i" |
| 227 | << (requested_format_ ? requested_format_->interval : 0); |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 228 | } |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 229 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 230 | // Drop frame. |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 231 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 232 | } |
| 233 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 234 | // Calculate how the input should be cropped. |
| 235 | if (!requested_format_ || |
| 236 | requested_format_->width == 0 || requested_format_->height == 0) { |
| 237 | *cropped_width = in_width; |
| 238 | *cropped_height = in_height; |
| 239 | } else { |
| 240 | // Adjust |requested_format_| orientation to match input. |
| 241 | if ((in_width > in_height) != |
| 242 | (requested_format_->width > requested_format_->height)) { |
| 243 | std::swap(requested_format_->width, requested_format_->height); |
| 244 | } |
| 245 | const float requested_aspect = |
| 246 | requested_format_->width / |
| 247 | static_cast<float>(requested_format_->height); |
| 248 | *cropped_width = |
| 249 | std::min(in_width, static_cast<int>(in_height * requested_aspect)); |
| 250 | *cropped_height = |
| 251 | std::min(in_height, static_cast<int>(in_width / requested_aspect)); |
| 252 | } |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 253 | const Fraction scale = |
| 254 | FindScale(*cropped_width * *cropped_height, |
| 255 | resolution_request_max_pixel_count_step_up_, max_pixel_count); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 256 | // Adjust cropping slightly to get even integer output size and a perfect |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 257 | // scale factor. Make sure the resulting dimensions are aligned correctly |
| 258 | // to be nice to hardware encoders. |
| 259 | *cropped_width = |
| 260 | roundUp(*cropped_width, |
| 261 | scale.denominator * required_resolution_alignment_, in_width); |
| 262 | *cropped_height = |
| 263 | roundUp(*cropped_height, |
| 264 | scale.denominator * required_resolution_alignment_, in_height); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 265 | RTC_DCHECK_EQ(0, *cropped_width % scale.denominator); |
| 266 | RTC_DCHECK_EQ(0, *cropped_height % scale.denominator); |
| 267 | |
| 268 | // Calculate final output size. |
| 269 | *out_width = *cropped_width / scale.denominator * scale.numerator; |
| 270 | *out_height = *cropped_height / scale.denominator * scale.numerator; |
kthelgason | 710c335 | 2016-12-08 02:12:31 -0800 | [diff] [blame^] | 271 | RTC_DCHECK_EQ(0, *out_height % required_resolution_alignment_); |
| 272 | RTC_DCHECK_EQ(0, *out_height % required_resolution_alignment_); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 273 | |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 274 | ++frames_out_; |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 275 | if (scale.numerator != scale.denominator) |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 276 | ++frames_scaled_; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 277 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 278 | if (previous_width_ && (previous_width_ != *out_width || |
| 279 | previous_height_ != *out_height)) { |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 280 | ++adaption_changes_; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 281 | LOG(LS_INFO) << "Frame size changed: scaled " << frames_scaled_ << " / out " |
| 282 | << frames_out_ << " / in " << frames_in_ |
| 283 | << " Changes: " << adaption_changes_ << " Input: " << in_width |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 284 | << "x" << in_height |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 285 | << " Scale: " << scale.numerator << "/" << scale.denominator |
| 286 | << " Output: " << *out_width << "x" << *out_height << " i" |
| 287 | << (requested_format_ ? requested_format_->interval : 0); |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 288 | } |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 289 | |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 290 | previous_width_ = *out_width; |
| 291 | previous_height_ = *out_height; |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 292 | |
| 293 | return true; |
magjed@webrtc.org | f58b455 | 2014-11-19 18:09:14 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 296 | void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) { |
| 297 | rtc::CritScope cs(&critical_section_); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 298 | requested_format_ = rtc::Optional<VideoFormat>(format); |
magjed | 604abe0 | 2016-05-19 06:05:40 -0700 | [diff] [blame] | 299 | next_frame_timestamp_ns_ = rtc::Optional<int64_t>(); |
henrike@webrtc.org | d43aa9d | 2014-02-21 23:43:24 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 302 | void VideoAdapter::OnResolutionRequest( |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 303 | rtc::Optional<int> max_pixel_count, |
| 304 | rtc::Optional<int> max_pixel_count_step_up) { |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 305 | rtc::CritScope cs(&critical_section_); |
| 306 | resolution_request_max_pixel_count_ = |
| 307 | max_pixel_count.value_or(std::numeric_limits<int>::max()); |
magjed | 709f73c | 2016-05-13 10:26:00 -0700 | [diff] [blame] | 308 | resolution_request_max_pixel_count_step_up_ = |
| 309 | max_pixel_count_step_up.value_or(0); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | } // namespace cricket |