forked from alibaba/CicadaPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_refer_clock.cpp
93 lines (73 loc) · 2.03 KB
/
system_refer_clock.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
#define LOG_TAG "AlivcPlayerClock"
#include <utils/timer.h>
#include "system_refer_clock.h"
#include "utils/frame_work_log.h"
#define CLOCK_DEVIATION_TIME_US (100 * 1000)
namespace Cicada {
int64_t SystemReferClock::GetTime()
{
int64_t timeRet = mClock.get();
if (mGetClock && !mClock.isPaused()) {
int64_t referTime = mGetClock(mClockArg);
// if the value is valid and gap is big
if ((INT64_MIN != referTime)
&& (llabs(referTime - timeRet) > CLOCK_DEVIATION_TIME_US)) {
mClock.set(referTime);
AF_LOGW("TIMEPOS reSync time %lld to %lld\n", timeRet, referTime);
timeRet = referTime;
}
//AF_LOGD("TIMEPOS timeRet: %lld", timeRet);
}
return timeRet;
}
void SystemReferClock::reset()
{
//AF_LOGD("TIMEPOS reset reset");
mClock.reset();
mGetClock = nullptr;
mClockArg = nullptr;
}
void SystemReferClock::SetScale(float scale)
{
//AF_LOGD("TIMEPOS SetScale :%f", scale);
mClock.setSpeed(scale);
}
void SystemReferClock::pause()
{
//AF_LOGD("TIMEPOS pause");
mClock.pause();
}
void SystemReferClock::start()
{
//AF_LOGD("TIMEPOS start");
mClock.start();
}
void SystemReferClock::setTime(int64_t time)
{
//AF_LOGD("TIMEPOS setTime:%lld", time);
mClock.set(time);
}
void SystemReferClock::setReferenceClock(get_clock getClock, void *arg)
{
//AF_LOGD("TIMEPOS setReferenceClock");
mGetClock = getClock;
mClockArg = arg;
}
bool SystemReferClock::haveMaster()
{
return mGetClock != nullptr;
}
bool SystemReferClock::isMasterValid()
{
if (mGetClock) {
if (INT64_MIN != mGetClock(mClockArg)) {
return true;
}
}
return false;
}
float SystemReferClock::GetScale()
{
return mClock.getSpeed();
}
};