bool FisrtLevelBuffer::writeBuffer(char* rtpPacket,int size,long * biggest_id) { //输入是RTP包的数据和长度 //缓冲区溢出,需要补充动态调整缓冲区策略 EnterCriticalSection( &CS); int emptyPos=findEmptyCell(); if(emptyPos<0) { //printf("no empty"); LeaveCriticalSection( &CS); return false; } char h264buff[1500]; int sqnum; int timeStamp; bool isstart=false; bool isend=false; int h264size; int topSqnum; unsigned short FrameType; long id; h264size=RTP2h264(rtpPacket,size,h264buff,&sqnum,&timeStamp,&isstart,&isend,&FrameType,&id,&topSqnum); //收到的RTP包转成264数据包 if(id < *biggest_id) { RetransUnit tmpUnit; tmpUnit.self_sqnum = sqnum; tmpUnit.self_timestmp = timeStamp; g_retrans_treator.retransDataArrive(tmpUnit); } else { *biggest_id = id; } m_datas[emptyPos].writeData(h264buff,h264size,sqnum,topSqnum,timeStamp,isstart,isend,FrameType,id); if(!SecondBuffer.writeData(&m_datas[emptyPos])) { //? //2级缓冲写入失败,删除回滚 //printf("roll back type:%d\n",m_datas[emptyPos].m_FrameType); m_datas[emptyPos].remove(); } LeaveCriticalSection( &CS); return true; }
bool FisrtLevelBuffer::writeRetran(char* rtpPacket,int size) { EnterCriticalSection( &CS); int emptyPos=findEmptyCell(); if(emptyPos<0) { //printf("no empty"); LeaveCriticalSection( &CS); return false; } char h264buff[1500]; memset(h264buff,0,1500); int sqnum; int timeStamp; bool isstart=false; bool isend=false; int h264size; unsigned short FrameType; long id; int topsqnum; h264size=RTP2h264(rtpPacket,size,h264buff,&sqnum,&timeStamp,&isstart,&isend,&FrameType,&id,&topsqnum); if(sqnum<0) { LeaveCriticalSection( &CS); return true; } m_datas[emptyPos].writeData(h264buff,h264size,sqnum,topsqnum,timeStamp,isstart,isend,FrameType,id); //printf("retran write second buff sqnum:%d timestmp:%d size:%d id:%ld %c\n",sqnum,timeStamp,h264size,id,h264buff[h264size-10]); if(SecondBuffer.writeRetran(&m_datas[emptyPos])==TIMEOUT) { //? //printf("retran roll back\n"); m_datas[emptyPos].remove(); //这样就可以删除掉datacell LeaveCriticalSection( &CS); return false; } LeaveCriticalSection( &CS); return true; }
//return true if puzzle is solved bool Puzzle::solved(){ return (!findEmptyCell()); }