blob: 544bb93b380c052def42e857a2fbb7aed1f10e71 [file] [log] [blame]
Chen Xingd2a66862019-06-03 12:53:421/*
2 * Copyright (c) 2019 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 "api/rtp_packet_infos.h"
12
Dor Henaefed552024-06-18 13:20:3513#include <stddef.h>
14
15#include "api/rtp_headers.h"
16#include "api/rtp_packet_info.h"
17#include "api/units/timestamp.h"
Chen Xingd2a66862019-06-03 12:53:4218#include "test/gmock.h"
19#include "test/gtest.h"
20
21namespace webrtc {
22namespace {
23
24using ::testing::ElementsAre;
25using ::testing::SizeIs;
26
27template <typename Iterator>
28RtpPacketInfos::vector_type ToVector(Iterator begin, Iterator end) {
29 return RtpPacketInfos::vector_type(begin, end);
30}
31
32} // namespace
33
34TEST(RtpPacketInfosTest, BasicFunctionality) {
Alessio Bazzicaa1d03562022-09-19 16:05:2935 RtpPacketInfo p0(/*ssrc=*/123, /*csrcs=*/{1, 2}, /*rtp_timestamp=*/89,
36 /*receive_time=*/Timestamp::Millis(7));
37 p0.set_audio_level(5);
38 p0.set_absolute_capture_time(AbsoluteCaptureTime{
39 .absolute_capture_timestamp = 45, .estimated_capture_clock_offset = 78});
40
41 RtpPacketInfo p1(/*ssrc=*/456, /*csrcs=*/{3, 4}, /*rtp_timestamp=*/89,
42 /*receive_time=*/Timestamp::Millis(1));
43 p1.set_audio_level(4);
44 p1.set_absolute_capture_time(AbsoluteCaptureTime{
45 .absolute_capture_timestamp = 13, .estimated_capture_clock_offset = 21});
46
47 RtpPacketInfo p2(/*ssrc=*/789, /*csrcs=*/{5, 6}, /*rtp_timestamp=*/88,
48 /*receive_time=*/Timestamp::Millis(7));
49 p2.set_audio_level(1);
50 p2.set_absolute_capture_time(AbsoluteCaptureTime{
51 .absolute_capture_timestamp = 99, .estimated_capture_clock_offset = 78});
Chen Xingd2a66862019-06-03 12:53:4252
53 RtpPacketInfos x({p0, p1, p2});
54
55 ASSERT_THAT(x, SizeIs(3));
56
57 EXPECT_EQ(x[0], p0);
58 EXPECT_EQ(x[1], p1);
59 EXPECT_EQ(x[2], p2);
60
61 EXPECT_EQ(x.front(), p0);
62 EXPECT_EQ(x.back(), p2);
63
64 EXPECT_THAT(ToVector(x.begin(), x.end()), ElementsAre(p0, p1, p2));
65 EXPECT_THAT(ToVector(x.rbegin(), x.rend()), ElementsAre(p2, p1, p0));
66
67 EXPECT_THAT(ToVector(x.cbegin(), x.cend()), ElementsAre(p0, p1, p2));
68 EXPECT_THAT(ToVector(x.crbegin(), x.crend()), ElementsAre(p2, p1, p0));
69
70 EXPECT_FALSE(x.empty());
71}
72
73TEST(RtpPacketInfosTest, CopyShareData) {
Alessio Bazzicaa1d03562022-09-19 16:05:2974 RtpPacketInfo p0(/*ssrc=*/123, /*csrcs=*/{1, 2}, /*rtp_timestamp=*/89,
75 /*receive_time=*/Timestamp::Millis(7));
76 p0.set_audio_level(5);
77 p0.set_absolute_capture_time(AbsoluteCaptureTime{
78 .absolute_capture_timestamp = 45, .estimated_capture_clock_offset = 78});
79
80 RtpPacketInfo p1(/*ssrc=*/456, /*csrcs=*/{3, 4}, /*rtp_timestamp=*/89,
81 /*receive_time=*/Timestamp::Millis(1));
82 p1.set_audio_level(4);
83 p1.set_absolute_capture_time(AbsoluteCaptureTime{
84 .absolute_capture_timestamp = 13, .estimated_capture_clock_offset = 21});
85
86 RtpPacketInfo p2(/*ssrc=*/789, /*csrcs=*/{5, 6}, /*rtp_timestamp=*/88,
87 /*receive_time=*/Timestamp::Millis(7));
88 p2.set_audio_level(1);
89 p2.set_absolute_capture_time(AbsoluteCaptureTime{
90 .absolute_capture_timestamp = 99, .estimated_capture_clock_offset = 78});
Chen Xingd2a66862019-06-03 12:53:4291
92 RtpPacketInfos lhs({p0, p1, p2});
93 RtpPacketInfos rhs = lhs;
94
95 ASSERT_THAT(lhs, SizeIs(3));
96 ASSERT_THAT(rhs, SizeIs(3));
97
98 for (size_t i = 0; i < lhs.size(); ++i) {
99 EXPECT_EQ(lhs[i], rhs[i]);
100 }
101
102 EXPECT_EQ(lhs.front(), rhs.front());
103 EXPECT_EQ(lhs.back(), rhs.back());
104
105 EXPECT_EQ(lhs.begin(), rhs.begin());
106 EXPECT_EQ(lhs.end(), rhs.end());
107 EXPECT_EQ(lhs.rbegin(), rhs.rbegin());
108 EXPECT_EQ(lhs.rend(), rhs.rend());
109
110 EXPECT_EQ(lhs.cbegin(), rhs.cbegin());
111 EXPECT_EQ(lhs.cend(), rhs.cend());
112 EXPECT_EQ(lhs.crbegin(), rhs.crbegin());
113 EXPECT_EQ(lhs.crend(), rhs.crend());
114
115 EXPECT_EQ(lhs.empty(), rhs.empty());
116}
117
118} // namespace webrtc