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