blob: 53f491c2b67174dd9868b08d9ddafe1e6abfeb63 [file] [log] [blame]
Danil Chapovalov735e33f2021-02-18 14:39:52 +01001/*
2 * Copyright (c) 2021 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_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_SIMULCAST_H_
11#define MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_SIMULCAST_H_
12
13#include <vector>
14
15#include "api/transport/rtp/dependency_descriptor.h"
16#include "api/video/video_bitrate_allocation.h"
17#include "common_video/generic_frame_descriptor/generic_frame_info.h"
18#include "modules/video_coding/svc/scalable_video_controller.h"
19
20namespace webrtc {
21
22// Scalability structure with multiple independent spatial layers each with the
23// same temporal layering.
24class ScalabilityStructureSimulcast : public ScalableVideoController {
25 public:
26 ScalabilityStructureSimulcast(int num_spatial_layers,
27 int num_temporal_layers);
28 ~ScalabilityStructureSimulcast() override;
29
30 StreamLayersConfig StreamConfig() const override;
31 std::vector<LayerFrameConfig> NextFrameConfig(bool restart) override;
32 GenericFrameInfo OnEncodeDone(const LayerFrameConfig& config) override;
33 void OnRatesUpdated(const VideoBitrateAllocation& bitrates) override;
34
35 private:
36 enum FramePattern {
37 kNone,
38 kDeltaT2A,
39 kDeltaT1,
40 kDeltaT2B,
41 kDeltaT0,
42 };
43 static constexpr int kMaxNumSpatialLayers = 3;
44 static constexpr int kMaxNumTemporalLayers = 3;
45
46 // Index of the buffer to store last frame for layer (`sid`, `tid`)
47 int BufferIndex(int sid, int tid) const {
48 return tid * num_spatial_layers_ + sid;
49 }
50 bool DecodeTargetIsActive(int sid, int tid) const {
51 return active_decode_targets_[sid * num_temporal_layers_ + tid];
52 }
53 void SetDecodeTargetIsActive(int sid, int tid, bool value) {
54 active_decode_targets_.set(sid * num_temporal_layers_ + tid, value);
55 }
56 FramePattern NextPattern() const;
57 bool TemporalLayerIsActive(int tid) const;
58
59 const int num_spatial_layers_;
60 const int num_temporal_layers_;
61
62 FramePattern last_pattern_ = kNone;
63 std::bitset<kMaxNumSpatialLayers> can_reference_t0_frame_for_spatial_id_ = 0;
64 std::bitset<kMaxNumSpatialLayers> can_reference_t1_frame_for_spatial_id_ = 0;
65 std::bitset<32> active_decode_targets_;
66};
67
68// S1 0--0--0-
69// ...
70// S0 0--0--0-
71class ScalabilityStructureS2T1 : public ScalabilityStructureSimulcast {
72 public:
73 ScalabilityStructureS2T1() : ScalabilityStructureSimulcast(2, 1) {}
74 ~ScalabilityStructureS2T1() override = default;
75
76 FrameDependencyStructure DependencyStructure() const override;
77};
78
Niels Möller3c24c092022-06-30 15:42:51 +020079// S1T2 3 7
80// | /
81// S1T1 / 5
82// |_/
83// S1T0 1-------9...
84//
85// S0T2 2 6
86// | /
87// S0T1 / 4
88// |_/
89// S0T0 0-------8...
90// Time-> 0 1 2 3 4
91class ScalabilityStructureS2T3 : public ScalabilityStructureSimulcast {
92 public:
93 ScalabilityStructureS2T3() : ScalabilityStructureSimulcast(2, 3) {}
94 ~ScalabilityStructureS2T3() override = default;
95
96 FrameDependencyStructure DependencyStructure() const override;
97};
98
Danil Chapovalov735e33f2021-02-18 14:39:52 +010099class ScalabilityStructureS3T3 : public ScalabilityStructureSimulcast {
100 public:
101 ScalabilityStructureS3T3() : ScalabilityStructureSimulcast(3, 3) {}
102 ~ScalabilityStructureS3T3() override = default;
103
104 FrameDependencyStructure DependencyStructure() const override;
105};
106
107} // namespace webrtc
108
109#endif // MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_SIMULCAST_H_