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