summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-01-18 02:36:27 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-01-18 02:36:27 +0100
commitd14b4e71f80227bc193a28e0f50c6ee007f3d050 (patch)
tree701428c51be997981fcf703a2e50e723b1eed2b5
parente294715aaa4b27f7f577d72c5cd4e606dde6baee (diff)
downloadODR-AudioEnc-d14b4e71f80227bc193a28e0f50c6ee007f3d050.tar.gz
ODR-AudioEnc-d14b4e71f80227bc193a28e0f50c6ee007f3d050.tar.bz2
ODR-AudioEnc-d14b4e71f80227bc193a28e0f50c6ee007f3d050.zip
Restart only up to five times due to mem leaks
-rw-r--r--README.md7
-rw-r--r--src/odr-audioenc.cpp28
2 files changed, 29 insertions, 6 deletions
diff --git a/README.md b/README.md
index 9c6758c..73b06ed 100644
--- a/README.md
+++ b/README.md
@@ -185,9 +185,10 @@ odr-audioenc returns:
* 4 it the ZeroMQ send failed
* 5 if the input had a fault
-You can use the *-R* option to get ODR-AudioEnc to restart the input automatically after
-a fault. This does not guarantee that the odr-audioenc process will never die, and running
-it under a process supervisor is encouraged regardless of this feature being enabled or not.
+You can use the *-R* option to get ODR-AudioEnc to restart the input
+automatically up to five times after a fault. As this does not guarantee that
+the odr-audioenc process will never die, running it under a process supervisor
+is recommended regardless of this feature being enabled or not.
Known Limitations
diff --git a/src/odr-audioenc.cpp b/src/odr-audioenc.cpp
index 7ad2222..9053eec 100644
--- a/src/odr-audioenc.cpp
+++ b/src/odr-audioenc.cpp
@@ -1,6 +1,6 @@
/* ------------------------------------------------------------------
* Copyright (C) 2011 Martin Storsjo
- * Copyright (C) 2017 Matthias P. Braendli
+ * Copyright (C) 2018 Matthias P. Braendli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,6 +85,10 @@ extern "C" {
#include "libtoolame-dab/toolame.h"
}
+/* Due to memory leaks in the VLC input,
+ * we don't want to restart it endlessly. */
+constexpr int MAX_FAULTS_ALLOWED = 5;
+
using vec_u8 = std::vector<uint8_t>;
//! Enumeration of encoders we can use
@@ -218,7 +222,7 @@ void usage(const char* name)
" (default: /tmp/pad.fifo).\n"
" -l, --level Show peak audio level indication.\n"
" -s, --silence=TIMEOUT Abort encoding after TIMEOUT seconds of silence.\n"
- " -R, --restart Automatically restart input on fault.\n"
+ " -R, --restart Automatically restart input on fault, up to five times.\n"
"\n"
"Only the tcp:// zeromq transport has been tested until now,\n"
" but epgm://, pgm:// and ipc:// are also accepted\n"
@@ -460,6 +464,7 @@ int main(int argc, char *argv[])
audioenc_settings_t settings;
bool restart_on_fault = false;
+ int fault_counter = 0;
int bitrate = 0; // 0 is default
int ch=0;
@@ -1038,12 +1043,21 @@ int main(int argc, char *argv[])
fprintf(stderr, "Detected fault in input!\n");
if (restart_on_fault) {
+ fault_counter++;
+
+ if (fault_counter >= MAX_FAULTS_ALLOWED) {
+ fprintf(stderr, "Maximum number of input faults reached, aborting");
+ retval = 5;
+ break;
+ }
+
try {
input = initialise_input(settings, queue);
}
catch (const runtime_error& e) {
fprintf(stderr, "Initialising input triggered exception: %s\n", e.what());
- return 1;
+ retval = 5;
+ break;
}
continue;
@@ -1090,6 +1104,14 @@ int main(int argc, char *argv[])
fprintf(stderr, "Detected fault in input! No data in time.\n");
if (restart_on_fault) {
+ fault_counter++;
+
+ if (fault_counter >= MAX_FAULTS_ALLOWED) {
+ fprintf(stderr, "Maximum number of input faults reached, aborting");
+ retval = 5;
+ break;
+ }
+
try {
input = initialise_input(settings, queue);
}