From f15dee6980152cded2f10c26748d7d88ab9501ae Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" Date: Mon, 27 Oct 2014 22:15:04 +0000 Subject: [PATCH] Check if a datachannel in the current local description is an sctp channel before assuming rtp. When generating an offer from a local description when 'sctp' is not explicitly set in the media session options, we were generating an offer with an RTP datachannel even though the channel in the local description was already sctp. R=pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/28819004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7539 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/session/media/mediasession.cc | 10 ++++++-- talk/session/media/mediasession_unittest.cc | 27 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/talk/session/media/mediasession.cc b/talk/session/media/mediasession.cc index 54eeffa600..79fc15144e 100644 --- a/talk/session/media/mediasession.cc +++ b/talk/session/media/mediasession.cc @@ -1191,8 +1191,14 @@ SessionDescription* MediaSessionDescriptionFactory::CreateOffer( } video_added = true; } else if (IsMediaContentOfType(&*it, MEDIA_TYPE_DATA)) { - if (!AddDataContentForOffer(options, current_description, &data_codecs, - ¤t_streams, offer.get())) { + MediaSessionOptions options_copy(options); + if (IsSctp(static_cast( + it->description))) { + options_copy.data_channel_type = DCT_SCTP; + } + if (!AddDataContentForOffer(options_copy, current_description, + &data_codecs, ¤t_streams, + offer.get())) { return NULL; } data_added = true; diff --git a/talk/session/media/mediasession_unittest.cc b/talk/session/media/mediasession_unittest.cc index ef155f0878..e3c678ee12 100644 --- a/talk/session/media/mediasession_unittest.cc +++ b/talk/session/media/mediasession_unittest.cc @@ -628,6 +628,33 @@ TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { EXPECT_TRUE(offer->GetContentByName("data") != NULL); } +// Test creating an sctp data channel from an already generated offer. +TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { + MediaSessionOptions opts; + opts.recv_audio = false; + opts.bundle_enabled = true; + opts.data_channel_type = cricket::DCT_SCTP; + f1_.set_secure(SEC_ENABLED); + rtc::scoped_ptr offer1(f1_.CreateOffer(opts, NULL)); + ASSERT_TRUE(offer1.get() != NULL); + const ContentInfo* data = offer1->GetContentByName("data"); + ASSERT_TRUE(data != NULL); + const MediaContentDescription* mdesc = + static_cast(data->description); + ASSERT_EQ(cricket::kMediaProtocolSctp, mdesc->protocol()); + + // Now set data_channel_type to 'none' (default) and make sure that the + // datachannel type that gets generated from the previous offer, is of the + // same type. + opts.data_channel_type = cricket::DCT_NONE; + rtc::scoped_ptr offer2( + f1_.CreateOffer(opts, offer1.get())); + data = offer2->GetContentByName("data"); + ASSERT_TRUE(data != NULL); + mdesc = static_cast(data->description); + EXPECT_EQ(cricket::kMediaProtocolSctp, mdesc->protocol()); +} + // Create an audio, video offer without legacy StreamParams. TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferWithoutLegacyStreams) {