Skip to content

Commit

Permalink
Wire up MID send value to the PeerConnection API
Browse files Browse the repository at this point in the history
Bug: webrtc:4050
Change-Id: I522cf8621e2cb639f54be2402174befd23e4af59
Reviewed-on: https://webrtc-review.googlesource.com/60962
Commit-Queue: Steve Anton <[email protected]>
Reviewed-by: Fredrik Solenberg <[email protected]>
Reviewed-by: Stefan Holmer <[email protected]>
Reviewed-by: Taylor Brandstetter <[email protected]>
Cr-Commit-Position: refs/heads/master@{#22610}
  • Loading branch information
steveanton authored and Commit Bot committed Mar 26, 2018
1 parent 1707168 commit bb50ce5
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 8 deletions.
12 changes: 9 additions & 3 deletions api/rtpparameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ const char RtpExtension::kVideoTimingUri[] =
"http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
const int RtpExtension::kVideoTimingDefaultId = 8;

const char RtpExtension::kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
const int RtpExtension::kMidDefaultId = 9;

const char RtpExtension::kEncryptHeaderExtensionsUri[] =
"urn:ietf:params:rtp-hdrext:encrypt";

Expand All @@ -122,7 +125,8 @@ const int RtpExtension::kMaxId = 14;

bool RtpExtension::IsSupportedForAudio(const std::string& uri) {
return uri == webrtc::RtpExtension::kAudioLevelUri ||
uri == webrtc::RtpExtension::kTransportSequenceNumberUri;
uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
uri == webrtc::RtpExtension::kMidUri;
}

bool RtpExtension::IsSupportedForVideo(const std::string& uri) {
Expand All @@ -132,7 +136,8 @@ bool RtpExtension::IsSupportedForVideo(const std::string& uri) {
uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
uri == webrtc::RtpExtension::kPlayoutDelayUri ||
uri == webrtc::RtpExtension::kVideoContentTypeUri ||
uri == webrtc::RtpExtension::kVideoTimingUri;
uri == webrtc::RtpExtension::kVideoTimingUri ||
uri == webrtc::RtpExtension::kMidUri;
}

bool RtpExtension::IsEncryptionSupported(const std::string& uri) {
Expand All @@ -149,7 +154,8 @@ bool RtpExtension::IsEncryptionSupported(const std::string& uri) {
uri == webrtc::RtpExtension::kVideoRotationUri ||
uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
uri == webrtc::RtpExtension::kPlayoutDelayUri ||
uri == webrtc::RtpExtension::kVideoContentTypeUri;
uri == webrtc::RtpExtension::kVideoContentTypeUri ||
uri == webrtc::RtpExtension::kMidUri;
}

const RtpExtension* RtpExtension::FindHeaderExtensionByUri(
Expand Down
5 changes: 5 additions & 0 deletions api/rtpparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ struct RtpExtension {
static const char kPlayoutDelayUri[];
static const int kPlayoutDelayDefaultId;

// Header extension for identifying media section within a transport.
// https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
static const char kMidUri[];
static const int kMidDefaultId;

// Encryption of Header Extensions, see RFC 6904 for details:
// https://tools.ietf.org/html/rfc6904
static const char kEncryptHeaderExtensionsUri[];
Expand Down
8 changes: 8 additions & 0 deletions audio/audio_send_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ AudioSendStream::ExtensionIds AudioSendStream::FindExtensionIds(
ids.audio_level = extension.id;
} else if (extension.uri == RtpExtension::kTransportSequenceNumberUri) {
ids.transport_sequence_number = extension.id;
} else if (extension.uri == RtpExtension::kMidUri) {
ids.mid = extension.id;
}
}
return ids;
Expand Down Expand Up @@ -260,6 +262,12 @@ void AudioSendStream::ConfigureStream(
bandwidth_observer);
}

// MID RTP header extension.
if ((first_time || new_ids.mid != old_ids.mid) && new_ids.mid != 0 &&
!new_config.rtp.mid.empty()) {
channel_proxy->SetMid(new_config.rtp.mid, new_ids.mid);
}

if (!ReconfigureSendCodec(stream, new_config)) {
RTC_LOG(LS_ERROR) << "Failed to set up send codec state.";
}
Expand Down
1 change: 1 addition & 0 deletions audio/audio_send_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
struct ExtensionIds {
int audio_level = 0;
int transport_sequence_number = 0;
int mid = 0;
};
static ExtensionIds FindExtensionIds(
const std::vector<RtpExtension>& extensions);
Expand Down
6 changes: 6 additions & 0 deletions audio/channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,12 @@ int Channel::SetLocalSSRC(unsigned int ssrc) {
return 0;
}

void Channel::SetMid(const std::string& mid, int extension_id) {
int ret = SetSendRtpHeaderExtension(true, kRtpExtensionMid, extension_id);
RTC_DCHECK_EQ(0, ret);
_rtpRtcpModule->SetMid(mid);
}

int Channel::GetRemoteSSRC(unsigned int& ssrc) {
ssrc = rtp_receiver_->SSRC();
return 0;
Expand Down
1 change: 1 addition & 0 deletions audio/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class Channel

// RTP+RTCP
int SetLocalSSRC(unsigned int ssrc);
void SetMid(const std::string& mid, int extension_id);
int SetSendAudioLevelIndicationStatus(bool enable, unsigned char id);
void EnableSendTransportSequenceNumber(int id);

Expand Down
5 changes: 5 additions & 0 deletions audio/channel_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ void ChannelProxy::SetLocalSSRC(uint32_t ssrc) {
RTC_DCHECK_EQ(0, error);
}

void ChannelProxy::SetMid(const std::string& mid, int extension_id) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel_->SetMid(mid, extension_id);
}

void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
// Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array.
Expand Down
1 change: 1 addition & 0 deletions audio/channel_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ChannelProxy : public RtpPacketSinkInterface {

virtual void SetRTCPStatus(bool enable);
virtual void SetLocalSSRC(uint32_t ssrc);
virtual void SetMid(const std::string& mid, int extension_id);
virtual void SetRTCP_CNAME(const std::string& c_name);
virtual void SetNACKStatus(bool enable, int max_packets);
virtual void SetSendAudioLevelIndicationStatus(bool enable, int id);
Expand Down
4 changes: 4 additions & 0 deletions call/audio_send_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class AudioSendStream {
// Sender SSRC.
uint32_t ssrc = 0;

// The value to send in the MID RTP header extension if the extension is
// included in the list of extensions.
std::string mid;

// RTP header extensions used for the sent stream.
std::vector<RtpExtension> extensions;

Expand Down
4 changes: 4 additions & 0 deletions call/video_send_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class VideoSendStream {

std::vector<uint32_t> ssrcs;

// The value to send in the MID RTP header extension if the extension is
// included in the list of extensions.
std::string mid;

// See RtcpMode for description.
RtcpMode rtcp_mode = RtcpMode::kCompound;

Expand Down
4 changes: 4 additions & 0 deletions media/base/mediachannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,15 @@ struct RtpSendParameters : RtpParameters<Codec> {
ost << "codecs: " << VectorToString(this->codecs) << ", ";
ost << "extensions: " << VectorToString(this->extensions) << ", ";
ost << "max_bandwidth_bps: " << max_bandwidth_bps << ", ";
ost << "mid: " << (mid.empty() ? "<not set>" : mid) << ", ";
ost << "}";
return ost.str();
}

int max_bandwidth_bps = -1;
// This is the value to be sent in the MID RTP header extension (if the header
// extension in included in the list of extensions).
std::string mid;
};

struct AudioSendParameters : RtpSendParameters<AudioCodec> {
Expand Down
14 changes: 14 additions & 0 deletions media/engine/webrtcvideoengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ RtpCapabilities WebRtcVideoEngine::GetCapabilities() const {
capabilities.header_extensions.push_back(
webrtc::RtpExtension(webrtc::RtpExtension::kVideoTimingUri,
webrtc::RtpExtension::kVideoTimingDefaultId));
// TODO(bugs.webrtc.org/4050): Add MID header extension as capability once MID
// demuxing is completed.
// capabilities.header_extensions.push_back(webrtc::RtpExtension(
// webrtc::RtpExtension::kMidUri, webrtc::RtpExtension::kMidDefaultId));
return capabilities;
}

Expand Down Expand Up @@ -715,6 +719,10 @@ bool WebRtcVideoChannel::GetChangedSendParameters(
rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions);
}

if (params.mid != send_params_.mid) {
changed_params->mid = params.mid;
}

// Handle max bitrate.
if (params.max_bandwidth_bps != send_params_.max_bandwidth_bps &&
params.max_bandwidth_bps >= -1) {
Expand Down Expand Up @@ -1632,6 +1640,8 @@ WebRtcVideoChannel::WebRtcVideoSendStream::WebRtcVideoSendStream(
parameters_.config.rtp.rtcp_mode = send_params.rtcp.reduced_size
? webrtc::RtcpMode::kReducedSize
: webrtc::RtcpMode::kCompound;
parameters_.config.rtp.mid = send_params.mid;

if (codec_settings) {
SetCodec(*codec_settings);
}
Expand Down Expand Up @@ -1776,6 +1786,10 @@ void WebRtcVideoChannel::WebRtcVideoSendStream::SetSendParameters(
parameters_.config.rtp.extensions = *params.rtp_header_extensions;
recreate_stream = true;
}
if (params.mid) {
parameters_.config.rtp.mid = *params.mid;
recreate_stream = true;
}
if (params.max_bandwidth_bps) {
parameters_.max_bitrate_bps = *params.max_bandwidth_bps;
ReconfigureEncoder();
Expand Down
1 change: 1 addition & 0 deletions media/engine/webrtcvideoengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
// These optionals are unset if not changed.
rtc::Optional<VideoCodecSettings> codec;
rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
rtc::Optional<std::string> mid;
rtc::Optional<int> max_bandwidth_bps;
rtc::Optional<bool> conference_mode;
rtc::Optional<webrtc::RtcpMode> rtcp_mode;
Expand Down
23 changes: 22 additions & 1 deletion media/engine/webrtcvoiceengine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ RtpCapabilities WebRtcVoiceEngine::GetCapabilities() const {
webrtc::RtpExtension::kTransportSequenceNumberUri,
webrtc::RtpExtension::kTransportSequenceNumberDefaultId));
}
// TODO(bugs.webrtc.org/4050): Add MID header extension as capability once MID
// demuxing is completed.
// capabilities.header_extensions.push_back(webrtc::RtpExtension(
// webrtc::RtpExtension::kMidUri, webrtc::RtpExtension::kMidDefaultId));
return capabilities;
}

Expand Down Expand Up @@ -742,6 +746,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
public:
WebRtcAudioSendStream(
uint32_t ssrc,
const std::string& mid,
const std::string& c_name,
const std::string track_id,
const rtc::Optional<webrtc::AudioSendStream::Config::SendCodecSpec>&
Expand All @@ -762,6 +767,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
RTC_DCHECK(call);
RTC_DCHECK(encoder_factory);
config_.rtp.ssrc = ssrc;
config_.rtp.mid = mid;
config_.rtp.c_name = c_name;
config_.rtp.extensions = extensions;
config_.audio_network_adaptor_config = audio_network_adaptor_config;
Expand Down Expand Up @@ -795,6 +801,15 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
ReconfigureAudioSendStream();
}

void SetMid(const std::string& mid) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
if (config_.rtp.mid == mid) {
return;
}
config_.rtp.mid = mid;
ReconfigureAudioSendStream();
}

void SetAudioNetworkAdaptorConfig(
const rtc::Optional<std::string>& audio_network_adaptor_config) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
Expand Down Expand Up @@ -1302,6 +1317,12 @@ bool WebRtcVoiceMediaChannel::SetSendParameters(
it.second->SetRtpExtensions(send_rtp_extensions_);
}
}
if (!params.mid.empty()) {
mid_ = params.mid;
for (auto& it : send_streams_) {
it.second->SetMid(params.mid);
}
}

if (!SetMaxSendBitrate(params.max_bandwidth_bps)) {
return false;
Expand Down Expand Up @@ -1768,7 +1789,7 @@ bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) {
rtc::Optional<std::string> audio_network_adaptor_config =
GetAudioNetworkAdaptorConfig(options_);
WebRtcAudioSendStream* stream = new WebRtcAudioSendStream(
ssrc, sp.cname, sp.id, send_codec_spec_, send_rtp_extensions_,
ssrc, mid_, sp.cname, sp.id, send_codec_spec_, send_rtp_extensions_,
max_send_bitrate_bps_, audio_network_adaptor_config, call_, this,
engine()->encoder_factory_, codec_pair_id_);
send_streams_.insert(std::make_pair(ssrc, stream));
Expand Down
1 change: 1 addition & 0 deletions media/engine/webrtcvoiceengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class WebRtcVoiceMediaChannel final : public VoiceMediaChannel,
class WebRtcAudioSendStream;
std::map<uint32_t, WebRtcAudioSendStream*> send_streams_;
std::vector<webrtc::RtpExtension> send_rtp_extensions_;
std::string mid_;

class WebRtcAudioReceiveStream;
std::map<uint32_t, WebRtcAudioReceiveStream*> recv_streams_;
Expand Down
2 changes: 2 additions & 0 deletions modules/rtp_rtcp/source/rtp_rtcp_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ RTPExtensionType StringToRtpExtensionType(const std::string& extension) {
return kRtpExtensionVideoContentType;
if (extension == RtpExtension::kVideoTimingUri)
return kRtpExtensionVideoTiming;
if (extension == RtpExtension::kMidUri)
return kRtpExtensionMid;
RTC_NOTREACHED() << "Looking up unsupported RTP extension.";
return kRtpExtensionNone;
}
Expand Down
2 changes: 2 additions & 0 deletions pc/channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content,
AudioSendParameters send_params = last_send_params_;
RtpSendParametersFromMediaDescription(audio, rtp_header_extensions,
&send_params);
send_params.mid = content_name();

bool parameters_applied = media_channel()->SetSendParameters(send_params);
if (!parameters_applied) {
Expand Down Expand Up @@ -1410,6 +1411,7 @@ bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content,
if (video->conference_mode()) {
send_params.conference_mode = true;
}
send_params.mid = content_name();

bool parameters_applied = media_channel()->SetSendParameters(send_params);

Expand Down
12 changes: 8 additions & 4 deletions video/video_send_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ std::unique_ptr<FlexfecSender> MaybeCreateFlexfecSender(
}

RTC_DCHECK_EQ(1U, config.rtp.flexfec.protected_media_ssrcs.size());
// TODO(bugs.webrtc.org/4050): Pass down MID value once it is exposed in the
// API.
return std::unique_ptr<FlexfecSender>(new FlexfecSender(
return rtc::MakeUnique<FlexfecSender>(
config.rtp.flexfec.payload_type, config.rtp.flexfec.ssrc,
config.rtp.flexfec.protected_media_ssrcs[0], config.rtp.extensions,
RTPSender::FecExtensionSizes(), rtp_state, Clock::GetRealTimeClock()));
RTPSender::FecExtensionSizes(), rtp_state, Clock::GetRealTimeClock());
}

bool TransportSeqNumExtensionConfigured(const VideoSendStream::Config& config) {
Expand Down Expand Up @@ -822,6 +820,12 @@ VideoSendStreamImpl::VideoSendStreamImpl(
ConfigureProtection();
ConfigureSsrcs();

if (!config_->rtp.mid.empty()) {
for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
rtp_rtcp->SetMid(config_->rtp.mid);
}
}

// TODO(pbos): Should we set CNAME on all RTP modules?
rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str());

Expand Down

0 comments on commit bb50ce5

Please sign in to comment.