Chromium Code Reviews| Index: webrtc/ortc/rtptransportadapter.cc |
| diff --git a/webrtc/ortc/rtptransportadapter.cc b/webrtc/ortc/rtptransportadapter.cc |
| index 439f9a83b450efc757b9f2e9a77b8d161dbc8b70..3c9e53f0ccc122bbb202aa618d9304ffbe3e69bd 100644 |
| --- a/webrtc/ortc/rtptransportadapter.cc |
| +++ b/webrtc/ortc/rtptransportadapter.cc |
| @@ -32,6 +32,20 @@ RtpTransportAdapter* GetInternal() override { |
| } |
| END_PROXY_MAP() |
| +BEGIN_OWNED_PROXY_MAP(SrtpTransport) |
| +PROXY_SIGNALING_THREAD_DESTRUCTOR() |
| +PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtpPacketTransport) |
| +PROXY_CONSTMETHOD0(PacketTransportInterface*, GetRtcpPacketTransport) |
| +PROXY_METHOD1(RTCError, SetRtcpParameters, const RtcpParameters&) |
| +PROXY_CONSTMETHOD0(RtcpParameters, GetRtcpParameters) |
| +PROXY_METHOD1(RTCError, SetSrtpSendKey, const cricket::CryptoParams&) |
| +PROXY_METHOD1(RTCError, SetSrtpReceiveKey, const cricket::CryptoParams&) |
| +protected: |
| +RtpTransportAdapter* GetInternal() override { |
| + return internal(); |
| +} |
| +END_PROXY_MAP() |
| + |
| // static |
| RTCErrorOr<std::unique_ptr<RtpTransportInterface>> |
| RtpTransportAdapter::CreateProxied( |
| @@ -64,7 +78,43 @@ RtpTransportAdapter::CreateProxied( |
| rtp_transport_controller->signaling_thread(), |
| rtp_transport_controller->worker_thread(), |
| std::unique_ptr<RtpTransportAdapter>(new RtpTransportAdapter( |
| - rtcp_parameters, rtp, rtcp, rtp_transport_controller))); |
| + rtcp_parameters, rtp, rtcp, rtp_transport_controller, |
| + /*is_srtp_transport*/ false))); |
| +} |
| + |
| +RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> |
| +RtpTransportAdapter::CreateSrtpProxied( |
| + const RtcpParameters& rtcp_parameters, |
| + PacketTransportInterface* rtp, |
| + PacketTransportInterface* rtcp, |
| + RtpTransportControllerAdapter* rtp_transport_controller) { |
| + if (!rtp) { |
| + LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, |
| + "Must provide an RTP packet transport."); |
| + } |
| + if (!rtcp_parameters.mux && !rtcp) { |
| + LOG_AND_RETURN_ERROR( |
| + RTCErrorType::INVALID_PARAMETER, |
| + "Must provide an RTCP packet transport when RTCP muxing is not used."); |
| + } |
| + if (rtcp_parameters.mux && rtcp) { |
| + LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, |
| + "Creating an RtpTransport with RTCP muxing enabled, " |
| + "with a separate RTCP packet transport?"); |
| + } |
| + if (!rtp_transport_controller) { |
| + // Since OrtcFactory::CreateRtpTransport creates an RtpTransportController |
| + // automatically when one isn't passed in, this should never be reached. |
| + RTC_NOTREACHED(); |
| + LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, |
| + "Must provide an RTP transport controller."); |
| + } |
| + return SrtpTransportProxyWithInternal<RtpTransportAdapter>::Create( |
| + rtp_transport_controller->signaling_thread(), |
| + rtp_transport_controller->worker_thread(), |
| + std::unique_ptr<RtpTransportAdapter>(new RtpTransportAdapter( |
| + rtcp_parameters, rtp, rtcp, rtp_transport_controller, |
| + /*is_srtp_transport*/ true))); |
| } |
| void RtpTransportAdapter::TakeOwnershipOfRtpTransportController( |
| @@ -78,11 +128,15 @@ RtpTransportAdapter::RtpTransportAdapter( |
| const RtcpParameters& rtcp_parameters, |
| PacketTransportInterface* rtp, |
| PacketTransportInterface* rtcp, |
| - RtpTransportControllerAdapter* rtp_transport_controller) |
| + RtpTransportControllerAdapter* rtp_transport_controller, |
| + bool is_srtp_transport) |
| : rtp_packet_transport_(rtp), |
| rtcp_packet_transport_(rtcp), |
| rtp_transport_controller_(rtp_transport_controller), |
| - rtcp_parameters_(rtcp_parameters) { |
| + rtcp_parameters_(rtcp_parameters), |
| + is_srtp_transport_(is_srtp_transport), |
| + have_send_key_(false), |
| + have_receive_key_(false) { |
| RTC_DCHECK(rtp_transport_controller); |
| // CNAME should have been filled by OrtcFactory if empty. |
| RTC_DCHECK(!rtcp_parameters_.cname.empty()); |
| @@ -126,4 +180,28 @@ RTCError RtpTransportAdapter::SetRtcpParameters( |
| return RTCError::OK(); |
| } |
| +RTCError RtpTransportAdapter::SetSrtpSendKey( |
| + const cricket::CryptoParams& params) { |
| + if (have_send_key_) { |
| + LOG_AND_RETURN_ERROR( |
| + webrtc::RTCErrorType::UNSUPPORTED_OPERATION, |
| + "Setting the SRTP send key twice is currently unsupported."); |
| + } |
|
Taylor Brandstetter
2017/03/01 19:18:08
I think it would make sense to check that the cryp
Zhi Huang
2017/03/02 23:35:39
Done.
|
| + send_key_ = params; |
| + have_send_key_ = true; |
| + return RTCError::OK(); |
| +} |
| + |
| +RTCError RtpTransportAdapter::SetSrtpReceiveKey( |
| + const cricket::CryptoParams& params) { |
| + if (have_receive_key_) { |
| + LOG_AND_RETURN_ERROR( |
| + webrtc::RTCErrorType::UNSUPPORTED_OPERATION, |
| + "Setting the SRTP receive key twice is currently unsupported."); |
| + } |
| + receive_key_ = params; |
| + have_receive_key_ = true; |
| + return RTCError::OK(); |
| +} |
| + |
| } // namespace webrtc |