// Loops through all Id in `ids` and changes its id if it is // already in use by another IdStruct. Call this methods with all Id // in a session description to make sure no duplicate ids exists. // Note that typename Id must be a type of IdStruct. template <typename Id> void FindAndSetIdUsed(std::vector<Id>* ids) {
for (const Id& id : *ids) {
FindAndSetIdUsed(&id);
}
}
// Finds and sets an unused id if the `idstruct` id is already in use. void FindAndSetIdUsed(IdStruct* idstruct) { const int original_id = idstruct->id;
int new_id = idstruct->id;
if (original_id > max_allowed_id_ || original_id < min_allowed_id_) { // If the original id is not in range - this is an id that can't be // dynamically changed. return;
}
if (IsIdUsed(original_id)) {
new_id = FindUnusedId(); // Duplicate id found. Reassign from the original id to the new.
idstruct->id = new_id;
}
SetIdUsed(new_id);
}
protected: virtualbool IsIdUsed(int new_id) { return id_set_.find(new_id) != id_set_.end();
} const int min_allowed_id_; const int max_allowed_id_;
private: // Returns the first unused id in reverse order. // This hopefully reduces the risk of more collisions. We want to change the // default ids as little as possible. This function is virtual and can be // overriden if the search for unused IDs should follow a specific pattern. virtual int FindUnusedId() { while (IsIdUsed(next_id_) && next_id_ >= min_allowed_id_) {
--next_id_;
}
RTC_DCHECK(next_id_ >= min_allowed_id_); return next_id_;
}
// Helper class used for finding duplicate RTP payload types among audio, video // and data codecs. When bundle is used the payload types may not collide. class UsedPayloadTypes : public UsedIds<Codec> { public:
UsedPayloadTypes()
: UsedIds<Codec>(kFirstDynamicPayloadTypeLowerRange,
kLastDynamicPayloadTypeUpperRange) {}
// Check if a payload type is valid. The range [64-95] is forbidden // when rtcp-mux is used. staticbool IsIdValid(Codec codec, bool rtcp_mux) {
if (rtcp_mux && (codec.id > kLastDynamicPayloadTypeLowerRange &&
codec.id < kFirstDynamicPayloadTypeUpperRange)) { return false;
} return codec.id >= 0 && codec.id <= kLastDynamicPayloadTypeUpperRange;
}
protected: bool IsIdUsed(int new_id) override { // Range marked for RTCP avoidance is "used".
if (new_id > kLastDynamicPayloadTypeLowerRange &&
new_id < kFirstDynamicPayloadTypeUpperRange) returntrue; return UsedIds<Codec>::IsIdUsed(new_id);
}
private: staticconst int kFirstDynamicPayloadTypeLowerRange = 35; staticconst int kLastDynamicPayloadTypeLowerRange = 63;
staticconst int kFirstDynamicPayloadTypeUpperRange = 96; staticconst int kLastDynamicPayloadTypeUpperRange = 127;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.