OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include <algorithm> // max | 10 #include <algorithm> // max |
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 // New bitrate should be reconfigured above the previous max. As there's no | 1186 // New bitrate should be reconfigured above the previous max. As there's no |
1187 // network connection this shouldn't be flaky, as no bitrate should've been | 1187 // network connection this shouldn't be flaky, as no bitrate should've been |
1188 // reported in between. | 1188 // reported in between. |
1189 EXPECT_TRUE(encoder.WaitForStartBitrate()); | 1189 EXPECT_TRUE(encoder.WaitForStartBitrate()); |
1190 EXPECT_EQ(bitrate_config.start_bitrate_bps / 1000, | 1190 EXPECT_EQ(bitrate_config.start_bitrate_bps / 1000, |
1191 encoder.GetStartBitrateKbps()); | 1191 encoder.GetStartBitrateKbps()); |
1192 | 1192 |
1193 DestroyStreams(); | 1193 DestroyStreams(); |
1194 } | 1194 } |
1195 | 1195 |
| 1196 // This test that if the encoder use an internal source, VideoEncoder::SetRates |
| 1197 // will be called with zero bitrate during initialization and that |
| 1198 // VideoSendStream::Stop also triggers VideoEncoder::SetRates Start to be called |
| 1199 // with zero bitrate. |
| 1200 TEST_F(VideoSendStreamTest, VideoSendStreamStopSetEncoderRateToZero) { |
| 1201 class StartStopBitrateObserver : public test::FakeEncoder { |
| 1202 public: |
| 1203 StartStopBitrateObserver() |
| 1204 : FakeEncoder(Clock::GetRealTimeClock()), |
| 1205 encoder_init_(false, false), |
| 1206 bitrate_changed_(false, false), |
| 1207 bitrate_kbps_(0) {} |
| 1208 int32_t InitEncode(const VideoCodec* config, |
| 1209 int32_t number_of_cores, |
| 1210 size_t max_payload_size) override { |
| 1211 rtc::CritScope lock(&crit_); |
| 1212 bitrate_kbps_ = config->startBitrate; |
| 1213 encoder_init_.Set(); |
| 1214 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 1215 } |
| 1216 |
| 1217 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override { |
| 1218 rtc::CritScope lock(&crit_); |
| 1219 bitrate_kbps_ = new_target_bitrate; |
| 1220 bitrate_changed_.Set(); |
| 1221 return FakeEncoder::SetRates(new_target_bitrate, framerate); |
| 1222 } |
| 1223 |
| 1224 int GetBitrateKbps() const { |
| 1225 rtc::CritScope lock(&crit_); |
| 1226 return bitrate_kbps_; |
| 1227 } |
| 1228 |
| 1229 bool WaitForEncoderInit() { |
| 1230 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); |
| 1231 } |
| 1232 bool WaitBitrateChanged() { |
| 1233 return bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); |
| 1234 } |
| 1235 |
| 1236 private: |
| 1237 rtc::CriticalSection crit_; |
| 1238 rtc::Event encoder_init_; |
| 1239 rtc::Event bitrate_changed_; |
| 1240 int bitrate_kbps_ GUARDED_BY(crit_); |
| 1241 }; |
| 1242 |
| 1243 CreateSenderCall(Call::Config()); |
| 1244 |
| 1245 test::NullTransport transport; |
| 1246 CreateSendConfig(1, 0, &transport); |
| 1247 |
| 1248 StartStopBitrateObserver encoder; |
| 1249 video_send_config_.encoder_settings.encoder = &encoder; |
| 1250 video_send_config_.encoder_settings.internal_source = true; |
| 1251 |
| 1252 CreateVideoStreams(); |
| 1253 |
| 1254 EXPECT_TRUE(encoder.WaitForEncoderInit()); |
| 1255 EXPECT_GT(encoder.GetBitrateKbps(), 0); |
| 1256 video_send_stream_->Start(); |
| 1257 EXPECT_TRUE(encoder.WaitBitrateChanged()); |
| 1258 EXPECT_GT(encoder.GetBitrateKbps(), 0); |
| 1259 video_send_stream_->Stop(); |
| 1260 EXPECT_TRUE(encoder.WaitBitrateChanged()); |
| 1261 EXPECT_EQ(0, encoder.GetBitrateKbps()); |
| 1262 video_send_stream_->Start(); |
| 1263 EXPECT_TRUE(encoder.WaitBitrateChanged()); |
| 1264 EXPECT_GT(encoder.GetBitrateKbps(), 0); |
| 1265 |
| 1266 DestroyStreams(); |
| 1267 } |
| 1268 |
1196 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) { | 1269 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) { |
1197 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> { | 1270 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> { |
1198 public: | 1271 public: |
1199 FrameObserver() : output_frame_event_(false, false) {} | 1272 FrameObserver() : output_frame_event_(false, false) {} |
1200 | 1273 |
1201 void OnFrame(const VideoFrame& video_frame) override { | 1274 void OnFrame(const VideoFrame& video_frame) override { |
1202 output_frames_.push_back(video_frame); | 1275 output_frames_.push_back(video_frame); |
1203 output_frame_event_.Set(); | 1276 output_frame_event_.Set(); |
1204 } | 1277 } |
1205 | 1278 |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 observation_complete_.Set(); | 2376 observation_complete_.Set(); |
2304 } | 2377 } |
2305 } | 2378 } |
2306 } test; | 2379 } test; |
2307 | 2380 |
2308 RunBaseTest(&test); | 2381 RunBaseTest(&test); |
2309 } | 2382 } |
2310 #endif // !defined(RTC_DISABLE_VP9) | 2383 #endif // !defined(RTC_DISABLE_VP9) |
2311 | 2384 |
2312 } // namespace webrtc | 2385 } // namespace webrtc |
OLD | NEW |