git.s-ol.nu obs-bmusb / 70effbd
get it barely working s-ol 5 months ago
3 changed file(s) with 41 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1414 bmusb
1515 ${BMUSB_LIBRARIES})
1616
17 install_obs_plugin_with_data(obs-bmusb data)
17 install_obs_plugin(obs-bmusb)
22 `obs-bmusb` is a Linux plugin for [OBS studio][obs] that provides a Source for capturing from the BlackMagic USB3 cards
33 Intensity Shuttle and UltraStudio SDI via the [bmusb][bmusb] driver.
44
5 ## Building
6
7 > When in doubt, follow [the OBS development instructions](https://obsproject.com/wiki/Getting-Started-with-OBS-Studio-Development)
8
9
10 git clone --recursive https://github.com/obsproject/obs-studio.git # clone OBS source
11 cd obs-studio
12
13 git submodule add https://git.s-ol.nu/obs-bmusb.git plugins/obs-bmusb # add obs-bmusb submodule
14 echo 'add_subdirectory(obs-bmusb)' >> plugins/CMakeLists.txt # add plugin to cmake
15 cmake . # generate makefile
16 make # build
517
618 [obs]: https://obsproject.com/
719 [bmusb]: https://git.sesse.net/?p=bmusb;a=summary
22 #include <util/platform.h>
33 #include <obs-module.h>
44 #include <bmusb/bmusb.h>
5 #include <bmusb/fake_capture.h>
56 #include <iostream>
67
7 using bmusb::BMUSBCapture;
8 using bmusb::FrameAllocator;
9 using bmusb::VideoFormat;
10 using bmusb::AudioFormat;
8 #undef BMUSB_AUDIO
9
10 namespace b = bmusb;
1111
1212 struct bmusb_inst {
1313 obs_source_t *source;
14 BMUSBCapture *capture;
14 b::CaptureInterface *capture;
1515 bool initialized;
1616 };
1717
2626 struct bmusb_inst *rt = (bmusb_inst *) data;
2727
2828 if (rt) {
29 std::cout << "DESTROY\n";
2930 if (rt->initialized) {
3031 delete rt->capture;
31 BMUSBCapture::stop_bm_thread();
32 b::BMUSBCapture::stop_bm_thread();
3233 }
3334
3435 bfree(rt);
3536 }
3637 }
3738
39
3840 static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
3941 {
4042 struct bmusb_inst *rt = (bmusb_inst *) bzalloc(sizeof(struct bmusb_inst));
4143 rt->source = source;
4244
43 rt->capture = new BMUSBCapture(0); // @TODO select card
44 rt->capture->set_pixel_format(bmusb::PixelFormat_8BitYCbCr);
45 rt->capture = new b::BMUSBCapture(0); // @TODO select card
46 rt->capture->set_pixel_format(b::PixelFormat_8BitYCbCr);
4547 rt->capture->set_frame_callback(
4648 [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 b::FrameAllocator::Frame video_frame, size_t video_offset, b::VideoFormat video_format,
50 b::FrameAllocator::Frame audio_frame, size_t audio_offset, b::AudioFormat audio_format
4951 ) {
5052 uint64_t cur_time = os_gettime_ns();
5153
5658 return;
5759 }
5860
59 uint8_t num_fields = video_format.interlaced ? 2 : 1;
6061 if (video_format.interlaced) {
6162 std::cerr << "oh no, video is interlaced" << std::endl;
6263 video_frame.owner->release_frame(video_frame);
7071 audio_frame.owner->release_frame(audio_frame);
7172 return;
7273 }
74
75 if (video_frame.data == nullptr) {
76 std::cerr << "oh no, data is NULL" << std::endl;
77 video_frame.owner->release_frame(video_frame);
78 audio_frame.owner->release_frame(audio_frame);
79 return;
80 }
81
7382 struct obs_source_frame frame;
7483 frame.width = video_format.width;
7584 frame.height = video_format.height;
7685 frame.format = VIDEO_FORMAT_UYVY;
77 frame.linesize[0] = frame.width * 2;
86 frame.linesize[0] = video_format.stride;
7887 frame.data[0] = video_frame.data + video_offset;
7988 frame.timestamp = cur_time;
89 frame.full_range = 1;
90 frame.flip = 0;
91 video_format_get_parameters(VIDEO_CS_DEFAULT, VIDEO_RANGE_FULL,
92 frame.color_matrix, frame.color_range_min, frame.color_range_max);
93
94
8095 obs_source_output_video(rt->source, &frame);
8196 video_frame.owner->release_frame(video_frame);
8297
103118 }
104119 );
105120 rt->capture->configure_card();
106 BMUSBCapture::start_bm_thread();
121 b::BMUSBCapture::start_bm_thread();
107122 rt->capture->start_bm_capture();
108123
109124 rt->initialized = true;