git.s-ol.nu obs-bmusb / 5e1e6ee
initial commit - WIP s-ol 4 years ago
3 changed file(s) with 110 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 project(obs-bmusb)
1
2 set(obs-bmusb_SOURCES
3 bmusb-source.cpp)
4
5 find_package(PkgConfig REQUIRED)
6 pkg_check_modules(BMUSB REQUIRED bmusb)
7
8 add_library(obs-bmusb MODULE
9 ${obs-bmusb_SOURCES})
10 target_include_directories(obs-bmusb PUBLIC
11 ${BMUSB_INCLUDE_DIRS})
12 target_link_libraries(obs-bmusb
13 libobs
14 bmusb
15 ${BMUSB_LIBRARIES})
16
17 install_obs_plugin_with_data(obs-bmusb data)
0 obs-bmusb
1 =========
2 `obs-bmusb` is a Linux plugin for [OBS studio][obs] that provides a Source for capturing from the BlackMagic USB3 cards
3 Intensity Shuttle and UltraStudio SDI via the [bmusb][bmusb] driver.
4
5
6 [obs]: https://obsproject.com/
7 [bmusb]: https://git.sesse.net/?p=bmusb;a=summary
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 }