[DBUG] ShoutCast client
void Servent::handshakeHTTP(HTTP &http, bool isHTTP)
{
LOG_DEBUG("ShoutCast client");
handshakeICY(Channel::SRC_SHOUTCAST,isHTTP);
}
void Servent::handshakeICY(Channel::SRC_TYPE type, bool isHTTP)
{
servMgr->checkFirewall();
//Channel ID用IP地址和速率来编码以避免重复
info.id = chanMgr->broadcastID;
info.id.encode(NULL,info.name.cstr(),loginMount,info.bitrate);
LOG_DEBUG("Incoming source: %s : %s",info.name.cstr(),ChanInfo::getTypeStr(info.contentType));
c = chanMgr->createChannel(info,loginMount); //创建频道
}
[DBUG] ICY icy-name:Sonic's radio
[DBUG] ICY icy-genre:Pop
[DBUG] ICY icy-url:http://www.sonic.com
[DBUG] ICY icy-irc:#shoutcast
[DBUG] ICY icy-icq:0
[DBUG] ICY icy-aim:N/A
[DBUG] ICY icy-pub:1
[DBUG] ICY icy-br:48
bool Servent::handshakeStream(ChanInfo &chanInfo)
{
HTTP http(*sock);
if (chanInfo.contentType != ChanInfo::T_MP3)
addMetadata=false;
if (addMetadata && (outputProtocol == ChanInfo::SP_HTTP)) // winamp mp3 metadata check
{
sock->writeLine(ICY_OK);
sock->writeLineF("%s %s",HTTP_HS_SERVER,PCX_AGENT);
sock->writeLineF("icy-name:%s",chanInfo.name.cstr());
sock->writeLineF("icy-br:%d",chanInfo.bitrate);
sock->writeLineF("icy-genre:%s",chanInfo.genre.cstr());
sock->writeLineF("icy-url:%s",chanInfo.url.cstr());
sock->writeLineF("icy-metaint:%d",chanMgr->icyMetaInterval);
sock->writeLineF("%s %s",PCX_HS_CHANNELID,idStr);
sock->writeLineF("%s %s",HTTP_HS_CONTENT,MIME_MP3);
}
}
在开始前我们需要一个有效的IP地址
[DBUG] Checking firewall..
void ServMgr::checkFirewall()
{
Servent::handshakeOutgoingPCP(atom,sock->host,remoteID,agent,true);
}
[DBUG] PCP outgoing waiting for OLEH..
[DBUG] Got new ip: 218.249.186.209:0
[DBUG] Firewall is set to ON
[DBUG] PCP Outgoing handshake complete.
void Servent::handshakeOutgoingPCP(AtomStream &atom, Host &rhost, GnuID &rid, String &agent, bool isTrusted)
{
LOG_DEBUG("PCP outgoing waiting for OLEH..");
LOG_DEBUG("Got new ip: %s",ipstr);
servMgr->serverHost.ip = thisHost.ip;
LOG_DEBUG("PCP Outgoing handshake complete.");
}