]> git.sesse.net Git - nageru/blob - patches/bmusb-add-support-for-persistent-device-memory.diff
Add some useful (pending) upstream patches that have not gone in yet.
[nageru] / patches / bmusb-add-support-for-persistent-device-memory.diff
1 diff --git a/bmusb.cpp b/bmusb.cpp
2 index 2ea6407..16ec380 100644
3 --- a/bmusb.cpp
4 +++ b/bmusb.cpp
5 @@ -1027,7 +1027,7 @@ void BMUSBCapture::configure_card()
6         // set up isochronous transfers for audio and video
7         for (int e = 3; e <= 4; ++e) {
8                 //int num_transfers = (e == 3) ? 6 : 6;
9 -               int num_transfers = 10;
10 +               int num_transfers = 6;
11                 for (int i = 0; i < num_transfers; ++i) {
12                         size_t buf_size;
13                         int num_iso_pack, size;
14 @@ -1043,8 +1043,14 @@ void BMUSBCapture::configure_card()
15                                 num_iso_pack = 80;
16                                 buf_size = num_iso_pack * size;
17                         }
18 -                       assert(size_t(num_iso_pack * size) <= buf_size);
19 -                       uint8_t *buf = new uint8_t[buf_size];
20 +                       int num_bytes = num_iso_pack * size;
21 +                       assert(size_t(num_bytes) <= buf_size);
22 +                       uint8_t *buf = libusb_dev_mem_alloc(devh, num_bytes);
23 +                       if (buf == nullptr) {
24 +                               fprintf(stderr, "Failed to allocate persistent DMA memory (probably missing kernel patch).\n");
25 +                               fprintf(stderr, "Will go slower, and likely fail due to memory fragmentation after a few hours.\n");
26 +                               buf = new uint8_t[num_bytes];
27 +                       }
28  
29                         xfr = libusb_alloc_transfer(num_iso_pack);
30                         if (!xfr) {