blob: 22770001f0784bea48d1565802294c3c3bd043df [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
Patrik Höglund7aee3d52017-11-15 13:15:17 +010021#include "api/cryptoparams.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/mediatypes.h"
23#include "media/base/codec.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "media/base/mediachannel.h"
25#include "media/base/mediaconstants.h"
26#include "media/base/mediaengine.h" // For DataChannelType
27#include "media/base/streamparams.h"
28#include "p2p/base/sessiondescription.h"
29#include "p2p/base/jseptransport.h"
30#include "p2p/base/transportdescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031
32namespace cricket {
33
34class ChannelManager;
35typedef std::vector<AudioCodec> AudioCodecs;
36typedef std::vector<VideoCodec> VideoCodecs;
37typedef std::vector<DataCodec> DataCodecs;
38typedef std::vector<CryptoParams> CryptoParamsVec;
isheriff6f8d6862016-05-26 11:24:55 -070039typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041enum MediaContentDirection {
42 MD_INACTIVE,
43 MD_SENDONLY,
44 MD_RECVONLY,
45 MD_SENDRECV
46};
47
ossu075af922016-06-14 03:29:38 -070048std::string MediaContentDirectionToString(MediaContentDirection direction);
49
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000050enum CryptoType {
51 CT_NONE,
52 CT_SDES,
53 CT_DTLS
54};
55
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056// RTC4585 RTP/AVPF
57extern const char kMediaProtocolAvpf[];
58// RFC5124 RTP/SAVPF
59extern const char kMediaProtocolSavpf[];
60
jiayl@webrtc.org8dcd43c2014-05-29 22:07:59 +000061extern const char kMediaProtocolDtlsSavpf[];
62
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063extern const char kMediaProtocolRtpPrefix[];
64
65extern const char kMediaProtocolSctp[];
66extern const char kMediaProtocolDtlsSctp[];
lally@webrtc.orgec97c652015-02-24 20:18:48 +000067extern const char kMediaProtocolUdpDtlsSctp[];
lally@webrtc.orga7470932015-02-24 20:19:21 +000068extern const char kMediaProtocolTcpDtlsSctp[];
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069
70// Options to control how session descriptions are generated.
71const int kAutoBandwidth = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072
zhihuang8f65cdf2016-05-06 18:40:30 -070073// Default RTCP CNAME for unit tests.
74const char kDefaultRtcpCname[] = "DefaultRtcpCname";
75
ossu075af922016-06-14 03:29:38 -070076struct RtpTransceiverDirection {
77 bool send;
78 bool recv;
79
80 RtpTransceiverDirection(bool send, bool recv) : send(send), recv(recv) {}
81
82 bool operator==(const RtpTransceiverDirection& o) const {
83 return send == o.send && recv == o.recv;
84 }
85
86 bool operator!=(const RtpTransceiverDirection& o) const {
87 return !(*this == o);
88 }
89
90 static RtpTransceiverDirection FromMediaContentDirection(
91 MediaContentDirection md);
92
93 MediaContentDirection ToMediaContentDirection() const;
deadbeefe814a0d2017-02-25 18:15:09 -080094
95 RtpTransceiverDirection Reversed() const {
96 return RtpTransceiverDirection(recv, send);
97 }
ossu075af922016-06-14 03:29:38 -070098};
99
100RtpTransceiverDirection
101NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer,
102 RtpTransceiverDirection wants);
103
zhihuang1c378ed2017-08-17 14:10:50 -0700104// Options for an RtpSender contained with an media description/"m=" section.
105struct SenderOptions {
106 std::string track_id;
Steve Anton8ffb9c32017-08-31 15:45:38 -0700107 // TODO(steveanton): As part of work towards Unified Plan, this has been
108 // changed to be a vector. But for now this can only have exactly one.
109 std::vector<std::string> stream_ids;
zhihuang1c378ed2017-08-17 14:10:50 -0700110 int num_sim_layers;
111};
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000112
zhihuang1c378ed2017-08-17 14:10:50 -0700113// Options for an individual media description/"m=" section.
114struct MediaDescriptionOptions {
115 MediaDescriptionOptions(MediaType type,
116 const std::string& mid,
117 RtpTransceiverDirection direction,
118 bool stopped)
119 : type(type), mid(mid), direction(direction), stopped(stopped) {}
zhihuanga77e6bb2017-08-14 18:17:48 -0700120
zhihuang1c378ed2017-08-17 14:10:50 -0700121 // TODO(deadbeef): When we don't support Plan B, there will only be one
122 // sender per media description and this can be simplified.
123 void AddAudioSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700124 const std::vector<std::string>& stream_ids);
zhihuang1c378ed2017-08-17 14:10:50 -0700125 void AddVideoSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700126 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -0700127 int num_sim_layers);
zhihuanga77e6bb2017-08-14 18:17:48 -0700128
zhihuang1c378ed2017-08-17 14:10:50 -0700129 // Internally just uses sender_options.
130 void AddRtpDataChannel(const std::string& track_id,
131 const std::string& stream_id);
olka3c747662017-08-17 06:50:32 -0700132
zhihuang1c378ed2017-08-17 14:10:50 -0700133 MediaType type;
134 std::string mid;
135 RtpTransceiverDirection direction;
136 bool stopped;
137 TransportOptions transport_options;
138 // Note: There's no equivalent "RtpReceiverOptions" because only send
139 // stream information goes in the local descriptions.
140 std::vector<SenderOptions> sender_options;
141
142 private:
143 // Doesn't DCHECK on |type|.
144 void AddSenderInternal(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700145 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -0700146 int num_sim_layers);
zhihuang1c378ed2017-08-17 14:10:50 -0700147};
olka3c747662017-08-17 06:50:32 -0700148
zhihuang1c378ed2017-08-17 14:10:50 -0700149// Provides a mechanism for describing how m= sections should be generated.
150// The m= section with index X will use media_description_options[X]. There
151// must be an option for each existing section if creating an answer, or a
152// subsequent offer.
153struct MediaSessionOptions {
154 MediaSessionOptions() {}
olka3c747662017-08-17 06:50:32 -0700155
zhihuang1c378ed2017-08-17 14:10:50 -0700156 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
157 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
158 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); }
159
160 bool HasMediaDescription(MediaType type) const;
161
162 DataChannelType data_channel_type = DCT_NONE;
163 bool is_muc = false;
164 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
165 bool rtcp_mux_enabled = true;
166 bool bundle_enabled = false;
167 std::string rtcp_cname = kDefaultRtcpCname;
jbauchcb560652016-08-04 05:20:32 -0700168 rtc::CryptoOptions crypto_options;
zhihuang1c378ed2017-08-17 14:10:50 -0700169 // List of media description options in the same order that the media
170 // descriptions will be generated.
171 std::vector<MediaDescriptionOptions> media_description_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172};
173
174// "content" (as used in XEP-0166) descriptions for voice and video.
175class MediaContentDescription : public ContentDescription {
176 public:
deadbeef13871492015-12-09 12:37:51 -0800177 MediaContentDescription() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178
179 virtual MediaType type() const = 0;
180 virtual bool has_codecs() const = 0;
181
182 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
183 // RTP/SAVPF or SCTP/DTLS.
184 std::string protocol() const { return protocol_; }
185 void set_protocol(const std::string& protocol) { protocol_ = protocol; }
186
187 MediaContentDirection direction() const { return direction_; }
188 void set_direction(MediaContentDirection direction) {
189 direction_ = direction;
190 }
191
192 bool rtcp_mux() const { return rtcp_mux_; }
193 void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
194
deadbeef13871492015-12-09 12:37:51 -0800195 bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
196 void set_rtcp_reduced_size(bool reduced_size) {
197 rtcp_reduced_size_ = reduced_size;
198 }
199
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 int bandwidth() const { return bandwidth_; }
201 void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
202
203 const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
204 void AddCrypto(const CryptoParams& params) {
205 cryptos_.push_back(params);
206 }
207 void set_cryptos(const std::vector<CryptoParams>& cryptos) {
208 cryptos_ = cryptos;
209 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000210
211 CryptoType crypto_required() const { return crypto_required_; }
212 void set_crypto_required(CryptoType type) {
213 crypto_required_ = type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 }
215
216 const RtpHeaderExtensions& rtp_header_extensions() const {
217 return rtp_header_extensions_;
218 }
219 void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
220 rtp_header_extensions_ = extensions;
221 rtp_header_extensions_set_ = true;
222 }
isheriff6f8d6862016-05-26 11:24:55 -0700223 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 rtp_header_extensions_.push_back(ext);
225 rtp_header_extensions_set_ = true;
226 }
isheriffa1c548b2016-05-31 16:12:24 -0700227 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
228 webrtc::RtpExtension webrtc_extension;
229 webrtc_extension.uri = ext.uri;
230 webrtc_extension.id = ext.id;
231 rtp_header_extensions_.push_back(webrtc_extension);
232 rtp_header_extensions_set_ = true;
233 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 void ClearRtpHeaderExtensions() {
235 rtp_header_extensions_.clear();
236 rtp_header_extensions_set_ = true;
237 }
238 // We can't always tell if an empty list of header extensions is
239 // because the other side doesn't support them, or just isn't hooked up to
240 // signal them. For now we assume an empty list means no signaling, but
241 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
242 // clearly indicated (i.e. when derived from other information).
243 bool rtp_header_extensions_set() const {
244 return rtp_header_extensions_set_;
245 }
246 // True iff the client supports multiple streams.
247 void set_multistream(bool multistream) { multistream_ = multistream; }
248 bool multistream() const { return multistream_; }
249 const StreamParamsVec& streams() const {
250 return streams_;
251 }
252 // TODO(pthatcher): Remove this by giving mediamessage.cc access
253 // to MediaContentDescription
254 StreamParamsVec& mutable_streams() {
255 return streams_;
256 }
257 void AddStream(const StreamParams& stream) {
258 streams_.push_back(stream);
259 }
260 // Legacy streams have an ssrc, but nothing else.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200261 void AddLegacyStream(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 streams_.push_back(StreamParams::CreateLegacy(ssrc));
263 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200264 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000265 StreamParams sp = StreamParams::CreateLegacy(ssrc);
266 sp.AddFidSsrc(ssrc, fid_ssrc);
267 streams_.push_back(sp);
268 }
269 // Sets the CNAME of all StreamParams if it have not been set.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 void SetCnameIfEmpty(const std::string& cname) {
271 for (cricket::StreamParamsVec::iterator it = streams_.begin();
272 it != streams_.end(); ++it) {
273 if (it->cname.empty())
274 it->cname = cname;
275 }
276 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200277 uint32_t first_ssrc() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 if (streams_.empty()) {
279 return 0;
280 }
281 return streams_[0].first_ssrc();
282 }
283 bool has_ssrcs() const {
284 if (streams_.empty()) {
285 return false;
286 }
287 return streams_[0].has_ssrcs();
288 }
289
290 void set_conference_mode(bool enable) { conference_mode_ = enable; }
291 bool conference_mode() const { return conference_mode_; }
292
293 void set_partial(bool partial) { partial_ = partial; }
294 bool partial() const { return partial_; }
295
zhihuang38989e52017-03-21 11:04:53 -0700296 // https://tools.ietf.org/html/rfc4566#section-5.7
297 // May be present at the media or session level of SDP. If present at both
298 // levels, the media-level attribute overwrites the session-level one.
299 void set_connection_address(const rtc::SocketAddress& address) {
300 connection_address_ = address;
301 }
302 const rtc::SocketAddress& connection_address() const {
303 return connection_address_;
304 }
305
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 protected:
deadbeef13871492015-12-09 12:37:51 -0800307 bool rtcp_mux_ = false;
308 bool rtcp_reduced_size_ = false;
309 int bandwidth_ = kAutoBandwidth;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 std::string protocol_;
311 std::vector<CryptoParams> cryptos_;
deadbeef13871492015-12-09 12:37:51 -0800312 CryptoType crypto_required_ = CT_NONE;
isheriff6f8d6862016-05-26 11:24:55 -0700313 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
deadbeef13871492015-12-09 12:37:51 -0800314 bool rtp_header_extensions_set_ = false;
315 bool multistream_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 StreamParamsVec streams_;
deadbeef13871492015-12-09 12:37:51 -0800317 bool conference_mode_ = false;
318 bool partial_ = false;
deadbeef13871492015-12-09 12:37:51 -0800319 MediaContentDirection direction_ = MD_SENDRECV;
zhihuang38989e52017-03-21 11:04:53 -0700320 rtc::SocketAddress connection_address_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321};
322
323template <class C>
324class MediaContentDescriptionImpl : public MediaContentDescription {
325 public:
deadbeef67cf2c12016-04-13 10:07:16 -0700326 typedef C CodecType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327
deadbeef67cf2c12016-04-13 10:07:16 -0700328 // Codecs should be in preference order (most preferred codec first).
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 const std::vector<C>& codecs() const { return codecs_; }
330 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
331 virtual bool has_codecs() const { return !codecs_.empty(); }
332 bool HasCodec(int id) {
333 bool found = false;
334 for (typename std::vector<C>::iterator iter = codecs_.begin();
335 iter != codecs_.end(); ++iter) {
336 if (iter->id == id) {
337 found = true;
338 break;
339 }
340 }
341 return found;
342 }
343 void AddCodec(const C& codec) {
344 codecs_.push_back(codec);
345 }
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000346 void AddOrReplaceCodec(const C& codec) {
347 for (typename std::vector<C>::iterator iter = codecs_.begin();
348 iter != codecs_.end(); ++iter) {
349 if (iter->id == codec.id) {
350 *iter = codec;
351 return;
352 }
353 }
354 AddCodec(codec);
355 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 void AddCodecs(const std::vector<C>& codecs) {
357 typename std::vector<C>::const_iterator codec;
358 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
359 AddCodec(*codec);
360 }
361 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362
363 private:
364 std::vector<C> codecs_;
365};
366
367class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
368 public:
369 AudioContentDescription() :
370 agc_minus_10db_(false) {}
371
372 virtual ContentDescription* Copy() const {
373 return new AudioContentDescription(*this);
374 }
375 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
376
377 const std::string &lang() const { return lang_; }
378 void set_lang(const std::string &lang) { lang_ = lang; }
379
380 bool agc_minus_10db() const { return agc_minus_10db_; }
381 void set_agc_minus_10db(bool enable) {
382 agc_minus_10db_ = enable;
383 }
384
385 private:
386 bool agc_minus_10db_;
387
388 private:
389 std::string lang_;
390};
391
392class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
393 public:
394 virtual ContentDescription* Copy() const {
395 return new VideoContentDescription(*this);
396 }
397 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
398};
399
400class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
401 public:
zstein4b2e0822017-02-17 19:48:38 -0800402 DataContentDescription() {}
403
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 virtual ContentDescription* Copy() const {
405 return new DataContentDescription(*this);
406 }
407 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
zstein4b2e0822017-02-17 19:48:38 -0800408
409 bool use_sctpmap() const { return use_sctpmap_; }
410 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
411
412 private:
413 bool use_sctpmap_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414};
415
416// Creates media session descriptions according to the supplied codecs and
417// other fields, as well as the supplied per-call options.
418// When creating answers, performs the appropriate negotiation
419// of the various fields to determine the proper result.
420class MediaSessionDescriptionFactory {
421 public:
422 // Default ctor; use methods below to set configuration.
423 // The TransportDescriptionFactory is not owned by MediaSessionDescFactory,
424 // so it must be kept alive by the user of this class.
425 explicit MediaSessionDescriptionFactory(
426 const TransportDescriptionFactory* factory);
427 // This helper automatically sets up the factory to get its configuration
428 // from the specified ChannelManager.
429 MediaSessionDescriptionFactory(ChannelManager* cmanager,
430 const TransportDescriptionFactory* factory);
431
ossudedfd282016-06-14 07:12:39 -0700432 const AudioCodecs& audio_sendrecv_codecs() const;
ossu075af922016-06-14 03:29:38 -0700433 const AudioCodecs& audio_send_codecs() const;
434 const AudioCodecs& audio_recv_codecs() const;
435 void set_audio_codecs(const AudioCodecs& send_codecs,
436 const AudioCodecs& recv_codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
438 audio_rtp_extensions_ = extensions;
439 }
440 const RtpHeaderExtensions& audio_rtp_header_extensions() const {
441 return audio_rtp_extensions_;
442 }
443 const VideoCodecs& video_codecs() const { return video_codecs_; }
444 void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; }
445 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
446 video_rtp_extensions_ = extensions;
447 }
448 const RtpHeaderExtensions& video_rtp_header_extensions() const {
449 return video_rtp_extensions_;
450 }
451 const DataCodecs& data_codecs() const { return data_codecs_; }
452 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
453 SecurePolicy secure() const { return secure_; }
454 void set_secure(SecurePolicy s) { secure_ = s; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455
jbauch5869f502017-06-29 12:31:36 -0700456 void set_enable_encrypted_rtp_header_extensions(bool enable) {
457 enable_encrypted_rtp_header_extensions_ = enable;
458 }
459
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 SessionDescription* CreateOffer(
461 const MediaSessionOptions& options,
462 const SessionDescription* current_description) const;
463 SessionDescription* CreateAnswer(
zstein4b2e0822017-02-17 19:48:38 -0800464 const SessionDescription* offer,
465 const MediaSessionOptions& options,
466 const SessionDescription* current_description) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467
468 private:
ossu075af922016-06-14 03:29:38 -0700469 const AudioCodecs& GetAudioCodecsForOffer(
470 const RtpTransceiverDirection& direction) const;
471 const AudioCodecs& GetAudioCodecsForAnswer(
472 const RtpTransceiverDirection& offer,
473 const RtpTransceiverDirection& answer) const;
zhihuang1c378ed2017-08-17 14:10:50 -0700474 void GetCodecsForOffer(const SessionDescription* current_description,
475 AudioCodecs* audio_codecs,
476 VideoCodecs* video_codecs,
477 DataCodecs* data_codecs) const;
478 void GetCodecsForAnswer(const SessionDescription* current_description,
479 const SessionDescription* remote_offer,
480 AudioCodecs* audio_codecs,
481 VideoCodecs* video_codecs,
482 DataCodecs* data_codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 void GetRtpHdrExtsToOffer(const SessionDescription* current_description,
484 RtpHeaderExtensions* audio_extensions,
485 RtpHeaderExtensions* video_extensions) const;
486 bool AddTransportOffer(
487 const std::string& content_name,
488 const TransportOptions& transport_options,
489 const SessionDescription* current_desc,
490 SessionDescription* offer) const;
491
492 TransportDescription* CreateTransportAnswer(
493 const std::string& content_name,
494 const SessionDescription* offer_desc,
495 const TransportOptions& transport_options,
deadbeefb7892532017-02-22 19:35:18 -0800496 const SessionDescription* current_desc,
497 bool require_transport_attributes) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498
499 bool AddTransportAnswer(
500 const std::string& content_name,
501 const TransportDescription& transport_desc,
502 SessionDescription* answer_desc) const;
503
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000504 // Helpers for adding media contents to the SessionDescription. Returns true
505 // it succeeds or the media content is not needed, or false if there is any
506 // error.
507
508 bool AddAudioContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700509 const MediaDescriptionOptions& media_description_options,
510 const MediaSessionOptions& session_options,
511 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000512 const SessionDescription* current_description,
513 const RtpHeaderExtensions& audio_rtp_extensions,
514 const AudioCodecs& audio_codecs,
515 StreamParamsVec* current_streams,
516 SessionDescription* desc) const;
517
518 bool AddVideoContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700519 const MediaDescriptionOptions& media_description_options,
520 const MediaSessionOptions& session_options,
521 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000522 const SessionDescription* current_description,
523 const RtpHeaderExtensions& video_rtp_extensions,
524 const VideoCodecs& video_codecs,
525 StreamParamsVec* current_streams,
526 SessionDescription* desc) const;
527
528 bool AddDataContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700529 const MediaDescriptionOptions& media_description_options,
530 const MediaSessionOptions& session_options,
531 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000532 const SessionDescription* current_description,
zhihuang1c378ed2017-08-17 14:10:50 -0700533 const DataCodecs& data_codecs,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000534 StreamParamsVec* current_streams,
535 SessionDescription* desc) const;
536
zhihuang1c378ed2017-08-17 14:10:50 -0700537 bool AddAudioContentForAnswer(
538 const MediaDescriptionOptions& media_description_options,
539 const MediaSessionOptions& session_options,
540 const ContentInfo* offer_content,
541 const SessionDescription* offer_description,
542 const ContentInfo* current_content,
543 const SessionDescription* current_description,
544 const TransportInfo* bundle_transport,
545 const AudioCodecs& audio_codecs,
546 StreamParamsVec* current_streams,
547 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000548
zhihuang1c378ed2017-08-17 14:10:50 -0700549 bool AddVideoContentForAnswer(
550 const MediaDescriptionOptions& media_description_options,
551 const MediaSessionOptions& session_options,
552 const ContentInfo* offer_content,
553 const SessionDescription* offer_description,
554 const ContentInfo* current_content,
555 const SessionDescription* current_description,
556 const TransportInfo* bundle_transport,
557 const VideoCodecs& video_codecs,
558 StreamParamsVec* current_streams,
559 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000560
zhihuang1c378ed2017-08-17 14:10:50 -0700561 bool AddDataContentForAnswer(
562 const MediaDescriptionOptions& media_description_options,
563 const MediaSessionOptions& session_options,
564 const ContentInfo* offer_content,
565 const SessionDescription* offer_description,
566 const ContentInfo* current_content,
567 const SessionDescription* current_description,
568 const TransportInfo* bundle_transport,
569 const DataCodecs& data_codecs,
570 StreamParamsVec* current_streams,
571 SessionDescription* answer) const;
572
573 void ComputeAudioCodecsIntersectionAndUnion();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000574
ossu075af922016-06-14 03:29:38 -0700575 AudioCodecs audio_send_codecs_;
576 AudioCodecs audio_recv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700577 // Intersection of send and recv.
ossu075af922016-06-14 03:29:38 -0700578 AudioCodecs audio_sendrecv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700579 // Union of send and recv.
580 AudioCodecs all_audio_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 RtpHeaderExtensions audio_rtp_extensions_;
582 VideoCodecs video_codecs_;
583 RtpHeaderExtensions video_rtp_extensions_;
584 DataCodecs data_codecs_;
jbauch5869f502017-06-29 12:31:36 -0700585 bool enable_encrypted_rtp_header_extensions_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700586 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter
587 // and setter.
588 SecurePolicy secure_ = SEC_DISABLED;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 std::string lang_;
590 const TransportDescriptionFactory* transport_desc_factory_;
591};
592
593// Convenience functions.
594bool IsMediaContent(const ContentInfo* content);
595bool IsAudioContent(const ContentInfo* content);
596bool IsVideoContent(const ContentInfo* content);
597bool IsDataContent(const ContentInfo* content);
deadbeef0ed85b22016-02-23 17:24:52 -0800598const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
599 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600const ContentInfo* GetFirstAudioContent(const ContentInfos& contents);
601const ContentInfo* GetFirstVideoContent(const ContentInfos& contents);
602const ContentInfo* GetFirstDataContent(const ContentInfos& contents);
603const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc);
604const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc);
605const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc);
606const AudioContentDescription* GetFirstAudioContentDescription(
607 const SessionDescription* sdesc);
608const VideoContentDescription* GetFirstVideoContentDescription(
609 const SessionDescription* sdesc);
610const DataContentDescription* GetFirstDataContentDescription(
611 const SessionDescription* sdesc);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700612// Non-const versions of the above functions.
613// Useful when modifying an existing description.
Steve Anton36b29d12017-10-30 09:57:42 -0700614ContentInfo* GetFirstMediaContent(ContentInfos* contents, MediaType media_type);
615ContentInfo* GetFirstAudioContent(ContentInfos* contents);
616ContentInfo* GetFirstVideoContent(ContentInfos* contents);
617ContentInfo* GetFirstDataContent(ContentInfos* contents);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700618ContentInfo* GetFirstAudioContent(SessionDescription* sdesc);
619ContentInfo* GetFirstVideoContent(SessionDescription* sdesc);
620ContentInfo* GetFirstDataContent(SessionDescription* sdesc);
621AudioContentDescription* GetFirstAudioContentDescription(
622 SessionDescription* sdesc);
623VideoContentDescription* GetFirstVideoContentDescription(
624 SessionDescription* sdesc);
625DataContentDescription* GetFirstDataContentDescription(
626 SessionDescription* sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627
deadbeef7914b8c2017-04-21 03:23:33 -0700628// Helper functions to return crypto suites used for SDES.
629void GetSupportedAudioSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
630 std::vector<int>* crypto_suites);
631void GetSupportedVideoSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
632 std::vector<int>* crypto_suites);
633void GetSupportedDataSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
634 std::vector<int>* crypto_suites);
635void GetSupportedAudioSdesCryptoSuiteNames(
636 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800637 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700638void GetSupportedVideoSdesCryptoSuiteNames(
639 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800640 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700641void GetSupportedDataSdesCryptoSuiteNames(
642 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800643 std::vector<std::string>* crypto_suite_names);
644
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645} // namespace cricket
646
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200647#endif // PC_MEDIASESSION_H_