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);
void set_video_frame_allocator(FrameAllocator *allocator) override
{
video_frame_allocator = allocator;
+ if (owned_video_frame_allocator.get() != allocator) {
+ owned_video_frame_allocator.reset();
+ }
}
FrameAllocator *get_video_frame_allocator() override
void set_audio_frame_allocator(FrameAllocator *allocator) override
{
audio_frame_allocator = allocator;
+ if (owned_audio_frame_allocator.get() != allocator) {
+ owned_audio_frame_allocator.reset();
+ }
}
FrameAllocator *get_audio_frame_allocator() override
FrameAllocator *video_frame_allocator = nullptr;
FrameAllocator *audio_frame_allocator = nullptr;
+ std::unique_ptr<FrameAllocator> owned_video_frame_allocator;
+ std::unique_ptr<FrameAllocator> owned_audio_frame_allocator;
frame_callback_t frame_callback = nullptr;
std::thread dequeue_thread;