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.

129 lines
4.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  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. #ifndef API_RTP_PACKET_INFOS_H_
  11. #define API_RTP_PACKET_INFOS_H_
  12. #include <cstdint>
  13. #include <utility>
  14. #include <vector>
  15. #include "api/ref_counted_base.h"
  16. #include "api/rtp_packet_info.h"
  17. #include "api/scoped_refptr.h"
  18. namespace webrtc {
  19. // Semi-immutable structure to hold information about packets used to assemble
  20. // an audio or video frame. Uses internal reference counting to make it very
  21. // cheap to copy.
  22. //
  23. // We should ideally just use |std::vector<RtpPacketInfo>| and have it
  24. // |std::move()|-ed as the per-packet information is transferred from one object
  25. // to another. But moving the info, instead of copying it, is not easily done
  26. // for the current video code.
  27. class RtpPacketInfos {
  28. public:
  29. using vector_type = std::vector<RtpPacketInfo>;
  30. using value_type = vector_type::value_type;
  31. using size_type = vector_type::size_type;
  32. using difference_type = vector_type::difference_type;
  33. using const_reference = vector_type::const_reference;
  34. using const_pointer = vector_type::const_pointer;
  35. using const_iterator = vector_type::const_iterator;
  36. using const_reverse_iterator = vector_type::const_reverse_iterator;
  37. using reference = const_reference;
  38. using pointer = const_pointer;
  39. using iterator = const_iterator;
  40. using reverse_iterator = const_reverse_iterator;
  41. RtpPacketInfos() {}
  42. explicit RtpPacketInfos(const vector_type& entries)
  43. : data_(Data::Create(entries)) {}
  44. explicit RtpPacketInfos(vector_type&& entries)
  45. : data_(Data::Create(std::move(entries))) {}
  46. RtpPacketInfos(const RtpPacketInfos& other) = default;
  47. RtpPacketInfos(RtpPacketInfos&& other) = default;
  48. RtpPacketInfos& operator=(const RtpPacketInfos& other) = default;
  49. RtpPacketInfos& operator=(RtpPacketInfos&& other) = default;
  50. const_reference operator[](size_type pos) const { return entries()[pos]; }
  51. const_reference at(size_type pos) const { return entries().at(pos); }
  52. const_reference front() const { return entries().front(); }
  53. const_reference back() const { return entries().back(); }
  54. const_iterator begin() const { return entries().begin(); }
  55. const_iterator end() const { return entries().end(); }
  56. const_reverse_iterator rbegin() const { return entries().rbegin(); }
  57. const_reverse_iterator rend() const { return entries().rend(); }
  58. const_iterator cbegin() const { return entries().cbegin(); }
  59. const_iterator cend() const { return entries().cend(); }
  60. const_reverse_iterator crbegin() const { return entries().crbegin(); }
  61. const_reverse_iterator crend() const { return entries().crend(); }
  62. bool empty() const { return entries().empty(); }
  63. size_type size() const { return entries().size(); }
  64. private:
  65. class Data : public rtc::RefCountedBase {
  66. public:
  67. static rtc::scoped_refptr<Data> Create(const vector_type& entries) {
  68. // Performance optimization for the empty case.
  69. if (entries.empty()) {
  70. return nullptr;
  71. }
  72. return new Data(entries);
  73. }
  74. static rtc::scoped_refptr<Data> Create(vector_type&& entries) {
  75. // Performance optimization for the empty case.
  76. if (entries.empty()) {
  77. return nullptr;
  78. }
  79. return new Data(std::move(entries));
  80. }
  81. const vector_type& entries() const { return entries_; }
  82. private:
  83. explicit Data(const vector_type& entries) : entries_(entries) {}
  84. explicit Data(vector_type&& entries) : entries_(std::move(entries)) {}
  85. ~Data() override {}
  86. const vector_type entries_;
  87. };
  88. static const vector_type& empty_entries() {
  89. static const vector_type& value = *new vector_type();
  90. return value;
  91. }
  92. const vector_type& entries() const {
  93. if (data_ != nullptr) {
  94. return data_->entries();
  95. } else {
  96. return empty_entries();
  97. }
  98. }
  99. rtc::scoped_refptr<Data> data_;
  100. };
  101. } // namespace webrtc
  102. #endif // API_RTP_PACKET_INFOS_H_