blob: 0781a6a283a64680517d65ccb63f0391a9a6926a [file] [log] [blame]
Amit Hilbucha2012042018-12-03 11:35:05 -08001/*
2 * Copyright 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#ifndef PC_SIMULCASTDESCRIPTION_H_
12#define PC_SIMULCASTDESCRIPTION_H_
13
14#include <string>
15#include <vector>
16
17namespace cricket {
18
19// Describes a Simulcast Layer.
20// Each simulcast layer has a rid as the identifier and a paused flag.
21// See also: https://tools.ietf.org/html/draft-ietf-mmusic-rid-15 for
22// an explanation about rids.
23struct SimulcastLayer final {
24 SimulcastLayer(const std::string& rid, bool is_paused);
25
26 SimulcastLayer(const SimulcastLayer& other) = default;
27 SimulcastLayer& operator=(const SimulcastLayer& other) = default;
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080028 bool operator==(const SimulcastLayer& other) const;
Amit Hilbucha2012042018-12-03 11:35:05 -080029
30 std::string rid;
31 bool is_paused;
32};
33
34// Describes a list of Simulcast layers.
35// Simulcast layers are specified in order of preference.
36// Each layer can have a list of alternatives (in order of preference).
37// https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-13#section-5.1
38// Example Usage:
39// To populate a list that specifies the following:
40// 1. Layer 1 or Layer 2
41// 2. Layer 3
42// 3. Layer 4 or Layer 5
43// Use the following code:
44// SimulcastLayerList list;
45// list.AddLayerWithAlternatives(
46// {SimulcastLayer("1", false), SimulcastLayer("2", false});
47// list.AddLayer("3");
48// list.AddLayerWithAlternatives(
49// {SimulcastLayer("4", false), SimulcastLayer("5", false});
50class SimulcastLayerList final {
51 public:
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080052 // Type definitions required by a container.
53 typedef size_t size_type;
54 typedef std::vector<SimulcastLayer> value_type;
55 typedef std::vector<std::vector<SimulcastLayer>>::const_iterator
56 const_iterator;
57
Amit Hilbucha2012042018-12-03 11:35:05 -080058 // Use to add a layer when there will be no alternatives.
59 void AddLayer(const SimulcastLayer& layer);
60
61 // Use to add a list of alternatives.
62 // The alternatives should be specified in order of preference.
63 void AddLayerWithAlternatives(const std::vector<SimulcastLayer>& layers);
64
65 // Read-only access to the contents.
66 // Note: This object does not allow removal of layers.
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080067 const_iterator begin() const { return list_.begin(); }
Amit Hilbucha2012042018-12-03 11:35:05 -080068
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080069 const_iterator end() const { return list_.end(); }
Amit Hilbucha2012042018-12-03 11:35:05 -080070
71 const std::vector<SimulcastLayer>& operator[](size_t index) const;
72
73 size_t size() const { return list_.size(); }
74 bool empty() const { return list_.empty(); }
75
Amit Hilbuchc57d5732018-12-11 15:30:11 -080076 // Provides access to all the layers in the simulcast without their
77 // association into groups of alternatives.
78 std::vector<SimulcastLayer> GetAllLayers() const;
79
Amit Hilbucha2012042018-12-03 11:35:05 -080080 private:
81 // TODO(amithi, bugs.webrtc.org/10075):
82 // Validate that rids do not repeat in the list.
83 std::vector<std::vector<SimulcastLayer>> list_;
84};
85
86// Describes the simulcast options of a video media section.
87// This will list the send and receive layers (along with their alternatives).
88// Each simulcast layer has an identifier (rid) and can optionally be paused.
89// The order of the layers (as well as alternates) indicates user preference
90// from first to last (most preferred to least preferred).
91// https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-13#section-5.1
92class SimulcastDescription final {
93 public:
94 const SimulcastLayerList& send_layers() const { return send_layers_; }
95 SimulcastLayerList& send_layers() { return send_layers_; }
96
97 const SimulcastLayerList& receive_layers() const { return receive_layers_; }
98 SimulcastLayerList& receive_layers() { return receive_layers_; }
99
100 bool empty() const;
101
102 private:
103 // TODO(amithi, bugs.webrtc.org/10075):
104 // Validate that rids do not repeat in send and receive layers.
105 SimulcastLayerList send_layers_;
106 SimulcastLayerList receive_layers_;
107};
108
109} // namespace cricket
110
111#endif // PC_SIMULCASTDESCRIPTION_H_