forked from wang-bin/QtAV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAVClock.cpp
130 lines (109 loc) · 3.04 KB
/
AVClock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2013 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/
#include <QtAV/AVClock.h>
namespace QtAV {
AVClock::AVClock(AVClock::ClockType c, QObject *parent):
QObject(parent)
, auto_clock(true)
, clock_type(c)
, mSpeed(1.0)
{
pts_ = pts_v = delay_ = 0;
}
AVClock::AVClock(QObject *parent):
QObject(parent)
, auto_clock(true)
, clock_type(AudioClock)
, mSpeed(1.0)
{
pts_ = pts_v = delay_ = 0;
}
void AVClock::setClockType(ClockType ct)
{
clock_type = ct;
}
AVClock::ClockType AVClock::clockType() const
{
return clock_type;
}
bool AVClock::isActive() const
{
return clock_type == AudioClock || timer.isValid();
}
void AVClock::setClockAuto(bool a)
{
auto_clock = a;
}
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::updateExternalClock(const AVClock &clock)
{
if (clock_type != ExternalClock)
return;
qDebug("External clock change: %f ==> %f", value(), clock.value());
pts_ = clock.value();
timer.restart();
}
void AVClock::setSpeed(qreal speed)
{
mSpeed = speed;
}
void AVClock::start()
{
qDebug("AVClock started!!!!!!!!");
timer.start();
emit started();
}
//remember last value because we don't reset pts_, pts_v, delay_
void AVClock::pause(bool p)
{
if (clock_type != ExternalClock)
return;
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)
emit paused();
} else {
timer.start();
emit resumed();
}
emit paused(p);
}
void AVClock::reset()
{
pts_ = pts_v = delay_ = 0;
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
timer.invalidate();
#else
timer.stop();
#endif //QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
emit resetted();
}
} //namespace QtAV