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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 RtpTransceiverDirection Reversed() const { | 96 RtpTransceiverDirection Reversed() const { |
97 return RtpTransceiverDirection(recv, send); | 97 return RtpTransceiverDirection(recv, send); |
98 } | 98 } |
99 }; | 99 }; |
100 | 100 |
101 RtpTransceiverDirection | 101 RtpTransceiverDirection |
102 NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer, | 102 NegotiateRtpTransceiverDirection(RtpTransceiverDirection offer, |
103 RtpTransceiverDirection wants); | 103 RtpTransceiverDirection wants); |
104 | 104 |
| 105 // Options for an RtpSender contained with an media description/"m=" section. |
| 106 struct SenderOptions { |
| 107 std::string track_id; |
| 108 std::string stream_id; |
| 109 int num_sim_layers; |
| 110 }; |
| 111 |
| 112 // Options for an individual media description/"m=" section. |
| 113 struct 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) {} |
| 119 |
| 120 // 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, |
| 126 int num_sim_layers); |
| 127 |
| 128 // Internally just uses sender_options. |
| 129 void AddRtpDataChannel(const std::string& track_id, |
| 130 const std::string& stream_id); |
| 131 |
| 132 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, |
| 145 int num_sim_layers); |
| 146 }; |
| 147 |
| 148 // 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. |
105 struct MediaSessionOptions { | 152 struct MediaSessionOptions { |
106 MediaSessionOptions() | 153 MediaSessionOptions() {} |
107 : recv_audio(true), | |
108 recv_video(false), | |
109 data_channel_type(DCT_NONE), | |
110 is_muc(false), | |
111 vad_enabled(true), // When disabled, removes all CN codecs from SDP. | |
112 rtcp_mux_enabled(true), | |
113 bundle_enabled(false), | |
114 video_bandwidth(kAutoBandwidth), | |
115 data_bandwidth(kDataMaxBandwidth), | |
116 rtcp_cname(kDefaultRtcpCname) {} | |
117 | 154 |
118 bool has_audio() const { | 155 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); } |
119 return recv_audio || HasSendMediaStream(MEDIA_TYPE_AUDIO); | 156 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); } |
120 } | 157 bool has_data() const { return HasMediaDescription(MEDIA_TYPE_DATA); } |
121 bool has_video() const { | |
122 return recv_video || HasSendMediaStream(MEDIA_TYPE_VIDEO); | |
123 } | |
124 bool has_data() const { return data_channel_type != DCT_NONE; } | |
125 | 158 |
126 // Add a stream with MediaType type and id. | 159 bool HasMediaDescription(MediaType type) const; |
127 // All streams with the same sync_label will get the same CNAME. | |
128 // All ids must be unique. | |
129 void AddSendStream(MediaType type, | |
130 const std::string& id, | |
131 const std::string& sync_label); | |
132 void AddSendVideoStream(const std::string& id, | |
133 const std::string& sync_label, | |
134 int num_sim_layers); | |
135 void RemoveSendStream(MediaType type, const std::string& id); | |
136 | 160 |
137 | 161 DataChannelType data_channel_type = DCT_NONE; |
138 // Helper function. | 162 bool is_muc = false; |
139 void AddSendStreamInternal(MediaType type, | 163 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP. |
140 const std::string& id, | 164 bool rtcp_mux_enabled = true; |
141 const std::string& sync_label, | 165 bool bundle_enabled = false; |
142 int num_sim_layers); | 166 std::string rtcp_cname = kDefaultRtcpCname; |
143 | |
144 bool HasSendMediaStream(MediaType type) const; | |
145 | |
146 // TODO(deadbeef): Put all the audio/video/data-specific options into a map | |
147 // structure (content name -> options). | |
148 // MediaSessionDescriptionFactory assumes there will never be more than one | |
149 // audio/video/data content, but this will change with unified plan. | |
150 bool recv_audio; | |
151 bool recv_video; | |
152 DataChannelType data_channel_type; | |
153 bool is_muc; | |
154 bool vad_enabled; | |
155 bool rtcp_mux_enabled; | |
156 bool bundle_enabled; | |
157 // bps. -1 == auto. | |
158 int video_bandwidth; | |
159 int data_bandwidth; | |
160 bool enable_ice_renomination = false; | |
161 // content name ("mid") => options. | |
162 std::map<std::string, TransportOptions> transport_options; | |
163 std::string rtcp_cname; | |
164 rtc::CryptoOptions crypto_options; | 167 rtc::CryptoOptions crypto_options; |
165 | 168 // List of media description options in the same order that the media |
166 struct Stream { | 169 // descriptions will be generated. |
167 Stream(MediaType type, | 170 std::vector<MediaDescriptionOptions> media_description_options; |
168 const std::string& id, | |
169 const std::string& sync_label, | |
170 int num_sim_layers) | |
171 : type(type), id(id), sync_label(sync_label), | |
172 num_sim_layers(num_sim_layers) { | |
173 } | |
174 MediaType type; | |
175 std::string id; | |
176 std::string sync_label; | |
177 int num_sim_layers; | |
178 }; | |
179 | |
180 typedef std::vector<Stream> Streams; | |
181 Streams streams; | |
182 }; | 171 }; |
183 | 172 |
184 // "content" (as used in XEP-0166) descriptions for voice and video. | 173 // "content" (as used in XEP-0166) descriptions for voice and video. |
185 class MediaContentDescription : public ContentDescription { | 174 class MediaContentDescription : public ContentDescription { |
186 public: | 175 public: |
187 MediaContentDescription() {} | 176 MediaContentDescription() {} |
188 | 177 |
189 virtual MediaType type() const = 0; | 178 virtual MediaType type() const = 0; |
190 virtual bool has_codecs() const = 0; | 179 virtual bool has_codecs() const = 0; |
191 | 180 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Legacy streams have an ssrc, but nothing else. | 259 // Legacy streams have an ssrc, but nothing else. |
271 void AddLegacyStream(uint32_t ssrc) { | 260 void AddLegacyStream(uint32_t ssrc) { |
272 streams_.push_back(StreamParams::CreateLegacy(ssrc)); | 261 streams_.push_back(StreamParams::CreateLegacy(ssrc)); |
273 } | 262 } |
274 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { | 263 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { |
275 StreamParams sp = StreamParams::CreateLegacy(ssrc); | 264 StreamParams sp = StreamParams::CreateLegacy(ssrc); |
276 sp.AddFidSsrc(ssrc, fid_ssrc); | 265 sp.AddFidSsrc(ssrc, fid_ssrc); |
277 streams_.push_back(sp); | 266 streams_.push_back(sp); |
278 } | 267 } |
279 // Sets the CNAME of all StreamParams if it have not been set. | 268 // Sets the CNAME of all StreamParams if it have not been set. |
280 // This can be used to set the CNAME of legacy streams. | |
281 void SetCnameIfEmpty(const std::string& cname) { | 269 void SetCnameIfEmpty(const std::string& cname) { |
282 for (cricket::StreamParamsVec::iterator it = streams_.begin(); | 270 for (cricket::StreamParamsVec::iterator it = streams_.begin(); |
283 it != streams_.end(); ++it) { | 271 it != streams_.end(); ++it) { |
284 if (it->cname.empty()) | 272 if (it->cname.empty()) |
285 it->cname = cname; | 273 it->cname = cname; |
286 } | 274 } |
287 } | 275 } |
288 uint32_t first_ssrc() const { | 276 uint32_t first_ssrc() const { |
289 if (streams_.empty()) { | 277 if (streams_.empty()) { |
290 return 0; | 278 return 0; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) { | 450 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) { |
463 video_rtp_extensions_ = extensions; | 451 video_rtp_extensions_ = extensions; |
464 } | 452 } |
465 const RtpHeaderExtensions& video_rtp_header_extensions() const { | 453 const RtpHeaderExtensions& video_rtp_header_extensions() const { |
466 return video_rtp_extensions_; | 454 return video_rtp_extensions_; |
467 } | 455 } |
468 const DataCodecs& data_codecs() const { return data_codecs_; } | 456 const DataCodecs& data_codecs() const { return data_codecs_; } |
469 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; } | 457 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; } |
470 SecurePolicy secure() const { return secure_; } | 458 SecurePolicy secure() const { return secure_; } |
471 void set_secure(SecurePolicy s) { secure_ = s; } | 459 void set_secure(SecurePolicy s) { secure_ = s; } |
472 // Decides if a StreamParams shall be added to the audio and video media | |
473 // content in SessionDescription when CreateOffer and CreateAnswer is called | |
474 // even if |options| don't include a Stream. This is needed to support legacy | |
475 // applications. |add_legacy_| is true per default. | |
476 void set_add_legacy_streams(bool add_legacy) { add_legacy_ = add_legacy; } | |
477 | 460 |
478 void set_enable_encrypted_rtp_header_extensions(bool enable) { | 461 void set_enable_encrypted_rtp_header_extensions(bool enable) { |
479 enable_encrypted_rtp_header_extensions_ = enable; | 462 enable_encrypted_rtp_header_extensions_ = enable; |
480 } | 463 } |
481 | 464 |
482 SessionDescription* CreateOffer( | 465 SessionDescription* CreateOffer( |
483 const MediaSessionOptions& options, | 466 const MediaSessionOptions& options, |
484 const SessionDescription* current_description) const; | 467 const SessionDescription* current_description) const; |
485 SessionDescription* CreateAnswer( | 468 SessionDescription* CreateAnswer( |
486 const SessionDescription* offer, | 469 const SessionDescription* offer, |
487 const MediaSessionOptions& options, | 470 const MediaSessionOptions& options, |
488 const SessionDescription* current_description) const; | 471 const SessionDescription* current_description) const; |
489 | 472 |
490 private: | 473 private: |
491 const AudioCodecs& GetAudioCodecsForOffer( | 474 const AudioCodecs& GetAudioCodecsForOffer( |
492 const RtpTransceiverDirection& direction) const; | 475 const RtpTransceiverDirection& direction) const; |
493 const AudioCodecs& GetAudioCodecsForAnswer( | 476 const AudioCodecs& GetAudioCodecsForAnswer( |
494 const RtpTransceiverDirection& offer, | 477 const RtpTransceiverDirection& offer, |
495 const RtpTransceiverDirection& answer) const; | 478 const RtpTransceiverDirection& answer) const; |
496 void GetCodecsToOffer(const SessionDescription* current_description, | 479 void GetCodecsForOffer(const SessionDescription* current_description, |
497 const AudioCodecs& supported_audio_codecs, | 480 AudioCodecs* audio_codecs, |
498 const VideoCodecs& supported_video_codecs, | 481 VideoCodecs* video_codecs, |
499 const DataCodecs& supported_data_codecs, | 482 DataCodecs* data_codecs) const; |
500 AudioCodecs* audio_codecs, | 483 void GetCodecsForAnswer(const SessionDescription* current_description, |
501 VideoCodecs* video_codecs, | 484 const SessionDescription* remote_offer, |
502 DataCodecs* data_codecs) const; | 485 AudioCodecs* audio_codecs, |
| 486 VideoCodecs* video_codecs, |
| 487 DataCodecs* data_codecs) const; |
503 void GetRtpHdrExtsToOffer(const SessionDescription* current_description, | 488 void GetRtpHdrExtsToOffer(const SessionDescription* current_description, |
504 RtpHeaderExtensions* audio_extensions, | 489 RtpHeaderExtensions* audio_extensions, |
505 RtpHeaderExtensions* video_extensions) const; | 490 RtpHeaderExtensions* video_extensions) const; |
506 bool AddTransportOffer( | 491 bool AddTransportOffer( |
507 const std::string& content_name, | 492 const std::string& content_name, |
508 const TransportOptions& transport_options, | 493 const TransportOptions& transport_options, |
509 const SessionDescription* current_desc, | 494 const SessionDescription* current_desc, |
510 SessionDescription* offer) const; | 495 SessionDescription* offer) const; |
511 | 496 |
512 TransportDescription* CreateTransportAnswer( | 497 TransportDescription* CreateTransportAnswer( |
513 const std::string& content_name, | 498 const std::string& content_name, |
514 const SessionDescription* offer_desc, | 499 const SessionDescription* offer_desc, |
515 const TransportOptions& transport_options, | 500 const TransportOptions& transport_options, |
516 const SessionDescription* current_desc, | 501 const SessionDescription* current_desc, |
517 bool require_transport_attributes) const; | 502 bool require_transport_attributes) const; |
518 | 503 |
519 bool AddTransportAnswer( | 504 bool AddTransportAnswer( |
520 const std::string& content_name, | 505 const std::string& content_name, |
521 const TransportDescription& transport_desc, | 506 const TransportDescription& transport_desc, |
522 SessionDescription* answer_desc) const; | 507 SessionDescription* answer_desc) const; |
523 | 508 |
524 // Helpers for adding media contents to the SessionDescription. Returns true | 509 // Helpers for adding media contents to the SessionDescription. Returns true |
525 // it succeeds or the media content is not needed, or false if there is any | 510 // it succeeds or the media content is not needed, or false if there is any |
526 // error. | 511 // error. |
527 | 512 |
528 bool AddAudioContentForOffer( | 513 bool AddAudioContentForOffer( |
529 const MediaSessionOptions& options, | 514 const MediaDescriptionOptions& media_description_options, |
| 515 const MediaSessionOptions& session_options, |
| 516 const ContentInfo* current_content, |
530 const SessionDescription* current_description, | 517 const SessionDescription* current_description, |
531 const RtpHeaderExtensions& audio_rtp_extensions, | 518 const RtpHeaderExtensions& audio_rtp_extensions, |
532 const AudioCodecs& audio_codecs, | 519 const AudioCodecs& audio_codecs, |
533 StreamParamsVec* current_streams, | 520 StreamParamsVec* current_streams, |
534 SessionDescription* desc) const; | 521 SessionDescription* desc) const; |
535 | 522 |
536 bool AddVideoContentForOffer( | 523 bool AddVideoContentForOffer( |
537 const MediaSessionOptions& options, | 524 const MediaDescriptionOptions& media_description_options, |
| 525 const MediaSessionOptions& session_options, |
| 526 const ContentInfo* current_content, |
538 const SessionDescription* current_description, | 527 const SessionDescription* current_description, |
539 const RtpHeaderExtensions& video_rtp_extensions, | 528 const RtpHeaderExtensions& video_rtp_extensions, |
540 const VideoCodecs& video_codecs, | 529 const VideoCodecs& video_codecs, |
541 StreamParamsVec* current_streams, | 530 StreamParamsVec* current_streams, |
542 SessionDescription* desc) const; | 531 SessionDescription* desc) const; |
543 | 532 |
544 bool AddDataContentForOffer( | 533 bool AddDataContentForOffer( |
545 const MediaSessionOptions& options, | 534 const MediaDescriptionOptions& media_description_options, |
| 535 const MediaSessionOptions& session_options, |
| 536 const ContentInfo* current_content, |
546 const SessionDescription* current_description, | 537 const SessionDescription* current_description, |
547 DataCodecs* data_codecs, | 538 const DataCodecs& data_codecs, |
548 StreamParamsVec* current_streams, | 539 StreamParamsVec* current_streams, |
549 SessionDescription* desc) const; | 540 SessionDescription* desc) const; |
550 | 541 |
551 bool AddAudioContentForAnswer(const SessionDescription* offer, | 542 bool AddAudioContentForAnswer( |
552 const MediaSessionOptions& options, | 543 const MediaDescriptionOptions& media_description_options, |
553 const SessionDescription* current_description, | 544 const MediaSessionOptions& session_options, |
554 const TransportInfo* bundle_transport, | 545 const ContentInfo* offer_content, |
555 StreamParamsVec* current_streams, | 546 const SessionDescription* offer_description, |
556 SessionDescription* answer) const; | 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; |
557 | 553 |
558 bool AddVideoContentForAnswer(const SessionDescription* offer, | 554 bool AddVideoContentForAnswer( |
559 const MediaSessionOptions& options, | 555 const MediaDescriptionOptions& media_description_options, |
560 const SessionDescription* current_description, | 556 const MediaSessionOptions& session_options, |
561 const TransportInfo* bundle_transport, | 557 const ContentInfo* offer_content, |
562 StreamParamsVec* current_streams, | 558 const SessionDescription* offer_description, |
563 SessionDescription* answer) const; | 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; |
564 | 565 |
565 bool AddDataContentForAnswer(const SessionDescription* offer, | 566 bool AddDataContentForAnswer( |
566 const MediaSessionOptions& options, | 567 const MediaDescriptionOptions& media_description_options, |
567 const SessionDescription* current_description, | 568 const MediaSessionOptions& session_options, |
568 const TransportInfo* bundle_transport, | 569 const ContentInfo* offer_content, |
569 StreamParamsVec* current_streams, | 570 const SessionDescription* offer_description, |
570 SessionDescription* answer) const; | 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(); |
571 | 579 |
572 AudioCodecs audio_send_codecs_; | 580 AudioCodecs audio_send_codecs_; |
573 AudioCodecs audio_recv_codecs_; | 581 AudioCodecs audio_recv_codecs_; |
| 582 // Intersection of send and recv. |
574 AudioCodecs audio_sendrecv_codecs_; | 583 AudioCodecs audio_sendrecv_codecs_; |
| 584 // Union of send and recv. |
| 585 AudioCodecs all_audio_codecs_; |
575 RtpHeaderExtensions audio_rtp_extensions_; | 586 RtpHeaderExtensions audio_rtp_extensions_; |
576 VideoCodecs video_codecs_; | 587 VideoCodecs video_codecs_; |
577 RtpHeaderExtensions video_rtp_extensions_; | 588 RtpHeaderExtensions video_rtp_extensions_; |
578 DataCodecs data_codecs_; | 589 DataCodecs data_codecs_; |
579 SecurePolicy secure_; | |
580 bool add_legacy_; | |
581 bool enable_encrypted_rtp_header_extensions_ = false; | 590 bool enable_encrypted_rtp_header_extensions_ = false; |
| 591 // TODO(zhihuang): Rename secure_ to sdec_policy_; rename the related getter |
| 592 // and setter. |
| 593 SecurePolicy secure_ = SEC_DISABLED; |
582 std::string lang_; | 594 std::string lang_; |
583 const TransportDescriptionFactory* transport_desc_factory_; | 595 const TransportDescriptionFactory* transport_desc_factory_; |
584 }; | 596 }; |
585 | 597 |
586 // Convenience functions. | 598 // Convenience functions. |
587 bool IsMediaContent(const ContentInfo* content); | 599 bool IsMediaContent(const ContentInfo* content); |
588 bool IsAudioContent(const ContentInfo* content); | 600 bool IsAudioContent(const ContentInfo* content); |
589 bool IsVideoContent(const ContentInfo* content); | 601 bool IsVideoContent(const ContentInfo* content); |
590 bool IsDataContent(const ContentInfo* content); | 602 bool IsDataContent(const ContentInfo* content); |
591 const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, | 603 const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 void GetSupportedVideoSdesCryptoSuiteNames( | 643 void GetSupportedVideoSdesCryptoSuiteNames( |
632 const rtc::CryptoOptions& crypto_options, | 644 const rtc::CryptoOptions& crypto_options, |
633 std::vector<std::string>* crypto_suite_names); | 645 std::vector<std::string>* crypto_suite_names); |
634 void GetSupportedDataSdesCryptoSuiteNames( | 646 void GetSupportedDataSdesCryptoSuiteNames( |
635 const rtc::CryptoOptions& crypto_options, | 647 const rtc::CryptoOptions& crypto_options, |
636 std::vector<std::string>* crypto_suite_names); | 648 std::vector<std::string>* crypto_suite_names); |
637 | 649 |
638 } // namespace cricket | 650 } // namespace cricket |
639 | 651 |
640 #endif // WEBRTC_PC_MEDIASESSION_H_ | 652 #endif // WEBRTC_PC_MEDIASESSION_H_ |
OLD | NEW |