aboutsummaryrefslogtreecommitdiffstats
path: root/bmusb-source.cpp
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2021-04-14 17:27:55 +0000
committers-ol <s+removethis@s-ol.nu>2021-04-14 17:30:34 +0000
commit70effbd10f186450d1d3fd8b6768ec32862e444f (patch)
tree47d3fb98dcdf59faa54054d3c99985587fed09e9 /bmusb-source.cpp
parentprogress (diff)
downloadobs-bmusb-70effbd10f186450d1d3fd8b6768ec32862e444f.tar.gz
obs-bmusb-70effbd10f186450d1d3fd8b6768ec32862e444f.zip
get it barely working
Diffstat (limited to 'bmusb-source.cpp')
-rw-r--r--bmusb-source.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/bmusb-source.cpp b/bmusb-source.cpp
index 174d039..f41dee6 100644
--- a/bmusb-source.cpp
+++ b/bmusb-source.cpp
@@ -3,16 +3,16 @@
#include <util/platform.h>
#include <obs-module.h>
#include <bmusb/bmusb.h>
+#include <bmusb/fake_capture.h>
#include <iostream>
-using bmusb::BMUSBCapture;
-using bmusb::FrameAllocator;
-using bmusb::VideoFormat;
-using bmusb::AudioFormat;
+#undef BMUSB_AUDIO
+
+namespace b = bmusb;
struct bmusb_inst {
obs_source_t *source;
- BMUSBCapture *capture;
+ b::CaptureInterface *capture;
bool initialized;
};
@@ -27,26 +27,28 @@ static void bmusb_destroy(void *data)
struct bmusb_inst *rt = (bmusb_inst *) data;
if (rt) {
+ std::cout << "DESTROY\n";
if (rt->initialized) {
delete rt->capture;
- BMUSBCapture::stop_bm_thread();
+ b::BMUSBCapture::stop_bm_thread();
}
bfree(rt);
}
}
+
static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
{
struct bmusb_inst *rt = (bmusb_inst *) bzalloc(sizeof(struct bmusb_inst));
rt->source = source;
- rt->capture = new BMUSBCapture(0); // @TODO select card
- rt->capture->set_pixel_format(bmusb::PixelFormat_8BitYCbCr);
+ rt->capture = new b::BMUSBCapture(0); // @TODO select card
+ rt->capture->set_pixel_format(b::PixelFormat_8BitYCbCr);
rt->capture->set_frame_callback(
[rt](uint16_t timecode,
- FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format,
- FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format
+ b::FrameAllocator::Frame video_frame, size_t video_offset, b::VideoFormat video_format,
+ b::FrameAllocator::Frame audio_frame, size_t audio_offset, b::AudioFormat audio_format
) {
uint64_t cur_time = os_gettime_ns();
@@ -57,7 +59,6 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
return;
}
- uint8_t num_fields = video_format.interlaced ? 2 : 1;
if (video_format.interlaced) {
std::cerr << "oh no, video is interlaced" << std::endl;
video_frame.owner->release_frame(video_frame);
@@ -71,13 +72,27 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
audio_frame.owner->release_frame(audio_frame);
return;
}
+
+ if (video_frame.data == nullptr) {
+ std::cerr << "oh no, data is NULL" << std::endl;
+ video_frame.owner->release_frame(video_frame);
+ audio_frame.owner->release_frame(audio_frame);
+ return;
+ }
+
struct obs_source_frame frame;
frame.width = video_format.width;
frame.height = video_format.height;
frame.format = VIDEO_FORMAT_UYVY;
- frame.linesize[0] = frame.width * 2;
+ frame.linesize[0] = video_format.stride;
frame.data[0] = video_frame.data + video_offset;
frame.timestamp = cur_time;
+ frame.full_range = 1;
+ frame.flip = 0;
+ video_format_get_parameters(VIDEO_CS_DEFAULT, VIDEO_RANGE_FULL,
+ frame.color_matrix, frame.color_range_min, frame.color_range_max);
+
+
obs_source_output_video(rt->source, &frame);
video_frame.owner->release_frame(video_frame);
@@ -104,7 +119,7 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source)
}
);
rt->capture->configure_card();
- BMUSBCapture::start_bm_thread();
+ b::BMUSBCapture::start_bm_thread();
rt->capture->start_bm_capture();
rt->initialized = true;