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_READER_H_
11 #define MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_READER_H_
12 
13 #include <cstdint>
14 #include <memory>
15 #include <vector>
16 
17 #include "api/array_view.h"
18 #include "api/transport/rtp/dependency_descriptor.h"
19 #include "rtc_base/bit_buffer.h"
20 
21 namespace webrtc {
22 // Deserializes DependencyDescriptor rtp header extension.
23 class RtpDependencyDescriptorReader {
24  public:
25   // Parses the dependency descriptor.
26   RtpDependencyDescriptorReader(rtc::ArrayView<const uint8_t> raw_data,
27                                 const FrameDependencyStructure* structure,
28                                 DependencyDescriptor* descriptor);
29   RtpDependencyDescriptorReader(const RtpDependencyDescriptorReader&) = delete;
30   RtpDependencyDescriptorReader& operator=(
31       const RtpDependencyDescriptorReader&) = delete;
32 
33   // Returns true if parse was successful.
ParseSuccessful()34   bool ParseSuccessful() { return !parsing_failed_; }
35 
36  private:
37   // Reads bits from |buffer_|. If it fails, returns 0 and marks parsing as
38   // failed, but doesn't stop the parsing.
39   uint32_t ReadBits(size_t bit_count);
40   uint32_t ReadNonSymmetric(size_t num_values);
41 
42   // Functions to read template dependency structure.
43   void ReadTemplateDependencyStructure();
44   void ReadTemplateLayers();
45   void ReadTemplateDtis();
46   void ReadTemplateFdiffs();
47   void ReadTemplateChains();
48   void ReadResolutions();
49 
50   // Function to read details for the current frame.
51   void ReadMandatoryFields();
52   void ReadExtendedFields();
53   void ReadFrameDependencyDefinition();
54 
55   void ReadFrameDtis();
56   void ReadFrameFdiffs();
57   void ReadFrameChains();
58 
59   // Output.
60   bool parsing_failed_ = false;
61   DependencyDescriptor* const descriptor_;
62   // Values that are needed while reading the descriptor, but can be discarded
63   // when reading is complete.
64   rtc::BitBuffer buffer_;
65   int frame_dependency_template_id_ = 0;
66   bool active_decode_targets_present_flag_ = false;
67   bool custom_dtis_flag_ = false;
68   bool custom_fdiffs_flag_ = false;
69   bool custom_chains_flag_ = false;
70   const FrameDependencyStructure* structure_ = nullptr;
71 };
72 
73 }  // namespace webrtc
74 
75 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_DEPENDENCY_DESCRIPTOR_READER_H_
76