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 std::bitset<32> RtpDependencyDescriptorExtension::kAllChainsAreActive;
27
Parse(rtc::ArrayView<const uint8_t> data,const FrameDependencyStructure * structure,DependencyDescriptor * descriptor)28 bool RtpDependencyDescriptorExtension::Parse(
29 rtc::ArrayView<const uint8_t> data,
30 const FrameDependencyStructure* structure,
31 DependencyDescriptor* descriptor) {
32 RtpDependencyDescriptorReader reader(data, structure, descriptor);
33 return reader.ParseSuccessful();
34 }
35
ValueSize(const FrameDependencyStructure & structure,std::bitset<32> active_chains,const DependencyDescriptor & descriptor)36 size_t RtpDependencyDescriptorExtension::ValueSize(
37 const FrameDependencyStructure& structure,
38 std::bitset<32> active_chains,
39 const DependencyDescriptor& descriptor) {
40 RtpDependencyDescriptorWriter writer(/*data=*/{}, structure, active_chains,
41 descriptor);
42 return DivideRoundUp(writer.ValueSizeBits(), 8);
43 }
44
Write(rtc::ArrayView<uint8_t> data,const FrameDependencyStructure & structure,std::bitset<32> active_chains,const DependencyDescriptor & descriptor)45 bool RtpDependencyDescriptorExtension::Write(
46 rtc::ArrayView<uint8_t> data,
47 const FrameDependencyStructure& structure,
48 std::bitset<32> active_chains,
49 const DependencyDescriptor& descriptor) {
50 RtpDependencyDescriptorWriter writer(data, structure, active_chains,
51 descriptor);
52 return writer.Write();
53 }
54
55 } // namespace webrtc
56