• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h"
12 
13 #include <cstdint>
14 
15 #include "rtc_base/checks.h"
16 
17 namespace webrtc {
18 
19 constexpr int RtpGenericFrameDescriptor::kMaxNumFrameDependencies;
20 constexpr int RtpGenericFrameDescriptor::kMaxTemporalLayers;
21 constexpr int RtpGenericFrameDescriptor::kMaxSpatialLayers;
22 
23 RtpGenericFrameDescriptor::RtpGenericFrameDescriptor() = default;
24 RtpGenericFrameDescriptor::RtpGenericFrameDescriptor(
25     const RtpGenericFrameDescriptor&) = default;
26 RtpGenericFrameDescriptor::~RtpGenericFrameDescriptor() = default;
27 
TemporalLayer() const28 int RtpGenericFrameDescriptor::TemporalLayer() const {
29   RTC_DCHECK(FirstPacketInSubFrame());
30   return temporal_layer_;
31 }
32 
SetTemporalLayer(int temporal_layer)33 void RtpGenericFrameDescriptor::SetTemporalLayer(int temporal_layer) {
34   RTC_DCHECK_GE(temporal_layer, 0);
35   RTC_DCHECK_LT(temporal_layer, kMaxTemporalLayers);
36   temporal_layer_ = temporal_layer;
37 }
38 
SpatialLayer() const39 int RtpGenericFrameDescriptor::SpatialLayer() const {
40   RTC_DCHECK(FirstPacketInSubFrame());
41   int layer = 0;
42   uint8_t spatial_layers = spatial_layers_;
43   while (spatial_layers_ != 0 && !(spatial_layers & 1)) {
44     spatial_layers >>= 1;
45     layer++;
46   }
47   return layer;
48 }
49 
SpatialLayersBitmask() const50 uint8_t RtpGenericFrameDescriptor::SpatialLayersBitmask() const {
51   RTC_DCHECK(FirstPacketInSubFrame());
52   return spatial_layers_;
53 }
54 
SetSpatialLayersBitmask(uint8_t spatial_layers)55 void RtpGenericFrameDescriptor::SetSpatialLayersBitmask(
56     uint8_t spatial_layers) {
57   RTC_DCHECK(FirstPacketInSubFrame());
58   spatial_layers_ = spatial_layers;
59 }
60 
SetResolution(int width,int height)61 void RtpGenericFrameDescriptor::SetResolution(int width, int height) {
62   RTC_DCHECK(FirstPacketInSubFrame());
63   RTC_DCHECK_GE(width, 0);
64   RTC_DCHECK_LE(width, 0xFFFF);
65   RTC_DCHECK_GE(height, 0);
66   RTC_DCHECK_LE(height, 0xFFFF);
67   width_ = width;
68   height_ = height;
69 }
70 
FrameId() const71 uint16_t RtpGenericFrameDescriptor::FrameId() const {
72   RTC_DCHECK(FirstPacketInSubFrame());
73   return frame_id_;
74 }
75 
SetFrameId(uint16_t frame_id)76 void RtpGenericFrameDescriptor::SetFrameId(uint16_t frame_id) {
77   RTC_DCHECK(FirstPacketInSubFrame());
78   frame_id_ = frame_id;
79 }
80 
81 rtc::ArrayView<const uint16_t>
FrameDependenciesDiffs() const82 RtpGenericFrameDescriptor::FrameDependenciesDiffs() const {
83   RTC_DCHECK(FirstPacketInSubFrame());
84   return rtc::MakeArrayView(frame_deps_id_diffs_, num_frame_deps_);
85 }
86 
AddFrameDependencyDiff(uint16_t fdiff)87 bool RtpGenericFrameDescriptor::AddFrameDependencyDiff(uint16_t fdiff) {
88   RTC_DCHECK(FirstPacketInSubFrame());
89   if (num_frame_deps_ == kMaxNumFrameDependencies)
90     return false;
91   if (fdiff == 0)
92     return false;
93   RTC_DCHECK_LT(fdiff, 1 << 14);
94   RTC_DCHECK_GT(fdiff, 0);
95   frame_deps_id_diffs_[num_frame_deps_] = fdiff;
96   num_frame_deps_++;
97   return true;
98 }
99 
100 }  // namespace webrtc
101