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> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 50 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 51 | #include <cstdint> |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 52 | #include <string> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | #include <vector> |
| 54 | |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame] | 55 | #include "absl/algorithm/container.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 56 | #include "media/base/rid_description.h" |
| 57 | #include "rtc_base/constructor_magic.h" |
Amit Hilbuch | bcd39d4 | 2019-01-25 17:13:56 -0800 | [diff] [blame] | 58 | #include "rtc_base/unique_id_generator.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | |
| 60 | namespace cricket { |
| 61 | |
| 62 | extern const char kFecSsrcGroupSemantics[]; |
brandtr | 9688e38 | 2016-11-22 00:59:48 -0800 | [diff] [blame] | 63 | extern const char kFecFrSsrcGroupSemantics[]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | extern const char kFidSsrcGroupSemantics[]; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 65 | extern const char kSimSsrcGroupSemantics[]; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | |
| 67 | struct SsrcGroup { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 68 | SsrcGroup(const std::string& usage, const std::vector<uint32_t>& ssrcs); |
| 69 | SsrcGroup(const SsrcGroup&); |
| 70 | SsrcGroup(SsrcGroup&&); |
| 71 | ~SsrcGroup(); |
| 72 | SsrcGroup& operator=(const SsrcGroup&); |
| 73 | SsrcGroup& operator=(SsrcGroup&&); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
| 75 | bool operator==(const SsrcGroup& other) const { |
| 76 | return (semantics == other.semantics && ssrcs == other.ssrcs); |
| 77 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 78 | bool operator!=(const SsrcGroup& other) const { return !(*this == other); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | |
| 80 | bool has_semantics(const std::string& semantics) const; |
| 81 | |
| 82 | std::string ToString() const; |
| 83 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 84 | std::string semantics; // e.g FIX, FEC, SIM. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 85 | std::vector<uint32_t> ssrcs; // SSRCs of this type. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
Seth Hampson | 7435b84 | 2018-04-10 10:52:10 -0700 | [diff] [blame] | 88 | // StreamParams is used to represent a sender/track in a SessionDescription. |
| 89 | // In Plan B, this means that multiple StreamParams can exist within one |
| 90 | // MediaContentDescription, while in UnifiedPlan this means that there is one |
| 91 | // StreamParams per MediaContentDescription. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | struct StreamParams { |
Paulina Hensman | 11b34f4 | 2018-04-09 14:24:52 +0200 | [diff] [blame] | 93 | StreamParams(); |
| 94 | StreamParams(const StreamParams&); |
| 95 | StreamParams(StreamParams&&); |
| 96 | ~StreamParams(); |
| 97 | StreamParams& operator=(const StreamParams&); |
| 98 | StreamParams& operator=(StreamParams&&); |
| 99 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 100 | static StreamParams CreateLegacy(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | StreamParams stream; |
| 102 | stream.ssrcs.push_back(ssrc); |
| 103 | return stream; |
| 104 | } |
| 105 | |
Amit Hilbuch | c57d573 | 2018-12-11 15:30:11 -0800 | [diff] [blame] | 106 | bool operator==(const StreamParams& other) const; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 107 | bool operator!=(const StreamParams& other) const { return !(*this == other); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 109 | uint32_t first_ssrc() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 110 | if (ssrcs.empty()) { |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | return ssrcs[0]; |
| 115 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 116 | bool has_ssrcs() const { return !ssrcs.empty(); } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 117 | bool has_ssrc(uint32_t ssrc) const { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame] | 118 | return absl::c_linear_search(ssrcs, ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 120 | void add_ssrc(uint32_t ssrc) { ssrcs.push_back(ssrc); } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 121 | bool has_ssrc_groups() const { return !ssrc_groups.empty(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | bool has_ssrc_group(const std::string& semantics) const { |
| 123 | return (get_ssrc_group(semantics) != NULL); |
| 124 | } |
| 125 | const SsrcGroup* get_ssrc_group(const std::string& semantics) const { |
Steve Anton | c664314 | 2019-02-15 10:50:44 -0800 | [diff] [blame] | 126 | for (const SsrcGroup& ssrc_group : ssrc_groups) { |
| 127 | if (ssrc_group.has_semantics(semantics)) { |
| 128 | return &ssrc_group; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 252 | template <class Condition> |
| 253 | const StreamParams* GetStream(const StreamParamsVec& streams, |
| 254 | Condition condition) { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame] | 255 | auto found = absl::c_find_if(streams, condition); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 256 | return found == streams.end() ? nullptr : &(*found); |
| 257 | } |
| 258 | |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 259 | template <class Condition> |
| 260 | StreamParams* GetStream(StreamParamsVec& streams, Condition condition) { |
Steve Anton | 2c9ebef | 2019-01-28 17:27:58 -0800 | [diff] [blame] | 261 | auto found = absl::c_find_if(streams, condition); |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 262 | return found == streams.end() ? nullptr : &(*found); |
| 263 | } |
| 264 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 265 | inline bool HasStreamWithNoSsrcs(const StreamParamsVec& streams) { |
| 266 | return GetStream(streams, |
| 267 | [](const StreamParams& sp) { return !sp.has_ssrcs(); }); |
| 268 | } |
| 269 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 270 | inline const StreamParams* GetStreamBySsrc(const StreamParamsVec& streams, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 271 | uint32_t ssrc) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 272 | return GetStream( |
| 273 | streams, [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | inline const StreamParams* GetStreamByIds(const StreamParamsVec& streams, |
| 277 | const std::string& groupid, |
| 278 | const std::string& id) { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 279 | return GetStream(streams, [&groupid, &id](const StreamParams& sp) { |
| 280 | return sp.groupid == groupid && sp.id == id; |
| 281 | }); |
| 282 | } |
| 283 | |
| 284 | inline StreamParams* GetStreamByIds(StreamParamsVec& streams, |
| 285 | const std::string& groupid, |
| 286 | const std::string& id) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 287 | return GetStream(streams, [&groupid, &id](const StreamParams& sp) { |
| 288 | return sp.groupid == groupid && sp.id == id; |
| 289 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | inline const StreamParams* GetStream(const StreamParamsVec& streams, |
| 293 | const StreamSelector& selector) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 294 | return GetStream(streams, [&selector](const StreamParams& sp) { |
| 295 | return selector.Matches(sp); |
| 296 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 297 | } |
| 298 | |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 299 | template <class Condition> |
| 300 | bool RemoveStream(StreamParamsVec* streams, Condition condition) { |
| 301 | auto iter(std::remove_if(streams->begin(), streams->end(), condition)); |
| 302 | if (iter == streams->end()) |
| 303 | return false; |
| 304 | streams->erase(iter, streams->end()); |
| 305 | return true; |
| 306 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 307 | |
| 308 | // Removes the stream from streams. Returns true if a stream is |
| 309 | // found and removed. |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 310 | inline bool RemoveStream(StreamParamsVec* streams, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 311 | const StreamSelector& selector) { |
| 312 | return RemoveStream(streams, [&selector](const StreamParams& sp) { |
| 313 | return selector.Matches(sp); |
| 314 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 315 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 316 | inline bool RemoveStreamBySsrc(StreamParamsVec* streams, uint32_t ssrc) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 317 | return RemoveStream( |
| 318 | streams, [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 319 | } |
| 320 | inline bool RemoveStreamByIds(StreamParamsVec* streams, |
| 321 | const std::string& groupid, |
| 322 | const std::string& id) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 323 | return RemoveStream(streams, [&groupid, &id](const StreamParams& sp) { |
| 324 | return sp.groupid == groupid && sp.id == id; |
| 325 | }); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 326 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 327 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 328 | } // namespace cricket |
| 329 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 330 | #endif // MEDIA_BASE_STREAM_PARAMS_H_ |