win-dshow: Fix color range when using FFmpeg decode

Full color range seems to be active when decoding video with FFMmpeg
even when partial is explicitly selected. This should keep the range
synchronized.
This commit is contained in:
jpark37 2019-09-14 17:04:22 -07:00
parent 3064887ae2
commit f60b820fee
3 changed files with 20 additions and 15 deletions

View File

@ -273,11 +273,11 @@ bool ffmpeg_decode_audio(struct ffmpeg_decode *decode, uint8_t *data,
bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
size_t size, long long *ts,
enum video_range_type range,
struct obs_source_frame2 *frame, bool *got_output)
{
AVPacket packet = {0};
int got_frame = false;
enum video_format new_format;
AVFrame *out_frame;
int ret;
@ -337,17 +337,17 @@ bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
frame->linesize[i] = decode->frame->linesize[i];
}
new_format = convert_pixel_format(decode->frame->format);
if (new_format != frame->format) {
bool success;
frame->format = convert_pixel_format(decode->frame->format);
frame->format = new_format;
frame->range = decode->frame->color_range == AVCOL_RANGE_JPEG
? VIDEO_RANGE_FULL
: VIDEO_RANGE_DEFAULT;
if (range == VIDEO_RANGE_DEFAULT) {
range = (decode->frame->color_range == AVCOL_RANGE_JPEG)
? VIDEO_RANGE_FULL
: VIDEO_RANGE_PARTIAL;
}
success = video_format_get_parameters(
VIDEO_CS_601, frame->range, frame->color_matrix,
if (range != frame->range) {
const bool success = video_format_get_parameters(
VIDEO_CS_601, range, frame->color_matrix,
frame->color_range_min, frame->color_range_max);
if (!success) {
blog(LOG_ERROR,
@ -356,6 +356,8 @@ bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
VIDEO_CS_601);
return false;
}
frame->range = range;
}
*ts = decode->frame->pkt_pts;

View File

@ -58,6 +58,7 @@ extern bool ffmpeg_decode_audio(struct ffmpeg_decode *decode, uint8_t *data,
extern bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
size_t size, long long *ts,
enum video_range_type range,
struct obs_source_frame2 *frame,
bool *got_output);

View File

@ -178,6 +178,7 @@ struct DShowInput {
VideoConfig videoConfig;
AudioConfig audioConfig;
video_range_type range;
obs_source_frame2 frame;
obs_source_audio audio;
@ -481,7 +482,7 @@ void DShowInput::OnEncodedVideoData(enum AVCodecID id, unsigned char *data,
bool got_output;
bool success = ffmpeg_decode_video(video_decoder, data, size, &ts,
&frame, &got_output);
range, &frame, &got_output);
if (!success) {
blog(LOG_WARNING, "Error decoding video");
return;
@ -1079,13 +1080,14 @@ inline bool DShowInput::Activate(obs_data_t *settings)
if (!device.ConnectFilters())
return false;
enum video_colorspace cs = GetColorSpace(settings);
frame.range = GetColorRange(settings);
if (device.Start() != Result::Success)
return false;
bool success = video_format_get_parameters(cs, frame.range,
enum video_colorspace cs = GetColorSpace(settings);
range = GetColorRange(settings);
frame.range = range;
bool success = video_format_get_parameters(cs, range,
frame.color_matrix,
frame.color_range_min,
frame.color_range_max);