blob: ee7183f92ff77a92798c9857a26f88db3e92b70d [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
zhihuang1c378ed2017-08-17 14:10:50 -0700105// Options for an RtpSender contained with an media description/"m=" section.
106struct SenderOptions {
107 std::string track_id;
Steve Anton8ffb9c32017-08-31 15:45:38 -0700108 // TODO(steveanton): As part of work towards Unified Plan, this has been
109 // changed to be a vector. But for now this can only have exactly one.
110 std::vector<std::string> stream_ids;
zhihuang1c378ed2017-08-17 14:10:50 -0700111 int num_sim_layers;
112};
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000113
zhihuang1c378ed2017-08-17 14:10:50 -0700114// Options for an individual media description/"m=" section.
115struct MediaDescriptionOptions {
116 MediaDescriptionOptions(MediaType type,
117 const std::string& mid,
118 RtpTransceiverDirection direction,
119 bool stopped)
120 : type(type), mid(mid), direction(direction), stopped(stopped) {}
zhihuanga77e6bb2017-08-14 18:17:48 -0700121
zhihuang1c378ed2017-08-17 14:10:50 -0700122 // TODO(deadbeef): When we don't support Plan B, there will only be one
123 // sender per media description and this can be simplified.
124 void AddAudioSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700125 const std::vector<std::string>& stream_ids);
zhihuang1c378ed2017-08-17 14:10:50 -0700126 void AddVideoSender(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700127 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -0700128 int num_sim_layers);
zhihuanga77e6bb2017-08-14 18:17:48 -0700129
zhihuang1c378ed2017-08-17 14:10:50 -0700130 // Internally just uses sender_options.
131 void AddRtpDataChannel(const std::string& track_id,
132 const std::string& stream_id);
olka3c747662017-08-17 06:50:32 -0700133
zhihuang1c378ed2017-08-17 14:10:50 -0700134 MediaType type;
135 std::string mid;
136 RtpTransceiverDirection direction;
137 bool stopped;
138 TransportOptions transport_options;
139 // Note: There's no equivalent "RtpReceiverOptions" because only send
140 // stream information goes in the local descriptions.
141 std::vector<SenderOptions> sender_options;
142
143 private:
144 // Doesn't DCHECK on |type|.
145 void AddSenderInternal(const std::string& track_id,
Steve Anton8ffb9c32017-08-31 15:45:38 -0700146 const std::vector<std::string>& stream_ids,
olka3c747662017-08-17 06:50:32 -0700147 int num_sim_layers);
zhihuang1c378ed2017-08-17 14:10:50 -0700148};
olka3c747662017-08-17 06:50:32 -0700149
zhihuang1c378ed2017-08-17 14:10:50 -0700150// Provides a mechanism for describing how m= sections should be generated.
151// The m= section with index X will use media_description_options[X]. There
152// must be an option for each existing section if creating an answer, or a
153// subsequent offer.
154struct MediaSessionOptions {
155 MediaSessionOptions() {}
olka3c747662017-08-17 06:50:32 -0700156
zhihuang1c378ed2017-08-17 14:10:50 -0700157 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
158 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
159 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); }
160
161 bool HasMediaDescription(MediaType type) const;
162
163 DataChannelType data_channel_type = DCT_NONE;
164 bool is_muc = false;
165 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
166 bool rtcp_mux_enabled = true;
167 bool bundle_enabled = false;
168 std::string rtcp_cname = kDefaultRtcpCname;
jbauchcb560652016-08-04 05:20:32 -0700169 rtc::CryptoOptions crypto_options;
zhihuang1c378ed2017-08-17 14:10:50 -0700170 // List of media description options in the same order that the media
171 // descriptions will be generated.
172 std::vector<MediaDescriptionOptions> media_description_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173};
174
175// "content" (as used in XEP-0166) descriptions for voice and video.
176class MediaContentDescription : public ContentDescription {
177 public:
deadbeef13871492015-12-09 12:37:51 -0800178 MediaContentDescription() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179
180 virtual MediaType type() const = 0;
181 virtual bool has_codecs() const = 0;
182
183 // |protocol| is the expected media transport protocol, such as RTP/AVPF,
184 // RTP/SAVPF or SCTP/DTLS.
185 std::string protocol() const { return protocol_; }
186 void set_protocol(const std::string& protocol) { protocol_ = protocol; }
187
188 MediaContentDirection direction() const { return direction_; }
189 void set_direction(MediaContentDirection direction) {
190 direction_ = direction;
191 }
192
193 bool rtcp_mux() const { return rtcp_mux_; }
194 void set_rtcp_mux(bool mux) { rtcp_mux_ = mux; }
195
deadbeef13871492015-12-09 12:37:51 -0800196 bool rtcp_reduced_size() const { return rtcp_reduced_size_; }
197 void set_rtcp_reduced_size(bool reduced_size) {
198 rtcp_reduced_size_ = reduced_size;
199 }
200
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 int bandwidth() const { return bandwidth_; }
202 void set_bandwidth(int bandwidth) { bandwidth_ = bandwidth; }
203
204 const std::vector<CryptoParams>& cryptos() const { return cryptos_; }
205 void AddCrypto(const CryptoParams& params) {
206 cryptos_.push_back(params);
207 }
208 void set_cryptos(const std::vector<CryptoParams>& cryptos) {
209 cryptos_ = cryptos;
210 }
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000211
212 CryptoType crypto_required() const { return crypto_required_; }
213 void set_crypto_required(CryptoType type) {
214 crypto_required_ = type;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 }
216
217 const RtpHeaderExtensions& rtp_header_extensions() const {
218 return rtp_header_extensions_;
219 }
220 void set_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
221 rtp_header_extensions_ = extensions;
222 rtp_header_extensions_set_ = true;
223 }
isheriff6f8d6862016-05-26 11:24:55 -0700224 void AddRtpHeaderExtension(const webrtc::RtpExtension& ext) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 rtp_header_extensions_.push_back(ext);
226 rtp_header_extensions_set_ = true;
227 }
isheriffa1c548b2016-05-31 16:12:24 -0700228 void AddRtpHeaderExtension(const cricket::RtpHeaderExtension& ext) {
229 webrtc::RtpExtension webrtc_extension;
230 webrtc_extension.uri = ext.uri;
231 webrtc_extension.id = ext.id;
232 rtp_header_extensions_.push_back(webrtc_extension);
233 rtp_header_extensions_set_ = true;
234 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 void ClearRtpHeaderExtensions() {
236 rtp_header_extensions_.clear();
237 rtp_header_extensions_set_ = true;
238 }
239 // We can't always tell if an empty list of header extensions is
240 // because the other side doesn't support them, or just isn't hooked up to
241 // signal them. For now we assume an empty list means no signaling, but
242 // provide the ClearRtpHeaderExtensions method to allow "no support" to be
243 // clearly indicated (i.e. when derived from other information).
244 bool rtp_header_extensions_set() const {
245 return rtp_header_extensions_set_;
246 }
247 // True iff the client supports multiple streams.
248 void set_multistream(bool multistream) { multistream_ = multistream; }
249 bool multistream() const { return multistream_; }
250 const StreamParamsVec& streams() const {
251 return streams_;
252 }
253 // TODO(pthatcher): Remove this by giving mediamessage.cc access
254 // to MediaContentDescription
255 StreamParamsVec& mutable_streams() {
256 return streams_;
257 }
258 void AddStream(const StreamParams& stream) {
259 streams_.push_back(stream);
260 }
261 // Legacy streams have an ssrc, but nothing else.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200262 void AddLegacyStream(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 streams_.push_back(StreamParams::CreateLegacy(ssrc));
264 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200265 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000266 StreamParams sp = StreamParams::CreateLegacy(ssrc);
267 sp.AddFidSsrc(ssrc, fid_ssrc);
268 streams_.push_back(sp);
269 }
270 // Sets the CNAME of all StreamParams if it have not been set.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 void SetCnameIfEmpty(const std::string& cname) {
272 for (cricket::StreamParamsVec::iterator it = streams_.begin();
273 it != streams_.end(); ++it) {
274 if (it->cname.empty())
275 it->cname = cname;
276 }
277 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200278 uint32_t first_ssrc() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 if (streams_.empty()) {
280 return 0;
281 }
282 return streams_[0].first_ssrc();
283 }
284 bool has_ssrcs() const {
285 if (streams_.empty()) {
286 return false;
287 }
288 return streams_[0].has_ssrcs();
289 }
290
291 void set_conference_mode(bool enable) { conference_mode_ = enable; }
292 bool conference_mode() const { return conference_mode_; }
293
294 void set_partial(bool partial) { partial_ = partial; }
295 bool partial() const { return partial_; }
296
297 void set_buffered_mode_latency(int latency) {
298 buffered_mode_latency_ = latency;
299 }
300 int buffered_mode_latency() const { return buffered_mode_latency_; }
301
zhihuang38989e52017-03-21 11:04:53 -0700302 // https://tools.ietf.org/html/rfc4566#section-5.7
303 // May be present at the media or session level of SDP. If present at both
304 // levels, the media-level attribute overwrites the session-level one.
305 void set_connection_address(const rtc::SocketAddress& address) {
306 connection_address_ = address;
307 }
308 const rtc::SocketAddress& connection_address() const {
309 return connection_address_;
310 }
311
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 protected:
deadbeef13871492015-12-09 12:37:51 -0800313 bool rtcp_mux_ = false;
314 bool rtcp_reduced_size_ = false;
315 int bandwidth_ = kAutoBandwidth;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 std::string protocol_;
317 std::vector<CryptoParams> cryptos_;
deadbeef13871492015-12-09 12:37:51 -0800318 CryptoType crypto_required_ = CT_NONE;
isheriff6f8d6862016-05-26 11:24:55 -0700319 std::vector<webrtc::RtpExtension> rtp_header_extensions_;
deadbeef13871492015-12-09 12:37:51 -0800320 bool rtp_header_extensions_set_ = false;
321 bool multistream_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 StreamParamsVec streams_;
deadbeef13871492015-12-09 12:37:51 -0800323 bool conference_mode_ = false;
324 bool partial_ = false;
325 int buffered_mode_latency_ = kBufferedModeDisabled;
326 MediaContentDirection direction_ = MD_SENDRECV;
zhihuang38989e52017-03-21 11:04:53 -0700327 rtc::SocketAddress connection_address_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328};
329
330template <class C>
331class MediaContentDescriptionImpl : public MediaContentDescription {
332 public:
deadbeef67cf2c12016-04-13 10:07:16 -0700333 typedef C CodecType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334
deadbeef67cf2c12016-04-13 10:07:16 -0700335 // Codecs should be in preference order (most preferred codec first).
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 const std::vector<C>& codecs() const { return codecs_; }
337 void set_codecs(const std::vector<C>& codecs) { codecs_ = codecs; }
338 virtual bool has_codecs() const { return !codecs_.empty(); }
339 bool HasCodec(int id) {
340 bool found = false;
341 for (typename std::vector<C>::iterator iter = codecs_.begin();
342 iter != codecs_.end(); ++iter) {
343 if (iter->id == id) {
344 found = true;
345 break;
346 }
347 }
348 return found;
349 }
350 void AddCodec(const C& codec) {
351 codecs_.push_back(codec);
352 }
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +0000353 void AddOrReplaceCodec(const C& codec) {
354 for (typename std::vector<C>::iterator iter = codecs_.begin();
355 iter != codecs_.end(); ++iter) {
356 if (iter->id == codec.id) {
357 *iter = codec;
358 return;
359 }
360 }
361 AddCodec(codec);
362 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 void AddCodecs(const std::vector<C>& codecs) {
364 typename std::vector<C>::const_iterator codec;
365 for (codec = codecs.begin(); codec != codecs.end(); ++codec) {
366 AddCodec(*codec);
367 }
368 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369
370 private:
371 std::vector<C> codecs_;
372};
373
374class AudioContentDescription : public MediaContentDescriptionImpl<AudioCodec> {
375 public:
376 AudioContentDescription() :
377 agc_minus_10db_(false) {}
378
379 virtual ContentDescription* Copy() const {
380 return new AudioContentDescription(*this);
381 }
382 virtual MediaType type() const { return MEDIA_TYPE_AUDIO; }
383
384 const std::string &lang() const { return lang_; }
385 void set_lang(const std::string &lang) { lang_ = lang; }
386
387 bool agc_minus_10db() const { return agc_minus_10db_; }
388 void set_agc_minus_10db(bool enable) {
389 agc_minus_10db_ = enable;
390 }
391
392 private:
393 bool agc_minus_10db_;
394
395 private:
396 std::string lang_;
397};
398
399class VideoContentDescription : public MediaContentDescriptionImpl<VideoCodec> {
400 public:
401 virtual ContentDescription* Copy() const {
402 return new VideoContentDescription(*this);
403 }
404 virtual MediaType type() const { return MEDIA_TYPE_VIDEO; }
405};
406
407class DataContentDescription : public MediaContentDescriptionImpl<DataCodec> {
408 public:
zstein4b2e0822017-02-17 19:48:38 -0800409 DataContentDescription() {}
410
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 virtual ContentDescription* Copy() const {
412 return new DataContentDescription(*this);
413 }
414 virtual MediaType type() const { return MEDIA_TYPE_DATA; }
zstein4b2e0822017-02-17 19:48:38 -0800415
416 bool use_sctpmap() const { return use_sctpmap_; }
417 void set_use_sctpmap(bool enable) { use_sctpmap_ = enable; }
418
419 private:
420 bool use_sctpmap_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421};
422
423// Creates media session descriptions according to the supplied codecs and
424// other fields, as well as the supplied per-call options.
425// When creating answers, performs the appropriate negotiation
426// of the various fields to determine the proper result.
427class MediaSessionDescriptionFactory {
428 public:
429 // Default ctor; use methods below to set configuration.
430 // The TransportDescriptionFactory is not owned by MediaSessionDescFactory,
431 // so it must be kept alive by the user of this class.
432 explicit MediaSessionDescriptionFactory(
433 const TransportDescriptionFactory* factory);
434 // This helper automatically sets up the factory to get its configuration
435 // from the specified ChannelManager.
436 MediaSessionDescriptionFactory(ChannelManager* cmanager,
437 const TransportDescriptionFactory* factory);
438
ossudedfd282016-06-14 07:12:39 -0700439 const AudioCodecs& audio_sendrecv_codecs() const;
ossu075af922016-06-14 03:29:38 -0700440 const AudioCodecs& audio_send_codecs() const;
441 const AudioCodecs& audio_recv_codecs() const;
442 void set_audio_codecs(const AudioCodecs& send_codecs,
443 const AudioCodecs& recv_codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 void set_audio_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
445 audio_rtp_extensions_ = extensions;
446 }
447 const RtpHeaderExtensions& audio_rtp_header_extensions() const {
448 return audio_rtp_extensions_;
449 }
450 const VideoCodecs& video_codecs() const { return video_codecs_; }
451 void set_video_codecs(const VideoCodecs& codecs) { video_codecs_ = codecs; }
452 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
453 video_rtp_extensions_ = extensions;
454 }
455 const RtpHeaderExtensions& video_rtp_header_extensions() const {
456 return video_rtp_extensions_;
457 }
458 const DataCodecs& data_codecs() const { return data_codecs_; }
459 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
460 SecurePolicy secure() const { return secure_; }
461 void set_secure(SecurePolicy s) { secure_ = s; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462
jbauch5869f502017-06-29 12:31:36 -0700463 void set_enable_encrypted_rtp_header_extensions(bool enable) {
464 enable_encrypted_rtp_header_extensions_ = enable;
465 }
466
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 SessionDescription* CreateOffer(
468 const MediaSessionOptions& options,
469 const SessionDescription* current_description) const;
470 SessionDescription* CreateAnswer(
zstein4b2e0822017-02-17 19:48:38 -0800471 const SessionDescription* offer,
472 const MediaSessionOptions& options,
473 const SessionDescription* current_description) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474
475 private:
ossu075af922016-06-14 03:29:38 -0700476 const AudioCodecs& GetAudioCodecsForOffer(
477 const RtpTransceiverDirection& direction) const;
478 const AudioCodecs& GetAudioCodecsForAnswer(
479 const RtpTransceiverDirection& offer,
480 const RtpTransceiverDirection& answer) const;
zhihuang1c378ed2017-08-17 14:10:50 -0700481 void GetCodecsForOffer(const SessionDescription* current_description,
482 AudioCodecs* audio_codecs,
483 VideoCodecs* video_codecs,
484 DataCodecs* data_codecs) const;
485 void GetCodecsForAnswer(const SessionDescription* current_description,
486 const SessionDescription* remote_offer,
487 AudioCodecs* audio_codecs,
488 VideoCodecs* video_codecs,
489 DataCodecs* data_codecs) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490 void GetRtpHdrExtsToOffer(const SessionDescription* current_description,
491 RtpHeaderExtensions* audio_extensions,
492 RtpHeaderExtensions* video_extensions) const;
493 bool AddTransportOffer(
494 const std::string& content_name,
495 const TransportOptions& transport_options,
496 const SessionDescription* current_desc,
497 SessionDescription* offer) const;
498
499 TransportDescription* CreateTransportAnswer(
500 const std::string& content_name,
501 const SessionDescription* offer_desc,
502 const TransportOptions& transport_options,
deadbeefb7892532017-02-22 19:35:18 -0800503 const SessionDescription* current_desc,
504 bool require_transport_attributes) const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505
506 bool AddTransportAnswer(
507 const std::string& content_name,
508 const TransportDescription& transport_desc,
509 SessionDescription* answer_desc) const;
510
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000511 // Helpers for adding media contents to the SessionDescription. Returns true
512 // it succeeds or the media content is not needed, or false if there is any
513 // error.
514
515 bool AddAudioContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700516 const MediaDescriptionOptions& media_description_options,
517 const MediaSessionOptions& session_options,
518 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000519 const SessionDescription* current_description,
520 const RtpHeaderExtensions& audio_rtp_extensions,
521 const AudioCodecs& audio_codecs,
522 StreamParamsVec* current_streams,
523 SessionDescription* desc) const;
524
525 bool AddVideoContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700526 const MediaDescriptionOptions& media_description_options,
527 const MediaSessionOptions& session_options,
528 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000529 const SessionDescription* current_description,
530 const RtpHeaderExtensions& video_rtp_extensions,
531 const VideoCodecs& video_codecs,
532 StreamParamsVec* current_streams,
533 SessionDescription* desc) const;
534
535 bool AddDataContentForOffer(
zhihuang1c378ed2017-08-17 14:10:50 -0700536 const MediaDescriptionOptions& media_description_options,
537 const MediaSessionOptions& session_options,
538 const ContentInfo* current_content,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000539 const SessionDescription* current_description,
zhihuang1c378ed2017-08-17 14:10:50 -0700540 const DataCodecs& data_codecs,
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000541 StreamParamsVec* current_streams,
542 SessionDescription* desc) const;
543
zhihuang1c378ed2017-08-17 14:10:50 -0700544 bool AddAudioContentForAnswer(
545 const MediaDescriptionOptions& media_description_options,
546 const MediaSessionOptions& session_options,
547 const ContentInfo* offer_content,
548 const SessionDescription* offer_description,
549 const ContentInfo* current_content,
550 const SessionDescription* current_description,
551 const TransportInfo* bundle_transport,
552 const AudioCodecs& audio_codecs,
553 StreamParamsVec* current_streams,
554 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000555
zhihuang1c378ed2017-08-17 14:10:50 -0700556 bool AddVideoContentForAnswer(
557 const MediaDescriptionOptions& media_description_options,
558 const MediaSessionOptions& session_options,
559 const ContentInfo* offer_content,
560 const SessionDescription* offer_description,
561 const ContentInfo* current_content,
562 const SessionDescription* current_description,
563 const TransportInfo* bundle_transport,
564 const VideoCodecs& video_codecs,
565 StreamParamsVec* current_streams,
566 SessionDescription* answer) const;
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000567
zhihuang1c378ed2017-08-17 14:10:50 -0700568 bool AddDataContentForAnswer(
569 const MediaDescriptionOptions& media_description_options,
570 const MediaSessionOptions& session_options,
571 const ContentInfo* offer_content,
572 const SessionDescription* offer_description,
573 const ContentInfo* current_content,
574 const SessionDescription* current_description,
575 const TransportInfo* bundle_transport,
576 const DataCodecs& data_codecs,
577 StreamParamsVec* current_streams,
578 SessionDescription* answer) const;
579
580 void ComputeAudioCodecsIntersectionAndUnion();
jiayl@webrtc.orge7d47a12014-08-05 19:19:05 +0000581
ossu075af922016-06-14 03:29:38 -0700582 AudioCodecs audio_send_codecs_;
583 AudioCodecs audio_recv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700584 // Intersection of send and recv.
ossu075af922016-06-14 03:29:38 -0700585 AudioCodecs audio_sendrecv_codecs_;
zhihuang1c378ed2017-08-17 14:10:50 -0700586 // Union of send and recv.
587 AudioCodecs all_audio_codecs_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 RtpHeaderExtensions audio_rtp_extensions_;
589 VideoCodecs video_codecs_;
590 RtpHeaderExtensions video_rtp_extensions_;
591 DataCodecs data_codecs_;
jbauch5869f502017-06-29 12:31:36 -0700592 bool enable_encrypted_rtp_header_extensions_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700593 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter
594 // and setter.
595 SecurePolicy secure_ = SEC_DISABLED;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 std::string lang_;
597 const TransportDescriptionFactory* transport_desc_factory_;
598};
599
600// Convenience functions.
601bool IsMediaContent(const ContentInfo* content);
602bool IsAudioContent(const ContentInfo* content);
603bool IsVideoContent(const ContentInfo* content);
604bool IsDataContent(const ContentInfo* content);
deadbeef0ed85b22016-02-23 17:24:52 -0800605const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
606 MediaType media_type);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607const ContentInfo* GetFirstAudioContent(const ContentInfos& contents);
608const ContentInfo* GetFirstVideoContent(const ContentInfos& contents);
609const ContentInfo* GetFirstDataContent(const ContentInfos& contents);
610const ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc);
611const ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc);
612const ContentInfo* GetFirstDataContent(const SessionDescription* sdesc);
613const AudioContentDescription* GetFirstAudioContentDescription(
614 const SessionDescription* sdesc);
615const VideoContentDescription* GetFirstVideoContentDescription(
616 const SessionDescription* sdesc);
617const DataContentDescription* GetFirstDataContentDescription(
618 const SessionDescription* sdesc);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700619// Non-const versions of the above functions.
620// Useful when modifying an existing description.
621ContentInfo* GetFirstMediaContent(ContentInfos& contents, MediaType media_type);
622ContentInfo* GetFirstAudioContent(ContentInfos& contents);
623ContentInfo* GetFirstVideoContent(ContentInfos& contents);
624ContentInfo* GetFirstDataContent(ContentInfos& contents);
625ContentInfo* GetFirstAudioContent(SessionDescription* sdesc);
626ContentInfo* GetFirstVideoContent(SessionDescription* sdesc);
627ContentInfo* GetFirstDataContent(SessionDescription* sdesc);
628AudioContentDescription* GetFirstAudioContentDescription(
629 SessionDescription* sdesc);
630VideoContentDescription* GetFirstVideoContentDescription(
631 SessionDescription* sdesc);
632DataContentDescription* GetFirstDataContentDescription(
633 SessionDescription* sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634
deadbeef7914b8c2017-04-21 03:23:33 -0700635// Helper functions to return crypto suites used for SDES.
636void GetSupportedAudioSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
637 std::vector<int>* crypto_suites);
638void GetSupportedVideoSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
639 std::vector<int>* crypto_suites);
640void GetSupportedDataSdesCryptoSuites(const rtc::CryptoOptions& crypto_options,
641 std::vector<int>* crypto_suites);
642void GetSupportedAudioSdesCryptoSuiteNames(
643 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800644 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700645void GetSupportedVideoSdesCryptoSuiteNames(
646 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800647 std::vector<std::string>* crypto_suite_names);
deadbeef7914b8c2017-04-21 03:23:33 -0700648void GetSupportedDataSdesCryptoSuiteNames(
649 const rtc::CryptoOptions& crypto_options,
Guo-wei Shieh521ed7b2015-11-18 19:41:53 -0800650 std::vector<std::string>* crypto_suite_names);
651
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652} // namespace cricket
653
terelius8c011e52016-04-26 05:28:11 -0700654#endif // WEBRTC_PC_MEDIASESSION_H_