• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WRITER_H_
11 #define MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_WRITER_H_
12 
13 #include <bitset>
14 #include <cstddef>
15 #include <cstdint>
16 #include <vector>
17 
18 #include "api/array_view.h"
19 #include "api/transport/rtp/dependency_descriptor.h"
20 #include "rtc_base/bit_buffer.h"
21 
22 namespace webrtc {
23 class RtpDependencyDescriptorWriter {
24  public:
25   // Assumes |structure| and |descriptor| are valid and
26   // |descriptor| matches the |structure|.
27   RtpDependencyDescriptorWriter(rtc::ArrayView<uint8_t> data,
28                                 const FrameDependencyStructure& structure,
29                                 std::bitset<32> active_chains,
30                                 const DependencyDescriptor& descriptor);
31 
32   // Serializes DependencyDescriptor rtp header extension.
33   // Returns false if |data| is too small to serialize the |descriptor|.
34   bool Write();
35 
36   // Returns minimum number of bits needed to serialize descriptor with respect
37   // to the |structure|. Returns 0 if |descriptor| can't be serialized.
38   int ValueSizeBits() const;
39 
40  private:
41   // Used both as pointer to the template and as index in the templates vector.
42   using TemplateIterator = std::vector<FrameDependencyTemplate>::const_iterator;
43   struct TemplateMatch {
44     TemplateIterator template_position;
45     bool need_custom_dtis;
46     bool need_custom_fdiffs;
47     bool need_custom_chains;
48     // Size in bits to store frame-specific details, i.e.
49     // excluding mandatory fields and template dependency structure.
50     int extra_size_bits;
51   };
52   int StructureSizeBits() const;
53   TemplateMatch CalculateMatch(TemplateIterator frame_template) const;
54   void FindBestTemplate();
55   bool ShouldWriteActiveDecodeTargetsBitmask() const;
56   bool HasExtendedFields() const;
57   uint64_t TemplateId() const;
58 
59   void WriteBits(uint64_t val, size_t bit_count);
60   void WriteNonSymmetric(uint32_t value, uint32_t num_values);
61 
62   // Functions to read template dependency structure.
63   void WriteTemplateDependencyStructure();
64   void WriteTemplateLayers();
65   void WriteTemplateDtis();
66   void WriteTemplateFdiffs();
67   void WriteTemplateChains();
68   void WriteResolutions();
69 
70   // Function to read details for the current frame.
71   void WriteMandatoryFields();
72   void WriteExtendedFields();
73   void WriteFrameDependencyDefinition();
74 
75   void WriteFrameDtis();
76   void WriteFrameFdiffs();
77   void WriteFrameChains();
78 
79   bool build_failed_ = false;
80   const DependencyDescriptor& descriptor_;
81   const FrameDependencyStructure& structure_;
82   std::bitset<32> active_chains_;
83   rtc::BitBufferWriter bit_writer_;
84   TemplateMatch best_template_;
85 };
86 
87 }  // namespace webrtc
88 
89 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_WRITER_H_
90