henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/mediasession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 13 | #include <algorithm> // For std::find_if, std::sort. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 14 | #include <functional> |
| 15 | #include <map> |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 16 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | #include <set> |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 18 | #include <unordered_map> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 19 | #include <utility> |
| 20 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 21 | #include "absl/memory/memory.h" |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 22 | #include "absl/strings/match.h" |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 23 | #include "absl/types/optional.h" |
Patrik Höglund | 7aee3d5 | 2017-11-15 13:15:17 +0100 | [diff] [blame] | 24 | #include "api/cryptoparams.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "media/base/h264_profile_level_id.h" |
| 26 | #include "media/base/mediaconstants.h" |
| 27 | #include "p2p/base/p2pconstants.h" |
| 28 | #include "pc/channelmanager.h" |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 29 | #include "pc/rtpmediautils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "pc/srtpfilter.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "rtc_base/checks.h" |
| 32 | #include "rtc_base/helpers.h" |
| 33 | #include "rtc_base/logging.h" |
| 34 | #include "rtc_base/stringutils.h" |
Artem Titov | a76af0c | 2018-07-23 17:38:12 +0200 | [diff] [blame] | 35 | #include "rtc_base/third_party/base64/base64.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | |
| 37 | namespace { |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 38 | |
| 39 | using webrtc::RtpTransceiverDirection; |
| 40 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | const char kInline[] = "inline:"; |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 42 | |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 43 | void GetSupportedSdesCryptoSuiteNames( |
| 44 | void (*func)(const webrtc::CryptoOptions&, std::vector<int>*), |
| 45 | const webrtc::CryptoOptions& crypto_options, |
| 46 | std::vector<std::string>* names) { |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 47 | std::vector<int> crypto_suites; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 48 | func(crypto_options, &crypto_suites); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 49 | for (const auto crypto : crypto_suites) { |
| 50 | names->push_back(rtc::SrtpCryptoSuiteToName(crypto)); |
| 51 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 52 | } |
terelius | 8c011e5 | 2016-04-26 05:28:11 -0700 | [diff] [blame] | 53 | } // namespace |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | |
| 55 | namespace cricket { |
| 56 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | // RTP Profile names |
| 58 | // http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml |
| 59 | // RFC4585 |
| 60 | const char kMediaProtocolAvpf[] = "RTP/AVPF"; |
| 61 | // RFC5124 |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 62 | const char kMediaProtocolDtlsSavpf[] = "UDP/TLS/RTP/SAVPF"; |
| 63 | |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 64 | // We always generate offers with "UDP/TLS/RTP/SAVPF" when using DTLS-SRTP, |
| 65 | // but we tolerate "RTP/SAVPF" in offers we receive, for compatibility. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | const char kMediaProtocolSavpf[] = "RTP/SAVPF"; |
| 67 | |
| 68 | const char kMediaProtocolRtpPrefix[] = "RTP/"; |
| 69 | |
| 70 | const char kMediaProtocolSctp[] = "SCTP"; |
| 71 | const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP"; |
lally@webrtc.org | ec97c65 | 2015-02-24 20:18:48 +0000 | [diff] [blame] | 72 | const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP"; |
lally@webrtc.org | a747093 | 2015-02-24 20:19:21 +0000 | [diff] [blame] | 73 | const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 75 | // Note that the below functions support some protocol strings purely for |
| 76 | // legacy compatibility, as required by JSEP in Section 5.1.2, Profile Names |
| 77 | // and Interoperability. |
| 78 | |
| 79 | static bool IsDtlsRtp(const std::string& protocol) { |
| 80 | // Most-likely values first. |
| 81 | return protocol == "UDP/TLS/RTP/SAVPF" || protocol == "TCP/TLS/RTP/SAVPF" || |
| 82 | protocol == "UDP/TLS/RTP/SAVP" || protocol == "TCP/TLS/RTP/SAVP"; |
| 83 | } |
| 84 | |
| 85 | static bool IsPlainRtp(const std::string& protocol) { |
| 86 | // Most-likely values first. |
| 87 | return protocol == "RTP/SAVPF" || protocol == "RTP/AVPF" || |
| 88 | protocol == "RTP/SAVP" || protocol == "RTP/AVP"; |
| 89 | } |
| 90 | |
| 91 | static bool IsDtlsSctp(const std::string& protocol) { |
| 92 | return protocol == kMediaProtocolDtlsSctp || |
| 93 | protocol == kMediaProtocolUdpDtlsSctp || |
| 94 | protocol == kMediaProtocolTcpDtlsSctp; |
| 95 | } |
| 96 | |
| 97 | static bool IsPlainSctp(const std::string& protocol) { |
| 98 | return protocol == kMediaProtocolSctp; |
| 99 | } |
| 100 | |
| 101 | static bool IsSctp(const std::string& protocol) { |
| 102 | return IsPlainSctp(protocol) || IsDtlsSctp(protocol); |
| 103 | } |
| 104 | |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 105 | static RtpTransceiverDirection NegotiateRtpTransceiverDirection( |
| 106 | RtpTransceiverDirection offer, |
| 107 | RtpTransceiverDirection wants) { |
| 108 | bool offer_send = webrtc::RtpTransceiverDirectionHasSend(offer); |
| 109 | bool offer_recv = webrtc::RtpTransceiverDirectionHasRecv(offer); |
| 110 | bool wants_send = webrtc::RtpTransceiverDirectionHasSend(wants); |
| 111 | bool wants_recv = webrtc::RtpTransceiverDirectionHasRecv(wants); |
| 112 | return webrtc::RtpTransceiverDirectionFromSendRecv(offer_recv && wants_send, |
| 113 | offer_send && wants_recv); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 114 | } |
| 115 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | static bool IsMediaContentOfType(const ContentInfo* content, |
| 117 | MediaType media_type) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 118 | if (!content || !content->media_description()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 119 | return false; |
| 120 | } |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 121 | return content->media_description()->type() == media_type; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 124 | static bool CreateCryptoParams(int tag, |
| 125 | const std::string& cipher, |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 126 | CryptoParams* crypto_out) { |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 127 | int key_len; |
| 128 | int salt_len; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 129 | if (!rtc::GetSrtpKeyAndSaltLengths(rtc::SrtpCryptoSuiteFromName(cipher), |
| 130 | &key_len, &salt_len)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | return false; |
| 132 | } |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 133 | |
| 134 | int master_key_len = key_len + salt_len; |
| 135 | std::string master_key; |
| 136 | if (!rtc::CreateRandomData(master_key_len, &master_key)) { |
| 137 | return false; |
| 138 | } |
| 139 | |
kwiberg | 352444f | 2016-11-28 15:58:53 -0800 | [diff] [blame] | 140 | RTC_CHECK_EQ(master_key_len, master_key.size()); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 141 | std::string key = rtc::Base64::Encode(master_key); |
| 142 | |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 143 | crypto_out->tag = tag; |
| 144 | crypto_out->cipher_suite = cipher; |
| 145 | crypto_out->key_params = kInline; |
| 146 | crypto_out->key_params += key; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 147 | return true; |
| 148 | } |
| 149 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 150 | static bool AddCryptoParams(const std::string& cipher_suite, |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 151 | CryptoParamsVec* cryptos_out) { |
| 152 | int size = static_cast<int>(cryptos_out->size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 154 | cryptos_out->resize(size + 1); |
| 155 | return CreateCryptoParams(size, cipher_suite, &cryptos_out->at(size)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void AddMediaCryptos(const CryptoParamsVec& cryptos, |
| 159 | MediaContentDescription* media) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 160 | for (const CryptoParams& crypto : cryptos) { |
| 161 | media->AddCrypto(crypto); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
| 165 | bool CreateMediaCryptos(const std::vector<std::string>& crypto_suites, |
| 166 | MediaContentDescription* media) { |
| 167 | CryptoParamsVec cryptos; |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 168 | for (const std::string& crypto_suite : crypto_suites) { |
| 169 | if (!AddCryptoParams(crypto_suite, &cryptos)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 170 | return false; |
| 171 | } |
| 172 | } |
| 173 | AddMediaCryptos(cryptos, media); |
| 174 | return true; |
| 175 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 177 | const CryptoParamsVec* GetCryptos(const ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 178 | if (!content || !content->media_description()) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 179 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | } |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 181 | return &content->media_description()->cryptos(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | bool FindMatchingCrypto(const CryptoParamsVec& cryptos, |
| 185 | const CryptoParams& crypto, |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 186 | CryptoParams* crypto_out) { |
| 187 | auto it = std::find_if( |
| 188 | cryptos.begin(), cryptos.end(), |
| 189 | [&crypto](const CryptoParams& c) { return crypto.Matches(c); }); |
| 190 | if (it == cryptos.end()) { |
| 191 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 192 | } |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 193 | *crypto_out = *it; |
| 194 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 197 | // For audio, HMAC 32 (if enabled) is prefered over HMAC 80 because of the |
| 198 | // low overhead. |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 199 | void GetSupportedAudioSdesCryptoSuites( |
| 200 | const webrtc::CryptoOptions& crypto_options, |
| 201 | std::vector<int>* crypto_suites) { |
| 202 | if (crypto_options.srtp.enable_gcm_crypto_suites) { |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 203 | crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); |
| 204 | crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); |
| 205 | } |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 206 | if (crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher) { |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 207 | crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_32); |
| 208 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 209 | crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | } |
| 211 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 212 | void GetSupportedAudioSdesCryptoSuiteNames( |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 213 | const webrtc::CryptoOptions& crypto_options, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 214 | std::vector<std::string>* crypto_suite_names) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 215 | GetSupportedSdesCryptoSuiteNames(GetSupportedAudioSdesCryptoSuites, |
| 216 | crypto_options, crypto_suite_names); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 219 | void GetSupportedVideoSdesCryptoSuites( |
| 220 | const webrtc::CryptoOptions& crypto_options, |
| 221 | std::vector<int>* crypto_suites) { |
| 222 | if (crypto_options.srtp.enable_gcm_crypto_suites) { |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 223 | crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); |
| 224 | crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); |
| 225 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 226 | crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | } |
| 228 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 229 | void GetSupportedVideoSdesCryptoSuiteNames( |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 230 | const webrtc::CryptoOptions& crypto_options, |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 231 | std::vector<std::string>* crypto_suite_names) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 232 | GetSupportedSdesCryptoSuiteNames(GetSupportedVideoSdesCryptoSuites, |
| 233 | crypto_options, crypto_suite_names); |
| 234 | } |
| 235 | |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 236 | void GetSupportedDataSdesCryptoSuites( |
| 237 | const webrtc::CryptoOptions& crypto_options, |
| 238 | std::vector<int>* crypto_suites) { |
| 239 | if (crypto_options.srtp.enable_gcm_crypto_suites) { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 240 | crypto_suites->push_back(rtc::SRTP_AEAD_AES_256_GCM); |
| 241 | crypto_suites->push_back(rtc::SRTP_AEAD_AES_128_GCM); |
| 242 | } |
| 243 | crypto_suites->push_back(rtc::SRTP_AES128_CM_SHA1_80); |
| 244 | } |
| 245 | |
| 246 | void GetSupportedDataSdesCryptoSuiteNames( |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 247 | const webrtc::CryptoOptions& crypto_options, |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 248 | std::vector<std::string>* crypto_suite_names) { |
| 249 | GetSupportedSdesCryptoSuiteNames(GetSupportedDataSdesCryptoSuites, |
| 250 | crypto_options, crypto_suite_names); |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 251 | } |
| 252 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 253 | // Support any GCM cipher (if enabled through options). For video support only |
Taylor Brandstetter | 5e55fe8 | 2018-03-23 11:50:16 -0700 | [diff] [blame] | 254 | // 80-bit SHA1 HMAC. For audio 32-bit HMAC is tolerated (if enabled) unless |
| 255 | // bundle is enabled because it is low overhead. |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 256 | // Pick the crypto in the list that is supported. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | static bool SelectCrypto(const MediaContentDescription* offer, |
| 258 | bool bundle, |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 259 | const webrtc::CryptoOptions& crypto_options, |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 260 | CryptoParams* crypto_out) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 261 | bool audio = offer->type() == MEDIA_TYPE_AUDIO; |
| 262 | const CryptoParamsVec& cryptos = offer->cryptos(); |
| 263 | |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 264 | for (const CryptoParams& crypto : cryptos) { |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 265 | if ((crypto_options.srtp.enable_gcm_crypto_suites && |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 266 | rtc::IsGcmCryptoSuiteName(crypto.cipher_suite)) || |
| 267 | rtc::CS_AES_CM_128_HMAC_SHA1_80 == crypto.cipher_suite || |
| 268 | (rtc::CS_AES_CM_128_HMAC_SHA1_32 == crypto.cipher_suite && audio && |
Benjamin Wright | a54daf1 | 2018-10-11 15:33:17 -0700 | [diff] [blame] | 269 | !bundle && crypto_options.srtp.enable_aes128_sha1_32_crypto_cipher)) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 270 | return CreateCryptoParams(crypto.tag, crypto.cipher_suite, crypto_out); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | return false; |
| 274 | } |
| 275 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 276 | // Generate random SSRC values that are not already present in |params_vec|. |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 277 | // The generated values are added to |ssrcs|. |
| 278 | // |num_ssrcs| is the number of the SSRC will be generated. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 279 | static void GenerateSsrcs(const StreamParamsVec& params_vec, |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 280 | int num_ssrcs, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 281 | std::vector<uint32_t>* ssrcs) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 282 | for (int i = 0; i < num_ssrcs; i++) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 283 | uint32_t candidate; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 284 | do { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 285 | candidate = rtc::CreateRandomNonZeroId(); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 286 | } while (GetStreamBySsrc(params_vec, candidate) || |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 287 | std::count(ssrcs->begin(), ssrcs->end(), candidate) > 0); |
| 288 | ssrcs->push_back(candidate); |
| 289 | } |
| 290 | } |
| 291 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 292 | // Finds all StreamParams of all media types and attach them to stream_params. |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 293 | static StreamParamsVec GetCurrentStreamParams( |
| 294 | const std::vector<const ContentInfo*>& active_local_contents) { |
| 295 | StreamParamsVec stream_params; |
| 296 | for (const ContentInfo* content : active_local_contents) { |
| 297 | for (const StreamParams& params : content->media_description()->streams()) { |
| 298 | stream_params.push_back(params); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 301 | return stream_params; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | } |
| 303 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 304 | // Filters the data codecs for the data channel type. |
| 305 | void FilterDataCodecs(std::vector<DataCodec>* codecs, bool sctp) { |
| 306 | // Filter RTP codec for SCTP and vice versa. |
solenberg | 9fa4975 | 2016-10-08 13:02:44 -0700 | [diff] [blame] | 307 | const char* codec_name = |
| 308 | sctp ? kGoogleRtpDataCodecName : kGoogleSctpDataCodecName; |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 309 | codecs->erase(std::remove_if(codecs->begin(), codecs->end(), |
| 310 | [&codec_name](const DataCodec& codec) { |
Niels Möller | 039743e | 2018-10-23 10:07:25 +0200 | [diff] [blame] | 311 | return absl::EqualsIgnoreCase(codec.name, |
| 312 | codec_name); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 313 | }), |
| 314 | codecs->end()); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 315 | } |
| 316 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | template <typename IdStruct> |
| 318 | class UsedIds { |
| 319 | public: |
| 320 | UsedIds(int min_allowed_id, int max_allowed_id) |
| 321 | : min_allowed_id_(min_allowed_id), |
| 322 | max_allowed_id_(max_allowed_id), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 323 | next_id_(max_allowed_id) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 324 | |
| 325 | // Loops through all Id in |ids| and changes its id if it is |
| 326 | // already in use by another IdStruct. Call this methods with all Id |
| 327 | // in a session description to make sure no duplicate ids exists. |
| 328 | // Note that typename Id must be a type of IdStruct. |
| 329 | template <typename Id> |
| 330 | void FindAndSetIdUsed(std::vector<Id>* ids) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 331 | for (const Id& id : *ids) { |
| 332 | FindAndSetIdUsed(&id); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
| 336 | // Finds and sets an unused id if the |idstruct| id is already in use. |
| 337 | void FindAndSetIdUsed(IdStruct* idstruct) { |
| 338 | const int original_id = idstruct->id; |
| 339 | int new_id = idstruct->id; |
| 340 | |
| 341 | if (original_id > max_allowed_id_ || original_id < min_allowed_id_) { |
| 342 | // If the original id is not in range - this is an id that can't be |
| 343 | // dynamically changed. |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | if (IsIdUsed(original_id)) { |
| 348 | new_id = FindUnusedId(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 349 | RTC_LOG(LS_WARNING) << "Duplicate id found. Reassigning from " |
| 350 | << original_id << " to " << new_id; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | idstruct->id = new_id; |
| 352 | } |
| 353 | SetIdUsed(new_id); |
| 354 | } |
| 355 | |
| 356 | private: |
| 357 | // Returns the first unused id in reverse order. |
| 358 | // This hopefully reduce the risk of more collisions. We want to change the |
| 359 | // default ids as little as possible. |
| 360 | int FindUnusedId() { |
| 361 | while (IsIdUsed(next_id_) && next_id_ >= min_allowed_id_) { |
| 362 | --next_id_; |
| 363 | } |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 364 | RTC_DCHECK(next_id_ >= min_allowed_id_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 365 | return next_id_; |
| 366 | } |
| 367 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 368 | bool IsIdUsed(int new_id) { return id_set_.find(new_id) != id_set_.end(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 369 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 370 | void SetIdUsed(int new_id) { id_set_.insert(new_id); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 371 | |
| 372 | const int min_allowed_id_; |
| 373 | const int max_allowed_id_; |
| 374 | int next_id_; |
| 375 | std::set<int> id_set_; |
| 376 | }; |
| 377 | |
| 378 | // Helper class used for finding duplicate RTP payload types among audio, video |
| 379 | // and data codecs. When bundle is used the payload types may not collide. |
| 380 | class UsedPayloadTypes : public UsedIds<Codec> { |
| 381 | public: |
| 382 | UsedPayloadTypes() |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 383 | : UsedIds<Codec>(kDynamicPayloadTypeMin, kDynamicPayloadTypeMax) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 384 | |
| 385 | private: |
| 386 | static const int kDynamicPayloadTypeMin = 96; |
| 387 | static const int kDynamicPayloadTypeMax = 127; |
| 388 | }; |
| 389 | |
| 390 | // Helper class used for finding duplicate RTP Header extension ids among |
Johannes Kron | 07ba2b9 | 2018-09-26 13:33:35 +0200 | [diff] [blame] | 391 | // audio and video extensions. Only applies to one-byte header extensions at the |
| 392 | // moment. ids > 14 will always be reported as available. |
| 393 | // TODO(kron): This class needs to be refactored when we start to send two-byte |
| 394 | // header extensions. |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 395 | class UsedRtpHeaderExtensionIds : public UsedIds<webrtc::RtpExtension> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 396 | public: |
| 397 | UsedRtpHeaderExtensionIds() |
Johannes Kron | 07ba2b9 | 2018-09-26 13:33:35 +0200 | [diff] [blame] | 398 | : UsedIds<webrtc::RtpExtension>( |
| 399 | webrtc::RtpExtension::kMinId, |
| 400 | webrtc::RtpExtension::kOneByteHeaderExtensionMaxId) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 401 | |
| 402 | private: |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 403 | }; |
| 404 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 405 | // Adds a StreamParams for each SenderOptions in |sender_options| to |
| 406 | // content_description. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 407 | // |current_params| - All currently known StreamParams of any media type. |
| 408 | template <class C> |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 409 | static bool AddStreamParams( |
| 410 | const std::vector<SenderOptions>& sender_options, |
| 411 | const std::string& rtcp_cname, |
| 412 | StreamParamsVec* current_streams, |
| 413 | MediaContentDescriptionImpl<C>* content_description) { |
Taylor Brandstetter | 1d7a637 | 2016-08-24 13:15:27 -0700 | [diff] [blame] | 414 | // SCTP streams are not negotiated using SDP/ContentDescriptions. |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 415 | if (IsSctp(content_description->protocol())) { |
Taylor Brandstetter | 1d7a637 | 2016-08-24 13:15:27 -0700 | [diff] [blame] | 416 | return true; |
| 417 | } |
| 418 | |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 419 | const bool include_rtx_streams = |
| 420 | ContainsRtxCodec(content_description->codecs()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 421 | |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 422 | const bool include_flexfec_stream = |
| 423 | ContainsFlexfecCodec(content_description->codecs()); |
| 424 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 425 | for (const SenderOptions& sender : sender_options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 426 | // groupid is empty for StreamParams generated using |
| 427 | // MediaSessionDescriptionFactory. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 428 | StreamParams* param = |
| 429 | GetStreamByIds(*current_streams, "" /*group_id*/, sender.track_id); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 430 | if (!param) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 431 | // This is a new sender. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 432 | std::vector<uint32_t> ssrcs; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 433 | GenerateSsrcs(*current_streams, sender.num_sim_layers, &ssrcs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 434 | StreamParams stream_param; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 435 | stream_param.id = sender.track_id; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 436 | // Add the generated ssrc. |
| 437 | for (size_t i = 0; i < ssrcs.size(); ++i) { |
| 438 | stream_param.ssrcs.push_back(ssrcs[i]); |
| 439 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 440 | if (sender.num_sim_layers > 1) { |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 441 | SsrcGroup group(kSimSsrcGroupSemantics, stream_param.ssrcs); |
| 442 | stream_param.ssrc_groups.push_back(group); |
| 443 | } |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 444 | // Generate extra ssrcs for include_rtx_streams case. |
| 445 | if (include_rtx_streams) { |
| 446 | // Generate an RTX ssrc for every ssrc in the group. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 447 | std::vector<uint32_t> rtx_ssrcs; |
Noah Richards | 2e7a098 | 2015-05-18 14:02:54 -0700 | [diff] [blame] | 448 | GenerateSsrcs(*current_streams, static_cast<int>(ssrcs.size()), |
| 449 | &rtx_ssrcs); |
| 450 | for (size_t i = 0; i < ssrcs.size(); ++i) { |
| 451 | stream_param.AddFidSsrc(ssrcs[i], rtx_ssrcs[i]); |
| 452 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 453 | } |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 454 | // Generate extra ssrc for include_flexfec_stream case. |
| 455 | if (include_flexfec_stream) { |
| 456 | // TODO(brandtr): Update when we support multistream protection. |
| 457 | if (ssrcs.size() == 1) { |
| 458 | std::vector<uint32_t> flexfec_ssrcs; |
| 459 | GenerateSsrcs(*current_streams, 1, &flexfec_ssrcs); |
| 460 | stream_param.AddFecFrSsrc(ssrcs[0], flexfec_ssrcs[0]); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 461 | } else if (!ssrcs.empty()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 462 | RTC_LOG(LS_WARNING) |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 463 | << "Our FlexFEC implementation only supports protecting " |
Jonas Olsson | 45cc890 | 2018-02-13 10:37:07 +0100 | [diff] [blame] | 464 | "a single media streams. This session has multiple " |
| 465 | "media streams however, so no FlexFEC SSRC will be generated."; |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 466 | } |
| 467 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 468 | stream_param.cname = rtcp_cname; |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 469 | stream_param.set_stream_ids(sender.stream_ids); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 470 | content_description->AddStream(stream_param); |
| 471 | |
| 472 | // Store the new StreamParams in current_streams. |
| 473 | // This is necessary so that we can use the CNAME for other media types. |
| 474 | current_streams->push_back(stream_param); |
| 475 | } else { |
deadbeef | 2f425aa | 2017-04-14 10:41:32 -0700 | [diff] [blame] | 476 | // Use existing generated SSRCs/groups, but update the sync_label if |
| 477 | // necessary. This may be needed if a MediaStreamTrack was moved from one |
| 478 | // MediaStream to another. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 479 | param->set_stream_ids(sender.stream_ids); |
tommi@webrtc.org | 586f2ed | 2015-01-22 23:00:41 +0000 | [diff] [blame] | 480 | content_description->AddStream(*param); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | return true; |
| 484 | } |
| 485 | |
| 486 | // Updates the transport infos of the |sdesc| according to the given |
| 487 | // |bundle_group|. The transport infos of the content names within the |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 488 | // |bundle_group| should be updated to use the ufrag, pwd and DTLS role of the |
| 489 | // first content within the |bundle_group|. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 490 | static bool UpdateTransportInfoForBundle(const ContentGroup& bundle_group, |
| 491 | SessionDescription* sdesc) { |
| 492 | // The bundle should not be empty. |
| 493 | if (!sdesc || !bundle_group.FirstContentName()) { |
| 494 | return false; |
| 495 | } |
| 496 | |
| 497 | // We should definitely have a transport for the first content. |
jbauch | 083b73f | 2015-07-16 02:46:32 -0700 | [diff] [blame] | 498 | const std::string& selected_content_name = *bundle_group.FirstContentName(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 499 | const TransportInfo* selected_transport_info = |
| 500 | sdesc->GetTransportInfoByName(selected_content_name); |
| 501 | if (!selected_transport_info) { |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | // Set the other contents to use the same ICE credentials. |
jbauch | 083b73f | 2015-07-16 02:46:32 -0700 | [diff] [blame] | 506 | const std::string& selected_ufrag = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 507 | selected_transport_info->description.ice_ufrag; |
jbauch | 083b73f | 2015-07-16 02:46:32 -0700 | [diff] [blame] | 508 | const std::string& selected_pwd = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | selected_transport_info->description.ice_pwd; |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 510 | ConnectionRole selected_connection_role = |
| 511 | selected_transport_info->description.connection_role; |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 512 | for (TransportInfo& transport_info : sdesc->transport_infos()) { |
| 513 | if (bundle_group.HasContentName(transport_info.content_name) && |
| 514 | transport_info.content_name != selected_content_name) { |
| 515 | transport_info.description.ice_ufrag = selected_ufrag; |
| 516 | transport_info.description.ice_pwd = selected_pwd; |
| 517 | transport_info.description.connection_role = selected_connection_role; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | return true; |
| 521 | } |
| 522 | |
| 523 | // Gets the CryptoParamsVec of the given |content_name| from |sdesc|, and |
| 524 | // sets it to |cryptos|. |
| 525 | static bool GetCryptosByName(const SessionDescription* sdesc, |
| 526 | const std::string& content_name, |
| 527 | CryptoParamsVec* cryptos) { |
| 528 | if (!sdesc || !cryptos) { |
| 529 | return false; |
| 530 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 531 | const ContentInfo* content = sdesc->GetContentByName(content_name); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 532 | if (!content || !content->media_description()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 533 | return false; |
| 534 | } |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 535 | *cryptos = content->media_description()->cryptos(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 536 | return true; |
| 537 | } |
| 538 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 539 | // Prunes the |target_cryptos| by removing the crypto params (cipher_suite) |
| 540 | // which are not available in |filter|. |
| 541 | static void PruneCryptos(const CryptoParamsVec& filter, |
| 542 | CryptoParamsVec* target_cryptos) { |
| 543 | if (!target_cryptos) { |
| 544 | return; |
| 545 | } |
tzik | 2199580 | 2018-04-26 17:38:28 +0900 | [diff] [blame] | 546 | |
| 547 | target_cryptos->erase( |
| 548 | std::remove_if(target_cryptos->begin(), target_cryptos->end(), |
| 549 | // Returns true if the |crypto|'s cipher_suite is not |
| 550 | // found in |filter|. |
| 551 | [&filter](const CryptoParams& crypto) { |
| 552 | for (const CryptoParams& entry : filter) { |
| 553 | if (entry.cipher_suite == crypto.cipher_suite) |
| 554 | return false; |
| 555 | } |
| 556 | return true; |
| 557 | }), |
| 558 | target_cryptos->end()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Steve Anton | fa2260d | 2017-12-28 16:38:23 -0800 | [diff] [blame] | 561 | bool IsRtpProtocol(const std::string& protocol) { |
deadbeef | b5cb19b | 2015-11-23 16:39:12 -0800 | [diff] [blame] | 562 | return protocol.empty() || |
| 563 | (protocol.find(cricket::kMediaProtocolRtpPrefix) != std::string::npos); |
| 564 | } |
| 565 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 566 | static bool IsRtpContent(SessionDescription* sdesc, |
| 567 | const std::string& content_name) { |
| 568 | bool is_rtp = false; |
| 569 | ContentInfo* content = sdesc->GetContentByName(content_name); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 570 | if (content && content->media_description()) { |
| 571 | is_rtp = IsRtpProtocol(content->media_description()->protocol()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 572 | } |
| 573 | return is_rtp; |
| 574 | } |
| 575 | |
| 576 | // Updates the crypto parameters of the |sdesc| according to the given |
| 577 | // |bundle_group|. The crypto parameters of all the contents within the |
| 578 | // |bundle_group| should be updated to use the common subset of the |
| 579 | // available cryptos. |
| 580 | static bool UpdateCryptoParamsForBundle(const ContentGroup& bundle_group, |
| 581 | SessionDescription* sdesc) { |
| 582 | // The bundle should not be empty. |
| 583 | if (!sdesc || !bundle_group.FirstContentName()) { |
| 584 | return false; |
| 585 | } |
| 586 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 587 | bool common_cryptos_needed = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 588 | // Get the common cryptos. |
| 589 | const ContentNames& content_names = bundle_group.content_names(); |
| 590 | CryptoParamsVec common_cryptos; |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 591 | bool first = true; |
| 592 | for (const std::string& content_name : content_names) { |
| 593 | if (!IsRtpContent(sdesc, content_name)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 594 | continue; |
| 595 | } |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 596 | // The common cryptos are needed if any of the content does not have DTLS |
| 597 | // enabled. |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 598 | if (!sdesc->GetTransportInfoByName(content_name)->description.secure()) { |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 599 | common_cryptos_needed = true; |
| 600 | } |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 601 | if (first) { |
| 602 | first = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 603 | // Initial the common_cryptos with the first content in the bundle group. |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 604 | if (!GetCryptosByName(sdesc, content_name, &common_cryptos)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 605 | return false; |
| 606 | } |
| 607 | if (common_cryptos.empty()) { |
| 608 | // If there's no crypto params, we should just return. |
| 609 | return true; |
| 610 | } |
| 611 | } else { |
| 612 | CryptoParamsVec cryptos; |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 613 | if (!GetCryptosByName(sdesc, content_name, &cryptos)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 614 | return false; |
| 615 | } |
| 616 | PruneCryptos(cryptos, &common_cryptos); |
| 617 | } |
| 618 | } |
| 619 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 620 | if (common_cryptos.empty() && common_cryptos_needed) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 621 | return false; |
| 622 | } |
| 623 | |
| 624 | // Update to use the common cryptos. |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 625 | for (const std::string& content_name : content_names) { |
| 626 | if (!IsRtpContent(sdesc, content_name)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 627 | continue; |
| 628 | } |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 629 | ContentInfo* content = sdesc->GetContentByName(content_name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 630 | if (IsMediaContent(content)) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 631 | MediaContentDescription* media_desc = content->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 632 | if (!media_desc) { |
| 633 | return false; |
| 634 | } |
| 635 | media_desc->set_cryptos(common_cryptos); |
| 636 | } |
| 637 | } |
| 638 | return true; |
| 639 | } |
| 640 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 641 | static std::vector<const ContentInfo*> GetActiveContents( |
| 642 | const SessionDescription& description, |
| 643 | const MediaSessionOptions& session_options) { |
| 644 | std::vector<const ContentInfo*> active_contents; |
| 645 | for (size_t i = 0; i < description.contents().size(); ++i) { |
| 646 | RTC_DCHECK_LT(i, session_options.media_description_options.size()); |
| 647 | const ContentInfo& content = description.contents()[i]; |
| 648 | const MediaDescriptionOptions& media_options = |
| 649 | session_options.media_description_options[i]; |
| 650 | if (!content.rejected && !media_options.stopped && |
| 651 | content.name == media_options.mid) { |
| 652 | active_contents.push_back(&content); |
| 653 | } |
| 654 | } |
| 655 | return active_contents; |
| 656 | } |
| 657 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 658 | template <class C> |
| 659 | static bool ContainsRtxCodec(const std::vector<C>& codecs) { |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 660 | for (const auto& codec : codecs) { |
| 661 | if (IsRtxCodec(codec)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 662 | return true; |
| 663 | } |
| 664 | } |
| 665 | return false; |
| 666 | } |
| 667 | |
| 668 | template <class C> |
| 669 | static bool IsRtxCodec(const C& codec) { |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 670 | return absl::EqualsIgnoreCase(codec.name, kRtxCodecName); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 671 | } |
| 672 | |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 673 | template <class C> |
| 674 | static bool ContainsFlexfecCodec(const std::vector<C>& codecs) { |
| 675 | for (const auto& codec : codecs) { |
| 676 | if (IsFlexfecCodec(codec)) { |
| 677 | return true; |
| 678 | } |
| 679 | } |
| 680 | return false; |
| 681 | } |
| 682 | |
| 683 | template <class C> |
| 684 | static bool IsFlexfecCodec(const C& codec) { |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 685 | return absl::EqualsIgnoreCase(codec.name, kFlexfecCodecName); |
brandtr | 03d5fb1 | 2016-11-22 03:37:59 -0800 | [diff] [blame] | 686 | } |
| 687 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 688 | // Create a media content to be offered for the given |sender_options|, |
| 689 | // according to the given options.rtcp_mux, session_options.is_muc, codecs, |
| 690 | // secure_transport, crypto, and current_streams. If we don't currently have |
| 691 | // crypto (in current_cryptos) and it is enabled (in secure_policy), crypto is |
| 692 | // created (according to crypto_suites). The created content is added to the |
| 693 | // offer. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 694 | template <class C> |
| 695 | static bool CreateMediaContentOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 696 | const std::vector<SenderOptions>& sender_options, |
| 697 | const MediaSessionOptions& session_options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 698 | const std::vector<C>& codecs, |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 699 | const SecurePolicy& secure_policy, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 700 | const CryptoParamsVec* current_cryptos, |
| 701 | const std::vector<std::string>& crypto_suites, |
| 702 | const RtpHeaderExtensions& rtp_extensions, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 703 | StreamParamsVec* current_streams, |
| 704 | MediaContentDescriptionImpl<C>* offer) { |
| 705 | offer->AddCodecs(codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 706 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 707 | offer->set_rtcp_mux(session_options.rtcp_mux_enabled); |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 708 | if (offer->type() == cricket::MEDIA_TYPE_VIDEO) { |
| 709 | offer->set_rtcp_reduced_size(true); |
| 710 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 711 | offer->set_rtp_header_extensions(rtp_extensions); |
| 712 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 713 | if (!AddStreamParams(sender_options, session_options.rtcp_cname, |
| 714 | current_streams, offer)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 715 | return false; |
| 716 | } |
| 717 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 718 | if (secure_policy != SEC_DISABLED) { |
| 719 | if (current_cryptos) { |
| 720 | AddMediaCryptos(*current_cryptos, offer); |
| 721 | } |
| 722 | if (offer->cryptos().empty()) { |
| 723 | if (!CreateMediaCryptos(crypto_suites, offer)) { |
| 724 | return false; |
| 725 | } |
| 726 | } |
| 727 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 728 | |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 729 | if (secure_policy == SEC_REQUIRED && offer->cryptos().empty()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 730 | return false; |
| 731 | } |
| 732 | return true; |
| 733 | } |
| 734 | |
| 735 | template <class C> |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 736 | static bool ReferencedCodecsMatch(const std::vector<C>& codecs1, |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 737 | const int codec1_id, |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 738 | const std::vector<C>& codecs2, |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 739 | const int codec2_id) { |
| 740 | const C* codec1 = FindCodecById(codecs1, codec1_id); |
| 741 | const C* codec2 = FindCodecById(codecs2, codec2_id); |
| 742 | return codec1 != nullptr && codec2 != nullptr && codec1->Matches(*codec2); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | template <class C> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 746 | static void NegotiateCodecs(const std::vector<C>& local_codecs, |
| 747 | const std::vector<C>& offered_codecs, |
| 748 | std::vector<C>* negotiated_codecs) { |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 749 | for (const C& ours : local_codecs) { |
| 750 | C theirs; |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 751 | // Note that we intentionally only find one matching codec for each of our |
| 752 | // local codecs, in case the remote offer contains duplicate codecs. |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 753 | if (FindMatchingCodec(local_codecs, offered_codecs, ours, &theirs)) { |
| 754 | C negotiated = ours; |
| 755 | negotiated.IntersectFeedbackParams(theirs); |
| 756 | if (IsRtxCodec(negotiated)) { |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 757 | const auto apt_it = |
| 758 | theirs.params.find(kCodecParamAssociatedPayloadType); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 759 | // FindMatchingCodec shouldn't return something with no apt value. |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 760 | RTC_DCHECK(apt_it != theirs.params.end()); |
| 761 | negotiated.SetParam(kCodecParamAssociatedPayloadType, apt_it->second); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 762 | } |
Niels Möller | 039743e | 2018-10-23 10:07:25 +0200 | [diff] [blame] | 763 | if (absl::EqualsIgnoreCase(ours.name, kH264CodecName)) { |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 764 | webrtc::H264::GenerateProfileLevelIdForAnswer( |
| 765 | ours.params, theirs.params, &negotiated.params); |
| 766 | } |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 767 | negotiated.id = theirs.id; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 768 | negotiated.name = theirs.name; |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 769 | negotiated_codecs->push_back(std::move(negotiated)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 770 | } |
| 771 | } |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 772 | // RFC3264: Although the answerer MAY list the formats in their desired |
| 773 | // order of preference, it is RECOMMENDED that unless there is a |
| 774 | // specific reason, the answerer list formats in the same relative order |
| 775 | // they were present in the offer. |
| 776 | std::unordered_map<int, int> payload_type_preferences; |
| 777 | int preference = static_cast<int>(offered_codecs.size() + 1); |
| 778 | for (const C& codec : offered_codecs) { |
| 779 | payload_type_preferences[codec.id] = preference--; |
| 780 | } |
| 781 | std::sort(negotiated_codecs->begin(), negotiated_codecs->end(), |
| 782 | [&payload_type_preferences](const C& a, const C& b) { |
| 783 | return payload_type_preferences[a.id] > |
| 784 | payload_type_preferences[b.id]; |
| 785 | }); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 788 | // Finds a codec in |codecs2| that matches |codec_to_match|, which is |
| 789 | // a member of |codecs1|. If |codec_to_match| is an RTX codec, both |
| 790 | // the codecs themselves and their associated codecs must match. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 791 | template <class C> |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 792 | static bool FindMatchingCodec(const std::vector<C>& codecs1, |
| 793 | const std::vector<C>& codecs2, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 794 | const C& codec_to_match, |
| 795 | C* found_codec) { |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 796 | // |codec_to_match| should be a member of |codecs1|, in order to look up RTX |
| 797 | // codecs' associated codecs correctly. If not, that's a programming error. |
| 798 | RTC_DCHECK(std::find_if(codecs1.begin(), codecs1.end(), |
| 799 | [&codec_to_match](const C& codec) { |
| 800 | return &codec == &codec_to_match; |
| 801 | }) != codecs1.end()); |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 802 | for (const C& potential_match : codecs2) { |
| 803 | if (potential_match.Matches(codec_to_match)) { |
| 804 | if (IsRtxCodec(codec_to_match)) { |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 805 | int apt_value_1 = 0; |
| 806 | int apt_value_2 = 0; |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 807 | if (!codec_to_match.GetParam(kCodecParamAssociatedPayloadType, |
| 808 | &apt_value_1) || |
| 809 | !potential_match.GetParam(kCodecParamAssociatedPayloadType, |
| 810 | &apt_value_2)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 811 | RTC_LOG(LS_WARNING) << "RTX missing associated payload type."; |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 812 | continue; |
| 813 | } |
| 814 | if (!ReferencedCodecsMatch(codecs1, apt_value_1, codecs2, |
| 815 | apt_value_2)) { |
| 816 | continue; |
| 817 | } |
| 818 | } |
| 819 | if (found_codec) { |
| 820 | *found_codec = potential_match; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 821 | } |
| 822 | return true; |
| 823 | } |
| 824 | } |
| 825 | return false; |
| 826 | } |
| 827 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 828 | // Find the codec in |codec_list| that |rtx_codec| is associated with. |
| 829 | template <class C> |
| 830 | static const C* GetAssociatedCodec(const std::vector<C>& codec_list, |
| 831 | const C& rtx_codec) { |
| 832 | std::string associated_pt_str; |
| 833 | if (!rtx_codec.GetParam(kCodecParamAssociatedPayloadType, |
| 834 | &associated_pt_str)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 835 | RTC_LOG(LS_WARNING) << "RTX codec " << rtx_codec.name |
| 836 | << " is missing an associated payload type."; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 837 | return nullptr; |
| 838 | } |
| 839 | |
| 840 | int associated_pt; |
| 841 | if (!rtc::FromString(associated_pt_str, &associated_pt)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 842 | RTC_LOG(LS_WARNING) << "Couldn't convert payload type " << associated_pt_str |
| 843 | << " of RTX codec " << rtx_codec.name |
| 844 | << " to an integer."; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 845 | return nullptr; |
| 846 | } |
| 847 | |
| 848 | // Find the associated reference codec for the reference RTX codec. |
| 849 | const C* associated_codec = FindCodecById(codec_list, associated_pt); |
| 850 | if (!associated_codec) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 851 | RTC_LOG(LS_WARNING) << "Couldn't find associated codec with payload type " |
| 852 | << associated_pt << " for RTX codec " << rtx_codec.name |
| 853 | << "."; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 854 | } |
| 855 | return associated_codec; |
| 856 | } |
| 857 | |
| 858 | // Adds all codecs from |reference_codecs| to |offered_codecs| that don't |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 859 | // already exist in |offered_codecs| and ensure the payload types don't |
| 860 | // collide. |
| 861 | template <class C> |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 862 | static void MergeCodecs(const std::vector<C>& reference_codecs, |
| 863 | std::vector<C>* offered_codecs, |
| 864 | UsedPayloadTypes* used_pltypes) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 865 | // Add all new codecs that are not RTX codecs. |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 866 | for (const C& reference_codec : reference_codecs) { |
| 867 | if (!IsRtxCodec(reference_codec) && |
| 868 | !FindMatchingCodec<C>(reference_codecs, *offered_codecs, |
| 869 | reference_codec, nullptr)) { |
| 870 | C codec = reference_codec; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 871 | used_pltypes->FindAndSetIdUsed(&codec); |
| 872 | offered_codecs->push_back(codec); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
| 875 | |
| 876 | // Add all new RTX codecs. |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 877 | for (const C& reference_codec : reference_codecs) { |
| 878 | if (IsRtxCodec(reference_codec) && |
| 879 | !FindMatchingCodec<C>(reference_codecs, *offered_codecs, |
| 880 | reference_codec, nullptr)) { |
| 881 | C rtx_codec = reference_codec; |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 882 | const C* associated_codec = |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 883 | GetAssociatedCodec(reference_codecs, rtx_codec); |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 884 | if (!associated_codec) { |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 885 | continue; |
| 886 | } |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 887 | // Find a codec in the offered list that matches the reference codec. |
| 888 | // Its payload type may be different than the reference codec. |
| 889 | C matching_codec; |
| 890 | if (!FindMatchingCodec<C>(reference_codecs, *offered_codecs, |
magjed | b05fa24 | 2016-11-11 04:00:16 -0800 | [diff] [blame] | 891 | *associated_codec, &matching_codec)) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 892 | RTC_LOG(LS_WARNING) |
| 893 | << "Couldn't find matching " << associated_codec->name << " codec."; |
Taylor Brandstetter | 6ec641b | 2016-03-04 16:47:56 -0800 | [diff] [blame] | 894 | continue; |
| 895 | } |
| 896 | |
| 897 | rtx_codec.params[kCodecParamAssociatedPayloadType] = |
| 898 | rtc::ToString(matching_codec.id); |
| 899 | used_pltypes->FindAndSetIdUsed(&rtx_codec); |
| 900 | offered_codecs->push_back(rtx_codec); |
| 901 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 905 | static bool FindByUriAndEncryption(const RtpHeaderExtensions& extensions, |
| 906 | const webrtc::RtpExtension& ext_to_match, |
| 907 | webrtc::RtpExtension* found_extension) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 908 | auto it = |
| 909 | std::find_if(extensions.begin(), extensions.end(), |
| 910 | [&ext_to_match](const webrtc::RtpExtension& extension) { |
| 911 | // We assume that all URIs are given in a canonical |
| 912 | // format. |
| 913 | return extension.uri == ext_to_match.uri && |
| 914 | extension.encrypt == ext_to_match.encrypt; |
| 915 | }); |
| 916 | if (it == extensions.end()) { |
| 917 | return false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 918 | } |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 919 | if (found_extension) { |
| 920 | *found_extension = *it; |
| 921 | } |
| 922 | return true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 923 | } |
| 924 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 925 | static bool FindByUri(const RtpHeaderExtensions& extensions, |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 926 | const webrtc::RtpExtension& ext_to_match, |
| 927 | webrtc::RtpExtension* found_extension) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 928 | // We assume that all URIs are given in a canonical format. |
| 929 | const webrtc::RtpExtension* found = |
| 930 | webrtc::RtpExtension::FindHeaderExtensionByUri(extensions, |
| 931 | ext_to_match.uri); |
| 932 | if (!found) { |
| 933 | return false; |
| 934 | } |
| 935 | if (found_extension) { |
| 936 | *found_extension = *found; |
| 937 | } |
| 938 | return true; |
| 939 | } |
| 940 | |
| 941 | static bool FindByUriWithEncryptionPreference( |
| 942 | const RtpHeaderExtensions& extensions, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 943 | const webrtc::RtpExtension& ext_to_match, |
| 944 | bool encryption_preference, |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 945 | webrtc::RtpExtension* found_extension) { |
| 946 | const webrtc::RtpExtension* unencrypted_extension = nullptr; |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 947 | for (const webrtc::RtpExtension& extension : extensions) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 948 | // We assume that all URIs are given in a canonical format. |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 949 | if (extension.uri == ext_to_match.uri) { |
| 950 | if (!encryption_preference || extension.encrypt) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 951 | if (found_extension) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 952 | *found_extension = extension; |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 953 | } |
| 954 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 955 | } |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 956 | unencrypted_extension = &extension; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 957 | } |
| 958 | } |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 959 | if (unencrypted_extension) { |
| 960 | if (found_extension) { |
| 961 | *found_extension = *unencrypted_extension; |
| 962 | } |
| 963 | return true; |
| 964 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 965 | return false; |
| 966 | } |
| 967 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 968 | // Adds all extensions from |reference_extensions| to |offered_extensions| that |
| 969 | // don't already exist in |offered_extensions| and ensure the IDs don't |
| 970 | // collide. If an extension is added, it's also added to |regular_extensions| or |
| 971 | // |encrypted_extensions|, and if the extension is in |regular_extensions| or |
| 972 | // |encrypted_extensions|, its ID is marked as used in |used_ids|. |
| 973 | // |offered_extensions| is for either audio or video while |regular_extensions| |
| 974 | // and |encrypted_extensions| are used for both audio and video. There could be |
| 975 | // overlap between audio extensions and video extensions. |
| 976 | static void MergeRtpHdrExts(const RtpHeaderExtensions& reference_extensions, |
| 977 | RtpHeaderExtensions* offered_extensions, |
| 978 | RtpHeaderExtensions* regular_extensions, |
| 979 | RtpHeaderExtensions* encrypted_extensions, |
| 980 | UsedRtpHeaderExtensionIds* used_ids) { |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 981 | for (auto reference_extension : reference_extensions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 982 | if (!FindByUriAndEncryption(*offered_extensions, reference_extension, |
| 983 | nullptr)) { |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 984 | webrtc::RtpExtension existing; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 985 | if (reference_extension.encrypt) { |
| 986 | if (FindByUriAndEncryption(*encrypted_extensions, reference_extension, |
| 987 | &existing)) { |
| 988 | offered_extensions->push_back(existing); |
| 989 | } else { |
| 990 | used_ids->FindAndSetIdUsed(&reference_extension); |
| 991 | encrypted_extensions->push_back(reference_extension); |
| 992 | offered_extensions->push_back(reference_extension); |
| 993 | } |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 994 | } else { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 995 | if (FindByUriAndEncryption(*regular_extensions, reference_extension, |
| 996 | &existing)) { |
| 997 | offered_extensions->push_back(existing); |
| 998 | } else { |
| 999 | used_ids->FindAndSetIdUsed(&reference_extension); |
| 1000 | regular_extensions->push_back(reference_extension); |
| 1001 | offered_extensions->push_back(reference_extension); |
| 1002 | } |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 1003 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1008 | static void AddEncryptedVersionsOfHdrExts(RtpHeaderExtensions* extensions, |
| 1009 | RtpHeaderExtensions* all_extensions, |
| 1010 | UsedRtpHeaderExtensionIds* used_ids) { |
| 1011 | RtpHeaderExtensions encrypted_extensions; |
| 1012 | for (const webrtc::RtpExtension& extension : *extensions) { |
| 1013 | webrtc::RtpExtension existing; |
| 1014 | // Don't add encrypted extensions again that were already included in a |
| 1015 | // previous offer or regular extensions that are also included as encrypted |
| 1016 | // extensions. |
| 1017 | if (extension.encrypt || |
| 1018 | !webrtc::RtpExtension::IsEncryptionSupported(extension.uri) || |
| 1019 | (FindByUriWithEncryptionPreference(*extensions, extension, true, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1020 | &existing) && |
| 1021 | existing.encrypt)) { |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1022 | continue; |
| 1023 | } |
| 1024 | |
| 1025 | if (FindByUri(*all_extensions, extension, &existing)) { |
| 1026 | encrypted_extensions.push_back(existing); |
| 1027 | } else { |
| 1028 | webrtc::RtpExtension encrypted(extension); |
| 1029 | encrypted.encrypt = true; |
| 1030 | used_ids->FindAndSetIdUsed(&encrypted); |
| 1031 | all_extensions->push_back(encrypted); |
| 1032 | encrypted_extensions.push_back(encrypted); |
| 1033 | } |
| 1034 | } |
| 1035 | extensions->insert(extensions->end(), encrypted_extensions.begin(), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1036 | encrypted_extensions.end()); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1039 | static void NegotiateRtpHeaderExtensions( |
| 1040 | const RtpHeaderExtensions& local_extensions, |
| 1041 | const RtpHeaderExtensions& offered_extensions, |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1042 | bool enable_encrypted_rtp_header_extensions, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1043 | RtpHeaderExtensions* negotiated_extenstions) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 1044 | for (const webrtc::RtpExtension& ours : local_extensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1045 | webrtc::RtpExtension theirs; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1046 | if (FindByUriWithEncryptionPreference( |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 1047 | offered_extensions, ours, enable_encrypted_rtp_header_extensions, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1048 | &theirs)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1049 | // We respond with their RTP header extension id. |
| 1050 | negotiated_extenstions->push_back(theirs); |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | static void StripCNCodecs(AudioCodecs* audio_codecs) { |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 1056 | audio_codecs->erase(std::remove_if(audio_codecs->begin(), audio_codecs->end(), |
| 1057 | [](const AudioCodec& codec) { |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 1058 | return absl::EqualsIgnoreCase( |
| 1059 | codec.name, kComfortNoiseCodecName); |
Steve Anton | 3a66edf | 2018-09-10 12:57:37 -0700 | [diff] [blame] | 1060 | }), |
| 1061 | audio_codecs->end()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1064 | // Create a media content to be answered for the given |sender_options| |
| 1065 | // according to the given session_options.rtcp_mux, session_options.streams, |
| 1066 | // codecs, crypto, and current_streams. If we don't currently have crypto (in |
| 1067 | // current_cryptos) and it is enabled (in secure_policy), crypto is created |
| 1068 | // (according to crypto_suites). The codecs, rtcp_mux, and crypto are all |
| 1069 | // negotiated with the offer. If the negotiation fails, this method returns |
| 1070 | // false. The created content is added to the offer. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1071 | template <class C> |
| 1072 | static bool CreateMediaContentAnswer( |
| 1073 | const MediaContentDescriptionImpl<C>* offer, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1074 | const MediaDescriptionOptions& media_description_options, |
| 1075 | const MediaSessionOptions& session_options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1076 | const std::vector<C>& local_codecs, |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1077 | const SecurePolicy& sdes_policy, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1078 | const CryptoParamsVec* current_cryptos, |
| 1079 | const RtpHeaderExtensions& local_rtp_extenstions, |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1080 | bool enable_encrypted_rtp_header_extensions, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1081 | StreamParamsVec* current_streams, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1082 | bool bundle_enabled, |
| 1083 | MediaContentDescriptionImpl<C>* answer) { |
| 1084 | std::vector<C> negotiated_codecs; |
| 1085 | NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs); |
| 1086 | answer->AddCodecs(negotiated_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1087 | answer->set_protocol(offer->protocol()); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1088 | |
Johannes Kron | 9581bc4 | 2018-10-23 10:17:39 +0200 | [diff] [blame] | 1089 | answer->set_extmap_allow_mixed_enum(offer->extmap_allow_mixed_enum()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1090 | RtpHeaderExtensions negotiated_rtp_extensions; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1091 | NegotiateRtpHeaderExtensions( |
| 1092 | local_rtp_extenstions, offer->rtp_header_extensions(), |
| 1093 | enable_encrypted_rtp_header_extensions, &negotiated_rtp_extensions); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1094 | answer->set_rtp_header_extensions(negotiated_rtp_extensions); |
| 1095 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1096 | answer->set_rtcp_mux(session_options.rtcp_mux_enabled && offer->rtcp_mux()); |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 1097 | if (answer->type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1098 | answer->set_rtcp_reduced_size(offer->rtcp_reduced_size()); |
| 1099 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1100 | |
| 1101 | if (sdes_policy != SEC_DISABLED) { |
| 1102 | CryptoParams crypto; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1103 | if (SelectCrypto(offer, bundle_enabled, session_options.crypto_options, |
| 1104 | &crypto)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1105 | if (current_cryptos) { |
| 1106 | FindMatchingCrypto(*current_cryptos, crypto, &crypto); |
| 1107 | } |
| 1108 | answer->AddCrypto(crypto); |
| 1109 | } |
| 1110 | } |
| 1111 | |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 1112 | if (answer->cryptos().empty() && sdes_policy == SEC_REQUIRED) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1113 | return false; |
| 1114 | } |
| 1115 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1116 | if (!AddStreamParams(media_description_options.sender_options, |
| 1117 | session_options.rtcp_cname, current_streams, answer)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1118 | return false; // Something went seriously wrong. |
| 1119 | } |
| 1120 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1121 | answer->set_direction(NegotiateRtpTransceiverDirection( |
| 1122 | offer->direction(), media_description_options.direction)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1123 | return true; |
| 1124 | } |
| 1125 | |
| 1126 | static bool IsMediaProtocolSupported(MediaType type, |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 1127 | const std::string& protocol, |
| 1128 | bool secure_transport) { |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 1129 | // Since not all applications serialize and deserialize the media protocol, |
| 1130 | // we will have to accept |protocol| to be empty. |
| 1131 | if (protocol.empty()) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1132 | return true; |
| 1133 | } |
jiayl@webrtc.org | 8dcd43c | 2014-05-29 22:07:59 +0000 | [diff] [blame] | 1134 | |
zhihuang | cf5b37c | 2016-05-05 11:44:35 -0700 | [diff] [blame] | 1135 | if (type == MEDIA_TYPE_DATA) { |
| 1136 | // Check for SCTP, but also for RTP for RTP-based data channels. |
| 1137 | // TODO(pthatcher): Remove RTP once RTP-based data channels are gone. |
| 1138 | if (secure_transport) { |
| 1139 | // Most likely scenarios first. |
| 1140 | return IsDtlsSctp(protocol) || IsDtlsRtp(protocol) || |
| 1141 | IsPlainRtp(protocol); |
| 1142 | } else { |
| 1143 | return IsPlainSctp(protocol) || IsPlainRtp(protocol); |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | // Allow for non-DTLS RTP protocol even when using DTLS because that's what |
| 1148 | // JSEP specifies. |
| 1149 | if (secure_transport) { |
| 1150 | // Most likely scenarios first. |
| 1151 | return IsDtlsRtp(protocol) || IsPlainRtp(protocol); |
| 1152 | } else { |
| 1153 | return IsPlainRtp(protocol); |
| 1154 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | static void SetMediaProtocol(bool secure_transport, |
| 1158 | MediaContentDescription* desc) { |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 1159 | if (!desc->cryptos().empty()) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1160 | desc->set_protocol(kMediaProtocolSavpf); |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 1161 | else if (secure_transport) |
| 1162 | desc->set_protocol(kMediaProtocolDtlsSavpf); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1163 | else |
| 1164 | desc->set_protocol(kMediaProtocolAvpf); |
| 1165 | } |
| 1166 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1167 | // Gets the TransportInfo of the given |content_name| from the |
| 1168 | // |current_description|. If doesn't exist, returns a new one. |
| 1169 | static const TransportDescription* GetTransportDescription( |
| 1170 | const std::string& content_name, |
| 1171 | const SessionDescription* current_description) { |
| 1172 | const TransportDescription* desc = NULL; |
| 1173 | if (current_description) { |
| 1174 | const TransportInfo* info = |
| 1175 | current_description->GetTransportInfoByName(content_name); |
| 1176 | if (info) { |
| 1177 | desc = &info->description; |
| 1178 | } |
| 1179 | } |
| 1180 | return desc; |
| 1181 | } |
| 1182 | |
| 1183 | // Gets the current DTLS state from the transport description. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1184 | static bool IsDtlsActive(const ContentInfo* content, |
| 1185 | const SessionDescription* current_description) { |
| 1186 | if (!content) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1187 | return false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1188 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1189 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1190 | size_t msection_index = content - ¤t_description->contents()[0]; |
| 1191 | |
| 1192 | if (current_description->transport_infos().size() <= msection_index) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1193 | return false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1194 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1195 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1196 | return current_description->transport_infos()[msection_index] |
| 1197 | .description.secure(); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 1200 | void MediaDescriptionOptions::AddAudioSender( |
| 1201 | const std::string& track_id, |
| 1202 | const std::vector<std::string>& stream_ids) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1203 | RTC_DCHECK(type == MEDIA_TYPE_AUDIO); |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 1204 | AddSenderInternal(track_id, stream_ids, 1); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 1207 | void MediaDescriptionOptions::AddVideoSender( |
| 1208 | const std::string& track_id, |
| 1209 | const std::vector<std::string>& stream_ids, |
| 1210 | int num_sim_layers) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1211 | RTC_DCHECK(type == MEDIA_TYPE_VIDEO); |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 1212 | AddSenderInternal(track_id, stream_ids, num_sim_layers); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1215 | void MediaDescriptionOptions::AddRtpDataChannel(const std::string& track_id, |
| 1216 | const std::string& stream_id) { |
| 1217 | RTC_DCHECK(type == MEDIA_TYPE_DATA); |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 1218 | // TODO(steveanton): Is it the case that RtpDataChannel will never have more |
| 1219 | // than one stream? |
| 1220 | AddSenderInternal(track_id, {stream_id}, 1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 1223 | void MediaDescriptionOptions::AddSenderInternal( |
| 1224 | const std::string& track_id, |
| 1225 | const std::vector<std::string>& stream_ids, |
| 1226 | int num_sim_layers) { |
| 1227 | // TODO(steveanton): Support any number of stream ids. |
| 1228 | RTC_CHECK(stream_ids.size() == 1U); |
| 1229 | sender_options.push_back(SenderOptions{track_id, stream_ids, num_sim_layers}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1232 | bool MediaSessionOptions::HasMediaDescription(MediaType type) const { |
| 1233 | return std::find_if(media_description_options.begin(), |
| 1234 | media_description_options.end(), |
| 1235 | [type](const MediaDescriptionOptions& t) { |
| 1236 | return t.type == type; |
| 1237 | }) != media_description_options.end(); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1238 | } |
| 1239 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1240 | MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
| 1241 | const TransportDescriptionFactory* transport_desc_factory) |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1242 | : transport_desc_factory_(transport_desc_factory) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1243 | |
| 1244 | MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
| 1245 | ChannelManager* channel_manager, |
| 1246 | const TransportDescriptionFactory* transport_desc_factory) |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1247 | : transport_desc_factory_(transport_desc_factory) { |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 1248 | channel_manager->GetSupportedAudioSendCodecs(&audio_send_codecs_); |
| 1249 | channel_manager->GetSupportedAudioReceiveCodecs(&audio_recv_codecs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1250 | channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); |
magjed | 3cf8ece | 2016-11-10 03:36:53 -0800 | [diff] [blame] | 1251 | channel_manager->GetSupportedVideoCodecs(&video_codecs_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1252 | channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); |
| 1253 | channel_manager->GetSupportedDataCodecs(&data_codecs_); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1254 | ComputeAudioCodecsIntersectionAndUnion(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 1257 | const AudioCodecs& MediaSessionDescriptionFactory::audio_sendrecv_codecs() |
| 1258 | const { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1259 | return audio_sendrecv_codecs_; |
| 1260 | } |
| 1261 | |
| 1262 | const AudioCodecs& MediaSessionDescriptionFactory::audio_send_codecs() const { |
| 1263 | return audio_send_codecs_; |
| 1264 | } |
| 1265 | |
| 1266 | const AudioCodecs& MediaSessionDescriptionFactory::audio_recv_codecs() const { |
| 1267 | return audio_recv_codecs_; |
| 1268 | } |
| 1269 | |
| 1270 | void MediaSessionDescriptionFactory::set_audio_codecs( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1271 | const AudioCodecs& send_codecs, |
| 1272 | const AudioCodecs& recv_codecs) { |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1273 | audio_send_codecs_ = send_codecs; |
| 1274 | audio_recv_codecs_ = recv_codecs; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1275 | ComputeAudioCodecsIntersectionAndUnion(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | SessionDescription* MediaSessionDescriptionFactory::CreateOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1279 | const MediaSessionOptions& session_options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1280 | const SessionDescription* current_description) const { |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1281 | // Must have options for each existing section. |
| 1282 | if (current_description) { |
| 1283 | RTC_DCHECK_LE(current_description->contents().size(), |
| 1284 | session_options.media_description_options.size()); |
| 1285 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1286 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1287 | IceCredentialsIterator ice_credentials( |
| 1288 | session_options.pooled_ice_credentials); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1289 | |
| 1290 | std::vector<const ContentInfo*> current_active_contents; |
| 1291 | if (current_description) { |
| 1292 | current_active_contents = |
| 1293 | GetActiveContents(*current_description, session_options); |
| 1294 | } |
| 1295 | |
| 1296 | StreamParamsVec current_streams = |
| 1297 | GetCurrentStreamParams(current_active_contents); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1298 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1299 | AudioCodecs offer_audio_codecs; |
| 1300 | VideoCodecs offer_video_codecs; |
| 1301 | DataCodecs offer_data_codecs; |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1302 | GetCodecsForOffer(current_active_contents, &offer_audio_codecs, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1303 | &offer_video_codecs, &offer_data_codecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1304 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1305 | if (!session_options.vad_enabled) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1306 | // If application doesn't want CN codecs in offer. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1307 | StripCNCodecs(&offer_audio_codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1308 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1309 | FilterDataCodecs(&offer_data_codecs, |
| 1310 | session_options.data_channel_type == DCT_SCTP); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1311 | |
| 1312 | RtpHeaderExtensions audio_rtp_extensions; |
| 1313 | RtpHeaderExtensions video_rtp_extensions; |
Steve Anton | 8f66ddb | 2018-12-10 16:08:05 -0800 | [diff] [blame^] | 1314 | GetRtpHdrExtsToOffer(current_active_contents, &audio_rtp_extensions, |
| 1315 | &video_rtp_extensions); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1316 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1317 | auto offer = absl::make_unique<SessionDescription>(); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1318 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1319 | // Iterate through the media description options, matching with existing media |
| 1320 | // descriptions in |current_description|. |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 1321 | size_t msection_index = 0; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1322 | for (const MediaDescriptionOptions& media_description_options : |
| 1323 | session_options.media_description_options) { |
| 1324 | const ContentInfo* current_content = nullptr; |
| 1325 | if (current_description && |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 1326 | msection_index < current_description->contents().size()) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1327 | current_content = ¤t_description->contents()[msection_index]; |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 1328 | // Media type must match unless this media section is being recycled. |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1329 | RTC_DCHECK(current_content->name != media_description_options.mid || |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 1330 | IsMediaContentOfType(current_content, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1331 | media_description_options.type)); |
| 1332 | } |
| 1333 | switch (media_description_options.type) { |
| 1334 | case MEDIA_TYPE_AUDIO: |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1335 | if (!AddAudioContentForOffer( |
| 1336 | media_description_options, session_options, current_content, |
| 1337 | current_description, audio_rtp_extensions, offer_audio_codecs, |
| 1338 | ¤t_streams, offer.get(), &ice_credentials)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1339 | return nullptr; |
| 1340 | } |
| 1341 | break; |
| 1342 | case MEDIA_TYPE_VIDEO: |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1343 | if (!AddVideoContentForOffer( |
| 1344 | media_description_options, session_options, current_content, |
| 1345 | current_description, video_rtp_extensions, offer_video_codecs, |
| 1346 | ¤t_streams, offer.get(), &ice_credentials)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1347 | return nullptr; |
| 1348 | } |
| 1349 | break; |
| 1350 | case MEDIA_TYPE_DATA: |
| 1351 | if (!AddDataContentForOffer(media_description_options, session_options, |
| 1352 | current_content, current_description, |
| 1353 | offer_data_codecs, ¤t_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1354 | offer.get(), &ice_credentials)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1355 | return nullptr; |
| 1356 | } |
| 1357 | break; |
| 1358 | default: |
| 1359 | RTC_NOTREACHED(); |
| 1360 | } |
| 1361 | ++msection_index; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | // Bundle the contents together, if we've been asked to do so, and update any |
| 1365 | // parameters that need to be tweaked for BUNDLE. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1366 | if (session_options.bundle_enabled && offer->contents().size() > 0u) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1367 | ContentGroup offer_bundle(GROUP_TYPE_BUNDLE); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1368 | for (const ContentInfo& content : offer->contents()) { |
| 1369 | // TODO(deadbeef): There are conditions that make bundling two media |
| 1370 | // descriptions together illegal. For example, they use the same payload |
| 1371 | // type to represent different codecs, or same IDs for different header |
| 1372 | // extensions. We need to detect this and not try to bundle those media |
| 1373 | // descriptions together. |
| 1374 | offer_bundle.AddContentName(content.name); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1375 | } |
| 1376 | offer->AddGroup(offer_bundle); |
| 1377 | if (!UpdateTransportInfoForBundle(offer_bundle, offer.get())) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1378 | RTC_LOG(LS_ERROR) |
| 1379 | << "CreateOffer failed to UpdateTransportInfoForBundle."; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1380 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1381 | } |
| 1382 | if (!UpdateCryptoParamsForBundle(offer_bundle, offer.get())) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1383 | RTC_LOG(LS_ERROR) << "CreateOffer failed to UpdateCryptoParamsForBundle."; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1384 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1385 | } |
| 1386 | } |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1387 | |
| 1388 | // The following determines how to signal MSIDs to ensure compatibility with |
| 1389 | // older endpoints (in particular, older Plan B endpoints). |
Steve Anton | 8f66ddb | 2018-12-10 16:08:05 -0800 | [diff] [blame^] | 1390 | if (is_unified_plan_) { |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1391 | // Be conservative and signal using both a=msid and a=ssrc lines. Unified |
| 1392 | // Plan answerers will look at a=msid and Plan B answerers will look at the |
| 1393 | // a=ssrc MSID line. |
| 1394 | offer->set_msid_signaling(cricket::kMsidSignalingMediaSection | |
| 1395 | cricket::kMsidSignalingSsrcAttribute); |
| 1396 | } else { |
| 1397 | // Plan B always signals MSID using a=ssrc lines. |
| 1398 | offer->set_msid_signaling(cricket::kMsidSignalingSsrcAttribute); |
| 1399 | } |
| 1400 | |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 1401 | offer->set_extmap_allow_mixed(session_options.offer_extmap_allow_mixed); |
| 1402 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1403 | return offer.release(); |
| 1404 | } |
| 1405 | |
| 1406 | SessionDescription* MediaSessionDescriptionFactory::CreateAnswer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1407 | const SessionDescription* offer, |
| 1408 | const MediaSessionOptions& session_options, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1409 | const SessionDescription* current_description) const { |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1410 | if (!offer) { |
| 1411 | return nullptr; |
| 1412 | } |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1413 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1414 | // Must have options for exactly as many sections as in the offer. |
| 1415 | RTC_DCHECK_EQ(offer->contents().size(), |
| 1416 | session_options.media_description_options.size()); |
| 1417 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1418 | IceCredentialsIterator ice_credentials( |
| 1419 | session_options.pooled_ice_credentials); |
| 1420 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1421 | std::vector<const ContentInfo*> current_active_contents; |
| 1422 | if (current_description) { |
| 1423 | current_active_contents = |
| 1424 | GetActiveContents(*current_description, session_options); |
| 1425 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1426 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1427 | StreamParamsVec current_streams = |
| 1428 | GetCurrentStreamParams(current_active_contents); |
Johannes Kron | 0854eb6 | 2018-10-10 22:33:20 +0200 | [diff] [blame] | 1429 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1430 | // Get list of all possible codecs that respects existing payload type |
| 1431 | // mappings and uses a single payload type space. |
| 1432 | // |
| 1433 | // Note that these lists may be further filtered for each m= section; this |
| 1434 | // step is done just to establish the payload type mappings shared by all |
| 1435 | // sections. |
| 1436 | AudioCodecs answer_audio_codecs; |
| 1437 | VideoCodecs answer_video_codecs; |
| 1438 | DataCodecs answer_data_codecs; |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1439 | GetCodecsForAnswer(current_active_contents, *offer, &answer_audio_codecs, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1440 | &answer_video_codecs, &answer_data_codecs); |
| 1441 | |
| 1442 | if (!session_options.vad_enabled) { |
| 1443 | // If application doesn't want CN codecs in answer. |
| 1444 | StripCNCodecs(&answer_audio_codecs); |
| 1445 | } |
| 1446 | FilterDataCodecs(&answer_data_codecs, |
| 1447 | session_options.data_channel_type == DCT_SCTP); |
| 1448 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1449 | auto answer = absl::make_unique<SessionDescription>(); |
| 1450 | |
| 1451 | // If the offer supports BUNDLE, and we want to use it too, create a BUNDLE |
| 1452 | // group in the answer with the appropriate content names. |
| 1453 | const ContentGroup* offer_bundle = offer->GetGroupByName(GROUP_TYPE_BUNDLE); |
| 1454 | ContentGroup answer_bundle(GROUP_TYPE_BUNDLE); |
| 1455 | // Transport info shared by the bundle group. |
| 1456 | std::unique_ptr<TransportInfo> bundle_transport; |
| 1457 | |
| 1458 | answer->set_extmap_allow_mixed(offer->extmap_allow_mixed()); |
| 1459 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1460 | // Iterate through the media description options, matching with existing |
| 1461 | // media descriptions in |current_description|. |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 1462 | size_t msection_index = 0; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1463 | for (const MediaDescriptionOptions& media_description_options : |
| 1464 | session_options.media_description_options) { |
| 1465 | const ContentInfo* offer_content = &offer->contents()[msection_index]; |
| 1466 | // Media types and MIDs must match between the remote offer and the |
| 1467 | // MediaDescriptionOptions. |
| 1468 | RTC_DCHECK( |
| 1469 | IsMediaContentOfType(offer_content, media_description_options.type)); |
| 1470 | RTC_DCHECK(media_description_options.mid == offer_content->name); |
| 1471 | const ContentInfo* current_content = nullptr; |
| 1472 | if (current_description && |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 1473 | msection_index < current_description->contents().size()) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1474 | current_content = ¤t_description->contents()[msection_index]; |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1475 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1476 | switch (media_description_options.type) { |
| 1477 | case MEDIA_TYPE_AUDIO: |
| 1478 | if (!AddAudioContentForAnswer( |
| 1479 | media_description_options, session_options, offer_content, |
| 1480 | offer, current_content, current_description, |
| 1481 | bundle_transport.get(), answer_audio_codecs, ¤t_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1482 | answer.get(), &ice_credentials)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1483 | return nullptr; |
| 1484 | } |
| 1485 | break; |
| 1486 | case MEDIA_TYPE_VIDEO: |
| 1487 | if (!AddVideoContentForAnswer( |
| 1488 | media_description_options, session_options, offer_content, |
| 1489 | offer, current_content, current_description, |
| 1490 | bundle_transport.get(), answer_video_codecs, ¤t_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1491 | answer.get(), &ice_credentials)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1492 | return nullptr; |
| 1493 | } |
| 1494 | break; |
| 1495 | case MEDIA_TYPE_DATA: |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1496 | if (!AddDataContentForAnswer( |
| 1497 | media_description_options, session_options, offer_content, |
| 1498 | offer, current_content, current_description, |
| 1499 | bundle_transport.get(), answer_data_codecs, ¤t_streams, |
| 1500 | answer.get(), &ice_credentials)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1501 | return nullptr; |
| 1502 | } |
| 1503 | break; |
| 1504 | default: |
| 1505 | RTC_NOTREACHED(); |
| 1506 | } |
| 1507 | ++msection_index; |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1508 | // See if we can add the newly generated m= section to the BUNDLE group in |
| 1509 | // the answer. |
| 1510 | ContentInfo& added = answer->contents().back(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1511 | if (!added.rejected && session_options.bundle_enabled && offer_bundle && |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1512 | offer_bundle->HasContentName(added.name)) { |
| 1513 | answer_bundle.AddContentName(added.name); |
| 1514 | bundle_transport.reset( |
| 1515 | new TransportInfo(*answer->GetTransportInfoByName(added.name))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1516 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Taylor Brandstetter | 0ab5651 | 2018-04-12 10:30:48 -0700 | [diff] [blame] | 1519 | // If a BUNDLE group was offered, put a BUNDLE group in the answer even if |
| 1520 | // it's empty. RFC5888 says: |
| 1521 | // |
| 1522 | // A SIP entity that receives an offer that contains an "a=group" line |
| 1523 | // with semantics that are understood MUST return an answer that |
| 1524 | // contains an "a=group" line with the same semantics. |
| 1525 | if (offer_bundle) { |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1526 | answer->AddGroup(answer_bundle); |
Taylor Brandstetter | 0ab5651 | 2018-04-12 10:30:48 -0700 | [diff] [blame] | 1527 | } |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1528 | |
Taylor Brandstetter | 0ab5651 | 2018-04-12 10:30:48 -0700 | [diff] [blame] | 1529 | if (answer_bundle.FirstContentName()) { |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1530 | // Share the same ICE credentials and crypto params across all contents, |
| 1531 | // as BUNDLE requires. |
| 1532 | if (!UpdateTransportInfoForBundle(answer_bundle, answer.get())) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1533 | RTC_LOG(LS_ERROR) |
| 1534 | << "CreateAnswer failed to UpdateTransportInfoForBundle."; |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1535 | return NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1536 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1537 | |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1538 | if (!UpdateCryptoParamsForBundle(answer_bundle, answer.get())) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1539 | RTC_LOG(LS_ERROR) |
| 1540 | << "CreateAnswer failed to UpdateCryptoParamsForBundle."; |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1541 | return NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1545 | // The following determines how to signal MSIDs to ensure compatibility with |
| 1546 | // older endpoints (in particular, older Plan B endpoints). |
Steve Anton | 8f66ddb | 2018-12-10 16:08:05 -0800 | [diff] [blame^] | 1547 | if (is_unified_plan_) { |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1548 | // Unified Plan needs to look at what the offer included to find the most |
| 1549 | // compatible answer. |
| 1550 | if (offer->msid_signaling() == 0) { |
| 1551 | // We end up here in one of three cases: |
| 1552 | // 1. An empty offer. We'll reply with an empty answer so it doesn't |
| 1553 | // matter what we pick here. |
| 1554 | // 2. A data channel only offer. We won't add any MSIDs to the answer so |
| 1555 | // it also doesn't matter what we pick here. |
| 1556 | // 3. Media that's either sendonly or inactive from the remote endpoint. |
| 1557 | // We don't have any information to say whether the endpoint is Plan B |
| 1558 | // or Unified Plan, so be conservative and send both. |
| 1559 | answer->set_msid_signaling(cricket::kMsidSignalingMediaSection | |
| 1560 | cricket::kMsidSignalingSsrcAttribute); |
| 1561 | } else if (offer->msid_signaling() == |
| 1562 | (cricket::kMsidSignalingMediaSection | |
| 1563 | cricket::kMsidSignalingSsrcAttribute)) { |
| 1564 | // If both a=msid and a=ssrc MSID signaling methods were used, we're |
| 1565 | // probably talking to a Unified Plan endpoint so respond with just |
| 1566 | // a=msid. |
| 1567 | answer->set_msid_signaling(cricket::kMsidSignalingMediaSection); |
| 1568 | } else { |
| 1569 | // Otherwise, it's clear which method the offerer is using so repeat that |
| 1570 | // back to them. |
| 1571 | answer->set_msid_signaling(offer->msid_signaling()); |
| 1572 | } |
| 1573 | } else { |
| 1574 | // Plan B always signals MSID using a=ssrc lines. |
| 1575 | answer->set_msid_signaling(cricket::kMsidSignalingSsrcAttribute); |
| 1576 | } |
| 1577 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1578 | return answer.release(); |
| 1579 | } |
| 1580 | |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1581 | const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForOffer( |
| 1582 | const RtpTransceiverDirection& direction) const { |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 1583 | switch (direction) { |
| 1584 | // If stream is inactive - generate list as if sendrecv. |
| 1585 | case RtpTransceiverDirection::kSendRecv: |
| 1586 | case RtpTransceiverDirection::kInactive: |
| 1587 | return audio_sendrecv_codecs_; |
| 1588 | case RtpTransceiverDirection::kSendOnly: |
| 1589 | return audio_send_codecs_; |
| 1590 | case RtpTransceiverDirection::kRecvOnly: |
| 1591 | return audio_recv_codecs_; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1592 | } |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 1593 | RTC_NOTREACHED(); |
| 1594 | return audio_sendrecv_codecs_; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | const AudioCodecs& MediaSessionDescriptionFactory::GetAudioCodecsForAnswer( |
| 1598 | const RtpTransceiverDirection& offer, |
| 1599 | const RtpTransceiverDirection& answer) const { |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 1600 | switch (answer) { |
| 1601 | // For inactive and sendrecv answers, generate lists as if we were to accept |
| 1602 | // the offer's direction. See RFC 3264 Section 6.1. |
| 1603 | case RtpTransceiverDirection::kSendRecv: |
| 1604 | case RtpTransceiverDirection::kInactive: |
| 1605 | return GetAudioCodecsForOffer( |
| 1606 | webrtc::RtpTransceiverDirectionReversed(offer)); |
| 1607 | case RtpTransceiverDirection::kSendOnly: |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1608 | return audio_send_codecs_; |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 1609 | case RtpTransceiverDirection::kRecvOnly: |
| 1610 | return audio_recv_codecs_; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1611 | } |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 1612 | RTC_NOTREACHED(); |
| 1613 | return audio_sendrecv_codecs_; |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1616 | void MergeCodecsFromDescription( |
| 1617 | const std::vector<const ContentInfo*>& current_active_contents, |
| 1618 | AudioCodecs* audio_codecs, |
| 1619 | VideoCodecs* video_codecs, |
| 1620 | DataCodecs* data_codecs, |
| 1621 | UsedPayloadTypes* used_pltypes) { |
| 1622 | for (const ContentInfo* content : current_active_contents) { |
| 1623 | if (IsMediaContentOfType(content, MEDIA_TYPE_AUDIO)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1624 | const AudioContentDescription* audio = |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1625 | content->media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1626 | MergeCodecs<AudioCodec>(audio->codecs(), audio_codecs, used_pltypes); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1627 | } else if (IsMediaContentOfType(content, MEDIA_TYPE_VIDEO)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1628 | const VideoContentDescription* video = |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1629 | content->media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1630 | MergeCodecs<VideoCodec>(video->codecs(), video_codecs, used_pltypes); |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1631 | } else if (IsMediaContentOfType(content, MEDIA_TYPE_DATA)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1632 | const DataContentDescription* data = |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1633 | content->media_description()->as_data(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1634 | MergeCodecs<DataCodec>(data->codecs(), data_codecs, used_pltypes); |
| 1635 | } |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | // Getting codecs for an offer involves these steps: |
| 1640 | // |
| 1641 | // 1. Construct payload type -> codec mappings for current description. |
| 1642 | // 2. Add any reference codecs that weren't already present |
| 1643 | // 3. For each individual media description (m= section), filter codecs based |
| 1644 | // on the directional attribute (happens in another method). |
| 1645 | void MediaSessionDescriptionFactory::GetCodecsForOffer( |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1646 | const std::vector<const ContentInfo*>& current_active_contents, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1647 | AudioCodecs* audio_codecs, |
| 1648 | VideoCodecs* video_codecs, |
| 1649 | DataCodecs* data_codecs) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1650 | // First - get all codecs from the current description if the media type |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1651 | // is used. Add them to |used_pltypes| so the payload type is not reused if a |
| 1652 | // new media type is added. |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1653 | UsedPayloadTypes used_pltypes; |
| 1654 | MergeCodecsFromDescription(current_active_contents, audio_codecs, |
| 1655 | video_codecs, data_codecs, &used_pltypes); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1656 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1657 | // Add our codecs that are not in the current description. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1658 | MergeCodecs<AudioCodec>(all_audio_codecs_, audio_codecs, &used_pltypes); |
| 1659 | MergeCodecs<VideoCodec>(video_codecs_, video_codecs, &used_pltypes); |
| 1660 | MergeCodecs<DataCodec>(data_codecs_, data_codecs, &used_pltypes); |
| 1661 | } |
| 1662 | |
| 1663 | // Getting codecs for an answer involves these steps: |
| 1664 | // |
| 1665 | // 1. Construct payload type -> codec mappings for current description. |
| 1666 | // 2. Add any codecs from the offer that weren't already present. |
| 1667 | // 3. Add any remaining codecs that weren't already present. |
| 1668 | // 4. For each individual media description (m= section), filter codecs based |
| 1669 | // on the directional attribute (happens in another method). |
| 1670 | void MediaSessionDescriptionFactory::GetCodecsForAnswer( |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1671 | const std::vector<const ContentInfo*>& current_active_contents, |
| 1672 | const SessionDescription& remote_offer, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1673 | AudioCodecs* audio_codecs, |
| 1674 | VideoCodecs* video_codecs, |
| 1675 | DataCodecs* data_codecs) const { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1676 | // First - get all codecs from the current description if the media type |
| 1677 | // is used. Add them to |used_pltypes| so the payload type is not reused if a |
| 1678 | // new media type is added. |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1679 | UsedPayloadTypes used_pltypes; |
| 1680 | MergeCodecsFromDescription(current_active_contents, audio_codecs, |
| 1681 | video_codecs, data_codecs, &used_pltypes); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1682 | |
| 1683 | // Second - filter out codecs that we don't support at all and should ignore. |
| 1684 | AudioCodecs filtered_offered_audio_codecs; |
| 1685 | VideoCodecs filtered_offered_video_codecs; |
| 1686 | DataCodecs filtered_offered_data_codecs; |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1687 | for (const ContentInfo& content : remote_offer.contents()) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1688 | if (IsMediaContentOfType(&content, MEDIA_TYPE_AUDIO)) { |
| 1689 | const AudioContentDescription* audio = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1690 | content.media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1691 | for (const AudioCodec& offered_audio_codec : audio->codecs()) { |
| 1692 | if (!FindMatchingCodec<AudioCodec>(audio->codecs(), |
| 1693 | filtered_offered_audio_codecs, |
| 1694 | offered_audio_codec, nullptr) && |
| 1695 | FindMatchingCodec<AudioCodec>(audio->codecs(), all_audio_codecs_, |
| 1696 | offered_audio_codec, nullptr)) { |
| 1697 | filtered_offered_audio_codecs.push_back(offered_audio_codec); |
| 1698 | } |
| 1699 | } |
| 1700 | } else if (IsMediaContentOfType(&content, MEDIA_TYPE_VIDEO)) { |
| 1701 | const VideoContentDescription* video = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1702 | content.media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1703 | for (const VideoCodec& offered_video_codec : video->codecs()) { |
| 1704 | if (!FindMatchingCodec<VideoCodec>(video->codecs(), |
| 1705 | filtered_offered_video_codecs, |
| 1706 | offered_video_codec, nullptr) && |
| 1707 | FindMatchingCodec<VideoCodec>(video->codecs(), video_codecs_, |
| 1708 | offered_video_codec, nullptr)) { |
| 1709 | filtered_offered_video_codecs.push_back(offered_video_codec); |
| 1710 | } |
| 1711 | } |
| 1712 | } else if (IsMediaContentOfType(&content, MEDIA_TYPE_DATA)) { |
| 1713 | const DataContentDescription* data = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1714 | content.media_description()->as_data(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1715 | for (const DataCodec& offered_data_codec : data->codecs()) { |
| 1716 | if (!FindMatchingCodec<DataCodec>(data->codecs(), |
| 1717 | filtered_offered_data_codecs, |
| 1718 | offered_data_codec, nullptr) && |
| 1719 | FindMatchingCodec<DataCodec>(data->codecs(), data_codecs_, |
| 1720 | offered_data_codec, nullptr)) { |
| 1721 | filtered_offered_data_codecs.push_back(offered_data_codec); |
| 1722 | } |
| 1723 | } |
| 1724 | } |
| 1725 | } |
| 1726 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1727 | // Add codecs that are not in the current description but were in |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1728 | // |remote_offer|. |
| 1729 | MergeCodecs<AudioCodec>(filtered_offered_audio_codecs, audio_codecs, |
| 1730 | &used_pltypes); |
| 1731 | MergeCodecs<VideoCodec>(filtered_offered_video_codecs, video_codecs, |
| 1732 | &used_pltypes); |
| 1733 | MergeCodecs<DataCodec>(filtered_offered_data_codecs, data_codecs, |
| 1734 | &used_pltypes); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1738 | const std::vector<const ContentInfo*>& current_active_contents, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1739 | RtpHeaderExtensions* offer_audio_extensions, |
| 1740 | RtpHeaderExtensions* offer_video_extensions) const { |
henrike@webrtc.org | 79047f9 | 2014-03-06 23:46:59 +0000 | [diff] [blame] | 1741 | // All header extensions allocated from the same range to avoid potential |
| 1742 | // issues when using BUNDLE. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1743 | UsedRtpHeaderExtensionIds used_ids; |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1744 | RtpHeaderExtensions all_regular_extensions; |
| 1745 | RtpHeaderExtensions all_encrypted_extensions; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1746 | |
| 1747 | // First - get all extensions from the current description if the media type |
| 1748 | // is used. |
| 1749 | // Add them to |used_ids| so the local ids are not reused if a new media |
| 1750 | // type is added. |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1751 | for (const ContentInfo* content : current_active_contents) { |
| 1752 | if (IsMediaContentOfType(content, MEDIA_TYPE_AUDIO)) { |
| 1753 | const AudioContentDescription* audio = |
| 1754 | content->media_description()->as_audio(); |
| 1755 | MergeRtpHdrExts(audio->rtp_header_extensions(), offer_audio_extensions, |
| 1756 | &all_regular_extensions, &all_encrypted_extensions, |
| 1757 | &used_ids); |
| 1758 | } else if (IsMediaContentOfType(content, MEDIA_TYPE_VIDEO)) { |
| 1759 | const VideoContentDescription* video = |
| 1760 | content->media_description()->as_video(); |
| 1761 | MergeRtpHdrExts(video->rtp_header_extensions(), offer_video_extensions, |
| 1762 | &all_regular_extensions, &all_encrypted_extensions, |
| 1763 | &used_ids); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1767 | // Add our default RTP header extensions that are not in the current |
| 1768 | // description. |
Steve Anton | 8f66ddb | 2018-12-10 16:08:05 -0800 | [diff] [blame^] | 1769 | MergeRtpHdrExts(audio_rtp_header_extensions(), offer_audio_extensions, |
| 1770 | &all_regular_extensions, &all_encrypted_extensions, |
| 1771 | &used_ids); |
| 1772 | MergeRtpHdrExts(video_rtp_header_extensions(), offer_video_extensions, |
| 1773 | &all_regular_extensions, &all_encrypted_extensions, |
| 1774 | &used_ids); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1775 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1776 | // TODO(jbauch): Support adding encrypted header extensions to existing |
| 1777 | // sessions. |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1778 | if (enable_encrypted_rtp_header_extensions_ && |
| 1779 | current_active_contents.empty()) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1780 | AddEncryptedVersionsOfHdrExts(offer_audio_extensions, |
| 1781 | &all_encrypted_extensions, &used_ids); |
| 1782 | AddEncryptedVersionsOfHdrExts(offer_video_extensions, |
| 1783 | &all_encrypted_extensions, &used_ids); |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 1784 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | bool MediaSessionDescriptionFactory::AddTransportOffer( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1788 | const std::string& content_name, |
| 1789 | const TransportOptions& transport_options, |
| 1790 | const SessionDescription* current_desc, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1791 | SessionDescription* offer_desc, |
| 1792 | IceCredentialsIterator* ice_credentials) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1793 | if (!transport_desc_factory_) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1794 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1795 | const TransportDescription* current_tdesc = |
| 1796 | GetTransportDescription(content_name, current_desc); |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1797 | std::unique_ptr<TransportDescription> new_tdesc( |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1798 | transport_desc_factory_->CreateOffer(transport_options, current_tdesc, |
| 1799 | ice_credentials)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1800 | bool ret = |
| 1801 | (new_tdesc.get() != NULL && |
| 1802 | offer_desc->AddTransportInfo(TransportInfo(content_name, *new_tdesc))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1803 | if (!ret) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1804 | RTC_LOG(LS_ERROR) << "Failed to AddTransportOffer, content name=" |
| 1805 | << content_name; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1806 | } |
| 1807 | return ret; |
| 1808 | } |
| 1809 | |
| 1810 | TransportDescription* MediaSessionDescriptionFactory::CreateTransportAnswer( |
| 1811 | const std::string& content_name, |
| 1812 | const SessionDescription* offer_desc, |
| 1813 | const TransportOptions& transport_options, |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1814 | const SessionDescription* current_desc, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1815 | bool require_transport_attributes, |
| 1816 | IceCredentialsIterator* ice_credentials) const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1817 | if (!transport_desc_factory_) |
| 1818 | return NULL; |
| 1819 | const TransportDescription* offer_tdesc = |
| 1820 | GetTransportDescription(content_name, offer_desc); |
| 1821 | const TransportDescription* current_tdesc = |
| 1822 | GetTransportDescription(content_name, current_desc); |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 1823 | return transport_desc_factory_->CreateAnswer(offer_tdesc, transport_options, |
| 1824 | require_transport_attributes, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1825 | current_tdesc, ice_credentials); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | bool MediaSessionDescriptionFactory::AddTransportAnswer( |
| 1829 | const std::string& content_name, |
| 1830 | const TransportDescription& transport_desc, |
| 1831 | SessionDescription* answer_desc) const { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1832 | if (!answer_desc->AddTransportInfo( |
| 1833 | TransportInfo(content_name, transport_desc))) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 1834 | RTC_LOG(LS_ERROR) << "Failed to AddTransportAnswer, content name=" |
| 1835 | << content_name; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1836 | return false; |
| 1837 | } |
| 1838 | return true; |
| 1839 | } |
| 1840 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1841 | // |audio_codecs| = set of all possible codecs that can be used, with correct |
| 1842 | // payload type mappings |
| 1843 | // |
| 1844 | // |supported_audio_codecs| = set of codecs that are supported for the direction |
| 1845 | // of this m= section |
| 1846 | // |
| 1847 | // acd->codecs() = set of previously negotiated codecs for this m= section |
| 1848 | // |
| 1849 | // The payload types should come from audio_codecs, but the order should come |
| 1850 | // from acd->codecs() and then supported_codecs, to ensure that re-offers don't |
| 1851 | // change existing codec priority, and that new codecs are added with the right |
| 1852 | // priority. |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1853 | bool MediaSessionDescriptionFactory::AddAudioContentForOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1854 | const MediaDescriptionOptions& media_description_options, |
| 1855 | const MediaSessionOptions& session_options, |
| 1856 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1857 | const SessionDescription* current_description, |
| 1858 | const RtpHeaderExtensions& audio_rtp_extensions, |
| 1859 | const AudioCodecs& audio_codecs, |
| 1860 | StreamParamsVec* current_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1861 | SessionDescription* desc, |
| 1862 | IceCredentialsIterator* ice_credentials) const { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1863 | // Filter audio_codecs (which includes all codecs, with correctly remapped |
| 1864 | // payload types) based on transceiver direction. |
| 1865 | const AudioCodecs& supported_audio_codecs = |
| 1866 | GetAudioCodecsForOffer(media_description_options.direction); |
| 1867 | |
| 1868 | AudioCodecs filtered_codecs; |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1869 | // Add the codecs from current content if it exists and is not rejected nor |
| 1870 | // recycled. |
| 1871 | if (current_content && !current_content->rejected && |
| 1872 | current_content->name == media_description_options.mid) { |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 1873 | RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1874 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1875 | current_content->media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1876 | for (const AudioCodec& codec : acd->codecs()) { |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 1877 | if (FindMatchingCodec<AudioCodec>(acd->codecs(), audio_codecs, codec, |
| 1878 | nullptr)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1879 | filtered_codecs.push_back(codec); |
| 1880 | } |
| 1881 | } |
| 1882 | } |
| 1883 | // Add other supported audio codecs. |
| 1884 | AudioCodec found_codec; |
| 1885 | for (const AudioCodec& codec : supported_audio_codecs) { |
| 1886 | if (FindMatchingCodec<AudioCodec>(supported_audio_codecs, audio_codecs, |
| 1887 | codec, &found_codec) && |
| 1888 | !FindMatchingCodec<AudioCodec>(supported_audio_codecs, filtered_codecs, |
| 1889 | codec, nullptr)) { |
| 1890 | // Use the |found_codec| from |audio_codecs| because it has the correctly |
| 1891 | // mapped payload type. |
| 1892 | filtered_codecs.push_back(found_codec); |
| 1893 | } |
| 1894 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 1895 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1896 | cricket::SecurePolicy sdes_policy = |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1897 | IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED |
| 1898 | : secure(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1899 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1900 | std::unique_ptr<AudioContentDescription> audio(new AudioContentDescription()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1901 | std::vector<std::string> crypto_suites; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1902 | GetSupportedAudioSdesCryptoSuiteNames(session_options.crypto_options, |
| 1903 | &crypto_suites); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1904 | if (!CreateMediaContentOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1905 | media_description_options.sender_options, session_options, |
| 1906 | filtered_codecs, sdes_policy, GetCryptos(current_content), |
| 1907 | crypto_suites, audio_rtp_extensions, current_streams, audio.get())) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1908 | return false; |
| 1909 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1910 | |
| 1911 | bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
| 1912 | SetMediaProtocol(secure_transport, audio.get()); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1913 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1914 | audio->set_direction(media_description_options.direction); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1915 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1916 | desc->AddContent(media_description_options.mid, MediaProtocolType::kRtp, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1917 | media_description_options.stopped, audio.release()); |
| 1918 | if (!AddTransportOffer(media_description_options.mid, |
| 1919 | media_description_options.transport_options, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1920 | current_description, desc, ice_credentials)) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1921 | return false; |
| 1922 | } |
| 1923 | |
| 1924 | return true; |
| 1925 | } |
| 1926 | |
| 1927 | bool MediaSessionDescriptionFactory::AddVideoContentForOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1928 | const MediaDescriptionOptions& media_description_options, |
| 1929 | const MediaSessionOptions& session_options, |
| 1930 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1931 | const SessionDescription* current_description, |
| 1932 | const RtpHeaderExtensions& video_rtp_extensions, |
| 1933 | const VideoCodecs& video_codecs, |
| 1934 | StreamParamsVec* current_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1935 | SessionDescription* desc, |
| 1936 | IceCredentialsIterator* ice_credentials) const { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1937 | cricket::SecurePolicy sdes_policy = |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1938 | IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED |
| 1939 | : secure(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1940 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1941 | std::unique_ptr<VideoContentDescription> video(new VideoContentDescription()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1942 | std::vector<std::string> crypto_suites; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1943 | GetSupportedVideoSdesCryptoSuiteNames(session_options.crypto_options, |
| 1944 | &crypto_suites); |
| 1945 | |
| 1946 | VideoCodecs filtered_codecs; |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 1947 | // Add the codecs from current content if it exists and is not rejected nor |
| 1948 | // recycled. |
| 1949 | if (current_content && !current_content->rejected && |
| 1950 | current_content->name == media_description_options.mid) { |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 1951 | RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1952 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1953 | current_content->media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1954 | for (const VideoCodec& codec : vcd->codecs()) { |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 1955 | if (FindMatchingCodec<VideoCodec>(vcd->codecs(), video_codecs, codec, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1956 | nullptr)) { |
| 1957 | filtered_codecs.push_back(codec); |
| 1958 | } |
| 1959 | } |
| 1960 | } |
| 1961 | // Add other supported video codecs. |
| 1962 | VideoCodec found_codec; |
| 1963 | for (const VideoCodec& codec : video_codecs_) { |
| 1964 | if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, |
| 1965 | &found_codec) && |
| 1966 | !FindMatchingCodec<VideoCodec>(video_codecs_, filtered_codecs, codec, |
| 1967 | nullptr)) { |
| 1968 | // Use the |found_codec| from |video_codecs| because it has the correctly |
| 1969 | // mapped payload type. |
| 1970 | filtered_codecs.push_back(found_codec); |
| 1971 | } |
| 1972 | } |
| 1973 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1974 | if (!CreateMediaContentOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1975 | media_description_options.sender_options, session_options, |
| 1976 | filtered_codecs, sdes_policy, GetCryptos(current_content), |
| 1977 | crypto_suites, video_rtp_extensions, current_streams, video.get())) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1978 | return false; |
| 1979 | } |
| 1980 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1981 | video->set_bandwidth(kAutoBandwidth); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1982 | |
| 1983 | bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
| 1984 | SetMediaProtocol(secure_transport, video.get()); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1985 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 1986 | video->set_direction(media_description_options.direction); |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1987 | |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 1988 | desc->AddContent(media_description_options.mid, MediaProtocolType::kRtp, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1989 | media_description_options.stopped, video.release()); |
| 1990 | if (!AddTransportOffer(media_description_options.mid, |
| 1991 | media_description_options.transport_options, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 1992 | current_description, desc, ice_credentials)) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1993 | return false; |
| 1994 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 1995 | return true; |
| 1996 | } |
| 1997 | |
| 1998 | bool MediaSessionDescriptionFactory::AddDataContentForOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1999 | const MediaDescriptionOptions& media_description_options, |
| 2000 | const MediaSessionOptions& session_options, |
| 2001 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2002 | const SessionDescription* current_description, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2003 | const DataCodecs& data_codecs, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2004 | StreamParamsVec* current_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 2005 | SessionDescription* desc, |
| 2006 | IceCredentialsIterator* ice_credentials) const { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2007 | bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
| 2008 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2009 | std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2010 | bool is_sctp = (session_options.data_channel_type == DCT_SCTP); |
| 2011 | // If the DataChannel type is not specified, use the DataChannel type in |
| 2012 | // the current description. |
| 2013 | if (session_options.data_channel_type == DCT_NONE && current_content) { |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 2014 | RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_DATA)); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2015 | is_sctp = (current_content->media_description()->protocol() == |
| 2016 | kMediaProtocolSctp); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2017 | } |
deadbeef | 44f0819 | 2015-12-15 16:20:09 -0800 | [diff] [blame] | 2018 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2019 | cricket::SecurePolicy sdes_policy = |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2020 | IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED |
| 2021 | : secure(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2022 | std::vector<std::string> crypto_suites; |
| 2023 | if (is_sctp) { |
| 2024 | // SDES doesn't make sense for SCTP, so we disable it, and we only |
| 2025 | // get SDES crypto suites for RTP-based data channels. |
| 2026 | sdes_policy = cricket::SEC_DISABLED; |
| 2027 | // Unlike SetMediaProtocol below, we need to set the protocol |
| 2028 | // before we call CreateMediaContentOffer. Otherwise, |
| 2029 | // CreateMediaContentOffer won't know this is SCTP and will |
| 2030 | // generate SSRCs rather than SIDs. |
deadbeef | 8b7e9ad | 2017-05-25 09:38:55 -0700 | [diff] [blame] | 2031 | // TODO(deadbeef): Offer kMediaProtocolUdpDtlsSctp (or TcpDtlsSctp), once |
| 2032 | // it's safe to do so. Older versions of webrtc would reject these |
| 2033 | // protocols; see https://bugs.chromium.org/p/webrtc/issues/detail?id=7706. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2034 | data->set_protocol(secure_transport ? kMediaProtocolDtlsSctp |
| 2035 | : kMediaProtocolSctp); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2036 | } else { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2037 | GetSupportedDataSdesCryptoSuiteNames(session_options.crypto_options, |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 2038 | &crypto_suites); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2041 | // Even SCTP uses a "codec". |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2042 | if (!CreateMediaContentOffer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2043 | media_description_options.sender_options, session_options, |
| 2044 | data_codecs, sdes_policy, GetCryptos(current_content), crypto_suites, |
| 2045 | RtpHeaderExtensions(), current_streams, data.get())) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2046 | return false; |
| 2047 | } |
| 2048 | |
| 2049 | if (is_sctp) { |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 2050 | desc->AddContent(media_description_options.mid, MediaProtocolType::kSctp, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2051 | data.release()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2052 | } else { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2053 | data->set_bandwidth(kDataMaxBandwidth); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2054 | SetMediaProtocol(secure_transport, data.get()); |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 2055 | desc->AddContent(media_description_options.mid, MediaProtocolType::kRtp, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2056 | media_description_options.stopped, data.release()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2057 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2058 | if (!AddTransportOffer(media_description_options.mid, |
| 2059 | media_description_options.transport_options, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 2060 | current_description, desc, ice_credentials)) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2061 | return false; |
| 2062 | } |
| 2063 | return true; |
| 2064 | } |
| 2065 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2066 | // |audio_codecs| = set of all possible codecs that can be used, with correct |
| 2067 | // payload type mappings |
| 2068 | // |
| 2069 | // |supported_audio_codecs| = set of codecs that are supported for the direction |
| 2070 | // of this m= section |
| 2071 | // |
| 2072 | // acd->codecs() = set of previously negotiated codecs for this m= section |
| 2073 | // |
| 2074 | // The payload types should come from audio_codecs, but the order should come |
| 2075 | // from acd->codecs() and then supported_codecs, to ensure that re-offers don't |
| 2076 | // change existing codec priority, and that new codecs are added with the right |
| 2077 | // priority. |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2078 | bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2079 | const MediaDescriptionOptions& media_description_options, |
| 2080 | const MediaSessionOptions& session_options, |
| 2081 | const ContentInfo* offer_content, |
| 2082 | const SessionDescription* offer_description, |
| 2083 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2084 | const SessionDescription* current_description, |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2085 | const TransportInfo* bundle_transport, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2086 | const AudioCodecs& audio_codecs, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2087 | StreamParamsVec* current_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 2088 | SessionDescription* answer, |
| 2089 | IceCredentialsIterator* ice_credentials) const { |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 2090 | RTC_CHECK(IsMediaContentOfType(offer_content, MEDIA_TYPE_AUDIO)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2091 | const AudioContentDescription* offer_audio_description = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2092 | offer_content->media_description()->as_audio(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2093 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 2094 | std::unique_ptr<TransportDescription> audio_transport(CreateTransportAnswer( |
| 2095 | media_description_options.mid, offer_description, |
| 2096 | media_description_options.transport_options, current_description, |
| 2097 | bundle_transport != nullptr, ice_credentials)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2098 | if (!audio_transport) { |
| 2099 | return false; |
| 2100 | } |
| 2101 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2102 | // Pick codecs based on the requested communications direction in the offer |
| 2103 | // and the selected direction in the answer. |
| 2104 | // Note these will be filtered one final time in CreateMediaContentAnswer. |
| 2105 | auto wants_rtd = media_description_options.direction; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 2106 | auto offer_rtd = offer_audio_description->direction(); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 2107 | auto answer_rtd = NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2108 | AudioCodecs supported_audio_codecs = |
| 2109 | GetAudioCodecsForAnswer(offer_rtd, answer_rtd); |
| 2110 | |
| 2111 | AudioCodecs filtered_codecs; |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2112 | // Add the codecs from current content if it exists and is not rejected nor |
| 2113 | // recycled. |
| 2114 | if (current_content && !current_content->rejected && |
| 2115 | current_content->name == media_description_options.mid) { |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 2116 | RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2117 | const AudioContentDescription* acd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2118 | current_content->media_description()->as_audio(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2119 | for (const AudioCodec& codec : acd->codecs()) { |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2120 | if (FindMatchingCodec<AudioCodec>(acd->codecs(), audio_codecs, codec, |
| 2121 | nullptr)) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2122 | filtered_codecs.push_back(codec); |
| 2123 | } |
| 2124 | } |
| 2125 | } |
| 2126 | // Add other supported audio codecs. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2127 | for (const AudioCodec& codec : supported_audio_codecs) { |
| 2128 | if (FindMatchingCodec<AudioCodec>(supported_audio_codecs, audio_codecs, |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 2129 | codec, nullptr) && |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2130 | !FindMatchingCodec<AudioCodec>(supported_audio_codecs, filtered_codecs, |
| 2131 | codec, nullptr)) { |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 2132 | // We should use the local codec with local parameters and the codec id |
| 2133 | // would be correctly mapped in |NegotiateCodecs|. |
| 2134 | filtered_codecs.push_back(codec); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2135 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2138 | bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && |
| 2139 | session_options.bundle_enabled; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2140 | std::unique_ptr<AudioContentDescription> audio_answer( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2141 | new AudioContentDescription()); |
| 2142 | // Do not require or create SDES cryptos if DTLS is used. |
| 2143 | cricket::SecurePolicy sdes_policy = |
| 2144 | audio_transport->secure() ? cricket::SEC_DISABLED : secure(); |
| 2145 | if (!CreateMediaContentAnswer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2146 | offer_audio_description, media_description_options, session_options, |
| 2147 | filtered_codecs, sdes_policy, GetCryptos(current_content), |
Steve Anton | 8f66ddb | 2018-12-10 16:08:05 -0800 | [diff] [blame^] | 2148 | audio_rtp_header_extensions(), |
Steve Anton | 1b8773d | 2018-04-06 11:13:34 -0700 | [diff] [blame] | 2149 | enable_encrypted_rtp_header_extensions_, current_streams, |
| 2150 | bundle_enabled, audio_answer.get())) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2151 | return false; // Fails the session setup. |
| 2152 | } |
| 2153 | |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2154 | bool secure = bundle_transport ? bundle_transport->description.secure() |
| 2155 | : audio_transport->secure(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2156 | bool rejected = media_description_options.stopped || |
| 2157 | offer_content->rejected || |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2158 | !IsMediaProtocolSupported(MEDIA_TYPE_AUDIO, |
| 2159 | audio_answer->protocol(), secure); |
Zhi Huang | 3518e7b | 2018-01-30 13:20:35 -0800 | [diff] [blame] | 2160 | if (!AddTransportAnswer(media_description_options.mid, |
| 2161 | *(audio_transport.get()), answer)) { |
| 2162 | return false; |
| 2163 | } |
| 2164 | |
| 2165 | if (rejected) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 2166 | RTC_LOG(LS_INFO) << "Audio m= section '" << media_description_options.mid |
| 2167 | << "' being rejected in answer."; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2170 | answer->AddContent(media_description_options.mid, offer_content->type, |
| 2171 | rejected, audio_answer.release()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2172 | return true; |
| 2173 | } |
| 2174 | |
| 2175 | bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2176 | const MediaDescriptionOptions& media_description_options, |
| 2177 | const MediaSessionOptions& session_options, |
| 2178 | const ContentInfo* offer_content, |
| 2179 | const SessionDescription* offer_description, |
| 2180 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2181 | const SessionDescription* current_description, |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2182 | const TransportInfo* bundle_transport, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2183 | const VideoCodecs& video_codecs, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2184 | StreamParamsVec* current_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 2185 | SessionDescription* answer, |
| 2186 | IceCredentialsIterator* ice_credentials) const { |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 2187 | RTC_CHECK(IsMediaContentOfType(offer_content, MEDIA_TYPE_VIDEO)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2188 | const VideoContentDescription* offer_video_description = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2189 | offer_content->media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2190 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 2191 | std::unique_ptr<TransportDescription> video_transport(CreateTransportAnswer( |
| 2192 | media_description_options.mid, offer_description, |
| 2193 | media_description_options.transport_options, current_description, |
| 2194 | bundle_transport != nullptr, ice_credentials)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2195 | if (!video_transport) { |
| 2196 | return false; |
| 2197 | } |
| 2198 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2199 | VideoCodecs filtered_codecs; |
Steve Anton | 5c72e71 | 2018-12-10 14:25:30 -0800 | [diff] [blame] | 2200 | // Add the codecs from current content if it exists and is not rejected nor |
| 2201 | // recycled. |
| 2202 | if (current_content && !current_content->rejected && |
| 2203 | current_content->name == media_description_options.mid) { |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 2204 | RTC_CHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2205 | const VideoContentDescription* vcd = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2206 | current_content->media_description()->as_video(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2207 | for (const VideoCodec& codec : vcd->codecs()) { |
Taylor Brandstetter | 1c34974 | 2017-10-03 18:25:36 -0700 | [diff] [blame] | 2208 | if (FindMatchingCodec<VideoCodec>(vcd->codecs(), video_codecs, codec, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2209 | nullptr)) { |
| 2210 | filtered_codecs.push_back(codec); |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | // Add other supported video codecs. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2215 | for (const VideoCodec& codec : video_codecs_) { |
| 2216 | if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 2217 | nullptr) && |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2218 | !FindMatchingCodec<VideoCodec>(video_codecs_, filtered_codecs, codec, |
| 2219 | nullptr)) { |
Zhi Huang | 6f36747 | 2017-11-22 13:20:02 -0800 | [diff] [blame] | 2220 | // We should use the local codec with local parameters and the codec id |
| 2221 | // would be correctly mapped in |NegotiateCodecs|. |
| 2222 | filtered_codecs.push_back(codec); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && |
| 2227 | session_options.bundle_enabled; |
| 2228 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2229 | std::unique_ptr<VideoContentDescription> video_answer( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2230 | new VideoContentDescription()); |
| 2231 | // Do not require or create SDES cryptos if DTLS is used. |
| 2232 | cricket::SecurePolicy sdes_policy = |
| 2233 | video_transport->secure() ? cricket::SEC_DISABLED : secure(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2234 | if (!CreateMediaContentAnswer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2235 | offer_video_description, media_description_options, session_options, |
| 2236 | filtered_codecs, sdes_policy, GetCryptos(current_content), |
Steve Anton | 8f66ddb | 2018-12-10 16:08:05 -0800 | [diff] [blame^] | 2237 | video_rtp_header_extensions(), |
Steve Anton | 1b8773d | 2018-04-06 11:13:34 -0700 | [diff] [blame] | 2238 | enable_encrypted_rtp_header_extensions_, current_streams, |
| 2239 | bundle_enabled, video_answer.get())) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2240 | return false; // Failed the sessin setup. |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2241 | } |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2242 | bool secure = bundle_transport ? bundle_transport->description.secure() |
| 2243 | : video_transport->secure(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2244 | bool rejected = media_description_options.stopped || |
| 2245 | offer_content->rejected || |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2246 | !IsMediaProtocolSupported(MEDIA_TYPE_VIDEO, |
| 2247 | video_answer->protocol(), secure); |
Zhi Huang | 3518e7b | 2018-01-30 13:20:35 -0800 | [diff] [blame] | 2248 | if (!AddTransportAnswer(media_description_options.mid, |
| 2249 | *(video_transport.get()), answer)) { |
| 2250 | return false; |
| 2251 | } |
| 2252 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2253 | if (!rejected) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2254 | video_answer->set_bandwidth(kAutoBandwidth); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2255 | } else { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 2256 | RTC_LOG(LS_INFO) << "Video m= section '" << media_description_options.mid |
| 2257 | << "' being rejected in answer."; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2258 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2259 | answer->AddContent(media_description_options.mid, offer_content->type, |
| 2260 | rejected, video_answer.release()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2261 | return true; |
| 2262 | } |
| 2263 | |
| 2264 | bool MediaSessionDescriptionFactory::AddDataContentForAnswer( |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2265 | const MediaDescriptionOptions& media_description_options, |
| 2266 | const MediaSessionOptions& session_options, |
| 2267 | const ContentInfo* offer_content, |
| 2268 | const SessionDescription* offer_description, |
| 2269 | const ContentInfo* current_content, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2270 | const SessionDescription* current_description, |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2271 | const TransportInfo* bundle_transport, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2272 | const DataCodecs& data_codecs, |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2273 | StreamParamsVec* current_streams, |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 2274 | SessionDescription* answer, |
| 2275 | IceCredentialsIterator* ice_credentials) const { |
| 2276 | std::unique_ptr<TransportDescription> data_transport(CreateTransportAnswer( |
| 2277 | media_description_options.mid, offer_description, |
| 2278 | media_description_options.transport_options, current_description, |
| 2279 | bundle_transport != nullptr, ice_credentials)); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2280 | if (!data_transport) { |
| 2281 | return false; |
| 2282 | } |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2283 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 2284 | std::unique_ptr<DataContentDescription> data_answer( |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2285 | new DataContentDescription()); |
| 2286 | // Do not require or create SDES cryptos if DTLS is used. |
| 2287 | cricket::SecurePolicy sdes_policy = |
| 2288 | data_transport->secure() ? cricket::SEC_DISABLED : secure(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2289 | bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && |
| 2290 | session_options.bundle_enabled; |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 2291 | RTC_CHECK(IsMediaContentOfType(offer_content, MEDIA_TYPE_DATA)); |
| 2292 | const DataContentDescription* offer_data_description = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2293 | offer_content->media_description()->as_data(); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2294 | if (!CreateMediaContentAnswer( |
Taylor Brandstetter | 80cfb52 | 2017-10-12 20:37:38 -0700 | [diff] [blame] | 2295 | offer_data_description, media_description_options, session_options, |
| 2296 | data_codecs, sdes_policy, GetCryptos(current_content), |
| 2297 | RtpHeaderExtensions(), enable_encrypted_rtp_header_extensions_, |
| 2298 | current_streams, bundle_enabled, data_answer.get())) { |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2299 | return false; // Fails the session setup. |
| 2300 | } |
| 2301 | |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 2302 | // Respond with sctpmap if the offer uses sctpmap. |
zstein | 4b2e082 | 2017-02-17 19:48:38 -0800 | [diff] [blame] | 2303 | bool offer_uses_sctpmap = offer_data_description->use_sctpmap(); |
| 2304 | data_answer->set_use_sctpmap(offer_uses_sctpmap); |
| 2305 | |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2306 | bool secure = bundle_transport ? bundle_transport->description.secure() |
| 2307 | : data_transport->secure(); |
| 2308 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2309 | bool rejected = session_options.data_channel_type == DCT_NONE || |
| 2310 | media_description_options.stopped || |
| 2311 | offer_content->rejected || |
deadbeef | b789253 | 2017-02-22 19:35:18 -0800 | [diff] [blame] | 2312 | !IsMediaProtocolSupported(MEDIA_TYPE_DATA, |
| 2313 | data_answer->protocol(), secure); |
Zhi Huang | 3518e7b | 2018-01-30 13:20:35 -0800 | [diff] [blame] | 2314 | if (!AddTransportAnswer(media_description_options.mid, |
| 2315 | *(data_transport.get()), answer)) { |
| 2316 | return false; |
| 2317 | } |
| 2318 | |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2319 | if (!rejected) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2320 | data_answer->set_bandwidth(kDataMaxBandwidth); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2321 | } else { |
| 2322 | // RFC 3264 |
| 2323 | // The answer MUST contain the same number of m-lines as the offer. |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 2324 | RTC_LOG(LS_INFO) << "Data is not supported in the answer."; |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2325 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2326 | answer->AddContent(media_description_options.mid, offer_content->type, |
| 2327 | rejected, data_answer.release()); |
jiayl@webrtc.org | e7d47a1 | 2014-08-05 19:19:05 +0000 | [diff] [blame] | 2328 | return true; |
| 2329 | } |
| 2330 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2331 | void MediaSessionDescriptionFactory::ComputeAudioCodecsIntersectionAndUnion() { |
| 2332 | audio_sendrecv_codecs_.clear(); |
| 2333 | all_audio_codecs_.clear(); |
| 2334 | // Compute the audio codecs union. |
| 2335 | for (const AudioCodec& send : audio_send_codecs_) { |
| 2336 | all_audio_codecs_.push_back(send); |
| 2337 | if (!FindMatchingCodec<AudioCodec>(audio_send_codecs_, audio_recv_codecs_, |
| 2338 | send, nullptr)) { |
| 2339 | // It doesn't make sense to have an RTX codec we support sending but not |
| 2340 | // receiving. |
| 2341 | RTC_DCHECK(!IsRtxCodec(send)); |
| 2342 | } |
| 2343 | } |
| 2344 | for (const AudioCodec& recv : audio_recv_codecs_) { |
| 2345 | if (!FindMatchingCodec<AudioCodec>(audio_recv_codecs_, audio_send_codecs_, |
| 2346 | recv, nullptr)) { |
| 2347 | all_audio_codecs_.push_back(recv); |
| 2348 | } |
| 2349 | } |
| 2350 | // Use NegotiateCodecs to merge our codec lists, since the operation is |
| 2351 | // essentially the same. Put send_codecs as the offered_codecs, which is the |
| 2352 | // order we'd like to follow. The reasoning is that encoding is usually more |
| 2353 | // expensive than decoding, and prioritizing a codec in the send list probably |
| 2354 | // means it's a codec we can handle efficiently. |
| 2355 | NegotiateCodecs(audio_recv_codecs_, audio_send_codecs_, |
| 2356 | &audio_sendrecv_codecs_); |
| 2357 | } |
| 2358 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2359 | bool IsMediaContent(const ContentInfo* content) { |
Steve Anton | 5adfafd | 2017-12-20 16:34:00 -0800 | [diff] [blame] | 2360 | return (content && (content->type == MediaProtocolType::kRtp || |
| 2361 | content->type == MediaProtocolType::kSctp)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | bool IsAudioContent(const ContentInfo* content) { |
| 2365 | return IsMediaContentOfType(content, MEDIA_TYPE_AUDIO); |
| 2366 | } |
| 2367 | |
| 2368 | bool IsVideoContent(const ContentInfo* content) { |
| 2369 | return IsMediaContentOfType(content, MEDIA_TYPE_VIDEO); |
| 2370 | } |
| 2371 | |
| 2372 | bool IsDataContent(const ContentInfo* content) { |
| 2373 | return IsMediaContentOfType(content, MEDIA_TYPE_DATA); |
| 2374 | } |
| 2375 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2376 | const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, |
| 2377 | MediaType media_type) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2378 | for (const ContentInfo& content : contents) { |
| 2379 | if (IsMediaContentOfType(&content, media_type)) { |
| 2380 | return &content; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2381 | } |
| 2382 | } |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2383 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | const ContentInfo* GetFirstAudioContent(const ContentInfos& contents) { |
| 2387 | return GetFirstMediaContent(contents, MEDIA_TYPE_AUDIO); |
| 2388 | } |
| 2389 | |
| 2390 | const ContentInfo* GetFirstVideoContent(const ContentInfos& contents) { |
| 2391 | return GetFirstMediaContent(contents, MEDIA_TYPE_VIDEO); |
| 2392 | } |
| 2393 | |
| 2394 | const ContentInfo* GetFirstDataContent(const ContentInfos& contents) { |
| 2395 | return GetFirstMediaContent(contents, MEDIA_TYPE_DATA); |
| 2396 | } |
| 2397 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 2398 | const ContentInfo* GetFirstMediaContent(const SessionDescription* sdesc, |
| 2399 | MediaType media_type) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2400 | if (sdesc == nullptr) { |
| 2401 | return nullptr; |
| 2402 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2403 | |
| 2404 | return GetFirstMediaContent(sdesc->contents(), media_type); |
| 2405 | } |
| 2406 | |
| 2407 | const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc) { |
| 2408 | return GetFirstMediaContent(sdesc, MEDIA_TYPE_AUDIO); |
| 2409 | } |
| 2410 | |
| 2411 | const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc) { |
| 2412 | return GetFirstMediaContent(sdesc, MEDIA_TYPE_VIDEO); |
| 2413 | } |
| 2414 | |
| 2415 | const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc) { |
| 2416 | return GetFirstMediaContent(sdesc, MEDIA_TYPE_DATA); |
| 2417 | } |
| 2418 | |
| 2419 | const MediaContentDescription* GetFirstMediaContentDescription( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2420 | const SessionDescription* sdesc, |
| 2421 | MediaType media_type) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2422 | const ContentInfo* content = GetFirstMediaContent(sdesc, media_type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2423 | return (content ? content->media_description() : nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | const AudioContentDescription* GetFirstAudioContentDescription( |
| 2427 | const SessionDescription* sdesc) { |
| 2428 | return static_cast<const AudioContentDescription*>( |
| 2429 | GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_AUDIO)); |
| 2430 | } |
| 2431 | |
| 2432 | const VideoContentDescription* GetFirstVideoContentDescription( |
| 2433 | const SessionDescription* sdesc) { |
| 2434 | return static_cast<const VideoContentDescription*>( |
| 2435 | GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
| 2436 | } |
| 2437 | |
| 2438 | const DataContentDescription* GetFirstDataContentDescription( |
| 2439 | const SessionDescription* sdesc) { |
| 2440 | return static_cast<const DataContentDescription*>( |
| 2441 | GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
| 2442 | } |
| 2443 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2444 | // |
| 2445 | // Non-const versions of the above functions. |
| 2446 | // |
| 2447 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 2448 | ContentInfo* GetFirstMediaContent(ContentInfos* contents, |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2449 | MediaType media_type) { |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 2450 | for (ContentInfo& content : *contents) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2451 | if (IsMediaContentOfType(&content, media_type)) { |
| 2452 | return &content; |
| 2453 | } |
| 2454 | } |
| 2455 | return nullptr; |
| 2456 | } |
| 2457 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 2458 | ContentInfo* GetFirstAudioContent(ContentInfos* contents) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2459 | return GetFirstMediaContent(contents, MEDIA_TYPE_AUDIO); |
| 2460 | } |
| 2461 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 2462 | ContentInfo* GetFirstVideoContent(ContentInfos* contents) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2463 | return GetFirstMediaContent(contents, MEDIA_TYPE_VIDEO); |
| 2464 | } |
| 2465 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 2466 | ContentInfo* GetFirstDataContent(ContentInfos* contents) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2467 | return GetFirstMediaContent(contents, MEDIA_TYPE_DATA); |
| 2468 | } |
| 2469 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 2470 | ContentInfo* GetFirstMediaContent(SessionDescription* sdesc, |
| 2471 | MediaType media_type) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2472 | if (sdesc == nullptr) { |
| 2473 | return nullptr; |
| 2474 | } |
| 2475 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 2476 | return GetFirstMediaContent(&sdesc->contents(), media_type); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | ContentInfo* GetFirstAudioContent(SessionDescription* sdesc) { |
| 2480 | return GetFirstMediaContent(sdesc, MEDIA_TYPE_AUDIO); |
| 2481 | } |
| 2482 | |
| 2483 | ContentInfo* GetFirstVideoContent(SessionDescription* sdesc) { |
| 2484 | return GetFirstMediaContent(sdesc, MEDIA_TYPE_VIDEO); |
| 2485 | } |
| 2486 | |
| 2487 | ContentInfo* GetFirstDataContent(SessionDescription* sdesc) { |
| 2488 | return GetFirstMediaContent(sdesc, MEDIA_TYPE_DATA); |
| 2489 | } |
| 2490 | |
| 2491 | MediaContentDescription* GetFirstMediaContentDescription( |
| 2492 | SessionDescription* sdesc, |
| 2493 | MediaType media_type) { |
| 2494 | ContentInfo* content = GetFirstMediaContent(sdesc, media_type); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2495 | return (content ? content->media_description() : nullptr); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | AudioContentDescription* GetFirstAudioContentDescription( |
| 2499 | SessionDescription* sdesc) { |
| 2500 | return static_cast<AudioContentDescription*>( |
| 2501 | GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_AUDIO)); |
| 2502 | } |
| 2503 | |
| 2504 | VideoContentDescription* GetFirstVideoContentDescription( |
| 2505 | SessionDescription* sdesc) { |
| 2506 | return static_cast<VideoContentDescription*>( |
| 2507 | GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
| 2508 | } |
| 2509 | |
| 2510 | DataContentDescription* GetFirstDataContentDescription( |
| 2511 | SessionDescription* sdesc) { |
| 2512 | return static_cast<DataContentDescription*>( |
| 2513 | GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
| 2514 | } |
| 2515 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2516 | } // namespace cricket |