Remove more codec-related templating
BUG=webrtc:15214 Change-Id: Ia597f674e5650dad31796c9a13769fbe873554fe Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/322122 Reviewed-by: Florent Castelli <orphis@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Philipp Hancke <phancke@microsoft.com> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/main@{#40920}
This commit is contained in:
parent
61a442809c
commit
19fe2437b7
@ -362,6 +362,14 @@ Codec CreateVideoRtxCodec(int rtx_payload_type, int associated_payload_type) {
|
||||
return rtx_codec;
|
||||
}
|
||||
|
||||
const Codec* FindCodecById(const std::vector<Codec>& codecs, int payload_type) {
|
||||
for (const auto& codec : codecs) {
|
||||
if (codec.id == payload_type)
|
||||
return &codec;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool HasLntf(const Codec& codec) {
|
||||
return codec.HasFeedbackParam(
|
||||
FeedbackParam(kRtcpFbParamLntf, kParamValueEmpty));
|
||||
|
||||
@ -200,14 +200,7 @@ Codec CreateVideoRtxCodec(int rtx_payload_type, int associated_payload_type);
|
||||
|
||||
// Get the codec setting associated with `payload_type`. If there
|
||||
// is no codec associated with that payload type it returns nullptr.
|
||||
template <class Codec>
|
||||
const Codec* FindCodecById(const std::vector<Codec>& codecs, int payload_type) {
|
||||
for (const auto& codec : codecs) {
|
||||
if (codec.id == payload_type)
|
||||
return &codec;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
const Codec* FindCodecById(const std::vector<Codec>& codecs, int payload_type);
|
||||
|
||||
bool HasLntf(const Codec& codec);
|
||||
bool HasNack(const Codec& codec);
|
||||
|
||||
@ -35,20 +35,6 @@ inline std::vector<T> MakeVector(const T a[], size_t s) {
|
||||
}
|
||||
#define MAKE_VECTOR(a) cricket::MakeVector(a, arraysize(a))
|
||||
|
||||
// Checks whether `codecs` contains `codec`; checks using Codec::Matches().
|
||||
template <class C>
|
||||
bool ContainsMatchingCodec(const std::vector<C>& codecs,
|
||||
const C& codec,
|
||||
const webrtc::FieldTrialsView* field_trials) {
|
||||
typename std::vector<C>::const_iterator it;
|
||||
for (it = codecs.begin(); it != codecs.end(); ++it) {
|
||||
if (it->Matches(codec, field_trials)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create Simulcast StreamParams with given `ssrcs` and `cname`.
|
||||
cricket::StreamParams CreateSimStreamParams(const std::string& cname,
|
||||
const std::vector<uint32_t>& ssrcs);
|
||||
|
||||
@ -78,12 +78,13 @@ struct StreamFinder {
|
||||
|
||||
} // namespace
|
||||
|
||||
template <class Codec>
|
||||
void MediaChannelParametersFromMediaDescription(
|
||||
const MediaContentDescriptionImpl<Codec>* desc,
|
||||
const RtpMediaContentDescription* desc,
|
||||
const RtpHeaderExtensions& extensions,
|
||||
bool is_stream_active,
|
||||
MediaChannelParameters* params) {
|
||||
RTC_DCHECK(desc->type() == MEDIA_TYPE_AUDIO ||
|
||||
desc->type() == MEDIA_TYPE_VIDEO);
|
||||
params->is_stream_active = is_stream_active;
|
||||
params->codecs = desc->codecs();
|
||||
// TODO(bugs.webrtc.org/11513): See if we really need
|
||||
@ -95,9 +96,8 @@ void MediaChannelParametersFromMediaDescription(
|
||||
params->rtcp.remote_estimate = desc->remote_estimate();
|
||||
}
|
||||
|
||||
template <class Codec>
|
||||
void RtpSendParametersFromMediaDescription(
|
||||
const MediaContentDescriptionImpl<Codec>* desc,
|
||||
const RtpMediaContentDescription* desc,
|
||||
webrtc::RtpExtension::Filter extensions_filter,
|
||||
SenderParameters* send_params) {
|
||||
RtpHeaderExtensions extensions =
|
||||
|
||||
@ -1029,13 +1029,12 @@ void MergeCodecs(const std::vector<Codec>& reference_codecs,
|
||||
// don't conflict with mappings of the other media type; `supported_codecs` is
|
||||
// a list filtered for the media section`s direction but with default payload
|
||||
// types.
|
||||
template <typename Codecs>
|
||||
Codecs MatchCodecPreference(
|
||||
std::vector<Codec> MatchCodecPreference(
|
||||
const std::vector<webrtc::RtpCodecCapability>& codec_preferences,
|
||||
const Codecs& codecs,
|
||||
const Codecs& supported_codecs,
|
||||
const std::vector<Codec>& codecs,
|
||||
const std::vector<Codec>& supported_codecs,
|
||||
const webrtc::FieldTrialsView* field_trials) {
|
||||
Codecs filtered_codecs;
|
||||
std::vector<Codec> filtered_codecs;
|
||||
bool want_rtx = false;
|
||||
bool want_red = false;
|
||||
|
||||
@ -1048,8 +1047,7 @@ Codecs MatchCodecPreference(
|
||||
}
|
||||
for (const auto& codec_preference : codec_preferences) {
|
||||
auto found_codec = absl::c_find_if(
|
||||
supported_codecs,
|
||||
[&codec_preference](const typename Codecs::value_type& codec) {
|
||||
supported_codecs, [&codec_preference](const Codec& codec) {
|
||||
webrtc::RtpCodecParameters codec_parameters =
|
||||
codec.ToCodecParameters();
|
||||
return codec_parameters.name == codec_preference.name &&
|
||||
@ -1061,9 +1059,8 @@ Codecs MatchCodecPreference(
|
||||
});
|
||||
|
||||
if (found_codec != supported_codecs.end()) {
|
||||
absl::optional<typename Codecs::value_type> found_codec_with_correct_pt =
|
||||
FindMatchingCodec(supported_codecs, codecs, *found_codec,
|
||||
field_trials);
|
||||
absl::optional<Codec> found_codec_with_correct_pt = FindMatchingCodec(
|
||||
supported_codecs, codecs, *found_codec, field_trials);
|
||||
if (found_codec_with_correct_pt) {
|
||||
filtered_codecs.push_back(*found_codec_with_correct_pt);
|
||||
std::string id = rtc::ToString(found_codec_with_correct_pt->id);
|
||||
@ -1337,15 +1334,16 @@ void StripCNCodecs(AudioCodecs* audio_codecs) {
|
||||
audio_codecs->end());
|
||||
}
|
||||
|
||||
template <class C>
|
||||
bool SetCodecsInAnswer(const MediaContentDescriptionImpl<C>* offer,
|
||||
const std::vector<C>& local_codecs,
|
||||
bool SetCodecsInAnswer(const MediaContentDescription* offer,
|
||||
const std::vector<Codec>& local_codecs,
|
||||
const MediaDescriptionOptions& media_description_options,
|
||||
const MediaSessionOptions& session_options,
|
||||
UniqueRandomIdGenerator* ssrc_generator,
|
||||
StreamParamsVec* current_streams,
|
||||
MediaContentDescription* answer,
|
||||
const webrtc::FieldTrialsView& field_trials) {
|
||||
RTC_DCHECK(offer->type() == MEDIA_TYPE_AUDIO ||
|
||||
offer->type() == MEDIA_TYPE_VIDEO);
|
||||
std::vector<Codec> negotiated_codecs;
|
||||
NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs,
|
||||
media_description_options.codec_preferences.empty(),
|
||||
|
||||
@ -291,36 +291,37 @@ class MediaContentDescription {
|
||||
};
|
||||
|
||||
template <class C>
|
||||
class MediaContentDescriptionImpl : public MediaContentDescription {
|
||||
class MediaContentDescriptionImpl : public MediaContentDescription {};
|
||||
using RtpMediaContentDescription = MediaContentDescriptionImpl<Codec>;
|
||||
|
||||
class AudioContentDescription : public RtpMediaContentDescription {
|
||||
public:
|
||||
void set_protocol(absl::string_view protocol) override {
|
||||
RTC_DCHECK(IsRtpProtocol(protocol));
|
||||
protocol_ = std::string(protocol);
|
||||
}
|
||||
};
|
||||
|
||||
class AudioContentDescription : public MediaContentDescriptionImpl<Codec> {
|
||||
public:
|
||||
AudioContentDescription() {}
|
||||
|
||||
virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
|
||||
virtual AudioContentDescription* as_audio() { return this; }
|
||||
virtual const AudioContentDescription* as_audio() const { return this; }
|
||||
MediaType type() const override { return MEDIA_TYPE_AUDIO; }
|
||||
AudioContentDescription* as_audio() override { return this; }
|
||||
const AudioContentDescription* as_audio() const override { return this; }
|
||||
|
||||
private:
|
||||
virtual AudioContentDescription* CloneInternal() const {
|
||||
AudioContentDescription* CloneInternal() const override {
|
||||
return new AudioContentDescription(*this);
|
||||
}
|
||||
};
|
||||
|
||||
class VideoContentDescription : public MediaContentDescriptionImpl<Codec> {
|
||||
class VideoContentDescription : public RtpMediaContentDescription {
|
||||
public:
|
||||
virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
|
||||
virtual VideoContentDescription* as_video() { return this; }
|
||||
virtual const VideoContentDescription* as_video() const { return this; }
|
||||
void set_protocol(absl::string_view protocol) override {
|
||||
RTC_DCHECK(IsRtpProtocol(protocol));
|
||||
protocol_ = std::string(protocol);
|
||||
}
|
||||
MediaType type() const override { return MEDIA_TYPE_VIDEO; }
|
||||
VideoContentDescription* as_video() override { return this; }
|
||||
const VideoContentDescription* as_video() const override { return this; }
|
||||
|
||||
private:
|
||||
virtual VideoContentDescription* CloneInternal() const {
|
||||
VideoContentDescription* CloneInternal() const override {
|
||||
return new VideoContentDescription(*this);
|
||||
}
|
||||
};
|
||||
|
||||
@ -2616,8 +2616,7 @@ void MaybeCreateStaticPayloadAudioCodecs(const std::vector<int>& fmts,
|
||||
}
|
||||
}
|
||||
|
||||
template <class C>
|
||||
static std::unique_ptr<C> ParseContentDescription(
|
||||
static std::unique_ptr<MediaContentDescription> ParseContentDescription(
|
||||
absl::string_view message,
|
||||
const cricket::MediaType media_type,
|
||||
int mline_index,
|
||||
@ -2630,7 +2629,16 @@ static std::unique_ptr<C> ParseContentDescription(
|
||||
TransportDescription* transport,
|
||||
std::vector<std::unique_ptr<JsepIceCandidate>>* candidates,
|
||||
webrtc::SdpParseError* error) {
|
||||
auto media_desc = std::make_unique<C>();
|
||||
std::unique_ptr<MediaContentDescription> media_desc;
|
||||
if (media_type == cricket::MediaType::MEDIA_TYPE_AUDIO) {
|
||||
media_desc = std::make_unique<AudioContentDescription>();
|
||||
} else if (media_type == cricket::MediaType::MEDIA_TYPE_VIDEO) {
|
||||
media_desc = std::make_unique<VideoContentDescription>();
|
||||
} else {
|
||||
RTC_DCHECK_NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
media_desc->set_extmap_allow_mixed_enum(MediaContentDescription::kNo);
|
||||
if (!ParseContent(message, media_type, mline_index, protocol, payload_types,
|
||||
pos, content_name, bundle_only, msid_signaling,
|
||||
@ -2725,12 +2733,12 @@ bool ParseMediaDescription(
|
||||
return ParseFailed(*mline, "Unsupported protocol for media type", error);
|
||||
}
|
||||
if (media_type == kMediaTypeVideo) {
|
||||
content = ParseContentDescription<VideoContentDescription>(
|
||||
content = ParseContentDescription(
|
||||
message, cricket::MEDIA_TYPE_VIDEO, mline_index, protocol,
|
||||
payload_types, pos, &content_name, &bundle_only,
|
||||
§ion_msid_signaling, &transport, candidates, error);
|
||||
} else if (media_type == kMediaTypeAudio) {
|
||||
content = ParseContentDescription<AudioContentDescription>(
|
||||
content = ParseContentDescription(
|
||||
message, cricket::MEDIA_TYPE_AUDIO, mline_index, protocol,
|
||||
payload_types, pos, &content_name, &bundle_only,
|
||||
§ion_msid_signaling, &transport, candidates, error);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user