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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_receiver_unittest.cc

Issue 2770233003: Implemented the GetSources() in native code. (Closed)
Patch Set: Fix the BUILD file. Created 3 years, 8 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12
13 #include "webrtc/common_types.h"
14 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
18 #include "webrtc/test/gtest.h"
19
20 namespace webrtc {
21
22 const int64_t kContributingSourcesTimeoutMs = 10000;
23 const uint32_t kTestRate = 64000u;
24 const uint8_t kTestPayload[] = {'t', 'e', 's', 't'};
25 const uint8_t kPcmuPayloadType = 96;
26
27 class RtpReceiverTest : public ::testing::Test {
28 protected:
29 RtpReceiverTest() : fake_clock(123456) {}
30 ~RtpReceiverTest() {}
31
32 void SetUp() override {
33 rtp_payload_registry_.reset(new RTPPayloadRegistry());
34
35 rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver(
36 &fake_clock, nullptr, nullptr, rtp_payload_registry_.get()));
37
38 CodecInst voice_codec = {};
39 voice_codec.pltype = kPcmuPayloadType;
40 voice_codec.plfreq = 8000;
41 voice_codec.rate = kTestRate;
42 memcpy(voice_codec.plname, "PCMU", 5);
43 rtp_receiver_->RegisterReceivePayload(voice_codec);
44 }
45
46 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
47 std::unique_ptr<RtpReceiver> rtp_receiver_;
48 SimulatedClock fake_clock;
49 };
50
51 TEST_F(RtpReceiverTest, GetContributingSources) {
52 int64_t timestamp = fake_clock.TimeInMilliseconds();
53 RTPHeader header;
54 header.payloadType = kPcmuPayloadType;
55 header.ssrc = 1;
56 header.timestamp = timestamp;
57 header.numCSRCs = 2;
58 header.arrOfCSRCs[0] = 111;
59 header.arrOfCSRCs[1] = 222;
60 PayloadUnion payload_specific;
61 bool in_order = false;
62
63 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
64 payload_specific, in_order));
65 auto sources = rtp_receiver_->GetContributingSources();
66 // Two sources use the CSRCs and one uses the SSRC.
67 ASSERT_EQ(3u, sources.size());
68 EXPECT_EQ(222u, sources[0].source());
69 EXPECT_EQ(timestamp, sources[0].timestamp());
70 EXPECT_EQ(111u, sources[1].source());
71 EXPECT_EQ(timestamp, sources[1].timestamp());
72 EXPECT_EQ(1u, sources[2].ssrc());
73 EXPECT_EQ(1u, sources[2].source());
74 EXPECT_EQ(timestamp, sources[2].timestamp());
75
76 // Advance the fake clock and the method is expected to return the
77 // contributing source object with same |source| and updated |timestamp()|.
78 fake_clock.AdvanceTimeMilliseconds(1);
79 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
80 payload_specific, in_order));
81 sources = rtp_receiver_->GetContributingSources();
82 ASSERT_EQ(3u, sources.size());
83 EXPECT_EQ(222u, sources[0].source());
84 EXPECT_EQ(timestamp + 1, sources[0].timestamp());
85 EXPECT_EQ(111u, sources[1].source());
86 EXPECT_EQ(timestamp + 1, sources[1].timestamp());
87 EXPECT_EQ(1u, sources[2].ssrc());
88 EXPECT_EQ(1u, sources[2].source());
89 EXPECT_EQ(timestamp + 1, sources[2].timestamp());
90
91 // Simulate the time out.
92 fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs + 1);
93 sources = rtp_receiver_->GetContributingSources();
94 // All the sources should be out of date.
95 ASSERT_EQ(0u, sources.size());
96 }
97
98 // Test the cases that the SSRC is changed.
99 TEST_F(RtpReceiverTest, GetContributingSourcesChangeSSRC) {
100 int64_t prev_time = -1;
101 int64_t cur_time = fake_clock.TimeInMilliseconds();
102 RTPHeader header;
103 header.payloadType = kPcmuPayloadType;
104 header.ssrc = 1;
105 header.timestamp = cur_time;
106 PayloadUnion payload_specific;
107 bool in_order = false;
108
109 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
110 payload_specific, in_order));
111 auto sources = rtp_receiver_->GetContributingSources();
112 ASSERT_EQ(1u, sources.size());
113 EXPECT_EQ(1u, sources[0].source());
114 EXPECT_EQ(cur_time, sources[0].timestamp());
115
116 // The SSRC is changed and the old SSRC is expected to be returned.
117 fake_clock.AdvanceTimeMilliseconds(100);
118 prev_time = cur_time;
119 cur_time = fake_clock.TimeInMilliseconds();
120 header.ssrc = 2;
121 header.timestamp = cur_time;
122 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
123 payload_specific, in_order));
124 sources = rtp_receiver_->GetContributingSources();
125 ASSERT_EQ(2u, sources.size());
126 EXPECT_EQ(2u, sources[0].source());
127 EXPECT_EQ(cur_time, sources[0].timestamp());
128 EXPECT_EQ(1u, sources[1].source());
129 EXPECT_EQ(prev_time, sources[1].timestamp());
130
131 // The SSRC is changed again and happen to be changed back to 1. No
132 // duplication is expected.
133 fake_clock.AdvanceTimeMilliseconds(100);
134 header.ssrc = 1;
135 header.timestamp = cur_time;
136 prev_time = cur_time;
137 cur_time = fake_clock.TimeInMilliseconds();
138 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
139 payload_specific, in_order));
140 sources = rtp_receiver_->GetContributingSources();
141 ASSERT_EQ(2u, sources.size());
142 EXPECT_EQ(1u, sources[0].source());
143 EXPECT_EQ(cur_time, sources[0].timestamp());
144 EXPECT_EQ(2u, sources[1].source());
145 EXPECT_EQ(prev_time, sources[1].timestamp());
146
147 // Old SSRC source timeout.
148 fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs);
149 cur_time = fake_clock.TimeInMilliseconds();
150 EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
151 payload_specific, in_order));
152 sources = rtp_receiver_->GetContributingSources();
153 ASSERT_EQ(1u, sources.size());
154 EXPECT_EQ(1u, sources[0].source());
155 EXPECT_EQ(cur_time, sources[0].timestamp());
156 }
157
158 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698