From: Steinar H. Gunderson Date: Tue, 7 Jun 2016 22:54:50 +0000 (+0200) Subject: Add support for persistent USB device memory. X-Git-Tag: 0.4~10 X-Git-Url: https://git.sesse.net/?p=bmusb;a=commitdiff_plain;h=c753d698b047822c11f5f97b889649a3e582a4c9 Add support for persistent USB device memory. This patch lived out-of-tree for a long time; now that libusb in git has taken in the functionality needed, we can pull it in, even though the version define isn't good enough to check the actual functionality. It can distinguish git from last release, though, and that's the most important thing. --- diff --git a/bmusb.cpp b/bmusb.cpp index 3aac81e..ed7a1f5 100644 --- a/bmusb.cpp +++ b/bmusb.cpp @@ -1028,7 +1028,7 @@ void BMUSBCapture::configure_card() // set up isochronous transfers for audio and video for (int e = 3; e <= 4; ++e) { //int num_transfers = (e == 3) ? 6 : 6; - int num_transfers = 10; + int num_transfers = 6; for (int i = 0; i < num_transfers; ++i) { size_t buf_size; int num_iso_pack, size; @@ -1044,8 +1044,23 @@ void BMUSBCapture::configure_card() num_iso_pack = 80; buf_size = num_iso_pack * size; } - assert(size_t(num_iso_pack * size) <= buf_size); - uint8_t *buf = new uint8_t[buf_size]; + int num_bytes = num_iso_pack * size; + assert(size_t(num_bytes) <= buf_size); +#if LIBUSB_API_VERSION >= 0x01000105 + uint8_t *buf = libusb_dev_mem_alloc(devh, num_bytes); +#else + uint8_t *buf = nullptr; +#endif + if (buf == nullptr) { + fprintf(stderr, "Failed to allocate persistent DMA memory "); +#if LIBUSB_API_VERSION >= 0x01000105 + fprintf(stderr, "(probably too old kernel; use 4.6.0 or newer).\n"); +#else + fprintf(stderr, "(compiled against too old libusb-1.0).\n"); +#endif + fprintf(stderr, "Will go slower, and likely fail due to memory fragmentation after a few hours.\n"); + buf = new uint8_t[num_bytes]; + } xfr = libusb_alloc_transfer(num_iso_pack); if (!xfr) {