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;
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]));
}
}
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);