-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.cpp
67 lines (57 loc) · 1.89 KB
/
service.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
#include "udp_stream.hpp"
#include <iostream>
#include <csignal>
#include <cstring>
#define STREAM_SERVICE_NOP_DELAY 500
udpstream::Service *service = nullptr;
void signalHandler(int sigNum)
{
if (service && service->IsEnabled()) {
service->Disable();
}
}
int main(int argc, char** argv)
{
std::string address = UDP_STREAM_DEFAULT_ADDRESS, device = UDP_STREAM_DEFAULT_INPUT_DEVICE;
uint32_t samplingRate = UDP_STREAM_DEFAULT_SAMPLE_RATE;
uint16_t port = UDP_STREAM_DEFAULT_PORT;
uint8_t channels = UDP_STREAM_DEFAULT_CHANNELS, bitsPerChannel = UDP_STREAM_DEFAULT_BITS;
if (argc > 1) { address = argv[1]; }
if (argc > 2) { port = std::stoi(argv[2]); }
if (argc > 3) { device = argv[3]; }
if (argc > 4) { samplingRate = std::stoi(argv[4]); }
if (argc > 5) { channels = std::stoi(argv[5]); }
if (argc > 6) { bitsPerChannel = std::stoi(argv[6]); }
std::signal(SIGINT, signalHandler);
std::signal(SIGTERM, signalHandler);
int result = EXIT_SUCCESS;
try {
service = new udpstream::Service(
[&](uint32_t samplingRate, uint8_t channels, uint8_t bitsPerChannel, uint8_t *data, std::size_t size) {
return;
}, [&](const std::exception &exception) {
std::cout << exception.what() << std::endl;
}, [&](const std::string &text) {
std::cout << text << std::endl;
});
service->Enable(
address,
port,
device,
samplingRate,
channels,
bitsPerChannel
);
while (service->IsEnabled()) {
std::this_thread::sleep_for(std::chrono::milliseconds(STREAM_SERVICE_NOP_DELAY));
}
} catch (...) {
result = EXIT_FAILURE;
}
if (service) {
auto temp = service;
service = nullptr;
delete temp;
}
return result;
}