improve exit handling on device removal
This commit is contained in:
parent
b8d33bfd82
commit
077613efc5
|
@ -85,6 +85,12 @@ void fl2k_callback(fl2k_data_info_t *data_info)
|
||||||
int r, left = FL2K_BUF_LEN;
|
int r, left = FL2K_BUF_LEN;
|
||||||
static uint32_t repeat_cnt = 0;
|
static uint32_t repeat_cnt = 0;
|
||||||
|
|
||||||
|
if (data_info->device_error) {
|
||||||
|
fprintf(stderr, "Device error, exiting.\n");
|
||||||
|
do_exit = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
data_info->sampletype_signed = 1;
|
data_info->sampletype_signed = 1;
|
||||||
data_info->r_buf = txbuf;
|
data_info->r_buf = txbuf;
|
||||||
|
|
||||||
|
|
|
@ -419,6 +419,7 @@ void fm_modulator_stereo(int use_rds)
|
||||||
void fl2k_callback(fl2k_data_info_t *data_info)
|
void fl2k_callback(fl2k_data_info_t *data_info)
|
||||||
{
|
{
|
||||||
if (data_info->device_error) {
|
if (data_info->device_error) {
|
||||||
|
fprintf(stderr, "Device error, exiting.\n");
|
||||||
do_exit = 1;
|
do_exit = 1;
|
||||||
pthread_cond_signal(&fm_cond);
|
pthread_cond_signal(&fm_cond);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,12 @@ void fl2k_callback(fl2k_data_info_t *data_info)
|
||||||
int r;
|
int r;
|
||||||
struct timeval tv = { 1, 0 };
|
struct timeval tv = { 1, 0 };
|
||||||
|
|
||||||
|
if (data_info->device_error) {
|
||||||
|
fprintf(stderr, "Device error, exiting.\n");
|
||||||
|
do_exit = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!connected)
|
if (!connected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -122,6 +128,12 @@ void fl2k_callback(fl2k_data_info_t *data_info)
|
||||||
|
|
||||||
if (r) {
|
if (r) {
|
||||||
received = recv(sock, txbuf + (FL2K_BUF_LEN - left), left, 0);
|
received = recv(sock, txbuf + (FL2K_BUF_LEN - left), left, 0);
|
||||||
|
if (!received) {
|
||||||
|
fprintf(stderr, "Connection was closed!\n");
|
||||||
|
fl2k_stop_tx(dev);
|
||||||
|
do_exit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
left -= received;
|
left -= received;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,6 +213,12 @@ static void ppm_test(uint32_t len)
|
||||||
|
|
||||||
void fl2k_callback(fl2k_data_info_t *data_info)
|
void fl2k_callback(fl2k_data_info_t *data_info)
|
||||||
{
|
{
|
||||||
|
if (data_info->device_error) {
|
||||||
|
fprintf(stderr, "Device error, exiting.\n");
|
||||||
|
do_exit = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* drop first couple of callbacks until everything is settled */
|
/* drop first couple of callbacks until everything is settled */
|
||||||
if (cb_cnt > 20) {
|
if (cb_cnt > 20) {
|
||||||
ppm_test(FL2K_BUF_LEN);
|
ppm_test(FL2K_BUF_LEN);
|
||||||
|
@ -222,7 +228,6 @@ void fl2k_callback(fl2k_data_info_t *data_info)
|
||||||
data_info->r_buf = buffer;
|
data_info->r_buf = buffer;
|
||||||
cb_cnt++;
|
cb_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -295,9 +300,6 @@ int main(int argc, char **argv)
|
||||||
while (!do_exit)
|
while (!do_exit)
|
||||||
sleep_ms(500);
|
sleep_ms(500);
|
||||||
|
|
||||||
if (do_exit)
|
|
||||||
fprintf(stderr, "\nUser cancel, exiting...\n");
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
fl2k_close(dev);
|
fl2k_close(dev);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
|
@ -529,6 +529,7 @@ static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer)
|
||||||
fl2k_xfer_info_t *next_xfer_info;
|
fl2k_xfer_info_t *next_xfer_info;
|
||||||
fl2k_dev_t *dev = (fl2k_dev_t *)xfer_info->dev;
|
fl2k_dev_t *dev = (fl2k_dev_t *)xfer_info->dev;
|
||||||
struct libusb_transfer *next_xfer = NULL;
|
struct libusb_transfer *next_xfer = NULL;
|
||||||
|
int r = 0;
|
||||||
|
|
||||||
if (LIBUSB_TRANSFER_COMPLETED == xfer->status) {
|
if (LIBUSB_TRANSFER_COMPLETED == xfer->status) {
|
||||||
/* resubmit transfer */
|
/* resubmit transfer */
|
||||||
|
@ -541,8 +542,7 @@ static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer)
|
||||||
|
|
||||||
/* Submit next filled transfer */
|
/* Submit next filled transfer */
|
||||||
next_xfer_info->state = BUF_SUBMITTED;
|
next_xfer_info->state = BUF_SUBMITTED;
|
||||||
libusb_submit_transfer(next_xfer);
|
r = libusb_submit_transfer(next_xfer);
|
||||||
|
|
||||||
xfer_info->state = BUF_EMPTY;
|
xfer_info->state = BUF_EMPTY;
|
||||||
pthread_cond_signal(&dev->buf_cond);
|
pthread_cond_signal(&dev->buf_cond);
|
||||||
} else {
|
} else {
|
||||||
|
@ -551,17 +551,21 @@ static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer)
|
||||||
* stops to output data and hangs
|
* stops to output data and hangs
|
||||||
* (happens only in the hacked 'gapless'
|
* (happens only in the hacked 'gapless'
|
||||||
* mode without HSYNC and VSYNC) */
|
* mode without HSYNC and VSYNC) */
|
||||||
libusb_submit_transfer(xfer);
|
r = libusb_submit_transfer(xfer);
|
||||||
pthread_cond_signal(&dev->buf_cond);
|
pthread_cond_signal(&dev->buf_cond);
|
||||||
dev->underflow_cnt++;
|
dev->underflow_cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (LIBUSB_TRANSFER_CANCELLED != xfer->status) {
|
}
|
||||||
|
|
||||||
|
if (((LIBUSB_TRANSFER_CANCELLED != xfer->status) &&
|
||||||
|
(LIBUSB_TRANSFER_COMPLETED != xfer->status)) ||
|
||||||
|
(r == LIBUSB_ERROR_NO_DEVICE)) {
|
||||||
dev->dev_lost = 1;
|
dev->dev_lost = 1;
|
||||||
fl2k_stop_tx(dev);
|
fl2k_stop_tx(dev);
|
||||||
pthread_cond_signal(&dev->buf_cond);
|
pthread_cond_signal(&dev->buf_cond);
|
||||||
fprintf(stderr, "cb transfer status: %d, "
|
fprintf(stderr, "cb transfer status: %d, submit "
|
||||||
"canceling...\n", xfer->status);
|
"transfer %d, canceling...\n", xfer->status, r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,7 +923,6 @@ static void *fl2k_sample_worker(void *arg)
|
||||||
if (dev->dev_lost && dev->cb) {
|
if (dev->dev_lost && dev->cb) {
|
||||||
data_info.device_error = 1;
|
data_info.device_error = 1;
|
||||||
dev->cb(&data_info);
|
dev->cb(&data_info);
|
||||||
fl2k_stop_tx(dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
|
|
Loading…
Reference in New Issue