henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | // This file contains structures for describing SSRCs from a media source such |
| 12 | // as a MediaStreamTrack when it is sent across an RTP session. Multiple media |
| 13 | // sources may be sent across the same RTP session, each of them will be |
| 14 | // described by one StreamParams object |
| 15 | // SsrcGroup is used to describe the relationship between the SSRCs that |
| 16 | // are used for this media source. |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 17 | // E.x: Consider a source that is sent as 3 simulcast streams |
| 18 | // Let the simulcast elements have SSRC 10, 20, 30. |
| 19 | // Let each simulcast element use FEC and let the protection packets have |
| 20 | // SSRC 11,21,31. |
| 21 | // To describe this 4 SsrcGroups are needed, |
| 22 | // StreamParams would then contain ssrc = {10,11,20,21,30,31} and |
| 23 | // ssrc_groups = {{SIM,{10,20,30}, {FEC,{10,11}, {FEC, {20,21}, {FEC {30,31}}} |
| 24 | // Please see RFC 5576. |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 25 | // A spec-compliant way to achieve this is to use RIDs and Simulcast attribute |
| 26 | // instead of the ssrc-group. In this method, the StreamParam object will |
| 27 | // have multiple RidDescriptions, each corresponding to a simulcast layer |
| 28 | // and the media section will have a simulcast attribute that indicates |
| 29 | // that these layers are for the same source. This also removes the extra |
| 30 | // lines for redundancy streams, as the same RIDs appear in the redundancy |
| 31 | // packets. |
| 32 | // Note: in the spec compliant simulcast scenario, some of the RIDs might be |
| 33 | // alternatives for one another (such as different encodings for same data). |
| 34 | // In the context of the StreamParams class, the notion of alternatives does |
| 35 | // not exist and all the RIDs will describe different layers of the same source. |
| 36 | // When the StreamParams class is used to configure the media engine, simulcast |
| 37 | // considerations will be used to remove the alternative layers outside of this |
| 38 | // class. |
| 39 | // As an example, let the simulcast layers have RID 10, 20, 30. |
| 40 | // StreamParams would contain rid = { 10, 20, 30 }. |
| 41 | // MediaSection would contain SimulcastDescription specifying these rids. |
| 42 | // a=simulcast:send 10;20;30 (or a=simulcast:send 10,20;30 or similar). |
| 43 | // See https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-13 |
| 44 | // and https://tools.ietf.org/html/draft-ietf-mmusic-rid-15. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 46 | #ifndef MEDIA_BASE_STREAM_PARAMS_H_ |
| 47 | #define MEDIA_BASE_STREAM_PARAMS_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 48 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 49 | #include <stddef.h> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 50 | #include <cstdint> |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 51 | #include <string> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | #include <vector> |
| 53 | |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame^] | 54 | #include "absl/algorithm/container.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 55 | #include "media/base/rid_description.h" |
| 56 | #include "rtc_base/constructor_magic.h" |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 57 | #include "rtc_base/unique_id_generator.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | |
| 59 | namespace cricket { |
| 60 | |
| 61 | extern const char kFecSsrcGroupSemantics[]; |
brandtr | 9688e38 | 2016-11-22 00:59:48 -0800 | [diff] [blame] | 62 | extern const char kFecFrSsrcGroupSemantics[]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 63 | extern const char kFidSsrcGroupSemantics[]; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 64 | extern const char kSimSsrcGroupSemantics[]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | |
| 66 | struct SsrcGroup { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 67 | SsrcGroup(const std::string& usage, const std::vector<uint32_t>& ssrcs); |
| 68 | SsrcGroup(const SsrcGroup&); |
| 69 | SsrcGroup(SsrcGroup&&); |
| 70 | ~SsrcGroup(); |
| 71 | SsrcGroup& operator=(const SsrcGroup&); |
| 72 | SsrcGroup& operator=(SsrcGroup&&); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | |
| 74 | bool operator==(const SsrcGroup& other) const { |
| 75 | return (semantics == other.semantics && ssrcs == other.ssrcs); |
| 76 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 77 | bool operator!=(const SsrcGroup& other) const { return !(*this == other); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | |
| 79 | bool has_semantics(const std::string& semantics) const; |
| 80 | |
| 81 | std::string ToString() const; |
| 82 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 83 | std::string semantics; // e.g FIX, FEC, SIM. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 84 | std::vector<uint32_t> ssrcs; // SSRCs of this type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
Seth Hampson | 7435b84 | 2018-04-10 10:52:10 -0700 | [diff] [blame] | 87 | // StreamParams is used to represent a sender/track in a SessionDescription. |
| 88 | // In Plan B, this means that multiple StreamParams can exist within one |
| 89 | // MediaContentDescription, while in UnifiedPlan this means that there is one |
| 90 | // StreamParams per MediaContentDescription. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | struct StreamParams { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 92 | StreamParams(); |
| 93 | StreamParams(const StreamParams&); |
| 94 | StreamParams(StreamParams&&); |
| 95 | ~StreamParams(); |
| 96 | StreamParams& operator=(const StreamParams&); |
| 97 | StreamParams& operator=(StreamParams&&); |
| 98 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 99 | static StreamParams CreateLegacy(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 100 | StreamParams stream; |
| 101 | stream.ssrcs.push_back(ssrc); |
| 102 | return stream; |
| 103 | } |
| 104 | |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 105 | bool operator==(const StreamParams& other) const; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 106 | bool operator!=(const StreamParams& other) const { return !(*this == other); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 107 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 108 | uint32_t first_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | if (ssrcs.empty()) { |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | return ssrcs[0]; |
| 114 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 115 | bool has_ssrcs() const { return !ssrcs.empty(); } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 116 | bool has_ssrc(uint32_t ssrc) const { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame^] | 117 | return absl::c_linear_search(ssrcs, ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 119 | void add_ssrc(uint32_t ssrc) { ssrcs.push_back(ssrc); } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 120 | bool has_ssrc_groups() const { return !ssrc_groups.empty(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | bool has_ssrc_group(const std::string& semantics) const { |
| 122 | return (get_ssrc_group(semantics) != NULL); |
| 123 | } |
| 124 | const SsrcGroup* get_ssrc_group(const std::string& semantics) const { |
| 125 | for (std::vector<SsrcGroup>::const_iterator it = ssrc_groups.begin(); |
| 126 | it != ssrc_groups.end(); ++it) { |
| 127 | if (it->has_semantics(semantics)) { |
| 128 | return &(*it); |
| 129 | } |
| 130 | } |
| 131 | return NULL; |
| 132 | } |
| 133 | |
| 134 | // Convenience function to add an FID ssrc for a primary_ssrc |
| 135 | // that's already been added. |
brandtr | 9688e38 | 2016-11-22 00:59:48 -0800 | [diff] [blame] | 136 | bool AddFidSsrc(uint32_t primary_ssrc, uint32_t fid_ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 137 | return AddSecondarySsrc(kFidSsrcGroupSemantics, primary_ssrc, fid_ssrc); |
| 138 | } |
| 139 | |
| 140 | // Convenience function to lookup the FID ssrc for a primary_ssrc. |
| 141 | // Returns false if primary_ssrc not found or FID not defined for it. |
brandtr | 9688e38 | 2016-11-22 00:59:48 -0800 | [diff] [blame] | 142 | bool GetFidSsrc(uint32_t primary_ssrc, uint32_t* fid_ssrc) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | return GetSecondarySsrc(kFidSsrcGroupSemantics, primary_ssrc, fid_ssrc); |
| 144 | } |
| 145 | |
brandtr | 9688e38 | 2016-11-22 00:59:48 -0800 | [diff] [blame] | 146 | // Convenience function to add an FEC-FR ssrc for a primary_ssrc |
| 147 | // that's already been added. |
| 148 | bool AddFecFrSsrc(uint32_t primary_ssrc, uint32_t fecfr_ssrc) { |
| 149 | return AddSecondarySsrc(kFecFrSsrcGroupSemantics, primary_ssrc, fecfr_ssrc); |
| 150 | } |
| 151 | |
| 152 | // Convenience function to lookup the FEC-FR ssrc for a primary_ssrc. |
| 153 | // Returns false if primary_ssrc not found or FEC-FR not defined for it. |
| 154 | bool GetFecFrSsrc(uint32_t primary_ssrc, uint32_t* fecfr_ssrc) const { |
| 155 | return GetSecondarySsrc(kFecFrSsrcGroupSemantics, primary_ssrc, fecfr_ssrc); |
| 156 | } |
| 157 | |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 158 | // Convenience function to populate the StreamParams with the requested number |
| 159 | // of SSRCs along with accompanying FID and FEC-FR ssrcs if requested. |
| 160 | // SSRCs are generated using the given generator. |
| 161 | void GenerateSsrcs(int num_layers, |
| 162 | bool generate_fid, |
| 163 | bool generate_fec_fr, |
| 164 | rtc::UniqueRandomIdGenerator* ssrc_generator); |
| 165 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 166 | // Convenience to get all the SIM SSRCs if there are SIM ssrcs, or |
| 167 | // the first SSRC otherwise. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 168 | void GetPrimarySsrcs(std::vector<uint32_t>* ssrcs) const; |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 169 | |
| 170 | // Convenience to get all the FID SSRCs for the given primary ssrcs. |
| 171 | // If a given primary SSRC does not have a FID SSRC, the list of FID |
| 172 | // SSRCS will be smaller than the list of primary SSRCs. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 173 | void GetFidSsrcs(const std::vector<uint32_t>& primary_ssrcs, |
| 174 | std::vector<uint32_t>* fid_ssrcs) const; |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 175 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 176 | // Stream ids serialized to SDP. |
| 177 | std::vector<std::string> stream_ids() const; |
| 178 | void set_stream_ids(const std::vector<std::string>& stream_ids); |
Steve Anton | ac7539e | 2018-02-26 17:20:29 -0800 | [diff] [blame] | 179 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 180 | // Returns the first stream id or "" if none exist. This method exists only |
Steve Anton | 5a26a3a | 2018-02-28 11:38:47 -0800 | [diff] [blame] | 181 | // as temporary backwards compatibility with the old sync_label. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 182 | std::string first_stream_id() const; |
Steve Anton | 5a26a3a | 2018-02-28 11:38:47 -0800 | [diff] [blame] | 183 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 184 | std::string ToString() const; |
| 185 | |
| 186 | // Resource of the MUC jid of the participant of with this stream. |
| 187 | // For 1:1 calls, should be left empty (which means remote streams |
Seth Hampson | 7435b84 | 2018-04-10 10:52:10 -0700 | [diff] [blame] | 188 | // and local streams should not be mixed together). This is not used |
| 189 | // internally and should be deprecated. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 190 | std::string groupid; |
Seth Hampson | 7435b84 | 2018-04-10 10:52:10 -0700 | [diff] [blame] | 191 | // A unique identifier of the StreamParams object. When the SDP is created, |
| 192 | // this comes from the track ID of the sender that the StreamParams object |
| 193 | // is associated with. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | std::string id; |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 195 | // There may be no SSRCs stored in unsignaled case when stream_ids are |
| 196 | // signaled with a=msid lines. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 197 | std::vector<uint32_t> ssrcs; // All SSRCs for this source |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 198 | std::vector<SsrcGroup> ssrc_groups; // e.g. FID, FEC, SIM |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 199 | std::string cname; // RTCP CNAME |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 201 | // RID functionality according to |
| 202 | // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15 |
| 203 | // Each layer can be represented by a RID identifier and can also have |
| 204 | // restrictions (such as max-width, max-height, etc.) |
| 205 | // If the track has multiple layers (ex. Simulcast), each layer will be |
| 206 | // represented by a RID. |
| 207 | bool has_rids() const { return !rids_.empty(); } |
| 208 | const std::vector<RidDescription>& rids() const { return rids_; } |
| 209 | void set_rids(const std::vector<RidDescription>& rids) { rids_ = rids; } |
| 210 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 211 | private: |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 212 | bool AddSecondarySsrc(const std::string& semantics, |
| 213 | uint32_t primary_ssrc, |
| 214 | uint32_t secondary_ssrc); |
| 215 | bool GetSecondarySsrc(const std::string& semantics, |
| 216 | uint32_t primary_ssrc, |
| 217 | uint32_t* secondary_ssrc) const; |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 218 | |
Seth Hampson | 7435b84 | 2018-04-10 10:52:10 -0700 | [diff] [blame] | 219 | // The stream IDs of the sender that the StreamParams object is associated |
| 220 | // with. In Plan B this should always be size of 1, while in Unified Plan this |
| 221 | // could be none or multiple stream IDs. |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 222 | std::vector<std::string> stream_ids_; |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 223 | |
| 224 | std::vector<RidDescription> rids_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
| 227 | // A Stream can be selected by either groupid+id or ssrc. |
| 228 | struct StreamSelector { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 229 | explicit StreamSelector(uint32_t ssrc) : ssrc(ssrc) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 230 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 231 | StreamSelector(const std::string& groupid, const std::string& streamid) |
| 232 | : ssrc(0), groupid(groupid), streamid(streamid) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | |
Seth Hampson | 23ffbe7 | 2018-03-30 16:59:31 -0700 | [diff] [blame] | 234 | explicit StreamSelector(const std::string& streamid) |
| 235 | : ssrc(0), streamid(streamid) {} |
| 236 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 237 | bool Matches(const StreamParams& stream) const { |
| 238 | if (ssrc == 0) { |
| 239 | return stream.groupid == groupid && stream.id == streamid; |
| 240 | } else { |
| 241 | return stream.has_ssrc(ssrc); |
| 242 | } |
| 243 | } |
| 244 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 245 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 246 | std::string groupid; |
| 247 | std::string streamid; |
| 248 | }; |
| 249 | |
| 250 | typedef std::vector<StreamParams> StreamParamsVec; |
| 251 | |
pthatcher@webrtc.org | e2b7585 | 2014-12-16 21:09:08 +0000 | [diff] [blame] | 252 | // A collection of audio and video and data streams. Most of the |
| 253 | // methods are merely for convenience. Many of these methods are keyed |
| 254 | // by ssrc, which is the source identifier in the RTP spec |
| 255 | // (http://tools.ietf.org/html/rfc3550). |
| 256 | // TODO(pthatcher): Add basic unit test for these. |
| 257 | // See https://code.google.com/p/webrtc/issues/detail?id=4107 |
| 258 | struct MediaStreams { |
| 259 | public: |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 260 | MediaStreams(); |
| 261 | ~MediaStreams(); |
pthatcher@webrtc.org | e2b7585 | 2014-12-16 21:09:08 +0000 | [diff] [blame] | 262 | void CopyFrom(const MediaStreams& sources); |
| 263 | |
| 264 | bool empty() const { |
| 265 | return audio_.empty() && video_.empty() && data_.empty(); |
| 266 | } |
| 267 | |
| 268 | std::vector<StreamParams>* mutable_audio() { return &audio_; } |
| 269 | std::vector<StreamParams>* mutable_video() { return &video_; } |
| 270 | std::vector<StreamParams>* mutable_data() { return &data_; } |
| 271 | const std::vector<StreamParams>& audio() const { return audio_; } |
| 272 | const std::vector<StreamParams>& video() const { return video_; } |
| 273 | const std::vector<StreamParams>& data() const { return data_; } |
| 274 | |
| 275 | // Gets a stream, returning true if found. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 276 | bool GetAudioStream(const StreamSelector& selector, StreamParams* stream); |
| 277 | bool GetVideoStream(const StreamSelector& selector, StreamParams* stream); |
| 278 | bool GetDataStream(const StreamSelector& selector, StreamParams* stream); |
pthatcher@webrtc.org | e2b7585 | 2014-12-16 21:09:08 +0000 | [diff] [blame] | 279 | // Adds a stream. |
| 280 | void AddAudioStream(const StreamParams& stream); |
| 281 | void AddVideoStream(const StreamParams& stream); |
| 282 | void AddDataStream(const StreamParams& stream); |
| 283 | // Removes a stream, returning true if found and removed. |
| 284 | bool RemoveAudioStream(const StreamSelector& selector); |
| 285 | bool RemoveVideoStream(const StreamSelector& selector); |
| 286 | bool RemoveDataStream(const StreamSelector& selector); |
| 287 | |
| 288 | private: |
| 289 | std::vector<StreamParams> audio_; |
| 290 | std::vector<StreamParams> video_; |
| 291 | std::vector<StreamParams> data_; |
| 292 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 293 | RTC_DISALLOW_COPY_AND_ASSIGN(MediaStreams); |
pthatcher@webrtc.org | e2b7585 | 2014-12-16 21:09:08 +0000 | [diff] [blame] | 294 | }; |
| 295 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 296 | template <class Condition> |
| 297 | const StreamParams* GetStream(const StreamParamsVec& streams, |
| 298 | Condition condition) { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame^] | 299 | auto found = absl::c_find_if(streams, condition); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 300 | return found == streams.end() ? nullptr : &(*found); |
| 301 | } |
| 302 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 303 | template <class Condition> |
| 304 | StreamParams* GetStream(StreamParamsVec& streams, Condition condition) { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame^] | 305 | auto found = absl::c_find_if(streams, condition); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 306 | return found == streams.end() ? nullptr : &(*found); |
| 307 | } |
| 308 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 309 | inline bool HasStreamWithNoSsrcs(const StreamParamsVec& streams) { |
| 310 | return GetStream(streams, |
| 311 | [](const StreamParams& sp) { return !sp.has_ssrcs(); }); |
| 312 | } |
| 313 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 314 | inline const StreamParams* GetStreamBySsrc(const StreamParamsVec& streams, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 315 | uint32_t ssrc) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 316 | return GetStream( |
| 317 | streams, [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | inline const StreamParams* GetStreamByIds(const StreamParamsVec& streams, |
| 321 | const std::string& groupid, |
| 322 | const std::string& id) { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 323 | return GetStream(streams, [&groupid, &id](const StreamParams& sp) { |
| 324 | return sp.groupid == groupid && sp.id == id; |
| 325 | }); |
| 326 | } |
| 327 | |
| 328 | inline StreamParams* GetStreamByIds(StreamParamsVec& streams, |
| 329 | const std::string& groupid, |
| 330 | const std::string& id) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 331 | return GetStream(streams, [&groupid, &id](const StreamParams& sp) { |
| 332 | return sp.groupid == groupid && sp.id == id; |
| 333 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | inline const StreamParams* GetStream(const StreamParamsVec& streams, |
| 337 | const StreamSelector& selector) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 338 | return GetStream(streams, [&selector](const StreamParams& sp) { |
| 339 | return selector.Matches(sp); |
| 340 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 341 | } |
| 342 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 343 | template <class Condition> |
| 344 | bool RemoveStream(StreamParamsVec* streams, Condition condition) { |
| 345 | auto iter(std::remove_if(streams->begin(), streams->end(), condition)); |
| 346 | if (iter == streams->end()) |
| 347 | return false; |
| 348 | streams->erase(iter, streams->end()); |
| 349 | return true; |
| 350 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | |
| 352 | // Removes the stream from streams. Returns true if a stream is |
| 353 | // found and removed. |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 354 | inline bool RemoveStream(StreamParamsVec* streams, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 355 | const StreamSelector& selector) { |
| 356 | return RemoveStream(streams, [&selector](const StreamParams& sp) { |
| 357 | return selector.Matches(sp); |
| 358 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 359 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 360 | inline bool RemoveStreamBySsrc(StreamParamsVec* streams, uint32_t ssrc) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 361 | return RemoveStream( |
| 362 | streams, [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 363 | } |
| 364 | inline bool RemoveStreamByIds(StreamParamsVec* streams, |
| 365 | const std::string& groupid, |
| 366 | const std::string& id) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 367 | return RemoveStream(streams, [&groupid, &id](const StreamParams& sp) { |
| 368 | return sp.groupid == groupid && sp.id == id; |
| 369 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 370 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 371 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 372 | // Checks if |sp| defines parameters for a single primary stream. There may |
brandtr | 9688e38 | 2016-11-22 00:59:48 -0800 | [diff] [blame] | 373 | // be an RTX stream or a FlexFEC stream (or both) associated with the primary |
| 374 | // stream. Leaving as non-static so we can test this function. |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 375 | bool IsOneSsrcStream(const StreamParams& sp); |
| 376 | |
| 377 | // Checks if |sp| defines parameters for one Simulcast stream. There may be RTX |
| 378 | // streams associated with the simulcast streams. Leaving as non-static so we |
| 379 | // can test this function. |
| 380 | bool IsSimulcastStream(const StreamParams& sp); |
| 381 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 382 | } // namespace cricket |
| 383 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 384 | #endif // MEDIA_BASE_STREAM_PARAMS_H_ |