#ifndef CC_WC_TOOL_H #define CC_WC_TOOL_H #include "CCString.h" #include "CCSocket.h" namespace CTL { struct WC_SDP { String sdp; CCHostInfo host; CCMap sdpInfo; }; class WCTool { public: //-------------------------------------------------------------------------------------------------------------- static CCVector ParseSDP(const String& sdp) { CCVector lines; size_t pos = 0; while (pos < sdp.size()) { size_t end = sdp.find("\r\n", pos); if (end == String::npos) { end = sdp.size(); } lines.add_lock(sdp.substr(pos, end - pos)); pos = end + 2; } return lines; } static WC_SDP ParseSDPMap(const std::string& sdp) { CCMap sdpInfo; WC_SDP sdpInfo_t; std::istringstream iss(sdp); std::string line; while (std::getline(iss, line)) { if (line.empty()) continue; char type = line[0]; std::string value = line.substr(2); switch (type) { case 'v': sdpInfo["version"] = value; break; case 'o': sdpInfo["origin"] = value; break; case 's': sdpInfo["sessionName"] = value; break; case 't': sdpInfo["timeDescription"] = value; break; case 'a': { size_t pos = value.find(':'); if (pos != std::string::npos) { std::string key = value.substr(0, pos); std::string val = value.substr(pos + 1); sdpInfo[key] = val; } } break; case 'm': { std::istringstream mss(value); std::string mediaType; int port; std::string transport; std::string formats; mss >> mediaType >> port >> transport >> formats; sdpInfo["mediaType"] = mediaType; sdpInfo["port"] = std::to_string(port); sdpInfo["transport"] = transport; sdpInfo["formats"] = formats; } break; case 'c': { std::istringstream css(value); std::string netType, addrType, ipAddress; css >> netType >> addrType >> ipAddress; sdpInfo["netType"] = netType; sdpInfo["addrType"] = addrType; sdpInfo["ipAddress"] = ipAddress; } break; default: std::cout << "Unknown SDP line type: " << type << std::endl; break; } } sdpInfo_t.sdpInfo = sdpInfo; sdpInfo_t.sdp = sdp; return sdpInfo_t; } //-------------------------------------------------------------------------------------------------------------- private: static CCHostInfo extractConnectionInfo(CCMap sdpInfo) { const auto itPort = sdpInfo.find("port"); CCHostInfo connectionInfo{}; if (const auto itIpAddress = sdpInfo.find("ipAddress"); itPort != sdpInfo.end() && itIpAddress != sdpInfo.end()) { connectionInfo.Port = std::stoi(itPort->second); connectionInfo.IPAddress = itIpAddress->second; } else { std::cerr << "Port or IP address not found in SDP." << std::endl; } return connectionInfo; } }; } #endif