?? rtpsources.cpp
字號(hào):
else if (tmp->rtcpport != port) collis = true; } if (collis) { // ssrc collision, ignore this packet if (handlers->handlers[RTP_EXCEPTION_SSRCCOLLISION].handler != NULL) CallSSRCCollisionHandler(tmp->ssrc,ip,false,port); return 0; } } tmp->rr.dlsr = dlsr; tmp->rr.exthighseqnum = exthighseqnum; tmp->rr.fractionlost = fraclost; tmp->rr.jitter = jitter; tmp->rr.lsr = lsr; tmp->rr.packetslost = packetslost; tmp->rr.rrreceived = true; tmp->rr.rrtime = rtpconn->GetRTCPReceiveTime(); tmp->stats.lastmsgtime = tmp->rr.rrtime.tv_sec; /* Calculate round trip time if possible */ if (lsr == 0 && dlsr == 0) return 0; getntptime(&(tmp->rr.rrtime),&lsw,&msw); lsw = ntohl(lsw); msw = ntohl(msw); ntp32 = ((msw&0xFFFF)<<16)|((lsw>>16)&0xFFFF); delay = ntp32 - tmp->rr.lsr - tmp->rr.dlsr; if (delay & (1<<31)) // if the high bit is set, the number cycled delay = 0; tmp->stats.rtt.tv_sec = (int)(((double)delay)/65536.0); tmp->stats.rtt.tv_usec = (int)(((double)(delay&0xFFFF))/(65536.0)*1000000.0); return 0;}void RTPSources::CSRCAdded(RTPuint32 csrc){ RTPSourceData *tmp; tmp = Retrieve(csrc); if (tmp != NULL) { if (!tmp->isaCSRC) { tmp->isaCSRC = true; if (tmp->hassentnewdata) numsenders--; // numsenders is to count the number of RR packets // that this source should transmit. According to // rfc1889, RRs do not have to be sent to CSRCs } }}void RTPSources::CSRCDeleted(RTPuint32 csrc){ RTPSourceData *tmp; tmp = Retrieve(csrc); if (tmp != NULL) { if (tmp->isaCSRC) { tmp->isaCSRC = false; if (tmp->hassentnewdata) numsenders++; // see remark above } }}void RTPSources::UpdateAllSources(){ int i; RTPSourceData *tmp,*tmpprev,*tmpnext; unsigned long curtime; cursource = NULL; curtablepos = RTP_SOURCETABLE_HASHSIZE; curtime = time(NULL); for (i = 0 ; i < RTP_SOURCETABLE_HASHSIZE ; i++) { tmpprev = NULL; tmp = sourcetable[i]; while (tmp != NULL) { if ((curtime - tmp->stats.lastmsgtime) >= RTP_TIMEOUTSEC) // timeout { if (handlers->handlers[RTP_EXCEPTION_SSRCTIMEOUT].handler != NULL) CallSSRCTimeoutHandler(tmp->ssrc); tmpnext = tmp->next; if (tmpprev == NULL) sourcetable[i] = tmpnext; else tmpprev->next = tmpnext; numsources--; delete tmp; tmp = tmpnext; } else // no timeout { tmp->hassentnewdata = false; tmp->stats.prevmaxseq = tmp->stats.maxseq; tmp->stats.numnewpackets = 0; tmpprev = tmp; tmp = tmp->next; } } } numsenders = 0;}RTPSourceData *RTPSources::RetrieveOrCreate(unsigned long src,double localtsunit,bool *created){ int index; bool done; RTPSourceData *tmp,*prevtmp,*nexttmp; *created = false; index = (int)(src%(unsigned long)RTP_SOURCETABLE_HASHSIZE); if ((tmp = sourcetable[index]) == NULL) { tmp = new RTPSourceData(src,localtsunit); if (tmp == NULL) return NULL; *created = true; sourcetable[index] = tmp; numsources++; return tmp; } prevtmp = NULL; done = false; while (!done && tmp != NULL) { if (tmp->ssrc < src) { prevtmp = tmp; tmp = tmp->next; } else done = true; } if (tmp == NULL) { tmp = new RTPSourceData(src,localtsunit); if (tmp == NULL) return NULL; *created = true; prevtmp->next = tmp; numsources++; } else // tmp found { if (tmp->ssrc != src) { if (prevtmp == NULL) { tmp = new RTPSourceData(src,localtsunit); if (tmp == NULL) return NULL; *created = true; tmp->next = sourcetable[index]; sourcetable[index] = tmp; numsources++; } else { nexttmp = tmp; tmp = new RTPSourceData(src,localtsunit); if (tmp == NULL) return NULL; *created = true; tmp->next = nexttmp; prevtmp->next = tmp; numsources++; } } } return tmp;}bool RTPSources::GotoFirstSender(){ bool found; curtablepos = 0; found = false; while (!found && curtablepos < RTP_SOURCETABLE_HASHSIZE) { cursource = sourcetable[curtablepos]; while (!found && cursource != NULL) { if (!cursource->isaCSRC && cursource->hassentnewdata) found = true; else cursource = cursource->next; } if (!found) curtablepos++; } if (!found) return false; return true;} bool RTPSources::GotoNextSender(){ bool found; found = false; if (cursource != NULL) cursource = cursource->next; while (!found && curtablepos < RTP_SOURCETABLE_HASHSIZE) { while (!found && cursource != NULL) { if (!cursource->isaCSRC && cursource->hassentnewdata) found = true; else cursource = cursource->next; } if (!found) { curtablepos++; if (curtablepos < RTP_SOURCETABLE_HASHSIZE) cursource = sourcetable[curtablepos]; } } if (!found) return false; return true;}bool RTPSources::GotoFirstSource(){ bool found; curtablepos = 0; found = false; while (!found && curtablepos < RTP_SOURCETABLE_HASHSIZE) { cursource = sourcetable[curtablepos]; if (cursource != NULL) found = true; else curtablepos++; } if (!found) return false; return true;}bool RTPSources::GotoNextSource(){ bool found; found = false; if (cursource != NULL) cursource = cursource->next; while (!found && curtablepos < RTP_SOURCETABLE_HASHSIZE) { if (cursource != NULL) found = true; else { curtablepos++; if (curtablepos < RTP_SOURCETABLE_HASHSIZE) cursource = sourcetable[curtablepos]; } } if (!found) return false; return true;}bool RTPSources::GotoFirstSourceWithData(){ bool found; curtablepos = 0; found = false; while (!found && curtablepos < RTP_SOURCETABLE_HASHSIZE) { cursource = sourcetable[curtablepos]; while (!found && cursource != NULL) { if (cursource->firstpacket != NULL) found = true; else cursource = cursource->next; } if (!found) curtablepos++; } if (!found) return false; return true;} bool RTPSources::GotoNextSourceWithData(){ bool found; found = false; if (cursource != NULL) cursource = cursource->next; while (!found && curtablepos < RTP_SOURCETABLE_HASHSIZE) { while (!found && cursource != NULL) { if (cursource->firstpacket != NULL) found = true; else cursource = cursource->next; } if (!found) { curtablepos++; if (curtablepos < RTP_SOURCETABLE_HASHSIZE) cursource = sourcetable[curtablepos]; } } if (!found) return false; return true;}void RTPSources::CallNewSourceHandler(RTPuint32 ssrc){ RTPExceptionHandler handler; void *usrdata; handler = handlers->handlers[RTP_EXCEPTION_NEWSOURCE].handler; usrdata = handlers->handlers[RTP_EXCEPTION_NEWSOURCE].usrdata; ex_ssrc.ssrc = ssrc; handler(RTP_EXCEPTION_NEWSOURCE,&ex_ssrc,usrdata);}void RTPSources::CallSSRCCollisionHandler(RTPuint32 ssrc,unsigned long ip,bool rtpdata,int port){ RTPExceptionHandler handler; void *usrdata; handler = handlers->handlers[RTP_EXCEPTION_SSRCCOLLISION].handler; usrdata = handlers->handlers[RTP_EXCEPTION_SSRCCOLLISION].usrdata; ex_ssrccol.ip = ip; ex_ssrccol.port = port; ex_ssrccol.rtpdata = rtpdata; ex_ssrccol.ssrc = ssrc; handler(RTP_EXCEPTION_SSRCCOLLISION,&ex_ssrccol,usrdata);}void RTPSources::CallInvalidSDESTypeHandler(RTPuint32 ssrc,int type,unsigned char *data,int datalen){ RTPExceptionHandler handler; void *usrdata; handler = handlers->handlers[RTP_EXCEPTION_INVALIDSDESTYPE].handler; usrdata = handlers->handlers[RTP_EXCEPTION_INVALIDSDESTYPE].usrdata; ex_invalsdes.datalen = datalen; ex_invalsdes.sdesdata = data; ex_invalsdes.sdestype = type; ex_invalsdes.ssrc = ssrc; handler(RTP_EXCEPTION_INVALIDSDESTYPE,&ex_invalsdes,usrdata);}void RTPSources::CallSSRCDepartureHandler(RTPuint32 ssrc){ RTPExceptionHandler handler; void *usrdata; handler = handlers->handlers[RTP_EXCEPTION_SSRCDEPARTURE].handler; usrdata = handlers->handlers[RTP_EXCEPTION_SSRCDEPARTURE].usrdata; ex_ssrc.ssrc = ssrc; handler(RTP_EXCEPTION_SSRCDEPARTURE,&ex_ssrc,usrdata);}void RTPSources::CallSSRCTimeoutHandler(RTPuint32 ssrc){ RTPExceptionHandler handler; void *usrdata; handler = handlers->handlers[RTP_EXCEPTION_SSRCTIMEOUT].handler; usrdata = handlers->handlers[RTP_EXCEPTION_SSRCTIMEOUT].usrdata; ex_ssrc.ssrc = ssrc; handler(RTP_EXCEPTION_SSRCTIMEOUT,&ex_ssrc,usrdata);}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -