X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bmusb.cpp;h=ed7a1f5caa42874909bf13804210322ee34942b5;hb=c753d698b047822c11f5f97b889649a3e582a4c9;hp=48bdcae3c41516815cb31a9d1cafb9a015d28f1c;hpb=b7e6e2e7df1bbae97a1b62112d9c8c67df212f44;p=bmusb diff --git a/bmusb.cpp b/bmusb.cpp index 48bdcae..ed7a1f5 100644 --- a/bmusb.cpp +++ b/bmusb.cpp @@ -782,10 +782,12 @@ libusb_device_handle *open_card(int card_index, string *description) void BMUSBCapture::configure_card() { if (video_frame_allocator == nullptr) { - set_video_frame_allocator(new MallocFrameAllocator(FRAME_SIZE, NUM_QUEUED_VIDEO_FRAMES)); // FIXME: leak. + owned_video_frame_allocator.reset(new MallocFrameAllocator(FRAME_SIZE, NUM_QUEUED_VIDEO_FRAMES)); + set_video_frame_allocator(owned_video_frame_allocator.get()); } if (audio_frame_allocator == nullptr) { - set_audio_frame_allocator(new MallocFrameAllocator(65536, NUM_QUEUED_AUDIO_FRAMES)); // FIXME: leak. + owned_audio_frame_allocator.reset(new MallocFrameAllocator(65536, NUM_QUEUED_AUDIO_FRAMES)); + set_audio_frame_allocator(owned_audio_frame_allocator.get()); } dequeue_thread_should_quit = false; dequeue_thread = thread(&BMUSBCapture::dequeue_thread_func, this); @@ -1026,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; @@ -1042,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) {