Move codecs() to base MediaDescription

remove some of the templating around the Codec-derived types and
use more modern C++ loops.

BUG=webrtc:15214

Change-Id: I2710628741deca647e7ae88f5966ec7c7f12669a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/311260
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40475}
This commit is contained in:
Philipp Hancke 2023-07-03 13:57:03 +02:00 committed by WebRTC LUCI CQ
parent 87e22fe0ab
commit 8c9e035edb
2 changed files with 20 additions and 26 deletions

View File

@ -269,46 +269,41 @@ class MediaContentDescriptionImpl : public MediaContentDescription {
protocol_ = std::string(protocol);
}
typedef C CodecType;
// Codecs should be in preference order (most preferred codec first).
const std::vector<C>& codecs() const { return codecs_; }
void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
const std::vector<Codec>& codecs() const { return codecs_; }
void set_codecs(const std::vector<Codec>& codecs) { codecs_ = codecs; }
bool has_codecs() const override { return !codecs_.empty(); }
bool HasCodec(int id) {
bool found = false;
for (typename std::vector<C>::iterator iter = codecs_.begin();
iter != codecs_.end(); ++iter) {
if (iter->id == id) {
for (auto it = codecs_.begin(); it != codecs_.end(); ++it) {
if (it->id == id) {
found = true;
break;
}
}
return found;
}
void AddCodec(const C& codec) { codecs_.push_back(codec); }
void AddOrReplaceCodec(const C& codec) {
for (typename std::vector<C>::iterator iter = codecs_.begin();
iter != codecs_.end(); ++iter) {
if (iter->id == codec.id) {
*iter = codec;
void AddCodec(const Codec& codec) { codecs_.push_back(codec); }
void AddOrReplaceCodec(const Codec& codec) {
for (auto it = codecs_.begin(); it != codecs_.end(); ++it) {
if (it->id == codec.id) {
*it = codec;
return;
}
}
AddCodec(codec);
}
void AddCodecs(const std::vector<C>& codecs) {
typename std::vector<C>::const_iterator codec;
for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
AddCodec(*codec);
void AddCodecs(const std::vector<Codec>& codecs) {
for (const auto& codec : codecs) {
AddCodec(codec);
}
}
private:
std::vector<C> codecs_;
std::vector<Codec> codecs_;
};
class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
class AudioContentDescription : public MediaContentDescriptionImpl<Codec> {
public:
AudioContentDescription() {}
@ -322,7 +317,7 @@ class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
}
};
class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
class VideoContentDescription : public MediaContentDescriptionImpl<Codec> {
public:
virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
virtual VideoContentDescription* as_video() { return this; }

View File

@ -2654,12 +2654,11 @@ static std::unique_ptr<C> ParseContentDescription(
for (int pt : payload_types) {
payload_type_preferences[pt] = preference--;
}
std::vector<typename C::CodecType> codecs = media_desc->codecs();
absl::c_sort(
codecs, [&payload_type_preferences](const typename C::CodecType& a,
const typename C::CodecType& b) {
return payload_type_preferences[a.id] > payload_type_preferences[b.id];
});
std::vector<cricket::Codec> codecs = media_desc->codecs();
absl::c_sort(codecs, [&payload_type_preferences](const cricket::Codec& a,
const cricket::Codec& b) {
return payload_type_preferences[a.id] > payload_type_preferences[b.id];
});
media_desc->set_codecs(codecs);
return media_desc;
}