Index: webrtc/pc/mediasession.cc |
diff --git a/webrtc/pc/mediasession.cc b/webrtc/pc/mediasession.cc |
index dbd32566d523d3d67d8ca3be8fee17e7190fcf9f..ac438ba1f85abc2054d84dcf07d218c1beb92b9e 100644 |
--- a/webrtc/pc/mediasession.cc |
+++ b/webrtc/pc/mediasession.cc |
@@ -932,16 +932,42 @@ static void FindCodecsToOffer( |
static bool FindByUri(const RtpHeaderExtensions& extensions, |
const webrtc::RtpExtension& ext_to_match, |
webrtc::RtpExtension* found_extension) { |
+ // We assume that all URIs are given in a canonical format. |
+ const webrtc::RtpExtension* found = |
+ webrtc::RtpExtension::FindHeaderExtensionByUri(extensions, |
+ ext_to_match.uri); |
+ if (!found) { |
+ return false; |
+ } |
+ if (found_extension) { |
+ *found_extension = *found; |
+ } |
+ return true; |
+} |
+ |
+static bool FindByUriWithEncryptionPreference( |
+ const RtpHeaderExtensions& extensions, |
+ const webrtc::RtpExtension& ext_to_match, bool encryption_preference, |
+ webrtc::RtpExtension* found_extension) { |
+ const webrtc::RtpExtension* regular_extension = nullptr; |
for (RtpHeaderExtensions::const_iterator it = extensions.begin(); |
it != extensions.end(); ++it) { |
// We assume that all URIs are given in a canonical format. |
if (it->uri == ext_to_match.uri) { |
- if (found_extension != NULL) { |
+ if (!found_extension) { |
+ return true; |
+ } |
+ if (!encryption_preference || it->encrypt) { |
*found_extension = *it; |
+ return true; |
} |
- return true; |
+ regular_extension = &(*it); |
} |
} |
+ if (regular_extension) { |
+ *found_extension = *regular_extension; |
+ return true; |
+ } |
return false; |
} |
@@ -984,15 +1010,35 @@ static void FindRtpHdrExtsToOffer( |
} |
} |
+static void AddEncryptedVersionsOfHdrExts(RtpHeaderExtensions* extensions, |
+ UsedRtpHeaderExtensionIds* used_ids) { |
+ RtpHeaderExtensions encrypted_extensions; |
+ for (const webrtc::RtpExtension& extension : *extensions) { |
+ if (extension.encrypt || |
Taylor Brandstetter
2017/03/23 20:10:56
Could you leave a comment explaining why "extensio
joachim
2017/03/30 22:43:49
Done and also updated the condition.
|
+ !webrtc::RtpExtension::IsEncryptionSupported(extension.uri)) { |
+ continue; |
+ } |
+ |
+ webrtc::RtpExtension encrypted(extension); |
+ encrypted.encrypt = true; |
+ used_ids->FindAndSetIdUsed(&encrypted); |
Taylor Brandstetter
2017/03/23 20:10:56
If the same encrypted extension is used for audio
joachim
2017/03/30 22:43:49
Done. Also added a test for encrypted id reuse and
|
+ encrypted_extensions.push_back(encrypted); |
+ } |
+ extensions->insert(extensions->end(), encrypted_extensions.begin(), |
+ encrypted_extensions.end()); |
+} |
+ |
static void NegotiateRtpHeaderExtensions( |
const RtpHeaderExtensions& local_extensions, |
const RtpHeaderExtensions& offered_extensions, |
+ bool enable_encrypted_rtp_header_extensions, |
RtpHeaderExtensions* negotiated_extenstions) { |
RtpHeaderExtensions::const_iterator ours; |
for (ours = local_extensions.begin(); |
ours != local_extensions.end(); ++ours) { |
webrtc::RtpExtension theirs; |
- if (FindByUri(offered_extensions, *ours, &theirs)) { |
+ if (FindByUriWithEncryptionPreference(offered_extensions, *ours, |
+ enable_encrypted_rtp_header_extensions, &theirs)) { |
// We respond with their RTP header extension id. |
negotiated_extenstions->push_back(theirs); |
} |
@@ -1027,6 +1073,7 @@ static bool CreateMediaContentAnswer( |
const SecurePolicy& sdes_policy, |
const CryptoParamsVec* current_cryptos, |
const RtpHeaderExtensions& local_rtp_extenstions, |
+ bool enable_encrypted_rtp_header_extensions, |
StreamParamsVec* current_streams, |
bool add_legacy_stream, |
bool bundle_enabled, |
@@ -1038,6 +1085,7 @@ static bool CreateMediaContentAnswer( |
RtpHeaderExtensions negotiated_rtp_extensions; |
NegotiateRtpHeaderExtensions(local_rtp_extenstions, |
offer->rtp_header_extensions(), |
+ enable_encrypted_rtp_header_extensions, |
&negotiated_rtp_extensions); |
answer->set_rtp_header_extensions(negotiated_rtp_extensions); |
@@ -1605,6 +1653,10 @@ void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( |
&all_extensions, &used_ids); |
FindRtpHdrExtsToOffer(video_rtp_header_extensions(), video_extensions, |
&all_extensions, &used_ids); |
+ if (enable_encrypted_rtp_header_extensions_) { |
+ AddEncryptedVersionsOfHdrExts(audio_extensions, &used_ids); |
+ AddEncryptedVersionsOfHdrExts(video_extensions, &used_ids); |
+ } |
} |
bool MediaSessionDescriptionFactory::AddTransportOffer( |
@@ -1878,6 +1930,7 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( |
sdes_policy, |
GetCryptos(GetFirstAudioContentDescription(current_description)), |
audio_rtp_extensions_, |
+ enable_encrypted_rtp_header_extensions_, |
current_streams, |
add_legacy_, |
bundle_enabled, |
@@ -1934,6 +1987,7 @@ bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( |
sdes_policy, |
GetCryptos(GetFirstVideoContentDescription(current_description)), |
video_rtp_extensions_, |
+ enable_encrypted_rtp_header_extensions_, |
current_streams, |
add_legacy_, |
bundle_enabled, |
@@ -1995,6 +2049,7 @@ bool MediaSessionDescriptionFactory::AddDataContentForAnswer( |
sdes_policy, |
GetCryptos(GetFirstDataContentDescription(current_description)), |
RtpHeaderExtensions(), |
+ enable_encrypted_rtp_header_extensions_, |
current_streams, |
add_legacy_, |
bundle_enabled, |