-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathav_publish_time.cpp
63 lines (56 loc) · 1.38 KB
/
av_publish_time.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
#include "av_publish_time.h"
AVPublishTime &AVPublishTime::GetInstance()
{
static AVPublishTime instance;
return instance;
}
void AVPublishTime::Rest()
{
start_time_ = GetCurrentTimeMsec();
}
int AVPublishTime::GetTimeBase()
{
//毫秒
return 1000;
}
int64_t AVPublishTime::GetVideoPts()
{
std::lock_guard<std::mutex> lck(mu_);
int64_t pts = GetCurrentTimeMsec() - start_time_;
return pts;
}
int64_t AVPublishTime::GetAudioPts()
{
std::lock_guard<std::mutex> lck(mu_);
int64_t pts = GetCurrentTimeMsec() - start_time_;
return pts;
}
AVPublishTime::AVPublishTime()
{
start_time_ = GetCurrentTimeMsec();
}
int64_t AVPublishTime::GetCurrentTimeMsec()
{
#ifdef _WIN32
struct timeval tv;
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm.tm_isdst = -1;
clock = mktime(&tm);
tv.tv_sec = clock;
tv.tv_usec = wtm.wMilliseconds * 1000;
return ((unsigned long long)tv.tv_sec * 1000 + ( long)tv.tv_usec / 1000);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return ((unsigned long long)tv.tv_sec * 1000 + (long)tv.tv_usec / 1000);
#endif
}