简体   繁体   English

Android&libusb提交ISOC传输错误

[英]Android & libusb submit ISOC transfer error

I write the Android application using libusb-1.0.9 and NDK (Android 4.0.4+) which has to read out audio-data from the USB-audiocard. 我使用libusb-1.0.9和NDK(Android 4.0.4+)编写了Android应用程序,该程序必须从USB声卡中读取音频数据。 The USB device from libusb opens successfully, and for it it is possible to receive all interfaces/EndPoint list. libusb的USB设备已成功打开,因此可以接收所有接口/端点列表。 But when making ISOC transfer I faced with following unclear me error: 但是在进行ISOC传输时,我面临以下不清楚的错误:

Debugging C code of making transfer: 调试传递的C代码:

static uint8_t buf[12];

static void cb_xfr(struct libusb_transfer *xfr)
{
     LOGD("USB callback\n");
     libusb_free_transfer(xfr);
}

JNIEXPORT jlong JNICALL
Java_com_usbtest_libusb_Libusb_makeISOCTransfer(JNIEnv *env, jobject this, jlong ms) 
{
      static struct libusb_transfer *xfr;
      int num_iso_pack = 1;
      unsigned char ep = 0x84;

       xfr = libusb_alloc_transfer(num_iso_pack);
       if (!xfr)  {
               LOGD("libusb_alloc_transfer: errno=%d\n", errno);
               return -1000;
       }

       LOGD("libusb_fill_iso_transfer: ep=%x, buf=%d, num iso=%d\n", ep, sizeof(buf), num_iso_pack);
       libusb_fill_iso_transfer(xfr, handle, ep, buf, sizeof(buf), num_iso_pack, cb_xfr, NULL, 0);
       libusb_set_iso_packet_lengths(xfr, sizeof(buf)/num_iso_pack);
       int res = libusb_submit_transfer(xfr);
       LOGD("libusb_submit_transfer: %d, errno=%d\n", res, errno);
       struct timeval tv;
       tv.tv_sec = 1;
       tv.tv_usec = 0;
       libusb_handle_events_timeout(NULL, &tv);
       return res;
}

After a call of libusb_submit_transfer I received a mistake: libusb_submit_transfer: -1, errno -2 And text messages: 调用libusb_submit_transfer后,我收到一个错误:libusb_submit_transfer:-1,errno -2和短信:

 need 1 32k URBs for transfer
 first URB failed, easy peasy

EndPoint 0x84 is true for audio-in. EndPoint 0x84适用于音频输入。 The buf[] size = 12 - corresponds to the field wMaxPacketSize of this EndPoint. buf [] size = 12-对应于此EndPoint的字段wMaxPacketSize。 I request 1 transfer. 我要求1次转帐。 Field of xfr->status = 0, but callback isn't caused. xfr-> status = 0的字段,但不会引起回调。 I thought that it is necessary to increase the buf buffer to 32K - I increased, but it didn't help. 我认为有必要将buf缓冲区增加到32K-我增加了,但没有帮助。 I tried to increase quantity of transfers. 我试图增加转账数量。 Same error. 同样的错误。 Prompt me please in what there can be a error? 请提示我有什么错误?

I found the solution of this problem. 我找到了解决这个问题的方法。 In this topic http://en.it-usenet.org/thread/14995/14985/ there was a similar question, and the decision appeared to make detach for device HID USB interfaces. 在本主题http://en.it-usenet.org/thread/14995/14985/中,有一个类似的问题,该决定似乎使设备HID USB接口脱离了。

I've used libusb_detach_kernel to detach the 2 hid drivers and submit transfer returned 0!! 我已经使用libusb_detach_kernel分离了2个隐藏驱动程序并提交了传输返回0!

I made libusb_detach_kernel_driver(handle, interface) for all interfaces of the device (0..3) after device opening, and as a result of libusb_submit_transfer return SUCCESS of transfer. 打开设备后,我为设备(0..3)的所有接口制作了libusb_detach_kernel_driver(句柄,接口) ,并且由于libusb_submit_transfer返回了SUCCESS传输的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM