Skip to content

Commit

Permalink
MultiFM: Support reconnecting decoder to FIFO
Browse files Browse the repository at this point in the history
If a decoder crashes or terminates spuriously, we now support
reconnecting that decoder to the MultiFM output pipe, withot having to
restart MultiFM from scratch.
  • Loading branch information
pvachon committed Feb 18, 2018
1 parent ff63dd3 commit 4439916
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
17 changes: 15 additions & 2 deletions multifm/demod.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,21 @@ aresult_t demod_thread_process(struct demod_thread *dthr, struct sample_buf *sbu
/* x. Write out the resulting PCM samples */
if (0 > write(dthr->fifo_fd, dthr->pcm_out_buf, dthr->nr_pcm_samples * sizeof(int16_t))) {
int errnum = errno;
PANIC("Failed to write %zu bytes to the output fifo. Reason: %s (%d)", sizeof(int16_t) * dthr->nr_pcm_samples,
strerror(errnum), errnum);
if (errnum == EPIPE) {
if (0 == dthr->nr_dropped_samples) {
MFM_MSG(SEV_WARNING, "FIFO-REMOTE-END-DISCONNECTED", "Remote end of FIFO disconnected. "
"Until a process picks up the FIFO, we're dropping samples.");
}
dthr->nr_dropped_samples += dthr->nr_pcm_samples;
} else {
PANIC("Failed to write %zu bytes to the output fifo. Reason: %s (%d)",
sizeof(int16_t) * dthr->nr_pcm_samples,
strerror(errnum), errnum);
}
} else if (0 != dthr->nr_dropped_samples) {
MFM_MSG(SEV_WARNING, "FIFO-RESUMED", "Remote FIFO end reconnected. Dropped %zu samples in the interim.",
dthr->nr_dropped_samples);
dthr->nr_dropped_samples = 0;
}

TSL_BUG_IF_FAILED(direct_fir_can_process(&dthr->fir, &can_process, NULL));
Expand Down
5 changes: 5 additions & 0 deletions multifm/demod.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ struct demod_thread {
*/
size_t total_nr_pcm_samples;

/**
* Number of samples dropped on the floor
*/
size_t nr_dropped_samples;

/**
* Number of FM signal samples available
*/
Expand Down
13 changes: 7 additions & 6 deletions multifm/multifm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
*/

#include <multifm/multifm.h>
#if HAVE_RTLSDR

#ifdef HAVE_RTLSDR
#include <multifm/rtl_sdr_if.h>
#include <rtl-sdr.h>
#endif /* HAVE_RTLSDR */

#if HAVE_DESPAIRSPY
#ifdef HAVE_DESPAIRSPY
#include <multifm/airspy_if.h>
#endif

#if HAVE_UHD
#ifdef HAVE_UHD
#include <multifm/uhd_if.h>
#endif

Expand Down Expand Up @@ -126,21 +127,21 @@ int main(int argc, const char *argv[])

/* Prepare the RTL-SDR thread and demod threads */
if (!strncmp(dev_type, "rtlsdr", 6)) {
#if HAVE_RTLSDR
#ifdef HAVE_RTLSDR
TSL_BUG_IF_FAILED(rtl_sdr_worker_thread_new(&rx_thr, cfg));
#else
MFM_MSG(SEV_FATAL, "RTLSDR-NOT-SUPPORTED", "RTL-SDR devices are not supported by this build.");
goto done;
#endif
} else if (!strncmp(dev_type, "airspy", 6)) {
#if HAVE_DESPAIRSPY
#ifdef HAVE_DESPAIRSPY
TSL_BUG_IF_FAILED(airspy_worker_thread_new(&rx_thr, cfg));
#else
MFM_MSG(SEV_FATAL, "AIRSPY-NOT-SUPPORTED", "Airspy devices are not supported by this build.");
goto done;
#endif
} else if (!strncmp(dev_type, "usrp", 4)) {
#if HAVE_UHD
#ifdef HAVE_UHD
TSL_BUG_IF_FAILED(uhd_worker_thread_new(&rx_thr, cfg));
#else
MFM_MSG(SEV_FATAL, "USRP-NOT-SUPPORTED", "USRP devices are not supported by this build.");
Expand Down
5 changes: 4 additions & 1 deletion multifm/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ aresult_t receiver_sample_buf_alloc(struct receiver *rx, struct sample_buf **pbu

/* Allocate an output buffer */
if (FAILED(ret = frame_alloc(rx->samp_alloc, (void **)&sbuf))) {
MFM_MSG(SEV_INFO, "NO-SAMPLE-BUFFER", "Out of sample buffers.");
if (0 == rx->nr_samp_buf_alloc_fails) {
MFM_MSG(SEV_INFO, "NO-SAMPLE-BUFFER", "There are no available sample buffers, dropping received samples.");
}
rx->nr_samp_buf_alloc_fails++;
goto done;
}

Expand Down
5 changes: 5 additions & 0 deletions multifm/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct receiver {
*/
size_t nr_demod_threads;

/**
* Number of failed sample buffer allocations
*/
size_t nr_samp_buf_alloc_fails;

/**
* Frame allocator of sample buffers
*/
Expand Down

0 comments on commit 4439916

Please sign in to comment.