7 // An interface for frame allocators; if you do not specify one
8 // (using set_video_frame_allocator), a default one that pre-allocates
9 // a freelist of eight frames using new[] will be used. Specifying
10 // your own can be useful if you have special demands for where you want the
11 // frame to end up and don't want to spend the extra copy to get it there, for
12 // instance GPU memory.
13 class FrameAllocator {
16 uint8_t *data = nullptr;
17 size_t len = 0; // Number of bytes we actually have.
18 size_t size = 0; // Number of bytes we have room for.
19 void *userdata = nullptr;
20 FrameAllocator *owner = nullptr;
23 virtual ~FrameAllocator();
25 // Request a video frame. Note that this is called from the
26 // USB thread, which runs with realtime priority and is
27 // very sensitive to delays. Thus, you should not do anything
28 // here that might sleep, including calling malloc().
29 // (Taking a mutex is borderline.)
31 // The Frame object will be given to the frame callback,
32 // which is responsible for releasing the video frame back
33 // once it is usable for new frames (ie., it will no longer
34 // be read from). You can use the "userdata" pointer for
35 // whatever you want to identify this frame if you need to.
37 // Returning a Frame with data==nullptr is allowed;
38 // if so, the frame in progress will be dropped.
39 virtual Frame alloc_frame() = 0;
41 virtual void release_frame(Frame frame) = 0;
44 typedef std::function<void(uint16_t timecode,
45 FrameAllocator::Frame video_frame, size_t video_offset, uint16_t video_format,
46 FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format)>
49 void set_video_frame_allocator(FrameAllocator *allocator); // Does not take ownership.
50 FrameAllocator *get_video_frame_allocator();
52 void set_audio_frame_allocator(FrameAllocator *allocator); // Does not take ownership.
53 FrameAllocator *get_audio_frame_allocator();
55 void set_frame_callback(frame_callback_t callback);
56 void start_bm_capture();
57 void stop_bm_capture();