-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsink.cc
117 lines (95 loc) · 2.43 KB
/
sink.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
117
#include <RTPInterface.hh>
#include "sink.hh"
#include <chrono>
#include <climits>
#include <thread>
#define BUFFER_SIZE 1600000
size_t frames = 0;
size_t bytes = 0;
std::chrono::high_resolution_clock::time_point start;
std::chrono::high_resolution_clock::time_point last;
static void thread_func(void)
{
unsigned prev_frames = UINT_MAX;
// looks like the only purpose of this function is to print the results to the log
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);
}
RTPSink_::RTPSink_(UsageEnvironment& env):
MediaSink(env)
{
fReceiveBuffer = new uint8_t[BUFFER_SIZE];
}
RTPSink_::~RTPSink_()
{
}
void RTPSink_::uninit()
{
stopPlaying();
delete fReceiveBuffer;
}
void RTPSink_::afterGettingFrame(
void *clientData,
unsigned frameSize,
unsigned numTruncatedBytes,
struct timeval presentationTime,
unsigned durationInMicroseconds
)
{
((RTPSink_ *)clientData)->afterGettingFrame(
frameSize,
numTruncatedBytes,
presentationTime,
durationInMicroseconds
);
}
void RTPSink_::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);
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 RTPSink_::process()
{
}
Boolean RTPSink_::continuePlaying()
{
if (!fSource)
return False;
fSource->getNextFrame(
fReceiveBuffer,
BUFFER_SIZE,
afterGettingFrame,
this,
onSourceClosure,
this
);
return True;
}