1 /*
2  *  Copyright (c) 2018 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_GENERIC_FRAME_DESCRIPTOR_H_
11 #define MODULES_RTP_RTCP_SOURCE_RTP_GENERIC_FRAME_DESCRIPTOR_H_
12 
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 #include <vector>
17 
18 #include "absl/types/optional.h"
19 #include "api/array_view.h"
20 
21 namespace webrtc {
22 
23 class RtpGenericFrameDescriptorExtension;
24 
25 // Data to put on the wire for FrameDescriptor rtp header extension.
26 class RtpGenericFrameDescriptor {
27  public:
28   static constexpr int kMaxNumFrameDependencies = 8;
29   static constexpr int kMaxTemporalLayers = 8;
30   static constexpr int kMaxSpatialLayers = 8;
31 
32   RtpGenericFrameDescriptor();
33   RtpGenericFrameDescriptor(const RtpGenericFrameDescriptor&);
34   ~RtpGenericFrameDescriptor();
35 
FirstPacketInSubFrame()36   bool FirstPacketInSubFrame() const { return beginning_of_subframe_; }
SetFirstPacketInSubFrame(bool first)37   void SetFirstPacketInSubFrame(bool first) { beginning_of_subframe_ = first; }
LastPacketInSubFrame()38   bool LastPacketInSubFrame() const { return end_of_subframe_; }
SetLastPacketInSubFrame(bool last)39   void SetLastPacketInSubFrame(bool last) { end_of_subframe_ = last; }
40 
41   // Properties below undefined if !FirstPacketInSubFrame()
42   // Valid range for temporal layer: [0, 7]
43   int TemporalLayer() const;
44   void SetTemporalLayer(int temporal_layer);
45 
46   // Frame might by used, possible indirectly, for spatial layer sid iff
47   // (bitmask & (1 << sid)) != 0
48   int SpatialLayer() const;
49   uint8_t SpatialLayersBitmask() const;
50   void SetSpatialLayersBitmask(uint8_t spatial_layers);
51 
Width()52   int Width() const { return width_; }
Height()53   int Height() const { return height_; }
54   void SetResolution(int width, int height);
55 
56   uint16_t FrameId() const;
57   void SetFrameId(uint16_t frame_id);
58 
59   rtc::ArrayView<const uint16_t> FrameDependenciesDiffs() const;
ClearFrameDependencies()60   void ClearFrameDependencies() { num_frame_deps_ = 0; }
61   // Returns false on failure, i.e. number of dependencies is too large.
62   bool AddFrameDependencyDiff(uint16_t fdiff);
63 
64  private:
65   bool beginning_of_subframe_ = false;
66   bool end_of_subframe_ = false;
67 
68   uint16_t frame_id_ = 0;
69   uint8_t spatial_layers_ = 1;
70   uint8_t temporal_layer_ = 0;
71   size_t num_frame_deps_ = 0;
72   uint16_t frame_deps_id_diffs_[kMaxNumFrameDependencies];
73   int width_ = 0;
74   int height_ = 0;
75 };
76 
77 }  // namespace webrtc
78 
79 #endif  // MODULES_RTP_RTCP_SOURCE_RTP_GENERIC_FRAME_DESCRIPTOR_H_
80