Преглед изворни кода

libobs,plugins: Replace video matrix function

video_format_get_parameters_for_format provides a more accurate matrix
than video_format_get_parameters.
jpark37 пре 3 година
родитељ
комит
848e128435

+ 3 - 4
deps/media-playback/media-playback/media.c

@@ -419,10 +419,9 @@ static void mp_media_next_video(mp_media_t *m, bool preload)
 		frame->format = new_format;
 		frame->full_range = new_range == VIDEO_RANGE_FULL;
 
-		success = video_format_get_parameters(new_space, new_range,
-						      frame->color_matrix,
-						      frame->color_range_min,
-						      frame->color_range_max);
+		success = video_format_get_parameters_for_format(
+			new_space, new_range, new_format, frame->color_matrix,
+			frame->color_range_min, frame->color_range_max);
 
 		frame->format = new_format;
 		m->cur_space = new_space;

+ 3 - 2
libobs/obs.c

@@ -546,8 +546,9 @@ static inline void set_video_matrix(struct obs_core_video *video,
 	struct vec4 r_row;
 
 	if (format_is_yuv(ovi->output_format)) {
-		video_format_get_parameters(ovi->colorspace, ovi->range,
-					    (float *)&mat, NULL, NULL);
+		video_format_get_parameters_for_format(
+			ovi->colorspace, ovi->range, ovi->output_format,
+			(float *)&mat, NULL, NULL);
 		matrix4_inv(&mat, &mat);
 
 		/* swap R and G */

+ 18 - 11
plugins/aja/aja-source.cpp

@@ -149,21 +149,25 @@ void AJASource::GenerateTestPattern(NTV2VideoFormat vf, NTV2PixelFormat pf,
 		return;
 	}
 
+	const enum video_format obs_vid_fmt =
+		aja::AJAPixelFormatToOBSVideoFormat(pix_fmt);
+
 	struct obs_source_frame2 obsFrame;
 	obsFrame.flip = false;
 	obsFrame.timestamp = os_gettime_ns();
 	obsFrame.width = fd.GetRasterWidth();
 	obsFrame.height = fd.GetRasterHeight();
-	obsFrame.format = aja::AJAPixelFormatToOBSVideoFormat(pix_fmt);
+	obsFrame.format = obs_vid_fmt;
 	obsFrame.data[0] = mTestPattern.data();
 	obsFrame.linesize[0] = fd.GetBytesPerRow();
 	video_colorspace colorspace = VIDEO_CS_709;
 	if (NTV2_IS_SD_VIDEO_FORMAT(vid_fmt))
 		colorspace = VIDEO_CS_601;
-	video_format_get_parameters(colorspace, VIDEO_RANGE_PARTIAL,
-				    obsFrame.color_matrix,
-				    obsFrame.color_range_min,
-				    obsFrame.color_range_max);
+	video_format_get_parameters_for_format(colorspace, VIDEO_RANGE_PARTIAL,
+					       obs_vid_fmt,
+					       obsFrame.color_matrix,
+					       obsFrame.color_range_min,
+					       obsFrame.color_range_max);
 	obs_source_output_video2(mSource, &obsFrame);
 	blog(LOG_DEBUG, "AJASource::GenerateTestPattern: Black");
 }
@@ -354,24 +358,27 @@ void AJASource::CaptureThread(AJAThread *thread, void *data)
 			actualVideoFormat = aja::GetLevelAFormatForLevelBFormat(
 				videoFormat);
 
+		const enum video_format obs_vid_fmt =
+			aja::AJAPixelFormatToOBSVideoFormat(
+				sourceProps.pixelFormat);
+
 		NTV2FormatDesc fd(actualVideoFormat, pixelFormat);
 		struct obs_source_frame2 obsFrame;
 		obsFrame.flip = false;
 		obsFrame.timestamp = os_gettime_ns();
 		obsFrame.width = fd.GetRasterWidth();
 		obsFrame.height = fd.GetRasterHeight();
-		obsFrame.format = aja::AJAPixelFormatToOBSVideoFormat(
-			sourceProps.pixelFormat);
+		obsFrame.format = obs_vid_fmt;
 		obsFrame.data[0] = reinterpret_cast<uint8_t *>(
 			(ULWord *)ajaSource->mVideoBuffer.GetHostPointer());
 		obsFrame.linesize[0] = fd.GetBytesPerRow();
 		video_colorspace colorspace = VIDEO_CS_709;
 		if (NTV2_IS_SD_VIDEO_FORMAT(actualVideoFormat))
 			colorspace = VIDEO_CS_601;
-		video_format_get_parameters(colorspace, VIDEO_RANGE_PARTIAL,
-					    obsFrame.color_matrix,
-					    obsFrame.color_range_min,
-					    obsFrame.color_range_max);
+		video_format_get_parameters_for_format(
+			colorspace, VIDEO_RANGE_PARTIAL, obs_vid_fmt,
+			obsFrame.color_matrix, obsFrame.color_range_min,
+			obsFrame.color_range_max);
 
 		obs_source_output_video2(ajaSource->mSource, &obsFrame);
 

+ 5 - 5
plugins/decklink/decklink-device-instance.cpp

@@ -305,7 +305,8 @@ void DeckLinkDeviceInstance::SetupVideoFormat(DeckLinkDeviceMode *mode_)
 	if (mode_ == nullptr)
 		return;
 
-	currentFrame.format = ConvertPixelFormat(pixelFormat);
+	const enum video_format format = ConvertPixelFormat(pixelFormat);
+	currentFrame.format = format;
 
 	colorSpace = static_cast<DeckLinkInput *>(decklink)->GetColorSpace();
 	if (colorSpace == VIDEO_CS_DEFAULT) {
@@ -323,10 +324,9 @@ void DeckLinkDeviceInstance::SetupVideoFormat(DeckLinkDeviceMode *mode_)
 	colorRange = static_cast<DeckLinkInput *>(decklink)->GetColorRange();
 	currentFrame.range = colorRange;
 
-	video_format_get_parameters(activeColorSpace, colorRange,
-				    currentFrame.color_matrix,
-				    currentFrame.color_range_min,
-				    currentFrame.color_range_max);
+	video_format_get_parameters_for_format(
+		activeColorSpace, colorRange, format, currentFrame.color_matrix,
+		currentFrame.color_range_min, currentFrame.color_range_max);
 
 	delete convertFrame;
 

+ 8 - 4
plugins/linux-v4l2/v4l2-input.c

@@ -121,12 +121,16 @@ static void v4l2_prep_obs_frame(struct v4l2_data *data,
 	memset(frame, 0, sizeof(struct obs_source_frame));
 	memset(plane_offsets, 0, sizeof(size_t) * MAX_AV_PLANES);
 
+	const enum video_format format = v4l2_to_obs_video_format(data->pixfmt);
+
 	frame->width = data->width;
 	frame->height = data->height;
-	frame->format = v4l2_to_obs_video_format(data->pixfmt);
-	video_format_get_parameters(VIDEO_CS_DEFAULT, data->color_range,
-				    frame->color_matrix, frame->color_range_min,
-				    frame->color_range_max);
+	frame->format = format;
+	video_format_get_parameters_for_format(VIDEO_CS_DEFAULT,
+					       data->color_range, format,
+					       frame->color_matrix,
+					       frame->color_range_min,
+					       frame->color_range_max);
 
 	switch (data->pixfmt) {
 	case V4L2_PIX_FMT_NV12:

+ 3 - 3
plugins/mac-avcapture/av-capture.mm

@@ -493,9 +493,9 @@ static inline bool update_colorspace(av_capture *capture,
 
 	frame->full_range = full_range;
 
-	if (!video_format_get_parameters(colorspace, range, frame->color_matrix,
-					 frame->color_range_min,
-					 frame->color_range_max)) {
+	if (!video_format_get_parameters_for_format(
+		    colorspace, range, frame->format, frame->color_matrix,
+		    frame->color_range_min, frame->color_range_max)) {
 		AVLOG(LOG_ERROR,
 		      "Failed to get colorspace parameters for "
 		      "colorspace %u range %u",

+ 4 - 4
plugins/vlc-video/vlc-video-source.c

@@ -420,10 +420,10 @@ static unsigned vlcs_video_format(void **p_data, char *chroma, unsigned *width,
 		c->frame.full_range = new_range;
 		range = c->frame.full_range ? VIDEO_RANGE_FULL
 					    : VIDEO_RANGE_PARTIAL;
-		video_format_get_parameters(VIDEO_CS_DEFAULT, range,
-					    c->frame.color_matrix,
-					    c->frame.color_range_min,
-					    c->frame.color_range_max);
+		video_format_get_parameters_for_format(
+			VIDEO_CS_DEFAULT, range, new_format,
+			c->frame.color_matrix, c->frame.color_range_min,
+			c->frame.color_range_max);
 	}
 
 	while (c->frame.data[i]) {

+ 5 - 3
plugins/win-dshow/ffmpeg-decode.c

@@ -368,7 +368,9 @@ bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
 		frame->linesize[i] = decode->frame->linesize[i];
 	}
 
-	frame->format = convert_pixel_format(decode->frame->format);
+	const enum video_format format =
+		convert_pixel_format(decode->frame->format);
+	frame->format = format;
 
 	if (range == VIDEO_RANGE_DEFAULT) {
 		range = (decode->frame->color_range == AVCOL_RANGE_JPEG)
@@ -379,8 +381,8 @@ bool ffmpeg_decode_video(struct ffmpeg_decode *decode, uint8_t *data,
 	const enum video_colorspace cs = convert_color_space(
 		decode->frame->colorspace, decode->frame->color_trc);
 
-	const bool success = video_format_get_parameters(
-		cs, range, frame->color_matrix, frame->color_range_min,
+	const bool success = video_format_get_parameters_for_format(
+		cs, range, format, frame->color_matrix, frame->color_range_min,
 		frame->color_range_max);
 	if (!success) {
 		blog(LOG_ERROR,

+ 4 - 4
plugins/win-dshow/win-dshow.cpp

@@ -1140,10 +1140,10 @@ inline bool DShowInput::Activate(obs_data_t *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);
+	bool success = video_format_get_parameters_for_format(
+		cs, range, ConvertVideoFormat(videoConfig.format),
+		frame.color_matrix, frame.color_range_min,
+		frame.color_range_max);
 	if (!success) {
 		blog(LOG_ERROR,
 		     "Failed to get video format parameters for "