Peercast收听电台的源代码流程分析
以收听JOKV-FM(TEST)为例,在YP上点击Play,则其URL地址为
peercast://pls/25838B9F1EAE27079B793C9FBA0E4156?tip=222.148.187.176:7144
case WM_COPYDATA:
{
COPYDATASTRUCT *pc = (COPYDATASTRUCT *)lParam;
LOG_DEBUG("URL request: %s",pc->lpData);
if (pc->dwData == WM_PLAYCHANNEL)
{
ChanInfo info;
servMgr->procConnectArgs((char *)pc->lpData,info);
chanMgr->findAndPlayChannel(info,false);
}
//sys->callLocalURL((const char *)pc->lpData,servMgr->serverHost.port);
}
break;
// 解析连接参数,str表示相应的频道URL,例65051E037A7A2A3433090065051E037A?tip=211.132.83.9:7144
// 从URL中解析频道的相关信息以初始化info
void ServMgr::procConnectArgs(char *str,ChanInfo &info)
{
char arg[512];
char curr[256];
//使args等于?后面的字符串,即tip=211.132.83.9:7144
char *args = strstr(str,"?");
if (args)
*args =0;
info.initNameID(str);
if (args)
{
//nextCGIarg分解字符串,把"tip"保存到curr中,"211.132.83.9"保存到arg中
while (args=nextCGIarg(args,curr,arg))
{
LOG_DEBUG("cmd: %s, arg: %s",curr,arg);
if (strcmp(curr,"sip")==0)
// sip - add network connection to client with channel
{
Host h;
h.fromStrName(arg,DEFAULT_PORT);
if (addOutgoing(h,servMgr->networkID,true))
LOG_NETWORK("Added connection: %s",arg);
}else if (strcmp(curr,"pip")==0)
// pip - add private network connection to client with channel
{
Host h;
h.fromStrName(arg,DEFAULT_PORT);
if (addOutgoing(h,info.id,true))
LOG_NETWORK("Added private connection: %s",arg);
}else if (strcmp(curr,"ip")==0)
// ip - add hit
{
Host h;
h.fromStrName(arg,DEFAULT_PORT);
ChanHit hit;
hit.init();
hit.host = h;
hit.rhost[0] = h;
hit.rhost[1].init();
hit.chanID = info.id;
hit.recv = true;
chanMgr->addHit(hit);
}else if (strcmp(curr,"tip")==0)
// tip - add tracker hit
{
Host h;
h.fromStrName(arg,DEFAULT_PORT);
chanMgr->addHit(h,info.id,true);
}
}
}
}
根据info中的信息寻找和播放频道
void ChanMgr::findAndPlayChannel(ChanInfo &info, bool keep)
{
ChanFindInfo *cfi = new ChanFindInfo;
cfi->info = info;
cfi->keep = keep;![]()
