Chromium Code Reviews| Index: webrtc/ortc/rtptransportcontrolleradapter.cc |
| diff --git a/webrtc/ortc/rtptransportcontrolleradapter.cc b/webrtc/ortc/rtptransportcontrolleradapter.cc |
| index 08e943a200ad1249784dd9267c7e341b6ba7462d..cb4c4bce7e04bde0e8af8adcf1cdc43286da8db1 100644 |
| --- a/webrtc/ortc/rtptransportcontrolleradapter.cc |
| +++ b/webrtc/ortc/rtptransportcontrolleradapter.cc |
| @@ -11,8 +11,8 @@ |
| #include "webrtc/ortc/rtptransportcontrolleradapter.h" |
| #include <algorithm> // For "remove", "find". |
| -#include <sstream> |
| #include <set> |
| +#include <sstream> |
| #include <unordered_map> |
| #include <utility> // For std::move. |
| @@ -138,6 +138,21 @@ RtpTransportControllerAdapter::CreateProxiedRtpTransport( |
| return result; |
| } |
| +RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> |
| +RtpTransportControllerAdapter::CreateProxiedSrtpTransport( |
| + const RtcpParameters& rtcp_parameters, |
| + PacketTransportInterface* rtp, |
| + PacketTransportInterface* rtcp) { |
| + auto result = |
| + RtpTransportAdapter::CreateSrtpProxied(rtcp_parameters, rtp, rtcp, this); |
| + if (result.ok()) { |
| + transport_proxies_.push_back(result.value().get()); |
| + transport_proxies_.back()->GetInternal()->SignalDestroyed.connect( |
| + this, &RtpTransportControllerAdapter::OnRtpTransportDestroyed); |
| + } |
| + return result; |
| +} |
| + |
| RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> |
| RtpTransportControllerAdapter::CreateProxiedRtpSender( |
| cricket::MediaType kind, |
| @@ -605,6 +620,10 @@ RTCError RtpTransportControllerAdapter::AttachAudioSender( |
| "RtpSender and RtpReceiver is not currently " |
| "supported."); |
| } |
| + RTCError err = MaybeSetCryptosForAudio(inner_transport); |
| + if (!err.ok()) { |
| + return err; |
| + } |
| // If setting new transport, extract its RTCP parameters and create voice |
| // channel. |
| if (!inner_audio_transport_) { |
| @@ -635,6 +654,10 @@ RTCError RtpTransportControllerAdapter::AttachVideoSender( |
| "RtpSender and RtpReceiver is not currently " |
| "supported."); |
| } |
| + RTCError err = MaybeSetCryptosForVideo(inner_transport); |
| + if (!err.ok()) { |
| + return err; |
| + } |
| // If setting new transport, extract its RTCP parameters and create video |
| // channel. |
| if (!inner_video_transport_) { |
| @@ -665,6 +688,10 @@ RTCError RtpTransportControllerAdapter::AttachAudioReceiver( |
| "RtpReceiver and RtpReceiver is not currently " |
| "supported."); |
| } |
| + RTCError err = MaybeSetCryptosForAudio(inner_transport); |
| + if (!err.ok()) { |
| + return err; |
| + } |
| // If setting new transport, extract its RTCP parameters and create voice |
| // channel. |
| if (!inner_audio_transport_) { |
| @@ -695,6 +722,10 @@ RTCError RtpTransportControllerAdapter::AttachVideoReceiver( |
| "RtpReceiver and RtpReceiver is not currently " |
| "supported."); |
| } |
| + RTCError err = MaybeSetCryptosForVideo(inner_transport); |
| + if (!err.ok()) { |
| + return err; |
| + } |
| // If setting new transport, extract its RTCP parameters and create video |
| // channel. |
| if (!inner_video_transport_) { |
| @@ -896,4 +927,40 @@ RtpTransportControllerAdapter::MakeSendStreamParamsVec( |
| return result; |
| } |
| +RTCError RtpTransportControllerAdapter::MaybeSetCryptosForAudio( |
|
Taylor Brandstetter
2017/03/01 19:18:08
nit: Instead of two separate methods, there could
Zhi Huang
2017/03/02 23:35:39
Done.
|
| + RtpTransportInterface* rtp_transport) { |
| + if (rtp_transport->GetInternal()->is_srtp_transport()) { |
| + if (!rtp_transport->GetInternal()->key_set()) { |
| + LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE, |
| + "The SRTP send key or receive key is not set.") |
| + } |
| + std::vector<cricket::CryptoParams> cryptos; |
| + cryptos.push_back(rtp_transport->GetInternal()->receive_key()); |
| + local_audio_description_.set_cryptos(cryptos); |
| + |
| + cryptos.clear(); |
| + cryptos.push_back(rtp_transport->GetInternal()->send_key()); |
| + remote_audio_description_.set_cryptos(cryptos); |
| + } |
| + return RTCError::OK(); |
| +} |
| + |
| +RTCError RtpTransportControllerAdapter::MaybeSetCryptosForVideo( |
| + RtpTransportInterface* rtp_transport) { |
| + if (rtp_transport->GetInternal()->is_srtp_transport()) { |
| + if (!rtp_transport->GetInternal()->key_set()) { |
| + LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE, |
| + "The SRTP send key or receive key is not set.") |
| + } |
| + std::vector<cricket::CryptoParams> cryptos; |
| + cryptos.push_back(rtp_transport->GetInternal()->receive_key()); |
| + local_video_description_.set_cryptos(cryptos); |
| + |
| + cryptos.clear(); |
| + cryptos.push_back(rtp_transport->GetInternal()->send_key()); |
| + remote_video_description_.set_cryptos(cryptos); |
| + } |
| + return RTCError::OK(); |
| +} |
| + |
| } // namespace webrtc |