|
0 |
#include <stdlib.h>
|
|
1 |
#include <obs.h>
|
|
2 |
#include <obs-module.h>
|
|
3 |
#include <bmusb/bmusb.h>
|
|
4 |
|
|
5 |
#include <stdio.h>
|
|
6 |
|
|
7 |
using bmusb::BMUSBCapture;
|
|
8 |
using bmusb::FrameAllocator;
|
|
9 |
using bmusb::VideoFormat;
|
|
10 |
using bmusb::AudioFormat;
|
|
11 |
|
|
12 |
struct bmusb_inst {
|
|
13 |
obs_source_t *source;
|
|
14 |
BMUSBCapture *capture;
|
|
15 |
bool initialized;
|
|
16 |
};
|
|
17 |
|
|
18 |
static const char *bmusb_getname(void *unused)
|
|
19 |
{
|
|
20 |
UNUSED_PARAMETER(unused);
|
|
21 |
return "Blackmagic USB3 source (bmusb)";
|
|
22 |
}
|
|
23 |
|
|
24 |
static void bmusb_destroy(void *data)
|
|
25 |
{
|
|
26 |
struct bmusb_inst *rt = (bmusb_inst *) data;
|
|
27 |
|
|
28 |
if (rt) {
|
|
29 |
if (rt->initialized) {
|
|
30 |
BMUSBCapture::stop_bm_thread();
|
|
31 |
delete rt->capture;
|
|
32 |
}
|
|
33 |
|
|
34 |
bfree(rt);
|
|
35 |
}
|
|
36 |
}
|
|
37 |
|
|
38 |
static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
|
|
39 |
{
|
|
40 |
struct bmusb_inst *rt = (bmusb_inst *) bzalloc(sizeof(struct bmusb_inst));
|
|
41 |
rt->source = source;
|
|
42 |
|
|
43 |
rt->capture = new BMUSBCapture(0); // @TODO select card
|
|
44 |
rt->capture->set_pixel_format(bmusb::PixelFormat_8BitYCbCr);
|
|
45 |
rt->capture->set_frame_callback(
|
|
46 |
[rt](uint16_t timecode,
|
|
47 |
FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
|
|
48 |
FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format
|
|
49 |
) {
|
|
50 |
printf("got fraem %d\n", timecode);
|
|
51 |
UNUSED_PARAMETER(video_format);
|
|
52 |
UNUSED_PARAMETER(audio_format);
|
|
53 |
rt->capture->get_video_frame_allocator()->release_frame(video_frame);
|
|
54 |
rt->capture->get_audio_frame_allocator()->release_frame(audio_frame);
|
|
55 |
}
|
|
56 |
);
|
|
57 |
rt->capture->configure_card();
|
|
58 |
BMUSBCapture::start_bm_thread();
|
|
59 |
rt->capture->start_bm_capture();
|
|
60 |
|
|
61 |
rt->initialized = true;
|
|
62 |
|
|
63 |
UNUSED_PARAMETER(settings);
|
|
64 |
UNUSED_PARAMETER(source);
|
|
65 |
return rt;
|
|
66 |
}
|
|
67 |
|
|
68 |
struct obs_source_info bmusb_source_info = {
|
|
69 |
.id = "bmusb",
|
|
70 |
.type = OBS_SOURCE_TYPE_INPUT,
|
|
71 |
.output_flags = OBS_SOURCE_ASYNC_VIDEO,
|
|
72 |
.get_name = bmusb_getname,
|
|
73 |
.create = bmusb_create,
|
|
74 |
.destroy = bmusb_destroy,
|
|
75 |
};
|
|
76 |
|
|
77 |
OBS_DECLARE_MODULE()
|
|
78 |
|
|
79 |
extern "C" bool obs_module_load(void)
|
|
80 |
{
|
|
81 |
obs_register_source(&bmusb_source_info);
|
|
82 |
return true;
|
|
83 |
}
|