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

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

Issue 2714813004: Create the SrtpTransportInterface. (Closed)
Patch Set: Use rtc::Optional for SRTP send and receive keys. 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
« no previous file with comments | « webrtc/ortc/rtptransportcontrolleradapter.h ('k') | webrtc/ortc/srtptransport_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = MaybeSetCryptos(inner_transport, &local_audio_description_,
624 &remote_audio_description_);
625 if (!err.ok()) {
626 return err;
627 }
608 // If setting new transport, extract its RTCP parameters and create voice 628 // If setting new transport, extract its RTCP parameters and create voice
609 // channel. 629 // channel.
610 if (!inner_audio_transport_) { 630 if (!inner_audio_transport_) {
611 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 631 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
612 &local_audio_description_, 632 &local_audio_description_,
613 &remote_audio_description_); 633 &remote_audio_description_);
614 inner_audio_transport_ = inner_transport; 634 inner_audio_transport_ = inner_transport;
615 CreateVoiceChannel(); 635 CreateVoiceChannel();
616 } 636 }
617 have_audio_sender_ = true; 637 have_audio_sender_ = true;
(...skipping 10 matching lines...) Expand all
628 "Using two video RtpSenders with the same " 648 "Using two video RtpSenders with the same "
629 "RtpTransportControllerAdapter is not currently " 649 "RtpTransportControllerAdapter is not currently "
630 "supported."); 650 "supported.");
631 } 651 }
632 if (inner_video_transport_ && inner_video_transport_ != inner_transport) { 652 if (inner_video_transport_ && inner_video_transport_ != inner_transport) {
633 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION, 653 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
634 "Using different transports for the video " 654 "Using different transports for the video "
635 "RtpSender and RtpReceiver is not currently " 655 "RtpSender and RtpReceiver is not currently "
636 "supported."); 656 "supported.");
637 } 657 }
658 RTCError err = MaybeSetCryptos(inner_transport, &local_video_description_,
659 &remote_video_description_);
660 if (!err.ok()) {
661 return err;
662 }
638 // If setting new transport, extract its RTCP parameters and create video 663 // If setting new transport, extract its RTCP parameters and create video
639 // channel. 664 // channel.
640 if (!inner_video_transport_) { 665 if (!inner_video_transport_) {
641 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 666 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
642 &local_video_description_, 667 &local_video_description_,
643 &remote_video_description_); 668 &remote_video_description_);
644 inner_video_transport_ = inner_transport; 669 inner_video_transport_ = inner_transport;
645 CreateVideoChannel(); 670 CreateVideoChannel();
646 } 671 }
647 have_video_sender_ = true; 672 have_video_sender_ = true;
(...skipping 10 matching lines...) Expand all
658 "Using two audio RtpReceivers with the same " 683 "Using two audio RtpReceivers with the same "
659 "RtpTransportControllerAdapter is not currently " 684 "RtpTransportControllerAdapter is not currently "
660 "supported."); 685 "supported.");
661 } 686 }
662 if (inner_audio_transport_ && inner_audio_transport_ != inner_transport) { 687 if (inner_audio_transport_ && inner_audio_transport_ != inner_transport) {
663 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION, 688 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
664 "Using different transports for the audio " 689 "Using different transports for the audio "
665 "RtpReceiver and RtpReceiver is not currently " 690 "RtpReceiver and RtpReceiver is not currently "
666 "supported."); 691 "supported.");
667 } 692 }
693 RTCError err = MaybeSetCryptos(inner_transport, &local_audio_description_,
694 &remote_audio_description_);
695 if (!err.ok()) {
696 return err;
697 }
668 // If setting new transport, extract its RTCP parameters and create voice 698 // If setting new transport, extract its RTCP parameters and create voice
669 // channel. 699 // channel.
670 if (!inner_audio_transport_) { 700 if (!inner_audio_transport_) {
671 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 701 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
672 &local_audio_description_, 702 &local_audio_description_,
673 &remote_audio_description_); 703 &remote_audio_description_);
674 inner_audio_transport_ = inner_transport; 704 inner_audio_transport_ = inner_transport;
675 CreateVoiceChannel(); 705 CreateVoiceChannel();
676 } 706 }
677 have_audio_receiver_ = true; 707 have_audio_receiver_ = true;
(...skipping 10 matching lines...) Expand all
688 "Using two video RtpReceivers with the same " 718 "Using two video RtpReceivers with the same "
689 "RtpTransportControllerAdapter is not currently " 719 "RtpTransportControllerAdapter is not currently "
690 "supported."); 720 "supported.");
691 } 721 }
692 if (inner_video_transport_ && inner_video_transport_ != inner_transport) { 722 if (inner_video_transport_ && inner_video_transport_ != inner_transport) {
693 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION, 723 LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_OPERATION,
694 "Using different transports for the video " 724 "Using different transports for the video "
695 "RtpReceiver and RtpReceiver is not currently " 725 "RtpReceiver and RtpReceiver is not currently "
696 "supported."); 726 "supported.");
697 } 727 }
728 RTCError err = MaybeSetCryptos(inner_transport, &local_video_description_,
729 &remote_video_description_);
730 if (!err.ok()) {
731 return err;
732 }
698 // If setting new transport, extract its RTCP parameters and create video 733 // If setting new transport, extract its RTCP parameters and create video
699 // channel. 734 // channel.
700 if (!inner_video_transport_) { 735 if (!inner_video_transport_) {
701 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(), 736 CopyRtcpParametersToDescriptions(inner_transport->GetRtcpParameters(),
702 &local_video_description_, 737 &local_video_description_,
703 &remote_video_description_); 738 &remote_video_description_);
704 inner_video_transport_ = inner_transport; 739 inner_video_transport_ = inner_transport;
705 CreateVideoChannel(); 740 CreateVideoChannel();
706 } 741 }
707 have_video_receiver_ = true; 742 have_video_receiver_ = true;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 auto result = ToCricketStreamParamsVec(encodings); 924 auto result = ToCricketStreamParamsVec(encodings);
890 if (!result.ok()) { 925 if (!result.ok()) {
891 return result.MoveError(); 926 return result.MoveError();
892 } 927 }
893 // If conversion was successful, there should be one StreamParams. 928 // If conversion was successful, there should be one StreamParams.
894 RTC_DCHECK_EQ(1u, result.value().size()); 929 RTC_DCHECK_EQ(1u, result.value().size());
895 result.value()[0].cname = cname; 930 result.value()[0].cname = cname;
896 return result; 931 return result;
897 } 932 }
898 933
934 RTCError RtpTransportControllerAdapter::MaybeSetCryptos(
935 RtpTransportInterface* rtp_transport,
936 cricket::MediaContentDescription* local_description,
937 cricket::MediaContentDescription* remote_description) {
938 if (rtp_transport->GetInternal()->is_srtp_transport()) {
939 if (!rtp_transport->GetInternal()->send_key() ||
940 !rtp_transport->GetInternal()->receive_key()) {
941 LOG_AND_RETURN_ERROR(webrtc::RTCErrorType::UNSUPPORTED_PARAMETER,
942 "The SRTP send key or receive key is not set.")
943 }
944 std::vector<cricket::CryptoParams> cryptos;
945 cryptos.push_back(*(rtp_transport->GetInternal()->receive_key()));
946 local_description->set_cryptos(cryptos);
947
948 cryptos.clear();
949 cryptos.push_back(*(rtp_transport->GetInternal()->send_key()));
950 remote_description->set_cryptos(cryptos);
951 }
952 return RTCError::OK();
953 }
954
899 } // namespace webrtc 955 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/ortc/rtptransportcontrolleradapter.h ('k') | webrtc/ortc/srtptransport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698