mirror of
http://www.pogo.org.uk/~mark/trx.git
synced 2024-11-24 11:25:06 +01:00
Add an optional daemon mode
This commit is contained in:
parent
b53aa73137
commit
e1682f4dd6
12
rx.c
12
rx.c
@ -162,9 +162,10 @@ static void usage(FILE *fd)
|
||||
fprintf(fd, " -c <n> Number of channels (default %d)\n",
|
||||
DEFAULT_CHANNELS);
|
||||
|
||||
fprintf(fd, "\nDisplay parameters:\n");
|
||||
fprintf(fd, "\nProgram parameters:\n");
|
||||
fprintf(fd, " -v <n> Verbosity level (default %d)\n",
|
||||
DEFAULT_VERBOSE);
|
||||
fprintf(fd, " -D <file> Run as a daemon, writing process ID to the given file\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -176,7 +177,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* command-line options */
|
||||
const char *device = DEFAULT_DEVICE,
|
||||
*addr = DEFAULT_ADDR;
|
||||
*addr = DEFAULT_ADDR,
|
||||
*pid = NULL;
|
||||
unsigned int buffer = DEFAULT_BUFFER,
|
||||
rate = DEFAULT_RATE,
|
||||
jitter = DEFAULT_JITTER,
|
||||
@ -216,6 +218,9 @@ int main(int argc, char *argv[])
|
||||
case 'v':
|
||||
verbose = atoi(optarg);
|
||||
break;
|
||||
case 'D':
|
||||
pid = optarg;
|
||||
break;
|
||||
default:
|
||||
usage(stderr);
|
||||
return -1;
|
||||
@ -244,6 +249,9 @@ int main(int argc, char *argv[])
|
||||
if (set_alsa_sw(snd) == -1)
|
||||
return -1;
|
||||
|
||||
if (pid)
|
||||
go_daemon(pid);
|
||||
|
||||
go_realtime();
|
||||
r = run_rx(session, decoder, snd, channels, rate);
|
||||
|
||||
|
29
sched.c
29
sched.c
@ -19,6 +19,7 @@
|
||||
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sched.h"
|
||||
|
||||
@ -49,3 +50,31 @@ int go_realtime(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int go_daemon(const char *pid_file)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if (daemon(0, 0) == -1) {
|
||||
perror("daemon");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!pid_file)
|
||||
return 0;
|
||||
|
||||
f = fopen(pid_file, "w");
|
||||
if (!f) {
|
||||
perror("fopen");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(f, "%d", getpid());
|
||||
|
||||
if (fclose(f) != 0) {
|
||||
perror("fclose");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
1
sched.h
1
sched.h
@ -21,5 +21,6 @@
|
||||
#define MISC_H
|
||||
|
||||
int go_realtime(void);
|
||||
int go_daemon(const char *pid_file);
|
||||
|
||||
#endif
|
||||
|
14
tx.c
14
tx.c
@ -149,9 +149,10 @@ static void usage(FILE *fd)
|
||||
fprintf(fd, " -b <kbps> Bitrate (approx., default %d)\n",
|
||||
DEFAULT_BITRATE);
|
||||
|
||||
fprintf(fd, "\nDisplay parameters:\n");
|
||||
fprintf(fd, "\nProgram parameters:\n");
|
||||
fprintf(fd, " -v <n> Verbosity level (default %d)\n",
|
||||
DEFAULT_VERBOSE);
|
||||
fprintf(fd, " -D <file> Run as a daemon, writing process ID to the given file\n");
|
||||
|
||||
fprintf(fd, "\nAllowed frame sizes (-f) are defined by the Opus codec. For example,\n"
|
||||
"at 48000Hz the permitted values are 120, 240, 480 or 960.\n");
|
||||
@ -168,7 +169,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* command-line options */
|
||||
const char *device = DEFAULT_DEVICE,
|
||||
*addr = DEFAULT_ADDR;
|
||||
*addr = DEFAULT_ADDR,
|
||||
*pid = NULL;
|
||||
unsigned int buffer = DEFAULT_BUFFER,
|
||||
rate = DEFAULT_RATE,
|
||||
channels = DEFAULT_CHANNELS,
|
||||
@ -181,7 +183,7 @@ int main(int argc, char *argv[])
|
||||
for (;;) {
|
||||
int c;
|
||||
|
||||
c = getopt(argc, argv, "b:c:d:f:h:m:p:r:v:");
|
||||
c = getopt(argc, argv, "b:c:d:f:h:m:p:r:v:D:");
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
@ -213,6 +215,9 @@ int main(int argc, char *argv[])
|
||||
case 'v':
|
||||
verbose = atoi(optarg);
|
||||
break;
|
||||
case 'D':
|
||||
pid = optarg;
|
||||
break;
|
||||
default:
|
||||
usage(stderr);
|
||||
return -1;
|
||||
@ -249,6 +254,9 @@ int main(int argc, char *argv[])
|
||||
if (set_alsa_sw(snd) == -1)
|
||||
return -1;
|
||||
|
||||
if (pid)
|
||||
go_daemon(pid);
|
||||
|
||||
go_realtime();
|
||||
r = run_tx(snd, channels, frame, encoder, bytes_per_frame,
|
||||
ts_per_frame, session);
|
||||
|
Loading…
Reference in New Issue
Block a user