OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 20 matching lines...) Expand all Loading... |
31 #include "webrtc/rtc_base/trace_event.h" | 31 #include "webrtc/rtc_base/trace_event.h" |
32 #include "webrtc/video/overuse_frame_detector.h" | 32 #include "webrtc/video/overuse_frame_detector.h" |
33 #include "webrtc/video/send_statistics_proxy.h" | 33 #include "webrtc/video/send_statistics_proxy.h" |
34 | 34 |
35 namespace webrtc { | 35 namespace webrtc { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Time interval for logging frame counts. | 39 // Time interval for logging frame counts. |
40 const int64_t kFrameLogIntervalMs = 60000; | 40 const int64_t kFrameLogIntervalMs = 60000; |
41 | |
42 // We will never ask for a resolution lower than this. | |
43 // TODO(kthelgason): Lower this limit when better testing | |
44 // on MediaCodec and fallback implementations are in place. | |
45 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=7206 | |
46 const int kMinPixelsPerFrame = 320 * 180; | |
47 const int kMinFramerateFps = 2; | 41 const int kMinFramerateFps = 2; |
48 const int kMaxFramerateFps = 120; | 42 const int kMaxFramerateFps = 120; |
49 | 43 |
50 // The maximum number of frames to drop at beginning of stream | 44 // The maximum number of frames to drop at beginning of stream |
51 // to try and achieve desired bitrate. | 45 // to try and achieve desired bitrate. |
52 const int kMaxInitialFramedrop = 4; | 46 const int kMaxInitialFramedrop = 4; |
53 | 47 |
54 uint32_t MaximumFrameSizeForBitrate(uint32_t kbps) { | 48 uint32_t MaximumFrameSizeForBitrate(uint32_t kbps) { |
55 if (kbps > 0) { | 49 if (kbps > 0) { |
56 if (kbps < 300 /* qvga */) { | 50 if (kbps < 300 /* qvga */) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 220 |
227 void ResetPixelFpsCount() { | 221 void ResetPixelFpsCount() { |
228 rtc::CritScope lock(&crit_); | 222 rtc::CritScope lock(&crit_); |
229 sink_wants_.max_pixel_count = std::numeric_limits<int>::max(); | 223 sink_wants_.max_pixel_count = std::numeric_limits<int>::max(); |
230 sink_wants_.target_pixel_count.reset(); | 224 sink_wants_.target_pixel_count.reset(); |
231 sink_wants_.max_framerate_fps = std::numeric_limits<int>::max(); | 225 sink_wants_.max_framerate_fps = std::numeric_limits<int>::max(); |
232 if (source_) | 226 if (source_) |
233 source_->AddOrUpdateSink(video_stream_encoder_, sink_wants_); | 227 source_->AddOrUpdateSink(video_stream_encoder_, sink_wants_); |
234 } | 228 } |
235 | 229 |
236 bool RequestResolutionLowerThan(int pixel_count) { | 230 bool RequestResolutionLowerThan(int pixel_count, int min_pixels_per_frame) { |
237 // Called on the encoder task queue. | 231 // Called on the encoder task queue. |
238 rtc::CritScope lock(&crit_); | 232 rtc::CritScope lock(&crit_); |
239 if (!source_ || !IsResolutionScalingEnabled(degradation_preference_)) { | 233 if (!source_ || !IsResolutionScalingEnabled(degradation_preference_)) { |
240 // This can happen since |degradation_preference_| is set on libjingle's | 234 // This can happen since |degradation_preference_| is set on libjingle's |
241 // worker thread but the adaptation is done on the encoder task queue. | 235 // worker thread but the adaptation is done on the encoder task queue. |
242 return false; | 236 return false; |
243 } | 237 } |
244 // The input video frame size will have a resolution less than or equal to | 238 // The input video frame size will have a resolution less than or equal to |
245 // |max_pixel_count| depending on how the source can scale the frame size. | 239 // |max_pixel_count| depending on how the source can scale the frame size. |
246 const int pixels_wanted = (pixel_count * 3) / 5; | 240 const int pixels_wanted = (pixel_count * 3) / 5; |
247 if (pixels_wanted < kMinPixelsPerFrame || | 241 if (pixels_wanted < min_pixels_per_frame || |
248 pixels_wanted >= sink_wants_.max_pixel_count) { | 242 pixels_wanted >= sink_wants_.max_pixel_count) { |
249 return false; | 243 return false; |
250 } | 244 } |
251 LOG(LS_INFO) << "Scaling down resolution, max pixels: " << pixels_wanted; | 245 LOG(LS_INFO) << "Scaling down resolution, max pixels: " << pixels_wanted; |
252 sink_wants_.max_pixel_count = pixels_wanted; | 246 sink_wants_.max_pixel_count = pixels_wanted; |
253 sink_wants_.target_pixel_count = rtc::Optional<int>(); | 247 sink_wants_.target_pixel_count = rtc::Optional<int>(); |
254 source_->AddOrUpdateSink(video_stream_encoder_, | 248 source_->AddOrUpdateSink(video_stream_encoder_, |
255 GetActiveSinkWantsInternal()); | 249 GetActiveSinkWantsInternal()); |
256 return true; | 250 return true; |
257 } | 251 } |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 if (source_proxy_->RestrictFramerate(fps)) { | 977 if (source_proxy_->RestrictFramerate(fps)) { |
984 GetAdaptCounter().IncrementFramerate(reason); | 978 GetAdaptCounter().IncrementFramerate(reason); |
985 break; | 979 break; |
986 } | 980 } |
987 // Scale down resolution. | 981 // Scale down resolution. |
988 FALLTHROUGH(); | 982 FALLTHROUGH(); |
989 } | 983 } |
990 case VideoSendStream::DegradationPreference::kMaintainFramerate: | 984 case VideoSendStream::DegradationPreference::kMaintainFramerate: |
991 // Scale down resolution. | 985 // Scale down resolution. |
992 if (!source_proxy_->RequestResolutionLowerThan( | 986 if (!source_proxy_->RequestResolutionLowerThan( |
993 adaptation_request.input_pixel_count_)) { | 987 adaptation_request.input_pixel_count_, |
| 988 settings_.encoder->GetScalingSettings().min_pixels_per_frame)) { |
994 return; | 989 return; |
995 } | 990 } |
996 GetAdaptCounter().IncrementResolution(reason); | 991 GetAdaptCounter().IncrementResolution(reason); |
997 break; | 992 break; |
998 case VideoSendStream::DegradationPreference::kMaintainResolution: { | 993 case VideoSendStream::DegradationPreference::kMaintainResolution: { |
999 // Scale down framerate. | 994 // Scale down framerate. |
1000 const int requested_framerate = source_proxy_->RequestFramerateLowerThan( | 995 const int requested_framerate = source_proxy_->RequestFramerateLowerThan( |
1001 adaptation_request.framerate_fps_); | 996 adaptation_request.framerate_fps_); |
1002 if (requested_framerate == -1) | 997 if (requested_framerate == -1) |
1003 return; | 998 return; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 std::string VideoStreamEncoder::AdaptCounter::ToString( | 1252 std::string VideoStreamEncoder::AdaptCounter::ToString( |
1258 const std::vector<int>& counters) const { | 1253 const std::vector<int>& counters) const { |
1259 std::stringstream ss; | 1254 std::stringstream ss; |
1260 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { | 1255 for (size_t reason = 0; reason < kScaleReasonSize; ++reason) { |
1261 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; | 1256 ss << (reason ? " cpu" : "quality") << ":" << counters[reason]; |
1262 } | 1257 } |
1263 return ss.str(); | 1258 return ss.str(); |
1264 } | 1259 } |
1265 | 1260 |
1266 } // namespace webrtc | 1261 } // namespace webrtc |
OLD | NEW |