From 7d136c3ce11c7e7255e6713317307c38304d9d4a Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 25 Apr 2019 13:32:32 -0700 Subject: [PATCH] decklink, win-dshow: Use obs_source_output_video2 Allows the ability to override and use partial range RGB with the DirectShow and Decklink device sources when partial range RGB is implemented. Fixes certain cases where devices could capture RGB in limited range via HDMI (per the HDMI specs). --- plugins/decklink/decklink-device-instance.cpp | 4 ++-- plugins/decklink/decklink-device-instance.hpp | 2 +- plugins/win-dshow/ffmpeg-decode.c | 13 +++++-------- plugins/win-dshow/ffmpeg-decode.h | 2 +- plugins/win-dshow/win-dshow.cpp | 16 +++++++--------- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/plugins/decklink/decklink-device-instance.cpp b/plugins/decklink/decklink-device-instance.cpp index 9b7e48090..e2e13d13a 100644 --- a/plugins/decklink/decklink-device-instance.cpp +++ b/plugins/decklink/decklink-device-instance.cpp @@ -135,7 +135,7 @@ void DeckLinkDeviceInstance::HandleVideoFrame( currentFrame.height = (uint32_t)videoFrame->GetHeight(); currentFrame.timestamp = timestamp; - obs_source_output_video(static_cast(decklink)->GetSource(), ¤tFrame); + obs_source_output_video2(static_cast(decklink)->GetSource(), ¤tFrame); } void DeckLinkDeviceInstance::FinalizeStream() @@ -177,7 +177,7 @@ void DeckLinkDeviceInstance::SetupVideoFormat(DeckLinkDeviceMode *mode_) } colorRange = static_cast(decklink)->GetColorRange(); - currentFrame.full_range = colorRange == VIDEO_RANGE_FULL; + currentFrame.range = colorRange; video_format_get_parameters(activeColorSpace, colorRange, currentFrame.color_matrix, currentFrame.color_range_min, diff --git a/plugins/decklink/decklink-device-instance.hpp b/plugins/decklink/decklink-device-instance.hpp index bf03d82af..bee60e2f4 100644 --- a/plugins/decklink/decklink-device-instance.hpp +++ b/plugins/decklink/decklink-device-instance.hpp @@ -11,7 +11,7 @@ class DecklinkBase; class DeckLinkDeviceInstance : public IDeckLinkInputCallback { protected: - struct obs_source_frame currentFrame; + struct obs_source_frame2 currentFrame; struct obs_source_audio currentPacket; DecklinkBase *decklink = nullptr; DeckLinkDevice *device = nullptr; diff --git a/plugins/win-dshow/ffmpeg-decode.c b/plugins/win-dshow/ffmpeg-decode.c index 196495631..5fba70014 100644 --- a/plugins/win-dshow/ffmpeg-decode.c +++ b/plugins/win-dshow/ffmpeg-decode.c @@ -181,7 +181,7 @@ bool ffmpeg_decode_audio(struct ffmpeg_decode *decode, bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data, size_t size, long long *ts, - struct obs_source_frame *frame, + struct obs_source_frame2 *frame, bool *got_output) { AVPacket packet = {0}; @@ -230,17 +230,14 @@ bool ffmpeg_decode_video(struct ffmpeg_decode *decode, new_format = convert_pixel_format(decode->frame->format); if (new_format != frame->format) { bool success; - enum video_range_type range; frame->format = new_format; - frame->full_range = - decode->frame->color_range == AVCOL_RANGE_JPEG; - - range = frame->full_range ? - VIDEO_RANGE_FULL : VIDEO_RANGE_PARTIAL; + frame->range = decode->frame->color_range == AVCOL_RANGE_JPEG + ? VIDEO_RANGE_FULL + : VIDEO_RANGE_DEFAULT; success = video_format_get_parameters(VIDEO_CS_601, - range, frame->color_matrix, + frame->range, frame->color_matrix, frame->color_range_min, frame->color_range_max); if (!success) { blog(LOG_ERROR, "Failed to get video format " diff --git a/plugins/win-dshow/ffmpeg-decode.h b/plugins/win-dshow/ffmpeg-decode.h index d5cb8526f..1a52b8e1e 100644 --- a/plugins/win-dshow/ffmpeg-decode.h +++ b/plugins/win-dshow/ffmpeg-decode.h @@ -56,7 +56,7 @@ extern bool ffmpeg_decode_audio(struct ffmpeg_decode *decode, extern bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data, size_t size, long long *ts, - struct obs_source_frame *frame, + struct obs_source_frame2 *frame, bool *got_output); static inline bool ffmpeg_decode_valid(struct ffmpeg_decode *decode) diff --git a/plugins/win-dshow/win-dshow.cpp b/plugins/win-dshow/win-dshow.cpp index 804a393a7..562057bd5 100644 --- a/plugins/win-dshow/win-dshow.cpp +++ b/plugins/win-dshow/win-dshow.cpp @@ -176,7 +176,7 @@ struct DShowInput { VideoConfig videoConfig; AudioConfig audioConfig; - obs_source_frame frame; + obs_source_frame2 frame; obs_source_audio audio; WinHandle semaphore; @@ -327,7 +327,7 @@ void DShowInput::DShowLoop() obs_data_t *settings; settings = obs_source_get_settings(source); if (!Activate(settings)) { - obs_source_output_video(source, + obs_source_output_video2(source, nullptr); } if (block) @@ -468,7 +468,7 @@ void DShowInput::OnEncodedVideoData(enum AVCodecID id, #if LOG_ENCODED_VIDEO_TS blog(LOG_DEBUG, "video ts: %llu", frame.timestamp); #endif - obs_source_output_video(source, &frame); + obs_source_output_video2(source, &frame); } } @@ -537,7 +537,7 @@ void DShowInput::OnVideoData(const VideoConfig &config, return; } - obs_source_output_video(source, &frame); + obs_source_output_video2(source, &frame); UNUSED_PARAMETER(endTime); /* it's the enndd tiimmes! */ UNUSED_PARAMETER(size); @@ -1040,15 +1040,13 @@ inline bool DShowInput::Activate(obs_data_t *settings) return false; enum video_colorspace cs = GetColorSpace(settings); - - video_range_type range = GetColorRange(settings); - frame.full_range = range == VIDEO_RANGE_FULL; + frame.range = GetColorRange(settings); if (device.Start() != Result::Success) return false; bool success = video_format_get_parameters( - cs, range, + cs, frame.range, frame.color_matrix, frame.color_range_min, frame.color_range_max); @@ -1063,7 +1061,7 @@ inline bool DShowInput::Activate(obs_data_t *settings) inline void DShowInput::Deactivate() { device.ResetGraph(); - obs_source_output_video(source, nullptr); + obs_source_output_video2(source, nullptr); } /* ------------------------------------------------------------------------- */