blob: 35bd44421a5f61e5e2954341da86e1ae02d245e6 [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
terelius8c011e52016-04-26 05:28:11 -070013#ifndef WEBRTC_PC_MEDIASESSION_H_
14#define WEBRTC_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
ossu7bb87ee2017-01-23 04:56:25 -080021#include "webrtc/api/mediatypes.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/media/base/codec.h"
kjellandera96e2d72016-02-04 23:52:28 -080023#include "webrtc/media/base/cryptoparams.h"
24#include "webrtc/media/base/mediachannel.h"
kjellanderf4752772016-03-02 05:42:30 -080025#include "webrtc/media/base/mediaconstants.h"
kjellandera96e2d72016-02-04 23:52:28 -080026#include "webrtc/media/base/mediaengine.h" // For DataChannelType
27#include "webrtc/media/base/streamparams.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000028#include "webrtc/p2p/base/sessiondescription.h"
deadbeef49f34fd2016-12-06 16:22:06 -080029#include "webrtc/p2p/base/jseptransport.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000030#include "webrtc/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;
72const int kBufferedModeDisabled = 0;
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
ossu075af922016-06-14 03:29:38 -070077struct RtpTransceiverDirection {
78 bool send;
79 bool recv;
80
81 RtpTransceiverDirection(bool send, bool recv) : send(send), recv(recv) {}
82
83 bool operator==(const RtpTransceiverDirection& o) const {
84 return send == o.send && recv == o.recv;
85 }
86
87 bool operator!=(const RtpTransceiverDirection& o) const {
88 return !(*this == o);
89 }
90
91 static RtpTransceiverDirection FromMediaContentDirection(
92 MediaContentDirection md);
93
94 MediaContentDirection ToMediaContentDirection() const;
deadbeefe814a0d2017-02-25 18:15:09 -080095
96 RtpTransceiverDirection Reversed() const {
97 return RtpTransceiverDirection(recv, send);
98 }
ossu075af922016-06-14 03:29:38 -070099};
100
101RtpTransceiverDirection
102NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer,
103 RtpTransceiverDirection wants);
104
zhihuanga77e6bb2017-08-14 18:17:48 -0700105// Options for an RtpSender contained with an media description/"m=" section.
106struct SenderOptions {
107 std::string track_id;
108 std::string stream_id;
109 int num_sim_layers;
110};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111
zhihuanga77e6bb2017-08-14 18:17:48 -0700112// Options for an individual media description/"m=" section.
113struct MediaDescriptionOptions {
114 MediaDescriptionOptions(MediaType type,
115 const std::string& mid,
116 RtpTransceiverDirection direction,
117 bool stopped)
118 : type(type), mid(mid), direction(direction), stopped(stopped) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119
zhihuanga77e6bb2017-08-14 18:17:48 -0700120 // TODO(deadbeef): When we don't support Plan B, there will only be one
121 // sender per media description and this can be simplified.
122 void AddAudioSender(const std::string& track_id,
123 const std::string& stream_id);
124 void AddVideoSender(const std::string& track_id,
125 const std::string& stream_id,
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000126 int num_sim_layers);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127
zhihuanga77e6bb2017-08-14 18:17:48 -0700128 // Internally just uses sender_options.
129 void AddRtpDataChannel(const std::string& track_id,
130 const std::string& stream_id);
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000131
zhihuanga77e6bb2017-08-14 18:17:48 -0700132 MediaType type;
133 std::string mid;
134 RtpTransceiverDirection direction;
135 bool stopped;
136 TransportOptions transport_options;
137 // Note: There's no equivalent "RtpReceiverOptions" because only send
138 // stream information goes in the local descriptions.
139 std::vector<SenderOptions> sender_options;
140
141 private:
142 // Doesn't DCHECK on |type|.
143 void AddSenderInternal(const std::string& track_id,
144 const std::string& stream_id,
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000145 int num_sim_layers);
zhihuanga77e6bb2017-08-14 18:17:48 -0700146};
wu@webrtc.orgcecfd182013-10-30 05:18:12 +0000147
zhihuanga77e6bb2017-08-14 18:17:48 -0700148// Provides a mechanism for describing how m= sections should be generated.
149// The m= section with index X will use media_description_options[X]. There
150// must be an option for each existing section if creating an answer, or a
151// subsequent offer.
152struct MediaSessionOptions {
153 MediaSessionOptions() {}
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000154
zhihuanga77e6bb2017-08-14 18:17:48 -0700155 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
156 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
157 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); }
158
159 bool HasMediaDescription(MediaType type) const;
160
161 DataChannelType data_channel_type = DCT_NONE;
162 bool is_muc = false;
163 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
164 bool rtcp_mux_enabled = true;
165 bool bundle_enabled = false;
166 std::string rtcp_cname = kDefaultRtcpCname;
jbauchcb560652016-08-04 05:20:32 -0700167 rtc::CryptoOptions crypto_options;
zhihuanga77e6bb2017-08-14 18:17:48 -0700168 // List of media description options in the same order that the media
169 // descriptions will be generated.
170 std::vector<MediaDescriptionOptions> media_description_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171};
172
173// "content" (as used in XEP-0166) descriptions for voice and video.
174class MediaContentDescription : public ContentDescription {
175 public:
deadbeef13871492015-12-09 12:37:51 -0800176 MediaContentDescription() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177
178 virtual MediaType type() const = 0;
179 virtual bool has_codecs() const = 0;
180
181 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
182 // RTP/SAVPF or SCTP/DTLS.
183 std::string protocol() const { return protocol_; }
184 void set_protocol(const std::string& protocol) { protocol_ = protocol; }
185
186 MediaContentDirection direction() const { return direction_; }
187 void set_direction(MediaContentDirection direction) {
188 direction_ = direction;
189 }
190
191 bool rtcp_mux() const { return rtcp_mux_; }
192 void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
193
deadbeef13871492015-12-09 12:37:51 -0800194 bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
195 void set_rtcp_reduced_size(bool reduced_size) {
196 rtcp_reduced_size_ = reduced_size;
197 }
198
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 int bandwidth() const { return bandwidth_; }
200 void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
201
202 const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
203 void AddCrypto(const CryptoParams& params) {
204 cryptos_.push_back(params);
205 }
206 void set_cryptos(const std::vector<CryptoParams>& cryptos) {
207 cryptos_ = cryptos;
208 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000209
210 CryptoType crypto_required() const { return crypto_required_; }
211 void set_crypto_required(CryptoType type) {
212 crypto_required_ = type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 }
214
215 const RtpHeaderExtensions& rtp_header_extensions() const {
216 return rtp_header_extensions_;
217 }
218 void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
219 rtp_header_extensions_ = extensions;
220 rtp_header_extensions_set_ = true;
221 }
isheriff6f8d6862016-05-26 11:24:55 -0700222 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 rtp_header_extensions_.push_back(ext);
224 rtp_header_extensions_set_ = true;
225 }
isheriffa1c548b2016-05-31 16:12:24 -0700226 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
227 webrtc::RtpExtension webrtc_extension;
228 webrtc_extension.uri = ext.uri;
229 webrtc_extension.id = ext.id;
230 rtp_header_extensions_.push_back(webrtc_extension);
231 rtp_header_extensions_set_ = true;
232 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 void ClearRtpHeaderExtensions() {
234 rtp_header_extensions_.clear();
235 rtp_header_extensions_set_ = true;
236 }
237 // We can't always tell if an empty list of header extensions is
238 // because the other side doesn't support them, or just isn't hooked up to
239 // signal them. For now we assume an empty list means no signaling, but
240 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
241 // clearly indicated (i.e. when derived from other information).
242 bool rtp_header_extensions_set() const {
243 return rtp_header_extensions_set_;
244 }
245 // True iff the client supports multiple streams.
246 void set_multistream(bool multistream) { multistream_ = multistream; }
247 bool multistream() const { return multistream_; }
248 const StreamParamsVec& streams() const {
249 return streams_;
250 }
251 // TODO(pthatcher): Remove this by giving mediamessage.cc access
252 // to MediaContentDescription
253 StreamParamsVec& mutable_streams() {
254 return streams_;
255 }
256 void AddStream(const StreamParams& stream) {
257 streams_.push_back(stream);
258 }
259 // Legacy streams have an ssrc, but nothing else.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200260 void AddLegacyStream(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 streams_.push_back(StreamParams::CreateLegacy(ssrc));
262 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200263 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 StreamParams sp = StreamParams::CreateLegacy(ssrc);
265 sp.AddFidSsrc(ssrc, fid_ssrc);
266 streams_.push_back(sp);
267 }
268 // Sets the CNAME of all StreamParams if it have not been set.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 void SetCnameIfEmpty(const std::string& cname) {
270 for (cricket::StreamParamsVec::iterator it = streams_.begin();
271 it != streams_.end(); ++it) {
272 if (it->cname.empty())
273 it->cname = cname;
274 }
275 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200276 uint32_t first_ssrc() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 if (streams_.empty()) {
278 return 0;
279 }
280 return streams_[0].first_ssrc();
281 }
282 bool has_ssrcs() const {
283 if (streams_.empty()) {
284 return false;
285 }
286 return streams_[0].has_ssrcs();
287 }
288
289 void set_conference_mode(bool enable) { conference_mode_ = enable; }
290 bool conference_mode() const { return conference_mode_; }
291
292 void set_partial(bool partial) { partial_ = partial; }
293 bool partial() const { return partial_; }
294
295 void set_buffered_mode_latency(int latency) {
296 buffered_mode_latency_ = latency;
297 }
298 int buffered_mode_latency() const { return buffered_mode_latency_; }
299
zhihuang38989e52017-03-21 11:04:53 -0700300 // https://tools.ietf.org/html/rfc4566#section-5.7
301 // May be present at the media or session level of SDP. If present at both
302 // levels, the media-level attribute overwrites the session-level one.
303 void set_connection_address(const rtc::SocketAddress& address) {
304 connection_address_ = address;
305 }
306 const rtc::SocketAddress& connection_address() const {
307 return connection_address_;
308 }
309
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 protected:
deadbeef13871492015-12-09 12:37:51 -0800311 bool rtcp_mux_ = false;
312 bool rtcp_reduced_size_ = false;
313 int bandwidth_ = kAutoBandwidth;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 std::string protocol_;
315 std::vector<CryptoParams> cryptos_;
deadbeef13871492015-12-09 12:37:51 -0800316 CryptoType crypto_required_ = CT_NONE;
isheriff6f8d6862016-05-26 11:24:55 -0700317 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
deadbeef13871492015-12-09 12:37:51 -0800318 bool rtp_header_extensions_set_ = false;
319 bool multistream_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 StreamParamsVec streams_;
deadbeef13871492015-12-09 12:37:51 -0800321 bool conference_mode_ = false;
322 bool partial_ = false;
323 int buffered_mode_latency_ = kBufferedModeDisabled;
324 MediaContentDirection direction_ = MD_SENDRECV;
zhihuang38989e52017-03-21 11:04:53 -0700325 rtc::SocketAddress connection_address_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326};
327
328template <class C>
329class MediaContentDescriptionImpl : public MediaContentDescription {
330 public:
deadbeef67cf2c12016-04-13 10:07:16 -0700331 typedef C CodecType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332
deadbeef67cf2c12016-04-13 10:07:16 -0700333 // Codecs should be in preference order (most preferred codec first).
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 const std::vector<C>& codecs() const { return codecs_; }
335 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
336 virtual bool has_codecs() const { return !codecs_.empty(); }
337 bool HasCodec(int id) {
338 bool found = false;
339 for (typename std::vector<C>::iterator iter = codecs_.begin();
340 iter != codecs_.end(); ++iter) {
341 if (iter->id == id) {
342 found = true;
343 break;
344 }
345 }
346 return found;
347 }
348 void AddCodec(const C& codec) {
349 codecs_.push_back(codec);
350 }
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000351 void AddOrReplaceCodec(const C& codec) {
352 for (typename std::vector<C>::iterator iter = codecs_.begin();
353 iter != codecs_.end(); ++iter) {
354 if (iter->id == codec.id) {
355 *iter = codec;
356 return;
357 }
358 }
359 AddCodec(codec);
360 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 void AddCodecs(const std::vector<C>& codecs) {
362 typename std::vector<C>::const_iterator codec;
363 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
364 AddCodec(*codec);
365 }
366 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367
368 private:
369 std::vector<C> codecs_;
370};
371
372class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
373 public:
374 AudioContentDescription() :
375 agc_minus_10db_(false) {}
376
377 virtual ContentDescription* Copy() const {
378 return new AudioContentDescription(*this);
379 }
380 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
381
382 const std::string &lang() const { return lang_; }
383 void set_lang(const std::string &lang) { lang_ = lang; }
384
385 bool agc_minus_10db() const { return agc_minus_10db_; }
386 void set_agc_minus_10db(bool enable) {
387 agc_minus_10db_ = enable;
388 }
389
390 private:
391 bool agc_minus_10db_;
392
393 private:
394 std::string lang_;
395};
396
397class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
398 public:
399 virtual ContentDescription* Copy() const {
400 return new VideoContentDescription(*this);
401 }
402 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
403};
404
405class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
406 public:
zstein4b2e0822017-02-17 19:48:38 -0800407 DataContentDescription() {}
408
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 virtual ContentDescription* Copy() const {
410 return new DataContentDescription(*this);
411 }
412 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
zstein4b2e0822017-02-17 19:48:38 -0800413
414 bool use_sctpmap() const { return use_sctpmap_; }
415 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
416
417 private:
418 bool use_sctpmap_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419};
420
421// Creates media session descriptions according to the supplied codecs and
422// other fields, as well as the supplied per-call options.
423// When creating answers, performs the appropriate negotiation
424// of the various fields to determine the proper result.
425class MediaSessionDescriptionFactory {
426 public:
427 // Default ctor; use methods below to set configuration.
428 // The TransportDescriptionFactory is not owned by MediaSessionDescFactory,
429 // so it must be kept alive by the user of this class.
430 explicit MediaSessionDescriptionFactory(
431 const TransportDescriptionFactory* factory);
432 // This helper automatically sets up the factory to get its configuration
433 // from the specified ChannelManager.
434 MediaSessionDescriptionFactory(ChannelManager* cmanager,
435 const TransportDescriptionFactory* factory);
436
ossudedfd282016-06-14 07:12:39 -0700437 const AudioCodecs& audio_sendrecv_codecs() const;
ossu075af922016-06-14 03:29:38 -0700438 const AudioCodecs& audio_send_codecs() const;
439 const AudioCodecs& audio_recv_codecs() const;
440 void set_audio_codecs(const AudioCodecs& send_codecs,
441 const AudioCodecs& recv_codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442 void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
443 audio_rtp_extensions_ = extensions;
444 }
445 const RtpHeaderExtensions& audio_rtp_header_extensions() const {
446 return audio_rtp_extensions_;
447 }
448 const VideoCodecs& video_codecs() const { return video_codecs_; }
449 void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; }
450 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
451 video_rtp_extensions_ = extensions;
452 }
453 const RtpHeaderExtensions& video_rtp_header_extensions() const {
454 return video_rtp_extensions_;
455 }
456 const DataCodecs& data_codecs() const { return data_codecs_; }
457 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
458 SecurePolicy secure() const { return secure_; }
459 void set_secure(SecurePolicy s) { secure_ = s; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460
jbauch5869f502017-06-29 12:31:36 -0700461 void set_enable_encrypted_rtp_header_extensions(bool enable) {
462 enable_encrypted_rtp_header_extensions_ = enable;
463 }
464
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 SessionDescription* CreateOffer(
466 const MediaSessionOptions& options,
467 const SessionDescription* current_description) const;
468 SessionDescription* CreateAnswer(
zstein4b2e0822017-02-17 19:48:38 -0800469 const SessionDescription* offer,
470 const MediaSessionOptions& options,
471 const SessionDescription* current_description) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472
473 private:
ossu075af922016-06-14 03:29:38 -0700474 const AudioCodecs& GetAudioCodecsForOffer(
475 const RtpTransceiverDirection& direction) const;
476 const AudioCodecs& GetAudioCodecsForAnswer(
477 const RtpTransceiverDirection& offer,
478 const RtpTransceiverDirection& answer) const;
zhihuanga77e6bb2017-08-14 18:17:48 -0700479 void GetCodecsForOffer(const SessionDescription* current_description,
480 AudioCodecs* audio_codecs,
481 VideoCodecs* video_codecs,
482 DataCodecs* data_codecs) const;
483 void GetCodecsForAnswer(const SessionDescription* current_description,
484 const SessionDescription* remote_offer,
485 AudioCodecs* audio_codecs,
486 VideoCodecs* video_codecs,
487 DataCodecs* data_codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 void GetRtpHdrExtsToOffer(const SessionDescription* current_description,
489 RtpHeaderExtensions* audio_extensions,
490 RtpHeaderExtensions* video_extensions) const;
491 bool AddTransportOffer(
492 const std::string& content_name,
493 const TransportOptions& transport_options,
494 const SessionDescription* current_desc,
495 SessionDescription* offer) const;
496
497 TransportDescription* CreateTransportAnswer(
498 const std::string& content_name,
499 const SessionDescription* offer_desc,
500 const TransportOptions& transport_options,
deadbeefb7892532017-02-22 19:35:18 -0800501 const SessionDescription* current_desc,
502 bool require_transport_attributes) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503
504 bool AddTransportAnswer(
505 const std::string& content_name,
506 const TransportDescription& transport_desc,
507 SessionDescription* answer_desc) const;
508
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000509 // Helpers for adding media contents to the SessionDescription. Returns true
510 // it succeeds or the media content is not needed, or false if there is any
511 // error.
512
513 bool AddAudioContentForOffer(
zhihuanga77e6bb2017-08-14 18:17:48 -0700514 const MediaDescriptionOptions& media_description_options,
515 const MediaSessionOptions& session_options,
516 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000517 const SessionDescription* current_description,
518 const RtpHeaderExtensions& audio_rtp_extensions,
519 const AudioCodecs& audio_codecs,
520 StreamParamsVec* current_streams,
521 SessionDescription* desc) const;
522
523 bool AddVideoContentForOffer(
zhihuanga77e6bb2017-08-14 18:17:48 -0700524 const MediaDescriptionOptions& media_description_options,
525 const MediaSessionOptions& session_options,
526 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000527 const SessionDescription* current_description,
528 const RtpHeaderExtensions& video_rtp_extensions,
529 const VideoCodecs& video_codecs,
530 StreamParamsVec* current_streams,
531 SessionDescription* desc) const;
532
533 bool AddDataContentForOffer(
zhihuanga77e6bb2017-08-14 18:17:48 -0700534 const MediaDescriptionOptions& media_description_options,
535 const MediaSessionOptions& session_options,
536 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000537 const SessionDescription* current_description,
zhihuanga77e6bb2017-08-14 18:17:48 -0700538 const DataCodecs& data_codecs,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000539 StreamParamsVec* current_streams,
540 SessionDescription* desc) const;
541
zhihuanga77e6bb2017-08-14 18:17:48 -0700542 bool AddAudioContentForAnswer(
543 const MediaDescriptionOptions& media_description_options,
544 const MediaSessionOptions& session_options,
545 const ContentInfo* offer_content,
546 const SessionDescription* offer_description,
547 const ContentInfo* current_content,
548 const SessionDescription* current_description,
549 const TransportInfo* bundle_transport,
550 const AudioCodecs& audio_codecs,
551 StreamParamsVec* current_streams,
552 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000553
zhihuanga77e6bb2017-08-14 18:17:48 -0700554 bool AddVideoContentForAnswer(
555 const MediaDescriptionOptions& media_description_options,
556 const MediaSessionOptions& session_options,
557 const ContentInfo* offer_content,
558 const SessionDescription* offer_description,
559 const ContentInfo* current_content,
560 const SessionDescription* current_description,
561 const TransportInfo* bundle_transport,
562 const VideoCodecs& video_codecs,
563 StreamParamsVec* current_streams,
564 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000565
zhihuanga77e6bb2017-08-14 18:17:48 -0700566 bool AddDataContentForAnswer(
567 const MediaDescriptionOptions& media_description_options,
568 const MediaSessionOptions& session_options,
569 const ContentInfo* offer_content,
570 const SessionDescription* offer_description,
571 const ContentInfo* current_content,
572 const SessionDescription* current_description,
573 const TransportInfo* bundle_transport,
574 const DataCodecs& data_codecs,
575 StreamParamsVec* current_streams,
576 SessionDescription* answer) const;
577
578 void ComputeAudioCodecsIntersectionAndUnion();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000579
ossu075af922016-06-14 03:29:38 -0700580 AudioCodecs audio_send_codecs_;
581 AudioCodecs audio_recv_codecs_;
zhihuanga77e6bb2017-08-14 18:17:48 -0700582 // Intersection of send and recv.
ossu075af922016-06-14 03:29:38 -0700583 AudioCodecs audio_sendrecv_codecs_;
zhihuanga77e6bb2017-08-14 18:17:48 -0700584 // Union of send and recv.
585 AudioCodecs all_audio_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 RtpHeaderExtensions audio_rtp_extensions_;
587 VideoCodecs video_codecs_;
588 RtpHeaderExtensions video_rtp_extensions_;
589 DataCodecs data_codecs_;
jbauch5869f502017-06-29 12:31:36 -0700590 bool enable_encrypted_rtp_header_extensions_ = false;
zhihuanga77e6bb2017-08-14 18:17:48 -0700591 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter
592 // and setter.
593 SecurePolicy secure_ = SEC_DISABLED;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 std::string lang_;
595 const TransportDescriptionFactory* transport_desc_factory_;
596};
597
598// Convenience functions.
599bool IsMediaContent(const ContentInfo* content);
600bool IsAudioContent(const ContentInfo* content);
601bool IsVideoContent(const ContentInfo* content);
602bool IsDataContent(const ContentInfo* content);
deadbeef0ed85b22016-02-23 17:24:52 -0800603const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
604 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605const ContentInfo* GetFirstAudioContent(const ContentInfos& contents);
606const ContentInfo* GetFirstVideoContent(const ContentInfos& contents);
607const ContentInfo* GetFirstDataContent(const ContentInfos& contents);
608const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc);
609const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc);
610const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc);
611const AudioContentDescription* GetFirstAudioContentDescription(
612 const SessionDescription* sdesc);
613const VideoContentDescription* GetFirstVideoContentDescription(
614 const SessionDescription* sdesc);
615const DataContentDescription* GetFirstDataContentDescription(
616 const SessionDescription* sdesc);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700617// Non-const versions of the above functions.
618// Useful when modifying an existing description.
619ContentInfo* GetFirstMediaContent(ContentInfos& contents, MediaType media_type);
620ContentInfo* GetFirstAudioContent(ContentInfos& contents);
621ContentInfo* GetFirstVideoContent(ContentInfos& contents);
622ContentInfo* GetFirstDataContent(ContentInfos& contents);
623ContentInfo* GetFirstAudioContent(SessionDescription* sdesc);
624ContentInfo* GetFirstVideoContent(SessionDescription* sdesc);
625ContentInfo* GetFirstDataContent(SessionDescription* sdesc);
626AudioContentDescription* GetFirstAudioContentDescription(
627 SessionDescription* sdesc);
628VideoContentDescription* GetFirstVideoContentDescription(
629 SessionDescription* sdesc);
630DataContentDescription* GetFirstDataContentDescription(
631 SessionDescription* sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632
deadbeef7914b8c2017-04-21 03:23:33 -0700633// Helper functions to return crypto suites used for SDES.
634void GetSupportedAudioSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
635 std::vector<int>* crypto_suites);
636void GetSupportedVideoSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
637 std::vector<int>* crypto_suites);
638void GetSupportedDataSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
639 std::vector<int>* crypto_suites);
640void GetSupportedAudioSdesCryptoSuiteNames(
641 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800642 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700643void GetSupportedVideoSdesCryptoSuiteNames(
644 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800645 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700646void GetSupportedDataSdesCryptoSuiteNames(
647 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800648 std::vector<std::string>* crypto_suite_names);
649
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650} // namespace cricket
651
terelius8c011e52016-04-26 05:28:11 -0700652#endif // WEBRTC_PC_MEDIASESSION_H_