OutPacketBuffer::maxSize & MAX_PACKET_SIZE & maxRTCPPacketSize (live555)

重要结构体

OutPacketBuffer:RTP输出的Buffer
BufferedPacket :RTP输入的Buffer

OutPacketBuffer::maxSize

live555\liveMedia\include\MediaSink.hh
// A data structure that a sink may use for an output packet:
class OutPacketBuffer 
{
public:
    OutPacketBuffer(unsigned preferredPacketSize, 
                    unsigned maxPacketSize,
                    unsigned maxBufferSize = 0);

    // if "maxBufferSize" is >0, use it - instead of "maxSize" to compute the buffer size
    ~OutPacketBuffer();

    static unsigned maxSize;
    ...
}

OutPacketBuffer中的静态变量maxSize用于定义输出buffer的最大值,即OutPacketBuffer的最大值。
默认值为:

live555\liveMedia\MediaSink.cpp
unsigned OutPacketBuffer::maxSize = 60000; // by default

也可自己进行手动设置,使用方法:

// Increase the maximum size of video frames that we can 'proxy' without truncation.
// (Such frames are unreasonably large; the back-end servers should really not be sending frames this large!)
OutPacketBuffer::maxSize = (1024*1024); // bytes

 // Begin by setting up our usage environment:
  TaskScheduler* scheduler = BasicTaskScheduler::createNew();
  env = BasicUsageEnvironment::createNew(*scheduler);

RTP输出,判断是否超过上限:

live555\liveMedia\include\MultiFramedRTPSink.hh
class MultiFramedRTPSink: public RTPSink {
...
private:
  OutPacketBuffer* fOutBuf;
...
}

live555\liveMedia\MultiFramedRTPSink.cpp
void MultiFramedRTPSink::afterGettingFrame1(unsigned       frameSize, 
                                            unsigned       numTruncatedBytes,
                                            struct timeval presentationTime,
                                            unsigned       durationInMicroseconds) 
{
    if (fIsFirstPacket) 
    {
        // Record the fact that we're starting to play now:
        gettimeofday(&fNextSendTime, NULL);
    }

    fMostRecentPresentationTime = presentationTime;
    if (fInitialPresentationTime.tv_sec == 0 && fInitialPresentationTime.tv_usec == 0) 
    {
        fInitialPresentationTime = presentationTime;
    }    

    if (numTruncatedBytes > 0) 
    {
        unsigned const bufferSize = fOutBuf->totalBytesAvailable();

        envir() << "MultiFramedRTPSink::afterGettingFrame1(): The input frame data was too large for our buffer size ("
                << bufferSize << ").  "
                << numTruncatedBytes 
                << " bytes of trailing data was dropped!  Correct this by increasing \"OutPacketBuffer::maxSize\" to at least "
                << OutPacketBuffer::maxSize + numTruncatedBytes 
                << ", *before* creating this 'RTPSink'.  (Current value is "
                << OutPacketBuffer::maxSize 
                << ".)\n";
    }
...
}

MAX_PACKET_SIZE

MAX_PACKET_SIZE用于定义输入Buffer的上限值,即BufferedPacket的最大值.

live555\liveMedia\MultiFramedRTPSource.cpp
#define MAX_PACKET_SIZE 65536

BufferedPacket::BufferedPacket()
               : fPacketSize(MAX_PACKET_SIZE),
                 fBuf(new unsigned char[MAX_PACKET_SIZE]),
                 fNextPacket(NULL) 
{

}

在哪里判断输入数据的大小是否超过MAX_PACKET_SIZE呢?
void MultiFramedRTPSource::networkReadHandler1()

具体代码:

void MultiFramedRTPSource::networkReadHandler1() 
{
    BufferedPacket* bPacket = fPacketReadInProgress;
    if (bPacket == NULL) 
    {
        // Normal case: Get a free BufferedPacket descriptor to hold the new network packet:
        bPacket = fReorderingBuffer->getFreePacket(this);
    }

    // Read the network packet, and perform sanity checks on the RTP header:
    Boolean readSuccess = False;
    do 
    {
        struct sockaddr_in fromAddress;
        Boolean packetReadWasIncomplete = fPacketReadInProgress != NULL;
        if (!bPacket->fillInData(fRTPInterface, fromAddress, packetReadWasIncomplete)) 
        {
            if (bPacket->bytesAvailable() == 0) 
            {   // should not happen??
                envir() << "MultiFramedRTPSource internal error: Hit limit when reading incoming packet over TCP\n";
                NsLogNotifyA_Add_file(0, 0, 
                    "Live555: MultiFramedRTPSource internal error: Hit limit when reading incoming packet over TCP");
            }

            fPacketReadInProgress = NULL;

            break;
        }
        ...
    } while (0);
    if (!readSuccess) fReorderingBuffer->freePacket(bPacket);
    doGetNextFrame1();
    // If we didn't get proper data this time, we'll get another chance
}

maxRTCPPacketSize

用于定义RTCP数据包的最大值。

live555\liveMedia\RTCP.cpp
static unsigned const maxRTCPPacketSize = 2048;

在哪里判断RTCP数据包是否超过maxRTCPPacketSize呢?

live555\liveMedia\RTCP.cpp
void RTCPInstance::incomingReportHandler1() 
{
    do 
    {
        if (fNumBytesAlreadyRead >= maxRTCPPacketSize) 
        {
            envir() << "RTCPInstance error: Hit limit when reading incoming packet over TCP. Increase \"maxRTCPPacketSize:\""
                    << maxRTCPPacketSize    << "; fNumBytesAlreadyRead:"
                    << fNumBytesAlreadyRead << " >= maxRTCPPacketSize. \n";

            break;
        }
        ...
    } while (0);
}

问题1: Hit limit when reading incoming packet over TCP

长时间拉取拉取RTSP流,有时会报以下错误:

RTCPInstance error: 
Hit limit when reading incoming packet over TCP. 
Increase "maxRTCPPacketSize"

可考虑提高maxRTCPPacketSize的值,比如:

static unsigned const maxRTCPPacketSize = (512 * 1024);

References:

http://blog.csdn.net/uyuanuyuan/article/details/17919177
http://blog.csdn.net/commshare/article/details/18705339

你可能感兴趣的:(OutPacketBuffer::maxSize & MAX_PACKET_SIZE & maxRTCPPacketSize (live555))