live555 调优总结

来源:互联网 发布:漫画控不能连接网络 编辑:程序博客网 时间:2024/06/05 20:04

       发送优化方面,主要就是调整live555的缓冲区大小和每次发送的数据大小,众所周知,流媒体发送的是各种大小的音视频数据,而这些数据大的几百k,小的就几个字节,如果每一个零散的数据都要走一遍发送循环,对于live555这种单线程的架构来说,性能吃紧,所以做了几点调整:

MediaSink.cpp114行:unsigned OutPacketBuffer::maxSize = 30000;StreamParser.cp宏定义:#define BANK_SIZE 150000,改为2400000;MultiFramedRTPSink.cpp47行:setPacketSizes(1000, 8192);RTPInterface.cpp129行:increaseSendBufferTo(envir(), fGS->socketNum(), 512*1024);//数据累积发送,不再单独发送//注释掉332行,修改为以下://if (!sendDataOverTCP(socketNum, framingHeader, 4, False)) break;//if (!sendDataOverTCP(socketNum, packet, packetSize, True)) break;    struct iovec iov[2];    iov[0].iov_base = framingHeader;    iov[0].iov_len = 4;    iov[1].iov_base = packet;    iov[1].iov_len = packetSize;    writev(socketNum, iov, 2);


调度方面优化

MultiFramedRTPSink.cpp402 行//当前的数据缓冲区如果没有发送完成,就继续发送,不再走一遍live555的eventloop流程,提高效率!#if 0    // We have more frames left to send.  Figure out when the next frame    // is due to start playing, then make sure that we wait this long before    // sending the next packet.    struct timeval timeNow;    gettimeofday(&timeNow, NULL);    int secsDiff = fNextSendTime.tv_sec - timeNow.tv_sec;    int64_t uSecondsToGo = secsDiff*1000000 + (fNextSendTime.tv_usec - timeNow.tv_usec);    if (uSecondsToGo < 0 || secsDiff < 0) { // sanity check: Make sure that the time-to-delay is non-negative:      uSecondsToGo = 0;    }    if (uSecondsToGo > 0)        printf("uSecondsToGo: %d\n", uSecondsToGo);    // Delay this amount of time:    nextTask() = envir().taskScheduler().scheduleDelayedTask(uSecondsToGo, (TaskFunc*)sendNext, this);#else    sendNext(this);#endif

这样几点修改,大大提升了live555在网络数据发送方面的性能