我正在编写自定义DirectShow源推送过滤器,它应该从视频服务器接收RTP数据并将它们推送到渲染器.我写了一个CVideoPushPin类,它继承自CSourceStream和CVideoReceiverThread类,它是从视频服务器接收RTP数据包的线程的包装器.接收者线程基本上做了三件事:
组装帧,将它们复制到缓冲区并将有关它们的信息存储到256个元素队列中,其定义如下:
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;
};
Run Code Online (Sandbox Code Playgroud)每个接收到的帧都用当前流时间加上时间戳
p->StreamTime(refTime);
REFERENCE_TIME rt = refTime.GetUnits();
Run Code Online (Sandbox Code Playgroud)问题是我不知道如何在FillBuffer方法中为每个MediaSample设置时间戳.我尝试了几种方法,但播放要么停止,要么太慢.目前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 …Run Code Online (Sandbox Code Playgroud)