blob: 7caf164de516da1ea302c938f740fcc540b86b65 [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef PC_SIMULCAST_DESCRIPTION_H_
12#define PC_SIMULCAST_DESCRIPTION_H_
Amit Hilbucha2012042018-12-03 11:35:05 -080013
Harald Alvestrand5761e7b2021-01-29 14:45:08 +000014#include <stddef.h>
15
Amit Hilbucha2012042018-12-03 11:35:05 -080016#include <string>
17#include <vector>
18
Niels Möller2d3186e2022-01-24 14:15:03 +010019#include "absl/strings/string_view.h"
20
Amit Hilbucha2012042018-12-03 11:35:05 -080021namespace 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.
27struct SimulcastLayer final {
Niels Möller2d3186e2022-01-24 14:15:03 +010028 SimulcastLayer(absl::string_view rid, bool is_paused);
Amit Hilbucha2012042018-12-03 11:35:05 -080029
30 SimulcastLayer(const SimulcastLayer& other) = default;
31 SimulcastLayer& operator=(const SimulcastLayer& other) = default;
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080032 bool operator==(const SimulcastLayer& other) const;
Amit Hilbucha2012042018-12-03 11:35:05 -080033
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});
54class SimulcastLayerList final {
55 public:
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080056 // 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
Amit Hilbucha2012042018-12-03 11:35:05 -080062 // 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.
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080071 const_iterator begin() const { return list_.begin(); }
Amit Hilbucha2012042018-12-03 11:35:05 -080072
Amit Hilbuchc63ddb22019-01-02 10:13:58 -080073 const_iterator end() const { return list_.end(); }
Amit Hilbucha2012042018-12-03 11:35:05 -080074
75 const std::vector<SimulcastLayer>& operator[](size_t index) const;
76
77 size_t size() const { return list_.size(); }
78 bool empty() const { return list_.empty(); }
79
Amit Hilbuchc57d5732018-12-11 15:30:11 -080080 // Provides access to all the layers in the simulcast without their
81 // association into groups of alternatives.
82 std::vector<SimulcastLayer> GetAllLayers() const;
83
Amit Hilbucha2012042018-12-03 11:35:05 -080084 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
96class SimulcastDescription final {
97 public:
98 const SimulcastLayerList& send_layers() const { return send_layers_; }
99 SimulcastLayerList& send_layers() { return send_layers_; }
100
101 const SimulcastLayerList& receive_layers() const { return 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
Steve Anton10542f22019-01-11 09:11:00 -0800115#endif // PC_SIMULCAST_DESCRIPTION_H_