Skip to content

Commit

Permalink
move waitAndCheck to AVThread for common use
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Dec 24, 2014
1 parent 4b12ba6 commit 4d13802
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 35 deletions.
24 changes: 24 additions & 0 deletions src/AVThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "AVThread.h"
#include "AVThread_p.h"
#include "QtAV/AVClock.h"
#include "QtAV/AVOutput.h"
#include "QtAV/Filter.h"
#include "output/OutputSet.h"
Expand Down Expand Up @@ -289,4 +290,27 @@ void AVThread::waitForReady()
}
}

void AVThread::waitAndCheck(ulong value, qreal pts)
{
DPTR_D(AVThread);
if (value <= 0)
return;
//qDebug("wating for %lu msecs", value);
ulong us = value * 1000UL;
static const ulong kWaitSlice = 20 * 1000UL; //20ms
while (us > kWaitSlice) {
usleep(kWaitSlice);
if (d.stop)
us = 0;
else
us -= kWaitSlice;
us = qMin(us, ulong((double)(pts - d.clock->value())*1000000.0));
processNextTask();
}
if (us > 0) {
usleep(us);
processNextTask();
}
}

} //namespace QtAV
1 change: 1 addition & 0 deletions src/AVThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public slots:
// has timeout so that the pending tasks can be processed
bool tryPause(unsigned long timeout = 100);
bool processNextTask(); //in AVThread
void waitAndCheck(ulong value, qreal pts);

DPTR_DECLARE(AVThread)

Expand Down
13 changes: 2 additions & 11 deletions src/AudioThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,12 @@ void AudioThread::run()
*TODO: 1. how to choose the value
* 2. use last delay when seeking
*/
if (qAbs(d.delay) < 2.718) {
if (qAbs(d.delay) < 2.0) {
if (d.delay < -kSyncThreshold) { //Speed up. drop frame?
//continue;
}
while (d.delay > kSyncThreshold) { //Slow down
//d.delay_cond.wait(&d.mutex, d.delay*1000); //replay may fail. why?
//qDebug("~~~~~wating for %f msecs", d.delay*1000);
usleep(kSyncThreshold * 1000000UL);
if (d.stop)
d.delay = 0;
else
d.delay -= kSyncThreshold;
}
if (d.delay > 0)
usleep(d.delay * 1000000UL);
waitAndCheck(d.delay, dts);
} else { //when to drop off?
if (d.delay > 0) {
msleep(64);
Expand Down
23 changes: 0 additions & 23 deletions src/VideoThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,6 @@ void VideoThread::setEQ(int b, int c, int s)
}
}

void VideoThread::waitAndCheck(ulong value, qreal pts)
{
DPTR_D(VideoThread);
if (value == 0)
return;
//qDebug("wating for %lu msecs", value);
ulong us = value * 1000UL;
static const ulong kWaitSlice = 20 * 1000UL; //20ms
while (us > kWaitSlice) {
usleep(kWaitSlice);
if (d.stop)
us = 0;
else
us -= kWaitSlice;
us = qMin(us, ulong((double)(pts - d.clock->value())*1000000.0));
processNextTask();
}
if (us > 0) {
usleep(us);
processNextTask();
}
}

void VideoThread::applyFilters(VideoFrame &frame)
{
DPTR_D(VideoThread);
Expand Down
1 change: 0 additions & 1 deletion src/VideoThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class VideoThread : public AVThread
public Q_SLOTS:
void addCaptureTask();
protected:
void waitAndCheck(ulong value, qreal pts);
void applyFilters(VideoFrame& frame);
// deliver video frame to video renderers. frame may be converted to a suitable format for renderer
bool deliverVideoFrame(VideoFrame &frame);
Expand Down

0 comments on commit 4d13802

Please sign in to comment.