capture_clock_offset_updater.cc (1514B)
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 <cstdint> 14 #include <optional> 15 16 #include "api/units/time_delta.h" 17 #include "system_wrappers/include/ntp_time.h" 18 19 namespace webrtc { 20 21 std::optional<int64_t> 22 CaptureClockOffsetUpdater::AdjustEstimatedCaptureClockOffset( 23 std::optional<int64_t> remote_capture_clock_offset) const { 24 if (remote_capture_clock_offset == std::nullopt || 25 remote_to_local_clock_offset_ == std::nullopt) { 26 return std::nullopt; 27 } 28 29 // Do calculations as "unsigned" to make overflows deterministic. 30 return static_cast<uint64_t>(*remote_capture_clock_offset) + 31 static_cast<uint64_t>(*remote_to_local_clock_offset_); 32 } 33 34 std::optional<TimeDelta> CaptureClockOffsetUpdater::ConvertToTimeDelta( 35 std::optional<int64_t> q32x32) { 36 if (q32x32 == std::nullopt) { 37 return std::nullopt; 38 } 39 return TimeDelta::Millis(Q32x32ToInt64Ms(*q32x32)); 40 } 41 42 void CaptureClockOffsetUpdater::SetRemoteToLocalClockOffset( 43 std::optional<int64_t> offset_q32x32) { 44 remote_to_local_clock_offset_ = offset_q32x32; 45 } 46 47 } // namespace webrtc