Skip to content

Commit

Permalink
add some signals in AVClock
Browse files Browse the repository at this point in the history
updateExternalClock can be non-inline. it is called outside and not frequently
TODO: updateExternalClock(const AVClock& clock)
  • Loading branch information
LucasWang committed Jan 23, 2013
1 parent b7b37b3 commit 5344527
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
29 changes: 25 additions & 4 deletions src/AVClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@

namespace QtAV {

AVClock::AVClock(AVClock::ClockType c)
:auto_clock(true),clock_type(c)
AVClock::AVClock(AVClock::ClockType c, QObject *parent)
:QObject(parent),auto_clock(true),clock_type(c)
{
pts_ = pts_v = delay_ = 0;
}

AVClock::AVClock(QObject *parent)
:QObject(parent),auto_clock(true),clock_type(AudioClock)
{
pts_ = pts_v = delay_ = 0;
}
Expand All @@ -47,24 +53,38 @@ bool AVClock::isClockAuto() const
return auto_clock;
}

void AVClock::updateExternalClock(qint64 msecs)
{
if (clock_type != ExternalClock)
return;
qDebug("External clock change: %f ==> %f", value(), double(msecs) * kThousandth);
pts_ = double(msecs) * kThousandth; //can not use msec/1000.
timer.restart();
}

void AVClock::start()
{
qDebug("AVClock started!!!!!!!!");
timer.start();
emit started();
}

void AVClock::pause(bool p)
{
if (clock_type != ExternalClock)
return;
if (p)
if (p) {
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
timer.invalidate();
#else
timer.stop();
#endif //QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
else
emit paused();
} else {
timer.start();
emit resumed();
}
emit paused(p);
}

void AVClock::reset()
Expand All @@ -75,6 +95,7 @@ void AVClock::reset()
#else
timer.stop();
#endif //QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
emit resetted();
}


Expand Down
26 changes: 13 additions & 13 deletions src/QtAV/AVClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef QTimer QElapsedTimer
*/
namespace QtAV {

static const double kMillionInv = 0.001;
static const double kThousandth = 0.001;

class Q_EXPORT AVClock : public QObject
{
Expand All @@ -46,7 +46,8 @@ class Q_EXPORT AVClock : public QObject
AudioClock, ExternalClock
} ClockType;

AVClock(ClockType c = AudioClock);
AVClock(ClockType c, QObject* parent = 0);
AVClock(QObject* parent = 0);
void setClockType(ClockType ct);
ClockType clockType() const;
/*
Expand All @@ -59,20 +60,27 @@ class Q_EXPORT AVClock : public QObject
inline double value() const; //the real timestamp: pts + delay
inline void updateValue(double pts); //update the pts
/*used when seeking and correcting from external*/
inline void updateExternalClock(qint64 msec);
void updateExternalClock(qint64 msecs); //(const AVClock& other): external clock outside still running

inline void updateVideoPts(double pts);
inline double videoPts() const;
inline double delay() const; //playing audio spends some time
inline void updateDelay(double delay);

signals:
void paused(bool);
void paused(); //equals to paused(true)
void resumed();//equals to paused(false)
void started();
void resetted();

public slots:
//these slots are not frequently used. so not inline
/*start the external clock*/
void start();
/*pause external clock*/
void pause(bool p);
/*reset external clock*/
/*reset(stop) external clock*/
void reset();

private:
Expand All @@ -90,7 +98,7 @@ double AVClock::value() const
return pts_ + delay_;
} else {
if (timer.isValid())
return pts_ += double(timer.restart()) * kMillionInv;
return pts_ += double(timer.restart()) * kThousandth;
else {//timer is paused
qDebug("clock is paused. return the last value %f", pts_);
return pts_;
Expand All @@ -104,14 +112,6 @@ void AVClock::updateValue(double pts)
pts_ = pts;
}

void AVClock::updateExternalClock(qint64 msec)
{
if (clock_type != ExternalClock)
return;
pts_ = double(msec) * kMillionInv; //can not use msec/1000.
timer.restart();
}

void AVClock::updateVideoPts(double pts)
{
pts_v = pts;
Expand Down

0 comments on commit 5344527

Please sign in to comment.