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