From d14b4e71f80227bc193a28e0f50c6ee007f3d050 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 18 Jan 2018 02:36:27 +0100 Subject: Restart only up to five times due to mem leaks --- src/odr-audioenc.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/odr-audioenc.cpp') 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; //! 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); } -- cgit v1.2.3