OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ - 1); | 159 stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ - 1); |
160 stream.max_framerate = framerate_; | 160 stream.max_framerate = framerate_; |
161 } | 161 } |
162 return streams; | 162 return streams; |
163 } | 163 } |
164 | 164 |
165 const size_t num_temporal_layers_; | 165 const size_t num_temporal_layers_; |
166 const int framerate_; | 166 const int framerate_; |
167 }; | 167 }; |
168 | 168 |
| 169 |
169 class AdaptingFrameForwarder : public test::FrameForwarder { | 170 class AdaptingFrameForwarder : public test::FrameForwarder { |
170 public: | 171 public: |
171 AdaptingFrameForwarder() : adaptation_enabled_(false) {} | 172 AdaptingFrameForwarder() : adaptation_enabled_(false) {} |
172 ~AdaptingFrameForwarder() override {} | 173 ~AdaptingFrameForwarder() override {} |
173 | 174 |
174 void set_adaptation_enabled(bool enabled) { | 175 void set_adaptation_enabled(bool enabled) { |
175 rtc::CritScope cs(&crit_); | 176 rtc::CritScope cs(&crit_); |
176 adaptation_enabled_ = enabled; | 177 adaptation_enabled_ = enabled; |
177 } | 178 } |
178 | 179 |
(...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2937 | 2938 |
2938 // Trigger adapt up, expect no change. | 2939 // Trigger adapt up, expect no change. |
2939 vie_encoder_->TriggerQualityHigh(); | 2940 vie_encoder_->TriggerQualityHigh(); |
2940 VerifyNoLimitation(source.sink_wants()); | 2941 VerifyNoLimitation(source.sink_wants()); |
2941 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); | 2942 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
2942 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); | 2943 EXPECT_EQ(2, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
2943 | 2944 |
2944 vie_encoder_->Stop(); | 2945 vie_encoder_->Stop(); |
2945 } | 2946 } |
2946 | 2947 |
| 2948 TEST_F(ViEEncoderTest, AcceptsFullHdAdaptedDownSimulcastFrames) { |
| 2949 // Simulates simulcast behavior and makes highest stream resolutions divisible |
| 2950 // by 4. |
| 2951 class CroppingVideoStreamFactory |
| 2952 : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 2953 public: |
| 2954 explicit CroppingVideoStreamFactory(size_t num_temporal_layers, |
| 2955 int framerate) |
| 2956 : num_temporal_layers_(num_temporal_layers), framerate_(framerate) { |
| 2957 EXPECT_GT(num_temporal_layers, 0u); |
| 2958 EXPECT_GT(framerate, 0); |
| 2959 } |
| 2960 |
| 2961 private: |
| 2962 std::vector<VideoStream> CreateEncoderStreams( |
| 2963 int width, |
| 2964 int height, |
| 2965 const VideoEncoderConfig& encoder_config) override { |
| 2966 std::vector<VideoStream> streams = |
| 2967 test::CreateVideoStreams(width - width % 4, height - height % 4, |
| 2968 encoder_config); |
| 2969 for (VideoStream& stream : streams) { |
| 2970 stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ - 1); |
| 2971 stream.max_framerate = framerate_; |
| 2972 } |
| 2973 return streams; |
| 2974 } |
| 2975 |
| 2976 const size_t num_temporal_layers_; |
| 2977 const int framerate_; |
| 2978 }; |
| 2979 |
| 2980 const int kFrameWidth = 1920; |
| 2981 const int kFrameHeight = 1080; |
| 2982 // 3/4 of 1920. |
| 2983 const int kAdaptedFrameWidth = 1440; |
| 2984 // 3/4 of 1080 rounded down to multiple of 4. |
| 2985 const int kAdaptedFrameHeight = 808; |
| 2986 const int kFramerate = 24; |
| 2987 |
| 2988 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
| 2989 // Trigger reconfigure encoder (without resetting the entire instance). |
| 2990 VideoEncoderConfig video_encoder_config; |
| 2991 video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
| 2992 video_encoder_config.number_of_streams = 1; |
| 2993 video_encoder_config.video_stream_factory = |
| 2994 new rtc::RefCountedObject<CroppingVideoStreamFactory>(1, kFramerate); |
| 2995 vie_encoder_->ConfigureEncoder(std::move(video_encoder_config), |
| 2996 kMaxPayloadLength, false); |
| 2997 vie_encoder_->WaitUntilTaskQueueIsIdle(); |
| 2998 |
| 2999 video_source_.set_adaptation_enabled(true); |
| 3000 |
| 3001 video_source_.IncomingCapturedFrame( |
| 3002 CreateFrame(1, kFrameWidth, kFrameHeight)); |
| 3003 sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
| 3004 |
| 3005 // Trigger CPU overuse, downscale by 3/4. |
| 3006 vie_encoder_->TriggerCpuOveruse(); |
| 3007 video_source_.IncomingCapturedFrame( |
| 3008 CreateFrame(2, kFrameWidth, kFrameHeight)); |
| 3009 sink_.WaitForEncodedFrame(kAdaptedFrameWidth, kAdaptedFrameHeight); |
| 3010 |
| 3011 vie_encoder_->Stop(); |
| 3012 } |
| 3013 |
| 3014 |
2947 } // namespace webrtc | 3015 } // namespace webrtc |
OLD | NEW |