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/test/testAPI/test_api_audio.cc

Issue 2770233003: Implemented the GetSources() in native code. (Closed)
Patch Set: Address the comments related to threading and the special ContributingSource that uses the SSRC. 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
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 <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 #include <vector> 13 #include <vector>
14 14
15 #include "webrtc/base/rate_limiter.h" 15 #include "webrtc/base/rate_limiter.h"
16 #include "webrtc/common_types.h" 16 #include "webrtc/common_types.h"
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" 19 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h"
20 #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" 20 #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h"
21 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
22 22
23 namespace webrtc { 23 namespace webrtc {
24 namespace { 24 namespace {
25 25
26 const uint32_t kTestRate = 64000u; 26 const uint32_t kTestRate = 64000u;
27 const uint8_t kTestPayload[] = { 't', 'e', 's', 't' }; 27 const uint8_t kTestPayload[] = { 't', 'e', 's', 't' };
28 const uint8_t kPcmuPayloadType = 96; 28 const uint8_t kPcmuPayloadType = 96;
29 const uint8_t kDtmfPayloadType = 97; 29 const uint8_t kDtmfPayloadType = 97;
30 const int64_t kContributingSourcesTimeoutMs = 10000;
30 31
31 struct CngCodecSpec { 32 struct CngCodecSpec {
32 int payload_type; 33 int payload_type;
33 int clockrate_hz; 34 int clockrate_hz;
34 }; 35 };
35 36
36 const CngCodecSpec kCngCodecs[] = {{13, 8000}, 37 const CngCodecSpec kCngCodecs[] = {{13, 8000},
37 {103, 16000}, 38 {103, 16000},
38 {104, 32000}, 39 {104, 32000},
39 {105, 48000}}; 40 {105, 48000}};
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 in_timestamp, -1, kTestPayload, 1, 278 in_timestamp, -1, kTestPayload, 1,
278 nullptr, nullptr, nullptr)); 279 nullptr, nullptr, nullptr));
279 280
280 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); 281 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC());
281 EXPECT_TRUE(rtp_receiver2_->Timestamp(&timestamp)); 282 EXPECT_TRUE(rtp_receiver2_->Timestamp(&timestamp));
282 EXPECT_EQ(test_timestamp + in_timestamp, timestamp); 283 EXPECT_EQ(test_timestamp + in_timestamp, timestamp);
283 in_timestamp += 10; 284 in_timestamp += 10;
284 } 285 }
285 } 286 }
286 287
288 TEST_F(RtpRtcpAudioTest, GetContributingSources) {
289 int64_t timestamp = fake_clock.TimeInMilliseconds();
290 RTPHeader header;
291 header.payloadType = kPcmuPayloadType;
292 header.ssrc = 1;
293 header.timestamp = timestamp;
294 header.numCSRCs = 2;
295 header.arrOfCSRCs[0] = 111;
296 header.arrOfCSRCs[1] = 222;
297
298 CodecInst voice_codec = {};
299 voice_codec.pltype = kPcmuPayloadType;
300 voice_codec.plfreq = 8000;
301 voice_codec.rate = kTestRate;
302 memcpy(voice_codec.plname, "PCMU", 5);
303 RegisterPayload(voice_codec);
304
305 PayloadUnion payload_specific;
306 bool in_order = false;
307
308 EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4,
309 payload_specific, in_order));
310 auto sources = rtp_receiver1_->GetContributingSources();
311 // Two sources use the CSRCs and one uses the SSRC.
312 ASSERT_EQ(3u, sources.size());
313 EXPECT_EQ(222u, sources[0].source);
314 EXPECT_EQ(timestamp, sources[0].timestamp);
315 EXPECT_EQ(111u, sources[1].source);
316 EXPECT_EQ(timestamp, sources[1].timestamp);
317 EXPECT_EQ(1u, sources[2].source);
318 EXPECT_EQ(timestamp, sources[2].timestamp);
319
320 // Advance the fake clock and the method is expected to return the
321 // contributing source object with same |source| and updated |timestamp|.
322 fake_clock.AdvanceTimeMilliseconds(1);
323 EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4,
324 payload_specific, in_order));
325 sources = rtp_receiver1_->GetContributingSources();
326 ASSERT_EQ(3u, sources.size());
327 EXPECT_EQ(222u, sources[0].source);
328 EXPECT_EQ(timestamp + 1, sources[0].timestamp);
329 EXPECT_EQ(111u, sources[1].source);
330 EXPECT_EQ(timestamp + 1, sources[1].timestamp);
331 EXPECT_EQ(1u, sources[2].source);
332 EXPECT_EQ(timestamp + 1, sources[2].timestamp);
333
334 // Simulate the time out.
335 fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs + 1);
336 sources = rtp_receiver1_->GetContributingSources();
337 // The sources using the CSRCs should be out of date.
338 ASSERT_EQ(1u, sources.size());
339 EXPECT_EQ(1u, sources[0].source);
340 EXPECT_EQ(timestamp + 1, sources[0].timestamp);
341 }
342
343 // Test that when the SSRC is changed, it returns an object for the old SSRC for
344 // 10 seconds after it switches.
345 TEST_F(RtpRtcpAudioTest, GetContributingSourcesChangeSSRC) {
346 int64_t timestamp = fake_clock.TimeInMilliseconds();
347 RTPHeader header;
348 header.payloadType = kPcmuPayloadType;
349 header.ssrc = 1;
350 header.timestamp = timestamp;
351
352 CodecInst voice_codec = {};
353 voice_codec.pltype = kPcmuPayloadType;
354 voice_codec.plfreq = 8000;
355 voice_codec.rate = kTestRate;
356 memcpy(voice_codec.plname, "PCMU", 5);
357 RegisterPayload(voice_codec);
358
359 PayloadUnion payload_specific;
360 bool in_order = false;
361
362 EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4,
363 payload_specific, in_order));
364 auto sources = rtp_receiver1_->GetContributingSources();
365 ASSERT_EQ(1u, sources.size());
366 EXPECT_EQ(1u, sources[0].source);
367 EXPECT_EQ(timestamp, sources[0].timestamp);
368
369 header.ssrc = 2;
370 fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs);
371 EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4,
372 payload_specific, in_order));
373 sources = rtp_receiver1_->GetContributingSources();
374 // Return the old SSRC since it is not out of date.
375 ASSERT_EQ(1u, sources.size());
376 EXPECT_EQ(1u, sources[0].source);
377 EXPECT_EQ(timestamp, sources[0].timestamp);
378
379 fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs + 1);
380 EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4,
381 payload_specific, in_order));
382 sources = rtp_receiver1_->GetContributingSources();
383 // Return new SSRC and new timestamp.
384 ASSERT_EQ(1u, sources.size());
385 EXPECT_EQ(2u, sources[0].source);
386 EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[0].timestamp);
387 }
388
287 } // namespace webrtc 389 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698