Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef PC_SIMULCAST_DESCRIPTION_H_ |
| 12 | #define PC_SIMULCAST_DESCRIPTION_H_ |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 13 | |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 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; |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 30 | bool operator==(const SimulcastLayer& other) const; |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 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: |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 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 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 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. |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 69 | const_iterator begin() const { return list_.begin(); } |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 70 | |
Amit Hilbuch | c63ddb2 | 2019-01-02 18:13:58 | [diff] [blame] | 71 | const_iterator end() const { return list_.end(); } |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 72 | |
| 73 | const std::vector<SimulcastLayer>& operator[](size_t index) const; |
| 74 | |
| 75 | size_t size() const { return list_.size(); } |
| 76 | bool empty() const { return list_.empty(); } |
| 77 | |
Amit Hilbuch | c57d573 | 2018-12-11 23:30:11 | [diff] [blame] | 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 | |
Amit Hilbuch | a201204 | 2018-12-03 19:35:05 | [diff] [blame] | 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: |
| 96 | const SimulcastLayerList& send_layers() const { return send_layers_; } |
| 97 | SimulcastLayerList& send_layers() { return send_layers_; } |
| 98 | |
| 99 | const SimulcastLayerList& receive_layers() const { return 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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 113 | #endif // PC_SIMULCAST_DESCRIPTION_H_ |