You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2011 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. #include "modules/video_coding/timestamp_map.h"
  11. #include <stdlib.h>
  12. #include "modules/include/module_common_types_public.h"
  13. namespace webrtc {
  14. VCMTimestampMap::VCMTimestampMap(size_t capacity)
  15. : ring_buffer_(new TimestampDataTuple[capacity]),
  16. capacity_(capacity),
  17. next_add_idx_(0),
  18. next_pop_idx_(0) {}
  19. VCMTimestampMap::~VCMTimestampMap() {}
  20. void VCMTimestampMap::Add(uint32_t timestamp, VCMFrameInformation* data) {
  21. ring_buffer_[next_add_idx_].timestamp = timestamp;
  22. ring_buffer_[next_add_idx_].data = data;
  23. next_add_idx_ = (next_add_idx_ + 1) % capacity_;
  24. if (next_add_idx_ == next_pop_idx_) {
  25. // Circular list full; forget oldest entry.
  26. next_pop_idx_ = (next_pop_idx_ + 1) % capacity_;
  27. }
  28. }
  29. VCMFrameInformation* VCMTimestampMap::Pop(uint32_t timestamp) {
  30. while (!IsEmpty()) {
  31. if (ring_buffer_[next_pop_idx_].timestamp == timestamp) {
  32. // Found start time for this timestamp.
  33. VCMFrameInformation* data = ring_buffer_[next_pop_idx_].data;
  34. ring_buffer_[next_pop_idx_].data = nullptr;
  35. next_pop_idx_ = (next_pop_idx_ + 1) % capacity_;
  36. return data;
  37. } else if (IsNewerTimestamp(ring_buffer_[next_pop_idx_].timestamp,
  38. timestamp)) {
  39. // The timestamp we are looking for is not in the list.
  40. return nullptr;
  41. }
  42. // Not in this position, check next (and forget this position).
  43. next_pop_idx_ = (next_pop_idx_ + 1) % capacity_;
  44. }
  45. // Could not find matching timestamp in list.
  46. return nullptr;
  47. }
  48. bool VCMTimestampMap::IsEmpty() const {
  49. return (next_add_idx_ == next_pop_idx_);
  50. }
  51. } // namespace webrtc