diff options
author | rmens <r.mens@me.com> | 2025-08-30 14:36:16 +0200 |
---|---|---|
committer | rmens <r.mens@me.com> | 2025-08-30 14:36:16 +0200 |
commit | 32cd3ce5ba33d85429365cbe2a43872371351fb9 (patch) | |
tree | 5ca34e4246ebba03ae61c6a36deef614645c4857 /src/odr-audioenc.cpp | |
parent | 97540d37d069a5b7ae535755fec32f2a3116485b (diff) | |
download | ODR-AudioEnc-32cd3ce5ba33d85429365cbe2a43872371351fb9.tar.gz ODR-AudioEnc-32cd3ce5ba33d85429365cbe2a43872371351fb9.tar.bz2 ODR-AudioEnc-32cd3ce5ba33d85429365cbe2a43872371351fb9.zip |
feat: use etiLog
Diffstat (limited to 'src/odr-audioenc.cpp')
-rw-r--r-- | src/odr-audioenc.cpp | 155 |
1 files changed, 74 insertions, 81 deletions
diff --git a/src/odr-audioenc.cpp b/src/odr-audioenc.cpp index 44fc694..d456c89 100644 --- a/src/odr-audioenc.cpp +++ b/src/odr-audioenc.cpp @@ -237,13 +237,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; } @@ -261,35 +261,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; } @@ -300,33 +299,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; } @@ -462,7 +461,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; @@ -527,11 +526,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; } @@ -543,13 +542,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; } } @@ -559,25 +557,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); @@ -595,7 +593,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()); @@ -622,11 +620,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!"; } } @@ -651,10 +649,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; @@ -663,20 +661,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); @@ -703,8 +699,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; } } @@ -723,14 +718,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; } } @@ -742,7 +737,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; } @@ -778,7 +773,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; } @@ -797,18 +792,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; @@ -847,7 +842,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; } } @@ -874,13 +869,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; } @@ -889,7 +884,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; } @@ -903,7 +898,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; } @@ -927,7 +922,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; } } @@ -958,13 +953,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; } @@ -973,7 +968,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; } @@ -1012,7 +1007,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"; } } @@ -1069,8 +1064,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; } @@ -1122,10 +1116,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; } @@ -1152,7 +1146,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) { @@ -1168,7 +1162,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; } } @@ -1182,8 +1176,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; @@ -1219,7 +1212,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 ++; } } @@ -1233,7 +1226,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; } @@ -1276,7 +1269,7 @@ int AudioEnc::run() fflush(stdout); } while (read_bytes > 0); - fprintf(stderr, "\n"); + // Final newline removed - etiLog provides its own line endings return retval; } @@ -1484,7 +1477,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; } @@ -1500,7 +1493,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; } @@ -1552,7 +1545,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); @@ -1572,7 +1565,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; @@ -1603,7 +1596,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; } @@ -1629,7 +1622,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': @@ -1665,7 +1658,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; } } |