bool SdpInfo::processSdp(const std::string& sdp) { std::string strLine; std::istringstream iss(sdp); char* line = (char*) malloc(1000); char** pieces = (char**) malloc(10000); char** cryptopiece = (char**) malloc(5000); MediaType mtype = OTHER; while (std::getline(iss, strLine)) { const char* theline = strLine.c_str(); sprintf(line, "%s\n", theline); char* isVideo = strstr(line, video); char* isAudio = strstr(line, audio); char* isGroup = strstr(line, group); char* isCand = strstr(line, cand); char* isCrypt = strstr(line, crypto); char* isUser = strstr(line, ice_user); char* isPass = strstr(line, ice_pass); char* isSsrc = strstr(line, ssrctag); char* isSAVPF = strstr(line, savpf); char* isRtpmap = strstr(line,rtpmap); char* isRtcpMuxchar = strstr(line,rtcpmux); if (isRtcpMuxchar){ isRtcpMux = true; } if (isSAVPF){ profile = SAVPF; printf("PROFILE %s (1 SAVPF)\n", isSAVPF); } if (isGroup) { isBundle = true; } if (isVideo) { mtype = VIDEO_TYPE; } if (isAudio) { mtype = AUDIO_TYPE; } if (isCand != NULL) { char *pch; pch = strtok(line, " :"); pieces[0] = pch; int i = 0; while (pch != NULL) { pch = strtok(NULL, " :"); pieces[i++] = pch; } processCandidate(pieces, i - 1, mtype); } if (isCrypt) { // printf("crypt %s\n", isCrypt ); CryptoInfo crypinfo; char *pch; pch = strtok(line, " :"); cryptopiece[0] = pch; int i = 0; while (pch != NULL) { pch = strtok(NULL, " :"); // printf("cryptopiece %i es %s\n", i, pch); cryptopiece[i++] = pch; } crypinfo.cipherSuite = std::string(cryptopiece[1]); crypinfo.keyParams = std::string(cryptopiece[3]); crypinfo.mediaType = mtype; cryptoVector_.push_back(crypinfo); // sprintf(key, "%s",cryptopiece[3]); // keys = g_slist_append(keys,key); } if (isUser) { char* pch; pch = strtok(line, " : \n"); pch = strtok(NULL, " : \n"); iceUsername_ = std::string(pch); } if (isPass) { char* pch; pch = strtok(line, " : \n"); pch = strtok(NULL, ": \n"); icePassword_ = std::string(pch); } if (isSsrc) { char* pch; pch = strtok(line, " : \n"); pch = strtok(NULL, ": \n"); if (mtype == VIDEO_TYPE) { videoSsrc = strtoul(pch, NULL, 10); } else if (mtype == AUDIO_TYPE) { audioSsrc = strtoul(pch, NULL, 10); } } // a=rtpmap:PT codec_name/clock_rate if(isRtpmap){ RtpMap theMap; char* pch; pch = strtok(line, " : / \n"); pch = strtok(NULL, " : / \n"); unsigned int PT = strtoul(pch, NULL, 10); pch = strtok(NULL, " : / \n"); std::string codecname(pch); pch = strtok(NULL, " : / \n"); unsigned int clock = strtoul(pch, NULL, 10); theMap.payloadType = PT; theMap.encodingName = codecname; theMap.clockRate = clock; theMap.mediaType = mtype; payloadVector_.push_back(theMap); } } free(line); free(pieces); free(cryptopiece); for (unsigned int i = 0; i < candidateVector_.size(); i++) { CandidateInfo& c = candidateVector_[i]; c.username = iceUsername_; c.password = icePassword_; c.isBundle = isBundle; } return true; }
bool SdpInfo::processSdp(const std::string& sdp) { APsetup = "NOT SET"; std::string strLine; std::istringstream iss(sdp); bool hasVideoSsrc = false; char line[500]; char* pieces[100]; char* cryptopiece[100]; MediaType mtype = OTHER; while (std::getline(iss, strLine)) { const char* theline = strLine.c_str(); sprintf(line, "%s\n", theline); char* isVideo = strstr(line, video); char* isAudio = strstr(line, audio); char* isGroup = strstr(line, group); char* isCand = strstr(line, cand); char* isCrypt = strstr(line, crypto); char* isUser = strstr(line, ice_user); char* isPass = strstr(line, ice_pass); char* isSsrc = strstr(line, ssrctag); char* isSAVPF = strstr(line, savpf); char* isRtpmap = strstr(line,rtpmap); char* isRtcpMuxchar = strstr(line,rtcpmux); char* isFP = strstr(line,fp); char* isSetAP = strstr(line,setactpass); if (isRtcpMuxchar){ isRtcpMux = true; } if (isSAVPF){ profile = SAVPF; ELOG_DEBUG("PROFILE %s (1 SAVPF)", isSAVPF); } if (isFP){ char *pch; pch = strtok(line, ":"); pch = strtok(NULL, " "); pch = strtok(NULL, " "); fingerprint = std::string(pch); isFingerprint = true; ELOG_DEBUG("Fingerprint %s ", fingerprint.c_str()); } if (isGroup) { isBundle = true; } if (isVideo) { mtype = VIDEO_TYPE; hasVideo = true; ELOG_DEBUG("TEST --- THIS PEER HAS VIDEO"); } if (isAudio) { mtype = AUDIO_TYPE; hasAudio = true; } if (isCand != NULL) { char *pch; pch = strtok(line, " :"); pieces[0] = pch; int i = 0; while (pch != NULL) { pch = strtok(NULL, " :"); pieces[i++] = pch; } processCandidate(pieces, i - 1, mtype); } if (isCrypt) { // ELOG_DEBUG("crypt %s", isCrypt ); CryptoInfo crypinfo; char *pch; pch = strtok(line, " :"); cryptopiece[0] = pch; int i = 0; while (pch != NULL) { pch = strtok(NULL, " :"); // ELOG_DEBUG("cryptopiece %i es %s", i, pch); cryptopiece[i++] = pch; } crypinfo.cipherSuite = std::string(cryptopiece[1]); crypinfo.keyParams = std::string(cryptopiece[3]); crypinfo.mediaType = mtype; cryptoVector_.push_back(crypinfo); // sprintf(key, "%s",cryptopiece[3]); // keys = g_slist_append(keys,key); } if (isUser) { char* pch; pch = strtok(line, " : \n"); pch = strtok(NULL, " : \n"); iceUsername_ = std::string(pch); } if (isPass) { char* pch; pch = strtok(line, " : \n"); pch = strtok(NULL, ": \n"); icePassword_ = std::string(pch); } if (isSetAP) { char* pch; pch = strtok(line, " : \n"); APsetup = std::string(pch); ELOG_DEBUG("SETUP LINE FOUNDED"); } if (isSsrc) { char* pch; pch = strtok(line, " : \n"); pch = strtok(NULL, ": \n"); if (mtype == VIDEO_TYPE) { videoSsrc = strtoul(pch, NULL, 10); hasVideoSsrc = true; } else if (mtype == AUDIO_TYPE) { audioSsrc = strtoul(pch, NULL, 10); } } // a=rtpmap:PT codec_name/clock_rate if(isRtpmap){ RtpMap theMap; char* pch; pch = strtok(line, " : / \n"); pch = strtok(NULL, " : / \n"); unsigned int PT = strtoul(pch, NULL, 10); pch = strtok(NULL, " : / \n"); std::string codecname(pch); pch = strtok(NULL, " : / \n"); unsigned int clock = strtoul(pch, NULL, 10); theMap.payloadType = PT; theMap.encodingName = codecname; theMap.clockRate = clock; theMap.mediaType = mtype; bool found = false; for (unsigned int it = 0; it < internalPayloadVector_.size(); it++) { const RtpMap& rtp = internalPayloadVector_[it]; if (rtp.encodingName == codecname && rtp.clockRate == clock) { outInPTMap[PT] = rtp.payloadType; inOutPTMap[rtp.payloadType] = PT; found = true; ELOG_DEBUG("Mapping %s/%d:%d to %s/%d:%d", codecname.c_str(), clock, PT, rtp.encodingName.c_str(), rtp.clockRate, rtp.payloadType); } } if (found) { payloadVector_.push_back(theMap); } } } for (unsigned int i = 0; i < candidateVector_.size(); i++) { CandidateInfo& c = candidateVector_[i]; c.username = iceUsername_; c.password = icePassword_; c.isBundle = isBundle; } // if (!hasVideoSsrc) // videoSsrc = 500000; return true; }
bool SdpInfo::processSdp(const std::string& sdp) { std::string line; std::istringstream iss(sdp); MediaType mtype = OTHER; while (std::getline(iss, line)) { size_t isVideo = line.find(video); size_t isAudio = line.find(audio); size_t isGroup = line.find(group); size_t isCand = line.find(cand); size_t isCrypt = line.find(crypto); size_t isUser = line.find(ice_user); size_t isPass = line.find(ice_pass); size_t isSsrc = line.find(ssrctag); size_t isSAVPF = line.find(savpf); size_t isRtpmap = line.find(rtpmap); size_t isRtcpMuxchar = line.find(rtcpmux); size_t isFP = line.find(fp); ELOG_DEBUG("current line -> %s", line.c_str()); if (isRtcpMuxchar != std::string::npos){ isRtcpMux = true; } if (isSAVPF != std::string::npos){ profile = SAVPF; ELOG_DEBUG("PROFILE %s (1 SAVPF)", line.substr(isSAVPF).c_str()); } if (isFP != std::string::npos){ std::vector<std::string> parts; // FIXME add error checking here parts = stringutil::splitOneOf(line, ":", 1); parts = stringutil::splitOneOf(parts[1], " "); fingerprint = parts[1]; isFingerprint = true; ELOG_DEBUG("Fingerprint %s ", fingerprint.c_str()); } if (isGroup != std::string::npos) { isBundle = true; } if (isVideo != std::string::npos) { mtype = VIDEO_TYPE; hasVideo = true; } if (isAudio != std::string::npos) { mtype = AUDIO_TYPE; hasAudio = true; } if (isCand != std::string::npos) { std::vector<std::string> pieces = stringutil::splitOneOf(line, " :"); processCandidate(pieces, mtype); } if (isCrypt != std::string::npos) { CryptoInfo crypinfo; std::vector<std::string> cryptopiece = stringutil::splitOneOf(line, " :"); // FIXME: add error checking here crypinfo.cipherSuite = cryptopiece[2]; crypinfo.keyParams = cryptopiece[4]; crypinfo.mediaType = mtype; cryptoVector_.push_back(crypinfo); ELOG_DEBUG("Crypto Info: %s %s %d", crypinfo.cipherSuite.c_str(), crypinfo.keyParams.c_str(), crypinfo.mediaType); } if (isUser != std::string::npos) { std::vector<std::string> parts = stringutil::splitOneOf(line, ":", 1); // FIXME add error checking iceUsername_ = parts[1]; ELOG_DEBUG("ICE username: %s", iceUsername_.c_str()); } if (isPass != std::string::npos) { std::vector<std::string> parts = stringutil::splitOneOf(line, ":", 1); // FIXME add error checking icePassword_ = parts[1]; ELOG_DEBUG("ICE password: %s", icePassword_.c_str()); } if (isSsrc != std::string::npos) { std::vector<std::string> parts = stringutil::splitOneOf(line, " :\n", 2); // FIXME add error checking if ((mtype == VIDEO_TYPE) && (videoSsrc == 0)) { videoSsrc = strtoul(parts[1].c_str(), NULL, 10); ELOG_DEBUG("video ssrc: %u", videoSsrc); } else if ((mtype == AUDIO_TYPE) && (audioSsrc == 0)) { audioSsrc = strtoul(parts[1].c_str(), NULL, 10); ELOG_DEBUG("audio ssrc: %u", audioSsrc); } } // a=rtpmap:PT codec_name/clock_rate if(isRtpmap != std::string::npos){ std::vector<std::string> parts = stringutil::splitOneOf(line, " :/\n", 4); RtpMap theMap; unsigned int PT = strtoul(parts[1].c_str(), NULL, 10); std::string codecname = parts[2]; unsigned int clock = strtoul(parts[3].c_str(), NULL, 10); theMap.payloadType = PT; theMap.encodingName = codecname; theMap.clockRate = clock; theMap.mediaType = mtype; bool found = false; for (unsigned int it = 0; it < internalPayloadVector_.size(); it++) { const RtpMap& rtp = internalPayloadVector_[it]; if (rtp.encodingName == codecname && rtp.clockRate == clock) { outInPTMap[PT] = rtp.payloadType; inOutPTMap[rtp.payloadType] = PT; found = true; ELOG_DEBUG("Mapping %s/%d:%d to %s/%d:%d", codecname.c_str(), clock, PT, rtp.encodingName.c_str(), rtp.clockRate, rtp.payloadType); } } if (found) { payloadVector_.push_back(theMap); } } } for (unsigned int i = 0; i < candidateVector_.size(); i++) { CandidateInfo& c = candidateVector_[i]; c.username = iceUsername_; c.password = icePassword_; c.isBundle = isBundle; } return true; }