diff options
| author | s-ol <s+removethis@s-ol.nu> | 2021-04-14 18:43:12 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2021-04-14 18:43:12 +0000 |
| commit | b1d68ddc27654286944610cf210e7b7895162875 (patch) | |
| tree | 07a56aeccf11d2e0d99692ce8cf6aa0396609ee5 /bmusb-source.cpp | |
| parent | get it barely working (diff) | |
| download | obs-bmusb-master.tar.gz obs-bmusb-master.zip | |
Diffstat (limited to 'bmusb-source.cpp')
| -rw-r--r-- | bmusb-source.cpp | 133 |
1 files changed, 90 insertions, 43 deletions
diff --git a/bmusb-source.cpp b/bmusb-source.cpp index f41dee6..b914c89 100644 --- a/bmusb-source.cpp +++ b/bmusb-source.cpp @@ -6,7 +6,15 @@ #include <bmusb/fake_capture.h> #include <iostream> -#undef BMUSB_AUDIO +#define COLOR_SPACE "color_space" +#define COLOR_RANGE "color_range" + +#define TEXT_COLOR_SPACE obs_module_text("ColorSpace") +#define TEXT_COLOR_SPACE_DEFAULT obs_module_text("ColorSpace.Default") +#define TEXT_COLOR_RANGE obs_module_text("ColorRange") +#define TEXT_COLOR_RANGE_DEFAULT obs_module_text("ColorRange.Default") +#define TEXT_COLOR_RANGE_PARTIAL obs_module_text("ColorRange.Partial") +#define TEXT_COLOR_RANGE_FULL obs_module_text("ColorRange.Full") namespace b = bmusb; @@ -14,36 +22,26 @@ struct bmusb_inst { obs_source_t *source; b::CaptureInterface *capture; bool initialized; + + video_colorspace space = VIDEO_CS_DEFAULT; + video_range_type range = VIDEO_RANGE_DEFAULT; }; -static const char *bmusb_getname(void *unused) +static const char *bmusb_get_name(void *unused) { UNUSED_PARAMETER(unused); return "Blackmagic USB3 source (bmusb)"; } -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; - 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 b::BMUSBCapture(0); // @TODO select card + *rt = { + .source = source, + .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, @@ -59,20 +57,6 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source) return; } - if (video_format.interlaced) { - std::cerr << "oh no, video is interlaced" << std::endl; - video_frame.owner->release_frame(video_frame); - audio_frame.owner->release_frame(audio_frame); - return; - } - - if (video_frame.interleaved) { - std::cerr << "oh no, video is interleaved" << std::endl; - video_frame.owner->release_frame(video_frame); - 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); @@ -87,9 +71,9 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source) 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.full_range = rt->range == VIDEO_RANGE_FULL; + video_format_get_parameters(rt->space, rt->range, frame.color_matrix, frame.color_range_min, frame.color_range_max); @@ -114,8 +98,13 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source) default: audio.speakers = SPEAKERS_UNKNOWN; break; } obs_source_output_audio(rt->source, &audio); +#else + UNUSED_PARAMETER(audio_offset); + UNUSED_PARAMETER(audio_format); #endif audio_frame.owner->release_frame(audio_frame); + + UNUSED_PARAMETER(timecode); } ); rt->capture->configure_card(); @@ -129,20 +118,78 @@ static void *bmusb_create(obs_data_t *settings, obs_source_t *source) return rt; } +static void bmusb_destroy(void *data) +{ + struct bmusb_inst *rt = (bmusb_inst *) data; + if (rt) { + if (rt->initialized) { + delete rt->capture; + b::BMUSBCapture::stop_bm_thread(); + } + + bfree(rt); + } +} + +static void bmusb_update(void *data, obs_data_t *settings) +{ + struct bmusb_inst *rt = (bmusb_inst *) data; + + rt->space = (video_colorspace)obs_data_get_int(settings, COLOR_SPACE); + rt->range = (video_range_type)obs_data_get_int(settings, COLOR_RANGE); +} + +static void bmusb_get_defaults(obs_data_t *settings) +{ + obs_data_set_default_int(settings, COLOR_SPACE, VIDEO_CS_DEFAULT); + obs_data_set_default_int(settings, COLOR_RANGE, VIDEO_RANGE_DEFAULT); +} + +static obs_properties_t *bmusb_get_properties(void *data) +{ + obs_properties_t *props = obs_properties_create(); + + obs_property_t *list = obs_properties_add_list(props, COLOR_SPACE, TEXT_COLOR_SPACE, + OBS_COMBO_TYPE_LIST, + OBS_COMBO_FORMAT_INT); + obs_property_list_add_int(list, TEXT_COLOR_SPACE_DEFAULT, + VIDEO_CS_DEFAULT); + obs_property_list_add_int(list, "BT.601", VIDEO_CS_601); + obs_property_list_add_int(list, "BT.709", VIDEO_CS_709); + + list = obs_properties_add_list(props, COLOR_RANGE, TEXT_COLOR_RANGE, + OBS_COMBO_TYPE_LIST, + OBS_COMBO_FORMAT_INT); + obs_property_list_add_int(list, TEXT_COLOR_RANGE_DEFAULT, + VIDEO_RANGE_DEFAULT); + obs_property_list_add_int(list, TEXT_COLOR_RANGE_PARTIAL, + VIDEO_RANGE_PARTIAL); + obs_property_list_add_int(list, TEXT_COLOR_RANGE_FULL, + VIDEO_RANGE_FULL); + + UNUSED_PARAMETER(data); + return props; +} + + struct obs_source_info bmusb_source_info = { - .id = "bmusb", - .type = OBS_SOURCE_TYPE_INPUT, + .id = "bmusb", + .type = OBS_SOURCE_TYPE_INPUT, #ifdef BMUSB_AUDIO - .output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO, + .output_flags = OBS_SOURCE_ASYNC_VIDEO | OBS_SOURCE_AUDIO, #else - .output_flags = OBS_SOURCE_ASYNC_VIDEO, + .output_flags = OBS_SOURCE_ASYNC_VIDEO, #endif - .get_name = bmusb_getname, - .create = bmusb_create, - .destroy = bmusb_destroy, + .get_name = bmusb_get_name, + .create = bmusb_create, + .destroy = bmusb_destroy, + .get_defaults = bmusb_get_defaults, + .get_properties = bmusb_get_properties, + .update = bmusb_update, }; OBS_DECLARE_MODULE() +OBS_MODULE_USE_DEFAULT_LOCALE("decklink", "en-US") extern "C" bool obs_module_load(void) { |
