-
Notifications
You must be signed in to change notification settings - Fork 3
/
latsink.cc
116 lines (95 loc) · 2.48 KB
/
latsink.cc
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
#include <chrono>
#include <climits>
#include <thread>
#include <RTPInterface.hh>
#include "latsink.hh"
#define BUFFER_SIZE 40 * 1000 * 1000
static size_t frames = 0;
static size_t bytes = 0;
static std::chrono::high_resolution_clock::time_point start;
static std::chrono::high_resolution_clock::time_point last;
static void thread_func(void)
{
unsigned prev_frames = UINT_MAX;
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
if (prev_frames == frames)
break;
prev_frames = frames;
}
fprintf(stderr, "%zu %zu %lu\n", bytes, frames,
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now() - start
).count()
);
exit(EXIT_FAILURE);
}
RTPLatencySink::RTPLatencySink(UsageEnvironment& env):
MediaSink(env)
{
fReceiveBuffer = new uint8_t[BUFFER_SIZE];
}
RTPLatencySink::~RTPLatencySink()
{
}
void RTPLatencySink::uninit()
{
stopPlaying();
delete fReceiveBuffer;
}
void RTPLatencySink::afterGettingFrame(
void *clientData,
unsigned frameSize,
unsigned numTruncatedBytes,
struct timeval presentationTime,
unsigned durationInMicroseconds
)
{
((RTPLatencySink *)clientData)->afterGettingFrame(
frameSize,
numTruncatedBytes,
presentationTime,
durationInMicroseconds
);
}
void RTPLatencySink::afterGettingFrame(
unsigned frameSize,
unsigned numTruncatedBytes,
struct timeval presentationTime,
unsigned durationInMicroseconds
)
{
(void)frameSize, (void)numTruncatedBytes;
(void)presentationTime, (void)durationInMicroseconds;
/* start loop that monitors activity and if there has been
* no activity for 2s (same as uvgRTP) the receiver is stopped) */
if (!frames)
(void)new std::thread(thread_func);
fprintf(stderr, "got frame\n");
if (++frames == 601) {
fprintf(stderr, "%zu %zu %lu\n", bytes, frames,
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now() - start
).count()
);
exit(EXIT_SUCCESS);
}
continuePlaying();
}
void RTPLatencySink::process()
{
}
Boolean RTPLatencySink::continuePlaying()
{
if (!fSource)
return False;
fSource->getNextFrame(
fReceiveBuffer,
BUFFER_SIZE,
afterGettingFrame,
this,
onSourceClosure,
this
);
return True;
}