Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(959)

Side by Side Diff: webrtc/ortc/rtptransportcontrolleradapter.cc

Issue 2714813004: Create the SrtpTransportInterface. (Closed)
Patch Set: Merge and modified the tests. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/ortc/rtptransportcontrolleradapter.h" 11 #include "webrtc/ortc/rtptransportcontrolleradapter.h"
12 12
13 #include <algorithm> // For "remove", "find". 13 #include <algorithm> // For "remove", "find".
14 #include <set>
14 #include <sstream> 15 #include <sstream>
15 #include <set>
16 #include <unordered_map> 16 #include <unordered_map>
17 #include <utility> // For std::move. 17 #include <utility> // For std::move.
18 18
19 #include "webrtc/api/proxy.h" 19 #include "webrtc/api/proxy.h"
20 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
21 #include "webrtc/media/base/mediaconstants.h" 21 #include "webrtc/media/base/mediaconstants.h"
22 #include "webrtc/ortc/ortcrtpreceiveradapter.h" 22 #include "webrtc/ortc/ortcrtpreceiveradapter.h"
23 #include "webrtc/ortc/ortcrtpsenderadapter.h" 23 #include "webrtc/ortc/ortcrtpsenderadapter.h"
24 #include "webrtc/ortc/rtpparametersconversion.h" 24 #include "webrtc/ortc/rtpparametersconversion.h"
25 #include "webrtc/ortc/rtptransportadapter.h" 25 #include "webrtc/ortc/rtptransportadapter.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 auto result = 131 auto result =
132 RtpTransportAdapter::CreateProxied(rtcp_parameters, rtp, rtcp, this); 132 RtpTransportAdapter::CreateProxied(rtcp_parameters, rtp, rtcp, this);
133 if (result.ok()) { 133 if (result.ok()) {
134 transport_proxies_.push_back(result.value().get()); 134 transport_proxies_.push_back(result.value().get());
135 transport_proxies_.back()->GetInternal()->SignalDestroyed.connect( 135 transport_proxies_.back()->GetInternal()->SignalDestroyed.connect(
136 this, &RtpTransportControllerAdapter::OnRtpTransportDestroyed); 136 this, &RtpTransportControllerAdapter::OnRtpTransportDestroyed);
137 } 137 }
138 return result; 138 return result;
139 } 139 }
140 140
141 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>>
142 RtpTransportControllerAdapter::CreateProxiedSrtpTransport(
143 const RtcpParameters& rtcp_parameters,
144 PacketTransportInterface* rtp,
145 PacketTransportInterface* rtcp) {
146 auto result =
147 RtpTransportAdapter::CreateSrtpProxied(rtcp_parameters, rtp, rtcp, this);
148 if (result.ok()) {
149 transport_proxies_.push_back(result.value().get());
150 transport_proxies_.back()->GetInternal()->SignalDestroyed.connect(
151 this, &RtpTransportControllerAdapter::OnRtpTransportDestroyed);
152 }
153 return result;
154 }
155
141 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> 156 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>>
142 RtpTransportControllerAdapter::CreateProxiedRtpSender( 157 RtpTransportControllerAdapter::CreateProxiedRtpSender(
143 cricket::MediaType kind, 158 cricket::MediaType kind,
144 RtpTransportInterface* transport_proxy) { 159 RtpTransportInterface* transport_proxy) {
145 RTC_DCHECK(transport_proxy); 160 RTC_DCHECK(transport_proxy);
146 RTC_DCHECK(std::find(transport_proxies_.begin(), transport_proxies_.end(), 161 RTC_DCHECK(std::find(transport_proxies_.begin(), transport_proxies_.end(),
147 transport_proxy) != transport_proxies_.end()); 162 transport_proxy) != transport_proxies_.end());
148 std::unique_ptr<OrtcRtpSenderAdapter> new_sender( 163 std::unique_ptr<OrtcRtpSenderAdapter> new_sender(
149 new OrtcRtpSenderAdapter(kind, transport_proxy, this)); 164 new OrtcRtpSenderAdapter(kind, transport_proxy, this));
150 RTCError err; 165 RTCError err;
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 "Using two audio RtpSenders with the same " 613 "Using two audio RtpSenders with the same "
599 "RtpTransportControllerAdapter is not currently " 614 "RtpTransportControllerAdapter is not currently "
600 "supported."); 615 "supported.");
601 } 616 }
602 if (inner_audio_transport_ && inner_audio_transport_ != inner_transport) { 617 if (inner_audio_transport_ && inner_audio_transport_ != inner_transport) {
603 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION, 618 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
604 "Using different transports for the audio " 619 "Using different transports for the audio "
605 "RtpSender and RtpReceiver is not currently " 620 "RtpSender and RtpReceiver is not currently "
606 "supported."); 621 "supported.");
607 } 622 }
623 RTCError err = MaybeSetCryptosForAudio(inner_transport);
624 if (!err.ok()) {
625 return err;
626 }
608 // If setting new transport, extract its RTCP parameters and create voice 627 // If setting new transport, extract its RTCP parameters and create voice
609 // channel. 628 // channel.
610 if (!inner_audio_transport_) { 629 if (!inner_audio_transport_) {
611 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 630 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
612 &local_audio_description_, 631 &local_audio_description_,
613 &remote_audio_description_); 632 &remote_audio_description_);
614 inner_audio_transport_ = inner_transport; 633 inner_audio_transport_ = inner_transport;
615 CreateVoiceChannel(); 634 CreateVoiceChannel();
616 } 635 }
617 have_audio_sender_ = true; 636 have_audio_sender_ = true;
(...skipping 10 matching lines...) Expand all
628 "Using two video RtpSenders with the same " 647 "Using two video RtpSenders with the same "
629 "RtpTransportControllerAdapter is not currently " 648 "RtpTransportControllerAdapter is not currently "
630 "supported."); 649 "supported.");
631 } 650 }
632 if (inner_video_transport_ && inner_video_transport_ != inner_transport) { 651 if (inner_video_transport_ && inner_video_transport_ != inner_transport) {
633 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION, 652 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
634 "Using different transports for the video " 653 "Using different transports for the video "
635 "RtpSender and RtpReceiver is not currently " 654 "RtpSender and RtpReceiver is not currently "
636 "supported."); 655 "supported.");
637 } 656 }
657 RTCError err = MaybeSetCryptosForVideo(inner_transport);
658 if (!err.ok()) {
659 return err;
660 }
638 // If setting new transport, extract its RTCP parameters and create video 661 // If setting new transport, extract its RTCP parameters and create video
639 // channel. 662 // channel.
640 if (!inner_video_transport_) { 663 if (!inner_video_transport_) {
641 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 664 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
642 &local_video_description_, 665 &local_video_description_,
643 &remote_video_description_); 666 &remote_video_description_);
644 inner_video_transport_ = inner_transport; 667 inner_video_transport_ = inner_transport;
645 CreateVideoChannel(); 668 CreateVideoChannel();
646 } 669 }
647 have_video_sender_ = true; 670 have_video_sender_ = true;
(...skipping 10 matching lines...) Expand all
658 "Using two audio RtpReceivers with the same " 681 "Using two audio RtpReceivers with the same "
659 "RtpTransportControllerAdapter is not currently " 682 "RtpTransportControllerAdapter is not currently "
660 "supported."); 683 "supported.");
661 } 684 }
662 if (inner_audio_transport_ && inner_audio_transport_ != inner_transport) { 685 if (inner_audio_transport_ && inner_audio_transport_ != inner_transport) {
663 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION, 686 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
664 "Using different transports for the audio " 687 "Using different transports for the audio "
665 "RtpReceiver and RtpReceiver is not currently " 688 "RtpReceiver and RtpReceiver is not currently "
666 "supported."); 689 "supported.");
667 } 690 }
691 RTCError err = MaybeSetCryptosForAudio(inner_transport);
692 if (!err.ok()) {
693 return err;
694 }
668 // If setting new transport, extract its RTCP parameters and create voice 695 // If setting new transport, extract its RTCP parameters and create voice
669 // channel. 696 // channel.
670 if (!inner_audio_transport_) { 697 if (!inner_audio_transport_) {
671 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 698 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
672 &local_audio_description_, 699 &local_audio_description_,
673 &remote_audio_description_); 700 &remote_audio_description_);
674 inner_audio_transport_ = inner_transport; 701 inner_audio_transport_ = inner_transport;
675 CreateVoiceChannel(); 702 CreateVoiceChannel();
676 } 703 }
677 have_audio_receiver_ = true; 704 have_audio_receiver_ = true;
(...skipping 10 matching lines...) Expand all
688 "Using two video RtpReceivers with the same " 715 "Using two video RtpReceivers with the same "
689 "RtpTransportControllerAdapter is not currently " 716 "RtpTransportControllerAdapter is not currently "
690 "supported."); 717 "supported.");
691 } 718 }
692 if (inner_video_transport_ && inner_video_transport_ != inner_transport) { 719 if (inner_video_transport_ && inner_video_transport_ != inner_transport) {
693 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION, 720 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
694 "Using different transports for the video " 721 "Using different transports for the video "
695 "RtpReceiver and RtpReceiver is not currently " 722 "RtpReceiver and RtpReceiver is not currently "
696 "supported."); 723 "supported.");
697 } 724 }
725 RTCError err = MaybeSetCryptosForVideo(inner_transport);
726 if (!err.ok()) {
727 return err;
728 }
698 // If setting new transport, extract its RTCP parameters and create video 729 // If setting new transport, extract its RTCP parameters and create video
699 // channel. 730 // channel.
700 if (!inner_video_transport_) { 731 if (!inner_video_transport_) {
701 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 732 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
702 &local_video_description_, 733 &local_video_description_,
703 &remote_video_description_); 734 &remote_video_description_);
704 inner_video_transport_ = inner_transport; 735 inner_video_transport_ = inner_transport;
705 CreateVideoChannel(); 736 CreateVideoChannel();
706 } 737 }
707 have_video_receiver_ = true; 738 have_video_receiver_ = true;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 auto result = ToCricketStreamParamsVec(encodings); 920 auto result = ToCricketStreamParamsVec(encodings);
890 if (!result.ok()) { 921 if (!result.ok()) {
891 return result.MoveError(); 922 return result.MoveError();
892 } 923 }
893 // If conversion was successful, there should be one StreamParams. 924 // If conversion was successful, there should be one StreamParams.
894 RTC_DCHECK_EQ(1u, result.value().size()); 925 RTC_DCHECK_EQ(1u, result.value().size());
895 result.value()[0].cname = cname; 926 result.value()[0].cname = cname;
896 return result; 927 return result;
897 } 928 }
898 929
930 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.
931 RtpTransportInterface* rtp_transport) {
932 if (rtp_transport->GetInternal()->is_srtp_transport()) {
933 if (!rtp_transport->GetInternal()->key_set()) {
934 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE,
935 "The SRTP send key or receive key is not set.")
936 }
937 std::vector<cricket::CryptoParams> cryptos;
938 cryptos.push_back(rtp_transport->GetInternal()->receive_key());
939 local_audio_description_.set_cryptos(cryptos);
940
941 cryptos.clear();
942 cryptos.push_back(rtp_transport->GetInternal()->send_key());
943 remote_audio_description_.set_cryptos(cryptos);
944 }
945 return RTCError::OK();
946 }
947
948 RTCError RtpTransportControllerAdapter::MaybeSetCryptosForVideo(
949 RtpTransportInterface* rtp_transport) {
950 if (rtp_transport->GetInternal()->is_srtp_transport()) {
951 if (!rtp_transport->GetInternal()->key_set()) {
952 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::INVALID_STATE,
953 "The SRTP send key or receive key is not set.")
954 }
955 std::vector<cricket::CryptoParams> cryptos;
956 cryptos.push_back(rtp_transport->GetInternal()->receive_key());
957 local_video_description_.set_cryptos(cryptos);
958
959 cryptos.clear();
960 cryptos.push_back(rtp_transport->GetInternal()->send_key());
961 remote_video_description_.set_cryptos(cryptos);
962 }
963 return RTCError::OK();
964 }
965
899 } // namespace webrtc 966 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698