summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/api/video/video_layers_allocation.h
blob: 39734151ae063988e77fa9e57bf8effcc1155f33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 *  Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef API_VIDEO_VIDEO_LAYERS_ALLOCATION_H_
#define API_VIDEO_VIDEO_LAYERS_ALLOCATION_H_

#include <cstdint>

#include "absl/container/inlined_vector.h"
#include "api/units/data_rate.h"

namespace webrtc {

// This struct contains additional stream-level information needed by a
// Selective Forwarding Middlebox to make relay decisions of RTP streams.
struct VideoLayersAllocation {
  static constexpr int kMaxSpatialIds = 4;
  static constexpr int kMaxTemporalIds = 4;

  friend bool operator==(const VideoLayersAllocation& lhs,
                         const VideoLayersAllocation& rhs) {
    return lhs.rtp_stream_index == rhs.rtp_stream_index &&
           lhs.resolution_and_frame_rate_is_valid ==
               rhs.resolution_and_frame_rate_is_valid &&
           lhs.active_spatial_layers == rhs.active_spatial_layers;
  }

  friend bool operator!=(const VideoLayersAllocation& lhs,
                         const VideoLayersAllocation& rhs) {
    return !(lhs == rhs);
  }

  struct SpatialLayer {
    friend bool operator==(const SpatialLayer& lhs, const SpatialLayer& rhs) {
      return lhs.rtp_stream_index == rhs.rtp_stream_index &&
             lhs.spatial_id == rhs.spatial_id &&
             lhs.target_bitrate_per_temporal_layer ==
                 rhs.target_bitrate_per_temporal_layer &&
             lhs.width == rhs.width && lhs.height == rhs.height &&
             lhs.frame_rate_fps == rhs.frame_rate_fps;
    }

    friend bool operator!=(const SpatialLayer& lhs, const SpatialLayer& rhs) {
      return !(lhs == rhs);
    }
    int rtp_stream_index = 0;
    // Index of the spatial layer per `rtp_stream_index`.
    int spatial_id = 0;
    // Target bitrate per decode target.
    absl::InlinedVector<DataRate, kMaxTemporalIds>
        target_bitrate_per_temporal_layer;

    // These fields are only valid if `resolution_and_frame_rate_is_valid` is
    // true
    uint16_t width = 0;
    uint16_t height = 0;
    // Max frame rate used in any temporal layer of this spatial layer.
    uint8_t frame_rate_fps = 0;
  };

  // Index of the rtp stream this allocation is sent on. Used for mapping
  // a SpatialLayer to a rtp stream.
  int rtp_stream_index = 0;
  bool resolution_and_frame_rate_is_valid = false;
  absl::InlinedVector<SpatialLayer, kMaxSpatialIds> active_spatial_layers;
};

}  // namespace webrtc

#endif  // API_VIDEO_VIDEO_LAYERS_ALLOCATION_H_