blob: b40974039b820a965f57d57f35c689021c445430 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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:36 +00009 */
10
11// Types and classes used in media session descriptions.
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#ifndef PC_MEDIASESSION_H_
14#define PC_MEDIASESSION_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000016#include <algorithm>
deadbeef0ed85b22016-02-23 17:24:52 -080017#include <map>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
19#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/mediatypes.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "media/base/mediaconstants.h"
23#include "media/base/mediaengine.h" // For DataChannelType
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "p2p/base/transportdescriptionfactory.h"
Zhi Huang365381f2018-04-13 16:44:34 -070025#include "pc/jseptransport.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080026#include "pc/sessiondescription.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28namespace cricket {
29
30class ChannelManager;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031
zhihuang8f65cdf2016-05-06 18:40:30 -070032// Default RTCP CNAME for unit tests.
33const char kDefaultRtcpCname[] = "DefaultRtcpCname";
34
zhihuang1c378ed2017-08-17 14:10:50 -070035// Options for an RtpSender contained with an media description/"m=" section.
36struct SenderOptions {
37 std::string track_id;
Steve Anton8ffb9c32017-08-31 15:45:38 -070038 std::vector<std::string> stream_ids;
zhihuang1c378ed2017-08-17 14:10:50 -070039 int num_sim_layers;
40};
jiayl@webrtc.org742922b2014-10-07 21:32:43 +000041
zhihuang1c378ed2017-08-17 14:10:50 -070042// Options for an individual media description/"m=" section.
43struct MediaDescriptionOptions {
44 MediaDescriptionOptions(MediaType type,
45 const std::string& mid,
Steve Anton1d03a752017-11-27 14:30:09 -080046 webrtc::RtpTransceiverDirection direction,
zhihuang1c378ed2017-08-17 14:10:50 -070047 bool stopped)
48 : type(type), mid(mid), direction(direction), stopped(stopped) {}
zhihuanga77e6bb2017-08-14 18:17:48 -070049
zhihuang1c378ed2017-08-17 14:10:50 -070050 // TODO(deadbeef): When we don't support Plan B, there will only be one
51 // sender per media description and this can be simplified.
52 void AddAudioSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -070053 const std::vector<std::string>& stream_ids);
zhihuang1c378ed2017-08-17 14:10:50 -070054 void AddVideoSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -070055 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -070056 int num_sim_layers);
zhihuanga77e6bb2017-08-14 18:17:48 -070057
zhihuang1c378ed2017-08-17 14:10:50 -070058 // Internally just uses sender_options.
59 void AddRtpDataChannel(const std::string& track_id,
60 const std::string& stream_id);
olka3c747662017-08-17 06:50:32 -070061
zhihuang1c378ed2017-08-17 14:10:50 -070062 MediaType type;
63 std::string mid;
Steve Anton1d03a752017-11-27 14:30:09 -080064 webrtc::RtpTransceiverDirection direction;
zhihuang1c378ed2017-08-17 14:10:50 -070065 bool stopped;
66 TransportOptions transport_options;
67 // Note: There's no equivalent "RtpReceiverOptions" because only send
68 // stream information goes in the local descriptions.
69 std::vector<SenderOptions> sender_options;
70
71 private:
72 // Doesn't DCHECK on |type|.
73 void AddSenderInternal(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -070074 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -070075 int num_sim_layers);
zhihuang1c378ed2017-08-17 14:10:50 -070076};
olka3c747662017-08-17 06:50:32 -070077
zhihuang1c378ed2017-08-17 14:10:50 -070078// Provides a mechanism for describing how m= sections should be generated.
79// The m= section with index X will use media_description_options[X]. There
80// must be an option for each existing section if creating an answer, or a
81// subsequent offer.
82struct MediaSessionOptions {
83 MediaSessionOptions() {}
olka3c747662017-08-17 06:50:32 -070084
zhihuang1c378ed2017-08-17 14:10:50 -070085 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
86 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
87 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); }
88
89 bool HasMediaDescription(MediaType type) const;
90
91 DataChannelType data_channel_type = DCT_NONE;
zhihuang1c378ed2017-08-17 14:10:50 -070092 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
93 bool rtcp_mux_enabled = true;
94 bool bundle_enabled = false;
Steve Antone831b8c2018-02-01 12:22:16 -080095 bool is_unified_plan = false;
zhihuang1c378ed2017-08-17 14:10:50 -070096 std::string rtcp_cname = kDefaultRtcpCname;
jbauchcb560652016-08-04 05:20:32 -070097 rtc::CryptoOptions crypto_options;
zhihuang1c378ed2017-08-17 14:10:50 -070098 // List of media description options in the same order that the media
99 // descriptions will be generated.
100 std::vector<MediaDescriptionOptions> media_description_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101};
102
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103// Creates media session descriptions according to the supplied codecs and
104// other fields, as well as the supplied per-call options.
105// When creating answers, performs the appropriate negotiation
106// of the various fields to determine the proper result.
107class MediaSessionDescriptionFactory {
108 public:
109 // Default ctor; use methods below to set configuration.
110 // The TransportDescriptionFactory is not owned by MediaSessionDescFactory,
111 // so it must be kept alive by the user of this class.
112 explicit MediaSessionDescriptionFactory(
113 const TransportDescriptionFactory* factory);
114 // This helper automatically sets up the factory to get its configuration
115 // from the specified ChannelManager.
116 MediaSessionDescriptionFactory(ChannelManager* cmanager,
117 const TransportDescriptionFactory* factory);
118
ossudedfd282016-06-14 07:12:39 -0700119 const AudioCodecs& audio_sendrecv_codecs() const;
ossu075af922016-06-14 03:29:38 -0700120 const AudioCodecs& audio_send_codecs() const;
121 const AudioCodecs& audio_recv_codecs() const;
122 void set_audio_codecs(const AudioCodecs& send_codecs,
123 const AudioCodecs& recv_codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
125 audio_rtp_extensions_ = extensions;
126 }
Steve Anton1b8773d2018-04-06 11:13:34 -0700127 RtpHeaderExtensions audio_rtp_header_extensions(bool unified_plan) const {
128 RtpHeaderExtensions extensions = audio_rtp_extensions_;
129 // If we are Unified Plan, also offer the MID header extension.
130 if (unified_plan) {
131 extensions.push_back(webrtc::RtpExtension(
132 webrtc::RtpExtension::kMidUri, webrtc::RtpExtension::kMidDefaultId));
133 }
134 return extensions;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 }
136 const VideoCodecs& video_codecs() const { return video_codecs_; }
137 void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; }
138 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
139 video_rtp_extensions_ = extensions;
140 }
Steve Anton1b8773d2018-04-06 11:13:34 -0700141 RtpHeaderExtensions video_rtp_header_extensions(bool unified_plan) const {
142 RtpHeaderExtensions extensions = video_rtp_extensions_;
143 // If we are Unified Plan, also offer the MID header extension.
144 if (unified_plan) {
145 extensions.push_back(webrtc::RtpExtension(
146 webrtc::RtpExtension::kMidUri, webrtc::RtpExtension::kMidDefaultId));
147 }
148 return extensions;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 }
150 const DataCodecs& data_codecs() const { return data_codecs_; }
151 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
152 SecurePolicy secure() const { return secure_; }
153 void set_secure(SecurePolicy s) { secure_ = s; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154
jbauch5869f502017-06-29 12:31:36 -0700155 void set_enable_encrypted_rtp_header_extensions(bool enable) {
156 enable_encrypted_rtp_header_extensions_ = enable;
157 }
158
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 SessionDescription* CreateOffer(
160 const MediaSessionOptions& options,
161 const SessionDescription* current_description) const;
162 SessionDescription* CreateAnswer(
zstein4b2e0822017-02-17 19:48:38 -0800163 const SessionDescription* offer,
164 const MediaSessionOptions& options,
165 const SessionDescription* current_description) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166
167 private:
ossu075af922016-06-14 03:29:38 -0700168 const AudioCodecs& GetAudioCodecsForOffer(
Steve Anton1d03a752017-11-27 14:30:09 -0800169 const webrtc::RtpTransceiverDirection& direction) const;
ossu075af922016-06-14 03:29:38 -0700170 const AudioCodecs& GetAudioCodecsForAnswer(
Steve Anton1d03a752017-11-27 14:30:09 -0800171 const webrtc::RtpTransceiverDirection& offer,
172 const webrtc::RtpTransceiverDirection& answer) const;
zhihuang1c378ed2017-08-17 14:10:50 -0700173 void GetCodecsForOffer(const SessionDescription* current_description,
174 AudioCodecs* audio_codecs,
175 VideoCodecs* video_codecs,
176 DataCodecs* data_codecs) const;
177 void GetCodecsForAnswer(const SessionDescription* current_description,
178 const SessionDescription* remote_offer,
179 AudioCodecs* audio_codecs,
180 VideoCodecs* video_codecs,
181 DataCodecs* data_codecs) const;
Steve Anton1b8773d2018-04-06 11:13:34 -0700182 void GetRtpHdrExtsToOffer(const MediaSessionOptions& session_options,
183 const SessionDescription* current_description,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 RtpHeaderExtensions* audio_extensions,
185 RtpHeaderExtensions* video_extensions) const;
Yves Gerey665174f2018-06-19 15:03:05 +0200186 bool AddTransportOffer(const std::string& content_name,
187 const TransportOptions& transport_options,
188 const SessionDescription* current_desc,
189 SessionDescription* offer) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190
191 TransportDescription* CreateTransportAnswer(
192 const std::string& content_name,
193 const SessionDescription* offer_desc,
194 const TransportOptions& transport_options,
deadbeefb7892532017-02-22 19:35:18 -0800195 const SessionDescription* current_desc,
196 bool require_transport_attributes) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197
Yves Gerey665174f2018-06-19 15:03:05 +0200198 bool AddTransportAnswer(const std::string& content_name,
199 const TransportDescription& transport_desc,
200 SessionDescription* answer_desc) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000202 // Helpers for adding media contents to the SessionDescription. Returns true
203 // it succeeds or the media content is not needed, or false if there is any
204 // error.
205
206 bool AddAudioContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700207 const MediaDescriptionOptions& media_description_options,
208 const MediaSessionOptions& session_options,
209 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000210 const SessionDescription* current_description,
211 const RtpHeaderExtensions& audio_rtp_extensions,
212 const AudioCodecs& audio_codecs,
213 StreamParamsVec* current_streams,
214 SessionDescription* desc) const;
215
216 bool AddVideoContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700217 const MediaDescriptionOptions& media_description_options,
218 const MediaSessionOptions& session_options,
219 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000220 const SessionDescription* current_description,
221 const RtpHeaderExtensions& video_rtp_extensions,
222 const VideoCodecs& video_codecs,
223 StreamParamsVec* current_streams,
224 SessionDescription* desc) const;
225
226 bool AddDataContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700227 const MediaDescriptionOptions& media_description_options,
228 const MediaSessionOptions& session_options,
229 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000230 const SessionDescription* current_description,
zhihuang1c378ed2017-08-17 14:10:50 -0700231 const DataCodecs& data_codecs,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000232 StreamParamsVec* current_streams,
233 SessionDescription* desc) const;
234
zhihuang1c378ed2017-08-17 14:10:50 -0700235 bool AddAudioContentForAnswer(
236 const MediaDescriptionOptions& media_description_options,
237 const MediaSessionOptions& session_options,
238 const ContentInfo* offer_content,
239 const SessionDescription* offer_description,
240 const ContentInfo* current_content,
241 const SessionDescription* current_description,
242 const TransportInfo* bundle_transport,
243 const AudioCodecs& audio_codecs,
244 StreamParamsVec* current_streams,
245 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000246
zhihuang1c378ed2017-08-17 14:10:50 -0700247 bool AddVideoContentForAnswer(
248 const MediaDescriptionOptions& media_description_options,
249 const MediaSessionOptions& session_options,
250 const ContentInfo* offer_content,
251 const SessionDescription* offer_description,
252 const ContentInfo* current_content,
253 const SessionDescription* current_description,
254 const TransportInfo* bundle_transport,
255 const VideoCodecs& video_codecs,
256 StreamParamsVec* current_streams,
257 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000258
zhihuang1c378ed2017-08-17 14:10:50 -0700259 bool AddDataContentForAnswer(
260 const MediaDescriptionOptions& media_description_options,
261 const MediaSessionOptions& session_options,
262 const ContentInfo* offer_content,
263 const SessionDescription* offer_description,
264 const ContentInfo* current_content,
265 const SessionDescription* current_description,
266 const TransportInfo* bundle_transport,
267 const DataCodecs& data_codecs,
268 StreamParamsVec* current_streams,
269 SessionDescription* answer) const;
270
271 void ComputeAudioCodecsIntersectionAndUnion();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000272
ossu075af922016-06-14 03:29:38 -0700273 AudioCodecs audio_send_codecs_;
274 AudioCodecs audio_recv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700275 // Intersection of send and recv.
ossu075af922016-06-14 03:29:38 -0700276 AudioCodecs audio_sendrecv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700277 // Union of send and recv.
278 AudioCodecs all_audio_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 RtpHeaderExtensions audio_rtp_extensions_;
280 VideoCodecs video_codecs_;
281 RtpHeaderExtensions video_rtp_extensions_;
282 DataCodecs data_codecs_;
jbauch5869f502017-06-29 12:31:36 -0700283 bool enable_encrypted_rtp_header_extensions_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700284 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter
285 // and setter.
286 SecurePolicy secure_ = SEC_DISABLED;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 const TransportDescriptionFactory* transport_desc_factory_;
288};
289
290// Convenience functions.
291bool IsMediaContent(const ContentInfo* content);
292bool IsAudioContent(const ContentInfo* content);
293bool IsVideoContent(const ContentInfo* content);
294bool IsDataContent(const ContentInfo* content);
deadbeef0ed85b22016-02-23 17:24:52 -0800295const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
296 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297const ContentInfo* GetFirstAudioContent(const ContentInfos& contents);
298const ContentInfo* GetFirstVideoContent(const ContentInfos& contents);
299const ContentInfo* GetFirstDataContent(const ContentInfos& contents);
Steve Antonad7bffc2018-01-22 10:21:56 -0800300const ContentInfo* GetFirstMediaContent(const SessionDescription* sdesc,
301 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc);
303const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc);
304const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc);
305const AudioContentDescription* GetFirstAudioContentDescription(
306 const SessionDescription* sdesc);
307const VideoContentDescription* GetFirstVideoContentDescription(
308 const SessionDescription* sdesc);
309const DataContentDescription* GetFirstDataContentDescription(
310 const SessionDescription* sdesc);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700311// Non-const versions of the above functions.
312// Useful when modifying an existing description.
Steve Anton36b29d12017-10-30 09:57:42 -0700313ContentInfo* GetFirstMediaContent(ContentInfos* contents, MediaType media_type);
314ContentInfo* GetFirstAudioContent(ContentInfos* contents);
315ContentInfo* GetFirstVideoContent(ContentInfos* contents);
316ContentInfo* GetFirstDataContent(ContentInfos* contents);
Steve Antonad7bffc2018-01-22 10:21:56 -0800317ContentInfo* GetFirstMediaContent(SessionDescription* sdesc,
318 MediaType media_type);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700319ContentInfo* GetFirstAudioContent(SessionDescription* sdesc);
320ContentInfo* GetFirstVideoContent(SessionDescription* sdesc);
321ContentInfo* GetFirstDataContent(SessionDescription* sdesc);
322AudioContentDescription* GetFirstAudioContentDescription(
323 SessionDescription* sdesc);
324VideoContentDescription* GetFirstVideoContentDescription(
325 SessionDescription* sdesc);
326DataContentDescription* GetFirstDataContentDescription(
327 SessionDescription* sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328
deadbeef7914b8c2017-04-21 03:23:33 -0700329// Helper functions to return crypto suites used for SDES.
330void GetSupportedAudioSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
331 std::vector<int>* crypto_suites);
332void GetSupportedVideoSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
333 std::vector<int>* crypto_suites);
334void GetSupportedDataSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
335 std::vector<int>* crypto_suites);
336void GetSupportedAudioSdesCryptoSuiteNames(
337 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800338 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700339void GetSupportedVideoSdesCryptoSuiteNames(
340 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800341 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700342void GetSupportedDataSdesCryptoSuiteNames(
343 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800344 std::vector<std::string>* crypto_suite_names);
345
Steve Antonfa2260d2017-12-28 16:38:23 -0800346// Returns true if the given media section protocol indicates use of RTP.
347bool IsRtpProtocol(const std::string& protocol);
348
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349} // namespace cricket
350
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200351#endif // PC_MEDIASESSION_H_