Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1860 LibUsb Transfer Buffer Error Handling Enhancements #1950

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ private void processAMBTC(P25P1Message message)
}
break;
default:
mLog.debug("Unrecognized AMBTC Opcode: " + ambtc.getHeader().getOpcode().name());
// mLog.debug("Unrecognized AMBTC Opcode: " + ambtc.getHeader().getOpcode().name());
break;
}
}
Expand Down Expand Up @@ -1486,13 +1486,13 @@ private void processTSBK(P25P1Message message)
case MOTOROLA_OSP_QUEUED_RESPONSE:
processTSBKQueuedResponse(tsbk);
default:
if(!tsbk.getOpcode().name().startsWith("ISP"))
{
LOGGING_SUPPRESSOR.info(tsbk.getOpcode().name() + tsbk.getMessage().toHexString(),
1, "Unrecognized TSBK Opcode: " + tsbk.getOpcode().name() +
" VENDOR:" + tsbk.getVendor() + " OPCODE:" + tsbk.getOpcodeNumber() +
" MSG:" + tsbk.getMessage().toHexString());
}
// if(!tsbk.getOpcode().name().startsWith("ISP"))
// {
// LOGGING_SUPPRESSOR.info(tsbk.getOpcode().name() + tsbk.getMessage().toHexString(),
// 1, "Unrecognized TSBK Opcode: " + tsbk.getOpcode().name() +
// " VENDOR:" + tsbk.getVendor() + " OPCODE:" + tsbk.getOpcodeNumber() +
// " MSG:" + tsbk.getMessage().toHexString());
// }
break;
}
}
Expand Down Expand Up @@ -2164,10 +2164,10 @@ private void processLC(LinkControlWord lcw, long timestamp, boolean isTerminator
{
closeCurrentCallEvent(timestamp);
}
LOGGING_SUPPRESSOR.info(lcw.getVendor().toString() + lcw.getOpcodeNumber() + lcw.getMessage().toHexString(),
1, "Unrecognized LCW Opcode: " + lcw.getOpcode().name() + " VENDOR:" + lcw.getVendor() +
" OPCODE:" + lcw.getOpcodeNumber() + " MSG:" + lcw.getMessage().toHexString() +
" CHAN:" + getCurrentChannel() + " FREQ:" + getCurrentFrequency());
// LOGGING_SUPPRESSOR.info(lcw.getVendor().toString() + lcw.getOpcodeNumber() + lcw.getMessage().toHexString(),
// 1, "Unrecognized LCW Opcode: " + lcw.getOpcode().name() + " VENDOR:" + lcw.getVendor() +
// " OPCODE:" + lcw.getOpcodeNumber() + " MSG:" + lcw.getMessage().toHexString() +
// " CHAN:" + getCurrentChannel() + " FREQ:" + getCurrentFrequency());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
* Copyright (C) 2014-2024 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -588,9 +588,14 @@ private void submitTransfers(List<Transfer> transfers)

/**
* (Re)Submits the transfer for stream processing
*
* Note: synchronized used here because there can be multiple threads can invoke LibUsb.handleTimeoutEvents
* (scheduled thread pool and a dedicated shutdown thread) during tuner shutdown and this has caused transfer
* tracking issues.
*
* @param transfer to (re)submit
*/
private void submitTransfer(Transfer transfer)
private synchronized void submitTransfer(Transfer transfer)
{
int status = LibUsb.submitTransfer(transfer);

Expand All @@ -616,35 +621,34 @@ private void submitTransfer(Transfer transfer)
mAvailableTransfers.size() + "]");
}
}
else if(resubmitStatus == LibUsb.ERROR_BUSY)
{
//Ignore - this indicates the transfer was previously submitted and libusb is still working it.
}
else
{
//Add it back to the queue to try again later.
mErrorTransfers.add(transfer);
mTransferErrorCount++;

//Only log this if more than half of the total transfer buffers are in error-holding
if(mErrorTransfers.size() >= (mAvailableTransfers.size() / 2))
{
mLog.error("Attempt to resubmit previous error USB transfer buffer failed with status [" +
LibUsb.errorName(resubmitStatus) + "] - this may be temporary and has happened [" +
mTransferErrorCount + "] times so far. Transfer buffer holding queue (error/total) [" +
mErrorTransfers.size() + "/" + mAvailableTransfers.size() + "]");
}
}
}
}
else if(status == LibUsb.ERROR_BUSY)
{
//Ignore - this indicates the transfer was previously submitted and libusb is still working it. I'm not
//sure how this happens because we give libusb a transfer and it hands it back when it's full. If
//libusb is still working it, then why did it indicate the transfer was completed? So, we simply
//ignore this error code. Other libraries simply ignore the submit status code altogether.
}
else
{
mLog.error("USB transfer [" + transfer + "] submit attempt failed with error [" + LibUsb.errorName(status) +
"] - adding to error queue to resubmit later - this may be a temporary USB issue and has happened [" +
mTransferErrorCount + "] time(s) so far. Current transfer error queue (error/total) [" +
mErrorTransfers.size() + "/" + mAvailableTransfers.size() + "]");

mErrorTransfers.add(transfer);
mTransferErrorCount++;

//Only log this if more than half of the total transfer buffers are in error-holding
if(mErrorTransfers.size() >= (mAvailableTransfers.size() / 2))
{
mLog.error("Attempt to submit USB transfer buffer failed with status [" +
LibUsb.errorName(status) + "] - this may be temporary and has happened [" +
mTransferErrorCount + "] time(s) so far. Transfer buffer holding queue (error/total) [" +
mErrorTransfers.size() + "/" + mAvailableTransfers.size() + "]");
}
}

if(mErrorTransfers.size() >= mAvailableTransfers.size())
Expand Down Expand Up @@ -703,6 +707,14 @@ public void processTransfer(Transfer transfer)
{
mInProgressTransfers.remove(transfer);

if(mErrorTransfers.contains(transfer))
{
mLog.warn("USB transfer [" + transfer + "] that was being tracked as an error transfer, has just been " +
"delivered as completed with transfer status [" + LibUsb.errorName(transfer.status()) +
"] - removing it from the transfer error queue");
mErrorTransfers.remove(transfer);
}

switch(transfer.status())
{
case LibUsb.TRANSFER_COMPLETED:
Expand Down
Loading