| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 |
| 11 #include <memory> |
| 11 #include <string> | 12 #include <string> |
| 12 | 13 |
| 13 #include "webrtc/api/jsepicecandidate.h" | 14 #include "webrtc/api/jsepicecandidate.h" |
| 14 #include "webrtc/api/jsepsessiondescription.h" | 15 #include "webrtc/api/jsepsessiondescription.h" |
| 15 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
| 16 #include "webrtc/base/helpers.h" | 17 #include "webrtc/base/helpers.h" |
| 17 #include "webrtc/base/scoped_ptr.h" | |
| 18 #include "webrtc/base/ssladapter.h" | 18 #include "webrtc/base/ssladapter.h" |
| 19 #include "webrtc/base/stringencode.h" | 19 #include "webrtc/base/stringencode.h" |
| 20 #include "webrtc/p2p/base/candidate.h" | 20 #include "webrtc/p2p/base/candidate.h" |
| 21 #include "webrtc/p2p/base/p2pconstants.h" | 21 #include "webrtc/p2p/base/p2pconstants.h" |
| 22 #include "webrtc/p2p/base/sessiondescription.h" | 22 #include "webrtc/p2p/base/sessiondescription.h" |
| 23 #include "webrtc/pc/mediasession.h" | 23 #include "webrtc/pc/mediasession.h" |
| 24 | 24 |
| 25 using webrtc::IceCandidateCollection; | 25 using webrtc::IceCandidateCollection; |
| 26 using webrtc::IceCandidateInterface; | 26 using webrtc::IceCandidateInterface; |
| 27 using webrtc::JsepIceCandidate; | 27 using webrtc::JsepIceCandidate; |
| 28 using webrtc::JsepSessionDescription; | 28 using webrtc::JsepSessionDescription; |
| 29 using webrtc::SessionDescriptionInterface; | 29 using webrtc::SessionDescriptionInterface; |
| 30 using rtc::scoped_ptr; | |
| 31 | 30 |
| 32 static const char kCandidateUfrag[] = "ufrag"; | 31 static const char kCandidateUfrag[] = "ufrag"; |
| 33 static const char kCandidatePwd[] = "pwd"; | 32 static const char kCandidatePwd[] = "pwd"; |
| 34 static const char kCandidateUfragVoice[] = "ufrag_voice"; | 33 static const char kCandidateUfragVoice[] = "ufrag_voice"; |
| 35 static const char kCandidatePwdVoice[] = "pwd_voice"; | 34 static const char kCandidatePwdVoice[] = "pwd_voice"; |
| 36 static const char kCandidateUfragVideo[] = "ufrag_video"; | 35 static const char kCandidateUfragVideo[] = "ufrag_video"; |
| 37 static const char kCandidatePwdVideo[] = "pwd_video"; | 36 static const char kCandidatePwdVideo[] = "pwd_video"; |
| 38 | 37 |
| 39 // This creates a session description with both audio and video media contents. | 38 // This creates a session description with both audio and video media contents. |
| 40 // In SDP this is described by two m lines, one audio and one video. | 39 // In SDP this is described by two m lines, one audio and one video. |
| 41 static cricket::SessionDescription* CreateCricketSessionDescription() { | 40 static cricket::SessionDescription* CreateCricketSessionDescription() { |
| 42 cricket::SessionDescription* desc(new cricket::SessionDescription()); | 41 cricket::SessionDescription* desc(new cricket::SessionDescription()); |
| 43 // AudioContentDescription | 42 // AudioContentDescription |
| 44 scoped_ptr<cricket::AudioContentDescription> audio( | 43 std::unique_ptr<cricket::AudioContentDescription> audio( |
| 45 new cricket::AudioContentDescription()); | 44 new cricket::AudioContentDescription()); |
| 46 | 45 |
| 47 // VideoContentDescription | 46 // VideoContentDescription |
| 48 scoped_ptr<cricket::VideoContentDescription> video( | 47 std::unique_ptr<cricket::VideoContentDescription> video( |
| 49 new cricket::VideoContentDescription()); | 48 new cricket::VideoContentDescription()); |
| 50 | 49 |
| 51 audio->AddCodec(cricket::AudioCodec(103, "ISAC", 16000, 0, 0)); | 50 audio->AddCodec(cricket::AudioCodec(103, "ISAC", 16000, 0, 0)); |
| 52 desc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP, | 51 desc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP, |
| 53 audio.release()); | 52 audio.release()); |
| 54 | 53 |
| 55 video->AddCodec(cricket::VideoCodec(120, "VP8", 640, 480, 30)); | 54 video->AddCodec(cricket::VideoCodec(120, "VP8", 640, 480, 30)); |
| 56 desc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, | 55 desc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, |
| 57 video.release()); | 56 video.release()); |
| 58 | 57 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 return sdp; | 92 return sdp; |
| 94 } | 93 } |
| 95 | 94 |
| 96 SessionDescriptionInterface* DeSerialize(const std::string& sdp) { | 95 SessionDescriptionInterface* DeSerialize(const std::string& sdp) { |
| 97 JsepSessionDescription* desc(new JsepSessionDescription("dummy")); | 96 JsepSessionDescription* desc(new JsepSessionDescription("dummy")); |
| 98 EXPECT_TRUE(desc->Initialize(sdp, NULL)); | 97 EXPECT_TRUE(desc->Initialize(sdp, NULL)); |
| 99 return desc; | 98 return desc; |
| 100 } | 99 } |
| 101 | 100 |
| 102 cricket::Candidate candidate_; | 101 cricket::Candidate candidate_; |
| 103 rtc::scoped_ptr<JsepSessionDescription> jsep_desc_; | 102 std::unique_ptr<JsepSessionDescription> jsep_desc_; |
| 104 }; | 103 }; |
| 105 | 104 |
| 106 // Test that number_of_mediasections() returns the number of media contents in | 105 // Test that number_of_mediasections() returns the number of media contents in |
| 107 // a session description. | 106 // a session description. |
| 108 TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) { | 107 TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) { |
| 109 EXPECT_EQ(2u, jsep_desc_->number_of_mediasections()); | 108 EXPECT_EQ(2u, jsep_desc_->number_of_mediasections()); |
| 110 } | 109 } |
| 111 | 110 |
| 112 // Test that we can add a candidate to a session description without MID. | 111 // Test that we can add a candidate to a session description without MID. |
| 113 TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) { | 112 TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 196 |
| 198 // This should also be identified as redundant and ignored. | 197 // This should also be identified as redundant and ignored. |
| 199 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate_with_credentials)); | 198 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate_with_credentials)); |
| 200 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count()); | 199 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count()); |
| 201 } | 200 } |
| 202 | 201 |
| 203 // Test that we can serialize a JsepSessionDescription and deserialize it again. | 202 // Test that we can serialize a JsepSessionDescription and deserialize it again. |
| 204 TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) { | 203 TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) { |
| 205 std::string sdp = Serialize(jsep_desc_.get()); | 204 std::string sdp = Serialize(jsep_desc_.get()); |
| 206 | 205 |
| 207 scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc(DeSerialize(sdp)); | 206 std::unique_ptr<SessionDescriptionInterface> parsed_jsep_desc( |
| 207 DeSerialize(sdp)); |
| 208 EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections()); | 208 EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections()); |
| 209 | 209 |
| 210 std::string parsed_sdp = Serialize(parsed_jsep_desc.get()); | 210 std::string parsed_sdp = Serialize(parsed_jsep_desc.get()); |
| 211 EXPECT_EQ(sdp, parsed_sdp); | 211 EXPECT_EQ(sdp, parsed_sdp); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Tests that we can serialize and deserialize a JsepSesssionDescription | 214 // Tests that we can serialize and deserialize a JsepSesssionDescription |
| 215 // with candidates. | 215 // with candidates. |
| 216 TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) { | 216 TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) { |
| 217 std::string sdp = Serialize(jsep_desc_.get()); | 217 std::string sdp = Serialize(jsep_desc_.get()); |
| 218 | 218 |
| 219 // Add a candidate and check that the serialized result is different. | 219 // Add a candidate and check that the serialized result is different. |
| 220 JsepIceCandidate jsep_candidate("audio", 0, candidate_); | 220 JsepIceCandidate jsep_candidate("audio", 0, candidate_); |
| 221 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); | 221 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); |
| 222 std::string sdp_with_candidate = Serialize(jsep_desc_.get()); | 222 std::string sdp_with_candidate = Serialize(jsep_desc_.get()); |
| 223 EXPECT_NE(sdp, sdp_with_candidate); | 223 EXPECT_NE(sdp, sdp_with_candidate); |
| 224 | 224 |
| 225 scoped_ptr<SessionDescriptionInterface> parsed_jsep_desc( | 225 std::unique_ptr<SessionDescriptionInterface> parsed_jsep_desc( |
| 226 DeSerialize(sdp_with_candidate)); | 226 DeSerialize(sdp_with_candidate)); |
| 227 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get()); | 227 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get()); |
| 228 | 228 |
| 229 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); | 229 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); |
| 230 } | 230 } |
| OLD | NEW |