mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-15 14:50:39 +01:00

Bug: webrtc:7135 Change-Id: I7ce9afe575241542e4e3f7e2e8459ee3257eec76 Reviewed-on: https://webrtc-review.googlesource.com/93466 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24271}
111 lines
4.3 KiB
C++
111 lines
4.3 KiB
C++
/*
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/rtp_rtcp/source/contributing_sources.h"
|
|
|
|
#include "rtc_base/timeutils.h"
|
|
|
|
#include "test/gmock.h"
|
|
#include "test/gtest.h"
|
|
|
|
namespace webrtc {
|
|
namespace {
|
|
|
|
using ::testing::UnorderedElementsAre;
|
|
|
|
constexpr uint32_t kCsrc1 = 111;
|
|
constexpr uint32_t kCsrc2 = 222;
|
|
constexpr uint32_t kCsrc3 = 333;
|
|
|
|
} // namespace
|
|
|
|
TEST(ContributingSourcesTest, RecordSources) {
|
|
ContributingSources csrcs;
|
|
constexpr uint32_t kCsrcs[] = {kCsrc1, kCsrc2};
|
|
constexpr int64_t kTime1 = 10;
|
|
csrcs.Update(kTime1, kCsrcs);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime1),
|
|
UnorderedElementsAre(RtpSource(kTime1, kCsrc1, RtpSourceType::CSRC),
|
|
RtpSource(kTime1, kCsrc2, RtpSourceType::CSRC)));
|
|
}
|
|
|
|
TEST(ContributingSourcesTest, UpdateSources) {
|
|
ContributingSources csrcs;
|
|
// TODO(nisse): When migrating to absl::Span, the named constant arrays should
|
|
// be replaced by unnamed literals where they are passed to csrcs.Update(...).
|
|
constexpr uint32_t kCsrcs1[] = {kCsrc1, kCsrc2};
|
|
constexpr uint32_t kCsrcs2[] = {kCsrc2, kCsrc3};
|
|
constexpr int64_t kTime1 = 10;
|
|
constexpr int64_t kTime2 = kTime1 + 5 * rtc::kNumMillisecsPerSec;
|
|
csrcs.Update(kTime1, kCsrcs1);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime1),
|
|
UnorderedElementsAre(RtpSource(kTime1, kCsrc1, RtpSourceType::CSRC),
|
|
RtpSource(kTime1, kCsrc2, RtpSourceType::CSRC)));
|
|
csrcs.Update(kTime2, kCsrcs2);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime2),
|
|
UnorderedElementsAre(RtpSource(kTime1, kCsrc1, RtpSourceType::CSRC),
|
|
RtpSource(kTime2, kCsrc2, RtpSourceType::CSRC),
|
|
RtpSource(kTime2, kCsrc3, RtpSourceType::CSRC)));
|
|
}
|
|
|
|
TEST(ContributingSourcesTest, ReturnRecentOnly) {
|
|
ContributingSources csrcs;
|
|
constexpr uint32_t kCsrcs1[] = {kCsrc1, kCsrc2};
|
|
constexpr uint32_t kCsrcs2[] = {kCsrc2, kCsrc3};
|
|
constexpr int64_t kTime1 = 10;
|
|
constexpr int64_t kTime2 = kTime1 + 5 * rtc::kNumMillisecsPerSec;
|
|
constexpr int64_t kTime3 = kTime1 + 12 * rtc::kNumMillisecsPerSec;
|
|
csrcs.Update(kTime1, kCsrcs1);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime1),
|
|
UnorderedElementsAre(RtpSource(kTime1, kCsrc1, RtpSourceType::CSRC),
|
|
RtpSource(kTime1, kCsrc2, RtpSourceType::CSRC)));
|
|
csrcs.Update(kTime2, kCsrcs2);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime3),
|
|
UnorderedElementsAre(RtpSource(kTime2, kCsrc2, RtpSourceType::CSRC),
|
|
RtpSource(kTime2, kCsrc3, RtpSourceType::CSRC)));
|
|
}
|
|
|
|
TEST(ContributingSourcesTest, PurgeOldSources) {
|
|
ContributingSources csrcs;
|
|
constexpr uint32_t kCsrcs1[] = {kCsrc1, kCsrc2};
|
|
constexpr uint32_t kCsrcs2[] = {kCsrc2, kCsrc3};
|
|
constexpr int64_t kTime1 = 10;
|
|
constexpr int64_t kTime2 = kTime1 + 10 * rtc::kNumMillisecsPerSec;
|
|
constexpr int64_t kTime3 = kTime1 + 20 * rtc::kNumMillisecsPerSec;
|
|
csrcs.Update(kTime1, kCsrcs1);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime2),
|
|
UnorderedElementsAre(RtpSource(kTime1, kCsrc1, RtpSourceType::CSRC),
|
|
RtpSource(kTime1, kCsrc2, RtpSourceType::CSRC)));
|
|
csrcs.Update(kTime2, kCsrcs2);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime2),
|
|
UnorderedElementsAre(RtpSource(kTime1, kCsrc1, RtpSourceType::CSRC),
|
|
RtpSource(kTime2, kCsrc2, RtpSourceType::CSRC),
|
|
RtpSource(kTime2, kCsrc3, RtpSourceType::CSRC)));
|
|
csrcs.Update(kTime3, kCsrcs2);
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime3),
|
|
UnorderedElementsAre(RtpSource(kTime3, kCsrc2, RtpSourceType::CSRC),
|
|
RtpSource(kTime3, kCsrc3, RtpSourceType::CSRC)));
|
|
// Query at an earlier time; check that old sources really have been purged
|
|
// and don't reappear.
|
|
EXPECT_THAT(
|
|
csrcs.GetSources(kTime2),
|
|
UnorderedElementsAre(RtpSource(kTime3, kCsrc2, RtpSourceType::CSRC),
|
|
RtpSource(kTime3, kCsrc3, RtpSourceType::CSRC)));
|
|
}
|
|
|
|
} // namespace webrtc
|