diff options
Diffstat (limited to 'vrplayer/demuxmedia.cpp')
-rw-r--r-- | vrplayer/demuxmedia.cpp | 126 |
1 files changed, 86 insertions, 40 deletions
diff --git a/vrplayer/demuxmedia.cpp b/vrplayer/demuxmedia.cpp index c6893ceb..a8de41a1 100644 --- a/vrplayer/demuxmedia.cpp +++ b/vrplayer/demuxmedia.cpp @@ -3,26 +3,25 @@ #include "demuxmedia.h" -DemuxMedia::DemuxMedia(QObject *parent, QQueue<MediaPacket *> *audioQueue, - QQueue<MediaPacket *> *videoQueue, void *channel, int stream_id) : - QObject(parent) +DemuxMedia::DemuxMedia(QObject *parent, QQueue<MediaPacket *> *videoQueue, + void *channel, int stream_id) : QObject(parent) { - this->audioQueue = audioQueue; - this->videoQueue = videoQueue; this->channel = channel; this->stream_id = stream_id; - this->threadsStarted = false; this->vcrFlag = 0; + this->elapsedTime = 0; + this->la_seekPos = -1; + this->isStopped = 0; + this->pausedTime = 0; + this->videoQueue = videoQueue; - playAudio = new PlayAudio(NULL, audioQueue, &sendMutex, channel, 101); - playAudioThread = new QThread(this); - connect(playAudioThread, SIGNAL(started()), playAudio, SLOT(play())); - playAudio->moveToThread(playAudioThread); - - playVideo = new PlayVideo(NULL, videoQueue, &sendMutex, channel, 101); + playVideo = new PlayVideo(NULL, videoQueue, &sendMutex, channel, 101, 24); playVideoThread = new QThread(this); connect(playVideoThread, SIGNAL(started()), playVideo, SLOT(play())); playVideo->moveToThread(playVideoThread); + + playVideoThread->start(); + } void DemuxMedia::setVcrOp(int op) @@ -30,12 +29,18 @@ void DemuxMedia::setVcrOp(int op) vcrMutex.lock(); vcrFlag = op; vcrMutex.unlock(); + if (op == VCR_STOP) + { + clear(); + } +} - if (playVideo) - playVideo->setVcrOp(op); - - if (playAudio) - playAudio->setVcrOp(op); +int DemuxMedia::clear() +{ + sendMutex.lock(); + videoQueue->clear(); + sendMutex.unlock(); + return 0; } void DemuxMedia::startDemuxing() @@ -44,9 +49,6 @@ void DemuxMedia::startDemuxing() int is_video_frame; int rv; - if ((audioQueue == NULL) || (videoQueue == NULL)) - return; - while (1) { vcrMutex.lock(); @@ -55,18 +57,40 @@ void DemuxMedia::startDemuxing() case VCR_PLAY: vcrFlag = 0; vcrMutex.unlock(); + if (pausedTime) + { + elapsedTime = av_gettime() - pausedTime; + pausedTime = 0; + } + isStopped = false; continue; break; case VCR_PAUSE: vcrMutex.unlock(); + if (!pausedTime) + { + /* save amount of video played so far */ + pausedTime = av_gettime() - elapsedTime; + } usleep(1000 * 100); + isStopped = false; continue; break; case VCR_STOP: vcrMutex.unlock(); - usleep(1000 * 100); + + if (isStopped) + { + usleep(1000 * 100); + continue; + } + elapsedTime = 0; + pausedTime = 0; + la_seekPos = -1; + xrdpvr_seek_media(0, 0); + isStopped = true; continue; break; @@ -75,14 +99,6 @@ void DemuxMedia::startDemuxing() break; } - if ((audioQueue->count() >= 20) || (videoQueue->count() >= 20)) - { - if (!threadsStarted) - startAudioVideoThreads(); - - usleep(1000 * 20); - } - mediaPkt = new MediaPacket; rv = xrdpvr_get_frame(&mediaPkt->av_pkt, &is_video_frame, @@ -91,31 +107,61 @@ void DemuxMedia::startDemuxing() { /* looks like we reached end of file */ delete mediaPkt; - playVideo->onMediaRestarted(); usleep(1000 * 100); xrdpvr_seek_media(0, 0); + this->elapsedTime = 0; continue; } if (is_video_frame) + { + sendMutex.lock(); +#if 1 videoQueue->enqueue(mediaPkt); +#else + send_video_pkt(channel, stream_id, mediaPkt->av_pkt); + delete mediaPkt; +#endif + sendMutex.unlock(); + } else - audioQueue->enqueue(mediaPkt); + { + int frame; + sendMutex.lock(); + send_audio_pkt(channel, stream_id, mediaPkt->av_pkt); + sendMutex.unlock(); + xrdpvr_read_ack(channel, &frame); + delete mediaPkt; + } + + updateMediaPos(); + if (elapsedTime == 0) + { + elapsedTime = av_gettime(); + } + + /* time elapsed in 1/100th sec units since play started */ + emit onElapsedtime((av_gettime() - elapsedTime) / 10000); + } /* end while (1) */ } -PlayVideo * DemuxMedia::getPlayVideoInstance() +void DemuxMedia::onMediaSeek(int value) { - return this->playVideo; + posMutex.lock(); + la_seekPos = value; + posMutex.unlock(); } -void DemuxMedia::startAudioVideoThreads() +void DemuxMedia::updateMediaPos() { - if (threadsStarted) - return; - - playVideoThread->start(); - playAudioThread->start(); - threadsStarted = true; + posMutex.lock(); + if (la_seekPos >= 0) + { + xrdpvr_seek_media(la_seekPos, 0); + elapsedTime = av_gettime() - la_seekPos * 1000000; + la_seekPos = -1; + } + posMutex.unlock(); } |