xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/source/capture_clock_offset_updater_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2021 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 "modules/rtp_rtcp/source/capture_clock_offset_updater.h"
12 
13 #include "system_wrappers/include/ntp_time.h"
14 #include "test/gmock.h"
15 #include "test/gtest.h"
16 
17 namespace webrtc {
18 
TEST(AbsoluteCaptureTimeReceiverTest,SkipEstimatedCaptureClockOffsetIfRemoteToLocalClockOffsetIsUnknown)19 TEST(AbsoluteCaptureTimeReceiverTest,
20      SkipEstimatedCaptureClockOffsetIfRemoteToLocalClockOffsetIsUnknown) {
21   static const absl::optional<int64_t> kRemoteCaptureClockOffset =
22       Int64MsToQ32x32(-350);
23   CaptureClockOffsetUpdater updater;
24   updater.SetRemoteToLocalClockOffset(absl::nullopt);
25   EXPECT_EQ(
26       updater.AdjustEstimatedCaptureClockOffset(kRemoteCaptureClockOffset),
27       absl::nullopt);
28 }
29 
TEST(AbsoluteCaptureTimeReceiverTest,SkipEstimatedCaptureClockOffsetIfRemoteCaptureClockOffsetIsUnknown)30 TEST(AbsoluteCaptureTimeReceiverTest,
31      SkipEstimatedCaptureClockOffsetIfRemoteCaptureClockOffsetIsUnknown) {
32   static const absl::optional<int64_t> kCaptureClockOffsetNull = absl::nullopt;
33   CaptureClockOffsetUpdater updater;
34   updater.SetRemoteToLocalClockOffset(0);
35   EXPECT_EQ(updater.AdjustEstimatedCaptureClockOffset(kCaptureClockOffsetNull),
36             kCaptureClockOffsetNull);
37 
38   static const absl::optional<int64_t> kRemoteCaptureClockOffset =
39       Int64MsToQ32x32(-350);
40   EXPECT_EQ(
41       updater.AdjustEstimatedCaptureClockOffset(kRemoteCaptureClockOffset),
42       kRemoteCaptureClockOffset);
43 }
44 
TEST(AbsoluteCaptureTimeReceiverTest,EstimatedCaptureClockOffsetArithmetic)45 TEST(AbsoluteCaptureTimeReceiverTest, EstimatedCaptureClockOffsetArithmetic) {
46   static const absl::optional<int64_t> kRemoteCaptureClockOffset =
47       Int64MsToQ32x32(-350);
48   static const absl::optional<int64_t> kRemoteToLocalClockOffset =
49       Int64MsToQ32x32(-7000007);
50   CaptureClockOffsetUpdater updater;
51   updater.SetRemoteToLocalClockOffset(kRemoteToLocalClockOffset);
52   EXPECT_THAT(
53       updater.AdjustEstimatedCaptureClockOffset(kRemoteCaptureClockOffset),
54       ::testing::Optional(::testing::Eq(*kRemoteCaptureClockOffset +
55                                         *kRemoteToLocalClockOffset)));
56 }
57 
58 }  // namespace webrtc
59