* Add the crypto serialize and deserialize.

* Populate candidates test data.

BUG=
TEST=

Review URL: http://webrtc-codereview.appspot.com/190004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@680 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
wu@webrtc.org
2011-10-03 21:13:29 +00:00
parent ee2c391c15
commit ed6d555775
2 changed files with 90 additions and 20 deletions

View File

@ -67,6 +67,25 @@ class PeerConnectionMessageTest: public testing::Test {
kVideoTrackLabel3, kStreamLabel2));
options_.is_video = true;
int port = 1234;
talk_base::SocketAddress address("127.0.0.1", port++);
cricket::Candidate candidate1("video_rtcp", "udp", address, 1,
"user_video_rtcp", "password_video_rtcp", "local", "eth0", 0);
address.SetPort(port++);
cricket::Candidate candidate2("video_rtp", "udp", address, 1,
"user_video_rtp", "password_video_rtp", "local", "eth0", 0);
address.SetPort(port++);
cricket::Candidate candidate3("rtp", "udp", address, 1,
"user_rtp", "password_rtp", "local", "eth0", 0);
address.SetPort(port++);
cricket::Candidate candidate4("rtcp", "udp", address, 1,
"user_rtcp", "password_rtcp", "local", "eth0", 0);
candidates_.push_back(candidate1);
candidates_.push_back(candidate2);
candidates_.push_back(candidate3);
candidates_.push_back(candidate4);
}
protected:
@ -74,15 +93,13 @@ class PeerConnectionMessageTest: public testing::Test {
talk_base::scoped_ptr<cricket::MediaSessionDescriptionFactory>
session_description_factory_;
cricket::MediaSessionOptions options_;
cricket::Candidates candidates_;
private:
int ssrc_counter_;
};
TEST_F(PeerConnectionMessageTest, Serialize) {
std::vector<cricket::Candidate> candidates;
// TODO(ronghuawu): Populate the test candidates.
std::string message;
scoped_refptr<PeerConnectionMessage> pc_message;
@ -90,7 +107,7 @@ TEST_F(PeerConnectionMessageTest, Serialize) {
talk_base::scoped_ptr<cricket::SessionDescription> offer(
session_description_factory_->CreateOffer(options_));
pc_message = PeerConnectionMessage::Create(PeerConnectionMessage::kOffer,
offer.get(), candidates);
offer.get(), candidates_);
EXPECT_TRUE(pc_message->Serialize(&message));
pc_message.release();
LOG(LS_INFO) << message;
@ -99,7 +116,7 @@ TEST_F(PeerConnectionMessageTest, Serialize) {
talk_base::scoped_ptr<cricket::SessionDescription> answer(
session_description_factory_->CreateAnswer(offer.get(), options_));
pc_message = PeerConnectionMessage::Create(PeerConnectionMessage::kAnswer,
answer.get(), candidates);
answer.get(), candidates_);
EXPECT_TRUE(pc_message->Serialize(&message));
pc_message.release();
LOG(LS_INFO) << message;
@ -115,9 +132,6 @@ TEST_F(PeerConnectionMessageTest, Serialize) {
}
TEST_F(PeerConnectionMessageTest, Deserialize) {
std::vector<cricket::Candidate> candidates;
// TODO(ronghuawu): Populate the test candidates.
std::string message_ref;
std::string message_result;
scoped_refptr<PeerConnectionMessage> pc_message;
@ -126,7 +140,7 @@ TEST_F(PeerConnectionMessageTest, Deserialize) {
talk_base::scoped_ptr<cricket::SessionDescription> offer(
session_description_factory_->CreateOffer(options_));
pc_message = PeerConnectionMessage::Create(PeerConnectionMessage::kOffer,
offer.get(), candidates);
offer.get(), candidates_);
EXPECT_TRUE(pc_message->Serialize(&message_ref));
pc_message.release();
LOG(LS_INFO) << "The reference message: " << message_ref;
@ -142,7 +156,7 @@ TEST_F(PeerConnectionMessageTest, Deserialize) {
talk_base::scoped_ptr<cricket::SessionDescription> answer(
session_description_factory_->CreateAnswer(offer.get(), options_));
pc_message = PeerConnectionMessage::Create(PeerConnectionMessage::kAnswer,
answer.get(), candidates);
answer.get(), candidates_);
EXPECT_TRUE(pc_message->Serialize(&message_ref));
pc_message.release();
LOG(LS_INFO) << "The reference message: " << message_ref;

View File

@ -34,6 +34,7 @@
#include "talk/base/logging.h"
#include "talk/base/stringutils.h"
#include "talk/session/phone/codec.h"
#include "talk/session/phone/cryptoparams.h"
#include "talk/session/phone/mediasession.h"
#include "talk/session/phone/mediasessionclient.h"
@ -60,10 +61,14 @@ static bool BuildCandidate(const std::vector<cricket::Candidate>& candidates,
bool video,
std::vector<Json::Value>* jcandidates);
static bool BuildRtpMapParams(const cricket::ContentInfo& audio_offer,
static bool BuildRtpMapParams(const cricket::ContentInfo& content_info,
bool video,
std::vector<Json::Value>* rtpmap);
static void BuildCrypto(const cricket::ContentInfo& content_info,
bool video,
std::vector<Json::Value>* cryptos);
static bool BuildTrack(const cricket::SessionDescription* sdp,
bool video,
std::vector<Json::Value>* track);
@ -80,6 +85,9 @@ static bool ParseAudioCodec(const Json::Value& value,
cricket::AudioContentDescription* content);
static bool ParseVideoCodec(const Json::Value& value,
cricket::VideoContentDescription* content);
static bool ParseCrypto(const Json::Value& content,
cricket::MediaContentDescription* desc);
static bool ParseCandidates(const Json::Value& content,
std::vector<cricket::Candidate>* candidates);
@ -173,8 +181,8 @@ bool BuildContent(
Append(content, "rtpmap", rtpmap);
// crypto
Json::Value crypto;
// TODO(ronghuawu): BuildCrypto
std::vector<Json::Value> crypto;
BuildCrypto(content_info, video, &crypto);
Append(content, "crypto", crypto);
// candidate
@ -194,14 +202,14 @@ bool BuildRtpMapParams(const cricket::ContentInfo& content_info,
bool video,
std::vector<Json::Value>* rtpmap) {
if (!video) {
const cricket::AudioContentDescription* audio_offer =
const cricket::AudioContentDescription* audio =
static_cast<const cricket::AudioContentDescription*>(
content_info.description);
std::vector<cricket::AudioCodec>::const_iterator iter =
audio_offer->codecs().begin();
audio->codecs().begin();
std::vector<cricket::AudioCodec>::const_iterator iter_end =
audio_offer->codecs().end();
audio->codecs().end();
for (; iter != iter_end; ++iter) {
Json::Value codec;
std::string codec_str(std::string("audio/").append(iter->name));
@ -213,14 +221,14 @@ bool BuildRtpMapParams(const cricket::ContentInfo& content_info,
rtpmap->push_back(codec_id);
}
} else {
const cricket::VideoContentDescription* video_offer =
const cricket::VideoContentDescription* video =
static_cast<const cricket::VideoContentDescription*>(
content_info.description);
std::vector<cricket::VideoCodec>::const_iterator iter =
video_offer->codecs().begin();
video->codecs().begin();
std::vector<cricket::VideoCodec>::const_iterator iter_end =
video_offer->codecs().end();
video->codecs().end();
for (; iter != iter_end; ++iter) {
Json::Value codec;
std::string codec_str(std::string("video/").append(iter->name));
@ -233,6 +241,24 @@ bool BuildRtpMapParams(const cricket::ContentInfo& content_info,
return true;
}
void BuildCrypto(const cricket::ContentInfo& content_info,
bool video,
std::vector<Json::Value>* cryptos) {
const cricket::MediaContentDescription* content_desc =
static_cast<const cricket::MediaContentDescription*>(
content_info.description);
std::vector<cricket::CryptoParams>::const_iterator iter =
content_desc->cryptos().begin();
std::vector<cricket::CryptoParams>::const_iterator iter_end =
content_desc->cryptos().end();
for (; iter != iter_end; ++iter) {
Json::Value crypto;
Append(&crypto, "cipher_suite", iter->cipher_suite);
Append(&crypto, "key_params", iter->key_params);
cryptos->push_back(crypto);
}
}
bool BuildCandidate(const std::vector<cricket::Candidate>& candidates,
bool video,
std::vector<Json::Value>* jcandidates) {
@ -355,7 +381,6 @@ bool ParseContent(const Json::Value& jmessage,
return false;
for (size_t i = 0; i < contents.size(); ++i) {
Json::Value content = contents[i];
// TODO(ronghuawu): crypto
// candidates
if (!ParseCandidates(content, candidates))
return false;
@ -371,6 +396,9 @@ bool ParseContent(const Json::Value& jmessage,
return false;
audio_content->set_rtcp_mux(rtcp_mux);
audio_content->SortCodecs();
// crypto
if (!ParseCrypto(content, audio_content))
return false;
// tracks
if (!ParseTrack(content, audio_content))
return false;
@ -383,6 +411,9 @@ bool ParseContent(const Json::Value& jmessage,
return false;
video_content->set_rtcp_mux(rtcp_mux);
video_content->SortCodecs();
// crypto
if (!ParseCrypto(content, video_content))
return false;
if (!ParseTrack(content, video_content))
return false;
(sdp)->AddContent(cricket::CN_VIDEO,
@ -508,6 +539,31 @@ bool ParseCandidates(const Json::Value& content,
return true;
}
bool ParseCrypto(const Json::Value& content,
cricket::MediaContentDescription* desc) {
std::vector<Json::Value> jcryptos(ReadValues(content, "crypto"));
std::vector<Json::Value>::const_iterator iter =
jcryptos.begin();
std::vector<Json::Value>::const_iterator iter_end =
jcryptos.end();
for (; iter != iter_end; ++iter) {
cricket::CryptoParams crypto;
std::string cipher_suite;
if (!GetStringFromJsonObject(*iter, "cipher_suite", &cipher_suite))
return false;
crypto.cipher_suite = cipher_suite;
std::string key_params;
if (!GetStringFromJsonObject(*iter, "key_params", &key_params))
return false;
crypto.key_params= key_params;
desc->AddCrypto(crypto);
}
return true;
}
bool ParseTrack(const Json::Value& content,
cricket::MediaContentDescription* content_desc) {
ASSERT(content_desc);