Chromium Code Reviews| Index: webrtc/api/peerconnection.cc |
| diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc |
| index 70a386ec14f8905382893b266589b17afefc5456..70e7a2b79eb94b869c837461b5b8e919004ea90f 100644 |
| --- a/webrtc/api/peerconnection.cc |
| +++ b/webrtc/api/peerconnection.cc |
| @@ -66,6 +66,9 @@ static const char kTransport[] = "transport"; |
| // NOTE: Must be in the same order as the ServiceType enum. |
| static const char* kValidIceServiceTypes[] = {"stun", "stuns", "turn", "turns"}; |
| +// The length of CNAMEs. |
| +static const int kCnameLength = 16; |
|
pthatcher1
2016/05/05 18:50:51
Can you call this kRtcpCnameLength and RTCP CNAME
Zhi Huang
2016/05/06 01:36:53
Done.
|
| + |
| // NOTE: A loop below assumes that the first value of this enum is 0 and all |
| // other values are incremental. |
| enum ServiceType { |
| @@ -377,6 +380,15 @@ void AddSendStreams( |
| namespace webrtc { |
| +// Generate a CNAME when a PeerConnection is created. |
| +std::string GenerateCname() { |
|
pthatcher1
2016/05/05 18:50:51
Can you call this GenerateRtcpCname() and use "RTC
Zhi Huang
2016/05/06 01:36:53
Done.
|
| + std::string cname; |
| + if (!rtc::CreateRandomString(kCnameLength, &cname)) { |
| + LOG(LS_ERROR) << "Failed to generate CNAME."; |
|
pthatcher1
2016/05/05 18:50:51
We should probably RTC_DCHECK(false) here as well.
Zhi Huang
2016/05/06 01:36:53
Right. This is a point I should not overlook.
|
| + } |
| + return cname; |
| +} |
| + |
| bool ExtractMediaSessionOptions( |
| const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| bool is_offer, |
| @@ -508,6 +520,7 @@ PeerConnection::PeerConnection(PeerConnectionFactory* factory) |
| ice_state_(kIceNew), |
| ice_connection_state_(kIceConnectionNew), |
| ice_gathering_state_(kIceGatheringNew), |
| + cname_(GenerateCname()), |
| local_streams_(StreamCollection::Create()), |
| remote_streams_(StreamCollection::Create()) {} |
| @@ -1503,6 +1516,8 @@ bool PeerConnection::GetOptionsForOffer( |
| if (session_->data_channel_type() == cricket::DCT_SCTP && HasDataChannels()) { |
| session_options->data_channel_type = cricket::DCT_SCTP; |
| } |
| + |
| + session_options->cname = cname_; |
| return true; |
| } |
| @@ -1540,6 +1555,8 @@ bool PeerConnection::GetOptionsForAnswer( |
| if (!ParseConstraintsForAnswer(constraints, session_options)) { |
| return false; |
| } |
| + session_options->cname = cname_; |
| + |
| FinishOptionsForAnswer(session_options); |
| return true; |
| } |
| @@ -1552,6 +1569,8 @@ bool PeerConnection::GetOptionsForAnswer( |
| if (!ExtractMediaSessionOptions(options, false, session_options)) { |
| return false; |
| } |
| + session_options->cname = cname_; |
| + |
| FinishOptionsForAnswer(session_options); |
| return true; |
| } |