2 | 2 |
#include <util/platform.h>
|
3 | 3 |
#include <obs-module.h>
|
4 | 4 |
#include <bmusb/bmusb.h>
|
|
5 |
#include <bmusb/fake_capture.h>
|
5 | 6 |
#include <iostream>
|
6 | 7 |
|
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;
|
11 | 11 |
|
12 | 12 |
struct bmusb_inst {
|
13 | 13 |
obs_source_t *source;
|
14 | |
BMUSBCapture *capture;
|
|
14 |
b::CaptureInterface *capture;
|
15 | 15 |
bool initialized;
|
16 | 16 |
};
|
17 | 17 |
|
|
26 | 26 |
struct bmusb_inst *rt = (bmusb_inst *) data;
|
27 | 27 |
|
28 | 28 |
if (rt) {
|
|
29 |
std::cout << "DESTROY\n";
|
29 | 30 |
if (rt->initialized) {
|
30 | 31 |
delete rt->capture;
|
31 | |
BMUSBCapture::stop_bm_thread();
|
|
32 |
b::BMUSBCapture::stop_bm_thread();
|
32 | 33 |
}
|
33 | 34 |
|
34 | 35 |
bfree(rt);
|
35 | 36 |
}
|
36 | 37 |
}
|
37 | 38 |
|
|
39 |
|
38 | 40 |
static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
|
39 | 41 |
{
|
40 | 42 |
struct bmusb_inst *rt = (bmusb_inst *) bzalloc(sizeof(struct bmusb_inst));
|
41 | 43 |
rt->source = source;
|
42 | 44 |
|
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);
|
45 | 47 |
rt->capture->set_frame_callback(
|
46 | 48 |
[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
|
49 | 51 |
) {
|
50 | 52 |
uint64_t cur_time = os_gettime_ns();
|
51 | 53 |
|
|
56 | 58 |
return;
|
57 | 59 |
}
|
58 | 60 |
|
59 | |
uint8_t num_fields = video_format.interlaced ? 2 : 1;
|
60 | 61 |
if (video_format.interlaced) {
|
61 | 62 |
std::cerr << "oh no, video is interlaced" << std::endl;
|
62 | 63 |
video_frame.owner->release_frame(video_frame);
|
|
70 | 71 |
audio_frame.owner->release_frame(audio_frame);
|
71 | 72 |
return;
|
72 | 73 |
}
|
|
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 |
|
73 | 82 |
struct obs_source_frame frame;
|
74 | 83 |
frame.width = video_format.width;
|
75 | 84 |
frame.height = video_format.height;
|
76 | 85 |
frame.format = VIDEO_FORMAT_UYVY;
|
77 | |
frame.linesize[0] = frame.width * 2;
|
|
86 |
frame.linesize[0] = video_format.stride;
|
78 | 87 |
frame.data[0] = video_frame.data + video_offset;
|
79 | 88 |
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 |
|
80 | 95 |
obs_source_output_video(rt->source, &frame);
|
81 | 96 |
video_frame.owner->release_frame(video_frame);
|
82 | 97 |
|
|
103 | 118 |
}
|
104 | 119 |
);
|
105 | 120 |
rt->capture->configure_card();
|
106 | |
BMUSBCapture::start_bm_thread();
|
|
121 |
b::BMUSBCapture::start_bm_thread();
|
107 | 122 |
rt->capture->start_bm_capture();
|
108 | 123 |
|
109 | 124 |
rt->initialized = true;
|