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 <string> 15 #include <vector> 16 17 namespace 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. 23 struct 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; 28 bool operator==(const SimulcastLayer& other) const; 29 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}); 50 class SimulcastLayerList final { 51 public: 52 // 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 58 // 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. begin()67 const_iterator begin() const { return list_.begin(); } 68 end()69 const_iterator end() const { return list_.end(); } 70 71 const std::vector<SimulcastLayer>& operator[](size_t index) const; 72 size()73 size_t size() const { return list_.size(); } empty()74 bool empty() const { return list_.empty(); } 75 76 // Provides access to all the layers in the simulcast without their 77 // association into groups of alternatives. 78 std::vector<SimulcastLayer> GetAllLayers() const; 79 80 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 92 class SimulcastDescription final { 93 public: send_layers()94 const SimulcastLayerList& send_layers() const { return send_layers_; } send_layers()95 SimulcastLayerList& send_layers() { return send_layers_; } 96 receive_layers()97 const SimulcastLayerList& receive_layers() const { return receive_layers_; } 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_SIMULCAST_DESCRIPTION_H_ 112