-
-
Notifications
You must be signed in to change notification settings - Fork 725
Requests: Add Deinterlacing Functionality #1192
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
Closed
asoulliereHT
wants to merge
7
commits into
obsproject:master
from
asoulliereHT:feature/deinterlacing
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c04eb2f
Requests: Add Deinterlacing Functionality
asoulliereHT af2653b
Merge branch 'master' into feature/deinterlacing
asoulliereHT 4e2278d
Merge branch 'master' into feature/deinterlacing
asoulliereHT ee77943
Merge branch 'master' into feature/deinterlacing
asoulliereHT 00abc22
Merge branch 'master' into feature/deinterlacing
asoulliereHT d2f26d0
Merge branch 'master' into feature/deinterlacing
asoulliereHT 5cb6e4d
Merge branch 'master' into feature/deinterlacing
asoulliereHT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,6 +317,211 @@ RequestResult RequestHandler::SaveSourceScreenshot(const Request &request) | |
return RequestResult::Success(); | ||
} | ||
|
||
/** | ||
* Gets the deinterlace mode of a source. | ||
* | ||
* Deinterlace modes: | ||
* | ||
* - `OBS_DEINTERLACE_MODE_DISABLE` | ||
* - `OBS_DEINTERLACE_MODE_DISCARD` | ||
* - `OBS_DEINTERLACE_MODE_RETRO` | ||
* - `OBS_DEINTERLACE_MODE_BLEND` | ||
* - `OBS_DEINTERLACE_MODE_BLEND_2X` | ||
* - `OBS_DEINTERLACE_MODE_LINEAR` | ||
* - `OBS_DEINTERLACE_MODE_LINEAR_2X` | ||
* - `OBS_DEINTERLACE_MODE_YADIF` | ||
* - `OBS_DEINTERLACE_MODE_YADIF_2X` | ||
* | ||
* **Compatible with inputs.** | ||
* | ||
* @requestField sourceName | String | Name of the source | ||
* | ||
* @responseField sourceDeinterlaceMode | String | Deinterlace mode | ||
* | ||
* @requestType GetSourceDeinterlaceMode | ||
* @api requests | ||
* @category sources | ||
*/ | ||
RequestResult RequestHandler::GetSourceDeinterlaceMode(const Request &request) | ||
{ | ||
RequestStatus::RequestStatus statusCode; | ||
std::string comment; | ||
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment); | ||
if (!source) | ||
return RequestResult::Error(statusCode, comment); | ||
|
||
if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT) | ||
return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input."); | ||
|
||
auto deinterlaceMode = obs_source_get_deinterlace_mode(source); | ||
|
||
json responseData; | ||
switch (deinterlaceMode) { | ||
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"; | ||
} | ||
|
||
return RequestResult::Success(responseData); | ||
} | ||
|
||
/** | ||
* Sets the deinterlace mode of a source. | ||
* | ||
* @requestField sourceName | String | Name of the source | ||
* @requestField sourceDeinterlaceMode | String | Deinterlace mode | ||
* | ||
* @requestType SetSourceDeinterlaceMode | ||
* @api requests | ||
* @category sources | ||
*/ | ||
RequestResult RequestHandler::SetSourceDeinterlaceMode(const Request &request) | ||
{ | ||
RequestStatus::RequestStatus statusCode; | ||
std::string comment; | ||
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment); | ||
if (!source || !request.ValidateString("sourceDeinterlaceMode", statusCode, comment)) | ||
return RequestResult::Error(statusCode, comment); | ||
|
||
enum obs_deinterlace_mode deinterlaceMode; | ||
std::string sourceDeinterlaceModeString = request.RequestData["sourceDeinterlaceMode"]; | ||
|
||
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."); | ||
} | ||
Comment on lines
+415
to
+436
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here. This can all be replaced by taking advantage of the |
||
|
||
obs_source_set_deinterlace_mode(source, deinterlaceMode); | ||
|
||
return RequestResult::Success(); | ||
} | ||
|
||
/** | ||
* Gets the deinterlace field order of a source. | ||
* | ||
* Deinterlace field orders: | ||
* | ||
* - `OBS_DEINTERLACE_FIELD_ORDER_TOP` | ||
* - `OBS_DEINTERLACE_FIELD_ORDER_BOTTOM` | ||
* | ||
* **Compatible with inputs.** | ||
* | ||
* @requestField sourceName | String | Name of the source | ||
* | ||
* @responseField sourceDeinterlaceFieldOrder | String | Deinterlace field order | ||
* | ||
* @requestType GetSourceDeinterlaceFieldOrder | ||
* @api requests | ||
* @category sources | ||
*/ | ||
RequestResult RequestHandler::GetSourceDeinterlaceFieldOrder(const Request &request) | ||
{ | ||
RequestStatus::RequestStatus statusCode; | ||
std::string comment; | ||
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment); | ||
if (!source) | ||
return RequestResult::Error(statusCode, comment); | ||
|
||
if (obs_source_get_type(source) != OBS_SOURCE_TYPE_INPUT) | ||
return RequestResult::Error(RequestStatus::InvalidResourceType, "The specified source is not an input."); | ||
|
||
auto deinterlaceFieldOrder = obs_source_get_deinterlace_field_order(source); | ||
|
||
json responseData; | ||
switch (deinterlaceFieldOrder) { | ||
case OBS_DEINTERLACE_FIELD_ORDER_TOP: | ||
responseData["sourceDeinterlaceFieldOrder"] = "OBS_DEINTERLACE_FIELD_ORDER_TOP"; | ||
break; | ||
case OBS_DEINTERLACE_FIELD_ORDER_BOTTOM: | ||
responseData["sourceDeinterlaceFieldOrder"] = "OBS_DEINTERLACE_FIELD_ORDER_BOTTOM"; | ||
break; | ||
default: | ||
responseData["sourceDeinterlaceFieldOrder"] = "OBS_DEINTERLACE_FIELD_ORDER_TOP"; | ||
break; | ||
} | ||
|
||
return RequestResult::Success(responseData); | ||
} | ||
|
||
/** | ||
* Sets the deinterlace field order of a source. | ||
* | ||
* @requestField sourceName | String | Name of the source | ||
* @requestField sourceDeinterlaceFieldOrder | String | Deinterlace field order | ||
* | ||
* @requestType SetSourceDeinterlaceFieldOrder | ||
* @api requests | ||
* @category sources | ||
*/ | ||
RequestResult RequestHandler::SetSourceDeinterlaceFieldOrder(const Request &request) | ||
{ | ||
RequestStatus::RequestStatus statusCode; | ||
std::string comment; | ||
OBSSourceAutoRelease source = request.ValidateSource("sourceName", statusCode, comment); | ||
if (!source || !request.ValidateString("sourceDeinterlaceFieldOrder", statusCode, comment)) | ||
return RequestResult::Error(statusCode, comment); | ||
|
||
enum obs_deinterlace_field_order deinterlaceFieldOrder; | ||
std::string sourceDeinterlaceFieldOrderString = request.RequestData["sourceDeinterlaceFieldOrder"]; | ||
|
||
if (sourceDeinterlaceFieldOrderString == "OBS_DEINTERLACE_FIELD_ORDER_TOP") { | ||
deinterlaceFieldOrder = OBS_DEINTERLACE_FIELD_ORDER_TOP; | ||
} else if (sourceDeinterlaceFieldOrderString == "OBS_DEINTERLACE_FIELD_ORDER_BOTTOM") { | ||
deinterlaceFieldOrder = OBS_DEINTERLACE_FIELD_ORDER_BOTTOM; | ||
} else { | ||
return RequestResult::Error(RequestStatus::InvalidRequestField, | ||
"Your specified deinterlace field order is invalid or not supported by this system."); | ||
} | ||
|
||
obs_source_set_deinterlace_field_order(source, deinterlaceFieldOrder); | ||
|
||
return RequestResult::Success(); | ||
} | ||
|
||
// Intentionally undocumented | ||
RequestResult RequestHandler::GetSourcePrivateSettings(const Request &request) | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
returnsenum 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: