dependency_descriptor.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (c) 2020 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_TRANSPORT_RTP_DEPENDENCY_DESCRIPTOR_H_
  11. #define API_TRANSPORT_RTP_DEPENDENCY_DESCRIPTOR_H_
  12. #include <stdint.h>
  13. #include <initializer_list>
  14. #include <memory>
  15. #include <vector>
  16. #include "absl/container/inlined_vector.h"
  17. #include "absl/strings/string_view.h"
  18. #include "absl/types/optional.h"
  19. namespace webrtc {
  20. // Structures to build and parse dependency descriptor as described in
  21. // https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension
  22. class RenderResolution {
  23. public:
  24. constexpr RenderResolution() = default;
  25. constexpr RenderResolution(int width, int height)
  26. : width_(width), height_(height) {}
  27. RenderResolution(const RenderResolution&) = default;
  28. RenderResolution& operator=(const RenderResolution&) = default;
  29. friend bool operator==(const RenderResolution& lhs,
  30. const RenderResolution& rhs) {
  31. return lhs.width_ == rhs.width_ && lhs.height_ == rhs.height_;
  32. }
  33. constexpr int Width() const { return width_; }
  34. constexpr int Height() const { return height_; }
  35. private:
  36. int width_ = 0;
  37. int height_ = 0;
  38. };
  39. // Relationship of a frame to a Decode target.
  40. enum class DecodeTargetIndication {
  41. kNotPresent = 0, // DecodeTargetInfo symbol '-'
  42. kDiscardable = 1, // DecodeTargetInfo symbol 'D'
  43. kSwitch = 2, // DecodeTargetInfo symbol 'S'
  44. kRequired = 3 // DecodeTargetInfo symbol 'R'
  45. };
  46. struct FrameDependencyTemplate {
  47. // Setters are named briefly to chain them when building the template.
  48. FrameDependencyTemplate& S(int spatial_layer);
  49. FrameDependencyTemplate& T(int temporal_layer);
  50. FrameDependencyTemplate& Dtis(absl::string_view dtis);
  51. FrameDependencyTemplate& FrameDiffs(std::initializer_list<int> diffs);
  52. FrameDependencyTemplate& ChainDiffs(std::initializer_list<int> diffs);
  53. friend bool operator==(const FrameDependencyTemplate& lhs,
  54. const FrameDependencyTemplate& rhs) {
  55. return lhs.spatial_id == rhs.spatial_id &&
  56. lhs.temporal_id == rhs.temporal_id &&
  57. lhs.decode_target_indications == rhs.decode_target_indications &&
  58. lhs.frame_diffs == rhs.frame_diffs &&
  59. lhs.chain_diffs == rhs.chain_diffs;
  60. }
  61. int spatial_id = 0;
  62. int temporal_id = 0;
  63. absl::InlinedVector<DecodeTargetIndication, 10> decode_target_indications;
  64. absl::InlinedVector<int, 4> frame_diffs;
  65. absl::InlinedVector<int, 4> chain_diffs;
  66. };
  67. struct FrameDependencyStructure {
  68. friend bool operator==(const FrameDependencyStructure& lhs,
  69. const FrameDependencyStructure& rhs) {
  70. return lhs.num_decode_targets == rhs.num_decode_targets &&
  71. lhs.num_chains == rhs.num_chains &&
  72. lhs.decode_target_protected_by_chain ==
  73. rhs.decode_target_protected_by_chain &&
  74. lhs.resolutions == rhs.resolutions && lhs.templates == rhs.templates;
  75. }
  76. int structure_id = 0;
  77. int num_decode_targets = 0;
  78. int num_chains = 0;
  79. // If chains are used (num_chains > 0), maps decode target index into index of
  80. // the chain protecting that target.
  81. absl::InlinedVector<int, 10> decode_target_protected_by_chain;
  82. absl::InlinedVector<RenderResolution, 4> resolutions;
  83. std::vector<FrameDependencyTemplate> templates;
  84. };
  85. struct DependencyDescriptor {
  86. static constexpr int kMaxSpatialIds = 4;
  87. static constexpr int kMaxTemporalIds = 8;
  88. static constexpr int kMaxDecodeTargets = 32;
  89. static constexpr int kMaxTemplates = 64;
  90. bool first_packet_in_frame = true;
  91. bool last_packet_in_frame = true;
  92. int frame_number = 0;
  93. FrameDependencyTemplate frame_dependencies;
  94. absl::optional<RenderResolution> resolution;
  95. absl::optional<uint32_t> active_decode_targets_bitmask;
  96. std::unique_ptr<FrameDependencyStructure> attached_structure;
  97. };
  98. // Below are implementation details.
  99. namespace webrtc_impl {
  100. absl::InlinedVector<DecodeTargetIndication, 10> StringToDecodeTargetIndications(
  101. absl::string_view indication_symbols);
  102. } // namespace webrtc_impl
  103. inline FrameDependencyTemplate& FrameDependencyTemplate::S(int spatial_layer) {
  104. this->spatial_id = spatial_layer;
  105. return *this;
  106. }
  107. inline FrameDependencyTemplate& FrameDependencyTemplate::T(int temporal_layer) {
  108. this->temporal_id = temporal_layer;
  109. return *this;
  110. }
  111. inline FrameDependencyTemplate& FrameDependencyTemplate::Dtis(
  112. absl::string_view dtis) {
  113. this->decode_target_indications =
  114. webrtc_impl::StringToDecodeTargetIndications(dtis);
  115. return *this;
  116. }
  117. inline FrameDependencyTemplate& FrameDependencyTemplate::FrameDiffs(
  118. std::initializer_list<int> diffs) {
  119. this->frame_diffs.assign(diffs.begin(), diffs.end());
  120. return *this;
  121. }
  122. inline FrameDependencyTemplate& FrameDependencyTemplate::ChainDiffs(
  123. std::initializer_list<int> diffs) {
  124. this->chain_diffs.assign(diffs.begin(), diffs.end());
  125. return *this;
  126. }
  127. } // namespace webrtc
  128. #endif // API_TRANSPORT_RTP_DEPENDENCY_DESCRIPTOR_H_