blob: b1df1dbd260a3746df58c0b6724437e0975a8c56 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:361/*
kjellander65c7f672016-02-12 08:05:012 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:363 *
kjellander65c7f672016-02-12 08:05:014 * 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.org28e20752013-07-10 00:45:369 */
10
11// Types and classes used in media session descriptions.
12
Mirko Bonadei92ea95e2017-09-15 04:47:3113#ifndef PC_MEDIASESSION_H_
14#define PC_MEDIASESSION_H_
henrike@webrtc.org28e20752013-07-10 00:45:3615
buildbot@webrtc.orga09a9992014-08-13 17:26:0816#include <algorithm>
deadbeef0ed85b22016-02-24 01:24:5217#include <map>
henrike@webrtc.org28e20752013-07-10 00:45:3618#include <string>
19#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:3620
Mirko Bonadei92ea95e2017-09-15 04:47:3121#include "api/mediatypes.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "media/base/mediaconstants.h"
23#include "media/base/mediaengine.h" // For DataChannelType
Jonas Oreland1cd39fa2018-10-11 05:47:1224#include "p2p/base/icecredentialsiterator.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "p2p/base/transportdescriptionfactory.h"
Zhi Huang365381f2018-04-13 23:44:3426#include "pc/jseptransport.h"
Steve Anton4ab68ee2017-12-19 22:26:1127#include "pc/sessiondescription.h"
henrike@webrtc.org28e20752013-07-10 00:45:3628
29namespace cricket {
30
31class ChannelManager;
henrike@webrtc.org28e20752013-07-10 00:45:3632
zhihuang8f65cdf2016-05-07 01:40:3033// Default RTCP CNAME for unit tests.
34const char kDefaultRtcpCname[] = "DefaultRtcpCname";
35
zhihuang1c378ed2017-08-17 21:10:5036// Options for an RtpSender contained with an media description/"m=" section.
37struct SenderOptions {
38 std::string track_id;
Steve Anton8ffb9c32017-08-31 22:45:3839 std::vector<std::string> stream_ids;
zhihuang1c378ed2017-08-17 21:10:5040 int num_sim_layers;
41};
jiayl@webrtc.org742922b2014-10-07 21:32:4342
zhihuang1c378ed2017-08-17 21:10:5043// Options for an individual media description/"m=" section.
44struct MediaDescriptionOptions {
45 MediaDescriptionOptions(MediaType type,
46 const std::string& mid,
Steve Anton1d03a752017-11-27 22:30:0947 webrtc::RtpTransceiverDirection direction,
zhihuang1c378ed2017-08-17 21:10:5048 bool stopped)
49 : type(type), mid(mid), direction(direction), stopped(stopped) {}
zhihuanga77e6bb2017-08-15 01:17:4850
zhihuang1c378ed2017-08-17 21:10:5051 // TODO(deadbeef): When we don't support Plan B, there will only be one
52 // sender per media description and this can be simplified.
53 void AddAudioSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 22:45:3854 const std::vector<std::string>& stream_ids);
zhihuang1c378ed2017-08-17 21:10:5055 void AddVideoSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 22:45:3856 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 13:50:3257 int num_sim_layers);
zhihuanga77e6bb2017-08-15 01:17:4858
zhihuang1c378ed2017-08-17 21:10:5059 // Internally just uses sender_options.
60 void AddRtpDataChannel(const std::string& track_id,
61 const std::string& stream_id);
olka3c747662017-08-17 13:50:3262
zhihuang1c378ed2017-08-17 21:10:5063 MediaType type;
64 std::string mid;
Steve Anton1d03a752017-11-27 22:30:0965 webrtc::RtpTransceiverDirection direction;
zhihuang1c378ed2017-08-17 21:10:5066 bool stopped;
67 TransportOptions transport_options;
68 // Note: There's no equivalent "RtpReceiverOptions" because only send
69 // stream information goes in the local descriptions.
70 std::vector<SenderOptions> sender_options;
71
72 private:
73 // Doesn't DCHECK on |type|.
74 void AddSenderInternal(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 22:45:3875 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 13:50:3276 int num_sim_layers);
zhihuang1c378ed2017-08-17 21:10:5077};
olka3c747662017-08-17 13:50:3278
zhihuang1c378ed2017-08-17 21:10:5079// Provides a mechanism for describing how m= sections should be generated.
80// The m= section with index X will use media_description_options[X]. There
81// must be an option for each existing section if creating an answer, or a
82// subsequent offer.
83struct MediaSessionOptions {
84 MediaSessionOptions() {}
olka3c747662017-08-17 13:50:3285
zhihuang1c378ed2017-08-17 21:10:5086 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
87 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
88 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); }
89
90 bool HasMediaDescription(MediaType type) const;
91
92 DataChannelType data_channel_type = DCT_NONE;
zhihuang1c378ed2017-08-17 21:10:5093 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
94 bool rtcp_mux_enabled = true;
95 bool bundle_enabled = false;
Steve Antone831b8c2018-02-01 20:22:1696 bool is_unified_plan = false;
zhihuang1c378ed2017-08-17 21:10:5097 std::string rtcp_cname = kDefaultRtcpCname;
Benjamin Wrighta54daf12018-10-11 22:33:1798 webrtc::CryptoOptions crypto_options;
zhihuang1c378ed2017-08-17 21:10:5099 // List of media description options in the same order that the media
100 // descriptions will be generated.
101 std::vector<MediaDescriptionOptions> media_description_options;
Jonas Oreland1cd39fa2018-10-11 05:47:12102 std::vector<IceParameters> pooled_ice_credentials;
henrike@webrtc.org28e20752013-07-10 00:45:36103};
104
henrike@webrtc.org28e20752013-07-10 00:45:36105// Creates media session descriptions according to the supplied codecs and
106// other fields, as well as the supplied per-call options.
107// When creating answers, performs the appropriate negotiation
108// of the various fields to determine the proper result.
109class MediaSessionDescriptionFactory {
110 public:
111 // Default ctor; use methods below to set configuration.
112 // The TransportDescriptionFactory is not owned by MediaSessionDescFactory,
113 // so it must be kept alive by the user of this class.
114 explicit MediaSessionDescriptionFactory(
115 const TransportDescriptionFactory* factory);
116 // This helper automatically sets up the factory to get its configuration
117 // from the specified ChannelManager.
118 MediaSessionDescriptionFactory(ChannelManager* cmanager,
119 const TransportDescriptionFactory* factory);
120
ossudedfd282016-06-14 14:12:39121 const AudioCodecs& audio_sendrecv_codecs() const;
ossu075af922016-06-14 10:29:38122 const AudioCodecs& audio_send_codecs() const;
123 const AudioCodecs& audio_recv_codecs() const;
124 void set_audio_codecs(const AudioCodecs& send_codecs,
125 const AudioCodecs& recv_codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36126 void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
127 audio_rtp_extensions_ = extensions;
128 }
Steve Anton1b8773d2018-04-06 18:13:34129 RtpHeaderExtensions audio_rtp_header_extensions(bool unified_plan) const {
130 RtpHeaderExtensions extensions = audio_rtp_extensions_;
131 // If we are Unified Plan, also offer the MID header extension.
132 if (unified_plan) {
133 extensions.push_back(webrtc::RtpExtension(
134 webrtc::RtpExtension::kMidUri, webrtc::RtpExtension::kMidDefaultId));
135 }
136 return extensions;
henrike@webrtc.org28e20752013-07-10 00:45:36137 }
138 const VideoCodecs& video_codecs() const { return video_codecs_; }
139 void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; }
140 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
141 video_rtp_extensions_ = extensions;
142 }
Steve Anton1b8773d2018-04-06 18:13:34143 RtpHeaderExtensions video_rtp_header_extensions(bool unified_plan) const {
144 RtpHeaderExtensions extensions = video_rtp_extensions_;
145 // If we are Unified Plan, also offer the MID header extension.
146 if (unified_plan) {
147 extensions.push_back(webrtc::RtpExtension(
148 webrtc::RtpExtension::kMidUri, webrtc::RtpExtension::kMidDefaultId));
149 }
150 return extensions;
henrike@webrtc.org28e20752013-07-10 00:45:36151 }
152 const DataCodecs& data_codecs() const { return data_codecs_; }
153 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
154 SecurePolicy secure() const { return secure_; }
155 void set_secure(SecurePolicy s) { secure_ = s; }
henrike@webrtc.org28e20752013-07-10 00:45:36156
jbauch5869f502017-06-29 19:31:36157 void set_enable_encrypted_rtp_header_extensions(bool enable) {
158 enable_encrypted_rtp_header_extensions_ = enable;
159 }
160
henrike@webrtc.org28e20752013-07-10 00:45:36161 SessionDescription* CreateOffer(
162 const MediaSessionOptions& options,
163 const SessionDescription* current_description) const;
164 SessionDescription* CreateAnswer(
zstein4b2e0822017-02-18 03:48:38165 const SessionDescription* offer,
166 const MediaSessionOptions& options,
167 const SessionDescription* current_description) const;
henrike@webrtc.org28e20752013-07-10 00:45:36168
169 private:
ossu075af922016-06-14 10:29:38170 const AudioCodecs& GetAudioCodecsForOffer(
Steve Anton1d03a752017-11-27 22:30:09171 const webrtc::RtpTransceiverDirection& direction) const;
ossu075af922016-06-14 10:29:38172 const AudioCodecs& GetAudioCodecsForAnswer(
Steve Anton1d03a752017-11-27 22:30:09173 const webrtc::RtpTransceiverDirection& offer,
174 const webrtc::RtpTransceiverDirection& answer) const;
zhihuang1c378ed2017-08-17 21:10:50175 void GetCodecsForOffer(const SessionDescription* current_description,
176 AudioCodecs* audio_codecs,
177 VideoCodecs* video_codecs,
178 DataCodecs* data_codecs) const;
179 void GetCodecsForAnswer(const SessionDescription* current_description,
180 const SessionDescription* remote_offer,
181 AudioCodecs* audio_codecs,
182 VideoCodecs* video_codecs,
183 DataCodecs* data_codecs) const;
Steve Anton1b8773d2018-04-06 18:13:34184 void GetRtpHdrExtsToOffer(const MediaSessionOptions& session_options,
185 const SessionDescription* current_description,
henrike@webrtc.org28e20752013-07-10 00:45:36186 RtpHeaderExtensions* audio_extensions,
187 RtpHeaderExtensions* video_extensions) const;
Yves Gerey665174f2018-06-19 13:03:05188 bool AddTransportOffer(const std::string& content_name,
189 const TransportOptions& transport_options,
190 const SessionDescription* current_desc,
Jonas Oreland1cd39fa2018-10-11 05:47:12191 SessionDescription* offer,
192 IceCredentialsIterator* ice_credentials) const;
henrike@webrtc.org28e20752013-07-10 00:45:36193
194 TransportDescription* CreateTransportAnswer(
195 const std::string& content_name,
196 const SessionDescription* offer_desc,
197 const TransportOptions& transport_options,
deadbeefb7892532017-02-23 03:35:18198 const SessionDescription* current_desc,
Jonas Oreland1cd39fa2018-10-11 05:47:12199 bool require_transport_attributes,
200 IceCredentialsIterator* ice_credentials) const;
henrike@webrtc.org28e20752013-07-10 00:45:36201
Yves Gerey665174f2018-06-19 13:03:05202 bool AddTransportAnswer(const std::string& content_name,
203 const TransportDescription& transport_desc,
204 SessionDescription* answer_desc) const;
henrike@webrtc.org28e20752013-07-10 00:45:36205
jiayl@webrtc.orge7d47a12014-08-05 19:19:05206 // Helpers for adding media contents to the SessionDescription. Returns true
207 // it succeeds or the media content is not needed, or false if there is any
208 // error.
209
210 bool AddAudioContentForOffer(
zhihuang1c378ed2017-08-17 21:10:50211 const MediaDescriptionOptions& media_description_options,
212 const MediaSessionOptions& session_options,
213 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05214 const SessionDescription* current_description,
215 const RtpHeaderExtensions& audio_rtp_extensions,
216 const AudioCodecs& audio_codecs,
217 StreamParamsVec* current_streams,
Jonas Oreland1cd39fa2018-10-11 05:47:12218 SessionDescription* desc,
219 IceCredentialsIterator* ice_credentials) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05220
221 bool AddVideoContentForOffer(
zhihuang1c378ed2017-08-17 21:10:50222 const MediaDescriptionOptions& media_description_options,
223 const MediaSessionOptions& session_options,
224 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05225 const SessionDescription* current_description,
226 const RtpHeaderExtensions& video_rtp_extensions,
227 const VideoCodecs& video_codecs,
228 StreamParamsVec* current_streams,
Jonas Oreland1cd39fa2018-10-11 05:47:12229 SessionDescription* desc,
230 IceCredentialsIterator* ice_credentials) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05231
232 bool AddDataContentForOffer(
zhihuang1c378ed2017-08-17 21:10:50233 const MediaDescriptionOptions& media_description_options,
234 const MediaSessionOptions& session_options,
235 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05236 const SessionDescription* current_description,
zhihuang1c378ed2017-08-17 21:10:50237 const DataCodecs& data_codecs,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05238 StreamParamsVec* current_streams,
Jonas Oreland1cd39fa2018-10-11 05:47:12239 SessionDescription* desc,
240 IceCredentialsIterator* ice_credentials) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05241
zhihuang1c378ed2017-08-17 21:10:50242 bool AddAudioContentForAnswer(
243 const MediaDescriptionOptions& media_description_options,
244 const MediaSessionOptions& session_options,
245 const ContentInfo* offer_content,
246 const SessionDescription* offer_description,
247 const ContentInfo* current_content,
248 const SessionDescription* current_description,
249 const TransportInfo* bundle_transport,
250 const AudioCodecs& audio_codecs,
251 StreamParamsVec* current_streams,
Jonas Oreland1cd39fa2018-10-11 05:47:12252 SessionDescription* answer,
253 IceCredentialsIterator* ice_credentials) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05254
zhihuang1c378ed2017-08-17 21:10:50255 bool AddVideoContentForAnswer(
256 const MediaDescriptionOptions& media_description_options,
257 const MediaSessionOptions& session_options,
258 const ContentInfo* offer_content,
259 const SessionDescription* offer_description,
260 const ContentInfo* current_content,
261 const SessionDescription* current_description,
262 const TransportInfo* bundle_transport,
263 const VideoCodecs& video_codecs,
264 StreamParamsVec* current_streams,
Jonas Oreland1cd39fa2018-10-11 05:47:12265 SessionDescription* answer,
266 IceCredentialsIterator* ice_credentials) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05267
zhihuang1c378ed2017-08-17 21:10:50268 bool AddDataContentForAnswer(
269 const MediaDescriptionOptions& media_description_options,
270 const MediaSessionOptions& session_options,
271 const ContentInfo* offer_content,
272 const SessionDescription* offer_description,
273 const ContentInfo* current_content,
274 const SessionDescription* current_description,
275 const TransportInfo* bundle_transport,
276 const DataCodecs& data_codecs,
277 StreamParamsVec* current_streams,
Jonas Oreland1cd39fa2018-10-11 05:47:12278 SessionDescription* answer,
279 IceCredentialsIterator* ice_credentials) const;
zhihuang1c378ed2017-08-17 21:10:50280
281 void ComputeAudioCodecsIntersectionAndUnion();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05282
ossu075af922016-06-14 10:29:38283 AudioCodecs audio_send_codecs_;
284 AudioCodecs audio_recv_codecs_;
zhihuang1c378ed2017-08-17 21:10:50285 // Intersection of send and recv.
ossu075af922016-06-14 10:29:38286 AudioCodecs audio_sendrecv_codecs_;
zhihuang1c378ed2017-08-17 21:10:50287 // Union of send and recv.
288 AudioCodecs all_audio_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36289 RtpHeaderExtensions audio_rtp_extensions_;
290 VideoCodecs video_codecs_;
291 RtpHeaderExtensions video_rtp_extensions_;
292 DataCodecs data_codecs_;
jbauch5869f502017-06-29 19:31:36293 bool enable_encrypted_rtp_header_extensions_ = false;
zhihuang1c378ed2017-08-17 21:10:50294 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter
295 // and setter.
296 SecurePolicy secure_ = SEC_DISABLED;
henrike@webrtc.org28e20752013-07-10 00:45:36297 const TransportDescriptionFactory* transport_desc_factory_;
298};
299
300// Convenience functions.
301bool IsMediaContent(const ContentInfo* content);
302bool IsAudioContent(const ContentInfo* content);
303bool IsVideoContent(const ContentInfo* content);
304bool IsDataContent(const ContentInfo* content);
deadbeef0ed85b22016-02-24 01:24:52305const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
306 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36307const ContentInfo* GetFirstAudioContent(const ContentInfos& contents);
308const ContentInfo* GetFirstVideoContent(const ContentInfos& contents);
309const ContentInfo* GetFirstDataContent(const ContentInfos& contents);
Steve Antonad7bffc2018-01-22 18:21:56310const ContentInfo* GetFirstMediaContent(const SessionDescription* sdesc,
311 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36312const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc);
313const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc);
314const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc);
315const AudioContentDescription* GetFirstAudioContentDescription(
316 const SessionDescription* sdesc);
317const VideoContentDescription* GetFirstVideoContentDescription(
318 const SessionDescription* sdesc);
319const DataContentDescription* GetFirstDataContentDescription(
320 const SessionDescription* sdesc);
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50321// Non-const versions of the above functions.
322// Useful when modifying an existing description.
Steve Anton36b29d12017-10-30 16:57:42323ContentInfo* GetFirstMediaContent(ContentInfos* contents, MediaType media_type);
324ContentInfo* GetFirstAudioContent(ContentInfos* contents);
325ContentInfo* GetFirstVideoContent(ContentInfos* contents);
326ContentInfo* GetFirstDataContent(ContentInfos* contents);
Steve Antonad7bffc2018-01-22 18:21:56327ContentInfo* GetFirstMediaContent(SessionDescription* sdesc,
328 MediaType media_type);
Taylor Brandstetterdc4eb8c2016-05-12 15:14:50329ContentInfo* GetFirstAudioContent(SessionDescription* sdesc);
330ContentInfo* GetFirstVideoContent(SessionDescription* sdesc);
331ContentInfo* GetFirstDataContent(SessionDescription* sdesc);
332AudioContentDescription* GetFirstAudioContentDescription(
333 SessionDescription* sdesc);
334VideoContentDescription* GetFirstVideoContentDescription(
335 SessionDescription* sdesc);
336DataContentDescription* GetFirstDataContentDescription(
337 SessionDescription* sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36338
deadbeef7914b8c2017-04-21 10:23:33339// Helper functions to return crypto suites used for SDES.
Benjamin Wrighta54daf12018-10-11 22:33:17340void GetSupportedAudioSdesCryptoSuites(
341 const webrtc::CryptoOptions& crypto_options,
342 std::vector<int>* crypto_suites);
343void GetSupportedVideoSdesCryptoSuites(
344 const webrtc::CryptoOptions& crypto_options,
345 std::vector<int>* crypto_suites);
346void GetSupportedDataSdesCryptoSuites(
347 const webrtc::CryptoOptions& crypto_options,
348 std::vector<int>* crypto_suites);
deadbeef7914b8c2017-04-21 10:23:33349void GetSupportedAudioSdesCryptoSuiteNames(
Benjamin Wrighta54daf12018-10-11 22:33:17350 const webrtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-19 03:41:53351 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 10:23:33352void GetSupportedVideoSdesCryptoSuiteNames(
Benjamin Wrighta54daf12018-10-11 22:33:17353 const webrtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-19 03:41:53354 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 10:23:33355void GetSupportedDataSdesCryptoSuiteNames(
Benjamin Wrighta54daf12018-10-11 22:33:17356 const webrtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-19 03:41:53357 std::vector<std::string>* crypto_suite_names);
358
Steve Antonfa2260d2017-12-29 00:38:23359// Returns true if the given media section protocol indicates use of RTP.
360bool IsRtpProtocol(const std::string& protocol);
361
henrike@webrtc.org28e20752013-07-10 00:45:36362} // namespace cricket
363
Mirko Bonadei92ea95e2017-09-15 04:47:31364#endif // PC_MEDIASESSION_H_