Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: webrtc/media/base/videoadapter.cc

Issue 2764133002: Revert of Add framerate to VideoSinkWants and ability to signal on overuse (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/media/base/videoadapter.h ('k') | webrtc/media/base/videoadapter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 VideoAdapter::VideoAdapter(int required_resolution_alignment) 100 VideoAdapter::VideoAdapter(int required_resolution_alignment)
101 : frames_in_(0), 101 : frames_in_(0),
102 frames_out_(0), 102 frames_out_(0),
103 frames_scaled_(0), 103 frames_scaled_(0),
104 adaption_changes_(0), 104 adaption_changes_(0),
105 previous_width_(0), 105 previous_width_(0),
106 previous_height_(0), 106 previous_height_(0),
107 required_resolution_alignment_(required_resolution_alignment), 107 required_resolution_alignment_(required_resolution_alignment),
108 resolution_request_target_pixel_count_(std::numeric_limits<int>::max()), 108 resolution_request_target_pixel_count_(std::numeric_limits<int>::max()),
109 resolution_request_max_pixel_count_(std::numeric_limits<int>::max()), 109 resolution_request_max_pixel_count_(std::numeric_limits<int>::max()) {}
110 max_framerate_request_(std::numeric_limits<int>::max()) {}
111 110
112 VideoAdapter::VideoAdapter() : VideoAdapter(1) {} 111 VideoAdapter::VideoAdapter() : VideoAdapter(1) {}
113 112
114 VideoAdapter::~VideoAdapter() {} 113 VideoAdapter::~VideoAdapter() {}
115 114
116 bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) { 115 bool VideoAdapter::KeepFrame(int64_t in_timestamp_ns) {
117 rtc::CritScope cs(&critical_section_); 116 rtc::CritScope cs(&critical_section_);
118 if (max_framerate_request_ <= 0) 117 if (!requested_format_ || requested_format_->interval == 0)
119 return false;
120
121 int64_t frame_interval_ns =
122 requested_format_ ? requested_format_->interval : 0;
123
124 // If |max_framerate_request_| is not set, it will default to maxint, which
125 // will lead to a frame_interval_ns rounded to 0.
126 frame_interval_ns = std::max<int64_t>(
127 frame_interval_ns, rtc::kNumNanosecsPerSec / max_framerate_request_);
128
129 if (frame_interval_ns <= 0) {
130 // Frame rate throttling not enabled.
131 return true; 118 return true;
132 }
133 119
134 if (next_frame_timestamp_ns_) { 120 if (next_frame_timestamp_ns_) {
135 // Time until next frame should be outputted. 121 // Time until next frame should be outputted.
136 const int64_t time_until_next_frame_ns = 122 const int64_t time_until_next_frame_ns =
137 (*next_frame_timestamp_ns_ - in_timestamp_ns); 123 (*next_frame_timestamp_ns_ - in_timestamp_ns);
138 124
139 // Continue if timestamp is within expected range. 125 // Continue if timestamp is withing expected range.
140 if (std::abs(time_until_next_frame_ns) < 2 * frame_interval_ns) { 126 if (std::abs(time_until_next_frame_ns) < 2 * requested_format_->interval) {
141 // Drop if a frame shouldn't be outputted yet. 127 // Drop if a frame shouldn't be outputted yet.
142 if (time_until_next_frame_ns > 0) 128 if (time_until_next_frame_ns > 0)
143 return false; 129 return false;
144 // Time to output new frame. 130 // Time to output new frame.
145 *next_frame_timestamp_ns_ += frame_interval_ns; 131 *next_frame_timestamp_ns_ += requested_format_->interval;
146 return true; 132 return true;
147 } 133 }
148 } 134 }
149 135
150 // First timestamp received or timestamp is way outside expected range, so 136 // First timestamp received or timestamp is way outside expected range, so
151 // reset. Set first timestamp target to just half the interval to prefer 137 // reset. Set first timestamp target to just half the interval to prefer
152 // keeping frames in case of jitter. 138 // keeping frames in case of jitter.
153 next_frame_timestamp_ns_ = 139 next_frame_timestamp_ns_ =
154 rtc::Optional<int64_t>(in_timestamp_ns + frame_interval_ns / 2); 140 rtc::Optional<int64_t>(in_timestamp_ns + requested_format_->interval / 2);
155 return true; 141 return true;
156 } 142 }
157 143
158 bool VideoAdapter::AdaptFrameResolution(int in_width, 144 bool VideoAdapter::AdaptFrameResolution(int in_width,
159 int in_height, 145 int in_height,
160 int64_t in_timestamp_ns, 146 int64_t in_timestamp_ns,
161 int* cropped_width, 147 int* cropped_width,
162 int* cropped_height, 148 int* cropped_height,
163 int* out_width, 149 int* out_width,
164 int* out_height) { 150 int* out_height) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 242
257 return true; 243 return true;
258 } 244 }
259 245
260 void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) { 246 void VideoAdapter::OnOutputFormatRequest(const VideoFormat& format) {
261 rtc::CritScope cs(&critical_section_); 247 rtc::CritScope cs(&critical_section_);
262 requested_format_ = rtc::Optional<VideoFormat>(format); 248 requested_format_ = rtc::Optional<VideoFormat>(format);
263 next_frame_timestamp_ns_ = rtc::Optional<int64_t>(); 249 next_frame_timestamp_ns_ = rtc::Optional<int64_t>();
264 } 250 }
265 251
266 void VideoAdapter::OnResolutionFramerateRequest( 252 void VideoAdapter::OnResolutionRequest(
267 const rtc::Optional<int>& target_pixel_count, 253 const rtc::Optional<int>& target_pixel_count,
268 int max_pixel_count, 254 const rtc::Optional<int>& max_pixel_count) {
269 int max_framerate_fps) {
270 rtc::CritScope cs(&critical_section_); 255 rtc::CritScope cs(&critical_section_);
271 resolution_request_max_pixel_count_ = max_pixel_count; 256 resolution_request_max_pixel_count_ =
257 max_pixel_count.value_or(std::numeric_limits<int>::max());
272 resolution_request_target_pixel_count_ = 258 resolution_request_target_pixel_count_ =
273 target_pixel_count.value_or(resolution_request_max_pixel_count_); 259 target_pixel_count.value_or(resolution_request_max_pixel_count_);
274 max_framerate_request_ = max_framerate_fps;
275 } 260 }
276 261
277 } // namespace cricket 262 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/base/videoadapter.h ('k') | webrtc/media/base/videoadapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698