Submit flush transfer as soon as end of data is reached.

This commit is contained in:
Martin Ling
2022-09-15 14:32:15 +01:00
parent 09c6030ec9
commit 69823397b1

View File

@ -391,6 +391,15 @@ static int prepare_transfers(
device->streaming = (ready_transfers == TRANSFER_COUNT); device->streaming = (ready_transfers == TRANSFER_COUNT);
device->transfers_setup = true; 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; return HACKRF_SUCCESS;
} }
@ -1744,24 +1753,13 @@ static void transfer_finished(
struct hackrf_device* device, struct hackrf_device* device,
struct libusb_transfer* finished_transfer) struct libusb_transfer* finished_transfer)
{ {
int result;
// If a transfer finished for any reason, we're shutting down. // If a transfer finished for any reason, we're shutting down.
device->streaming = false; device->streaming = false;
// If this is the last transfer, signal that all are now finished. // If this is the last transfer, signal that all are now finished.
pthread_mutex_lock(&device->all_finished_lock); pthread_mutex_lock(&device->all_finished_lock);
if (device->active_transfers == 1) { if (device->active_transfers == 1) {
if (device->flush) { 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 {
device->active_transfers = 0; device->active_transfers = 0;
pthread_cond_broadcast(&device->all_finished_cv); 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) if (resubmit && result == LIBUSB_SUCCESS)
return; return;
} else if (device->flush) {
libusb_submit_transfer(device->flush_transfer);
} }
} }