OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 static RtpTransceiverDirection FromMediaContentDirection( | 98 static RtpTransceiverDirection FromMediaContentDirection( |
99 MediaContentDirection md); | 99 MediaContentDirection md); |
100 | 100 |
101 MediaContentDirection ToMediaContentDirection() const; | 101 MediaContentDirection ToMediaContentDirection() const; |
102 }; | 102 }; |
103 | 103 |
104 RtpTransceiverDirection | 104 RtpTransceiverDirection |
105 NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer, | 105 NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer, |
106 RtpTransceiverDirection wants); | 106 RtpTransceiverDirection wants); |
107 | 107 |
| 108 struct SenderOptions { |
| 109 std::string track_id; |
| 110 std::string stream_id; |
| 111 int num_sim_layers; |
| 112 }; |
| 113 |
| 114 // Options for an individual media description/"m=" section. |
| 115 struct 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) {} |
| 121 |
| 122 // TODO(deadbeef): When we don't support Plan B, there will only be one |
| 123 // sender per transceiver and this can be simplified. |
| 124 void AddAudioSender(const std::string& track_id, |
| 125 const std::string& stream_id); |
| 126 void AddVideoSender(const std::string& track_id, |
| 127 const std::string& stream_id, |
| 128 int num_sim_layers); |
| 129 |
| 130 // Internally just uses sender_options. |
| 131 void AddRtpDataChannel(const std::string& track_id, |
| 132 const std::string& stream_id); |
| 133 |
| 134 MediaType type; |
| 135 // TODO: Stop using mid for identification, doesn't work for endpoints that |
| 136 // don't use MID. |
| 137 std::string mid; |
| 138 RtpTransceiverDirection direction; |
| 139 bool stopped; |
| 140 TransportOptions transport_options; |
| 141 // Note: There's no equivalent "RtpReceiverOptions" because only send |
| 142 // stream information goes in local descriptions. |
| 143 std::vector<SenderOptions> sender_options; |
| 144 |
| 145 private: |
| 146 // Doesn't DCHECK on |type|. |
| 147 void AddSenderInternal(const std::string& track_id, |
| 148 const std::string& stream_id, |
| 149 int num_sim_layers); |
| 150 }; |
| 151 |
| 152 // Provides a mechanism for describing how m= sections should be generated. |
| 153 // The m= section with index X will use media_description_options[X]. If no such |
| 154 // MediaDescriptionOptions exists, the m= section will just be rejected (port of |
| 155 // 0). If |data_channel_type| is not DCT_NONE, a data m= section will be |
| 156 // generated in the next available space. |
108 struct MediaSessionOptions { | 157 struct MediaSessionOptions { |
109 MediaSessionOptions() | 158 MediaSessionOptions() {} |
110 : recv_audio(true), | |
111 recv_video(false), | |
112 data_channel_type(DCT_NONE), | |
113 is_muc(false), | |
114 vad_enabled(true), // When disabled, removes all CN codecs from SDP. | |
115 rtcp_mux_enabled(true), | |
116 bundle_enabled(false), | |
117 video_bandwidth(kAutoBandwidth), | |
118 data_bandwidth(kDataMaxBandwidth), | |
119 rtcp_cname(kDefaultRtcpCname) {} | |
120 | 159 |
121 bool has_audio() const { | 160 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); } |
122 return recv_audio || HasSendMediaStream(MEDIA_TYPE_AUDIO); | 161 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); } |
123 } | 162 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); } |
124 bool has_video() const { | |
125 return recv_video || HasSendMediaStream(MEDIA_TYPE_VIDEO); | |
126 } | |
127 bool has_data() const { return data_channel_type != DCT_NONE; } | |
128 | 163 |
129 // Add a stream with MediaType type and id. | 164 bool HasMediaDescription(MediaType type) const; |
130 // All streams with the same sync_label will get the same CNAME. | |
131 // All ids must be unique. | |
132 void AddSendStream(MediaType type, | |
133 const std::string& id, | |
134 const std::string& sync_label); | |
135 void AddSendVideoStream(const std::string& id, | |
136 const std::string& sync_label, | |
137 int num_sim_layers); | |
138 void RemoveSendStream(MediaType type, const std::string& id); | |
139 | 165 |
| 166 // They're not stored in a map in the first place because the order matters. |
| 167 // TODO: make index-based |
| 168 std::vector<MediaDescriptionOptions>::iterator FindMediaDescription( |
| 169 const std::string& mid); |
140 | 170 |
141 // Helper function. | 171 DataChannelType data_channel_type = DCT_NONE; |
142 void AddSendStreamInternal(MediaType type, | 172 bool is_muc = false; |
143 const std::string& id, | 173 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP. |
144 const std::string& sync_label, | 174 bool rtcp_mux_enabled = true; |
145 int num_sim_layers); | 175 bool bundle_enabled = false; |
146 | 176 std::string rtcp_cname = kDefaultRtcpCname; |
147 bool HasSendMediaStream(MediaType type) const; | |
148 | |
149 // TODO(deadbeef): Put all the audio/video/data-specific options into a map | |
150 // structure (content name -> options). | |
151 // MediaSessionDescriptionFactory assumes there will never be more than one | |
152 // audio/video/data content, but this will change with unified plan. | |
153 bool recv_audio; | |
154 bool recv_video; | |
155 DataChannelType data_channel_type; | |
156 bool is_muc; | |
157 bool vad_enabled; | |
158 bool rtcp_mux_enabled; | |
159 bool bundle_enabled; | |
160 // bps. -1 == auto. | |
161 int video_bandwidth; | |
162 int data_bandwidth; | |
163 bool enable_ice_renomination = false; | |
164 // content name ("mid") => options. | |
165 std::map<std::string, TransportOptions> transport_options; | |
166 std::string rtcp_cname; | |
167 rtc::CryptoOptions crypto_options; | 177 rtc::CryptoOptions crypto_options; |
168 | 178 |
169 struct Stream { | 179 // List of media description options in the same order that the media |
170 Stream(MediaType type, | 180 // descriptions will be generated. |
171 const std::string& id, | 181 std::vector<MediaDescriptionOptions> media_description_options; |
172 const std::string& sync_label, | |
173 int num_sim_layers) | |
174 : type(type), id(id), sync_label(sync_label), | |
175 num_sim_layers(num_sim_layers) { | |
176 } | |
177 MediaType type; | |
178 std::string id; | |
179 std::string sync_label; | |
180 int num_sim_layers; | |
181 }; | |
182 | |
183 typedef std::vector<Stream> Streams; | |
184 Streams streams; | |
185 }; | 182 }; |
186 | 183 |
187 // "content" (as used in XEP-0166) descriptions for voice and video. | 184 // "content" (as used in XEP-0166) descriptions for voice and video. |
188 class MediaContentDescription : public ContentDescription { | 185 class MediaContentDescription : public ContentDescription { |
189 public: | 186 public: |
190 MediaContentDescription() {} | 187 MediaContentDescription() {} |
191 | 188 |
192 virtual MediaType type() const = 0; | 189 virtual MediaType type() const = 0; |
193 virtual bool has_codecs() const = 0; | 190 virtual bool has_codecs() const = 0; |
194 | 191 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // Legacy streams have an ssrc, but nothing else. | 270 // Legacy streams have an ssrc, but nothing else. |
274 void AddLegacyStream(uint32_t ssrc) { | 271 void AddLegacyStream(uint32_t ssrc) { |
275 streams_.push_back(StreamParams::CreateLegacy(ssrc)); | 272 streams_.push_back(StreamParams::CreateLegacy(ssrc)); |
276 } | 273 } |
277 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { | 274 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { |
278 StreamParams sp = StreamParams::CreateLegacy(ssrc); | 275 StreamParams sp = StreamParams::CreateLegacy(ssrc); |
279 sp.AddFidSsrc(ssrc, fid_ssrc); | 276 sp.AddFidSsrc(ssrc, fid_ssrc); |
280 streams_.push_back(sp); | 277 streams_.push_back(sp); |
281 } | 278 } |
282 // Sets the CNAME of all StreamParams if it have not been set. | 279 // Sets the CNAME of all StreamParams if it have not been set. |
283 // This can be used to set the CNAME of legacy streams. | |
284 void SetCnameIfEmpty(const std::string& cname) { | 280 void SetCnameIfEmpty(const std::string& cname) { |
285 for (cricket::StreamParamsVec::iterator it = streams_.begin(); | 281 for (cricket::StreamParamsVec::iterator it = streams_.begin(); |
286 it != streams_.end(); ++it) { | 282 it != streams_.end(); ++it) { |
287 if (it->cname.empty()) | 283 if (it->cname.empty()) |
288 it->cname = cname; | 284 it->cname = cname; |
289 } | 285 } |
290 } | 286 } |
291 uint32_t first_ssrc() const { | 287 uint32_t first_ssrc() const { |
292 if (streams_.empty()) { | 288 if (streams_.empty()) { |
293 return 0; | 289 return 0; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) { | 442 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
447 video_rtp_extensions_ = extensions; | 443 video_rtp_extensions_ = extensions; |
448 } | 444 } |
449 const RtpHeaderExtensions& video_rtp_header_extensions() const { | 445 const RtpHeaderExtensions& video_rtp_header_extensions() const { |
450 return video_rtp_extensions_; | 446 return video_rtp_extensions_; |
451 } | 447 } |
452 const DataCodecs& data_codecs() const { return data_codecs_; } | 448 const DataCodecs& data_codecs() const { return data_codecs_; } |
453 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; } | 449 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; } |
454 SecurePolicy secure() const { return secure_; } | 450 SecurePolicy secure() const { return secure_; } |
455 void set_secure(SecurePolicy s) { secure_ = s; } | 451 void set_secure(SecurePolicy s) { secure_ = s; } |
456 // Decides if a StreamParams shall be added to the audio and video media | |
457 // content in SessionDescription when CreateOffer and CreateAnswer is called | |
458 // even if |options| don't include a Stream. This is needed to support legacy | |
459 // applications. |add_legacy_| is true per default. | |
460 void set_add_legacy_streams(bool add_legacy) { add_legacy_ = add_legacy; } | |
461 | 452 |
462 SessionDescription* CreateOffer( | 453 SessionDescription* CreateOffer( |
463 const MediaSessionOptions& options, | 454 const MediaSessionOptions& options, |
464 const SessionDescription* current_description) const; | 455 const SessionDescription* current_description) const; |
465 SessionDescription* CreateAnswer( | 456 SessionDescription* CreateAnswer( |
466 const SessionDescription* offer, | 457 const SessionDescription* offer, |
467 const MediaSessionOptions& options, | 458 const MediaSessionOptions& options, |
468 const SessionDescription* current_description) const; | 459 const SessionDescription* current_description) const; |
469 | 460 |
470 private: | 461 private: |
471 const AudioCodecs& GetAudioCodecsForOffer( | 462 const AudioCodecs& GetAudioCodecsForOffer( |
472 const RtpTransceiverDirection& direction) const; | 463 const RtpTransceiverDirection& direction) const; |
473 const AudioCodecs& GetAudioCodecsForAnswer( | 464 const AudioCodecs& GetAudioCodecsForAnswer( |
474 const RtpTransceiverDirection& offer, | 465 const RtpTransceiverDirection& offer, |
475 const RtpTransceiverDirection& answer) const; | 466 const RtpTransceiverDirection& answer) const; |
476 void GetCodecsToOffer(const SessionDescription* current_description, | 467 void GetCodecsForOffer(const SessionDescription* current_description, |
477 const AudioCodecs& supported_audio_codecs, | 468 AudioCodecs* audio_codecs, |
478 const VideoCodecs& supported_video_codecs, | 469 VideoCodecs* video_codecs, |
479 const DataCodecs& supported_data_codecs, | 470 DataCodecs* data_codecs) const; |
480 AudioCodecs* audio_codecs, | 471 void GetCodecsForAnswer(const SessionDescription* current_description, |
481 VideoCodecs* video_codecs, | 472 const SessionDescription* remote_offer, |
482 DataCodecs* data_codecs) const; | 473 AudioCodecs* audio_codecs, |
| 474 VideoCodecs* video_codecs, |
| 475 DataCodecs* data_codecs) const; |
483 void GetRtpHdrExtsToOffer(const SessionDescription* current_description, | 476 void GetRtpHdrExtsToOffer(const SessionDescription* current_description, |
484 RtpHeaderExtensions* audio_extensions, | 477 RtpHeaderExtensions* audio_extensions, |
485 RtpHeaderExtensions* video_extensions) const; | 478 RtpHeaderExtensions* video_extensions) const; |
486 bool AddTransportOffer( | 479 bool AddTransportOffer( |
487 const std::string& content_name, | 480 const std::string& content_name, |
488 const TransportOptions& transport_options, | 481 const TransportOptions& transport_options, |
489 const SessionDescription* current_desc, | 482 const SessionDescription* current_desc, |
490 SessionDescription* offer) const; | 483 SessionDescription* offer) const; |
491 | 484 |
492 TransportDescription* CreateTransportAnswer( | 485 TransportDescription* CreateTransportAnswer( |
493 const std::string& content_name, | 486 const std::string& content_name, |
494 const SessionDescription* offer_desc, | 487 const SessionDescription* offer_desc, |
495 const TransportOptions& transport_options, | 488 const TransportOptions& transport_options, |
496 const SessionDescription* current_desc) const; | 489 const SessionDescription* current_desc) const; |
497 | 490 |
498 bool AddTransportAnswer( | 491 bool AddTransportAnswer( |
499 const std::string& content_name, | 492 const std::string& content_name, |
500 const TransportDescription& transport_desc, | 493 const TransportDescription& transport_desc, |
501 SessionDescription* answer_desc) const; | 494 SessionDescription* answer_desc) const; |
502 | 495 |
503 // Helpers for adding media contents to the SessionDescription. Returns true | 496 // Helpers for adding media contents to the SessionDescription. Returns true |
504 // it succeeds or the media content is not needed, or false if there is any | 497 // it succeeds or the media content is not needed, or false if there is any |
505 // error. | 498 // error. |
506 | 499 |
507 bool AddAudioContentForOffer( | 500 bool AddAudioContentForOffer( |
508 const MediaSessionOptions& options, | 501 const MediaDescriptionOptions& media_description_options, |
| 502 const MediaSessionOptions& session_options, |
| 503 const ContentInfo* current_content, |
509 const SessionDescription* current_description, | 504 const SessionDescription* current_description, |
510 const RtpHeaderExtensions& audio_rtp_extensions, | 505 const RtpHeaderExtensions& audio_rtp_extensions, |
511 const AudioCodecs& audio_codecs, | 506 const AudioCodecs& audio_codecs, |
512 StreamParamsVec* current_streams, | 507 StreamParamsVec* current_streams, |
513 SessionDescription* desc) const; | 508 SessionDescription* desc) const; |
514 | 509 |
515 bool AddVideoContentForOffer( | 510 bool AddVideoContentForOffer( |
516 const MediaSessionOptions& options, | 511 const MediaDescriptionOptions& media_description_options, |
| 512 const MediaSessionOptions& session_options, |
| 513 const ContentInfo* current_content, |
517 const SessionDescription* current_description, | 514 const SessionDescription* current_description, |
518 const RtpHeaderExtensions& video_rtp_extensions, | 515 const RtpHeaderExtensions& video_rtp_extensions, |
519 const VideoCodecs& video_codecs, | 516 const VideoCodecs& video_codecs, |
520 StreamParamsVec* current_streams, | 517 StreamParamsVec* current_streams, |
521 SessionDescription* desc) const; | 518 SessionDescription* desc) const; |
522 | 519 |
523 bool AddDataContentForOffer( | 520 bool AddDataContentForOffer( |
524 const MediaSessionOptions& options, | 521 const MediaDescriptionOptions& media_description_options, |
| 522 const MediaSessionOptions& session_options, |
| 523 const ContentInfo* current_content, |
525 const SessionDescription* current_description, | 524 const SessionDescription* current_description, |
526 DataCodecs* data_codecs, | 525 const DataCodecs& data_codecs, |
527 StreamParamsVec* current_streams, | 526 StreamParamsVec* current_streams, |
528 SessionDescription* desc) const; | 527 SessionDescription* desc) const; |
529 | 528 |
530 bool AddAudioContentForAnswer( | 529 bool AddAudioContentForAnswer( |
531 const SessionDescription* offer, | 530 const MediaDescriptionOptions& media_description_options, |
532 const MediaSessionOptions& options, | 531 const MediaSessionOptions& session_options, |
| 532 const ContentInfo* offer_content, |
| 533 const SessionDescription* offer_description, |
| 534 const ContentInfo* current_content, |
533 const SessionDescription* current_description, | 535 const SessionDescription* current_description, |
| 536 const AudioCodecs& audio_codecs, |
534 StreamParamsVec* current_streams, | 537 StreamParamsVec* current_streams, |
535 SessionDescription* answer) const; | 538 SessionDescription* answer) const; |
536 | 539 |
537 bool AddVideoContentForAnswer( | 540 bool AddVideoContentForAnswer( |
538 const SessionDescription* offer, | 541 const MediaDescriptionOptions& media_description_options, |
539 const MediaSessionOptions& options, | 542 const MediaSessionOptions& session_options, |
| 543 const ContentInfo* offer_content, |
| 544 const SessionDescription* offer_description, |
| 545 const ContentInfo* current_content, |
540 const SessionDescription* current_description, | 546 const SessionDescription* current_description, |
| 547 const VideoCodecs& video_codecs, |
541 StreamParamsVec* current_streams, | 548 StreamParamsVec* current_streams, |
542 SessionDescription* answer) const; | 549 SessionDescription* answer) const; |
543 | 550 |
544 bool AddDataContentForAnswer( | 551 bool AddDataContentForAnswer( |
545 const SessionDescription* offer, | 552 const MediaDescriptionOptions& media_description_options, |
546 const MediaSessionOptions& options, | 553 const MediaSessionOptions& session_options, |
| 554 const ContentInfo* offer_content, |
| 555 const SessionDescription* offer_description, |
| 556 const ContentInfo* current_content, |
547 const SessionDescription* current_description, | 557 const SessionDescription* current_description, |
| 558 const DataCodecs& data_codecs, |
548 StreamParamsVec* current_streams, | 559 StreamParamsVec* current_streams, |
549 SessionDescription* answer) const; | 560 SessionDescription* answer) const; |
550 | 561 |
551 AudioCodecs audio_send_codecs_; | 562 AudioCodecs audio_send_codecs_; |
552 AudioCodecs audio_recv_codecs_; | 563 AudioCodecs audio_recv_codecs_; |
| 564 // Intersection of send and recv. |
553 AudioCodecs audio_sendrecv_codecs_; | 565 AudioCodecs audio_sendrecv_codecs_; |
| 566 // Union of send and recv. |
| 567 AudioCodecs all_audio_codecs_; |
554 RtpHeaderExtensions audio_rtp_extensions_; | 568 RtpHeaderExtensions audio_rtp_extensions_; |
555 VideoCodecs video_codecs_; | 569 VideoCodecs video_codecs_; |
556 RtpHeaderExtensions video_rtp_extensions_; | 570 RtpHeaderExtensions video_rtp_extensions_; |
557 DataCodecs data_codecs_; | 571 DataCodecs data_codecs_; |
558 SecurePolicy secure_; | 572 SecurePolicy secure_ = SEC_DISABLED; |
559 bool add_legacy_; | |
560 std::string lang_; | 573 std::string lang_; |
561 const TransportDescriptionFactory* transport_desc_factory_; | 574 const TransportDescriptionFactory* transport_desc_factory_; |
562 }; | 575 }; |
563 | 576 |
564 // Convenience functions. | 577 // Convenience functions. |
565 bool IsMediaContent(const ContentInfo* content); | 578 bool IsMediaContent(const ContentInfo* content); |
566 bool IsAudioContent(const ContentInfo* content); | 579 bool IsAudioContent(const ContentInfo* content); |
567 bool IsVideoContent(const ContentInfo* content); | 580 bool IsVideoContent(const ContentInfo* content); |
568 bool IsDataContent(const ContentInfo* content); | 581 bool IsDataContent(const ContentInfo* content); |
569 const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, | 582 const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 void GetSupportedVideoCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, | 622 void GetSupportedVideoCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
610 std::vector<std::string>* crypto_suite_names); | 623 std::vector<std::string>* crypto_suite_names); |
611 void GetSupportedDataCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, | 624 void GetSupportedDataCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
612 std::vector<std::string>* crypto_suite_names); | 625 std::vector<std::string>* crypto_suite_names); |
613 void GetDefaultSrtpCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, | 626 void GetDefaultSrtpCryptoSuiteNames(const rtc::CryptoOptions& crypto_options, |
614 std::vector<std::string>* crypto_suite_names); | 627 std::vector<std::string>* crypto_suite_names); |
615 | 628 |
616 } // namespace cricket | 629 } // namespace cricket |
617 | 630 |
618 #endif // WEBRTC_PC_MEDIASESSION_H_ | 631 #endif // WEBRTC_PC_MEDIASESSION_H_ |
OLD | NEW |