1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker *
4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker */
10*d9f75844SAndroid Build Coastguard Worker #include <functional>
11*d9f75844SAndroid Build Coastguard Worker #include <list>
12*d9f75844SAndroid Build Coastguard Worker #include <memory>
13*d9f75844SAndroid Build Coastguard Worker #include <string>
14*d9f75844SAndroid Build Coastguard Worker
15*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
16*d9f75844SAndroid Build Coastguard Worker #include "api/test/create_frame_generator.h"
17*d9f75844SAndroid Build Coastguard Worker #include "call/call.h"
18*d9f75844SAndroid Build Coastguard Worker #include "call/fake_network_pipe.h"
19*d9f75844SAndroid Build Coastguard Worker #include "call/simulated_network.h"
20*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/checks.h"
21*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/event.h"
22*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/logging.h"
23*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/synchronization/mutex.h"
24*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/task_queue_for_test.h"
25*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread_annotations.h"
26*d9f75844SAndroid Build Coastguard Worker #include "test/call_test.h"
27*d9f75844SAndroid Build Coastguard Worker #include "test/direct_transport.h"
28*d9f75844SAndroid Build Coastguard Worker #include "test/encoder_settings.h"
29*d9f75844SAndroid Build Coastguard Worker #include "test/fake_decoder.h"
30*d9f75844SAndroid Build Coastguard Worker #include "test/fake_encoder.h"
31*d9f75844SAndroid Build Coastguard Worker #include "test/frame_generator_capturer.h"
32*d9f75844SAndroid Build Coastguard Worker #include "test/gtest.h"
33*d9f75844SAndroid Build Coastguard Worker
34*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
35*d9f75844SAndroid Build Coastguard Worker namespace {
36*d9f75844SAndroid Build Coastguard Worker // Note: If you consider to re-use this class, think twice and instead consider
37*d9f75844SAndroid Build Coastguard Worker // writing tests that don't depend on the logging system.
38*d9f75844SAndroid Build Coastguard Worker class LogObserver {
39*d9f75844SAndroid Build Coastguard Worker public:
LogObserver()40*d9f75844SAndroid Build Coastguard Worker LogObserver() { rtc::LogMessage::AddLogToStream(&callback_, rtc::LS_INFO); }
41*d9f75844SAndroid Build Coastguard Worker
~LogObserver()42*d9f75844SAndroid Build Coastguard Worker ~LogObserver() { rtc::LogMessage::RemoveLogToStream(&callback_); }
43*d9f75844SAndroid Build Coastguard Worker
PushExpectedLogLine(absl::string_view expected_log_line)44*d9f75844SAndroid Build Coastguard Worker void PushExpectedLogLine(absl::string_view expected_log_line) {
45*d9f75844SAndroid Build Coastguard Worker callback_.PushExpectedLogLine(expected_log_line);
46*d9f75844SAndroid Build Coastguard Worker }
47*d9f75844SAndroid Build Coastguard Worker
Wait()48*d9f75844SAndroid Build Coastguard Worker bool Wait() { return callback_.Wait(); }
49*d9f75844SAndroid Build Coastguard Worker
50*d9f75844SAndroid Build Coastguard Worker private:
51*d9f75844SAndroid Build Coastguard Worker class Callback : public rtc::LogSink {
52*d9f75844SAndroid Build Coastguard Worker public:
OnLogMessage(const std::string & message)53*d9f75844SAndroid Build Coastguard Worker void OnLogMessage(const std::string& message) override {
54*d9f75844SAndroid Build Coastguard Worker OnLogMessage(absl::string_view(message));
55*d9f75844SAndroid Build Coastguard Worker }
56*d9f75844SAndroid Build Coastguard Worker
OnLogMessage(absl::string_view message)57*d9f75844SAndroid Build Coastguard Worker void OnLogMessage(absl::string_view message) override {
58*d9f75844SAndroid Build Coastguard Worker MutexLock lock(&mutex_);
59*d9f75844SAndroid Build Coastguard Worker // Ignore log lines that are due to missing AST extensions, these are
60*d9f75844SAndroid Build Coastguard Worker // logged when we switch back from AST to TOF until the wrapping bitrate
61*d9f75844SAndroid Build Coastguard Worker // estimator gives up on using AST.
62*d9f75844SAndroid Build Coastguard Worker if (message.find("BitrateEstimator") != absl::string_view::npos &&
63*d9f75844SAndroid Build Coastguard Worker message.find("packet is missing") == absl::string_view::npos) {
64*d9f75844SAndroid Build Coastguard Worker received_log_lines_.push_back(std::string(message));
65*d9f75844SAndroid Build Coastguard Worker }
66*d9f75844SAndroid Build Coastguard Worker
67*d9f75844SAndroid Build Coastguard Worker int num_popped = 0;
68*d9f75844SAndroid Build Coastguard Worker while (!received_log_lines_.empty() && !expected_log_lines_.empty()) {
69*d9f75844SAndroid Build Coastguard Worker std::string a = received_log_lines_.front();
70*d9f75844SAndroid Build Coastguard Worker std::string b = expected_log_lines_.front();
71*d9f75844SAndroid Build Coastguard Worker received_log_lines_.pop_front();
72*d9f75844SAndroid Build Coastguard Worker expected_log_lines_.pop_front();
73*d9f75844SAndroid Build Coastguard Worker num_popped++;
74*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(a.find(b) != absl::string_view::npos) << a << " != " << b;
75*d9f75844SAndroid Build Coastguard Worker }
76*d9f75844SAndroid Build Coastguard Worker if (expected_log_lines_.empty()) {
77*d9f75844SAndroid Build Coastguard Worker if (num_popped > 0) {
78*d9f75844SAndroid Build Coastguard Worker done_.Set();
79*d9f75844SAndroid Build Coastguard Worker }
80*d9f75844SAndroid Build Coastguard Worker return;
81*d9f75844SAndroid Build Coastguard Worker }
82*d9f75844SAndroid Build Coastguard Worker }
83*d9f75844SAndroid Build Coastguard Worker
Wait()84*d9f75844SAndroid Build Coastguard Worker bool Wait() { return done_.Wait(test::CallTest::kDefaultTimeout); }
85*d9f75844SAndroid Build Coastguard Worker
PushExpectedLogLine(absl::string_view expected_log_line)86*d9f75844SAndroid Build Coastguard Worker void PushExpectedLogLine(absl::string_view expected_log_line) {
87*d9f75844SAndroid Build Coastguard Worker MutexLock lock(&mutex_);
88*d9f75844SAndroid Build Coastguard Worker expected_log_lines_.emplace_back(expected_log_line);
89*d9f75844SAndroid Build Coastguard Worker }
90*d9f75844SAndroid Build Coastguard Worker
91*d9f75844SAndroid Build Coastguard Worker private:
92*d9f75844SAndroid Build Coastguard Worker typedef std::list<std::string> Strings;
93*d9f75844SAndroid Build Coastguard Worker Mutex mutex_;
94*d9f75844SAndroid Build Coastguard Worker Strings received_log_lines_ RTC_GUARDED_BY(mutex_);
95*d9f75844SAndroid Build Coastguard Worker Strings expected_log_lines_ RTC_GUARDED_BY(mutex_);
96*d9f75844SAndroid Build Coastguard Worker rtc::Event done_;
97*d9f75844SAndroid Build Coastguard Worker };
98*d9f75844SAndroid Build Coastguard Worker
99*d9f75844SAndroid Build Coastguard Worker Callback callback_;
100*d9f75844SAndroid Build Coastguard Worker };
101*d9f75844SAndroid Build Coastguard Worker } // namespace
102*d9f75844SAndroid Build Coastguard Worker
103*d9f75844SAndroid Build Coastguard Worker static const int kTOFExtensionId = 4;
104*d9f75844SAndroid Build Coastguard Worker static const int kASTExtensionId = 5;
105*d9f75844SAndroid Build Coastguard Worker
106*d9f75844SAndroid Build Coastguard Worker class BitrateEstimatorTest : public test::CallTest {
107*d9f75844SAndroid Build Coastguard Worker public:
BitrateEstimatorTest()108*d9f75844SAndroid Build Coastguard Worker BitrateEstimatorTest() : receive_config_(nullptr) {}
109*d9f75844SAndroid Build Coastguard Worker
~BitrateEstimatorTest()110*d9f75844SAndroid Build Coastguard Worker virtual ~BitrateEstimatorTest() { EXPECT_TRUE(streams_.empty()); }
111*d9f75844SAndroid Build Coastguard Worker
SetUp()112*d9f75844SAndroid Build Coastguard Worker virtual void SetUp() {
113*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
114*d9f75844SAndroid Build Coastguard Worker CreateCalls();
115*d9f75844SAndroid Build Coastguard Worker
116*d9f75844SAndroid Build Coastguard Worker send_transport_.reset(new test::DirectTransport(
117*d9f75844SAndroid Build Coastguard Worker task_queue(),
118*d9f75844SAndroid Build Coastguard Worker std::make_unique<FakeNetworkPipe>(
119*d9f75844SAndroid Build Coastguard Worker Clock::GetRealTimeClock(), std::make_unique<SimulatedNetwork>(
120*d9f75844SAndroid Build Coastguard Worker BuiltInNetworkBehaviorConfig())),
121*d9f75844SAndroid Build Coastguard Worker sender_call_.get(), payload_type_map_));
122*d9f75844SAndroid Build Coastguard Worker send_transport_->SetReceiver(receiver_call_->Receiver());
123*d9f75844SAndroid Build Coastguard Worker receive_transport_.reset(new test::DirectTransport(
124*d9f75844SAndroid Build Coastguard Worker task_queue(),
125*d9f75844SAndroid Build Coastguard Worker std::make_unique<FakeNetworkPipe>(
126*d9f75844SAndroid Build Coastguard Worker Clock::GetRealTimeClock(), std::make_unique<SimulatedNetwork>(
127*d9f75844SAndroid Build Coastguard Worker BuiltInNetworkBehaviorConfig())),
128*d9f75844SAndroid Build Coastguard Worker receiver_call_.get(), payload_type_map_));
129*d9f75844SAndroid Build Coastguard Worker receive_transport_->SetReceiver(sender_call_->Receiver());
130*d9f75844SAndroid Build Coastguard Worker
131*d9f75844SAndroid Build Coastguard Worker VideoSendStream::Config video_send_config(send_transport_.get());
132*d9f75844SAndroid Build Coastguard Worker video_send_config.rtp.ssrcs.push_back(kVideoSendSsrcs[0]);
133*d9f75844SAndroid Build Coastguard Worker video_send_config.encoder_settings.encoder_factory =
134*d9f75844SAndroid Build Coastguard Worker &fake_encoder_factory_;
135*d9f75844SAndroid Build Coastguard Worker video_send_config.encoder_settings.bitrate_allocator_factory =
136*d9f75844SAndroid Build Coastguard Worker bitrate_allocator_factory_.get();
137*d9f75844SAndroid Build Coastguard Worker video_send_config.rtp.payload_name = "FAKE";
138*d9f75844SAndroid Build Coastguard Worker video_send_config.rtp.payload_type = kFakeVideoSendPayloadType;
139*d9f75844SAndroid Build Coastguard Worker SetVideoSendConfig(video_send_config);
140*d9f75844SAndroid Build Coastguard Worker VideoEncoderConfig video_encoder_config;
141*d9f75844SAndroid Build Coastguard Worker test::FillEncoderConfiguration(kVideoCodecVP8, 1, &video_encoder_config);
142*d9f75844SAndroid Build Coastguard Worker SetVideoEncoderConfig(video_encoder_config);
143*d9f75844SAndroid Build Coastguard Worker
144*d9f75844SAndroid Build Coastguard Worker receive_config_ =
145*d9f75844SAndroid Build Coastguard Worker VideoReceiveStreamInterface::Config(receive_transport_.get());
146*d9f75844SAndroid Build Coastguard Worker // receive_config_.decoders will be set by every stream separately.
147*d9f75844SAndroid Build Coastguard Worker receive_config_.rtp.remote_ssrc = GetVideoSendConfig()->rtp.ssrcs[0];
148*d9f75844SAndroid Build Coastguard Worker receive_config_.rtp.local_ssrc = kReceiverLocalVideoSsrc;
149*d9f75844SAndroid Build Coastguard Worker receive_config_.rtp.extensions.push_back(
150*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId));
151*d9f75844SAndroid Build Coastguard Worker receive_config_.rtp.extensions.push_back(
152*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId));
153*d9f75844SAndroid Build Coastguard Worker });
154*d9f75844SAndroid Build Coastguard Worker }
155*d9f75844SAndroid Build Coastguard Worker
TearDown()156*d9f75844SAndroid Build Coastguard Worker virtual void TearDown() {
157*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
158*d9f75844SAndroid Build Coastguard Worker for (auto* stream : streams_) {
159*d9f75844SAndroid Build Coastguard Worker stream->StopSending();
160*d9f75844SAndroid Build Coastguard Worker delete stream;
161*d9f75844SAndroid Build Coastguard Worker }
162*d9f75844SAndroid Build Coastguard Worker streams_.clear();
163*d9f75844SAndroid Build Coastguard Worker
164*d9f75844SAndroid Build Coastguard Worker send_transport_.reset();
165*d9f75844SAndroid Build Coastguard Worker receive_transport_.reset();
166*d9f75844SAndroid Build Coastguard Worker
167*d9f75844SAndroid Build Coastguard Worker DestroyCalls();
168*d9f75844SAndroid Build Coastguard Worker });
169*d9f75844SAndroid Build Coastguard Worker }
170*d9f75844SAndroid Build Coastguard Worker
171*d9f75844SAndroid Build Coastguard Worker protected:
172*d9f75844SAndroid Build Coastguard Worker friend class Stream;
173*d9f75844SAndroid Build Coastguard Worker
174*d9f75844SAndroid Build Coastguard Worker class Stream {
175*d9f75844SAndroid Build Coastguard Worker public:
Stream(BitrateEstimatorTest * test)176*d9f75844SAndroid Build Coastguard Worker explicit Stream(BitrateEstimatorTest* test)
177*d9f75844SAndroid Build Coastguard Worker : test_(test),
178*d9f75844SAndroid Build Coastguard Worker is_sending_receiving_(false),
179*d9f75844SAndroid Build Coastguard Worker send_stream_(nullptr),
180*d9f75844SAndroid Build Coastguard Worker frame_generator_capturer_(),
181*d9f75844SAndroid Build Coastguard Worker decoder_factory_(
182*d9f75844SAndroid Build Coastguard Worker []() { return std::make_unique<test::FakeDecoder>(); }) {
183*d9f75844SAndroid Build Coastguard Worker test_->GetVideoSendConfig()->rtp.ssrcs[0]++;
184*d9f75844SAndroid Build Coastguard Worker send_stream_ = test_->sender_call_->CreateVideoSendStream(
185*d9f75844SAndroid Build Coastguard Worker test_->GetVideoSendConfig()->Copy(),
186*d9f75844SAndroid Build Coastguard Worker test_->GetVideoEncoderConfig()->Copy());
187*d9f75844SAndroid Build Coastguard Worker RTC_DCHECK_EQ(1, test_->GetVideoEncoderConfig()->number_of_streams);
188*d9f75844SAndroid Build Coastguard Worker frame_generator_capturer_ =
189*d9f75844SAndroid Build Coastguard Worker std::make_unique<test::FrameGeneratorCapturer>(
190*d9f75844SAndroid Build Coastguard Worker test->clock_,
191*d9f75844SAndroid Build Coastguard Worker test::CreateSquareFrameGenerator(kDefaultWidth, kDefaultHeight,
192*d9f75844SAndroid Build Coastguard Worker absl::nullopt, absl::nullopt),
193*d9f75844SAndroid Build Coastguard Worker kDefaultFramerate, *test->task_queue_factory_);
194*d9f75844SAndroid Build Coastguard Worker frame_generator_capturer_->Init();
195*d9f75844SAndroid Build Coastguard Worker send_stream_->SetSource(frame_generator_capturer_.get(),
196*d9f75844SAndroid Build Coastguard Worker DegradationPreference::MAINTAIN_FRAMERATE);
197*d9f75844SAndroid Build Coastguard Worker send_stream_->Start();
198*d9f75844SAndroid Build Coastguard Worker
199*d9f75844SAndroid Build Coastguard Worker VideoReceiveStreamInterface::Decoder decoder;
200*d9f75844SAndroid Build Coastguard Worker test_->receive_config_.decoder_factory = &decoder_factory_;
201*d9f75844SAndroid Build Coastguard Worker decoder.payload_type = test_->GetVideoSendConfig()->rtp.payload_type;
202*d9f75844SAndroid Build Coastguard Worker decoder.video_format =
203*d9f75844SAndroid Build Coastguard Worker SdpVideoFormat(test_->GetVideoSendConfig()->rtp.payload_name);
204*d9f75844SAndroid Build Coastguard Worker test_->receive_config_.decoders.clear();
205*d9f75844SAndroid Build Coastguard Worker test_->receive_config_.decoders.push_back(decoder);
206*d9f75844SAndroid Build Coastguard Worker test_->receive_config_.rtp.remote_ssrc =
207*d9f75844SAndroid Build Coastguard Worker test_->GetVideoSendConfig()->rtp.ssrcs[0];
208*d9f75844SAndroid Build Coastguard Worker test_->receive_config_.rtp.local_ssrc++;
209*d9f75844SAndroid Build Coastguard Worker test_->receive_config_.renderer = &test->fake_renderer_;
210*d9f75844SAndroid Build Coastguard Worker video_receive_stream_ = test_->receiver_call_->CreateVideoReceiveStream(
211*d9f75844SAndroid Build Coastguard Worker test_->receive_config_.Copy());
212*d9f75844SAndroid Build Coastguard Worker video_receive_stream_->Start();
213*d9f75844SAndroid Build Coastguard Worker is_sending_receiving_ = true;
214*d9f75844SAndroid Build Coastguard Worker }
215*d9f75844SAndroid Build Coastguard Worker
~Stream()216*d9f75844SAndroid Build Coastguard Worker ~Stream() {
217*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(is_sending_receiving_);
218*d9f75844SAndroid Build Coastguard Worker test_->sender_call_->DestroyVideoSendStream(send_stream_);
219*d9f75844SAndroid Build Coastguard Worker frame_generator_capturer_.reset(nullptr);
220*d9f75844SAndroid Build Coastguard Worker send_stream_ = nullptr;
221*d9f75844SAndroid Build Coastguard Worker if (video_receive_stream_) {
222*d9f75844SAndroid Build Coastguard Worker test_->receiver_call_->DestroyVideoReceiveStream(video_receive_stream_);
223*d9f75844SAndroid Build Coastguard Worker video_receive_stream_ = nullptr;
224*d9f75844SAndroid Build Coastguard Worker }
225*d9f75844SAndroid Build Coastguard Worker }
226*d9f75844SAndroid Build Coastguard Worker
StopSending()227*d9f75844SAndroid Build Coastguard Worker void StopSending() {
228*d9f75844SAndroid Build Coastguard Worker if (is_sending_receiving_) {
229*d9f75844SAndroid Build Coastguard Worker send_stream_->Stop();
230*d9f75844SAndroid Build Coastguard Worker if (video_receive_stream_) {
231*d9f75844SAndroid Build Coastguard Worker video_receive_stream_->Stop();
232*d9f75844SAndroid Build Coastguard Worker }
233*d9f75844SAndroid Build Coastguard Worker is_sending_receiving_ = false;
234*d9f75844SAndroid Build Coastguard Worker }
235*d9f75844SAndroid Build Coastguard Worker }
236*d9f75844SAndroid Build Coastguard Worker
237*d9f75844SAndroid Build Coastguard Worker private:
238*d9f75844SAndroid Build Coastguard Worker BitrateEstimatorTest* test_;
239*d9f75844SAndroid Build Coastguard Worker bool is_sending_receiving_;
240*d9f75844SAndroid Build Coastguard Worker VideoSendStream* send_stream_;
241*d9f75844SAndroid Build Coastguard Worker VideoReceiveStreamInterface* video_receive_stream_;
242*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
243*d9f75844SAndroid Build Coastguard Worker
244*d9f75844SAndroid Build Coastguard Worker test::FunctionVideoDecoderFactory decoder_factory_;
245*d9f75844SAndroid Build Coastguard Worker };
246*d9f75844SAndroid Build Coastguard Worker
247*d9f75844SAndroid Build Coastguard Worker LogObserver receiver_log_;
248*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<test::DirectTransport> send_transport_;
249*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<test::DirectTransport> receive_transport_;
250*d9f75844SAndroid Build Coastguard Worker VideoReceiveStreamInterface::Config receive_config_;
251*d9f75844SAndroid Build Coastguard Worker std::vector<Stream*> streams_;
252*d9f75844SAndroid Build Coastguard Worker };
253*d9f75844SAndroid Build Coastguard Worker
254*d9f75844SAndroid Build Coastguard Worker static const char* kAbsSendTimeLog =
255*d9f75844SAndroid Build Coastguard Worker "RemoteBitrateEstimatorAbsSendTime: Instantiating.";
256*d9f75844SAndroid Build Coastguard Worker static const char* kSingleStreamLog =
257*d9f75844SAndroid Build Coastguard Worker "RemoteBitrateEstimatorSingleStream: Instantiating.";
258*d9f75844SAndroid Build Coastguard Worker
TEST_F(BitrateEstimatorTest,InstantiatesTOFPerDefaultForVideo)259*d9f75844SAndroid Build Coastguard Worker TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) {
260*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
261*d9f75844SAndroid Build Coastguard Worker GetVideoSendConfig()->rtp.extensions.push_back(
262*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId));
263*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
264*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
265*d9f75844SAndroid Build Coastguard Worker streams_.push_back(new Stream(this));
266*d9f75844SAndroid Build Coastguard Worker });
267*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(receiver_log_.Wait());
268*d9f75844SAndroid Build Coastguard Worker }
269*d9f75844SAndroid Build Coastguard Worker
TEST_F(BitrateEstimatorTest,ImmediatelySwitchToASTForVideo)270*d9f75844SAndroid Build Coastguard Worker TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) {
271*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
272*d9f75844SAndroid Build Coastguard Worker GetVideoSendConfig()->rtp.extensions.push_back(
273*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId));
274*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
275*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
276*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
277*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
278*d9f75844SAndroid Build Coastguard Worker streams_.push_back(new Stream(this));
279*d9f75844SAndroid Build Coastguard Worker });
280*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(receiver_log_.Wait());
281*d9f75844SAndroid Build Coastguard Worker }
282*d9f75844SAndroid Build Coastguard Worker
TEST_F(BitrateEstimatorTest,SwitchesToASTForVideo)283*d9f75844SAndroid Build Coastguard Worker TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) {
284*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
285*d9f75844SAndroid Build Coastguard Worker GetVideoSendConfig()->rtp.extensions.push_back(
286*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId));
287*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
288*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
289*d9f75844SAndroid Build Coastguard Worker streams_.push_back(new Stream(this));
290*d9f75844SAndroid Build Coastguard Worker });
291*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(receiver_log_.Wait());
292*d9f75844SAndroid Build Coastguard Worker
293*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
294*d9f75844SAndroid Build Coastguard Worker GetVideoSendConfig()->rtp.extensions[0] =
295*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId);
296*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
297*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
298*d9f75844SAndroid Build Coastguard Worker streams_.push_back(new Stream(this));
299*d9f75844SAndroid Build Coastguard Worker });
300*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(receiver_log_.Wait());
301*d9f75844SAndroid Build Coastguard Worker }
302*d9f75844SAndroid Build Coastguard Worker
303*d9f75844SAndroid Build Coastguard Worker // This test is flaky. See webrtc:5790.
TEST_F(BitrateEstimatorTest,DISABLED_SwitchesToASTThenBackToTOFForVideo)304*d9f75844SAndroid Build Coastguard Worker TEST_F(BitrateEstimatorTest, DISABLED_SwitchesToASTThenBackToTOFForVideo) {
305*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
306*d9f75844SAndroid Build Coastguard Worker GetVideoSendConfig()->rtp.extensions.push_back(
307*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId));
308*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
309*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
310*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kSingleStreamLog);
311*d9f75844SAndroid Build Coastguard Worker streams_.push_back(new Stream(this));
312*d9f75844SAndroid Build Coastguard Worker });
313*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(receiver_log_.Wait());
314*d9f75844SAndroid Build Coastguard Worker
315*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
316*d9f75844SAndroid Build Coastguard Worker GetVideoSendConfig()->rtp.extensions[0] =
317*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId);
318*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
319*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
320*d9f75844SAndroid Build Coastguard Worker streams_.push_back(new Stream(this));
321*d9f75844SAndroid Build Coastguard Worker });
322*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(receiver_log_.Wait());
323*d9f75844SAndroid Build Coastguard Worker
324*d9f75844SAndroid Build Coastguard Worker SendTask(task_queue(), [this]() {
325*d9f75844SAndroid Build Coastguard Worker GetVideoSendConfig()->rtp.extensions[0] =
326*d9f75844SAndroid Build Coastguard Worker RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId);
327*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
328*d9f75844SAndroid Build Coastguard Worker receiver_log_.PushExpectedLogLine(
329*d9f75844SAndroid Build Coastguard Worker "WrappingBitrateEstimator: Switching to transmission time offset RBE.");
330*d9f75844SAndroid Build Coastguard Worker streams_.push_back(new Stream(this));
331*d9f75844SAndroid Build Coastguard Worker streams_[0]->StopSending();
332*d9f75844SAndroid Build Coastguard Worker streams_[1]->StopSending();
333*d9f75844SAndroid Build Coastguard Worker });
334*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(receiver_log_.Wait());
335*d9f75844SAndroid Build Coastguard Worker }
336*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc
337