OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2011 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 <set> | 12 #include <set> |
12 #include <string> | 13 #include <string> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "webrtc/api/jsepsessiondescription.h" | 16 #include "webrtc/api/jsepsessiondescription.h" |
16 #ifdef WEBRTC_ANDROID | 17 #ifdef WEBRTC_ANDROID |
17 #include "webrtc/api/test/androidtestinitializer.h" | 18 #include "webrtc/api/test/androidtestinitializer.h" |
18 #endif | 19 #endif |
19 #include "webrtc/api/webrtcsdp.h" | 20 #include "webrtc/api/webrtcsdp.h" |
20 #include "webrtc/base/gunit.h" | 21 #include "webrtc/base/gunit.h" |
21 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
22 #include "webrtc/base/messagedigest.h" | 23 #include "webrtc/base/messagedigest.h" |
23 #include "webrtc/base/scoped_ptr.h" | |
24 #include "webrtc/base/sslfingerprint.h" | 24 #include "webrtc/base/sslfingerprint.h" |
25 #include "webrtc/base/stringencode.h" | 25 #include "webrtc/base/stringencode.h" |
26 #include "webrtc/base/stringutils.h" | 26 #include "webrtc/base/stringutils.h" |
27 #include "webrtc/media/base/mediaconstants.h" | 27 #include "webrtc/media/base/mediaconstants.h" |
28 #include "webrtc/media/engine/webrtcvideoengine2.h" | 28 #include "webrtc/media/engine/webrtcvideoengine2.h" |
29 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 29 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
30 #include "webrtc/p2p/base/p2pconstants.h" | 30 #include "webrtc/p2p/base/p2pconstants.h" |
31 #include "webrtc/pc/mediasession.h" | 31 #include "webrtc/pc/mediasession.h" |
32 | 32 |
33 using cricket::AudioCodec; | 33 using cricket::AudioCodec; |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, | 1387 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
1388 kSessionVersion)) { | 1388 kSessionVersion)) { |
1389 return false; | 1389 return false; |
1390 } | 1390 } |
1391 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); | 1391 std::string message = webrtc::SdpSerialize(jdesc_no_candidates, false); |
1392 EXPECT_EQ(new_sdp, message); | 1392 EXPECT_EQ(new_sdp, message); |
1393 return true; | 1393 return true; |
1394 } | 1394 } |
1395 | 1395 |
1396 void AddSctpDataChannel() { | 1396 void AddSctpDataChannel() { |
1397 rtc::scoped_ptr<DataContentDescription> data( | 1397 std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
1398 new DataContentDescription()); | |
1399 data_desc_ = data.get(); | 1398 data_desc_ = data.get(); |
1400 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); | 1399 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); |
1401 DataCodec codec(cricket::kGoogleSctpDataCodecId, | 1400 DataCodec codec(cricket::kGoogleSctpDataCodecId, |
1402 cricket::kGoogleSctpDataCodecName); | 1401 cricket::kGoogleSctpDataCodecName); |
1403 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort); | 1402 codec.SetParam(cricket::kCodecParamPort, kDefaultSctpPort); |
1404 data_desc_->AddCodec(codec); | 1403 data_desc_->AddCodec(codec); |
1405 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release()); | 1404 desc_.AddContent(kDataContentName, NS_JINGLE_DRAFT_SCTP, data.release()); |
1406 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( | 1405 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( |
1407 kDataContentName, TransportDescription(kUfragData, kPwdData)))); | 1406 kDataContentName, TransportDescription(kUfragData, kPwdData)))); |
1408 } | 1407 } |
1409 | 1408 |
1410 void AddRtpDataChannel() { | 1409 void AddRtpDataChannel() { |
1411 rtc::scoped_ptr<DataContentDescription> data( | 1410 std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
1412 new DataContentDescription()); | |
1413 data_desc_ = data.get(); | 1411 data_desc_ = data.get(); |
1414 | 1412 |
1415 data_desc_->AddCodec(DataCodec(101, "google-data")); | 1413 data_desc_->AddCodec(DataCodec(101, "google-data")); |
1416 StreamParams data_stream; | 1414 StreamParams data_stream; |
1417 data_stream.id = kDataChannelMsid; | 1415 data_stream.id = kDataChannelMsid; |
1418 data_stream.cname = kDataChannelCname; | 1416 data_stream.cname = kDataChannelCname; |
1419 data_stream.sync_label = kDataChannelLabel; | 1417 data_stream.sync_label = kDataChannelLabel; |
1420 data_stream.ssrcs.push_back(kDataChannelSsrc); | 1418 data_stream.ssrcs.push_back(kDataChannelSsrc); |
1421 data_desc_->AddStream(data_stream); | 1419 data_desc_->AddStream(data_stream); |
1422 data_desc_->AddCrypto(CryptoParams( | 1420 data_desc_->AddCrypto(CryptoParams( |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); | 1670 EXPECT_TRUE(webrtc::SdpDeserialize(message, &jdesc_output_des, &error)); |
1673 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); | 1671 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_output_des)); |
1674 } | 1672 } |
1675 | 1673 |
1676 protected: | 1674 protected: |
1677 SessionDescription desc_; | 1675 SessionDescription desc_; |
1678 AudioContentDescription* audio_desc_; | 1676 AudioContentDescription* audio_desc_; |
1679 VideoContentDescription* video_desc_; | 1677 VideoContentDescription* video_desc_; |
1680 DataContentDescription* data_desc_; | 1678 DataContentDescription* data_desc_; |
1681 Candidates candidates_; | 1679 Candidates candidates_; |
1682 rtc::scoped_ptr<IceCandidateInterface> jcandidate_; | 1680 std::unique_ptr<IceCandidateInterface> jcandidate_; |
1683 JsepSessionDescription jdesc_; | 1681 JsepSessionDescription jdesc_; |
1684 }; | 1682 }; |
1685 | 1683 |
1686 void TestMismatch(const std::string& string1, const std::string& string2) { | 1684 void TestMismatch(const std::string& string1, const std::string& string2) { |
1687 int position = 0; | 1685 int position = 0; |
1688 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { | 1686 for (size_t i = 0; i < string1.length() && i < string2.length(); ++i) { |
1689 if (string1.c_str()[i] != string2.c_str()[i]) { | 1687 if (string1.c_str()[i] != string2.c_str()[i]) { |
1690 position = static_cast<int>(i); | 1688 position = static_cast<int>(i); |
1691 break; | 1689 break; |
1692 } | 1690 } |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 } | 2073 } |
2076 | 2074 |
2077 // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing | 2075 // TODO(mallinath) : Enable this test once WebRTCSdp capable of parsing |
2078 // RFC 6544. | 2076 // RFC 6544. |
2079 TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { | 2077 TEST_F(WebRtcSdpTest, SerializeTcpCandidates) { |
2080 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", | 2078 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
2081 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, | 2079 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
2082 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, | 2080 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
2083 kCandidateFoundation1); | 2081 kCandidateFoundation1); |
2084 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); | 2082 candidate.set_tcptype(cricket::TCPTYPE_ACTIVE_STR); |
2085 rtc::scoped_ptr<IceCandidateInterface> jcandidate( | 2083 std::unique_ptr<IceCandidateInterface> jcandidate( |
2086 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); | 2084 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
2087 | 2085 |
2088 std::string message = webrtc::SdpSerializeCandidate(*jcandidate); | 2086 std::string message = webrtc::SdpSerializeCandidate(*jcandidate); |
2089 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); | 2087 EXPECT_EQ(std::string(kSdpTcpActiveCandidate), message); |
2090 } | 2088 } |
2091 | 2089 |
2092 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) { | 2090 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithH264) { |
2093 if (!webrtc::H264Encoder::IsSupported()) | 2091 if (!webrtc::H264Encoder::IsSupported()) |
2094 return; | 2092 return; |
2095 for (const auto& codec : cricket::DefaultVideoCodecList()) { | 2093 for (const auto& codec : cricket::DefaultVideoCodecList()) { |
2096 video_desc_->AddCodec(codec); | 2094 video_desc_->AddCodec(codec); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2398 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); | 2396 EXPECT_TRUE(jcandidate.candidate().IsEquivalent(expected)); |
2399 EXPECT_EQ(9, jcandidate.candidate().network_cost()); | 2397 EXPECT_EQ(9, jcandidate.candidate().network_cost()); |
2400 | 2398 |
2401 sdp = kSdpTcpActiveCandidate; | 2399 sdp = kSdpTcpActiveCandidate; |
2402 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); | 2400 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
2403 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. | 2401 // Make a cricket::Candidate equivalent to kSdpTcpCandidate string. |
2404 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", | 2402 Candidate candidate(ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
2405 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, | 2403 rtc::SocketAddress("192.168.1.5", 9), kCandidatePriority, |
2406 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, | 2404 "", "", LOCAL_PORT_TYPE, kCandidateGeneration, |
2407 kCandidateFoundation1); | 2405 kCandidateFoundation1); |
2408 rtc::scoped_ptr<IceCandidateInterface> jcandidate_template( | 2406 std::unique_ptr<IceCandidateInterface> jcandidate_template( |
2409 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); | 2407 new JsepIceCandidate(std::string("audio_content_name"), 0, candidate)); |
2410 EXPECT_TRUE(jcandidate.candidate().IsEquivalent( | 2408 EXPECT_TRUE(jcandidate.candidate().IsEquivalent( |
2411 jcandidate_template->candidate())); | 2409 jcandidate_template->candidate())); |
2412 sdp = kSdpTcpPassiveCandidate; | 2410 sdp = kSdpTcpPassiveCandidate; |
2413 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); | 2411 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
2414 sdp = kSdpTcpSOCandidate; | 2412 sdp = kSdpTcpSOCandidate; |
2415 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); | 2413 EXPECT_TRUE(SdpDeserializeCandidate(sdp, &jcandidate)); |
2416 } | 2414 } |
2417 | 2415 |
2418 // This test verifies the deserialization of candidate-attribute | 2416 // This test verifies the deserialization of candidate-attribute |
2419 // as per RFC 5245. Candiate-attribute will be of the format | 2417 // as per RFC 5245. Candiate-attribute will be of the format |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3144 EXPECT_TRUE( | 3142 EXPECT_TRUE( |
3145 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); | 3143 SdpDeserialize(kUnifiedPlanSdpFullString, &deserialized_description)); |
3146 | 3144 |
3147 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); | 3145 EXPECT_TRUE(CompareSessionDescription(jdesc_, deserialized_description)); |
3148 } | 3146 } |
3149 | 3147 |
3150 TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { | 3148 TEST_F(WebRtcSdpTest, SerializeUnifiedPlanSessionDescription) { |
3151 MakeUnifiedPlanDescription(); | 3149 MakeUnifiedPlanDescription(); |
3152 TestSerialize(jdesc_, true); | 3150 TestSerialize(jdesc_, true); |
3153 } | 3151 } |
OLD | NEW |