Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests: Add Deinterlacing Functionality #1192

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

asoulliereHT
Copy link

@asoulliereHT asoulliereHT commented Dec 18, 2023

Description

Added GetSourceDeinterlaceMode, SetSourceDeinterlaceMode, GetSourceDeinterlaceFieldOrder, SetSourceDeinterlaceFieldOrder

Motivation and Context

There's currently no way to get/set the deinterlacing settings on a source. I needed the ability to enable deinterlacing via websockets for an automation project.

This PR addresses #1183

How Has This Been Tested?

I built the plugin with the latest release of OBS and tested using postman calls.
Tested OS(s):

  • Windows 10
  • macOS Ventura

Types of changes

  • New request/event (non-breaking)

Checklist:

  • I have read the Contributing Guidelines.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • My code is not on master or a release/* branch.
  • The code has been tested.
  • I have included updates to all appropriate documentation.

Copy link

@NoTalkOnlyProx NoTalkOnlyProx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look, I am not an OBS maintainer, but you mentioned you are desperate for some feedback, so I decided to donate some of my time to your cause.

I think a good first step for you to get this PR back in motion is to switch to using NLOHMANN_JSON_SERIALIZE_ENUM, so that your contributions conform with what already exists

Comment on lines +359 to +388
case OBS_DEINTERLACE_MODE_DISABLE:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_DISABLE";
break;
case OBS_DEINTERLACE_MODE_DISCARD:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_DISCARD";
break;
case OBS_DEINTERLACE_MODE_RETRO:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_RETRO";
break;
case OBS_DEINTERLACE_MODE_BLEND:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_BLEND";
break;
case OBS_DEINTERLACE_MODE_BLEND_2X:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_BLEND_2X";
break;
case OBS_DEINTERLACE_MODE_LINEAR:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_LINEAR";
break;
case OBS_DEINTERLACE_MODE_LINEAR_2X:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_LINEAR_2X";
break;
case OBS_DEINTERLACE_MODE_YADIF:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_YADIF";
break;
case OBS_DEINTERLACE_MODE_YADIF_2X:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_YADIF_2X";
break;
default:
responseData["sourceDeinterlaceMode"] = "OBS_DEINTERLACE_MODE_DISABLE";
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, hardcoding these outputs with a switch is an anti-pattern.

Previous contributions all use the NLOHMANN_JSON_SERIALIZE_ENUM macro.

For example, take a look at RequestHandler::GetMediaInputStatus.

Specifically, these lines:

json responseData;
responseData["mediaState"] = obs_source_media_get_state(input);

obs_source_media_get_state returns enum obs_media_state not a string.

I suggest you follow the same pattern, if you want this to be merged.

See obs-studio\plugins\obs-websocket\src\utils\Json.h. This seems to be the place where this syntactic sugar is setup.

For example:

NLOHMANN_JSON_SERIALIZE_ENUM(obs_media_state, {
						      {OBS_MEDIA_STATE_NONE, "OBS_MEDIA_STATE_NONE"},
						      {OBS_MEDIA_STATE_PLAYING, "OBS_MEDIA_STATE_PLAYING"},
						      {OBS_MEDIA_STATE_OPENING, "OBS_MEDIA_STATE_OPENING"},
						      {OBS_MEDIA_STATE_BUFFERING, "OBS_MEDIA_STATE_BUFFERING"},
						      {OBS_MEDIA_STATE_PAUSED, "OBS_MEDIA_STATE_PAUSED"},
						      {OBS_MEDIA_STATE_STOPPED, "OBS_MEDIA_STATE_STOPPED"},
						      {OBS_MEDIA_STATE_ENDED, "OBS_MEDIA_STATE_ENDED"},
						      {OBS_MEDIA_STATE_ERROR, "OBS_MEDIA_STATE_ERROR"},
					      })

Comment on lines +414 to +435
if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_DISABLE") {
deinterlaceMode = OBS_DEINTERLACE_MODE_DISABLE;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_DISCARD") {
deinterlaceMode = OBS_DEINTERLACE_MODE_DISCARD;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_RETRO") {
deinterlaceMode = OBS_DEINTERLACE_MODE_RETRO;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_BLEND") {
deinterlaceMode = OBS_DEINTERLACE_MODE_BLEND;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_BLEND_2X") {
deinterlaceMode = OBS_DEINTERLACE_MODE_BLEND_2X;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_LINEAR") {
deinterlaceMode = OBS_DEINTERLACE_MODE_LINEAR;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_LINEAR_2X") {
deinterlaceMode = OBS_DEINTERLACE_MODE_LINEAR_2X;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_YADIF") {
deinterlaceMode = OBS_DEINTERLACE_MODE_YADIF;
} else if (sourceDeinterlaceModeString == "OBS_DEINTERLACE_MODE_YADIF_2X") {
deinterlaceMode = OBS_DEINTERLACE_MODE_YADIF_2X;
} else {
return RequestResult::Error(RequestStatus::InvalidRequestField,
"Your specified deinterlace mode is invalid or not supported by this system.");
}
Copy link

@NoTalkOnlyProx NoTalkOnlyProx Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here. This can all be replaced by taking advantage of the NLOHMANN_JSON_SERIALIZE_ENUM macro. Possibly there is other setup required for it to work, too, but you can find that out by trying it out yourself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants