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 MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_EXTENSION_H_
11 #define MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_EXTENSION_H_
12 
13 #include <bitset>
14 #include <cstdint>
15 
16 #include "api/array_view.h"
17 #include "api/transport/rtp/dependency_descriptor.h"
18 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19 
20 namespace webrtc {
21 // Trait to read/write the dependency descriptor extension as described in
22 // https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension
23 // While the format is still in design, the code might change without backward
24 // compatibility.
25 class RtpDependencyDescriptorExtension {
26  public:
27   static constexpr RTPExtensionType kId = kRtpExtensionGenericFrameDescriptor02;
28   // TODO(bugs.webrtc.org/10342): Use uri from the spec when there is one.
29   static constexpr char kUri[] =
30       "https://aomediacodec.github.io/av1-rtp-spec/"
31       "#dependency-descriptor-rtp-header-extension";
32 
33   static bool Parse(rtc::ArrayView<const uint8_t> data,
34                     const FrameDependencyStructure* structure,
35                     DependencyDescriptor* descriptor);
36 
ValueSize(const FrameDependencyStructure & structure,const DependencyDescriptor & descriptor)37   static size_t ValueSize(const FrameDependencyStructure& structure,
38                           const DependencyDescriptor& descriptor) {
39     return ValueSize(structure, kAllChainsAreActive, descriptor);
40   }
41   static size_t ValueSize(const FrameDependencyStructure& structure,
42                           std::bitset<32> active_chains,
43                           const DependencyDescriptor& descriptor);
Write(rtc::ArrayView<uint8_t> data,const FrameDependencyStructure & structure,const DependencyDescriptor & descriptor)44   static bool Write(rtc::ArrayView<uint8_t> data,
45                     const FrameDependencyStructure& structure,
46                     const DependencyDescriptor& descriptor) {
47     return Write(data, structure, kAllChainsAreActive, descriptor);
48   }
49   static bool Write(rtc::ArrayView<uint8_t> data,
50                     const FrameDependencyStructure& structure,
51                     std::bitset<32> active_chains,
52                     const DependencyDescriptor& descriptor);
53 
54  private:
55   static constexpr std::bitset<32> kAllChainsAreActive = ~uint32_t{0};
56 };
57 
58 }  // namespace webrtc
59 
60 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_EXTENSION_H_
61