From fd5928ed939da4790445fba505ebeb469a361d96 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sat, 17 Aug 2024 13:10:53 -0700 Subject: [PATCH] Fix segfaults when transmitting through external vocoder. --- src/freedv_interface.cpp | 7 +++++++ src/pipeline/ExternVocoderStep.cpp | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/freedv_interface.cpp b/src/freedv_interface.cpp index a933b2ee..86152785 100644 --- a/src/freedv_interface.cpp +++ b/src/freedv_interface.cpp @@ -455,12 +455,16 @@ int FreeDVInterface::getTxSpeechSampleRate() const int FreeDVInterface::getTxNumSpeechSamples() const { + if (txMode_ == -1) return 1024; + assert(currentTxMode_ != nullptr); return freedv_get_n_speech_samples(currentTxMode_); } int FreeDVInterface::getTxNNomModemSamples() const { + if (txMode_ == -1) return 1024; + assert(currentTxMode_ != nullptr); return freedv_get_n_nom_modem_samples(currentTxMode_); } @@ -603,6 +607,9 @@ IPipelineStep* FreeDVInterface::createTransmitPipeline(int inputSampleRate, int std::function modeFn = [&](ParallelStep*) { + // Special handling for external vocoder. + if (txMode_ == -1) return 0; + int index = 0; for (auto& dv : dvObjects_) { diff --git a/src/pipeline/ExternVocoderStep.cpp b/src/pipeline/ExternVocoderStep.cpp index ca0be14a..078baff5 100644 --- a/src/pipeline/ExternVocoderStep.cpp +++ b/src/pipeline/ExternVocoderStep.cpp @@ -128,7 +128,10 @@ std::shared_ptr ExternVocoderStep::execute(std::shared_ptr inputSa short output_buf[samplesToRead]; short* inputPtr = inputSamples.get(); - write(receiveStdinFd_, inputPtr, numInputSamples * sizeof(short)); + if (numInputSamples > 0) + { + write(receiveStdinFd_, inputPtr, numInputSamples * sizeof(short)); + } *numOutputSamples = read(receiveStdoutFd_, output_buf, samplesToRead * sizeof(short)); if (*numOutputSamples == -1) {