Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: webrtc/pc/mediasession.h

Issue 2991693002: Adding support for Unified Plan offer/answer negotiation. (Closed)
Patch Set: More tests. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/pc/mediasession.cc » ('j') | webrtc/pc/mediasession.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 struct SenderOptions {
Taylor Brandstetter 2017/08/05 00:39:08 Let's add a comment explaining that a "SenderOptio
Zhi Huang 2017/08/09 00:54:50 Done.
106 std::string track_id;
107 std::string stream_id;
108 int num_sim_layers;
109 };
110
111 // Options for an individual media description/"m=" section.
112 struct MediaDescriptionOptions {
113 MediaDescriptionOptions(MediaType type,
114 const std::string& mid,
115 RtpTransceiverDirection direction,
116 bool stopped)
117 : type(type), mid(mid), direction(direction), stopped(stopped) {}
118
119 // TODO(deadbeef): When we don't support Plan B, there will only be one
120 // sender per media descritption and this can be simplified.
Taylor Brandstetter 2017/08/05 00:39:09 nit: "descritption" has an extra 't'
Zhi Huang 2017/08/09 00:54:50 Done.
121 void AddAudioSender(const std::string& track_id,
122 const std::string& stream_id);
123 void AddVideoSender(const std::string& track_id,
124 const std::string& stream_id,
125 int num_sim_layers);
126
127 // Internally just uses sender_options.
128 void AddRtpDataChannel(const std::string& track_id,
129 const std::string& stream_id);
130
131 MediaType type;
132 std::string mid;
133 RtpTransceiverDirection direction;
134 bool stopped;
135 TransportOptions transport_options;
136 // Note: There's no equivalent "RtpReceiverOptions" because only send
137 // stream information goes in the local descriptions.
138 std::vector<SenderOptions> sender_options;
139
140 private:
141 // Doesn't DCHECK on |type|.
142 void AddSenderInternal(const std::string& track_id,
143 const std::string& stream_id,
144 int num_sim_layers);
145 };
146
147 // Provides a mechanism for describing how m= sections should be generated.
148 // The m= section with index X will use media_description_options[X]. There
149 // must be an option for each existing section.
Taylor Brandstetter 2017/08/05 00:39:08 Can you clarify this comment slightly? "There must
Zhi Huang 2017/08/09 00:54:49 Done.
105 struct MediaSessionOptions { 150 struct MediaSessionOptions {
106 MediaSessionOptions() 151 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 152
118 bool has_audio() const { 153 bool has_audio() const { return HasMediaDescription(MEDIA_TYPE_AUDIO); }
119 return recv_audio || HasSendMediaStream(MEDIA_TYPE_AUDIO); 154 bool has_video() const { return HasMediaDescription(MEDIA_TYPE_VIDEO); }
120 } 155 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 156
126 // Add a stream with MediaType type and id. 157 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 158
137 159 DataChannelType data_channel_type = DCT_NONE;
138 // Helper function. 160 bool is_muc = false;
139 void AddSendStreamInternal(MediaType type, 161 bool vad_enabled = true; // When disabled, removes all CN codecs from SDP.
140 const std::string& id, 162 bool rtcp_mux_enabled = true;
141 const std::string& sync_label, 163 bool bundle_enabled = false;
142 int num_sim_layers); 164 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; 165 rtc::CryptoOptions crypto_options;
165 166 // List of media description options in the same order that the media
166 struct Stream { 167 // descriptions will be generated.
167 Stream(MediaType type, 168 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 }; 169 };
183 170
184 // "content" (as used in XEP-0166) descriptions for voice and video. 171 // "content" (as used in XEP-0166) descriptions for voice and video.
185 class MediaContentDescription : public ContentDescription { 172 class MediaContentDescription : public ContentDescription {
186 public: 173 public:
187 MediaContentDescription() {} 174 MediaContentDescription() {}
188 175
189 virtual MediaType type() const = 0; 176 virtual MediaType type() const = 0;
190 virtual bool has_codecs() const = 0; 177 virtual bool has_codecs() const = 0;
191 178
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // Legacy streams have an ssrc, but nothing else. 257 // Legacy streams have an ssrc, but nothing else.
271 void AddLegacyStream(uint32_t ssrc) { 258 void AddLegacyStream(uint32_t ssrc) {
272 streams_.push_back(StreamParams::CreateLegacy(ssrc)); 259 streams_.push_back(StreamParams::CreateLegacy(ssrc));
273 } 260 }
274 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) { 261 void AddLegacyStream(uint32_t ssrc, uint32_t fid_ssrc) {
275 StreamParams sp = StreamParams::CreateLegacy(ssrc); 262 StreamParams sp = StreamParams::CreateLegacy(ssrc);
276 sp.AddFidSsrc(ssrc, fid_ssrc); 263 sp.AddFidSsrc(ssrc, fid_ssrc);
277 streams_.push_back(sp); 264 streams_.push_back(sp);
278 } 265 }
279 // Sets the CNAME of all StreamParams if it have not been set. 266 // 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) { 267 void SetCnameIfEmpty(const std::string& cname) {
282 for (cricket::StreamParamsVec::iterator it = streams_.begin(); 268 for (cricket::StreamParamsVec::iterator it = streams_.begin();
283 it != streams_.end(); ++it) { 269 it != streams_.end(); ++it) {
284 if (it->cname.empty()) 270 if (it->cname.empty())
285 it->cname = cname; 271 it->cname = cname;
286 } 272 }
287 } 273 }
288 uint32_t first_ssrc() const { 274 uint32_t first_ssrc() const {
289 if (streams_.empty()) { 275 if (streams_.empty()) {
290 return 0; 276 return 0;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) { 448 void set_video_rtp_header_extensions(const RtpHeaderExtensions& extensions) {
463 video_rtp_extensions_ = extensions; 449 video_rtp_extensions_ = extensions;
464 } 450 }
465 const RtpHeaderExtensions& video_rtp_header_extensions() const { 451 const RtpHeaderExtensions& video_rtp_header_extensions() const {
466 return video_rtp_extensions_; 452 return video_rtp_extensions_;
467 } 453 }
468 const DataCodecs& data_codecs() const { return data_codecs_; } 454 const DataCodecs& data_codecs() const { return data_codecs_; }
469 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; } 455 void set_data_codecs(const DataCodecs& codecs) { data_codecs_ = codecs; }
470 SecurePolicy secure() const { return secure_; } 456 SecurePolicy secure() const { return secure_; }
471 void set_secure(SecurePolicy s) { secure_ = s; } 457 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 458
478 void set_enable_encrypted_rtp_header_extensions(bool enable) { 459 void set_enable_encrypted_rtp_header_extensions(bool enable) {
479 enable_encrypted_rtp_header_extensions_ = enable; 460 enable_encrypted_rtp_header_extensions_ = enable;
480 } 461 }
481 462
482 SessionDescription* CreateOffer( 463 SessionDescription* CreateOffer(
483 const MediaSessionOptions& options, 464 const MediaSessionOptions& options,
484 const SessionDescription* current_description) const; 465 const SessionDescription* current_description) const;
485 SessionDescription* CreateAnswer( 466 SessionDescription* CreateAnswer(
486 const SessionDescription* offer, 467 const SessionDescription* offer,
487 const MediaSessionOptions& options, 468 const MediaSessionOptions& options,
488 const SessionDescription* current_description) const; 469 const SessionDescription* current_description) const;
489 470
490 private: 471 private:
491 const AudioCodecs& GetAudioCodecsForOffer( 472 const AudioCodecs& GetAudioCodecsForOffer(
492 const RtpTransceiverDirection& direction) const; 473 const RtpTransceiverDirection& direction) const;
493 const AudioCodecs& GetAudioCodecsForAnswer( 474 const AudioCodecs& GetAudioCodecsForAnswer(
494 const RtpTransceiverDirection& offer, 475 const RtpTransceiverDirection& offer,
495 const RtpTransceiverDirection& answer) const; 476 const RtpTransceiverDirection& answer) const;
496 void GetCodecsToOffer(const SessionDescription* current_description, 477 void GetCodecsForOffer(const SessionDescription* current_description,
497 const AudioCodecs& supported_audio_codecs, 478 AudioCodecs* audio_codecs,
498 const VideoCodecs& supported_video_codecs, 479 VideoCodecs* video_codecs,
499 const DataCodecs& supported_data_codecs, 480 DataCodecs* data_codecs) const;
500 AudioCodecs* audio_codecs, 481 void GetCodecsForAnswer(const SessionDescription* current_description,
501 VideoCodecs* video_codecs, 482 const SessionDescription* remote_offer,
502 DataCodecs* data_codecs) const; 483 AudioCodecs* audio_codecs,
484 VideoCodecs* video_codecs,
485 DataCodecs* data_codecs) const;
503 void GetRtpHdrExtsToOffer(const SessionDescription* current_description, 486 void GetRtpHdrExtsToOffer(const SessionDescription* current_description,
504 RtpHeaderExtensions* audio_extensions, 487 RtpHeaderExtensions* audio_extensions,
505 RtpHeaderExtensions* video_extensions) const; 488 RtpHeaderExtensions* video_extensions) const;
506 bool AddTransportOffer( 489 bool AddTransportOffer(
507 const std::string& content_name, 490 const std::string& content_name,
508 const TransportOptions& transport_options, 491 const TransportOptions& transport_options,
509 const SessionDescription* current_desc, 492 const SessionDescription* current_desc,
510 SessionDescription* offer) const; 493 SessionDescription* offer) const;
511 494
512 TransportDescription* CreateTransportAnswer( 495 TransportDescription* CreateTransportAnswer(
513 const std::string& content_name, 496 const std::string& content_name,
514 const SessionDescription* offer_desc, 497 const SessionDescription* offer_desc,
515 const TransportOptions& transport_options, 498 const TransportOptions& transport_options,
516 const SessionDescription* current_desc, 499 const SessionDescription* current_desc,
517 bool require_transport_attributes) const; 500 bool require_transport_attributes) const;
518 501
519 bool AddTransportAnswer( 502 bool AddTransportAnswer(
520 const std::string& content_name, 503 const std::string& content_name,
521 const TransportDescription& transport_desc, 504 const TransportDescription& transport_desc,
522 SessionDescription* answer_desc) const; 505 SessionDescription* answer_desc) const;
523 506
524 // Helpers for adding media contents to the SessionDescription. Returns true 507 // 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 508 // it succeeds or the media content is not needed, or false if there is any
526 // error. 509 // error.
527 510
528 bool AddAudioContentForOffer( 511 bool AddAudioContentForOffer(
529 const MediaSessionOptions& options, 512 const MediaDescriptionOptions& media_description_options,
513 const MediaSessionOptions& session_options,
514 const ContentInfo* current_content,
530 const SessionDescription* current_description, 515 const SessionDescription* current_description,
531 const RtpHeaderExtensions& audio_rtp_extensions, 516 const RtpHeaderExtensions& audio_rtp_extensions,
532 const AudioCodecs& audio_codecs, 517 const AudioCodecs& audio_codecs,
533 StreamParamsVec* current_streams, 518 StreamParamsVec* current_streams,
534 SessionDescription* desc) const; 519 SessionDescription* desc) const;
535 520
536 bool AddVideoContentForOffer( 521 bool AddVideoContentForOffer(
537 const MediaSessionOptions& options, 522 const MediaDescriptionOptions& media_description_options,
523 const MediaSessionOptions& session_options,
524 const ContentInfo* current_content,
538 const SessionDescription* current_description, 525 const SessionDescription* current_description,
539 const RtpHeaderExtensions& video_rtp_extensions, 526 const RtpHeaderExtensions& video_rtp_extensions,
540 const VideoCodecs& video_codecs, 527 const VideoCodecs& video_codecs,
541 StreamParamsVec* current_streams, 528 StreamParamsVec* current_streams,
542 SessionDescription* desc) const; 529 SessionDescription* desc) const;
543 530
544 bool AddDataContentForOffer( 531 bool AddDataContentForOffer(
545 const MediaSessionOptions& options, 532 const MediaDescriptionOptions& media_description_options,
533 const MediaSessionOptions& session_options,
534 const ContentInfo* current_content,
546 const SessionDescription* current_description, 535 const SessionDescription* current_description,
547 DataCodecs* data_codecs, 536 const DataCodecs& data_codecs,
548 StreamParamsVec* current_streams, 537 StreamParamsVec* current_streams,
549 SessionDescription* desc) const; 538 SessionDescription* desc) const;
550 539
551 bool AddAudioContentForAnswer(const SessionDescription* offer, 540 bool AddAudioContentForAnswer(
552 const MediaSessionOptions& options, 541 const MediaDescriptionOptions& media_description_options,
553 const SessionDescription* current_description, 542 const MediaSessionOptions& session_options,
554 const TransportInfo* bundle_transport, 543 const ContentInfo* offer_content,
555 StreamParamsVec* current_streams, 544 const SessionDescription* offer_description,
556 SessionDescription* answer) const; 545 const ContentInfo* current_content,
546 const SessionDescription* current_description,
547 const TransportInfo* bundle_transport,
548 const AudioCodecs& audio_codecs,
549 StreamParamsVec* current_streams,
550 SessionDescription* answer) const;
557 551
558 bool AddVideoContentForAnswer(const SessionDescription* offer, 552 bool AddVideoContentForAnswer(
559 const MediaSessionOptions& options, 553 const MediaDescriptionOptions& media_description_options,
560 const SessionDescription* current_description, 554 const MediaSessionOptions& session_options,
561 const TransportInfo* bundle_transport, 555 const ContentInfo* offer_content,
562 StreamParamsVec* current_streams, 556 const SessionDescription* offer_description,
563 SessionDescription* answer) const; 557 const ContentInfo* current_content,
558 const SessionDescription* current_description,
559 const TransportInfo* bundle_transport,
560 const VideoCodecs& video_codecs,
561 StreamParamsVec* current_streams,
562 SessionDescription* answer) const;
564 563
565 bool AddDataContentForAnswer(const SessionDescription* offer, 564 bool AddDataContentForAnswer(
566 const MediaSessionOptions& options, 565 const MediaDescriptionOptions& media_description_options,
567 const SessionDescription* current_description, 566 const MediaSessionOptions& session_options,
568 const TransportInfo* bundle_transport, 567 const ContentInfo* offer_content,
569 StreamParamsVec* current_streams, 568 const SessionDescription* offer_description,
570 SessionDescription* answer) const; 569 const ContentInfo* current_content,
570 const SessionDescription* current_description,
571 const TransportInfo* bundle_transport,
572 const DataCodecs& data_codecs,
573 StreamParamsVec* current_streams,
574 SessionDescription* answer) const;
575
576 void ComputeAudioCodecsIntersectionAndUnion();
571 577
572 AudioCodecs audio_send_codecs_; 578 AudioCodecs audio_send_codecs_;
573 AudioCodecs audio_recv_codecs_; 579 AudioCodecs audio_recv_codecs_;
580 // Intersection of send and recv.
574 AudioCodecs audio_sendrecv_codecs_; 581 AudioCodecs audio_sendrecv_codecs_;
582 // Union of send and recv.
583 AudioCodecs all_audio_codecs_;
575 RtpHeaderExtensions audio_rtp_extensions_; 584 RtpHeaderExtensions audio_rtp_extensions_;
576 VideoCodecs video_codecs_; 585 VideoCodecs video_codecs_;
577 RtpHeaderExtensions video_rtp_extensions_; 586 RtpHeaderExtensions video_rtp_extensions_;
578 DataCodecs data_codecs_; 587 DataCodecs data_codecs_;
579 SecurePolicy secure_;
580 bool add_legacy_;
581 bool enable_encrypted_rtp_header_extensions_ = false; 588 bool enable_encrypted_rtp_header_extensions_ = false;
589 SecurePolicy secure_ = SEC_DISABLED;
Taylor Brandstetter 2017/08/05 00:39:08 Not really related to this CL, but something that'
Zhi Huang 2017/08/09 00:54:49 I think it also make sense to rename the getter an
582 std::string lang_; 590 std::string lang_;
583 const TransportDescriptionFactory* transport_desc_factory_; 591 const TransportDescriptionFactory* transport_desc_factory_;
584 }; 592 };
585 593
586 // Convenience functions. 594 // Convenience functions.
587 bool IsMediaContent(const ContentInfo* content); 595 bool IsMediaContent(const ContentInfo* content);
588 bool IsAudioContent(const ContentInfo* content); 596 bool IsAudioContent(const ContentInfo* content);
589 bool IsVideoContent(const ContentInfo* content); 597 bool IsVideoContent(const ContentInfo* content);
590 bool IsDataContent(const ContentInfo* content); 598 bool IsDataContent(const ContentInfo* content);
591 const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, 599 const ContentInfo* GetFirstMediaContent(const ContentInfos& contents,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 void GetSupportedVideoSdesCryptoSuiteNames( 639 void GetSupportedVideoSdesCryptoSuiteNames(
632 const rtc::CryptoOptions& crypto_options, 640 const rtc::CryptoOptions& crypto_options,
633 std::vector<std::string>* crypto_suite_names); 641 std::vector<std::string>* crypto_suite_names);
634 void GetSupportedDataSdesCryptoSuiteNames( 642 void GetSupportedDataSdesCryptoSuiteNames(
635 const rtc::CryptoOptions& crypto_options, 643 const rtc::CryptoOptions& crypto_options,
636 std::vector<std::string>* crypto_suite_names); 644 std::vector<std::string>* crypto_suite_names);
637 645
638 } // namespace cricket 646 } // namespace cricket
639 647
640 #endif // WEBRTC_PC_MEDIASESSION_H_ 648 #endif // WEBRTC_PC_MEDIASESSION_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/pc/mediasession.cc » ('j') | webrtc/pc/mediasession.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698