Переглянути джерело

win-dshow: Add option to allow vertical flip

I'm putting this option in due to the fact that there are legitimate
cases where a device may flip the output unexpectedly (such as the
Datapath VisionDVI-DL running in RGB video format), and that a user may
want to be able to view the source in a projector or source properties
without the image being inverted.

My original line of thinking was that they can just use a transform to
flip the image, but I felt this problem impacts rendering everywhere,
such as in the projector and in the source properties, so having it as
an option in the source itself feels like the best way to ensure that a
user can get it to render everywhere properly.
jp9000 10 роки тому
батько
коміт
13051da0e8

+ 1 - 0
plugins/win-dshow/data/locale/en-US.ini

@@ -26,6 +26,7 @@ Buffering.Enable="Enable"
 Buffering.Disable="Disable"
 Activate="Activate"
 Deactivate="Deactivate"
+FlipVertically="Flip Vertically"
 
 # encoder text
 Bitrate="Bitrate"

+ 11 - 0
plugins/win-dshow/win-dshow.cpp

@@ -37,6 +37,7 @@ using namespace DShow;
 #define LAST_VIDEO_DEV_ID "last_video_device_id"
 #define LAST_RESOLUTION   "last_resolution"
 #define BUFFERING_VAL     "buffering"
+#define FLIP_IMAGE        "flip_vertically"
 #define USE_CUSTOM_AUDIO  "use_custom_audio_device"
 #define AUDIO_DEVICE_ID   "audio_device_id"
 #define COLOR_SPACE       "color_space"
@@ -58,6 +59,7 @@ using namespace DShow;
 #define TEXT_BUFFERING_AUTO obs_module_text("Buffering.AutoDetect")
 #define TEXT_BUFFERING_ON   obs_module_text("Buffering.Enable")
 #define TEXT_BUFFERING_OFF  obs_module_text("Buffering.Disable")
+#define TEXT_FLIP_IMAGE     obs_module_text("FlipVertically")
 #define TEXT_CUSTOM_AUDIO   obs_module_text("UseCustomAudioDevice")
 #define TEXT_AUDIO_DEVICE   obs_module_text("AudioDevice")
 #define TEXT_ACTIVATE       obs_module_text("Activate")
@@ -154,6 +156,7 @@ struct DShowInput {
 	obs_source_t *source;
 	Device       device;
 	bool         deviceHasAudio = false;
+	bool         flip = false;
 	bool         active = false;
 
 	Decoder      audio_decoder;
@@ -407,6 +410,8 @@ void DShowInput::OnEncodedVideoData(enum AVCodecID id,
 
 	if (got_output) {
 		frame.timestamp = (uint64_t)ts * 100;
+		if (flip)
+			frame.flip = !frame.flip;
 #if LOG_ENCODED_VIDEO_TS
 		blog(LOG_DEBUG, "video ts: %llu", frame.timestamp);
 #endif
@@ -434,6 +439,9 @@ void DShowInput::OnVideoData(const VideoConfig &config,
 	frame.flip       = (config.format == VideoFormat::XRGB ||
 	                    config.format == VideoFormat::ARGB);
 
+	if (flip)
+		frame.flip = !frame.flip;
+
 	if (videoConfig.format == VideoFormat::XRGB ||
 	    videoConfig.format == VideoFormat::ARGB) {
 		frame.data[0]     = data;
@@ -728,6 +736,7 @@ inline void DShowInput::SetupBuffering(obs_data_t *settings)
 bool DShowInput::UpdateVideoConfig(obs_data_t *settings)
 {
 	string video_device_id = obs_data_get_string(settings, VIDEO_DEVICE_ID);
+	flip = obs_data_get_bool(settings, FLIP_IMAGE);
 
 	DeviceId id;
 	if (!DecodeDeviceId(id, video_device_id.c_str()))
@@ -1686,6 +1695,8 @@ static obs_properties_t *GetDShowProperties(void *obj)
 	obs_property_list_add_int(p, TEXT_BUFFERING_OFF,
 			(int64_t)BufferingType::Off);
 
+	obs_properties_add_bool(ppts, FLIP_IMAGE, TEXT_FLIP_IMAGE);
+
 	/* ------------------------------------- */
 	/* audio settings */