/* * Copyright (c) 2026 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/video_coding/utility/reference_buffer_tracker.h" #include #include #include #include #include "absl/algorithm/container.h" #include "api/units/timestamp.h" #include "rtc_base/checks.h" namespace webrtc { ReferenceBufferTracker::ReferenceBufferTracker(int num_buffers) : timestamps_(num_buffers) { RTC_DCHECK_GT(num_buffers, 0); } void ReferenceBufferTracker::Update(int buffer_id, Timestamp timestamp) { RTC_DCHECK_GE(buffer_id, 0); RTC_DCHECK_LT(buffer_id, num_buffers()); timestamps_[buffer_id] = timestamp; } std::optional ReferenceBufferTracker::GetTimestamp( int buffer_id) const { RTC_DCHECK_GE(buffer_id, 0); RTC_DCHECK_LT(buffer_id, num_buffers()); return timestamps_[buffer_id]; } void ReferenceBufferTracker::Reset() { std::fill(timestamps_.begin(), timestamps_.end(), std::nullopt); } std::vector ReferenceBufferTracker::OrderByTimestamp( std::span reference_buffers) const { std::vector sorted(reference_buffers.begin(), reference_buffers.end()); absl::c_stable_sort(sorted, [this](int a, int b) { return GetTimestamp(a) > GetTimestamp(b); }); return sorted; } } // namespace webrtc