diff options
-rw-r--r-- | contrib/edioutput/Transport.cpp | 16 | ||||
-rw-r--r-- | contrib/edioutput/Transport.h | 7 | ||||
-rw-r--r-- | src/AlsaInput.cpp | 12 | ||||
-rw-r--r-- | src/GSTInput.cpp | 7 | ||||
-rw-r--r-- | src/JackInput.cpp | 3 | ||||
-rw-r--r-- | src/Outputs.cpp | 5 | ||||
-rw-r--r-- | src/VLCInput.cpp | 87 | ||||
-rw-r--r-- | src/odr-audioenc.cpp | 155 |
8 files changed, 181 insertions, 111 deletions
diff --git a/contrib/edioutput/Transport.cpp b/contrib/edioutput/Transport.cpp index 6707a90..b4b6f1a 100644 --- a/contrib/edioutput/Transport.cpp +++ b/contrib/edioutput/Transport.cpp @@ -107,7 +107,7 @@ Sender::Sender(const configuration_t& conf) : make_shared<PFTSpreader>(tcp_dest->pft_settings, sender)); } else if (auto tcp_dest = dynamic_pointer_cast<edi::tcp_client_t>(edi_dest)) { - auto sender = make_shared<tcp_send_client_t>(tcp_dest->dest_addr, tcp_dest->dest_port); + auto sender = make_shared<tcp_send_client_t>(tcp_dest->dest_addr, tcp_dest->dest_port, m_conf.verbose); m_pft_spreaders.emplace_back( make_shared<PFTSpreader>(tcp_dest->pft_settings, sender)); } @@ -207,7 +207,13 @@ void Sender::tcp_dispatcher_t::send_packet(const std::vector<uint8_t> &frame) void Sender::tcp_send_client_t::send_packet(const std::vector<uint8_t> &frame) { - sock.sendall(frame); + const auto error_stats = sock.sendall(frame); + + if (verbose and error_stats.has_seen_new_errors) { + etiLog.level(warn) << "TCP output " << dest_addr << ":" << dest_port + << " has " << error_stats.num_reconnects + << " reconnects: most recent error: " << error_stats.last_error; + } } Sender::udp_sender_t::udp_sender_t(std::string dest_addr, @@ -229,7 +235,11 @@ Sender::tcp_dispatcher_t::tcp_dispatcher_t(uint16_t listen_port, } Sender::tcp_send_client_t::tcp_send_client_t(const std::string &dest_addr, - uint16_t dest_port) : + uint16_t dest_port, + bool verbose) : + dest_addr(dest_addr), + dest_port(dest_port), + verbose(verbose), sock(dest_addr, dest_port) { } diff --git a/contrib/edioutput/Transport.h b/contrib/edioutput/Transport.h index b8a9008..96784c0 100644 --- a/contrib/edioutput/Transport.h +++ b/contrib/edioutput/Transport.h @@ -118,8 +118,13 @@ class Sender { struct tcp_send_client_t : public i_sender { tcp_send_client_t( const std::string& dest_addr, - uint16_t dest_port); + uint16_t dest_port, + bool verbose); + std::string dest_addr; + uint16_t dest_port; + bool verbose; + size_t m_num_reconnects_prev = 0; Socket::TCPSendClient sock; virtual void send_packet(const std::vector<uint8_t> &frame) override; }; diff --git a/src/AlsaInput.cpp b/src/AlsaInput.cpp index 442304c..7d14eb0 100644 --- a/src/AlsaInput.cpp +++ b/src/AlsaInput.cpp @@ -21,6 +21,7 @@ #if HAVE_ALSA #include "AlsaInput.h" +#include "Log.h" #include <cstdio> #include <stdexcept> #include <string> @@ -51,7 +52,7 @@ void AlsaInput::m_init_alsa() int err; snd_pcm_hw_params_t *hw_params; - fprintf(stderr, "Initialising ALSA...\n"); + etiLog.level(info) << "Initialising ALSA..."; const int open_mode = 0; @@ -104,7 +105,7 @@ void AlsaInput::m_init_alsa() alsa_strerror(err) + ")"); } - fprintf(stderr, "ALSA init done.\n"); + etiLog.level(info) << "ALSA init done."; } ssize_t AlsaInput::m_read(uint8_t* buf, snd_pcm_uframes_t length) @@ -115,11 +116,10 @@ ssize_t AlsaInput::m_read(uint8_t* buf, snd_pcm_uframes_t length) if (err != (ssize_t)length) { if (err < 0) { - fprintf (stderr, "read from audio interface failed (%s)\n", - snd_strerror(err)); + etiLog.level(error) << "read from audio interface failed (" << snd_strerror(err) << ")"; } else { - fprintf(stderr, "short alsa read: %d\n", err); + etiLog.level(warn) << "short alsa read: " << err; } } @@ -141,7 +141,7 @@ AlsaInputThreaded::~AlsaInputThreaded() void AlsaInputThreaded::prepare() { if (m_fault) { - fprintf(stderr, "Cannot start alsa input. Fault detected previsouly!\n"); + etiLog.level(error) << "Cannot start alsa input. Fault detected previously!"; } else { m_init_alsa(); diff --git a/src/GSTInput.cpp b/src/GSTInput.cpp index af27db1..811c13d 100644 --- a/src/GSTInput.cpp +++ b/src/GSTInput.cpp @@ -26,6 +26,7 @@ #include <cstring> #include "GSTInput.h" +#include "Log.h" #include "config.h" @@ -59,8 +60,8 @@ static void error_cb(GstBus *bus, GstMessage *msg, GSTData *data) /* Print error details on the screen */ gst_message_parse_error(msg, &err, &debug_info); - g_printerr("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message); - g_printerr("Debugging information: %s\n", debug_info ? debug_info : "none"); + etiLog.level(error) << "Error received from element " << GST_OBJECT_NAME (msg->src) << ": " << err->message; + etiLog.level(error) << "Debugging information: " << (debug_info ? debug_info : "none"); g_clear_error(&err); g_free(debug_info); } @@ -282,7 +283,7 @@ void GSTInput::process() { GError *err = nullptr; gst_message_parse_error(msg, &err, nullptr); - fprintf(stderr, "GST error: %s\n", err->message); + etiLog.level(error) << "GST error: " << err->message; g_error_free(err); m_fault = true; break; diff --git a/src/JackInput.cpp b/src/JackInput.cpp index 4d9a530..f5a63b5 100644 --- a/src/JackInput.cpp +++ b/src/JackInput.cpp @@ -28,6 +28,7 @@ extern "C" { } #include "JackInput.h" +#include "Log.h" #include <sys/time.h> using namespace std; @@ -60,7 +61,7 @@ void JackInput::prepare() } if (status & JackServerStarted) { - fprintf(stderr, "JACK server started\n"); + etiLog.level(info) << "JACK server started"; } if (status & JackNameNotUnique) { diff --git a/src/Outputs.cpp b/src/Outputs.cpp index 3f78501..91f9181 100644 --- a/src/Outputs.cpp +++ b/src/Outputs.cpp @@ -18,6 +18,7 @@ */ #include "Outputs.h" +#include "Log.h" #include <chrono> #include <string> #include <stdexcept> @@ -75,7 +76,7 @@ ZMQ::~ZMQ() {} void ZMQ::connect(const char *uri, const char *keyfile) { if (keyfile) { - fprintf(stderr, "Enabling encryption\n"); + etiLog.level(info) << "Enabling encryption"; int rc = readkey(keyfile, m_secretkey); if (rc) { @@ -130,7 +131,7 @@ bool ZMQ::write_frame(const uint8_t *buf, size_t len) zmq::send_flags::dontwait); } catch (zmq::error_t& e) { - fprintf(stderr, "ZeroMQ send error !\n"); + etiLog.level(error) << "ZeroMQ send error !"; return false; } diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index ef4cfc4..e3e815e 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -23,8 +23,10 @@ #include <chrono> #include <algorithm> #include <functional> +#include <cstdarg> #include "VLCInput.h" +#include "Log.h" #include "config.h" @@ -122,6 +124,61 @@ void handleVLCExit(void* opaque) ((VLCInput*)opaque)->exit_cb(); } +/*! VLC Log callback to route VLC messages through etiLog */ +void handleVLCLog(void* data, int level, const libvlc_log_t* ctx, const char* fmt, va_list args) +{ + // Map VLC log levels to etiLog levels + log_level_t etiLogLevel; + switch (level) { + case LIBVLC_DEBUG: + etiLogLevel = debug; + break; + case LIBVLC_NOTICE: + etiLogLevel = info; + break; + case LIBVLC_WARNING: + etiLogLevel = warn; + break; + case LIBVLC_ERROR: + etiLogLevel = error; + break; + default: + etiLogLevel = debug; // Default to debug for unknown levels + break; + } + + // Format the message using vsnprintf + char buffer[1024]; + int ret = vsnprintf(buffer, sizeof(buffer), fmt, args); + + if (ret > 0) { + // Get module and object information from context if available + const char* module = nullptr; + const char* file = nullptr; + unsigned line = 0; + const char* object_type = nullptr; + const char* header = nullptr; + uintptr_t object_id = 0; + + libvlc_log_get_context(ctx, &module, &file, &line); + libvlc_log_get_object(ctx, &object_type, &header, &object_id); + + // Use module name if available, otherwise use object type + const char* identifier = nullptr; + if (module && strlen(module) > 0) { + identifier = module; + } else if (object_type && strlen(object_type) > 0) { + identifier = object_type; + } + + if (identifier) { + etiLog.level(etiLogLevel) << "VLC [" << identifier << "] " << buffer; + } else { + etiLog.level(etiLogLevel) << "VLC " << buffer; + } + } +} + VLCInput::~VLCInput() { m_running = false; @@ -142,20 +199,20 @@ void VLCInput::prepare() throw runtime_error("Cannot start VLC input. Fault detected previously!"); } - fprintf(stderr, "Initialising VLC...\n"); + etiLog.level(info) << "Initialising VLC..."; long long int handleStream_address; long long int prepareRender_address; switch (check_vlc_uses_size_t()) { case vlc_data_type_e::vlc_uses_unsigned_int: - fprintf(stderr, "You are using VLC with unsigned int size callbacks\n"); + etiLog.level(info) << "You are using VLC with unsigned int size callbacks"; handleStream_address = (long long int)(intptr_t)(void*)&handleStream; prepareRender_address = (long long int)(intptr_t)(void*)&prepareRender; break; case vlc_data_type_e::vlc_uses_size_t: - fprintf(stderr, "You are using VLC with size_t size callbacks\n"); + etiLog.level(info) << "You are using VLC with size_t size callbacks"; handleStream_address = (long long int)(intptr_t)(void*)&handleStream_size_t; prepareRender_address = (long long int)(intptr_t)(void*)&prepareRender_size_t; @@ -179,9 +236,9 @@ void VLCInput::prepare() back_inserter(vlc_args)); if (m_verbosity) { - fprintf(stderr, "Initialising VLC with options:\n"); + etiLog.level(info) << "Initialising VLC with options:"; for (const auto& arg : vlc_args) { - fprintf(stderr, " %s\n", arg.c_str()); + etiLog.level(info) << " " << arg; } } @@ -197,6 +254,9 @@ void VLCInput::prepare() throw runtime_error("VLC initialisation failed"); } + // Set up VLC log callback to route messages through etiLog + libvlc_log_set(m_vlc, handleVLCLog, this); + libvlc_set_exit_handler(m_vlc, handleVLCExit, this); // Load the media @@ -224,7 +284,7 @@ void VLCInput::prepare() (long long int)(intptr_t)this); if (m_verbosity) { - fprintf(stderr, "Setting VLC media option: %s\n", smem_options); + etiLog.level(debug) << "Setting VLC media option: " << smem_options; } libvlc_media_add_option(m, smem_options); @@ -296,14 +356,14 @@ void VLCInput::exit_cb() if (m_running) { std::lock_guard<std::mutex> lock(m_queue_mutex); - fprintf(stderr, "VLC exit, restarting...\n"); + etiLog.level(warn) << "VLC exit, restarting..."; cleanup(); m_current_buf.clear(); prepare(); } else { - fprintf(stderr, "VLC exit.\n"); + etiLog.level(info) << "VLC exit."; } } @@ -342,8 +402,7 @@ void VLCInput::postRender_cb(unsigned int channels, size_t size) } } else { - fprintf(stderr, "Got invalid number of channels back from VLC! " - "requested: %d, got %d\n", m_channels, channels); + etiLog.level(error) << "Got invalid number of channels back from VLC! requested: " << m_channels << ", got " << channels; m_running = false; m_fault = true; } @@ -388,7 +447,7 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) libvlc_media_t *media = libvlc_media_player_get_media(m_mp); if (!media) { - fprintf(stderr, "VLC no media\n"); + etiLog.level(error) << "VLC no media"; err = -1; break; } @@ -397,7 +456,7 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) if (!(st == libvlc_Opening || st == libvlc_Buffering || st == libvlc_Playing) ) { - fprintf(stderr, "VLC state is %d\n", st); + etiLog.level(warn) << "VLC state is " << st; err = -1; break; } @@ -505,8 +564,8 @@ vlc_data_type_e check_vlc_uses_size_t() } } - fprintf(stderr, "Error detecting VLC version!\n"); - fprintf(stderr, " you are using %s\n", libvlc_get_version()); + etiLog.level(error) << "Error detecting VLC version!"; + etiLog.level(error) << " you are using " << libvlc_get_version(); throw runtime_error("Cannot identify VLC datatype!"); } diff --git a/src/odr-audioenc.cpp b/src/odr-audioenc.cpp index de3843c..98e9c34 100644 --- a/src/odr-audioenc.cpp +++ b/src/odr-audioenc.cpp @@ -239,13 +239,13 @@ static int prepare_aac_encoder( case 1: mode = MODE_1; break; case 2: mode = MODE_2; break; default: - fprintf(stderr, "Unsupported channels number %d\n", channels); + etiLog.level(error) << "Unsupported channels number " << channels; return 1; } if (aacEncOpen(encoder, 0x01|0x02|0x04, channels) != AACENC_OK) { - fprintf(stderr, "Unable to open encoder\n"); + etiLog.level(error) << "Unable to open encoder"; return 1; } @@ -263,35 +263,34 @@ static int prepare_aac_encoder( } } - fprintf(stderr, "Using %d subchannels. AAC type: %s%s%s. channels=%d, sample_rate=%d\n", - subchannel_index, - *aot == AOT_DABPLUS_PS ? "HE-AAC v2" : "", - *aot == AOT_DABPLUS_SBR ? "HE-AAC" : "", - *aot == AOT_DABPLUS_AAC_LC ? "AAC-LC" : "", - channels, sample_rate); + etiLog.level(info) << "Using " << subchannel_index << " subchannels. AAC type: " + << (*aot == AOT_DABPLUS_PS ? "HE-AAC v2" : "") + << (*aot == AOT_DABPLUS_SBR ? "HE-AAC" : "") + << (*aot == AOT_DABPLUS_AAC_LC ? "AAC-LC" : "") + << ". channels=" << channels << ", sample_rate=" << sample_rate; if (aacEncoder_SetParam(*encoder, AACENC_AOT, *aot) != AACENC_OK) { - fprintf(stderr, "Unable to set the AOT\n"); + etiLog.level(error) << "Unable to set the AOT"; return 1; } if (aacEncoder_SetParam(*encoder, AACENC_SAMPLERATE, sample_rate) != AACENC_OK) { - fprintf(stderr, "Unable to set the sample rate\n"); + etiLog.level(error) << "Unable to set the sample rate"; return 1; } if (aacEncoder_SetParam(*encoder, AACENC_CHANNELMODE, mode) != AACENC_OK) { - fprintf(stderr, "Unable to set the channel mode\n"); + etiLog.level(error) << "Unable to set the channel mode"; return 1; } if (aacEncoder_SetParam(*encoder, AACENC_CHANNELORDER, 1) != AACENC_OK) { - fprintf(stderr, "Unable to set the wav channel order\n"); + etiLog.level(error) << "Unable to set the wav channel order"; return 1; } if (aacEncoder_SetParam(*encoder, AACENC_GRANULE_LENGTH, 960) != AACENC_OK) { - fprintf(stderr, "Unable to set the granule length\n"); + etiLog.level(error) << "Unable to set the granule length"; return 1; } if (aacEncoder_SetParam(*encoder, AACENC_TRANSMUX, TT_DABPLUS) != AACENC_OK) { - fprintf(stderr, "Unable to set the RAW transmux\n"); + etiLog.level(error) << "Unable to set the RAW transmux"; return 1; } @@ -302,33 +301,33 @@ static int prepare_aac_encoder( }*/ - fprintf(stderr, "AAC bitrate set to: %d\n", subchannel_index*8000); + etiLog.level(info) << "AAC bitrate set to: " << (subchannel_index*8000); if (aacEncoder_SetParam(*encoder, AACENC_BITRATE, subchannel_index*8000) != AACENC_OK) { - fprintf(stderr, "Unable to set the bitrate\n"); + etiLog.level(error) << "Unable to set the bitrate"; return 1; } if (aacEncoder_SetParam(*encoder, AACENC_AFTERBURNER, afterburner) != AACENC_OK) { - fprintf(stderr, "Unable to set the afterburner mode\n"); + etiLog.level(error) << "Unable to set the afterburner mode"; return 1; } if (!afterburner) { - fprintf(stderr, "Warning: Afterburned disabled!\n"); + etiLog.level(warn) << "Warning: Afterburner disabled!"; } if (bandwidth > 0) { - fprintf(stderr, "Setting bandwidth is %d\n", bandwidth); + etiLog.level(info) << "Setting bandwidth to " << bandwidth; if (aacEncoder_SetParam(*encoder, AACENC_BANDWIDTH, bandwidth) != AACENC_OK) { - fprintf(stderr, "Unable to set bandwidth mode\n"); + etiLog.level(error) << "Unable to set bandwidth mode"; return 1; } } if (aacEncEncode(*encoder, nullptr, nullptr, nullptr, nullptr) != AACENC_OK) { - fprintf(stderr, "Unable to initialize the encoder\n"); + etiLog.level(error) << "Unable to initialize the encoder"; return 1; } const uint32_t bw = aacEncoder_GetParam(*encoder, AACENC_BANDWIDTH); - fprintf(stderr, "Bandwidth is %d\n", bw); + etiLog.level(info) << "Bandwidth is " << bw; return 0; } @@ -464,7 +463,7 @@ public: vector<string> edi_output_uris; void *rs_handler = nullptr; - AACENC_InfoStruct info = { 0 }; + AACENC_InfoStruct aac_info = { 0 }; int aot = AOT_NONE; string decode_wavfilename; @@ -529,11 +528,11 @@ int AudioEnc::run() #endif if (num_inputs == 0) { - fprintf(stderr, "No input defined!\n"); + etiLog.level(error) << "No input defined!"; return 1; } else if (num_inputs > 1) { - fprintf(stderr, "You must define only one possible input, not several!\n"); + etiLog.level(error) << "You must define only one possible input, not several!"; return 1; } @@ -545,13 +544,12 @@ int AudioEnc::run() int subchannel_index = bitrate / 8; if (subchannel_index < 1 || subchannel_index > 24) { - fprintf(stderr, "Bad subchannel index: %d, must be between 1 and 24. Try other bitrate.\n", - subchannel_index); + etiLog.level(error) << "Bad subchannel index: " << subchannel_index << ", must be between 1 and 24. Try other bitrate."; return 1; } if ( ! (sample_rate == 32000 || sample_rate == 48000)) { - fprintf(stderr, "Invalid sample rate. Possible values are: 32000, 48000.\n"); + etiLog.level(error) << "Invalid sample rate. Possible values are: 32000, 48000."; return 1; } } @@ -561,25 +559,25 @@ int AudioEnc::run() } if ( ! (sample_rate == 24000 || sample_rate == 48000)) { - fprintf(stderr, "Invalid sample rate. Possible values are: 24000, 48000.\n"); + etiLog.level(error) << "Invalid sample rate. Possible values are: 24000, 48000."; return 1; } } if (padlen < 0 or padlen > 255) { - fprintf(stderr, "Invalid PAD length specified\n"); + etiLog.level(error) << "Invalid PAD length specified"; return 1; } if (output_uris.empty() and edi_output_uris.empty()) { - fprintf(stderr, "No output defined\n"); + etiLog.level(error) << "No output defined"; return 1; } for (const auto& uri : output_uris) { if (uri == "-") { if (file_output) { - fprintf(stderr, "You can't write to more than one file!\n"); + etiLog.level(error) << "You can't write to more than one file!"; return 1; } file_output = make_shared<Output::File>(stdout); @@ -597,7 +595,7 @@ int AudioEnc::run() } else { // We assume it's a file name if (file_output) { - fprintf(stderr, "You can't write to more than one file!\n"); + etiLog.level(error) << "You can't write to more than one file!"; return 1; } file_output = make_shared<Output::File>(uri.c_str()); @@ -624,11 +622,11 @@ int AudioEnc::run() } } else { - fprintf(stderr, "Invalid EDI URL host!\n"); + etiLog.level(error) << "Invalid EDI URL host!"; } } else { - fprintf(stderr, "Invalid EDI protocol!\n"); + etiLog.level(error) << "Invalid EDI protocol!"; } } @@ -653,10 +651,10 @@ int AudioEnc::run() if (padlen != 0 and not pad_ident.empty()) { pad_intf.open(pad_ident); - fprintf(stderr, "PAD socket opened\n"); + etiLog.level(info) << "PAD socket opened"; } else { - fprintf(stderr, "PAD disabled because neither PAD length nor PAD identifier given\n"); + etiLog.level(info) << "PAD disabled because neither PAD length nor PAD identifier given"; } vec_u8 input_buf; @@ -665,20 +663,18 @@ int AudioEnc::run() int subchannel_index = bitrate / 8; if (prepare_aac_encoder(&encoder, subchannel_index, channels, sample_rate, afterburner, bandwidth, &aot) != 0) { - fprintf(stderr, "Encoder preparation failed\n"); + etiLog.level(error) << "Encoder preparation failed"; return 1; } - if (aacEncInfo(encoder, &info) != AACENC_OK) { - fprintf(stderr, "Unable to get the encoder info\n"); + if (aacEncInfo(encoder, &aac_info) != AACENC_OK) { + etiLog.level(error) << "Unable to get the encoder info"; return 1; } // Each DAB+ frame will need input_size audio bytes - const int input_size = channels * BYTES_PER_SAMPLE * info.frameLength; - fprintf(stderr, "DAB+ Encoding: framelen=%d (%dB)\n", - info.frameLength, - input_size); + const int input_size = channels * BYTES_PER_SAMPLE * aac_info.frameLength; + etiLog.level(info) << "DAB+ Encoding: framelen=" << aac_info.frameLength << " (" << input_size << "B)"; input_buf.resize(input_size); @@ -705,8 +701,7 @@ int AudioEnc::run() dab_channel_mode = 'm'; // Default to mono } else { - fprintf(stderr, "Unsupported channels number %d\n", - channels); + etiLog.level(error) << "Unsupported channels number " << channels; return 1; } } @@ -725,14 +720,14 @@ int AudioEnc::run() } if (err) { - fprintf(stderr, "libtoolame-dab init failed: %d\n", err); + etiLog.level(error) << "libtoolame-dab init failed: " << err; return err; } input_buf.resize(channels * 1152 * BYTES_PER_SAMPLE); if (not decode_wavfilename.empty()) { - fprintf(stderr, "--decode not supported for DAB\n"); + etiLog.level(error) << "--decode not supported for DAB"; return 1; } } @@ -744,7 +739,7 @@ int AudioEnc::run() stats_publisher.reset(s); } catch (const runtime_error& e) { - fprintf(stderr, "Failed to initialise Stats Publisher: %s", e.what()); + etiLog.level(error) << "Failed to initialise Stats Publisher: " << e.what(); if (s != nullptr) { delete s; } @@ -780,7 +775,7 @@ int AudioEnc::run() input = initialise_input(); } catch (const runtime_error& e) { - fprintf(stderr, "Initialising input triggered exception: %s\n", e.what()); + etiLog.level(error) << "Initialising input triggered exception: " << e.what(); return 1; } @@ -799,18 +794,18 @@ int AudioEnc::run() case encoder_selection_t::toolame_dab: outbuf_size = 4092; outbuf.resize(outbuf_size); - fprintf(stderr, "Setting outbuf size to %zu\n", outbuf.size()); + etiLog.level(info) << "Setting outbuf size to " << outbuf.size(); break; } vector<uint8_t> pad_buf(padlen + 1); if (restart_on_fault) { - fprintf(stderr, "Autorestart has been deprecated and will be removed in the future!\n"); + etiLog.level(warn) << "Autorestart has been deprecated and will be removed in the future!"; this_thread::sleep_for(chrono::seconds(2)); } - fprintf(stderr, "Starting encoding\n"); + etiLog.level(info) << "Starting encoding"; int retval = 0; int send_error_count = 0; @@ -849,7 +844,7 @@ int AudioEnc::run() copy(pad_data.begin(), pad_data.end(), pad_buf.begin()); } else { - fprintf(stderr, "Incorrect PAD length received: %zu expected %d\n", pad_data.size(), padlen + 1); + etiLog.level(error) << "Incorrect PAD length received: " << pad_data.size() << " expected " << (padlen + 1); break; } } @@ -876,13 +871,13 @@ int AudioEnc::run() */ if (input->fault_detected()) { - fprintf(stderr, "Detected fault in input!\n"); + etiLog.level(warn) << "Detected fault in input!"; if (restart_on_fault) { fault_counter++; if (fault_counter >= MAX_FAULTS_ALLOWED) { - fprintf(stderr, "Maximum number of input faults reached, aborting"); + etiLog.level(error) << "Maximum number of input faults reached, aborting"; retval = 5; break; } @@ -891,7 +886,7 @@ int AudioEnc::run() input = initialise_input(); } catch (const runtime_error& e) { - fprintf(stderr, "Initialising input triggered exception: %s\n", e.what()); + etiLog.level(error) << "Initialising input triggered exception: " << e.what(); retval = 5; break; } @@ -905,7 +900,7 @@ int AudioEnc::run() } if (not input->read_source(input_buf.size())) { - fprintf(stderr, "End of input reached\n"); + etiLog.level(info) << "End of input reached"; retval = 0; break; } @@ -929,7 +924,7 @@ int AudioEnc::run() const auto elapsed = chrono::duration_cast<chrono::seconds>( now - timepoint_last_received_sample); if (elapsed.count() > 60) { - fprintf(stderr, "Underruns for 60s, aborting!\n"); + etiLog.level(error) << "Underruns for 60s, aborting!"; return 1; } } @@ -960,13 +955,13 @@ int AudioEnc::run() if (bytes_from_queue < read_bytes) { // queue timeout occurred - fprintf(stderr, "Detected fault in input! No data in time.\n"); + etiLog.level(warn) << "Detected fault in input! No data in time."; if (restart_on_fault) { fault_counter++; if (fault_counter >= MAX_FAULTS_ALLOWED) { - fprintf(stderr, "Maximum number of input faults reached, aborting"); + etiLog.level(error) << "Maximum number of input faults reached, aborting"; retval = 5; break; } @@ -975,7 +970,7 @@ int AudioEnc::run() input = initialise_input(); } catch (const runtime_error& e) { - fprintf(stderr, "Initialising input triggered exception: %s\n", e.what()); + etiLog.level(error) << "Initialising input triggered exception: " << e.what(); return 1; } @@ -1014,7 +1009,7 @@ int AudioEnc::run() bool success = write_icy_to_file(text, icytext_file, icytext_dlplus); if (not success) { - fprintf(stderr, "Failed to write ICY Text\n"); + etiLog.level(warn) << "Failed to write ICY Text"; } } @@ -1071,8 +1066,7 @@ int AudioEnc::run() measured_silence_ms += frame_time_msec; if (measured_silence_ms > 1000*silence_timeout) { - fprintf(stderr, "Silence detected for %d seconds, aborting.\n", - silence_timeout); + etiLog.level(info) << "Silence detected for " << silence_timeout << " seconds, aborting."; retval = 2; break; } @@ -1124,10 +1118,10 @@ int AudioEnc::run() if ((err = aacEncEncode(encoder, &in_buf, &out_buf, &in_args, &out_args)) != AACENC_OK) { if (err == AACENC_ENCODE_EOF) { - fprintf(stderr, "encoder error: EOF reached\n"); + etiLog.level(info) << "encoder error: EOF reached"; break; } - fprintf(stderr, "Encoding failed (%d)\n", err); + etiLog.level(error) << "Encoding failed (" << err << ")"; retval = 3; break; } @@ -1154,7 +1148,7 @@ int AudioEnc::run() } } else { - fprintf(stderr, "INTERNAL ERROR! invalid number of channels\n"); + etiLog.level(error) << "INTERNAL ERROR! invalid number of channels"; } if (read_bytes) { @@ -1170,7 +1164,7 @@ int AudioEnc::run() decoder->decode_frame(outbuf.data(), numOutBytes); } catch (runtime_error &e) { - fprintf(stderr, "Decoding failed with: %s\n", e.what()); + etiLog.level(error) << "Decoding failed with: " << e.what(); return 1; } } @@ -1184,8 +1178,7 @@ int AudioEnc::run() // Our timing code depends on this if (calls != enc_calls_per_output) { - fprintf(stderr, "INTERNAL ERROR! calls=%d, expected %d\n", - calls, enc_calls_per_output); + etiLog.level(error) << "INTERNAL ERROR! calls=" << calls << ", expected " << enc_calls_per_output; } calls = 0; @@ -1221,7 +1214,7 @@ int AudioEnc::run() bool success = send_frame(frame.data(), frame.size(), peak_left, peak_right); if (not success) { - fprintf(stderr, "Send error !\n"); + etiLog.level(error) << "Send error !"; send_error_count ++; } } @@ -1235,7 +1228,7 @@ int AudioEnc::run() } if (send_error_count > 10) { - fprintf(stderr, "Send failed ten times, aborting!\n"); + etiLog.level(error) << "Send failed ten times, aborting!"; retval = 4; break; } @@ -1278,7 +1271,7 @@ int AudioEnc::run() fflush(stdout); } while (read_bytes > 0); - fprintf(stderr, "\n"); + // Final newline removed - etiLog provides its own line endings return retval; } @@ -1486,7 +1479,7 @@ int main(int argc, char *argv[]) audio_enc.dab_channel_mode == "d" or audio_enc.dab_channel_mode == "j" or audio_enc.dab_channel_mode == "m")) { - fprintf(stderr, "Invalid DAB channel mode\n"); + etiLog.level(error) << "Invalid DAB channel mode"; usage(argv[0]); return 1; } @@ -1502,7 +1495,7 @@ int main(int argc, char *argv[]) /* The 32 character length restriction is arbitrary, but guarantees * that the EDI packet will not grow too large */ if (audio_enc.identifier.size() > 32) { - fprintf(stderr, "Output Identifier too long!\n"); + etiLog.level(error) << "Output Identifier too long!"; usage(argv[0]); return 1; } @@ -1554,7 +1547,7 @@ int main(int argc, char *argv[]) } break; case 10: - fprintf(stderr, "WARNING: the --vlc-gain option has been deprecated in favour of --audio-gain\n"); + etiLog.level(warn) << "WARNING: the --vlc-gain option has been deprecated in favour of --audio-gain"; // fallthrough case 'g': audio_enc.gain_dB = std::stod(optarg); @@ -1574,7 +1567,7 @@ int main(int argc, char *argv[]) #if HAVE_JACK audio_enc.jack_name = optarg; #else - fprintf(stderr, "JACK disabled at compile time!\n"); + etiLog.level(error) << "JACK disabled at compile time!"; return 1; #endif break; @@ -1605,7 +1598,7 @@ int main(int argc, char *argv[]) audio_enc.die_on_silence = true; } else { - fprintf(stderr, "Invalid silence timeout (%d) given!\n", audio_enc.silence_timeout); + etiLog.level(error) << "Invalid silence timeout (" << audio_enc.silence_timeout << ") given!"; return 1; } @@ -1631,7 +1624,7 @@ int main(int argc, char *argv[]) break; #else case 'v': - fprintf(stderr, "VLC input not enabled at compile time!\n"); + etiLog.level(error) << "VLC input not enabled at compile time!"; return 1; #endif case 'V': @@ -1667,7 +1660,7 @@ int main(int argc, char *argv[]) return audio_enc.run(); } catch (const std::runtime_error& e) { - fprintf(stderr, "ODR-AudioEnc failed to start: %s\n", e.what()); + etiLog.level(error) << "ODR-AudioEnc failed to start: " << e.what(); return 1; } } |