15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/* 25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle 35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2004 Google Inc. 45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without 65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met: 75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 1. Redistributions of source code must retain the above copyright notice, 95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * this list of conditions and the following disclaimer. 105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 2. Redistributions in binary form must reproduce the above copyright notice, 115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * this list of conditions and the following disclaimer in the documentation 125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * and/or other materials provided with the distribution. 135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 3. The name of the author may not be used to endorse or promote products 145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * derived from this software without specific prior written permission. 155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * 165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */ 275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/session/media/mediasession.h" 295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <functional> 315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <map> 325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <set> 335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <utility> 345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/helpers.h" 365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/logging.h" 375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/scoped_ptr.h" 385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/stringutils.h" 395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/base/constants.h" 405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/base/cryptoparams.h" 415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/p2p/base/constants.h" 425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/session/media/channelmanager.h" 435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/session/media/srtpfilter.h" 445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/xmpp/constants.h" 455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 46e73fa366a56d0c3c46860c534db19fffe110f167mallinath@webrtc.org#ifdef HAVE_SCTP 47e73fa366a56d0c3c46860c534db19fffe110f167mallinath@webrtc.org#include "talk/media/sctp/sctpdataengine.h" 48e73fa366a56d0c3c46860c534db19fffe110f167mallinath@webrtc.org#else 49582fe818e571fa2571267f5e369715188472f352wu@webrtc.orgstatic const uint32 kMaxSctpSid = 1023; 50e73fa366a56d0c3c46860c534db19fffe110f167mallinath@webrtc.org#endif 51e73fa366a56d0c3c46860c534db19fffe110f167mallinath@webrtc.org 525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace { 535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst char kInline[] = "inline:"; 545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace cricket { 575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgusing talk_base::scoped_ptr; 595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// RTP Profile names 615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml 625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// RFC4585 635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst char kMediaProtocolAvpf[] = "RTP/AVPF"; 645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// RFC5124 655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst char kMediaProtocolSavpf[] = "RTP/SAVPF"; 665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst char kMediaProtocolRtpPrefix[] = "RTP/"; 685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst char kMediaProtocolSctp[] = "SCTP"; 705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst char kMediaProtocolDtlsSctp[] = "DTLS/SCTP"; 715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool IsMediaContentOfType(const ContentInfo* content, 735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaType media_type) { 745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!IsMediaContent(content)) { 755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaContentDescription* mdesc = 795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<const MediaContentDescription*>(content->description); 805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return mdesc && mdesc->type() == media_type; 815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool CreateCryptoParams(int tag, const std::string& cipher, 845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParams *out) { 855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string key; 865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org key.reserve(SRTP_MASTER_KEY_BASE64_LEN); 875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!talk_base::CreateRandomString(SRTP_MASTER_KEY_BASE64_LEN, &key)) { 895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org out->tag = tag; 925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org out->cipher_suite = cipher; 935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org out->key_params = kInline; 945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org out->key_params += key; 955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifdef HAVE_SRTP 995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool AddCryptoParams(const std::string& cipher_suite, 1005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParamsVec *out) { 101b30f5947ff2af0e3b77751bacec5dc7350c4dcd6sergeyu@chromium.org int size = static_cast<int>(out->size()); 1025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org out->resize(size + 1); 1045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return CreateCryptoParams(size, cipher_suite, &out->at(size)); 1055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid AddMediaCryptos(const CryptoParamsVec& cryptos, 1085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescription* media) { 1095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (CryptoParamsVec::const_iterator crypto = cryptos.begin(); 1105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org crypto != cryptos.end(); ++crypto) { 1115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org media->AddCrypto(*crypto); 1125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool CreateMediaCryptos(const std::vector<std::string>& crypto_suites, 1165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescription* media) { 1175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParamsVec cryptos; 1185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (std::vector<std::string>::const_iterator it = crypto_suites.begin(); 1195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != crypto_suites.end(); ++it) { 1205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddCryptoParams(*it, &cryptos)) { 1215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 1225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org AddMediaCryptos(cryptos, media); 1255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 1265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 1285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst CryptoParamsVec* GetCryptos(const MediaContentDescription* media) { 1305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!media) { 1315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 1325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return &media->cryptos(); 1345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool FindMatchingCrypto(const CryptoParamsVec& cryptos, 1375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const CryptoParams& crypto, 1385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParams* out) { 1395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (CryptoParamsVec::const_iterator it = cryptos.begin(); 1405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != cryptos.end(); ++it) { 1415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (crypto.Matches(*it)) { 1425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *out = *it; 1435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 1445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 1475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// For audio, HMAC 32 is prefered because of the low overhead. 1505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid GetSupportedAudioCryptoSuites( 1515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string>* crypto_suites) { 1525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifdef HAVE_SRTP 1535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org crypto_suites->push_back(CS_AES_CM_128_HMAC_SHA1_32); 1545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org crypto_suites->push_back(CS_AES_CM_128_HMAC_SHA1_80); 1555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 1565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid GetSupportedVideoCryptoSuites( 1595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string>* crypto_suites) { 1605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetSupportedDefaultCryptoSuites(crypto_suites); 1615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid GetSupportedDataCryptoSuites( 1645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string>* crypto_suites) { 1655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetSupportedDefaultCryptoSuites(crypto_suites); 1665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid GetSupportedDefaultCryptoSuites( 1695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string>* crypto_suites) { 1705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifdef HAVE_SRTP 1715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org crypto_suites->push_back(CS_AES_CM_128_HMAC_SHA1_80); 1725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 1735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// For video support only 80-bit SHA1 HMAC. For audio 32-bit HMAC is 1765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// tolerated unless bundle is enabled because it is low overhead. Pick the 1775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// crypto in the list that is supported. 1785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool SelectCrypto(const MediaContentDescription* offer, 1795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool bundle, 1805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParams *crypto) { 1815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool audio = offer->type() == MEDIA_TYPE_AUDIO; 1825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const CryptoParamsVec& cryptos = offer->cryptos(); 1835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (CryptoParamsVec::const_iterator i = cryptos.begin(); 1855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org i != cryptos.end(); ++i) { 1865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (CS_AES_CM_128_HMAC_SHA1_80 == i->cipher_suite || 1875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org (CS_AES_CM_128_HMAC_SHA1_32 == i->cipher_suite && audio && !bundle)) { 1885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return CreateCryptoParams(i->tag, i->cipher_suite, crypto); 1895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 1915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 1925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 1935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const StreamParams* FindFirstStreamParamsByCname( 1955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const StreamParamsVec& params_vec, 1965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& cname) { 1975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (StreamParamsVec::const_iterator it = params_vec.begin(); 1985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != params_vec.end(); ++it) { 1995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (cname == it->cname) 2005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return &*it; 2015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 2035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 2045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Generates a new CNAME or the CNAME of an already existing StreamParams 2065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// if a StreamParams exist for another Stream in streams with sync_label 2075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// sync_label. 2085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool GenerateCname(const StreamParamsVec& params_vec, 2095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaSessionOptions::Streams& streams, 2105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& synch_label, 2115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string* cname) { 2125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT(cname != NULL); 2135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!cname) 2145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 2155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Check if a CNAME exist for any of the other synched streams. 2175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (MediaSessionOptions::Streams::const_iterator stream_it = streams.begin(); 2185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org stream_it != streams.end() ; ++stream_it) { 2195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (synch_label != stream_it->sync_label) 2205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org continue; 2215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParams param; 2235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // groupid is empty for StreamParams generated using 2245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // MediaSessionDescriptionFactory. 2255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (GetStreamByIds(params_vec, "", stream_it->id, 2265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¶m)) { 2275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *cname = param.cname; 2285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 2295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // No other stream seems to exist that we should sync with. 2325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Generate a random string for the RTCP CNAME, as stated in RFC 6222. 2335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // This string is only used for synchronization, and therefore is opaque. 2345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org do { 2355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!talk_base::CreateRandomString(16, cname)) { 2365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT(false); 2375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 2385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } while (FindFirstStreamParamsByCname(params_vec, *cname)); 2405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 2425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 2435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Generate random SSRC values that are not already present in |params_vec|. 245582fe818e571fa2571267f5e369715188472f352wu@webrtc.org// The generated values are added to |ssrcs|. 246582fe818e571fa2571267f5e369715188472f352wu@webrtc.org// |num_ssrcs| is the number of the SSRC will be generated. 2475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void GenerateSsrcs(const StreamParamsVec& params_vec, 248582fe818e571fa2571267f5e369715188472f352wu@webrtc.org int num_ssrcs, 2495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<uint32>* ssrcs) { 250582fe818e571fa2571267f5e369715188472f352wu@webrtc.org for (int i = 0; i < num_ssrcs; i++) { 2515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org uint32 candidate; 2525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org do { 2535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org candidate = talk_base::CreateRandomNonZeroId(); 2545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } while (GetStreamBySsrc(params_vec, candidate, NULL) || 2555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::count(ssrcs->begin(), ssrcs->end(), candidate) > 0); 2565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ssrcs->push_back(candidate); 2575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 2595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Returns false if we exhaust the range of SIDs. 2615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool GenerateSctpSid(const StreamParamsVec& params_vec, 2625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org uint32* sid) { 2635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (params_vec.size() > kMaxSctpSid) { 2645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_WARNING) << 2655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org "Could not generate an SCTP SID: too many SCTP streams."; 2665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 2675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org while (true) { 2695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org uint32 candidate = talk_base::CreateRandomNonZeroId() % kMaxSctpSid; 2705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!GetStreamBySsrc(params_vec, candidate, NULL)) { 2715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *sid = candidate; 2725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 2735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 2765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool GenerateSctpSids(const StreamParamsVec& params_vec, 2785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<uint32>* sids) { 2795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org uint32 sid; 2805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!GenerateSctpSid(params_vec, &sid)) { 2815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_WARNING) << "Could not generated an SCTP SID."; 2825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 2835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 2845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sids->push_back(sid); 2855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 2865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 2875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Finds all StreamParams of all media types and attach them to stream_params. 2895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void GetCurrentStreamParams(const SessionDescription* sdesc, 2905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParamsVec* stream_params) { 2915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!sdesc) 2925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return; 2935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 2945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentInfos& contents = sdesc->contents(); 2955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ContentInfos::const_iterator content = contents.begin(); 2965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content != contents.end(); ++content) { 2975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!IsMediaContent(&*content)) { 2985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org continue; 2995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaContentDescription* media = 3015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<const MediaContentDescription*>( 3025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content->description); 3035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const StreamParamsVec& streams = media->streams(); 3045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (StreamParamsVec::const_iterator it = streams.begin(); 3055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != streams.end(); ++it) { 3065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org stream_params->push_back(*it); 3075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 3105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <typename IdStruct> 3125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass UsedIds { 3135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public: 3145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org UsedIds(int min_allowed_id, int max_allowed_id) 3155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org : min_allowed_id_(min_allowed_id), 3165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org max_allowed_id_(max_allowed_id), 3175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org next_id_(max_allowed_id) { 3185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Loops through all Id in |ids| and changes its id if it is 3215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // already in use by another IdStruct. Call this methods with all Id 3225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // in a session description to make sure no duplicate ids exists. 3235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Note that typename Id must be a type of IdStruct. 3245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org template <typename Id> 3255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org void FindAndSetIdUsed(std::vector<Id>* ids) { 3265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (typename std::vector<Id>::iterator it = ids->begin(); 3275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != ids->end(); ++it) { 3285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org FindAndSetIdUsed(&*it); 3295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Finds and sets an unused id if the |idstruct| id is already in use. 3335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org void FindAndSetIdUsed(IdStruct* idstruct) { 3345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const int original_id = idstruct->id; 3355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int new_id = idstruct->id; 3365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (original_id > max_allowed_id_ || original_id < min_allowed_id_) { 3385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // If the original id is not in range - this is an id that can't be 3395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // dynamically changed. 3405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return; 3415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsIdUsed(original_id)) { 3445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new_id = FindUnusedId(); 3455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_WARNING) << "Duplicate id found. Reassigning from " << original_id 3465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org << " to " << new_id; 3475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org idstruct->id = new_id; 3485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SetIdUsed(new_id); 3505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private: 3535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Returns the first unused id in reverse order. 3545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // This hopefully reduce the risk of more collisions. We want to change the 3555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // default ids as little as possible. 3565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int FindUnusedId() { 3575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org while (IsIdUsed(next_id_) && next_id_ >= min_allowed_id_) { 3585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org --next_id_; 3595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT(next_id_ >= min_allowed_id_); 3615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return next_id_; 3625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool IsIdUsed(int new_id) { 3655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return id_set_.find(new_id) != id_set_.end(); 3665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org void SetIdUsed(int new_id) { 3695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org id_set_.insert(new_id); 3705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const int min_allowed_id_; 3735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const int max_allowed_id_; 3745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int next_id_; 3755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::set<int> id_set_; 3765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}; 3775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Helper class used for finding duplicate RTP payload types among audio, video 3795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// and data codecs. When bundle is used the payload types may not collide. 3805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass UsedPayloadTypes : public UsedIds<Codec> { 3815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public: 3825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org UsedPayloadTypes() 3835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org : UsedIds<Codec>(kDynamicPayloadTypeMin, kDynamicPayloadTypeMax) { 3845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private: 3885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static const int kDynamicPayloadTypeMin = 96; 3895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static const int kDynamicPayloadTypeMax = 127; 3905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}; 3915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 3925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Helper class used for finding duplicate RTP Header extension ids among 3935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// audio and video extensions. 3945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass UsedRtpHeaderExtensionIds : public UsedIds<RtpHeaderExtension> { 3955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public: 3965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org UsedRtpHeaderExtensionIds() 3975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org : UsedIds<RtpHeaderExtension>(kLocalIdMin, kLocalIdMax) { 3985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 3995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private: 4015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Min and Max local identifier as specified by RFC5285. 4025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static const int kLocalIdMin = 1; 4035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static const int kLocalIdMax = 255; 4045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}; 4055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool IsSctp(const MediaContentDescription* desc) { 4075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return ((desc->protocol() == kMediaProtocolSctp) || 4085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org (desc->protocol() == kMediaProtocolDtlsSctp)); 4095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 4105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Adds a StreamParams for each Stream in Streams with media type 4125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// media_type to content_description. 4135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// |current_params| - All currently known StreamParams of any media type. 4145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 4155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool AddStreamParams( 4165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaType media_type, 4175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaSessionOptions::Streams& streams, 4185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParamsVec* current_streams, 4195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescriptionImpl<C>* content_description, 4205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const bool add_legacy_stream) { 4215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const bool include_rtx_stream = 4225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ContainsRtxCodec(content_description->codecs()); 4235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (streams.empty() && add_legacy_stream) { 4255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // TODO(perkj): Remove this legacy stream when all apps use StreamParams. 4265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<uint32> ssrcs; 4275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsSctp(content_description)) { 4285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GenerateSctpSids(*current_streams, &ssrcs); 4295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 430582fe818e571fa2571267f5e369715188472f352wu@webrtc.org int num_ssrcs = include_rtx_stream ? 2 : 1; 431582fe818e571fa2571267f5e369715188472f352wu@webrtc.org GenerateSsrcs(*current_streams, num_ssrcs, &ssrcs); 4325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (include_rtx_stream) { 4345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content_description->AddLegacyStream(ssrcs[0], ssrcs[1]); 4355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content_description->set_multistream(true); 4365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 4375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content_description->AddLegacyStream(ssrcs[0]); 4385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 4405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaSessionOptions::Streams::const_iterator stream_it; 4435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (stream_it = streams.begin(); 4445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org stream_it != streams.end(); ++stream_it) { 4455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (stream_it->type != media_type) 4465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org continue; // Wrong media type. 4475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParams param; 4495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // groupid is empty for StreamParams generated using 4505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // MediaSessionDescriptionFactory. 4515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!GetStreamByIds(*current_streams, "", stream_it->id, 4525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¶m)) { 4535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // This is a new stream. 4545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Get a CNAME. Either new or same as one of the other synched streams. 4555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string cname; 4565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!GenerateCname(*current_streams, streams, stream_it->sync_label, 4575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org &cname)) { 4585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 4595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<uint32> ssrcs; 4625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsSctp(content_description)) { 4635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GenerateSctpSids(*current_streams, &ssrcs); 4645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 465582fe818e571fa2571267f5e369715188472f352wu@webrtc.org GenerateSsrcs(*current_streams, stream_it->num_sim_layers, &ssrcs); 4665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParams stream_param; 4685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org stream_param.id = stream_it->id; 469582fe818e571fa2571267f5e369715188472f352wu@webrtc.org // Add the generated ssrc. 470582fe818e571fa2571267f5e369715188472f352wu@webrtc.org for (size_t i = 0; i < ssrcs.size(); ++i) { 471582fe818e571fa2571267f5e369715188472f352wu@webrtc.org stream_param.ssrcs.push_back(ssrcs[i]); 472582fe818e571fa2571267f5e369715188472f352wu@webrtc.org } 473582fe818e571fa2571267f5e369715188472f352wu@webrtc.org if (stream_it->num_sim_layers > 1) { 474582fe818e571fa2571267f5e369715188472f352wu@webrtc.org SsrcGroup group(kSimSsrcGroupSemantics, stream_param.ssrcs); 475582fe818e571fa2571267f5e369715188472f352wu@webrtc.org stream_param.ssrc_groups.push_back(group); 476582fe818e571fa2571267f5e369715188472f352wu@webrtc.org } 477582fe818e571fa2571267f5e369715188472f352wu@webrtc.org // Generate an extra ssrc for include_rtx_stream case. 4785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (include_rtx_stream) { 479582fe818e571fa2571267f5e369715188472f352wu@webrtc.org std::vector<uint32> rtx_ssrc; 480582fe818e571fa2571267f5e369715188472f352wu@webrtc.org GenerateSsrcs(*current_streams, 1, &rtx_ssrc); 481582fe818e571fa2571267f5e369715188472f352wu@webrtc.org stream_param.AddFidSsrc(ssrcs[0], rtx_ssrc[0]); 4825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content_description->set_multistream(true); 4835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org stream_param.cname = cname; 4855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org stream_param.sync_label = stream_it->sync_label; 4865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content_description->AddStream(stream_param); 4875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Store the new StreamParams in current_streams. 4895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // This is necessary so that we can use the CNAME for other media types. 4905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_streams->push_back(stream_param); 4915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 4925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content_description->AddStream(param); 4935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 4955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 4965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 4975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 4985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Updates the transport infos of the |sdesc| according to the given 4995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// |bundle_group|. The transport infos of the content names within the 5005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// |bundle_group| should be updated to use the ufrag and pwd of the first 5015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// content within the |bundle_group|. 5025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool UpdateTransportInfoForBundle(const ContentGroup& bundle_group, 5035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SessionDescription* sdesc) { 5045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // The bundle should not be empty. 5055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!sdesc || !bundle_group.FirstContentName()) { 5065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 5075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // We should definitely have a transport for the first content. 5105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string selected_content_name = *bundle_group.FirstContentName(); 5115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportInfo* selected_transport_info = 5125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sdesc->GetTransportInfoByName(selected_content_name); 5135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!selected_transport_info) { 5145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 5155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Set the other contents to use the same ICE credentials. 5185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string selected_ufrag = 5195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org selected_transport_info->description.ice_ufrag; 5205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string selected_pwd = 5215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org selected_transport_info->description.ice_pwd; 5225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (TransportInfos::iterator it = 5235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sdesc->transport_infos().begin(); 5245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != sdesc->transport_infos().end(); ++it) { 5255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (bundle_group.HasContentName(it->content_name) && 5265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it->content_name != selected_content_name) { 5275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it->description.ice_ufrag = selected_ufrag; 5285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it->description.ice_pwd = selected_pwd; 5295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 5325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 5335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Gets the CryptoParamsVec of the given |content_name| from |sdesc|, and 5355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// sets it to |cryptos|. 5365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool GetCryptosByName(const SessionDescription* sdesc, 5375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& content_name, 5385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParamsVec* cryptos) { 5395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!sdesc || !cryptos) { 5405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 5415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentInfo* content = sdesc->GetContentByName(content_name); 5445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!IsMediaContent(content) || !content->description) { 5455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 5465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaContentDescription* media_desc = 5495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<const MediaContentDescription*>(content->description); 5505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *cryptos = media_desc->cryptos(); 5515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 5525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 5535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Predicate function used by the remove_if. 5555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Returns true if the |crypto|'s cipher_suite is not found in |filter|. 5565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool CryptoNotFound(const CryptoParams crypto, 5575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const CryptoParamsVec* filter) { 5585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (filter == NULL) { 5595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 5605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (CryptoParamsVec::const_iterator it = filter->begin(); 5625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != filter->end(); ++it) { 5635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (it->cipher_suite == crypto.cipher_suite) { 5645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 5655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 5685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 5695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Prunes the |target_cryptos| by removing the crypto params (cipher_suite) 5715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// which are not available in |filter|. 5725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void PruneCryptos(const CryptoParamsVec& filter, 5735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParamsVec* target_cryptos) { 5745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!target_cryptos) { 5755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return; 5765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org target_cryptos->erase(std::remove_if(target_cryptos->begin(), 5785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org target_cryptos->end(), 5795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bind2nd(ptr_fun(CryptoNotFound), 5805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org &filter)), 5815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org target_cryptos->end()); 5825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 5835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 5845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool IsRtpContent(SessionDescription* sdesc, 5855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& content_name) { 5865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool is_rtp = false; 5875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ContentInfo* content = sdesc->GetContentByName(content_name); 5885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsMediaContent(content)) { 5895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescription* media_desc = 5905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<MediaContentDescription*>(content->description); 5915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!media_desc) { 5925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 5935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org is_rtp = media_desc->protocol().empty() || 5955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org talk_base::starts_with(media_desc->protocol().data(), 5965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org kMediaProtocolRtpPrefix); 5975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 5985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return is_rtp; 5995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 6005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 6015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Updates the crypto parameters of the |sdesc| according to the given 6025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// |bundle_group|. The crypto parameters of all the contents within the 6035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// |bundle_group| should be updated to use the common subset of the 6045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// available cryptos. 6055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool UpdateCryptoParamsForBundle(const ContentGroup& bundle_group, 6065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SessionDescription* sdesc) { 6075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // The bundle should not be empty. 6085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!sdesc || !bundle_group.FirstContentName()) { 6095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 6105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 61259a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org bool common_cryptos_needed = false; 6135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Get the common cryptos. 6145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentNames& content_names = bundle_group.content_names(); 6155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParamsVec common_cryptos; 6165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ContentNames::const_iterator it = content_names.begin(); 6175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != content_names.end(); ++it) { 6185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!IsRtpContent(sdesc, *it)) { 6195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org continue; 6205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 62159a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org // The common cryptos are needed if any of the content does not have DTLS 62259a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org // enabled. 62359a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org if (!sdesc->GetTransportInfoByName(*it)->description.secure()) { 62459a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org common_cryptos_needed = true; 62559a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org } 6265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (it == content_names.begin()) { 6275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Initial the common_cryptos with the first content in the bundle group. 6285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!GetCryptosByName(sdesc, *it, &common_cryptos)) { 6295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 6305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (common_cryptos.empty()) { 6325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // If there's no crypto params, we should just return. 6335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 6345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 6365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParamsVec cryptos; 6375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!GetCryptosByName(sdesc, *it, &cryptos)) { 6385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 6395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org PruneCryptos(cryptos, &common_cryptos); 6415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 64459a1e5569576b61b7ae1f0d7fe72c958c940e156wu@webrtc.org if (common_cryptos.empty() && common_cryptos_needed) { 6455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 6465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 6485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Update to use the common cryptos. 6495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ContentNames::const_iterator it = content_names.begin(); 6505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != content_names.end(); ++it) { 6515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!IsRtpContent(sdesc, *it)) { 6525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org continue; 6535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ContentInfo* content = sdesc->GetContentByName(*it); 6555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsMediaContent(content)) { 6565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescription* media_desc = 6575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<MediaContentDescription*>(content->description); 6585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!media_desc) { 6595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 6605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org media_desc->set_cryptos(common_cryptos); 6625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 6655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 6665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 6675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 6685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool ContainsRtxCodec(const std::vector<C>& codecs) { 6695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org typename std::vector<C>::const_iterator it; 6705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (it = codecs.begin(); it != codecs.end(); ++it) { 6715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsRtxCodec(*it)) { 6725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 6735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 6755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 6765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 6775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 6785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 6795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool IsRtxCodec(const C& codec) { 6805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return stricmp(codec.name.c_str(), kRtxCodecName) == 0; 6815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 6825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 6835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Create a media content to be offered in a session-initiate, 6845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// according to the given options.rtcp_mux, options.is_muc, 6855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// options.streams, codecs, secure_transport, crypto, and streams. If we don't 6865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// currently have crypto (in current_cryptos) and it is enabled (in 6875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// secure_policy), crypto is created (according to crypto_suites). If 6885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// add_legacy_stream is true, and current_streams is empty, a legacy 6895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// stream is created. The created content is added to the offer. 6905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 6915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool CreateMediaContentOffer( 6925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaSessionOptions& options, 6935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::vector<C>& codecs, 6945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SecureMediaPolicy& secure_policy, 6955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const CryptoParamsVec* current_cryptos, 6965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::vector<std::string>& crypto_suites, 6975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const RtpHeaderExtensions& rtp_extensions, 6985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool add_legacy_stream, 6995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParamsVec* current_streams, 7005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescriptionImpl<C>* offer) { 7015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->AddCodecs(codecs); 7025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->SortCodecs(); 7035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->set_crypto_required(secure_policy == SEC_REQUIRED); 7055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->set_rtcp_mux(options.rtcp_mux_enabled); 7065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->set_multistream(options.is_muc); 7075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->set_rtp_header_extensions(rtp_extensions); 7085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddStreamParams( 7105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->type(), options.streams, current_streams, 7115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer, add_legacy_stream)) { 7125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 7135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifdef HAVE_SRTP 7165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (secure_policy != SEC_DISABLED) { 7175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (current_cryptos) { 7185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org AddMediaCryptos(*current_cryptos, offer); 7195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (offer->cryptos().empty()) { 7215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!CreateMediaCryptos(crypto_suites, offer)) { 7225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 7235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif 7275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (offer->crypto_required() && offer->cryptos().empty()) { 7295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 7305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 7325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 7335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 7355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void NegotiateCodecs(const std::vector<C>& local_codecs, 7365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::vector<C>& offered_codecs, 7375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<C>* negotiated_codecs) { 7385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org typename std::vector<C>::const_iterator ours; 7395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ours = local_codecs.begin(); 7405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ours != local_codecs.end(); ++ours) { 7415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org typename std::vector<C>::const_iterator theirs; 7425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (theirs = offered_codecs.begin(); 7435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org theirs != offered_codecs.end(); ++theirs) { 7445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (ours->Matches(*theirs)) { 7455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org C negotiated = *ours; 7465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org negotiated.IntersectFeedbackParams(*theirs); 7475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsRtxCodec(negotiated)) { 7485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Only negotiate RTX if kCodecParamAssociatedPayloadType has been 7495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // set. 7505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::string apt_value; 7515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!theirs->GetParam(kCodecParamAssociatedPayloadType, &apt_value)) { 7525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_WARNING) << "RTX missing associated payload type."; 7535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org continue; 7545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org negotiated.SetParam(kCodecParamAssociatedPayloadType, apt_value); 7565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org negotiated.id = theirs->id; 7585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org negotiated_codecs->push_back(negotiated); 7595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 7635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 7655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool FindMatchingCodec(const std::vector<C>& codecs, 7665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const C& codec_to_match, 7675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org C* found_codec) { 7685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (typename std::vector<C>::const_iterator it = codecs.begin(); 7695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != codecs.end(); ++it) { 7705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (it->Matches(codec_to_match)) { 7715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (found_codec != NULL) { 7725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *found_codec= *it; 7735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 7755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 7775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 7785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 7795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Adds all codecs from |reference_codecs| to |offered_codecs| that dont' 7815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// already exist in |offered_codecs| and ensure the payload types don't 7825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// collide. 7835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 7845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void FindCodecsToOffer( 7855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::vector<C>& reference_codecs, 7865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<C>* offered_codecs, 7875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org UsedPayloadTypes* used_pltypes) { 7885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org typedef std::map<int, C> RtxCodecReferences; 7905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtxCodecReferences new_rtx_codecs; 7915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 7925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Find all new RTX codecs. 7935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (typename std::vector<C>::const_iterator it = reference_codecs.begin(); 7945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != reference_codecs.end(); ++it) { 7955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!FindMatchingCodec<C>(*offered_codecs, *it, NULL) && IsRtxCodec(*it)) { 7965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org C rtx_codec = *it; 7975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int referenced_pl_type = 798c1c67e5a722135af4ca83ee4c7d2dbe3f26bae70henrike@webrtc.org talk_base::FromString<int>(0, 7995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org rtx_codec.params[kCodecParamAssociatedPayloadType]); 8005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new_rtx_codecs.insert(std::pair<int, C>(referenced_pl_type, 8015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org rtx_codec)); 8025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Add all new codecs that are not RTX codecs. 8065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (typename std::vector<C>::const_iterator it = reference_codecs.begin(); 8075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != reference_codecs.end(); ++it) { 8085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!FindMatchingCodec<C>(*offered_codecs, *it, NULL) && !IsRtxCodec(*it)) { 8095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org C codec = *it; 8105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int original_payload_id = codec.id; 8115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_pltypes->FindAndSetIdUsed(&codec); 8125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offered_codecs->push_back(codec); 8135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // If this codec is referenced by a new RTX codec, update the reference 8155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // in the RTX codec with the new payload type. 8165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org typename RtxCodecReferences::iterator rtx_it = 8175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new_rtx_codecs.find(original_payload_id); 8185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (rtx_it != new_rtx_codecs.end()) { 8195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org C& rtx_codec = rtx_it->second; 8205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org rtx_codec.params[kCodecParamAssociatedPayloadType] = 8215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org talk_base::ToString(codec.id); 8225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Add all new RTX codecs. 8275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (typename RtxCodecReferences::iterator it = new_rtx_codecs.begin(); 8285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != new_rtx_codecs.end(); ++it) { 8295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org C& rtx_codec = it->second; 8305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_pltypes->FindAndSetIdUsed(&rtx_codec); 8315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offered_codecs->push_back(rtx_codec); 8325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 8345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool FindByUri(const RtpHeaderExtensions& extensions, 8375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const RtpHeaderExtension& ext_to_match, 8385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtension* found_extension) { 8395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (RtpHeaderExtensions::const_iterator it = extensions.begin(); 8405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != extensions.end(); ++it) { 8415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // We assume that all URIs are given in a canonical format. 8425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (it->uri == ext_to_match.uri) { 8435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (found_extension != NULL) { 8445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *found_extension= *it; 8455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 8475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 8505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 8515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void FindAndSetRtpHdrExtUsed( 8535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const RtpHeaderExtensions& reference_extensions, 8545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions* offered_extensions, 8555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org UsedRtpHeaderExtensionIds* used_extensions) { 8565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (RtpHeaderExtensions::const_iterator it = reference_extensions.begin(); 8575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org it != reference_extensions.end(); ++it) { 8585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!FindByUri(*offered_extensions, *it, NULL)) { 8595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtension ext = *it; 8605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_extensions->FindAndSetIdUsed(&ext); 8615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offered_extensions->push_back(ext); 8625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 8655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void NegotiateRtpHeaderExtensions( 8675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const RtpHeaderExtensions& local_extensions, 8685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const RtpHeaderExtensions& offered_extensions, 8695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions* negotiated_extenstions) { 8705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions::const_iterator ours; 8715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ours = local_extensions.begin(); 8725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ours != local_extensions.end(); ++ours) { 8735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtension theirs; 8745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (FindByUri(offered_extensions, *ours, &theirs)) { 8755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // We respond with their RTP header extension id. 8765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org negotiated_extenstions->push_back(theirs); 8775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 8805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void StripCNCodecs(AudioCodecs* audio_codecs) { 8825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org AudioCodecs::iterator iter = audio_codecs->begin(); 8835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org while (iter != audio_codecs->end()) { 8845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (stricmp(iter->name.c_str(), kComfortNoiseCodecName) == 0) { 8855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org iter = audio_codecs->erase(iter); 8865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 8875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ++iter; 8885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 8905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 8915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 8925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Create a media content to be answered in a session-accept, 8935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// according to the given options.rtcp_mux, options.streams, codecs, 8945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// crypto, and streams. If we don't currently have crypto (in 8955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// current_cryptos) and it is enabled (in secure_policy), crypto is 8965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// created (according to crypto_suites). If add_legacy_stream is 8975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// true, and current_streams is empty, a legacy stream is created. 8985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// The codecs, rtcp_mux, and crypto are all negotiated with the offer 8995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// from the incoming session-initiate. If the negotiation fails, this 9005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// method returns false. The created content is added to the offer. 9015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgtemplate <class C> 9025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool CreateMediaContentAnswer( 9035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaContentDescriptionImpl<C>* offer, 9045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaSessionOptions& options, 9055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::vector<C>& local_codecs, 9065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SecureMediaPolicy& sdes_policy, 9075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const CryptoParamsVec* current_cryptos, 9085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const RtpHeaderExtensions& local_rtp_extenstions, 9095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParamsVec* current_streams, 9105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool add_legacy_stream, 9115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool bundle_enabled, 9125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescriptionImpl<C>* answer) { 9135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<C> negotiated_codecs; 9145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs); 9155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->AddCodecs(negotiated_codecs); 9165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->SortCodecs(); 9175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->set_protocol(offer->protocol()); 9185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions negotiated_rtp_extensions; 9195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org NegotiateRtpHeaderExtensions(local_rtp_extenstions, 9205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->rtp_header_extensions(), 9215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org &negotiated_rtp_extensions); 9225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->set_rtp_header_extensions(negotiated_rtp_extensions); 9235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->set_rtcp_mux(options.rtcp_mux_enabled && offer->rtcp_mux()); 9255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (sdes_policy != SEC_DISABLED) { 9275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CryptoParams crypto; 9285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (SelectCrypto(offer, bundle_enabled, &crypto)) { 9295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (current_cryptos) { 9305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org FindMatchingCrypto(*current_cryptos, crypto, &crypto); 9315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 9325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->AddCrypto(crypto); 9335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 9345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 9355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (answer->cryptos().empty() && 9375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org (offer->crypto_required() || sdes_policy == SEC_REQUIRED)) { 9385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 9395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 9405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddStreamParams( 9425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->type(), options.streams, current_streams, 9435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer, add_legacy_stream)) { 9445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; // Something went seriously wrong. 9455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 9465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Make sure the answer media content direction is per default set as 9485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // described in RFC3264 section 6.1. 9495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org switch (offer->direction()) { 9505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org case MD_INACTIVE: 9515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->set_direction(MD_INACTIVE); 9525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org break; 9535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org case MD_SENDONLY: 9545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->set_direction(MD_RECVONLY); 9555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org break; 9565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org case MD_RECVONLY: 9575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->set_direction(MD_SENDONLY); 9585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org break; 9595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org case MD_SENDRECV: 9605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->set_direction(MD_SENDRECV); 9615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org break; 9625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org default: 9635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org break; 9645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 9655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 9675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 9685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic bool IsMediaProtocolSupported(MediaType type, 9705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& protocol) { 9715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Data channels can have a protocol of SCTP or SCTP/DTLS. 9725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (type == MEDIA_TYPE_DATA && 9735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org (protocol == kMediaProtocolSctp || 9745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org protocol == kMediaProtocolDtlsSctp)) { 9755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 9765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 9775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Since not all applications serialize and deserialize the media protocol, 9785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // we will have to accept |protocol| to be empty. 9795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return protocol == kMediaProtocolAvpf || protocol == kMediaProtocolSavpf || 9805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org protocol.empty(); 9815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 9825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 9835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic void SetMediaProtocol(bool secure_transport, 9845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaContentDescription* desc) { 9855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!desc->cryptos().empty() || secure_transport) 9865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org desc->set_protocol(kMediaProtocolSavpf); 9875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org else 9885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org desc->set_protocol(kMediaProtocolAvpf); 9895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 9905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 991bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org// Gets the TransportInfo of the given |content_name| from the 992bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org// |current_description|. If doesn't exist, returns a new one. 993bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.orgstatic const TransportDescription* GetTransportDescription( 994bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const std::string& content_name, 995bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const SessionDescription* current_description) { 996bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const TransportDescription* desc = NULL; 997bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org if (current_description) { 998bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const TransportInfo* info = 999bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org current_description->GetTransportInfoByName(content_name); 1000bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org if (info) { 1001bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org desc = &info->description; 1002bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org } 1003bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org } 1004bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org return desc; 1005bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org} 1006bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 1007bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org// Gets the current DTLS state from the transport description. 1008bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.orgstatic bool IsDtlsActive( 1009bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const std::string& content_name, 1010bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const SessionDescription* current_description) { 1011bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org if (!current_description) 1012bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org return false; 1013bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 1014bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const ContentInfo* content = 1015bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org current_description->GetContentByName(content_name); 1016bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org if (!content) 1017bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org return false; 1018bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 1019bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org const TransportDescription* current_tdesc = 1020bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org GetTransportDescription(content_name, current_description); 1021bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org if (!current_tdesc) 1022bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org return false; 1023bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 1024bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org return current_tdesc->secure(); 1025bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org} 1026bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 10275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid MediaSessionOptions::AddStream(MediaType type, 10285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& id, 10295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& sync_label) { 1030582fe818e571fa2571267f5e369715188472f352wu@webrtc.org AddStreamInternal(type, id, sync_label, 1); 1031582fe818e571fa2571267f5e369715188472f352wu@webrtc.org} 1032582fe818e571fa2571267f5e369715188472f352wu@webrtc.org 1033582fe818e571fa2571267f5e369715188472f352wu@webrtc.orgvoid MediaSessionOptions::AddVideoStream( 1034582fe818e571fa2571267f5e369715188472f352wu@webrtc.org const std::string& id, 1035582fe818e571fa2571267f5e369715188472f352wu@webrtc.org const std::string& sync_label, 1036582fe818e571fa2571267f5e369715188472f352wu@webrtc.org int num_sim_layers) { 1037582fe818e571fa2571267f5e369715188472f352wu@webrtc.org AddStreamInternal(MEDIA_TYPE_VIDEO, id, sync_label, num_sim_layers); 1038582fe818e571fa2571267f5e369715188472f352wu@webrtc.org} 1039582fe818e571fa2571267f5e369715188472f352wu@webrtc.org 1040582fe818e571fa2571267f5e369715188472f352wu@webrtc.orgvoid MediaSessionOptions::AddStreamInternal( 1041582fe818e571fa2571267f5e369715188472f352wu@webrtc.org MediaType type, 1042582fe818e571fa2571267f5e369715188472f352wu@webrtc.org const std::string& id, 1043582fe818e571fa2571267f5e369715188472f352wu@webrtc.org const std::string& sync_label, 1044582fe818e571fa2571267f5e369715188472f352wu@webrtc.org int num_sim_layers) { 1045582fe818e571fa2571267f5e369715188472f352wu@webrtc.org streams.push_back(Stream(type, id, sync_label, num_sim_layers)); 10465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (type == MEDIA_TYPE_VIDEO) 10485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org has_video = true; 10495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org else if (type == MEDIA_TYPE_AUDIO) 10505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org has_audio = true; 10515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // If we haven't already set the data_channel_type, and we add a 10525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // stream, we assume it's an RTP data stream. 10535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org else if (type == MEDIA_TYPE_DATA && data_channel_type == DCT_NONE) 10545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_channel_type = DCT_RTP; 10555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 10565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid MediaSessionOptions::RemoveStream(MediaType type, 10585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& id) { 10595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org Streams::iterator stream_it = streams.begin(); 10605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (; stream_it != streams.end(); ++stream_it) { 10615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (stream_it->type == type && stream_it->id == id) { 10625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org streams.erase(stream_it); 10635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return; 10645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 10655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 10665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ASSERT(false); 10675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 10685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgMediaSessionDescriptionFactory::MediaSessionDescriptionFactory( 10705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportDescriptionFactory* transport_desc_factory) 10715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org : secure_(SEC_DISABLED), 10725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_(true), 10735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org transport_desc_factory_(transport_desc_factory) { 10745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 10755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgMediaSessionDescriptionFactory::MediaSessionDescriptionFactory( 10775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ChannelManager* channel_manager, 10785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportDescriptionFactory* transport_desc_factory) 10795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org : secure_(SEC_DISABLED), 10805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_(true), 10815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org transport_desc_factory_(transport_desc_factory) { 10825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_manager->GetSupportedAudioCodecs(&audio_codecs_); 10835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); 10845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_manager->GetSupportedVideoCodecs(&video_codecs_); 10855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); 10865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_manager->GetSupportedDataCodecs(&data_codecs_); 10875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 10885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgSessionDescription* MediaSessionDescriptionFactory::CreateOffer( 10905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const MediaSessionOptions& options, 10915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* current_description) const { 10925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); 10935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<SessionDescription> offer(new SessionDescription()); 10955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParamsVec current_streams; 10975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCurrentStreamParams(current_description, ¤t_streams); 10985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 10995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org AudioCodecs audio_codecs; 11005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org VideoCodecs video_codecs; 11015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org DataCodecs data_codecs; 11025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCodecsToOffer(current_description, &audio_codecs, &video_codecs, 11035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org &data_codecs); 11045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 11055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!options.vad_enabled) { 11065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // If application doesn't want CN codecs in offer. 11075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StripCNCodecs(&audio_codecs); 11085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 11105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions audio_rtp_extensions; 11115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions video_rtp_extensions; 11125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, 11135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org &video_rtp_extensions); 11145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 11155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Handle m=audio. 11165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (options.has_audio) { 1117bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org cricket::SecurePolicy sdes_policy = 1118bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org IsDtlsActive(CN_AUDIO, current_description) ? 1119bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org cricket::SEC_DISABLED : secure(); 1120bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 11215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<AudioContentDescription> audio(new AudioContentDescription()); 11225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string> crypto_suites; 11235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetSupportedAudioCryptoSuites(&crypto_suites); 11245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!CreateMediaContentOffer( 11255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options, 11265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_codecs, 1127bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org sdes_policy, 11285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCryptos(GetFirstAudioContentDescription(current_description)), 11295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org crypto_suites, 11305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_rtp_extensions, 11315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_, 11325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¤t_streams, 11335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio.get())) { 11345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 11355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 11375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio->set_lang(lang_); 11385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SetMediaProtocol(secure_transport, audio.get()); 11395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->AddContent(CN_AUDIO, NS_JINGLE_RTP, audio.release()); 11405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddTransportOffer(CN_AUDIO, options.transport_options, 11415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_description, offer.get())) { 11425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 11435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 11465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Handle m=video. 11475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (options.has_video) { 1148bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org cricket::SecurePolicy sdes_policy = 1149bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org IsDtlsActive(CN_VIDEO, current_description) ? 1150bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org cricket::SEC_DISABLED : secure(); 1151bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org 11525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<VideoContentDescription> video(new VideoContentDescription()); 11535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string> crypto_suites; 11545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetSupportedVideoCryptoSuites(&crypto_suites); 11555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!CreateMediaContentOffer( 11565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options, 11575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_codecs, 1158bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org sdes_policy, 11595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCryptos(GetFirstVideoContentDescription(current_description)), 11605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org crypto_suites, 11615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_rtp_extensions, 11625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_, 11635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¤t_streams, 11645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video.get())) { 11655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 11665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 11685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video->set_bandwidth(options.video_bandwidth); 11695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SetMediaProtocol(secure_transport, video.get()); 11705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->AddContent(CN_VIDEO, NS_JINGLE_RTP, video.release()); 11715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddTransportOffer(CN_VIDEO, options.transport_options, 11725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_description, offer.get())) { 11735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 11745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 11775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Handle m=data. 11785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (options.has_data()) { 11795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<DataContentDescription> data(new DataContentDescription()); 11805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool is_sctp = (options.data_channel_type == DCT_SCTP); 11815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 1182bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org cricket::SecurePolicy sdes_policy = 1183bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org IsDtlsActive(CN_DATA, current_description) ? 1184bc7581abbe24c0f45fd04ec30099198670c92512mallinath@webrtc.org cricket::SEC_DISABLED : secure(); 11855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org std::vector<std::string> crypto_suites; 11865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (is_sctp) { 11875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // SDES doesn't make sense for SCTP, so we disable it, and we only 11885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // get SDES crypto suites for RTP-based data channels. 11895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sdes_policy = cricket::SEC_DISABLED; 11905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Unlike SetMediaProtocol below, we need to set the protocol 11915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // before we call CreateMediaContentOffer. Otherwise, 11925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // CreateMediaContentOffer won't know this is SCTP and will 11935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // generate SSRCs rather than SIDs. 11945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data->set_protocol( 11955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org secure_transport ? kMediaProtocolDtlsSctp : kMediaProtocolSctp); 11965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 11975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetSupportedDataCryptoSuites(&crypto_suites); 11985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 11995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!CreateMediaContentOffer( 12015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options, 12025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_codecs, 12035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sdes_policy, 12045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCryptos(GetFirstDataContentDescription(current_description)), 12055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org crypto_suites, 12065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions(), 12075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_, 12085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¤t_streams, 12095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data.get())) { 12105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 12115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (is_sctp) { 12145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->AddContent(CN_DATA, NS_JINGLE_DRAFT_SCTP, data.release()); 12155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 12165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data->set_bandwidth(options.data_bandwidth); 12175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SetMediaProtocol(secure_transport, data.get()); 12185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->AddContent(CN_DATA, NS_JINGLE_RTP, data.release()); 12195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddTransportOffer(CN_DATA, options.transport_options, 12215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_description, offer.get())) { 12225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 12235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Bundle the contents together, if we've been asked to do so, and update any 12275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // parameters that need to be tweaked for BUNDLE. 12285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (options.bundle_enabled) { 12295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ContentGroup offer_bundle(GROUP_TYPE_BUNDLE); 12305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ContentInfos::const_iterator content = offer->contents().begin(); 12315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content != offer->contents().end(); ++content) { 12325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer_bundle.AddContentName(content->name); 12335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->AddGroup(offer_bundle); 12355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!UpdateTransportInfoForBundle(offer_bundle, offer.get())) { 12365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_ERROR) << "CreateOffer failed to UpdateTransportInfoForBundle."; 12375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 12385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!UpdateCryptoParamsForBundle(offer_bundle, offer.get())) { 12405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_ERROR) << "CreateOffer failed to UpdateCryptoParamsForBundle."; 12415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 12425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return offer.release(); 12465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 12475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgSessionDescription* MediaSessionDescriptionFactory::CreateAnswer( 12495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* offer, const MediaSessionOptions& options, 12505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* current_description) const { 12515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // The answer contains the intersection of the codecs in the offer with the 12525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // codecs we support, ordered by our local preference. As indicated by 12535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // XEP-0167, we retain the same payload ids from the offer in the answer. 12545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<SessionDescription> answer(new SessionDescription()); 12555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StreamParamsVec current_streams; 12575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCurrentStreamParams(current_description, ¤t_streams); 12585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool bundle_enabled = 12605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; 12615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Handle m=audio. 12635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentInfo* audio_content = GetFirstAudioContent(offer); 12645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (audio_content) { 12655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<TransportDescription> audio_transport( 12665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CreateTransportAnswer(audio_content->name, offer, 12675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options.transport_options, 12685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_description)); 12695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!audio_transport) { 12705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 12715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org AudioCodecs audio_codecs = audio_codecs_; 12745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!options.vad_enabled) { 12755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org StripCNCodecs(&audio_codecs); 12765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<AudioContentDescription> audio_answer( 12795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new AudioContentDescription()); 12805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Do not require or create SDES cryptos if DTLS is used. 12815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::SecurePolicy sdes_policy = 12825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_transport->secure() ? cricket::SEC_DISABLED : secure(); 12835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!CreateMediaContentAnswer( 12845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<const AudioContentDescription*>( 12855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_content->description), 12865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options, 12875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_codecs, 12885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sdes_policy, 12895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCryptos(GetFirstAudioContentDescription(current_description)), 12905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_rtp_extensions_, 12915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¤t_streams, 12925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_, 12935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bundle_enabled, 12945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_answer.get())) { 12955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; // Fails the session setup. 12965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 12975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 12985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool rejected = !options.has_audio || audio_content->rejected || 12995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org !IsMediaProtocolSupported(MEDIA_TYPE_AUDIO, 13005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_answer->protocol()); 13015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!rejected) { 13025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org AddTransportAnswer(audio_content->name, *(audio_transport.get()), 13035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer.get()); 13045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 13055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // RFC 3264 13065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // The answer MUST contain the same number of m-lines as the offer. 13075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_INFO) << "Audio is not supported in the answer."; 13085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 13105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->AddContent(audio_content->name, audio_content->type, rejected, 13115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_answer.release()); 13125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 13135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_INFO) << "Audio is not available in the offer."; 13145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 13165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Handle m=video. 13175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentInfo* video_content = GetFirstVideoContent(offer); 13185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (video_content) { 13195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<TransportDescription> video_transport( 13205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CreateTransportAnswer(video_content->name, offer, 13215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options.transport_options, 13225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_description)); 13235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!video_transport) { 13245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 13255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 13275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<VideoContentDescription> video_answer( 13285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new VideoContentDescription()); 13295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Do not require or create SDES cryptos if DTLS is used. 13305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::SecurePolicy sdes_policy = 13315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_transport->secure() ? cricket::SEC_DISABLED : secure(); 13325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!CreateMediaContentAnswer( 13335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<const VideoContentDescription*>( 13345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_content->description), 13355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options, 13365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_codecs_, 13375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sdes_policy, 13385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCryptos(GetFirstVideoContentDescription(current_description)), 13395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_rtp_extensions_, 13405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¤t_streams, 13415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_, 13425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bundle_enabled, 13435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_answer.get())) { 13445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 13455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool rejected = !options.has_video || video_content->rejected || 13475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org !IsMediaProtocolSupported(MEDIA_TYPE_VIDEO, video_answer->protocol()); 13485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!rejected) { 13495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddTransportAnswer(video_content->name, *(video_transport.get()), 13505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer.get())) { 13515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 13525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_answer->set_bandwidth(options.video_bandwidth); 13545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 13555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // RFC 3264 13565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // The answer MUST contain the same number of m-lines as the offer. 13575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_INFO) << "Video is not supported in the answer."; 13585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->AddContent(video_content->name, video_content->type, rejected, 13605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_answer.release()); 13615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 13625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_INFO) << "Video is not available in the offer."; 13635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 13655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Handle m=data. 13665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentInfo* data_content = GetFirstDataContent(offer); 13675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (data_content) { 13685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<TransportDescription> data_transport( 13695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org CreateTransportAnswer(data_content->name, offer, 13705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options.transport_options, 13715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_description)); 13725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!data_transport) { 13735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 13745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org scoped_ptr<DataContentDescription> data_answer( 13765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org new DataContentDescription()); 13775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Do not require or create SDES cryptos if DTLS is used. 13785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org cricket::SecurePolicy sdes_policy = 13795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_transport->secure() ? cricket::SEC_DISABLED : secure(); 13805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!CreateMediaContentAnswer( 13815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org static_cast<const DataContentDescription*>( 13825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_content->description), 13835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org options, 13845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_codecs_, 13855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org sdes_policy, 13865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetCryptos(GetFirstDataContentDescription(current_description)), 13875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions(), 13885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ¤t_streams, 13895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org add_legacy_, 13905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bundle_enabled, 13915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_answer.get())) { 13925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; // Fails the session setup. 13935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 13945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 13955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool rejected = !options.has_data() || data_content->rejected || 13965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org !IsMediaProtocolSupported(MEDIA_TYPE_DATA, data_answer->protocol()); 13975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!rejected) { 13985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_answer->set_bandwidth(options.data_bandwidth); 13995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!AddTransportAnswer(data_content->name, *(data_transport.get()), 14005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer.get())) { 14015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 14025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 14045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // RFC 3264 14055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // The answer MUST contain the same number of m-lines as the offer. 14065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_INFO) << "Data is not supported in the answer."; 14075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->AddContent(data_content->name, data_content->type, rejected, 14095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_answer.release()); 14105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else { 14115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_INFO) << "Data is not available in the offer."; 14125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // If the offer supports BUNDLE, and we want to use it too, create a BUNDLE 14155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // group in the answer with the appropriate content names. 14165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled) { 14175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentGroup* offer_bundle = offer->GetGroupByName(GROUP_TYPE_BUNDLE); 14185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org ContentGroup answer_bundle(GROUP_TYPE_BUNDLE); 14195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ContentInfos::const_iterator content = answer->contents().begin(); 14205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content != answer->contents().end(); ++content) { 14215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!content->rejected && offer_bundle->HasContentName(content->name)) { 14225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer_bundle.AddContentName(content->name); 14235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (answer_bundle.FirstContentName()) { 14265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org answer->AddGroup(answer_bundle); 14275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Share the same ICE credentials and crypto params across all contents, 14295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // as BUNDLE requires. 14305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!UpdateTransportInfoForBundle(answer_bundle, answer.get())) { 14315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_ERROR) << "CreateAnswer failed to UpdateTransportInfoForBundle."; 14325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 14335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!UpdateCryptoParamsForBundle(answer_bundle, answer.get())) { 14365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_ERROR) << "CreateAnswer failed to UpdateCryptoParamsForBundle."; 14375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 14385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return answer.release(); 14435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 14445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid MediaSessionDescriptionFactory::GetCodecsToOffer( 14465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* current_description, 14475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org AudioCodecs* audio_codecs, 14485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org VideoCodecs* video_codecs, 14495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org DataCodecs* data_codecs) const { 14505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org UsedPayloadTypes used_pltypes; 14515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_codecs->clear(); 14525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_codecs->clear(); 14535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org data_codecs->clear(); 14545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // First - get all codecs from the current description if the media type 14575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // is used. 14585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Add them to |used_pltypes| so the payloadtype is not reused if a new media 14595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // type is added. 14605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (current_description) { 14615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const AudioContentDescription* audio = 14625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstAudioContentDescription(current_description); 14635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (audio) { 14645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *audio_codecs = audio->codecs(); 14655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_pltypes.FindAndSetIdUsed<AudioCodec>(audio_codecs); 14665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const VideoContentDescription* video = 14685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstVideoContentDescription(current_description); 14695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (video) { 14705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *video_codecs = video->codecs(); 14715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_pltypes.FindAndSetIdUsed<VideoCodec>(video_codecs); 14725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const DataContentDescription* data = 14745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstDataContentDescription(current_description); 14755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (data) { 14765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *data_codecs = data->codecs(); 14775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); 14785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 14805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Add our codecs that are not in |current_description|. 14825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org FindCodecsToOffer<AudioCodec>(audio_codecs_, audio_codecs, &used_pltypes); 14835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org FindCodecsToOffer<VideoCodec>(video_codecs_, video_codecs, &used_pltypes); 14845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org FindCodecsToOffer<DataCodec>(data_codecs_, data_codecs, &used_pltypes); 14855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 14865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgvoid MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( 14885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* current_description, 14895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions* audio_extensions, 14905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org RtpHeaderExtensions* video_extensions) const { 14915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org UsedRtpHeaderExtensionIds used_ids; 14925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org audio_extensions->clear(); 14935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org video_extensions->clear(); 14945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 14955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // First - get all extensions from the current description if the media type 14965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // is used. 14975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Add them to |used_ids| so the local ids are not reused if a new media 14985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // type is added. 14995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (current_description) { 15005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const AudioContentDescription* audio = 15015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstAudioContentDescription(current_description); 15025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (audio) { 15035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *audio_extensions = audio->rtp_header_extensions(); 15045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_ids.FindAndSetIdUsed(audio_extensions); 15055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 15065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const VideoContentDescription* video = 15075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstVideoContentDescription(current_description); 15085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (video) { 15095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *video_extensions = video->rtp_header_extensions(); 15105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org used_ids.FindAndSetIdUsed(video_extensions); 15115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 15125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 15135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // Add our default RTP header extensions that are not in 15155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org // |current_description|. 15165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org FindAndSetRtpHdrExtUsed(audio_rtp_header_extensions(), audio_extensions, 15175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org &used_ids); 15185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org FindAndSetRtpHdrExtUsed(video_rtp_header_extensions(), video_extensions, 15195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org &used_ids); 15205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool MediaSessionDescriptionFactory::AddTransportOffer( 15235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& content_name, 15245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportOptions& transport_options, 15255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* current_desc, 15265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SessionDescription* offer_desc) const { 15275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!transport_desc_factory_) 15285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 15295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportDescription* current_tdesc = 15305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetTransportDescription(content_name, current_desc); 15315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org talk_base::scoped_ptr<TransportDescription> new_tdesc( 15325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org transport_desc_factory_->CreateOffer(transport_options, current_tdesc)); 15335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org bool ret = (new_tdesc.get() != NULL && 15345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org offer_desc->AddTransportInfo(TransportInfo(content_name, *new_tdesc))); 15355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!ret) { 15365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_ERROR) 15375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org << "Failed to AddTransportOffer, content name=" << content_name; 15385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 15395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return ret; 15405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgTransportDescription* MediaSessionDescriptionFactory::CreateTransportAnswer( 15435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& content_name, 15445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* offer_desc, 15455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportOptions& transport_options, 15465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* current_desc) const { 15475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!transport_desc_factory_) 15485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 15495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportDescription* offer_tdesc = 15505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetTransportDescription(content_name, offer_desc); 15515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportDescription* current_tdesc = 15525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetTransportDescription(content_name, current_desc); 15535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return 15545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org transport_desc_factory_->CreateAnswer(offer_tdesc, transport_options, 15555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org current_tdesc); 15565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool MediaSessionDescriptionFactory::AddTransportAnswer( 15595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& content_name, 15605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const TransportDescription& transport_desc, 15615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org SessionDescription* answer_desc) const { 15625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (!answer_desc->AddTransportInfo(TransportInfo(content_name, 15635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org transport_desc))) { 15645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org LOG(LS_ERROR) 15655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org << "Failed to AddTransportAnswer, content name=" << content_name; 15665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 15675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 15685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 15695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool IsMediaContent(const ContentInfo* content) { 15725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return (content && 15735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org (content->type == NS_JINGLE_RTP || 15745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content->type == NS_JINGLE_DRAFT_SCTP)); 15755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool IsAudioContent(const ContentInfo* content) { 15785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return IsMediaContentOfType(content, MEDIA_TYPE_AUDIO); 15795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool IsVideoContent(const ContentInfo* content) { 15825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return IsMediaContentOfType(content, MEDIA_TYPE_VIDEO); 15835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool IsDataContent(const ContentInfo* content) { 15865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return IsMediaContentOfType(content, MEDIA_TYPE_DATA); 15875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 15895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const ContentInfo* GetFirstMediaContent(const ContentInfos& contents, 15905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaType media_type) { 15915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org for (ContentInfos::const_iterator content = contents.begin(); 15925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org content != contents.end(); content++) { 15935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (IsMediaContentOfType(&*content, media_type)) { 15945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return &*content; 15955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 15965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 15975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 15985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 15995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst ContentInfo* GetFirstAudioContent(const ContentInfos& contents) { 16015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return GetFirstMediaContent(contents, MEDIA_TYPE_AUDIO); 16025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst ContentInfo* GetFirstVideoContent(const ContentInfos& contents) { 16055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return GetFirstMediaContent(contents, MEDIA_TYPE_VIDEO); 16065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst ContentInfo* GetFirstDataContent(const ContentInfos& contents) { 16095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return GetFirstMediaContent(contents, MEDIA_TYPE_DATA); 16105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgstatic const ContentInfo* GetFirstMediaContent(const SessionDescription* sdesc, 16135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org MediaType media_type) { 16145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (sdesc == NULL) 16155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return NULL; 16165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return GetFirstMediaContent(sdesc->contents(), media_type); 16185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst ContentInfo* GetFirstAudioContent(const SessionDescription* sdesc) { 16215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return GetFirstMediaContent(sdesc, MEDIA_TYPE_AUDIO); 16225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst ContentInfo* GetFirstVideoContent(const SessionDescription* sdesc) { 16255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return GetFirstMediaContent(sdesc, MEDIA_TYPE_VIDEO); 16265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst ContentInfo* GetFirstDataContent(const SessionDescription* sdesc) { 16295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return GetFirstMediaContent(sdesc, MEDIA_TYPE_DATA); 16305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst MediaContentDescription* GetFirstMediaContentDescription( 16335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* sdesc, MediaType media_type) { 16345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentInfo* content = GetFirstMediaContent(sdesc, media_type); 16355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const ContentDescription* description = content ? content->description : NULL; 16365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return static_cast<const MediaContentDescription*>(description); 16375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst AudioContentDescription* GetFirstAudioContentDescription( 16405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* sdesc) { 16415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return static_cast<const AudioContentDescription*>( 16425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_AUDIO)); 16435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst VideoContentDescription* GetFirstVideoContentDescription( 16465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* sdesc) { 16475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return static_cast<const VideoContentDescription*>( 16485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); 16495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgconst DataContentDescription* GetFirstDataContentDescription( 16525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const SessionDescription* sdesc) { 16535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return static_cast<const DataContentDescription*>( 16545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); 16555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool GetMediaChannelNameFromComponent( 16585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org int component, MediaType media_type, std::string* channel_name) { 16595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (media_type == MEDIA_TYPE_AUDIO) { 16605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (component == ICE_CANDIDATE_COMPONENT_RTP) { 16615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *channel_name = GICE_CHANNEL_NAME_RTP; 16625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 16635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (component == ICE_CANDIDATE_COMPONENT_RTCP) { 16645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *channel_name = GICE_CHANNEL_NAME_RTCP; 16655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 16665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 16675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (media_type == MEDIA_TYPE_VIDEO) { 16685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (component == ICE_CANDIDATE_COMPONENT_RTP) { 16695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *channel_name = GICE_CHANNEL_NAME_VIDEO_RTP; 16705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 16715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (component == ICE_CANDIDATE_COMPONENT_RTCP) { 16725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *channel_name = GICE_CHANNEL_NAME_VIDEO_RTCP; 16735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 16745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 16755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (media_type == MEDIA_TYPE_DATA) { 16765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (component == ICE_CANDIDATE_COMPONENT_RTP) { 16775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *channel_name = GICE_CHANNEL_NAME_DATA_RTP; 16785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 16795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (component == ICE_CANDIDATE_COMPONENT_RTCP) { 16805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *channel_name = GICE_CHANNEL_NAME_DATA_RTCP; 16815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 16825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 16835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 16845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 16865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 16875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 16885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool GetMediaComponentFromChannelName( 16895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& channel_name, int* component) { 16905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (channel_name == GICE_CHANNEL_NAME_RTP || 16915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_name == GICE_CHANNEL_NAME_VIDEO_RTP || 16925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_name == GICE_CHANNEL_NAME_DATA_RTP) { 16935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *component = ICE_CANDIDATE_COMPONENT_RTP; 16945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 16955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (channel_name == GICE_CHANNEL_NAME_RTCP || 16965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_name == GICE_CHANNEL_NAME_VIDEO_RTCP || 16975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_name == GICE_CHANNEL_NAME_DATA_RTP) { 16985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *component = ICE_CANDIDATE_COMPONENT_RTCP; 16995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 17005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 17015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 17025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 17035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 17045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 17055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgbool GetMediaTypeFromChannelName( 17065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org const std::string& channel_name, MediaType* media_type) { 17075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org if (channel_name == GICE_CHANNEL_NAME_RTP || 17085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_name == GICE_CHANNEL_NAME_RTCP) { 17095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *media_type = MEDIA_TYPE_AUDIO; 17105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 17115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (channel_name == GICE_CHANNEL_NAME_VIDEO_RTP || 17125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_name == GICE_CHANNEL_NAME_VIDEO_RTCP) { 17135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *media_type = MEDIA_TYPE_VIDEO; 17145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 17155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } else if (channel_name == GICE_CHANNEL_NAME_DATA_RTP || 17165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org channel_name == GICE_CHANNEL_NAME_DATA_RTCP) { 17175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *media_type = MEDIA_TYPE_DATA; 17185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return true; 17195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org } 17205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 17215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org return false; 17225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} 17235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org 17245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org} // namespace cricket 1725