From 69823397b1218bc4708ebe41a4299ef9c86e8f3a Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Thu, 15 Sep 2022 14:32:15 +0100 Subject: [PATCH] Submit flush transfer as soon as end of data is reached. --- host/libhackrf/src/hackrf.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 0ccc57e5..40545cde 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -391,6 +391,15 @@ static int prepare_transfers( device->streaming = (ready_transfers == TRANSFER_COUNT); device->transfers_setup = true; + // If we're not continuing streaming, follow up with a flush if needed. + if (!device->streaming && device->flush) { + error = libusb_submit_transfer(device->flush_transfer); + if (error != 0) { + last_libusb_error = error; + return HACKRF_ERROR_LIBUSB; + } + } + return HACKRF_SUCCESS; } @@ -1744,24 +1753,13 @@ static void transfer_finished( struct hackrf_device* device, struct libusb_transfer* finished_transfer) { - int result; - // If a transfer finished for any reason, we're shutting down. device->streaming = false; // If this is the last transfer, signal that all are now finished. pthread_mutex_lock(&device->all_finished_lock); if (device->active_transfers == 1) { - if (device->flush) { - // Don't finish yet - flush the TX buffer first. - result = libusb_submit_transfer(device->flush_transfer); - // If that fails, just shut down. - if (result != LIBUSB_SUCCESS) { - device->flush = false; - device->active_transfers = 0; - pthread_cond_broadcast(&device->all_finished_cv); - } - } else { + if (!device->flush) { device->active_transfers = 0; pthread_cond_broadcast(&device->all_finished_cv); } @@ -1817,6 +1815,8 @@ hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer) if (resubmit && result == LIBUSB_SUCCESS) return; + } else if (device->flush) { + libusb_submit_transfer(device->flush_transfer); } }