xrdp/vrplayer/playvideo.cpp

67 lines
1.5 KiB
C++
Raw Normal View History

#include <unistd.h>
2013-11-11 13:52:14 +04:00
#include <sys/time.h>
#include "playvideo.h"
#include <QDebug>
PlayVideo::PlayVideo(QObject *parent,
QQueue<MediaPacket *> *videoQueue,
QMutex *sendMutex,
void *channel,
2013-11-11 13:52:14 +04:00
int stream_id, int fps) :
QObject(parent)
{
this->videoQueue = videoQueue;
this->channel = channel;
this->sendMutex = sendMutex;
this->stream_id = stream_id;
2013-11-11 13:52:14 +04:00
this->fps = fps;
}
/**
******************************************************************************/
static int
get_mstime(void)
{
struct timeval tp;
gettimeofday(&tp, 0);
return (tp.tv_sec * 1000) + (tp.tv_usec / 1000);
}
void PlayVideo::play()
{
MediaPacket *pkt;
2013-11-11 13:52:14 +04:00
int now_time;
int sleep_time;
int last_display_time;
2013-11-11 13:52:14 +04:00
last_display_time = 0;
while (1)
{
2013-11-11 13:52:14 +04:00
sendMutex->lock();
if (videoQueue->isEmpty())
{
2013-11-11 13:52:14 +04:00
sendMutex->unlock();
usleep(10 * 1000);
continue;
}
pkt = videoQueue->dequeue();
send_video_pkt(channel, stream_id, pkt->av_pkt);
sendMutex->unlock();
2013-11-11 13:52:14 +04:00
now_time = get_mstime();
sleep_time = now_time - last_display_time;
if (sleep_time > (1000 / fps))
2013-01-16 22:31:11 +04:00
{
2013-11-11 13:52:14 +04:00
sleep_time = (1000 / fps);
2013-01-16 22:31:11 +04:00
}
2013-11-11 13:52:14 +04:00
if (sleep_time > 0)
2013-01-16 22:31:11 +04:00
{
2013-11-11 13:52:14 +04:00
usleep(sleep_time * 1000);
2013-01-16 22:31:11 +04:00
}
2013-11-11 13:52:14 +04:00
last_display_time = now_time;
delete pkt;
}
}