Writing a custom DirectShow RTSP / RTP Source filter - temporarily bind data coming from live sources

I am writing my own DirectShow direct source filter, which should receive RTP data from a video server and click it on a visualization tool. I wrote the CVideoPushPin class, which inherits the CSourceStream class and CVideoReceiverThread, which is the wrapper for the stream that receives RTP packets from the video server. The receiver stream essentially performs three functions:

  • receives raw RTP packets and collects some data needed for recipient reports
  • collects frames, copies them to the buffer and saves information about them in the 256 element queue, which is defined as follows:

    struct queue_elem {
       char *start; // Pointer to a frame in a buffer
       int length; // Lenght of data
       REFERENCE_TIME recvTime; // Timestamp when the frame was received (stream time)
    };
    
    struct data {
       struct queue_elem queue[QUEUE_LENGTH];
       int qWrIdx;
       int qRdIdx;
    HANDLE mutex;
    };
    
  • each received frame has a time stamp with the current flow time

    p->StreamTime(refTime);
    REFERENCE_TIME rt = refTime.GetUnits();
    

, , MediaSample FillBuffer. , . FillBuffer :

   REFERENCE_TIME thisFrameStartTime, thisFrameEndTime;
// Make sure if there are at least 4 frames in the buffer
    if(noOfFrames >= 4)
    {   
        currentQe = m_myData.queue[m_myData.qRdIdx++]; //Take current frame description     
        if(m_myData.qRdIdx >= QUEUE_LENGTH)
        {
            m_myData.qRdIdx = 0;
        }           
        nextQe = m_myData.queue[m_myData.qRdIdx]; //Take next frame description
        if(currentQe.length > 0)
        {
            memcpy(pData, currentQe.start, currentQe.length);               

             pSample->SetActualDataLength(currentQe.length);                
            CRefTime refTime;
            m_pFilter->StreamTime(refTime);
            REFERENCE_TIME rt;
            rt = refTime.GetUnits();
            pSample->GetTime(&thisFrameStartTime, &thisFrameEndTime);
            thisFrameEndTime = thisFrameStartTime + (nextQe.recvTime - currentQe.recvTime);
            pSample->SetTime(&thisFrameStartTime, &thisFrameEndTime);   
        }
    }
    else 
    {
        pSample->SetActualDataLength(0);
    }

, ( - FillBuffer ), . - , ?

+5
1

, . , , . : , , , , .

  • , . , , 300 ( + 300 ).

  • , . RTP 300 ; (rtp - rtp_at_baseline) + dshow ( .

  • , . , , RTP , RTCP RTP () NTP, NTP directshow ( NTP = dshow + 300 ).

+6

All Articles