Implement RTCRtpTransceiver.setCodecPreferences
SetCodecPreferences allows clients to filter and reorder codecs in their SDP offer and answer. Bug: webrtc:9777 Change-Id: I716bed9b06496629b45210883b286f599c875239 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129727 Reviewed-by: Steve Anton <steveanton@webrtc.org> Reviewed-by: Seth Hampson <shampson@webrtc.org> Commit-Queue: Florent Castelli <orphis@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27817}
This commit is contained in:
committed by
Commit Bot
parent
2ad2fabdcf
commit
2d9d82ecef
@ -13,7 +13,9 @@
|
||||
#include <string>
|
||||
|
||||
#include "absl/algorithm/container.h"
|
||||
#include "pc/channel_manager.h"
|
||||
#include "pc/rtp_media_utils.h"
|
||||
#include "pc/rtp_parameters_conversion.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
@ -28,8 +30,11 @@ RtpTransceiver::RtpTransceiver(cricket::MediaType media_type)
|
||||
RtpTransceiver::RtpTransceiver(
|
||||
rtc::scoped_refptr<RtpSenderProxyWithInternal<RtpSenderInternal>> sender,
|
||||
rtc::scoped_refptr<RtpReceiverProxyWithInternal<RtpReceiverInternal>>
|
||||
receiver)
|
||||
: unified_plan_(true), media_type_(sender->media_type()) {
|
||||
receiver,
|
||||
cricket::ChannelManager* channel_manager)
|
||||
: unified_plan_(true),
|
||||
media_type_(sender->media_type()),
|
||||
channel_manager_(channel_manager) {
|
||||
RTC_DCHECK(media_type_ == cricket::MEDIA_TYPE_AUDIO ||
|
||||
media_type_ == cricket::MEDIA_TYPE_VIDEO);
|
||||
RTC_DCHECK_EQ(sender->media_type(), receiver->media_type());
|
||||
@ -223,10 +228,129 @@ void RtpTransceiver::Stop() {
|
||||
current_direction_ = absl::nullopt;
|
||||
}
|
||||
|
||||
void RtpTransceiver::SetCodecPreferences(
|
||||
rtc::ArrayView<RtpCodecCapability> codecs) {
|
||||
// TODO(steveanton): Implement this.
|
||||
RTC_NOTREACHED() << "Not implemented";
|
||||
RTCError RtpTransceiver::SetCodecPreferences(
|
||||
rtc::ArrayView<RtpCodecCapability> codec_capabilities) {
|
||||
RTC_DCHECK(unified_plan_);
|
||||
|
||||
// 3. If codecs is an empty list, set transceiver's [[PreferredCodecs]] slot
|
||||
// to codecs and abort these steps.
|
||||
if (codec_capabilities.empty()) {
|
||||
codec_preferences_.clear();
|
||||
return RTCError::OK();
|
||||
}
|
||||
|
||||
// 4. Remove any duplicate values in codecs.
|
||||
std::vector<RtpCodecCapability> codecs;
|
||||
absl::c_remove_copy_if(codec_capabilities, std::back_inserter(codecs),
|
||||
[&codecs](const RtpCodecCapability& codec) {
|
||||
return absl::c_linear_search(codecs, codec);
|
||||
});
|
||||
|
||||
if (media_type_ == cricket::MEDIA_TYPE_AUDIO) {
|
||||
std::vector<cricket::AudioCodec> audio_codecs;
|
||||
|
||||
std::vector<cricket::AudioCodec> recv_codecs, send_codecs;
|
||||
channel_manager_->GetSupportedAudioReceiveCodecs(&recv_codecs);
|
||||
channel_manager_->GetSupportedAudioSendCodecs(&send_codecs);
|
||||
|
||||
// 6. If the intersection between codecs and
|
||||
// RTCRtpSender.getCapabilities(kind).codecs or the intersection between
|
||||
// codecs and RTCRtpReceiver.getCapabilities(kind).codecs only contains RTX,
|
||||
// RED or FEC codecs or is an empty set, throw InvalidModificationError.
|
||||
// This ensures that we always have something to offer, regardless of
|
||||
// transceiver.direction.
|
||||
|
||||
if (!absl::c_any_of(
|
||||
codecs, [&recv_codecs](const RtpCodecCapability& codec) {
|
||||
return codec.name != cricket::kRtxCodecName &&
|
||||
codec.name != cricket::kRedCodecName &&
|
||||
codec.name != cricket::kFlexfecCodecName &&
|
||||
absl::c_any_of(
|
||||
recv_codecs,
|
||||
[&codec](const cricket::AudioCodec& recv_codec) {
|
||||
return recv_codec.MatchesCapability(codec);
|
||||
});
|
||||
})) {
|
||||
return RTCError(RTCErrorType::INVALID_MODIFICATION,
|
||||
"Invalid codec preferences: Missing codec from recv "
|
||||
"codec capabilities.");
|
||||
}
|
||||
|
||||
if (!absl::c_any_of(
|
||||
codecs, [&send_codecs](const RtpCodecCapability& codec) {
|
||||
return codec.name != cricket::kRtxCodecName &&
|
||||
codec.name != cricket::kRedCodecName &&
|
||||
codec.name != cricket::kFlexfecCodecName &&
|
||||
absl::c_any_of(
|
||||
send_codecs,
|
||||
[&codec](const cricket::AudioCodec& send_codec) {
|
||||
return send_codec.MatchesCapability(codec);
|
||||
});
|
||||
})) {
|
||||
return RTCError(RTCErrorType::INVALID_MODIFICATION,
|
||||
"Invalid codec preferences: Missing codec from send "
|
||||
"codec capabilities.");
|
||||
}
|
||||
|
||||
// 7. Let codecCapabilities be the union of
|
||||
// RTCRtpSender.getCapabilities(kind).codecs and
|
||||
// RTCRtpReceiver.getCapabilities(kind).codecs. 8.1 For each codec in
|
||||
// codecs, If codec is not in codecCapabilities, throw
|
||||
// InvalidModificationError.
|
||||
for (const auto& codec_preference : codecs) {
|
||||
bool is_recv_codec = absl::c_any_of(
|
||||
recv_codecs, [&codec_preference](const cricket::AudioCodec& codec) {
|
||||
return codec.MatchesCapability(codec_preference);
|
||||
});
|
||||
|
||||
bool is_send_codec = absl::c_any_of(
|
||||
send_codecs, [&codec_preference](const cricket::AudioCodec& codec) {
|
||||
return codec.MatchesCapability(codec_preference);
|
||||
});
|
||||
|
||||
if (!is_recv_codec && !is_send_codec) {
|
||||
return RTCError(
|
||||
RTCErrorType::INVALID_MODIFICATION,
|
||||
std::string(
|
||||
"Invalid codec preferences: invalid codec with name \"") +
|
||||
codec_preference.name + "\".");
|
||||
}
|
||||
}
|
||||
} else if (media_type_ == cricket::MEDIA_TYPE_VIDEO) {
|
||||
std::vector<cricket::VideoCodec> video_codecs;
|
||||
// Video codecs are both for the receive and send side, so the checks are
|
||||
// simpler than the audio ones.
|
||||
channel_manager_->GetSupportedVideoCodecs(&video_codecs);
|
||||
|
||||
// Validate codecs
|
||||
for (const auto& codec_preference : codecs) {
|
||||
if (!absl::c_any_of(video_codecs, [&codec_preference](
|
||||
const cricket::VideoCodec& codec) {
|
||||
return codec.MatchesCapability(codec_preference);
|
||||
})) {
|
||||
return RTCError(
|
||||
RTCErrorType::INVALID_MODIFICATION,
|
||||
std::string(
|
||||
"Invalid codec preferences: invalid codec with name \"") +
|
||||
codec_preference.name + "\".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check we have a real codec (not just rtx, red or fec)
|
||||
if (absl::c_all_of(codecs, [](const RtpCodecCapability& codec) {
|
||||
return codec.name == cricket::kRtxCodecName ||
|
||||
codec.name == cricket::kRedCodecName ||
|
||||
codec.name == cricket::kUlpfecCodecName;
|
||||
})) {
|
||||
return RTCError(RTCErrorType::INVALID_MODIFICATION,
|
||||
"Invalid codec preferences: codec list must have a non "
|
||||
"RTX, RED or FEC entry.");
|
||||
}
|
||||
|
||||
codec_preferences_ = codecs;
|
||||
|
||||
return RTCError::OK();
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user