OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "webrtc/base/basictypes.h" | 51 #include "webrtc/base/basictypes.h" |
52 #include "webrtc/base/constructormagic.h" | 52 #include "webrtc/base/constructormagic.h" |
53 | 53 |
54 namespace cricket { | 54 namespace cricket { |
55 | 55 |
56 extern const char kFecSsrcGroupSemantics[]; | 56 extern const char kFecSsrcGroupSemantics[]; |
57 extern const char kFidSsrcGroupSemantics[]; | 57 extern const char kFidSsrcGroupSemantics[]; |
58 extern const char kSimSsrcGroupSemantics[]; | 58 extern const char kSimSsrcGroupSemantics[]; |
59 | 59 |
60 struct SsrcGroup { | 60 struct SsrcGroup { |
61 SsrcGroup(const std::string& usage, const std::vector<uint32>& ssrcs) | 61 SsrcGroup(const std::string& usage, const std::vector<uint32_t>& ssrcs) |
62 : semantics(usage), ssrcs(ssrcs) { | 62 : semantics(usage), ssrcs(ssrcs) {} |
63 } | |
64 | 63 |
65 bool operator==(const SsrcGroup& other) const { | 64 bool operator==(const SsrcGroup& other) const { |
66 return (semantics == other.semantics && ssrcs == other.ssrcs); | 65 return (semantics == other.semantics && ssrcs == other.ssrcs); |
67 } | 66 } |
68 bool operator!=(const SsrcGroup &other) const { | 67 bool operator!=(const SsrcGroup &other) const { |
69 return !(*this == other); | 68 return !(*this == other); |
70 } | 69 } |
71 | 70 |
72 bool has_semantics(const std::string& semantics) const; | 71 bool has_semantics(const std::string& semantics) const; |
73 | 72 |
74 std::string ToString() const; | 73 std::string ToString() const; |
75 | 74 |
76 std::string semantics; // e.g FIX, FEC, SIM. | 75 std::string semantics; // e.g FIX, FEC, SIM. |
77 std::vector<uint32> ssrcs; // SSRCs of this type. | 76 std::vector<uint32_t> ssrcs; // SSRCs of this type. |
78 }; | 77 }; |
79 | 78 |
80 struct StreamParams { | 79 struct StreamParams { |
81 static StreamParams CreateLegacy(uint32 ssrc) { | 80 static StreamParams CreateLegacy(uint32_t ssrc) { |
82 StreamParams stream; | 81 StreamParams stream; |
83 stream.ssrcs.push_back(ssrc); | 82 stream.ssrcs.push_back(ssrc); |
84 return stream; | 83 return stream; |
85 } | 84 } |
86 | 85 |
87 bool operator==(const StreamParams& other) const { | 86 bool operator==(const StreamParams& other) const { |
88 return (groupid == other.groupid && | 87 return (groupid == other.groupid && |
89 id == other.id && | 88 id == other.id && |
90 ssrcs == other.ssrcs && | 89 ssrcs == other.ssrcs && |
91 ssrc_groups == other.ssrc_groups && | 90 ssrc_groups == other.ssrc_groups && |
92 type == other.type && | 91 type == other.type && |
93 display == other.display && | 92 display == other.display && |
94 cname == other.cname && | 93 cname == other.cname && |
95 sync_label == other.sync_label); | 94 sync_label == other.sync_label); |
96 } | 95 } |
97 bool operator!=(const StreamParams &other) const { | 96 bool operator!=(const StreamParams &other) const { |
98 return !(*this == other); | 97 return !(*this == other); |
99 } | 98 } |
100 | 99 |
101 uint32 first_ssrc() const { | 100 uint32_t first_ssrc() const { |
102 if (ssrcs.empty()) { | 101 if (ssrcs.empty()) { |
103 return 0; | 102 return 0; |
104 } | 103 } |
105 | 104 |
106 return ssrcs[0]; | 105 return ssrcs[0]; |
107 } | 106 } |
108 bool has_ssrcs() const { | 107 bool has_ssrcs() const { |
109 return !ssrcs.empty(); | 108 return !ssrcs.empty(); |
110 } | 109 } |
111 bool has_ssrc(uint32 ssrc) const { | 110 bool has_ssrc(uint32_t ssrc) const { |
112 return std::find(ssrcs.begin(), ssrcs.end(), ssrc) != ssrcs.end(); | 111 return std::find(ssrcs.begin(), ssrcs.end(), ssrc) != ssrcs.end(); |
113 } | 112 } |
114 void add_ssrc(uint32 ssrc) { | 113 void add_ssrc(uint32_t ssrc) { ssrcs.push_back(ssrc); } |
115 ssrcs.push_back(ssrc); | |
116 } | |
117 bool has_ssrc_groups() const { | 114 bool has_ssrc_groups() const { |
118 return !ssrc_groups.empty(); | 115 return !ssrc_groups.empty(); |
119 } | 116 } |
120 bool has_ssrc_group(const std::string& semantics) const { | 117 bool has_ssrc_group(const std::string& semantics) const { |
121 return (get_ssrc_group(semantics) != NULL); | 118 return (get_ssrc_group(semantics) != NULL); |
122 } | 119 } |
123 const SsrcGroup* get_ssrc_group(const std::string& semantics) const { | 120 const SsrcGroup* get_ssrc_group(const std::string& semantics) const { |
124 for (std::vector<SsrcGroup>::const_iterator it = ssrc_groups.begin(); | 121 for (std::vector<SsrcGroup>::const_iterator it = ssrc_groups.begin(); |
125 it != ssrc_groups.end(); ++it) { | 122 it != ssrc_groups.end(); ++it) { |
126 if (it->has_semantics(semantics)) { | 123 if (it->has_semantics(semantics)) { |
127 return &(*it); | 124 return &(*it); |
128 } | 125 } |
129 } | 126 } |
130 return NULL; | 127 return NULL; |
131 } | 128 } |
132 | 129 |
133 // Convenience function to add an FID ssrc for a primary_ssrc | 130 // Convenience function to add an FID ssrc for a primary_ssrc |
134 // that's already been added. | 131 // that's already been added. |
135 inline bool AddFidSsrc(uint32 primary_ssrc, uint32 fid_ssrc) { | 132 inline bool AddFidSsrc(uint32_t primary_ssrc, uint32_t fid_ssrc) { |
136 return AddSecondarySsrc(kFidSsrcGroupSemantics, primary_ssrc, fid_ssrc); | 133 return AddSecondarySsrc(kFidSsrcGroupSemantics, primary_ssrc, fid_ssrc); |
137 } | 134 } |
138 | 135 |
139 // Convenience function to lookup the FID ssrc for a primary_ssrc. | 136 // Convenience function to lookup the FID ssrc for a primary_ssrc. |
140 // Returns false if primary_ssrc not found or FID not defined for it. | 137 // Returns false if primary_ssrc not found or FID not defined for it. |
141 inline bool GetFidSsrc(uint32 primary_ssrc, uint32* fid_ssrc) const { | 138 inline bool GetFidSsrc(uint32_t primary_ssrc, uint32_t* fid_ssrc) const { |
142 return GetSecondarySsrc(kFidSsrcGroupSemantics, primary_ssrc, fid_ssrc); | 139 return GetSecondarySsrc(kFidSsrcGroupSemantics, primary_ssrc, fid_ssrc); |
143 } | 140 } |
144 | 141 |
145 // Convenience to get all the SIM SSRCs if there are SIM ssrcs, or | 142 // Convenience to get all the SIM SSRCs if there are SIM ssrcs, or |
146 // the first SSRC otherwise. | 143 // the first SSRC otherwise. |
147 void GetPrimarySsrcs(std::vector<uint32>* ssrcs) const; | 144 void GetPrimarySsrcs(std::vector<uint32_t>* ssrcs) const; |
148 | 145 |
149 // Convenience to get all the FID SSRCs for the given primary ssrcs. | 146 // Convenience to get all the FID SSRCs for the given primary ssrcs. |
150 // If a given primary SSRC does not have a FID SSRC, the list of FID | 147 // If a given primary SSRC does not have a FID SSRC, the list of FID |
151 // SSRCS will be smaller than the list of primary SSRCs. | 148 // SSRCS will be smaller than the list of primary SSRCs. |
152 void GetFidSsrcs(const std::vector<uint32>& primary_ssrcs, | 149 void GetFidSsrcs(const std::vector<uint32_t>& primary_ssrcs, |
153 std::vector<uint32>* fid_ssrcs) const; | 150 std::vector<uint32_t>* fid_ssrcs) const; |
154 | 151 |
155 std::string ToString() const; | 152 std::string ToString() const; |
156 | 153 |
157 // Resource of the MUC jid of the participant of with this stream. | 154 // Resource of the MUC jid of the participant of with this stream. |
158 // For 1:1 calls, should be left empty (which means remote streams | 155 // For 1:1 calls, should be left empty (which means remote streams |
159 // and local streams should not be mixed together). | 156 // and local streams should not be mixed together). |
160 std::string groupid; | 157 std::string groupid; |
161 // Unique per-groupid, not across all groupids | 158 // Unique per-groupid, not across all groupids |
162 std::string id; | 159 std::string id; |
163 std::vector<uint32> ssrcs; // All SSRCs for this source | 160 std::vector<uint32_t> ssrcs; // All SSRCs for this source |
164 std::vector<SsrcGroup> ssrc_groups; // e.g. FID, FEC, SIM | 161 std::vector<SsrcGroup> ssrc_groups; // e.g. FID, FEC, SIM |
165 // Examples: "camera", "screencast" | 162 // Examples: "camera", "screencast" |
166 std::string type; | 163 std::string type; |
167 // Friendly name describing stream | 164 // Friendly name describing stream |
168 std::string display; | 165 std::string display; |
169 std::string cname; // RTCP CNAME | 166 std::string cname; // RTCP CNAME |
170 std::string sync_label; // Friendly name of cname. | 167 std::string sync_label; // Friendly name of cname. |
171 | 168 |
172 private: | 169 private: |
173 bool AddSecondarySsrc(const std::string& semantics, uint32 primary_ssrc, | 170 bool AddSecondarySsrc(const std::string& semantics, |
174 uint32 secondary_ssrc); | 171 uint32_t primary_ssrc, |
175 bool GetSecondarySsrc(const std::string& semantics, uint32 primary_ssrc, | 172 uint32_t secondary_ssrc); |
176 uint32* secondary_ssrc) const; | 173 bool GetSecondarySsrc(const std::string& semantics, |
| 174 uint32_t primary_ssrc, |
| 175 uint32_t* secondary_ssrc) const; |
177 }; | 176 }; |
178 | 177 |
179 // A Stream can be selected by either groupid+id or ssrc. | 178 // A Stream can be selected by either groupid+id or ssrc. |
180 struct StreamSelector { | 179 struct StreamSelector { |
181 explicit StreamSelector(uint32 ssrc) : | 180 explicit StreamSelector(uint32_t ssrc) : ssrc(ssrc) {} |
182 ssrc(ssrc) { | |
183 } | |
184 | 181 |
185 StreamSelector(const std::string& groupid, | 182 StreamSelector(const std::string& groupid, |
186 const std::string& streamid) : | 183 const std::string& streamid) : |
187 ssrc(0), | 184 ssrc(0), |
188 groupid(groupid), | 185 groupid(groupid), |
189 streamid(streamid) { | 186 streamid(streamid) { |
190 } | 187 } |
191 | 188 |
192 bool Matches(const StreamParams& stream) const { | 189 bool Matches(const StreamParams& stream) const { |
193 if (ssrc == 0) { | 190 if (ssrc == 0) { |
194 return stream.groupid == groupid && stream.id == streamid; | 191 return stream.groupid == groupid && stream.id == streamid; |
195 } else { | 192 } else { |
196 return stream.has_ssrc(ssrc); | 193 return stream.has_ssrc(ssrc); |
197 } | 194 } |
198 } | 195 } |
199 | 196 |
200 uint32 ssrc; | 197 uint32_t ssrc; |
201 std::string groupid; | 198 std::string groupid; |
202 std::string streamid; | 199 std::string streamid; |
203 }; | 200 }; |
204 | 201 |
205 typedef std::vector<StreamParams> StreamParamsVec; | 202 typedef std::vector<StreamParams> StreamParamsVec; |
206 | 203 |
207 // A collection of audio and video and data streams. Most of the | 204 // A collection of audio and video and data streams. Most of the |
208 // methods are merely for convenience. Many of these methods are keyed | 205 // methods are merely for convenience. Many of these methods are keyed |
209 // by ssrc, which is the source identifier in the RTP spec | 206 // by ssrc, which is the source identifier in the RTP spec |
210 // (http://tools.ietf.org/html/rfc3550). | 207 // (http://tools.ietf.org/html/rfc3550). |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 274 |
278 template <class Condition> | 275 template <class Condition> |
279 const StreamParams* GetStream(const StreamParamsVec& streams, | 276 const StreamParams* GetStream(const StreamParamsVec& streams, |
280 Condition condition) { | 277 Condition condition) { |
281 StreamParamsVec::const_iterator found = | 278 StreamParamsVec::const_iterator found = |
282 std::find_if(streams.begin(), streams.end(), condition); | 279 std::find_if(streams.begin(), streams.end(), condition); |
283 return found == streams.end() ? nullptr : &(*found); | 280 return found == streams.end() ? nullptr : &(*found); |
284 } | 281 } |
285 | 282 |
286 inline const StreamParams* GetStreamBySsrc(const StreamParamsVec& streams, | 283 inline const StreamParams* GetStreamBySsrc(const StreamParamsVec& streams, |
287 uint32 ssrc) { | 284 uint32_t ssrc) { |
288 return GetStream(streams, | 285 return GetStream(streams, |
289 [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); | 286 [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); |
290 } | 287 } |
291 | 288 |
292 inline const StreamParams* GetStreamByIds(const StreamParamsVec& streams, | 289 inline const StreamParams* GetStreamByIds(const StreamParamsVec& streams, |
293 const std::string& groupid, | 290 const std::string& groupid, |
294 const std::string& id) { | 291 const std::string& id) { |
295 return GetStream(streams, | 292 return GetStream(streams, |
296 [&groupid, &id](const StreamParams& sp) { | 293 [&groupid, &id](const StreamParams& sp) { |
297 return sp.groupid == groupid && sp.id == id; | 294 return sp.groupid == groupid && sp.id == id; |
(...skipping 15 matching lines...) Expand all Loading... |
313 return true; | 310 return true; |
314 } | 311 } |
315 | 312 |
316 // Removes the stream from streams. Returns true if a stream is | 313 // Removes the stream from streams. Returns true if a stream is |
317 // found and removed. | 314 // found and removed. |
318 inline bool RemoveStream(StreamParamsVec* streams, | 315 inline bool RemoveStream(StreamParamsVec* streams, |
319 const StreamSelector& selector) { | 316 const StreamSelector& selector) { |
320 return RemoveStream(streams, | 317 return RemoveStream(streams, |
321 [&selector](const StreamParams& sp) { return selector.Matches(sp); }); | 318 [&selector](const StreamParams& sp) { return selector.Matches(sp); }); |
322 } | 319 } |
323 inline bool RemoveStreamBySsrc(StreamParamsVec* streams, uint32 ssrc) { | 320 inline bool RemoveStreamBySsrc(StreamParamsVec* streams, uint32_t ssrc) { |
324 return RemoveStream(streams, | 321 return RemoveStream(streams, |
325 [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); | 322 [&ssrc](const StreamParams& sp) { return sp.has_ssrc(ssrc); }); |
326 } | 323 } |
327 inline bool RemoveStreamByIds(StreamParamsVec* streams, | 324 inline bool RemoveStreamByIds(StreamParamsVec* streams, |
328 const std::string& groupid, | 325 const std::string& groupid, |
329 const std::string& id) { | 326 const std::string& id) { |
330 return RemoveStream(streams, | 327 return RemoveStream(streams, |
331 [&groupid, &id](const StreamParams& sp) { | 328 [&groupid, &id](const StreamParams& sp) { |
332 return sp.groupid == groupid && sp.id == id; | 329 return sp.groupid == groupid && sp.id == id; |
333 }); | 330 }); |
334 } | 331 } |
335 | 332 |
336 // Checks if |sp| defines parameters for a single primary stream. There may | 333 // Checks if |sp| defines parameters for a single primary stream. There may |
337 // be an RTX stream associated with the primary stream. Leaving as non-static so | 334 // be an RTX stream associated with the primary stream. Leaving as non-static so |
338 // we can test this function. | 335 // we can test this function. |
339 bool IsOneSsrcStream(const StreamParams& sp); | 336 bool IsOneSsrcStream(const StreamParams& sp); |
340 | 337 |
341 // Checks if |sp| defines parameters for one Simulcast stream. There may be RTX | 338 // Checks if |sp| defines parameters for one Simulcast stream. There may be RTX |
342 // streams associated with the simulcast streams. Leaving as non-static so we | 339 // streams associated with the simulcast streams. Leaving as non-static so we |
343 // can test this function. | 340 // can test this function. |
344 bool IsSimulcastStream(const StreamParams& sp); | 341 bool IsSimulcastStream(const StreamParams& sp); |
345 | 342 |
346 } // namespace cricket | 343 } // namespace cricket |
347 | 344 |
348 #endif // TALK_MEDIA_BASE_STREAMPARAMS_H_ | 345 #endif // TALK_MEDIA_BASE_STREAMPARAMS_H_ |
OLD | NEW |