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

Side by Side Diff: talk/session/media/channel.cc

Issue 1416673006: Convert internal representation of Srtp cryptos from string to int. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: remove thread checker Created 5 years, 1 month 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 * libjingle 2 * libjingle
3 * Copyright 2004 Google Inc. 3 * Copyright 2004 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); 211 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
212 } 212 }
213 LOG(LS_INFO) << "Destroyed channel"; 213 LOG(LS_INFO) << "Destroyed channel";
214 } 214 }
215 215
216 bool BaseChannel::Init() { 216 bool BaseChannel::Init() {
217 if (!SetTransport(content_name())) { 217 if (!SetTransport(content_name())) {
218 return false; 218 return false;
219 } 219 }
220 220
221 if (!SetDtlsSrtpCiphers(transport_channel(), false)) { 221 if (!SetDtlsSrtpCryptoSuites(transport_channel(), false)) {
222 return false; 222 return false;
223 } 223 }
224 if (rtcp_transport_enabled() && 224 if (rtcp_transport_enabled() &&
225 !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) { 225 !SetDtlsSrtpCryptoSuites(rtcp_transport_channel(), true)) {
226 return false; 226 return false;
227 } 227 }
228 228
229 // Both RTP and RTCP channels are set, we can call SetInterface on 229 // Both RTP and RTCP channels are set, we can call SetInterface on
230 // media channel and it can set network options. 230 // media channel and it can set network options.
231 media_channel_->SetInterface(this); 231 media_channel_->SetInterface(this);
232 return true; 232 return true;
233 } 233 }
234 234
235 void BaseChannel::Deinit() { 235 void BaseChannel::Deinit() {
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 ASSERT(worker_thread() == rtc::Thread::Current()); 802 ASSERT(worker_thread() == rtc::Thread::Current());
803 signaling_thread()->Invoke<void>(Bind( 803 signaling_thread()->Invoke<void>(Bind(
804 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp)); 804 &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp));
805 } 805 }
806 806
807 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) { 807 void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) {
808 ASSERT(signaling_thread() == rtc::Thread::Current()); 808 ASSERT(signaling_thread() == rtc::Thread::Current());
809 SignalDtlsSetupFailure(this, rtcp); 809 SignalDtlsSetupFailure(this, rtcp);
810 } 810 }
811 811
812 bool BaseChannel::SetDtlsSrtpCiphers(TransportChannel *tc, bool rtcp) { 812 bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) {
813 std::vector<std::string> ciphers; 813 std::vector<int> crypto_suites;
814 // We always use the default SRTP ciphers for RTCP, but we may use different 814 // We always use the default SRTP crypto suites for RTCP, but we may use
815 // ciphers for RTP depending on the media type. 815 // different crypto suites for RTP depending on the media type.
816 if (!rtcp) { 816 if (!rtcp) {
817 GetSrtpCryptoSuiteNames(&ciphers); 817 GetSrtpCryptoSuites(&crypto_suites);
818 } else { 818 } else {
819 GetDefaultSrtpCryptoSuiteNames(&ciphers); 819 GetDefaultSrtpCryptoSuites(&crypto_suites);
820 } 820 }
821 return tc->SetSrtpCiphers(ciphers); 821 return tc->SetSrtpCryptoSuites(crypto_suites);
822 } 822 }
823 823
824 bool BaseChannel::ShouldSetupDtlsSrtp() const { 824 bool BaseChannel::ShouldSetupDtlsSrtp() const {
825 return true; 825 return true;
826 } 826 }
827 827
828 // This function returns true if either DTLS-SRTP is not in use 828 // This function returns true if either DTLS-SRTP is not in use
829 // *or* DTLS-SRTP is successfully set up. 829 // *or* DTLS-SRTP is successfully set up.
830 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) { 830 bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
831 bool ret = false; 831 bool ret = false;
832 832
833 TransportChannel* channel = 833 TransportChannel* channel =
834 rtcp_channel ? rtcp_transport_channel_ : transport_channel_; 834 rtcp_channel ? rtcp_transport_channel_ : transport_channel_;
835 835
836 // No DTLS 836 // No DTLS
837 if (!channel->IsDtlsActive()) 837 if (!channel->IsDtlsActive())
838 return true; 838 return true;
839 839
840 std::string selected_cipher; 840 int selected_crypto_suite;
841 841
842 if (!channel->GetSrtpCryptoSuite(&selected_cipher)) { 842 if (!channel->GetSrtpCryptoSuite(&selected_crypto_suite)) {
843 LOG(LS_ERROR) << "No DTLS-SRTP selected cipher"; 843 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite";
844 return false; 844 return false;
845 } 845 }
846 846
847 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " 847 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on "
848 << content_name() << " " 848 << content_name() << " "
849 << PacketType(rtcp_channel); 849 << PacketType(rtcp_channel);
850 850
851 // OK, we're now doing DTLS (RFC 5764) 851 // OK, we're now doing DTLS (RFC 5764)
852 std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 + 852 std::vector<unsigned char> dtls_buffer(SRTP_MASTER_KEY_KEY_LEN * 2 +
853 SRTP_MASTER_KEY_SALT_LEN * 2); 853 SRTP_MASTER_KEY_SALT_LEN * 2);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 889
890 if (role == rtc::SSL_SERVER) { 890 if (role == rtc::SSL_SERVER) {
891 send_key = &server_write_key; 891 send_key = &server_write_key;
892 recv_key = &client_write_key; 892 recv_key = &client_write_key;
893 } else { 893 } else {
894 send_key = &client_write_key; 894 send_key = &client_write_key;
895 recv_key = &server_write_key; 895 recv_key = &server_write_key;
896 } 896 }
897 897
898 if (rtcp_channel) { 898 if (rtcp_channel) {
899 ret = srtp_filter_.SetRtcpParams( 899 ret = srtp_filter_.SetRtcpParams(selected_crypto_suite, &(*send_key)[0],
900 selected_cipher, 900 static_cast<int>(send_key->size()),
901 &(*send_key)[0], 901 selected_crypto_suite, &(*recv_key)[0],
902 static_cast<int>(send_key->size()), 902 static_cast<int>(recv_key->size()));
903 selected_cipher,
904 &(*recv_key)[0],
905 static_cast<int>(recv_key->size()));
906 } else { 903 } else {
907 ret = srtp_filter_.SetRtpParams( 904 ret = srtp_filter_.SetRtpParams(selected_crypto_suite, &(*send_key)[0],
908 selected_cipher, 905 static_cast<int>(send_key->size()),
909 &(*send_key)[0], 906 selected_crypto_suite, &(*recv_key)[0],
910 static_cast<int>(send_key->size()), 907 static_cast<int>(recv_key->size()));
911 selected_cipher,
912 &(*recv_key)[0],
913 static_cast<int>(recv_key->size()));
914 } 908 }
915 909
916 if (!ret) 910 if (!ret)
917 LOG(LS_WARNING) << "DTLS-SRTP key installation failed"; 911 LOG(LS_WARNING) << "DTLS-SRTP key installation failed";
918 else 912 else
919 dtls_keyed_ = true; 913 dtls_keyed_ = true;
920 914
921 return ret; 915 return ret;
922 } 916 }
923 917
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1573 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) { 1567 VoiceMediaChannel* media_channel, const VoiceMediaInfo& info) {
1574 ASSERT(media_channel == this->media_channel()); 1568 ASSERT(media_channel == this->media_channel());
1575 SignalMediaMonitor(this, info); 1569 SignalMediaMonitor(this, info);
1576 } 1570 }
1577 1571
1578 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor, 1572 void VoiceChannel::OnAudioMonitorUpdate(AudioMonitor* monitor,
1579 const AudioInfo& info) { 1573 const AudioInfo& info) {
1580 SignalAudioMonitor(this, info); 1574 SignalAudioMonitor(this, info);
1581 } 1575 }
1582 1576
1583 void VoiceChannel::GetSrtpCryptoSuiteNames( 1577 void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
1584 std::vector<std::string>* ciphers) const { 1578 GetSupportedAudioCryptoSuites(crypto_suites);
1585 GetSupportedAudioCryptoSuites(ciphers);
1586 } 1579 }
1587 1580
1588 VideoChannel::VideoChannel(rtc::Thread* thread, 1581 VideoChannel::VideoChannel(rtc::Thread* thread,
1589 VideoMediaChannel* media_channel, 1582 VideoMediaChannel* media_channel,
1590 TransportController* transport_controller, 1583 TransportController* transport_controller,
1591 const std::string& content_name, 1584 const std::string& content_name,
1592 bool rtcp) 1585 bool rtcp)
1593 : BaseChannel(thread, 1586 : BaseChannel(thread,
1594 media_channel, 1587 media_channel,
1595 transport_controller, 1588 transport_controller,
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 for (ScreencastMap::iterator iter = screencast_capturers_.begin(); 1956 for (ScreencastMap::iterator iter = screencast_capturers_.begin();
1964 iter != screencast_capturers_.end(); ++iter) { 1957 iter != screencast_capturers_.end(); ++iter) {
1965 if (iter->second == capturer) { 1958 if (iter->second == capturer) {
1966 *ssrc = iter->first; 1959 *ssrc = iter->first;
1967 return true; 1960 return true;
1968 } 1961 }
1969 } 1962 }
1970 return false; 1963 return false;
1971 } 1964 }
1972 1965
1973 void VideoChannel::GetSrtpCryptoSuiteNames( 1966 void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
1974 std::vector<std::string>* ciphers) const { 1967 GetSupportedVideoCryptoSuites(crypto_suites);
1975 GetSupportedVideoCryptoSuites(ciphers);
1976 } 1968 }
1977 1969
1978 DataChannel::DataChannel(rtc::Thread* thread, 1970 DataChannel::DataChannel(rtc::Thread* thread,
1979 DataMediaChannel* media_channel, 1971 DataMediaChannel* media_channel,
1980 TransportController* transport_controller, 1972 TransportController* transport_controller,
1981 const std::string& content_name, 1973 const std::string& content_name,
1982 bool rtcp) 1974 bool rtcp)
1983 : BaseChannel(thread, 1975 : BaseChannel(thread,
1984 media_channel, 1976 media_channel,
1985 transport_controller, 1977 transport_controller,
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 } 2263 }
2272 2264
2273 void DataChannel::OnDataChannelReadyToSend(bool writable) { 2265 void DataChannel::OnDataChannelReadyToSend(bool writable) {
2274 // This is usded for congestion control to indicate that the stream is ready 2266 // This is usded for congestion control to indicate that the stream is ready
2275 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates 2267 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates
2276 // that the transport channel is ready. 2268 // that the transport channel is ready.
2277 signaling_thread()->Post(this, MSG_READYTOSENDDATA, 2269 signaling_thread()->Post(this, MSG_READYTOSENDDATA,
2278 new DataChannelReadyToSendMessageData(writable)); 2270 new DataChannelReadyToSendMessageData(writable));
2279 } 2271 }
2280 2272
2281 void DataChannel::GetSrtpCryptoSuiteNames( 2273 void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
2282 std::vector<std::string>* ciphers) const { 2274 GetSupportedDataCryptoSuites(crypto_suites);
2283 GetSupportedDataCryptoSuites(ciphers);
2284 } 2275 }
2285 2276
2286 bool DataChannel::ShouldSetupDtlsSrtp() const { 2277 bool DataChannel::ShouldSetupDtlsSrtp() const {
2287 return (data_channel_type_ == DCT_RTP); 2278 return (data_channel_type_ == DCT_RTP);
2288 } 2279 }
2289 2280
2290 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { 2281 void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
2291 rtc::TypedMessageData<uint32_t>* message = 2282 rtc::TypedMessageData<uint32_t>* message =
2292 new rtc::TypedMessageData<uint32_t>(sid); 2283 new rtc::TypedMessageData<uint32_t>(sid);
2293 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); 2284 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message);
2294 } 2285 }
2295 2286
2296 } // namespace cricket 2287 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698