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