From ffdf54bcfe1ad3baaa9e193da4073af3d1230073 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 14 Oct 2015 01:34:46 +0200 Subject: [PATCH] Default to queueing up more audio than video frames. --- bmusb.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bmusb.cpp b/bmusb.cpp index 387e042..e55d85d 100644 --- a/bmusb.cpp +++ b/bmusb.cpp @@ -52,10 +52,16 @@ atomic should_quit; FrameAllocator::~FrameAllocator() {} -#define NUM_QUEUED_FRAMES 16 +// Audio is more important than video, and also much cheaper. +// By having many more audio frames available, hopefully if something +// starts to drop, we'll have CPU load go down (from not having to +// process as much video) before we have to drop audio. +#define NUM_QUEUED_VIDEO_FRAMES 16 +#define NUM_QUEUED_AUDIO_FRAMES 64 + class MallocFrameAllocator : public FrameAllocator { public: - MallocFrameAllocator(size_t frame_size); + MallocFrameAllocator(size_t frame_size, size_t num_queued_frames); Frame alloc_frame() override; void release_frame(Frame frame) override; @@ -66,10 +72,10 @@ private: stack> freelist; // All of size . }; -MallocFrameAllocator::MallocFrameAllocator(size_t frame_size) +MallocFrameAllocator::MallocFrameAllocator(size_t frame_size, size_t num_queued_frames) : frame_size(frame_size) { - for (int i = 0; i < NUM_QUEUED_FRAMES; ++i) { + for (size_t i = 0; i < num_queued_frames; ++i) { freelist.push(unique_ptr(new uint8_t[frame_size])); } } @@ -656,10 +662,10 @@ void BMUSBCapture::usb_thread_func() void BMUSBCapture::configure_card() { if (video_frame_allocator == nullptr) { - set_video_frame_allocator(new MallocFrameAllocator(FRAME_SIZE)); // FIXME: leak. + set_video_frame_allocator(new MallocFrameAllocator(FRAME_SIZE, NUM_QUEUED_VIDEO_FRAMES)); // FIXME: leak. } if (audio_frame_allocator == nullptr) { - set_audio_frame_allocator(new MallocFrameAllocator(65536)); // FIXME: leak. + set_audio_frame_allocator(new MallocFrameAllocator(65536, NUM_QUEUED_AUDIO_FRAMES)); // FIXME: leak. } dequeue_thread_should_quit = false; dequeue_thread = thread(&BMUSBCapture::dequeue_thread_func, this); -- 2.39.2