22 #ifndef QTAV_AVCLOCK_H 23 #define QTAV_AVCLOCK_H 26 #include <QtCore/QAtomicInt> 27 #include <QtCore/QBasicTimer> 28 #include <QtCore/QObject> 29 #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) 30 #include <QtCore/QElapsedTimer> 32 #include <QtCore/QTime> 33 typedef QTime QElapsedTimer;
44 static const double kThousandth = 0.001;
56 AVClock(ClockType c, QObject* parent = 0);
58 void setClockType(ClockType ct);
59 ClockType clockType()
const;
60 bool isActive()
const;
65 void setInitialValue(
double v);
66 double initialValue()
const;
70 void setClockAuto(
bool a);
71 bool isClockAuto()
const;
73 inline double pts()
const;
79 inline double value()
const;
80 inline void updateValue(
double pts);
82 void updateExternalClock(qint64 msecs);
84 void updateExternalClock(
const AVClock& clock);
86 inline void updateVideoTime(
double pts);
87 inline double videoTime()
const;
88 inline double delay()
const;
89 inline void updateDelay(
double delay);
90 inline qreal diff()
const;
92 void setSpeed(qreal speed);
93 inline qreal speed()
const;
95 bool isPaused()
const;
104 int syncStart(
int count);
111 bool syncEndOnce(
int id);
129 virtual void timerEvent(QTimerEvent *event);
132 void restartCorrectionTimer();
133 void stopCorrectionTimer();
137 ClockType clock_type;
139 mutable double pts_v;
141 mutable QElapsedTimer timer;
151 QBasicTimer correction_schedule_timer;
153 static const int kCorrectionInterval = 1;
156 mutable int nb_restarted;
163 if (clock_type == AudioClock) {
166 return pts_ == 0 ? value0 : pts_ + delay_;
167 }
else if (clock_type == ExternalClock) {
168 if (timer.isValid()) {
170 pts_ += (double(timer.restart()) * kThousandth + avg_err)* speed();
174 return pts_ + value0;
176 if (timer.isValid()) {
178 pts_v += (double(timer.restart()) * kThousandth + avg_err)* speed();
186 if (clock_type == AudioClock)
193 if (clock_type == VideoClock)
214 return value() - videoTime();
223 #endif // QTAV_AVCLOCK_H int syncId() const
Definition: AVClock.h:105
#define Q_AV_EXPORT
Definition: QtAV_Global.h:40
ClockType
Definition: AVClock.h:50
double delay() const
Definition: AVClock.h:202
qreal speed() const
Definition: AVClock.h:217
void updateValue(double pts)
Definition: AVClock.h:184
double value() const
value the real timestamp in seconds: pts + delay
Definition: AVClock.h:161
void updateDelay(double delay)
Definition: AVClock.h:207
qreal diff() const
Definition: AVClock.h:212
AudioOutput ao; ao.setAudioFormat(fmt); ao.open(); while (has_data) { data = read_data(ao->bufferSize...
Definition: AudioDecoder.h:31
double videoTime() const
Definition: AVClock.h:197
void updateVideoTime(double pts)
Definition: AVClock.h:190