blob: 09a103a03f58c2200efc06a72358c171589d5db1 [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.orgb90991d2014-03-04 19:54:57 +000042enum CryptoType {
43 CT_NONE,
44 CT_SDES,
45 CT_DTLS
46};
47
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048// RTC4585 RTP/AVPF
49extern const char kMediaProtocolAvpf[];
50// RFC5124 RTP/SAVPF
51extern const char kMediaProtocolSavpf[];
52
jiayl@webrtc.org8dcd43c2014-05-29 22:07:59 +000053extern const char kMediaProtocolDtlsSavpf[];
54
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055extern const char kMediaProtocolRtpPrefix[];
56
57extern const char kMediaProtocolSctp[];
58extern const char kMediaProtocolDtlsSctp[];
lally@webrtc.orgec97c652015-02-24 20:18:48 +000059extern const char kMediaProtocolUdpDtlsSctp[];
lally@webrtc.orga7470932015-02-24 20:19:21 +000060extern const char kMediaProtocolTcpDtlsSctp[];
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
62// Options to control how session descriptions are generated.
63const int kAutoBandwidth = -1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064
zhihuang8f65cdf2016-05-06 18:40:30 -070065// Default RTCP CNAME for unit tests.
66const char kDefaultRtcpCname[] = "DefaultRtcpCname";
67
zhihuang1c378ed2017-08-17 14:10:50 -070068// Options for an RtpSender contained with an media description/"m=" section.
69struct SenderOptions {
70 std::string track_id;
Steve Anton8ffb9c32017-08-31 15:45:38 -070071 // TODO(steveanton): As part of work towards Unified Plan, this has been
72 // changed to be a vector. But for now this can only have exactly one.
73 std::vector<std::string> stream_ids;
zhihuang1c378ed2017-08-17 14:10:50 -070074 int num_sim_layers;
75};
jiayl@webrtc.org742922b2014-10-07 21:32:43 +000076
zhihuang1c378ed2017-08-17 14:10:50 -070077// Options for an individual media description/"m=" section.
78struct MediaDescriptionOptions {
79 MediaDescriptionOptions(MediaType type,
80 const std::string& mid,
Steve Anton1d03a752017-11-27 14:30:09 -080081 webrtc::RtpTransceiverDirection direction,
zhihuang1c378ed2017-08-17 14:10:50 -070082 bool stopped)
83 : type(type), mid(mid), direction(direction), stopped(stopped) {}
zhihuanga77e6bb2017-08-14 18:17:48 -070084
zhihuang1c378ed2017-08-17 14:10:50 -070085 // TODO(deadbeef): When we don't support Plan B, there will only be one
86 // sender per media description and this can be simplified.
87 void AddAudioSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -070088 const std::vector<std::string>& stream_ids);
zhihuang1c378ed2017-08-17 14:10:50 -070089 void AddVideoSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -070090 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -070091 int num_sim_layers);
zhihuanga77e6bb2017-08-14 18:17:48 -070092
zhihuang1c378ed2017-08-17 14:10:50 -070093 // Internally just uses sender_options.
94 void AddRtpDataChannel(const std::string& track_id,
95 const std::string& stream_id);
olka3c747662017-08-17 06:50:32 -070096
zhihuang1c378ed2017-08-17 14:10:50 -070097 MediaType type;
98 std::string mid;
Steve Anton1d03a752017-11-27 14:30:09 -080099 webrtc::RtpTransceiverDirection direction;
zhihuang1c378ed2017-08-17 14:10:50 -0700100 bool stopped;
101 TransportOptions transport_options;
102 // Note: There's no equivalent "RtpReceiverOptions" because only send
103 // stream information goes in the local descriptions.
104 std::vector<SenderOptions> sender_options;
105
106 private:
107 // Doesn't DCHECK on |type|.
108 void AddSenderInternal(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700109 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -0700110 int num_sim_layers);
zhihuang1c378ed2017-08-17 14:10:50 -0700111};
olka3c747662017-08-17 06:50:32 -0700112
zhihuang1c378ed2017-08-17 14:10:50 -0700113// Provides a mechanism for describing how m= sections should be generated.
114// The m= section with index X will use media_description_options[X]. There
115// must be an option for each existing section if creating an answer, or a
116// subsequent offer.
117struct MediaSessionOptions {
118 MediaSessionOptions() {}
olka3c747662017-08-17 06:50:32 -0700119
zhihuang1c378ed2017-08-17 14:10:50 -0700120 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
121 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
122 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); }
123
124 bool HasMediaDescription(MediaType type) const;
125
126 DataChannelType data_channel_type = DCT_NONE;
127 bool is_muc = false;
128 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
129 bool rtcp_mux_enabled = true;
130 bool bundle_enabled = false;
131 std::string rtcp_cname = kDefaultRtcpCname;
jbauchcb560652016-08-04 05:20:32 -0700132 rtc::CryptoOptions crypto_options;
zhihuang1c378ed2017-08-17 14:10:50 -0700133 // List of media description options in the same order that the media
134 // descriptions will be generated.
135 std::vector<MediaDescriptionOptions> media_description_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136};
137
138// "content" (as used in XEP-0166) descriptions for voice and video.
139class MediaContentDescription : public ContentDescription {
140 public:
deadbeef13871492015-12-09 12:37:51 -0800141 MediaContentDescription() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142
143 virtual MediaType type() const = 0;
144 virtual bool has_codecs() const = 0;
145
146 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
147 // RTP/SAVPF or SCTP/DTLS.
148 std::string protocol() const { return protocol_; }
149 void set_protocol(const std::string& protocol) { protocol_ = protocol; }
150
Steve Anton73da79c2017-11-27 15:12:31 -0800151 // TODO(steveanton): Remove once |direction()| uses RtpTransceiverDirection.
152 webrtc::RtpTransceiverDirection transceiver_direction() const {
153 return direction_;
154 }
155 void set_transceiver_direction(webrtc::RtpTransceiverDirection direction) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 direction_ = direction;
157 }
158
Steve Anton4e70a722017-11-28 14:57:10 -0800159 webrtc::RtpTransceiverDirection direction() const { return direction_; }
160 void set_direction(webrtc::RtpTransceiverDirection direction) {
161 direction_ = direction;
Steve Anton73da79c2017-11-27 15:12:31 -0800162 }
163
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 bool rtcp_mux() const { return rtcp_mux_; }
165 void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
166
deadbeef13871492015-12-09 12:37:51 -0800167 bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
168 void set_rtcp_reduced_size(bool reduced_size) {
169 rtcp_reduced_size_ = reduced_size;
170 }
171
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 int bandwidth() const { return bandwidth_; }
173 void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
174
175 const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
176 void AddCrypto(const CryptoParams& params) {
177 cryptos_.push_back(params);
178 }
179 void set_cryptos(const std::vector<CryptoParams>& cryptos) {
180 cryptos_ = cryptos;
181 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000182
183 CryptoType crypto_required() const { return crypto_required_; }
184 void set_crypto_required(CryptoType type) {
185 crypto_required_ = type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
187
188 const RtpHeaderExtensions& rtp_header_extensions() const {
189 return rtp_header_extensions_;
190 }
191 void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
192 rtp_header_extensions_ = extensions;
193 rtp_header_extensions_set_ = true;
194 }
isheriff6f8d6862016-05-26 11:24:55 -0700195 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 rtp_header_extensions_.push_back(ext);
197 rtp_header_extensions_set_ = true;
198 }
isheriffa1c548b2016-05-31 16:12:24 -0700199 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
200 webrtc::RtpExtension webrtc_extension;
201 webrtc_extension.uri = ext.uri;
202 webrtc_extension.id = ext.id;
203 rtp_header_extensions_.push_back(webrtc_extension);
204 rtp_header_extensions_set_ = true;
205 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 void ClearRtpHeaderExtensions() {
207 rtp_header_extensions_.clear();
208 rtp_header_extensions_set_ = true;
209 }
210 // We can't always tell if an empty list of header extensions is
211 // because the other side doesn't support them, or just isn't hooked up to
212 // signal them. For now we assume an empty list means no signaling, but
213 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
214 // clearly indicated (i.e. when derived from other information).
215 bool rtp_header_extensions_set() const {
216 return rtp_header_extensions_set_;
217 }
218 // True iff the client supports multiple streams.
219 void set_multistream(bool multistream) { multistream_ = multistream; }
220 bool multistream() const { return multistream_; }
221 const StreamParamsVec& streams() const {
222 return streams_;
223 }
224 // TODO(pthatcher): Remove this by giving mediamessage.cc access
225 // to MediaContentDescription
226 StreamParamsVec& mutable_streams() {
227 return streams_;
228 }
229 void AddStream(const StreamParams& stream) {
230 streams_.push_back(stream);
231 }
232 // Legacy streams have an ssrc, but nothing else.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200233 void AddLegacyStream(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 streams_.push_back(StreamParams::CreateLegacy(ssrc));
235 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200236 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 StreamParams sp = StreamParams::CreateLegacy(ssrc);
238 sp.AddFidSsrc(ssrc, fid_ssrc);
239 streams_.push_back(sp);
240 }
241 // Sets the CNAME of all StreamParams if it have not been set.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 void SetCnameIfEmpty(const std::string& cname) {
243 for (cricket::StreamParamsVec::iterator it = streams_.begin();
244 it != streams_.end(); ++it) {
245 if (it->cname.empty())
246 it->cname = cname;
247 }
248 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200249 uint32_t first_ssrc() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 if (streams_.empty()) {
251 return 0;
252 }
253 return streams_[0].first_ssrc();
254 }
255 bool has_ssrcs() const {
256 if (streams_.empty()) {
257 return false;
258 }
259 return streams_[0].has_ssrcs();
260 }
261
262 void set_conference_mode(bool enable) { conference_mode_ = enable; }
263 bool conference_mode() const { return conference_mode_; }
264
265 void set_partial(bool partial) { partial_ = partial; }
266 bool partial() const { return partial_; }
267
zhihuang38989e52017-03-21 11:04:53 -0700268 // https://tools.ietf.org/html/rfc4566#section-5.7
269 // May be present at the media or session level of SDP. If present at both
270 // levels, the media-level attribute overwrites the session-level one.
271 void set_connection_address(const rtc::SocketAddress& address) {
272 connection_address_ = address;
273 }
274 const rtc::SocketAddress& connection_address() const {
275 return connection_address_;
276 }
277
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 protected:
deadbeef13871492015-12-09 12:37:51 -0800279 bool rtcp_mux_ = false;
280 bool rtcp_reduced_size_ = false;
281 int bandwidth_ = kAutoBandwidth;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 std::string protocol_;
283 std::vector<CryptoParams> cryptos_;
deadbeef13871492015-12-09 12:37:51 -0800284 CryptoType crypto_required_ = CT_NONE;
isheriff6f8d6862016-05-26 11:24:55 -0700285 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
deadbeef13871492015-12-09 12:37:51 -0800286 bool rtp_header_extensions_set_ = false;
287 bool multistream_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 StreamParamsVec streams_;
deadbeef13871492015-12-09 12:37:51 -0800289 bool conference_mode_ = false;
290 bool partial_ = false;
Steve Anton73da79c2017-11-27 15:12:31 -0800291 webrtc::RtpTransceiverDirection direction_ =
292 webrtc::RtpTransceiverDirection::kSendRecv;
zhihuang38989e52017-03-21 11:04:53 -0700293 rtc::SocketAddress connection_address_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294};
295
296template <class C>
297class MediaContentDescriptionImpl : public MediaContentDescription {
298 public:
deadbeef67cf2c12016-04-13 10:07:16 -0700299 typedef C CodecType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300
deadbeef67cf2c12016-04-13 10:07:16 -0700301 // Codecs should be in preference order (most preferred codec first).
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 const std::vector<C>& codecs() const { return codecs_; }
303 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
304 virtual bool has_codecs() const { return !codecs_.empty(); }
305 bool HasCodec(int id) {
306 bool found = false;
307 for (typename std::vector<C>::iterator iter = codecs_.begin();
308 iter != codecs_.end(); ++iter) {
309 if (iter->id == id) {
310 found = true;
311 break;
312 }
313 }
314 return found;
315 }
316 void AddCodec(const C& codec) {
317 codecs_.push_back(codec);
318 }
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000319 void AddOrReplaceCodec(const C& codec) {
320 for (typename std::vector<C>::iterator iter = codecs_.begin();
321 iter != codecs_.end(); ++iter) {
322 if (iter->id == codec.id) {
323 *iter = codec;
324 return;
325 }
326 }
327 AddCodec(codec);
328 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 void AddCodecs(const std::vector<C>& codecs) {
330 typename std::vector<C>::const_iterator codec;
331 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
332 AddCodec(*codec);
333 }
334 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335
336 private:
337 std::vector<C> codecs_;
338};
339
340class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
341 public:
342 AudioContentDescription() :
343 agc_minus_10db_(false) {}
344
345 virtual ContentDescription* Copy() const {
346 return new AudioContentDescription(*this);
347 }
348 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
349
350 const std::string &lang() const { return lang_; }
351 void set_lang(const std::string &lang) { lang_ = lang; }
352
353 bool agc_minus_10db() const { return agc_minus_10db_; }
354 void set_agc_minus_10db(bool enable) {
355 agc_minus_10db_ = enable;
356 }
357
358 private:
359 bool agc_minus_10db_;
360
361 private:
362 std::string lang_;
363};
364
365class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
366 public:
367 virtual ContentDescription* Copy() const {
368 return new VideoContentDescription(*this);
369 }
370 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
371};
372
373class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
374 public:
zstein4b2e0822017-02-17 19:48:38 -0800375 DataContentDescription() {}
376
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 virtual ContentDescription* Copy() const {
378 return new DataContentDescription(*this);
379 }
380 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
zstein4b2e0822017-02-17 19:48:38 -0800381
382 bool use_sctpmap() const { return use_sctpmap_; }
383 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
384
385 private:
386 bool use_sctpmap_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387};
388
389// Creates media session descriptions according to the supplied codecs and
390// other fields, as well as the supplied per-call options.
391// When creating answers, performs the appropriate negotiation
392// of the various fields to determine the proper result.
393class MediaSessionDescriptionFactory {
394 public:
395 // Default ctor; use methods below to set configuration.
396 // The TransportDescriptionFactory is not owned by MediaSessionDescFactory,
397 // so it must be kept alive by the user of this class.
398 explicit MediaSessionDescriptionFactory(
399 const TransportDescriptionFactory* factory);
400 // This helper automatically sets up the factory to get its configuration
401 // from the specified ChannelManager.
402 MediaSessionDescriptionFactory(ChannelManager* cmanager,
403 const TransportDescriptionFactory* factory);
404
ossudedfd282016-06-14 07:12:39 -0700405 const AudioCodecs& audio_sendrecv_codecs() const;
ossu075af922016-06-14 03:29:38 -0700406 const AudioCodecs& audio_send_codecs() const;
407 const AudioCodecs& audio_recv_codecs() const;
408 void set_audio_codecs(const AudioCodecs& send_codecs,
409 const AudioCodecs& recv_codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
411 audio_rtp_extensions_ = extensions;
412 }
413 const RtpHeaderExtensions& audio_rtp_header_extensions() const {
414 return audio_rtp_extensions_;
415 }
416 const VideoCodecs& video_codecs() const { return video_codecs_; }
417 void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; }
418 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
419 video_rtp_extensions_ = extensions;
420 }
421 const RtpHeaderExtensions& video_rtp_header_extensions() const {
422 return video_rtp_extensions_;
423 }
424 const DataCodecs& data_codecs() const { return data_codecs_; }
425 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
426 SecurePolicy secure() const { return secure_; }
427 void set_secure(SecurePolicy s) { secure_ = s; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428
jbauch5869f502017-06-29 12:31:36 -0700429 void set_enable_encrypted_rtp_header_extensions(bool enable) {
430 enable_encrypted_rtp_header_extensions_ = enable;
431 }
432
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000433 SessionDescription* CreateOffer(
434 const MediaSessionOptions& options,
435 const SessionDescription* current_description) const;
436 SessionDescription* CreateAnswer(
zstein4b2e0822017-02-17 19:48:38 -0800437 const SessionDescription* offer,
438 const MediaSessionOptions& options,
439 const SessionDescription* current_description) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440
441 private:
ossu075af922016-06-14 03:29:38 -0700442 const AudioCodecs& GetAudioCodecsForOffer(
Steve Anton1d03a752017-11-27 14:30:09 -0800443 const webrtc::RtpTransceiverDirection& direction) const;
ossu075af922016-06-14 03:29:38 -0700444 const AudioCodecs& GetAudioCodecsForAnswer(
Steve Anton1d03a752017-11-27 14:30:09 -0800445 const webrtc::RtpTransceiverDirection& offer,
446 const webrtc::RtpTransceiverDirection& answer) const;
zhihuang1c378ed2017-08-17 14:10:50 -0700447 void GetCodecsForOffer(const SessionDescription* current_description,
448 AudioCodecs* audio_codecs,
449 VideoCodecs* video_codecs,
450 DataCodecs* data_codecs) const;
451 void GetCodecsForAnswer(const SessionDescription* current_description,
452 const SessionDescription* remote_offer,
453 AudioCodecs* audio_codecs,
454 VideoCodecs* video_codecs,
455 DataCodecs* data_codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000456 void GetRtpHdrExtsToOffer(const SessionDescription* current_description,
457 RtpHeaderExtensions* audio_extensions,
458 RtpHeaderExtensions* video_extensions) const;
459 bool AddTransportOffer(
460 const std::string& content_name,
461 const TransportOptions& transport_options,
462 const SessionDescription* current_desc,
463 SessionDescription* offer) const;
464
465 TransportDescription* CreateTransportAnswer(
466 const std::string& content_name,
467 const SessionDescription* offer_desc,
468 const TransportOptions& transport_options,
deadbeefb7892532017-02-22 19:35:18 -0800469 const SessionDescription* current_desc,
470 bool require_transport_attributes) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471
472 bool AddTransportAnswer(
473 const std::string& content_name,
474 const TransportDescription& transport_desc,
475 SessionDescription* answer_desc) const;
476
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000477 // Helpers for adding media contents to the SessionDescription. Returns true
478 // it succeeds or the media content is not needed, or false if there is any
479 // error.
480
481 bool AddAudioContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700482 const MediaDescriptionOptions& media_description_options,
483 const MediaSessionOptions& session_options,
484 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000485 const SessionDescription* current_description,
486 const RtpHeaderExtensions& audio_rtp_extensions,
487 const AudioCodecs& audio_codecs,
488 StreamParamsVec* current_streams,
489 SessionDescription* desc) const;
490
491 bool AddVideoContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700492 const MediaDescriptionOptions& media_description_options,
493 const MediaSessionOptions& session_options,
494 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000495 const SessionDescription* current_description,
496 const RtpHeaderExtensions& video_rtp_extensions,
497 const VideoCodecs& video_codecs,
498 StreamParamsVec* current_streams,
499 SessionDescription* desc) const;
500
501 bool AddDataContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700502 const MediaDescriptionOptions& media_description_options,
503 const MediaSessionOptions& session_options,
504 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000505 const SessionDescription* current_description,
zhihuang1c378ed2017-08-17 14:10:50 -0700506 const DataCodecs& data_codecs,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000507 StreamParamsVec* current_streams,
508 SessionDescription* desc) const;
509
zhihuang1c378ed2017-08-17 14:10:50 -0700510 bool AddAudioContentForAnswer(
511 const MediaDescriptionOptions& media_description_options,
512 const MediaSessionOptions& session_options,
513 const ContentInfo* offer_content,
514 const SessionDescription* offer_description,
515 const ContentInfo* current_content,
516 const SessionDescription* current_description,
517 const TransportInfo* bundle_transport,
518 const AudioCodecs& audio_codecs,
519 StreamParamsVec* current_streams,
520 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000521
zhihuang1c378ed2017-08-17 14:10:50 -0700522 bool AddVideoContentForAnswer(
523 const MediaDescriptionOptions& media_description_options,
524 const MediaSessionOptions& session_options,
525 const ContentInfo* offer_content,
526 const SessionDescription* offer_description,
527 const ContentInfo* current_content,
528 const SessionDescription* current_description,
529 const TransportInfo* bundle_transport,
530 const VideoCodecs& video_codecs,
531 StreamParamsVec* current_streams,
532 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000533
zhihuang1c378ed2017-08-17 14:10:50 -0700534 bool AddDataContentForAnswer(
535 const MediaDescriptionOptions& media_description_options,
536 const MediaSessionOptions& session_options,
537 const ContentInfo* offer_content,
538 const SessionDescription* offer_description,
539 const ContentInfo* current_content,
540 const SessionDescription* current_description,
541 const TransportInfo* bundle_transport,
542 const DataCodecs& data_codecs,
543 StreamParamsVec* current_streams,
544 SessionDescription* answer) const;
545
546 void ComputeAudioCodecsIntersectionAndUnion();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000547
ossu075af922016-06-14 03:29:38 -0700548 AudioCodecs audio_send_codecs_;
549 AudioCodecs audio_recv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700550 // Intersection of send and recv.
ossu075af922016-06-14 03:29:38 -0700551 AudioCodecs audio_sendrecv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700552 // Union of send and recv.
553 AudioCodecs all_audio_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 RtpHeaderExtensions audio_rtp_extensions_;
555 VideoCodecs video_codecs_;
556 RtpHeaderExtensions video_rtp_extensions_;
557 DataCodecs data_codecs_;
jbauch5869f502017-06-29 12:31:36 -0700558 bool enable_encrypted_rtp_header_extensions_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700559 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter
560 // and setter.
561 SecurePolicy secure_ = SEC_DISABLED;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 std::string lang_;
563 const TransportDescriptionFactory* transport_desc_factory_;
564};
565
566// Convenience functions.
567bool IsMediaContent(const ContentInfo* content);
568bool IsAudioContent(const ContentInfo* content);
569bool IsVideoContent(const ContentInfo* content);
570bool IsDataContent(const ContentInfo* content);
deadbeef0ed85b22016-02-23 17:24:52 -0800571const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
572 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573const ContentInfo* GetFirstAudioContent(const ContentInfos& contents);
574const ContentInfo* GetFirstVideoContent(const ContentInfos& contents);
575const ContentInfo* GetFirstDataContent(const ContentInfos& contents);
576const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc);
577const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc);
578const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc);
579const AudioContentDescription* GetFirstAudioContentDescription(
580 const SessionDescription* sdesc);
581const VideoContentDescription* GetFirstVideoContentDescription(
582 const SessionDescription* sdesc);
583const DataContentDescription* GetFirstDataContentDescription(
584 const SessionDescription* sdesc);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700585// Non-const versions of the above functions.
586// Useful when modifying an existing description.
Steve Anton36b29d12017-10-30 09:57:42 -0700587ContentInfo* GetFirstMediaContent(ContentInfos* contents, MediaType media_type);
588ContentInfo* GetFirstAudioContent(ContentInfos* contents);
589ContentInfo* GetFirstVideoContent(ContentInfos* contents);
590ContentInfo* GetFirstDataContent(ContentInfos* contents);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700591ContentInfo* GetFirstAudioContent(SessionDescription* sdesc);
592ContentInfo* GetFirstVideoContent(SessionDescription* sdesc);
593ContentInfo* GetFirstDataContent(SessionDescription* sdesc);
594AudioContentDescription* GetFirstAudioContentDescription(
595 SessionDescription* sdesc);
596VideoContentDescription* GetFirstVideoContentDescription(
597 SessionDescription* sdesc);
598DataContentDescription* GetFirstDataContentDescription(
599 SessionDescription* sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600
deadbeef7914b8c2017-04-21 03:23:33 -0700601// Helper functions to return crypto suites used for SDES.
602void GetSupportedAudioSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
603 std::vector<int>* crypto_suites);
604void GetSupportedVideoSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
605 std::vector<int>* crypto_suites);
606void GetSupportedDataSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
607 std::vector<int>* crypto_suites);
608void GetSupportedAudioSdesCryptoSuiteNames(
609 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800610 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700611void GetSupportedVideoSdesCryptoSuiteNames(
612 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800613 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700614void GetSupportedDataSdesCryptoSuiteNames(
615 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800616 std::vector<std::string>* crypto_suite_names);
617
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618} // namespace cricket
619
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200620#endif // PC_MEDIASESSION_H_