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

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

Issue 2290203002: Delete Timing class, timing.h, and update all users. (Closed)
Patch Set: New helper rtc::WallTimeSeconds. Created 4 years, 3 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
« webrtc/base/timeutils.cc ('K') | « webrtc/media/base/rtpdataengine.cc ('k') | no next file » | 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) 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
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "webrtc/base/copyonwritebuffer.h" 14 #include "webrtc/base/copyonwritebuffer.h"
15 #include "webrtc/base/gunit.h" 15 #include "webrtc/base/gunit.h"
16 #include "webrtc/base/helpers.h" 16 #include "webrtc/base/helpers.h"
17 #include "webrtc/base/ssladapter.h" 17 #include "webrtc/base/ssladapter.h"
18 #include "webrtc/base/timing.h"
19 #include "webrtc/media/base/fakenetworkinterface.h" 18 #include "webrtc/media/base/fakenetworkinterface.h"
20 #include "webrtc/media/base/mediaconstants.h" 19 #include "webrtc/media/base/mediaconstants.h"
21 #include "webrtc/media/base/rtpdataengine.h" 20 #include "webrtc/media/base/rtpdataengine.h"
22 #include "webrtc/media/base/rtputils.h" 21 #include "webrtc/media/base/rtputils.h"
23 22
24 class FakeTiming : public rtc::Timing {
25 public:
26 FakeTiming() : now_(0.0) {}
27
28 virtual double TimerNow() {
29 return now_;
30 }
31
32 void set_now(double now) {
33 now_ = now;
34 }
35
36 private:
37 double now_;
38 };
39
40 class FakeDataReceiver : public sigslot::has_slots<> { 23 class FakeDataReceiver : public sigslot::has_slots<> {
41 public: 24 public:
42 FakeDataReceiver() : has_received_data_(false) {} 25 FakeDataReceiver() : has_received_data_(false) {}
43 26
44 void OnDataReceived( 27 void OnDataReceived(
45 const cricket::ReceiveDataParams& params, 28 const cricket::ReceiveDataParams& params,
46 const char* data, size_t len) { 29 const char* data, size_t len) {
47 has_received_data_ = true; 30 has_received_data_ = true;
48 last_received_data_ = std::string(data, len); 31 last_received_data_ = std::string(data, len);
49 last_received_data_len_ = len; 32 last_received_data_len_ = len;
(...skipping 12 matching lines...) Expand all
62 std::string last_received_data_; 45 std::string last_received_data_;
63 size_t last_received_data_len_; 46 size_t last_received_data_len_;
64 cricket::ReceiveDataParams last_received_data_params_; 47 cricket::ReceiveDataParams last_received_data_params_;
65 }; 48 };
66 49
67 class RtpDataMediaChannelTest : public testing::Test { 50 class RtpDataMediaChannelTest : public testing::Test {
68 protected: 51 protected:
69 virtual void SetUp() { 52 virtual void SetUp() {
70 // Seed needed for each test to satisfy expectations. 53 // Seed needed for each test to satisfy expectations.
71 iface_.reset(new cricket::FakeNetworkInterface()); 54 iface_.reset(new cricket::FakeNetworkInterface());
72 timing_ = new FakeTiming(); 55 dme_.reset(CreateEngine());
73 dme_.reset(CreateEngine(timing_));
74 receiver_.reset(new FakeDataReceiver()); 56 receiver_.reset(new FakeDataReceiver());
75 } 57 }
76 58
77 void SetNow(double now) { 59 void SetNow(double now) {
78 timing_->set_now(now); 60 clock_.SetTimeNanos(now * rtc::kNumNanosecsPerSec);
79 } 61 }
80 62
81 cricket::RtpDataEngine* CreateEngine(FakeTiming* timing) { 63 cricket::RtpDataEngine* CreateEngine() {
82 cricket::RtpDataEngine* dme = new cricket::RtpDataEngine(); 64 cricket::RtpDataEngine* dme = new cricket::RtpDataEngine();
83 dme->SetTiming(timing);
84 return dme; 65 return dme;
85 } 66 }
86 67
87 cricket::RtpDataMediaChannel* CreateChannel() { 68 cricket::RtpDataMediaChannel* CreateChannel() {
88 return CreateChannel(dme_.get()); 69 return CreateChannel(dme_.get());
89 } 70 }
90 71
91 cricket::RtpDataMediaChannel* CreateChannel(cricket::RtpDataEngine* dme) { 72 cricket::RtpDataMediaChannel* CreateChannel(cricket::RtpDataEngine* dme) {
92 cricket::RtpDataMediaChannel* channel = 73 cricket::RtpDataMediaChannel* channel =
93 static_cast<cricket::RtpDataMediaChannel*>(dme->CreateChannel( 74 static_cast<cricket::RtpDataMediaChannel*>(dme->CreateChannel(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 cricket::RtpHeader GetSentDataHeader(int index) { 117 cricket::RtpHeader GetSentDataHeader(int index) {
137 std::unique_ptr<const rtc::CopyOnWriteBuffer> packet( 118 std::unique_ptr<const rtc::CopyOnWriteBuffer> packet(
138 iface_->GetRtpPacket(index)); 119 iface_->GetRtpPacket(index));
139 cricket::RtpHeader header; 120 cricket::RtpHeader header;
140 GetRtpHeader(packet->data(), packet->size(), &header); 121 GetRtpHeader(packet->data(), packet->size(), &header);
141 return header; 122 return header;
142 } 123 }
143 124
144 private: 125 private:
145 std::unique_ptr<cricket::RtpDataEngine> dme_; 126 std::unique_ptr<cricket::RtpDataEngine> dme_;
146 // Timing passed into dme_. Owned by dme_; 127 rtc::ScopedFakeClock clock_;
147 FakeTiming* timing_;
148 std::unique_ptr<cricket::FakeNetworkInterface> iface_; 128 std::unique_ptr<cricket::FakeNetworkInterface> iface_;
149 std::unique_ptr<FakeDataReceiver> receiver_; 129 std::unique_ptr<FakeDataReceiver> receiver_;
150 }; 130 };
151 131
152 TEST_F(RtpDataMediaChannelTest, SetUnknownCodecs) { 132 TEST_F(RtpDataMediaChannelTest, SetUnknownCodecs) {
153 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); 133 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
154 134
155 cricket::DataCodec known_codec; 135 cricket::DataCodec known_codec;
156 known_codec.id = 103; 136 known_codec.id = 103;
157 known_codec.name = "google-data"; 137 known_codec.name = "google-data";
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 padded_data, GetSentData(1).data(), sizeof(padded_data))); 264 padded_data, GetSentData(1).data(), sizeof(padded_data)));
285 cricket::RtpHeader header1 = GetSentDataHeader(1); 265 cricket::RtpHeader header1 = GetSentDataHeader(1);
286 EXPECT_EQ(header1.ssrc, 42U); 266 EXPECT_EQ(header1.ssrc, 42U);
287 EXPECT_EQ(header1.payload_type, 103); 267 EXPECT_EQ(header1.payload_type, 103);
288 EXPECT_EQ(static_cast<uint16_t>(header0.seq_num + 1), 268 EXPECT_EQ(static_cast<uint16_t>(header0.seq_num + 1),
289 static_cast<uint16_t>(header1.seq_num)); 269 static_cast<uint16_t>(header1.seq_num));
290 EXPECT_EQ(header0.timestamp + 180000, header1.timestamp); 270 EXPECT_EQ(header0.timestamp + 180000, header1.timestamp);
291 } 271 }
292 272
293 TEST_F(RtpDataMediaChannelTest, SendDataMultipleClocks) { 273 TEST_F(RtpDataMediaChannelTest, SendDataMultipleClocks) {
294 // Timings owned by RtpDataEngines. 274 std::unique_ptr<cricket::RtpDataEngine> dme1(CreateEngine());
295 FakeTiming* timing1 = new FakeTiming();
296 std::unique_ptr<cricket::RtpDataEngine> dme1(CreateEngine(timing1));
297 std::unique_ptr<cricket::RtpDataMediaChannel> dmc1( 275 std::unique_ptr<cricket::RtpDataMediaChannel> dmc1(
298 CreateChannel(dme1.get())); 276 CreateChannel(dme1.get()));
299 FakeTiming* timing2 = new FakeTiming(); 277 std::unique_ptr<cricket::RtpDataEngine> dme2(CreateEngine());
300 std::unique_ptr<cricket::RtpDataEngine> dme2(CreateEngine(timing2));
301 std::unique_ptr<cricket::RtpDataMediaChannel> dmc2( 278 std::unique_ptr<cricket::RtpDataMediaChannel> dmc2(
302 CreateChannel(dme2.get())); 279 CreateChannel(dme2.get()));
303 280
304 ASSERT_TRUE(dmc1->SetSend(true)); 281 ASSERT_TRUE(dmc1->SetSend(true));
305 ASSERT_TRUE(dmc2->SetSend(true)); 282 ASSERT_TRUE(dmc2->SetSend(true));
306 283
307 cricket::StreamParams stream1; 284 cricket::StreamParams stream1;
308 stream1.add_ssrc(41); 285 stream1.add_ssrc(41);
309 ASSERT_TRUE(dmc1->AddSendStream(stream1)); 286 ASSERT_TRUE(dmc1->AddSendStream(stream1));
310 cricket::StreamParams stream2; 287 cricket::StreamParams stream2;
(...skipping 14 matching lines...) Expand all
325 params2.ssrc = 42; 302 params2.ssrc = 42;
326 303
327 unsigned char data[] = "foo"; 304 unsigned char data[] = "foo";
328 rtc::CopyOnWriteBuffer payload(data, 3); 305 rtc::CopyOnWriteBuffer payload(data, 3);
329 cricket::SendDataResult result; 306 cricket::SendDataResult result;
330 307
331 EXPECT_TRUE(dmc1->SendData(params1, payload, &result)); 308 EXPECT_TRUE(dmc1->SendData(params1, payload, &result));
332 EXPECT_TRUE(dmc2->SendData(params2, payload, &result)); 309 EXPECT_TRUE(dmc2->SendData(params2, payload, &result));
333 310
334 // Should bump timestamp by 90000 because the clock rate is 90khz. 311 // Should bump timestamp by 90000 because the clock rate is 90khz.
335 timing1->set_now(1); 312 SetNow(1);
313 EXPECT_TRUE(dmc1->SendData(params1, payload, &result));
336 // Should bump timestamp by 180000 because the clock rate is 90khz. 314 // Should bump timestamp by 180000 because the clock rate is 90khz.
337 timing2->set_now(2); 315 SetNow(2);
338
339 EXPECT_TRUE(dmc1->SendData(params1, payload, &result));
340 EXPECT_TRUE(dmc2->SendData(params2, payload, &result)); 316 EXPECT_TRUE(dmc2->SendData(params2, payload, &result));
341 317
342 ASSERT_TRUE(HasSentData(3)); 318 ASSERT_TRUE(HasSentData(3));
343 cricket::RtpHeader header1a = GetSentDataHeader(0); 319 cricket::RtpHeader header1a = GetSentDataHeader(0);
344 cricket::RtpHeader header2a = GetSentDataHeader(1); 320 cricket::RtpHeader header2a = GetSentDataHeader(1);
345 cricket::RtpHeader header1b = GetSentDataHeader(2); 321 cricket::RtpHeader header1b = GetSentDataHeader(2);
346 cricket::RtpHeader header2b = GetSentDataHeader(3); 322 cricket::RtpHeader header2b = GetSentDataHeader(3);
347 323
348 EXPECT_EQ(static_cast<uint16_t>(header1a.seq_num + 1), 324 EXPECT_EQ(static_cast<uint16_t>(header1a.seq_num + 1),
349 static_cast<uint16_t>(header1b.seq_num)); 325 static_cast<uint16_t>(header1b.seq_num));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 0x80, 0x65, 0x00, 0x02 427 0x80, 0x65, 0x00, 0x02
452 }; 428 };
453 rtc::CopyOnWriteBuffer packet(data, sizeof(data)); 429 rtc::CopyOnWriteBuffer packet(data, sizeof(data));
454 430
455 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); 431 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel());
456 432
457 // Too short 433 // Too short
458 dmc->OnPacketReceived(&packet, rtc::PacketTime()); 434 dmc->OnPacketReceived(&packet, rtc::PacketTime());
459 EXPECT_FALSE(HasReceivedData()); 435 EXPECT_FALSE(HasReceivedData());
460 } 436 }
OLDNEW
« webrtc/base/timeutils.cc ('K') | « webrtc/media/base/rtpdataengine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698