]> git.sesse.net Git - bmusb/blobdiff - bmusb.cpp
Default to queueing up more audio than video frames.
[bmusb] / bmusb.cpp
index 387e042900ea82bc10d3f7775e1915c7f8113c1e..e55d85d5acc07e5c891e944b59db2b4db4deb0d0 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -52,10 +52,16 @@ atomic<bool> 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<unique_ptr<uint8_t[]>> freelist;  // All of size <frame_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<uint8_t[]>(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);