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
11 #include "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 #include "modules/rtp_rtcp/source/rtp_dependency_descriptor_reader.h"
20 #include "modules/rtp_rtcp/source/rtp_dependency_descriptor_writer.h"
21 #include "rtc_base/numerics/divide_round.h"
22
23 namespace webrtc {
24
25 constexpr RTPExtensionType RtpDependencyDescriptorExtension::kId;
26 constexpr char RtpDependencyDescriptorExtension::kUri[];
27 constexpr std::bitset<32> RtpDependencyDescriptorExtension::kAllChainsAreActive;
28
Parse(rtc::ArrayView<const uint8_t> data,const FrameDependencyStructure * structure,DependencyDescriptor * descriptor)29 bool RtpDependencyDescriptorExtension::Parse(
30 rtc::ArrayView<const uint8_t> data,
31 const FrameDependencyStructure* structure,
32 DependencyDescriptor* descriptor) {
33 RtpDependencyDescriptorReader reader(data, structure, descriptor);
34 return reader.ParseSuccessful();
35 }
36
ValueSize(const FrameDependencyStructure & structure,std::bitset<32> active_chains,const DependencyDescriptor & descriptor)37 size_t RtpDependencyDescriptorExtension::ValueSize(
38 const FrameDependencyStructure& structure,
39 std::bitset<32> active_chains,
40 const DependencyDescriptor& descriptor) {
41 RtpDependencyDescriptorWriter writer(/*data=*/{}, structure, active_chains,
42 descriptor);
43 return DivideRoundUp(writer.ValueSizeBits(), 8);
44 }
45
Write(rtc::ArrayView<uint8_t> data,const FrameDependencyStructure & structure,std::bitset<32> active_chains,const DependencyDescriptor & descriptor)46 bool RtpDependencyDescriptorExtension::Write(
47 rtc::ArrayView<uint8_t> data,
48 const FrameDependencyStructure& structure,
49 std::bitset<32> active_chains,
50 const DependencyDescriptor& descriptor) {
51 RtpDependencyDescriptorWriter writer(data, structure, active_chains,
52 descriptor);
53 return writer.Write();
54 }
55
56 } // namespace webrtc
57