blob: 41e867be1295b5017bdd45c0907e70f921daea54 [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"
Steve Anton1d03a752017-11-27 14:30:09 -080023#include "api/rtptransceiverinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "media/base/codec.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "media/base/mediachannel.h"
26#include "media/base/mediaconstants.h"
27#include "media/base/mediaengine.h" // For DataChannelType
28#include "media/base/streamparams.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "p2p/base/jseptransport.h"
Steve Anton1d03a752017-11-27 14:30:09 -080030#include "p2p/base/sessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "p2p/base/transportdescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032
33namespace cricket {
34
35class ChannelManager;
36typedef std::vector<AudioCodec> AudioCodecs;
37typedef std::vector<VideoCodec> VideoCodecs;
38typedef std::vector<DataCodec> DataCodecs;
39typedef std::vector<CryptoParams> CryptoParamsVec;
isheriff6f8d6862016-05-26 11:24:55 -070040typedef std::vector<webrtc::RtpExtension> RtpHeaderExtensions;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042enum MediaContentDirection {
43 MD_INACTIVE,
44 MD_SENDONLY,
45 MD_RECVONLY,
46 MD_SENDRECV
47};
48
ossu075af922016-06-14 03:29:38 -070049std::string MediaContentDirectionToString(MediaContentDirection direction);
50
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000051enum CryptoType {
52 CT_NONE,
53 CT_SDES,
54 CT_DTLS
55};
56
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057// RTC4585 RTP/AVPF
58extern const char kMediaProtocolAvpf[];
59// RFC5124 RTP/SAVPF
60extern const char kMediaProtocolSavpf[];
61
jiayl@webrtc.org8dcd43c2014-05-29 22:07:59 +000062extern const char kMediaProtocolDtlsSavpf[];
63
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064extern const char kMediaProtocolRtpPrefix[];
65
66extern const char kMediaProtocolSctp[];
67extern const char kMediaProtocolDtlsSctp[];
lally@webrtc.orgec97c652015-02-24 20:18:48 +000068extern const char kMediaProtocolUdpDtlsSctp[];
lally@webrtc.orga7470932015-02-24 20:19:21 +000069extern const char kMediaProtocolTcpDtlsSctp[];
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070
71// Options to control how session descriptions are generated.
72const int kAutoBandwidth = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073
zhihuang8f65cdf2016-05-06 18:40:30 -070074// Default RTCP CNAME for unit tests.
75const char kDefaultRtcpCname[] = "DefaultRtcpCname";
76
Steve Anton1d03a752017-11-27 14:30:09 -080077webrtc::RtpTransceiverDirection
78RtpTransceiverDirectionFromMediaContentDirection(
79 MediaContentDirection direction);
80MediaContentDirection MediaContentDirectionFromRtpTransceiverDirection(
81 webrtc::RtpTransceiverDirection direction);
ossu075af922016-06-14 03:29:38 -070082
zhihuang1c378ed2017-08-17 14:10:50 -070083// Options for an RtpSender contained with an media description/"m=" section.
84struct SenderOptions {
85 std::string track_id;
Steve Anton8ffb9c32017-08-31 15:45:38 -070086 // TODO(steveanton): As part of work towards Unified Plan, this has been
87 // changed to be a vector. But for now this can only have exactly one.
88 std::vector<std::string> stream_ids;
zhihuang1c378ed2017-08-17 14:10:50 -070089 int num_sim_layers;
90};
jiayl@webrtc.org742922b2014-10-07 21:32:43 +000091
zhihuang1c378ed2017-08-17 14:10:50 -070092// Options for an individual media description/"m=" section.
93struct MediaDescriptionOptions {
94 MediaDescriptionOptions(MediaType type,
95 const std::string& mid,
Steve Anton1d03a752017-11-27 14:30:09 -080096 webrtc::RtpTransceiverDirection direction,
zhihuang1c378ed2017-08-17 14:10:50 -070097 bool stopped)
98 : type(type), mid(mid), direction(direction), stopped(stopped) {}
zhihuanga77e6bb2017-08-14 18:17:48 -070099
zhihuang1c378ed2017-08-17 14:10:50 -0700100 // TODO(deadbeef): When we don't support Plan B, there will only be one
101 // sender per media description and this can be simplified.
102 void AddAudioSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700103 const std::vector<std::string>& stream_ids);
zhihuang1c378ed2017-08-17 14:10:50 -0700104 void AddVideoSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700105 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -0700106 int num_sim_layers);
zhihuanga77e6bb2017-08-14 18:17:48 -0700107
zhihuang1c378ed2017-08-17 14:10:50 -0700108 // Internally just uses sender_options.
109 void AddRtpDataChannel(const std::string& track_id,
110 const std::string& stream_id);
olka3c747662017-08-17 06:50:32 -0700111
zhihuang1c378ed2017-08-17 14:10:50 -0700112 MediaType type;
113 std::string mid;
Steve Anton1d03a752017-11-27 14:30:09 -0800114 webrtc::RtpTransceiverDirection direction;
zhihuang1c378ed2017-08-17 14:10:50 -0700115 bool stopped;
116 TransportOptions transport_options;
117 // Note: There's no equivalent "RtpReceiverOptions" because only send
118 // stream information goes in the local descriptions.
119 std::vector<SenderOptions> sender_options;
120
121 private:
122 // Doesn't DCHECK on |type|.
123 void AddSenderInternal(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700124 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -0700125 int num_sim_layers);
zhihuang1c378ed2017-08-17 14:10:50 -0700126};
olka3c747662017-08-17 06:50:32 -0700127
zhihuang1c378ed2017-08-17 14:10:50 -0700128// Provides a mechanism for describing how m= sections should be generated.
129// The m= section with index X will use media_description_options[X]. There
130// must be an option for each existing section if creating an answer, or a
131// subsequent offer.
132struct MediaSessionOptions {
133 MediaSessionOptions() {}
olka3c747662017-08-17 06:50:32 -0700134
zhihuang1c378ed2017-08-17 14:10:50 -0700135 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
136 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
137 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); }
138
139 bool HasMediaDescription(MediaType type) const;
140
141 DataChannelType data_channel_type = DCT_NONE;
142 bool is_muc = false;
143 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
144 bool rtcp_mux_enabled = true;
145 bool bundle_enabled = false;
146 std::string rtcp_cname = kDefaultRtcpCname;
jbauchcb560652016-08-04 05:20:32 -0700147 rtc::CryptoOptions crypto_options;
zhihuang1c378ed2017-08-17 14:10:50 -0700148 // List of media description options in the same order that the media
149 // descriptions will be generated.
150 std::vector<MediaDescriptionOptions> media_description_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151};
152
153// "content" (as used in XEP-0166) descriptions for voice and video.
154class MediaContentDescription : public ContentDescription {
155 public:
deadbeef13871492015-12-09 12:37:51 -0800156 MediaContentDescription() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157
158 virtual MediaType type() const = 0;
159 virtual bool has_codecs() const = 0;
160
161 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
162 // RTP/SAVPF or SCTP/DTLS.
163 std::string protocol() const { return protocol_; }
164 void set_protocol(const std::string& protocol) { protocol_ = protocol; }
165
166 MediaContentDirection direction() const { return direction_; }
167 void set_direction(MediaContentDirection direction) {
168 direction_ = direction;
169 }
170
171 bool rtcp_mux() const { return rtcp_mux_; }
172 void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
173
deadbeef13871492015-12-09 12:37:51 -0800174 bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
175 void set_rtcp_reduced_size(bool reduced_size) {
176 rtcp_reduced_size_ = reduced_size;
177 }
178
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 int bandwidth() const { return bandwidth_; }
180 void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
181
182 const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
183 void AddCrypto(const CryptoParams& params) {
184 cryptos_.push_back(params);
185 }
186 void set_cryptos(const std::vector<CryptoParams>& cryptos) {
187 cryptos_ = cryptos;
188 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000189
190 CryptoType crypto_required() const { return crypto_required_; }
191 void set_crypto_required(CryptoType type) {
192 crypto_required_ = type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 }
194
195 const RtpHeaderExtensions& rtp_header_extensions() const {
196 return rtp_header_extensions_;
197 }
198 void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
199 rtp_header_extensions_ = extensions;
200 rtp_header_extensions_set_ = true;
201 }
isheriff6f8d6862016-05-26 11:24:55 -0700202 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 rtp_header_extensions_.push_back(ext);
204 rtp_header_extensions_set_ = true;
205 }
isheriffa1c548b2016-05-31 16:12:24 -0700206 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
207 webrtc::RtpExtension webrtc_extension;
208 webrtc_extension.uri = ext.uri;
209 webrtc_extension.id = ext.id;
210 rtp_header_extensions_.push_back(webrtc_extension);
211 rtp_header_extensions_set_ = true;
212 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 void ClearRtpHeaderExtensions() {
214 rtp_header_extensions_.clear();
215 rtp_header_extensions_set_ = true;
216 }
217 // We can't always tell if an empty list of header extensions is
218 // because the other side doesn't support them, or just isn't hooked up to
219 // signal them. For now we assume an empty list means no signaling, but
220 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
221 // clearly indicated (i.e. when derived from other information).
222 bool rtp_header_extensions_set() const {
223 return rtp_header_extensions_set_;
224 }
225 // True iff the client supports multiple streams.
226 void set_multistream(bool multistream) { multistream_ = multistream; }
227 bool multistream() const { return multistream_; }
228 const StreamParamsVec& streams() const {
229 return streams_;
230 }
231 // TODO(pthatcher): Remove this by giving mediamessage.cc access
232 // to MediaContentDescription
233 StreamParamsVec& mutable_streams() {
234 return streams_;
235 }
236 void AddStream(const StreamParams& stream) {
237 streams_.push_back(stream);
238 }
239 // Legacy streams have an ssrc, but nothing else.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200240 void AddLegacyStream(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 streams_.push_back(StreamParams::CreateLegacy(ssrc));
242 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200243 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 StreamParams sp = StreamParams::CreateLegacy(ssrc);
245 sp.AddFidSsrc(ssrc, fid_ssrc);
246 streams_.push_back(sp);
247 }
248 // Sets the CNAME of all StreamParams if it have not been set.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 void SetCnameIfEmpty(const std::string& cname) {
250 for (cricket::StreamParamsVec::iterator it = streams_.begin();
251 it != streams_.end(); ++it) {
252 if (it->cname.empty())
253 it->cname = cname;
254 }
255 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200256 uint32_t first_ssrc() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 if (streams_.empty()) {
258 return 0;
259 }
260 return streams_[0].first_ssrc();
261 }
262 bool has_ssrcs() const {
263 if (streams_.empty()) {
264 return false;
265 }
266 return streams_[0].has_ssrcs();
267 }
268
269 void set_conference_mode(bool enable) { conference_mode_ = enable; }
270 bool conference_mode() const { return conference_mode_; }
271
272 void set_partial(bool partial) { partial_ = partial; }
273 bool partial() const { return partial_; }
274
zhihuang38989e52017-03-21 11:04:53 -0700275 // https://tools.ietf.org/html/rfc4566#section-5.7
276 // May be present at the media or session level of SDP. If present at both
277 // levels, the media-level attribute overwrites the session-level one.
278 void set_connection_address(const rtc::SocketAddress& address) {
279 connection_address_ = address;
280 }
281 const rtc::SocketAddress& connection_address() const {
282 return connection_address_;
283 }
284
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 protected:
deadbeef13871492015-12-09 12:37:51 -0800286 bool rtcp_mux_ = false;
287 bool rtcp_reduced_size_ = false;
288 int bandwidth_ = kAutoBandwidth;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 std::string protocol_;
290 std::vector<CryptoParams> cryptos_;
deadbeef13871492015-12-09 12:37:51 -0800291 CryptoType crypto_required_ = CT_NONE;
isheriff6f8d6862016-05-26 11:24:55 -0700292 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
deadbeef13871492015-12-09 12:37:51 -0800293 bool rtp_header_extensions_set_ = false;
294 bool multistream_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 StreamParamsVec streams_;
deadbeef13871492015-12-09 12:37:51 -0800296 bool conference_mode_ = false;
297 bool partial_ = false;
deadbeef13871492015-12-09 12:37:51 -0800298 MediaContentDirection direction_ = MD_SENDRECV;
zhihuang38989e52017-03-21 11:04:53 -0700299 rtc::SocketAddress connection_address_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300};
301
302template <class C>
303class MediaContentDescriptionImpl : public MediaContentDescription {
304 public:
deadbeef67cf2c12016-04-13 10:07:16 -0700305 typedef C CodecType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306
deadbeef67cf2c12016-04-13 10:07:16 -0700307 // Codecs should be in preference order (most preferred codec first).
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 const std::vector<C>& codecs() const { return codecs_; }
309 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
310 virtual bool has_codecs() const { return !codecs_.empty(); }
311 bool HasCodec(int id) {
312 bool found = false;
313 for (typename std::vector<C>::iterator iter = codecs_.begin();
314 iter != codecs_.end(); ++iter) {
315 if (iter->id == id) {
316 found = true;
317 break;
318 }
319 }
320 return found;
321 }
322 void AddCodec(const C& codec) {
323 codecs_.push_back(codec);
324 }
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000325 void AddOrReplaceCodec(const C& codec) {
326 for (typename std::vector<C>::iterator iter = codecs_.begin();
327 iter != codecs_.end(); ++iter) {
328 if (iter->id == codec.id) {
329 *iter = codec;
330 return;
331 }
332 }
333 AddCodec(codec);
334 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 void AddCodecs(const std::vector<C>& codecs) {
336 typename std::vector<C>::const_iterator codec;
337 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
338 AddCodec(*codec);
339 }
340 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341
342 private:
343 std::vector<C> codecs_;
344};
345
346class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
347 public:
348 AudioContentDescription() :
349 agc_minus_10db_(false) {}
350
351 virtual ContentDescription* Copy() const {
352 return new AudioContentDescription(*this);
353 }
354 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
355
356 const std::string &lang() const { return lang_; }
357 void set_lang(const std::string &lang) { lang_ = lang; }
358
359 bool agc_minus_10db() const { return agc_minus_10db_; }
360 void set_agc_minus_10db(bool enable) {
361 agc_minus_10db_ = enable;
362 }
363
364 private:
365 bool agc_minus_10db_;
366
367 private:
368 std::string lang_;
369};
370
371class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
372 public:
373 virtual ContentDescription* Copy() const {
374 return new VideoContentDescription(*this);
375 }
376 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
377};
378
379class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
380 public:
zstein4b2e0822017-02-17 19:48:38 -0800381 DataContentDescription() {}
382
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 virtual ContentDescription* Copy() const {
384 return new DataContentDescription(*this);
385 }
386 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
zstein4b2e0822017-02-17 19:48:38 -0800387
388 bool use_sctpmap() const { return use_sctpmap_; }
389 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
390
391 private:
392 bool use_sctpmap_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393};
394
395// Creates media session descriptions according to the supplied codecs and
396// other fields, as well as the supplied per-call options.
397// When creating answers, performs the appropriate negotiation
398// of the various fields to determine the proper result.
399class MediaSessionDescriptionFactory {
400 public:
401 // Default ctor; use methods below to set configuration.
402 // The TransportDescriptionFactory is not owned by MediaSessionDescFactory,
403 // so it must be kept alive by the user of this class.
404 explicit MediaSessionDescriptionFactory(
405 const TransportDescriptionFactory* factory);
406 // This helper automatically sets up the factory to get its configuration
407 // from the specified ChannelManager.
408 MediaSessionDescriptionFactory(ChannelManager* cmanager,
409 const TransportDescriptionFactory* factory);
410
ossudedfd282016-06-14 07:12:39 -0700411 const AudioCodecs& audio_sendrecv_codecs() const;
ossu075af922016-06-14 03:29:38 -0700412 const AudioCodecs& audio_send_codecs() const;
413 const AudioCodecs& audio_recv_codecs() const;
414 void set_audio_codecs(const AudioCodecs& send_codecs,
415 const AudioCodecs& recv_codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
417 audio_rtp_extensions_ = extensions;
418 }
419 const RtpHeaderExtensions& audio_rtp_header_extensions() const {
420 return audio_rtp_extensions_;
421 }
422 const VideoCodecs& video_codecs() const { return video_codecs_; }
423 void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; }
424 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
425 video_rtp_extensions_ = extensions;
426 }
427 const RtpHeaderExtensions& video_rtp_header_extensions() const {
428 return video_rtp_extensions_;
429 }
430 const DataCodecs& data_codecs() const { return data_codecs_; }
431 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
432 SecurePolicy secure() const { return secure_; }
433 void set_secure(SecurePolicy s) { secure_ = s; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434
jbauch5869f502017-06-29 12:31:36 -0700435 void set_enable_encrypted_rtp_header_extensions(bool enable) {
436 enable_encrypted_rtp_header_extensions_ = enable;
437 }
438
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 SessionDescription* CreateOffer(
440 const MediaSessionOptions& options,
441 const SessionDescription* current_description) const;
442 SessionDescription* CreateAnswer(
zstein4b2e0822017-02-17 19:48:38 -0800443 const SessionDescription* offer,
444 const MediaSessionOptions& options,
445 const SessionDescription* current_description) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446
447 private:
ossu075af922016-06-14 03:29:38 -0700448 const AudioCodecs& GetAudioCodecsForOffer(
Steve Anton1d03a752017-11-27 14:30:09 -0800449 const webrtc::RtpTransceiverDirection& direction) const;
ossu075af922016-06-14 03:29:38 -0700450 const AudioCodecs& GetAudioCodecsForAnswer(
Steve Anton1d03a752017-11-27 14:30:09 -0800451 const webrtc::RtpTransceiverDirection& offer,
452 const webrtc::RtpTransceiverDirection& answer) const;
zhihuang1c378ed2017-08-17 14:10:50 -0700453 void GetCodecsForOffer(const SessionDescription* current_description,
454 AudioCodecs* audio_codecs,
455 VideoCodecs* video_codecs,
456 DataCodecs* data_codecs) const;
457 void GetCodecsForAnswer(const SessionDescription* current_description,
458 const SessionDescription* remote_offer,
459 AudioCodecs* audio_codecs,
460 VideoCodecs* video_codecs,
461 DataCodecs* data_codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 void GetRtpHdrExtsToOffer(const SessionDescription* current_description,
463 RtpHeaderExtensions* audio_extensions,
464 RtpHeaderExtensions* video_extensions) const;
465 bool AddTransportOffer(
466 const std::string& content_name,
467 const TransportOptions& transport_options,
468 const SessionDescription* current_desc,
469 SessionDescription* offer) const;
470
471 TransportDescription* CreateTransportAnswer(
472 const std::string& content_name,
473 const SessionDescription* offer_desc,
474 const TransportOptions& transport_options,
deadbeefb7892532017-02-22 19:35:18 -0800475 const SessionDescription* current_desc,
476 bool require_transport_attributes) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000477
478 bool AddTransportAnswer(
479 const std::string& content_name,
480 const TransportDescription& transport_desc,
481 SessionDescription* answer_desc) const;
482
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000483 // Helpers for adding media contents to the SessionDescription. Returns true
484 // it succeeds or the media content is not needed, or false if there is any
485 // error.
486
487 bool AddAudioContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700488 const MediaDescriptionOptions& media_description_options,
489 const MediaSessionOptions& session_options,
490 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000491 const SessionDescription* current_description,
492 const RtpHeaderExtensions& audio_rtp_extensions,
493 const AudioCodecs& audio_codecs,
494 StreamParamsVec* current_streams,
495 SessionDescription* desc) const;
496
497 bool AddVideoContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700498 const MediaDescriptionOptions& media_description_options,
499 const MediaSessionOptions& session_options,
500 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000501 const SessionDescription* current_description,
502 const RtpHeaderExtensions& video_rtp_extensions,
503 const VideoCodecs& video_codecs,
504 StreamParamsVec* current_streams,
505 SessionDescription* desc) const;
506
507 bool AddDataContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700508 const MediaDescriptionOptions& media_description_options,
509 const MediaSessionOptions& session_options,
510 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000511 const SessionDescription* current_description,
zhihuang1c378ed2017-08-17 14:10:50 -0700512 const DataCodecs& data_codecs,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000513 StreamParamsVec* current_streams,
514 SessionDescription* desc) const;
515
zhihuang1c378ed2017-08-17 14:10:50 -0700516 bool AddAudioContentForAnswer(
517 const MediaDescriptionOptions& media_description_options,
518 const MediaSessionOptions& session_options,
519 const ContentInfo* offer_content,
520 const SessionDescription* offer_description,
521 const ContentInfo* current_content,
522 const SessionDescription* current_description,
523 const TransportInfo* bundle_transport,
524 const AudioCodecs& audio_codecs,
525 StreamParamsVec* current_streams,
526 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000527
zhihuang1c378ed2017-08-17 14:10:50 -0700528 bool AddVideoContentForAnswer(
529 const MediaDescriptionOptions& media_description_options,
530 const MediaSessionOptions& session_options,
531 const ContentInfo* offer_content,
532 const SessionDescription* offer_description,
533 const ContentInfo* current_content,
534 const SessionDescription* current_description,
535 const TransportInfo* bundle_transport,
536 const VideoCodecs& video_codecs,
537 StreamParamsVec* current_streams,
538 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000539
zhihuang1c378ed2017-08-17 14:10:50 -0700540 bool AddDataContentForAnswer(
541 const MediaDescriptionOptions& media_description_options,
542 const MediaSessionOptions& session_options,
543 const ContentInfo* offer_content,
544 const SessionDescription* offer_description,
545 const ContentInfo* current_content,
546 const SessionDescription* current_description,
547 const TransportInfo* bundle_transport,
548 const DataCodecs& data_codecs,
549 StreamParamsVec* current_streams,
550 SessionDescription* answer) const;
551
552 void ComputeAudioCodecsIntersectionAndUnion();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000553
ossu075af922016-06-14 03:29:38 -0700554 AudioCodecs audio_send_codecs_;
555 AudioCodecs audio_recv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700556 // Intersection of send and recv.
ossu075af922016-06-14 03:29:38 -0700557 AudioCodecs audio_sendrecv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700558 // Union of send and recv.
559 AudioCodecs all_audio_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 RtpHeaderExtensions audio_rtp_extensions_;
561 VideoCodecs video_codecs_;
562 RtpHeaderExtensions video_rtp_extensions_;
563 DataCodecs data_codecs_;
jbauch5869f502017-06-29 12:31:36 -0700564 bool enable_encrypted_rtp_header_extensions_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700565 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter
566 // and setter.
567 SecurePolicy secure_ = SEC_DISABLED;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 std::string lang_;
569 const TransportDescriptionFactory* transport_desc_factory_;
570};
571
572// Convenience functions.
573bool IsMediaContent(const ContentInfo* content);
574bool IsAudioContent(const ContentInfo* content);
575bool IsVideoContent(const ContentInfo* content);
576bool IsDataContent(const ContentInfo* content);
deadbeef0ed85b22016-02-23 17:24:52 -0800577const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
578 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579const ContentInfo* GetFirstAudioContent(const ContentInfos& contents);
580const ContentInfo* GetFirstVideoContent(const ContentInfos& contents);
581const ContentInfo* GetFirstDataContent(const ContentInfos& contents);
582const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc);
583const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc);
584const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc);
585const AudioContentDescription* GetFirstAudioContentDescription(
586 const SessionDescription* sdesc);
587const VideoContentDescription* GetFirstVideoContentDescription(
588 const SessionDescription* sdesc);
589const DataContentDescription* GetFirstDataContentDescription(
590 const SessionDescription* sdesc);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700591// Non-const versions of the above functions.
592// Useful when modifying an existing description.
Steve Anton36b29d12017-10-30 09:57:42 -0700593ContentInfo* GetFirstMediaContent(ContentInfos* contents, MediaType media_type);
594ContentInfo* GetFirstAudioContent(ContentInfos* contents);
595ContentInfo* GetFirstVideoContent(ContentInfos* contents);
596ContentInfo* GetFirstDataContent(ContentInfos* contents);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700597ContentInfo* GetFirstAudioContent(SessionDescription* sdesc);
598ContentInfo* GetFirstVideoContent(SessionDescription* sdesc);
599ContentInfo* GetFirstDataContent(SessionDescription* sdesc);
600AudioContentDescription* GetFirstAudioContentDescription(
601 SessionDescription* sdesc);
602VideoContentDescription* GetFirstVideoContentDescription(
603 SessionDescription* sdesc);
604DataContentDescription* GetFirstDataContentDescription(
605 SessionDescription* sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606
deadbeef7914b8c2017-04-21 03:23:33 -0700607// Helper functions to return crypto suites used for SDES.
608void GetSupportedAudioSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
609 std::vector<int>* crypto_suites);
610void GetSupportedVideoSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
611 std::vector<int>* crypto_suites);
612void GetSupportedDataSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
613 std::vector<int>* crypto_suites);
614void GetSupportedAudioSdesCryptoSuiteNames(
615 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800616 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700617void GetSupportedVideoSdesCryptoSuiteNames(
618 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800619 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700620void GetSupportedDataSdesCryptoSuiteNames(
621 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800622 std::vector<std::string>* crypto_suite_names);
623
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624} // namespace cricket
625
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200626#endif // PC_MEDIASESSION_H_