git.s-ol.nu obs-bmusb / 5e1e6ee
initial commit - WIP s-ol 1 year, 26 days ago
3 changed file(s) with 110 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1 project(obs-bmusb)
2
3 set(obs-bmusb_SOURCES
4 bmusb-source.cpp)
5
6 find_package(PkgConfig REQUIRED)
7 pkg_check_modules(BMUSB REQUIRED bmusb)
8
9 add_library(obs-bmusb MODULE
10 ${obs-bmusb_SOURCES})
11 target_include_directories(obs-bmusb PUBLIC
12 ${BMUSB_INCLUDE_DIRS})
13 target_link_libraries(obs-bmusb
14 libobs
15 bmusb
16 ${BMUSB_LIBRARIES})
17
18 install_obs_plugin_with_data(obs-bmusb data)
1 obs-bmusb
2 =========
3 `obs-bmusb` is a Linux plugin for [OBS studio][obs] that provides a Source for capturing from the BlackMagic USB3 cards
4 Intensity Shuttle and UltraStudio SDI via the [bmusb][bmusb] driver.
5
6
7 [obs]: https://obsproject.com/
8 [bmusb]: https://git.sesse.net/?p=bmusb;a=summary
1 #include <stdlib.h>
2 #include <obs.h>
3 #include <obs-module.h>
4 #include <bmusb/bmusb.h>
5
6 #include <stdio.h>
7
8 using bmusb::BMUSBCapture;
9 using bmusb::FrameAllocator;
10 using bmusb::VideoFormat;
11 using bmusb::AudioFormat;
12
13 struct bmusb_inst {
14 obs_source_t *source;
15 BMUSBCapture *capture;
16 bool initialized;
17 };
18
19 static const char *bmusb_getname(void *unused)
20 {
21 UNUSED_PARAMETER(unused);
22 return "Blackmagic USB3 source (bmusb)";
23 }
24
25 static void bmusb_destroy(void *data)
26 {
27 struct bmusb_inst *rt = (bmusb_inst *) data;
28
29 if (rt) {
30 if (rt->initialized) {
31 BMUSBCapture::stop_bm_thread();
32 delete rt->capture;
33 }
34
35 bfree(rt);
36 }
37 }
38
39 static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
40 {
41 struct bmusb_inst *rt = (bmusb_inst *) bzalloc(sizeof(struct bmusb_inst));
42 rt->source = source;
43
44 rt->capture = new BMUSBCapture(0); // @TODO select card
45 rt->capture->set_pixel_format(bmusb::PixelFormat_8BitYCbCr);
46 rt->capture->set_frame_callback(
47 [rt](uint16_t timecode,
48 FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
49 FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format
50 ) {
51 printf("got fraem %d\n", timecode);
52 UNUSED_PARAMETER(video_format);
53 UNUSED_PARAMETER(audio_format);
54 rt->capture->get_video_frame_allocator()->release_frame(video_frame);
55 rt->capture->get_audio_frame_allocator()->release_frame(audio_frame);
56 }
57 );
58 rt->capture->configure_card();
59 BMUSBCapture::start_bm_thread();
60 rt->capture->start_bm_capture();
61
62 rt->initialized = true;
63
64 UNUSED_PARAMETER(settings);
65 UNUSED_PARAMETER(source);
66 return rt;
67 }
68
69 struct obs_source_info bmusb_source_info = {
70 .id = "bmusb",
71 .type = OBS_SOURCE_TYPE_INPUT,
72 .output_flags = OBS_SOURCE_ASYNC_VIDEO,
73 .get_name = bmusb_getname,
74 .create = bmusb_create,
75 .destroy = bmusb_destroy,
76 };
77
78 OBS_DECLARE_MODULE()
79
80 extern "C" bool obs_module_load(void)
81 {
82 obs_register_source(&bmusb_source_info);
83 return true;
84 }