blob: 7b57df2985ec9613b6df36a80d8d86133210c345 [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
79class ScalabilityStructureS3T3 : public ScalabilityStructureSimulcast {
80 public:
81 ScalabilityStructureS3T3() : ScalabilityStructureSimulcast(3, 3) {}
82 ~ScalabilityStructureS3T3() override = default;
83
84 FrameDependencyStructure DependencyStructure() const override;
85};
86
87} // namespace webrtc
88
89#endif // MODULES_VIDEO_CODING_SVC_SCALABILITY_STRUCTURE_SIMULCAST_H_