/*
* Copyright (C) 2024 Mikhail Burakov. This file is part of streamer.
*
* streamer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* streamer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with streamer. If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include "util.h"
namespace {
volatile sig_atomic_t g_signal;
void OnSignal(int status) { g_signal = status; }
void SetupSignalHandler(int sig, void (*func)(int)) {
struct sigaction sa {};
sa.sa_handler = func;
if (sigemptyset(&sa.sa_mask) || sigaddset(&sa.sa_mask, sig)) {
throw std::system_error(errno, std::system_category(),
FROM_HERE "Failed to configure signal set");
}
if (sigaction(sig, &sa, NULL)) {
throw std::system_error(errno, std::system_category(),
FROM_HERE "Failed to set signal action");
}
}
} // namespace
int main(int argc, char* argv[]) {
try {
if (argc < 2) {
throw std::runtime_error(FROM_HERE "Usage: streamer ");
}
int port = std::atoi(argv[1]);
if (0 >= port || port > UINT16_MAX) {
throw std::runtime_error(FROM_HERE "Invalid port number");
}
pw_init(&argc, &argv);
Defer defer_pw_deinit([] { pw_deinit(); });
SetupSignalHandler(SIGINT, OnSignal);
SetupSignalHandler(SIGPIPE, SIG_IGN);
SetupSignalHandler(SIGTERM, OnSignal);
while (!g_signal) {
// BLAH
}
return EXIT_SUCCESS;
} catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
return EXIT_FAILURE;
}
}