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

win-capture: Add option to adjust hook rate for game capture #1479

Merged
merged 1 commit into from Sep 17, 2018
Merged

win-capture: Add option to adjust hook rate for game capture #1479

merged 1 commit into from Sep 17, 2018

Conversation

tompeeters368
Copy link
Contributor

I run an automatic stream in which the game is frequently restarted, and OBS's retry interval on finding the game window was so long that you'd often miss the first few seconds.
This pull request adds an option to adjust the speed at which the game capture plugin tries to find a valid window.
It may be a niche option, but it improved my stream, so I figured I'd see if there was interest to include it.

I tried to make the option easy to understand by making it a simple slow/normal/fast/fastest setting.
The code mentions that trying too fast can cause crashes, e.g. by Steam, which is not a concern in my case. I have not encountered any problems thus far with using the fastest setting. Regardless, the default is unchanged from the existing retry interval and the option recommends to leave it at that.

Copy link
Member

@RytoEX RytoEX left a comment

Choose a reason for hiding this comment

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

Hi! Congrats on your first PR here! To help out, I've reviewed this PR, mostly for conformance with this project's style guidelines.

Other than my inline remarks, please also wrap your commit message body (the paragraph under the initial commit message line/subject) at 72 characters.

HOOK_RATE_SLOW,
HOOK_RATE_NORMAL,
HOOK_RATE_FAST,
HOOK_RATE_FASTEST,
Copy link
Member

Choose a reason for hiding this comment

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

There's an unneeded comma after the last enum item. Remove it.

static inline float hook_rate_to_float(enum hook_rate rate)
{
switch (rate) {
case HOOK_RATE_SLOW: return 2.0f;
Copy link
Member

Choose a reason for hiding this comment

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

Style: Generally, avoid putting multiple statements on a single line. In this case, split case and return statements onto separate lines.

case HOOK_RATE_FAST: return 0.5f;
case HOOK_RATE_FASTEST: return 0.1f;
case HOOK_RATE_NORMAL:
default: return 1.0f;
Copy link
Member

Choose a reason for hiding this comment

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

I believe a "fallthrough" indicator is needed above this to avoid a GCC-7 warning.

@@ -537,7 +565,8 @@ static void *game_capture_create(obs_data_t *settings, obs_source_t *source)

gc->source = source;
gc->initial_config = true;
gc->retry_interval = DEFAULT_RETRY_INTERVAL;
gc->retry_interval = DEFAULT_RETRY_INTERVAL*
Copy link
Member

Choose a reason for hiding this comment

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

Style: Typically, you need to surround math operators by a single space on each side. Don't leave a trailing space at the end of the line either, so in this case:

	gc->retry_interval = DEFAULT_RETRY_INTERVAL *

@@ -537,7 +565,8 @@ static void *game_capture_create(obs_data_t *settings, obs_source_t *source)

gc->source = source;
gc->initial_config = true;
gc->retry_interval = DEFAULT_RETRY_INTERVAL;
gc->retry_interval = DEFAULT_RETRY_INTERVAL*
hook_rate_to_float(gc->config.hook_rate);
Copy link
Member

Choose a reason for hiding this comment

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

Style: Tab twice to indent a line continuation.

@@ -1614,7 +1644,7 @@ static void game_capture_tick(void *data, float seconds)
return;

} else if (!gc->showing) {
gc->retry_time = 10.0f;
gc->retry_time = 10.0f*hook_rate_to_float(gc->config.hook_rate);
Copy link
Member

Choose a reason for hiding this comment

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

Style: You need to surround math operators by a single space on each side. Doing this will exceed the line length limit, so also line-break this line.

@@ -1640,7 +1670,8 @@ static void game_capture_tick(void *data, float seconds)
gc->error_acquiring = true;

} else if (!gc->capturing) {
gc->retry_interval = ERROR_RETRY_INTERVAL;
gc->retry_interval = ERROR_RETRY_INTERVAL*
Copy link
Member

Choose a reason for hiding this comment

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

Style: Typically, you need to surround math operators by a single space on each side. Don't leave a trailing space at the end of the line.

@@ -1640,7 +1670,8 @@ static void game_capture_tick(void *data, float seconds)
gc->error_acquiring = true;

} else if (!gc->capturing) {
gc->retry_interval = ERROR_RETRY_INTERVAL;
gc->retry_interval = ERROR_RETRY_INTERVAL*
hook_rate_to_float(gc->config.hook_rate);
Copy link
Member

Choose a reason for hiding this comment

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

Style: Tab twice to indent a line continuation.

@@ -1655,7 +1686,8 @@ static void game_capture_tick(void *data, float seconds)
debug("init_capture_data failed");

if (result != CAPTURE_RETRY && !gc->capturing) {
gc->retry_interval = ERROR_RETRY_INTERVAL;
gc->retry_interval = ERROR_RETRY_INTERVAL*
Copy link
Member

Choose a reason for hiding this comment

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

Style: Typically, you need to surround math operators by a single space on each side. Don't leave a trailing space at the end of the line.

@@ -1655,7 +1686,8 @@ static void game_capture_tick(void *data, float seconds)
debug("init_capture_data failed");

if (result != CAPTURE_RETRY && !gc->capturing) {
gc->retry_interval = ERROR_RETRY_INTERVAL;
gc->retry_interval = ERROR_RETRY_INTERVAL*
hook_rate_to_float(gc->config.hook_rate);
Copy link
Member

Choose a reason for hiding this comment

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

Style: Tab twice to indent a line continuation.

This option slows down or speeds up the rate at which
the game capture plugin checks for a valid window.
@tompeeters368
Copy link
Contributor Author

tompeeters368 commented Sep 13, 2018

Lots of style comments! Apologies, I've never worked with C that much so I mostly just tried to copy the style of the files. Should've just read the proper guide.

I addressed all points you mentioned except for the fallthrough issue. I could not get it to compile with a [[fallthrough]] indicator, and I can't find any in the surrounding code so I presume that it is a feature from a later update than what OBS runs on. I added a comment instead to signify that it is intentional. Alternatively I can simply remove the default case and have it return the default value in case no switch condition applies, if that would be preferred?

As for the commit message, is the current message a problem? I believe that the current, equal length message:

This option slows down or speeds up the rate at which
the game capture plugin checks for a valid window.

reads nicer than the enforced wrap at 72 characters:

This option slows down or speeds up the rate at which the game capture
plugin checks for a valid window.

Or did I misinterpret the style guidelines? To me it was purely an aesthetical choice, since it is shorter than 72 characters regardless.

@RytoEX
Copy link
Member

RytoEX commented Sep 13, 2018

Regarding the "fallthrough" issue, see Pull Request #935. I do not believe "[[fallthrough]]", specifically, is supported in all compilers we currently use, which is why we use the comment mechanism instead. I build primarily on Windows, so I don't use GCC that often. You should be able to verify if this is needed by compiling with GCC 7.

Alternatively I can simply remove the default case

I'm not sure what compiler optimizations occur with a default case compared to assigning a default outside of the switch. It's probably better to have the default case.

As for the commit message, the specific style rule in question is:

OBS Studio uses the 50/72 standard for commits. 50 characters max for the title (excluding module prefix), an empty line, and then a full description of the commit, wrapped to 72 columns max. See this link for more information: http://chris.beams.io/posts/git-commit/

I suppose one could interpret that as "wrap the commit body at 72 characters or less". I don't know Jim's preference on this one. I usually just recommend wrapping at 72, but you can keep it this way until Jim has time to review it.

@jp9000
Copy link
Member

jp9000 commented Sep 17, 2018

I don't really like adding too many advanced options like this, but I do acknowledge that the default hook retry interval is quite large. In the future, I think some of these more advanced options need to be segregated from the simple options. A redo of the settings here would be ideal in the future.

@jp9000 jp9000 merged commit 0f67614 into obsproject:master Sep 17, 2018
@RytoEX
Copy link
Member

RytoEX commented Sep 17, 2018

Not sure if this will still emit a warning in GCC7 for the fallthrough syntax used.

@RytoEX
Copy link
Member

RytoEX commented Sep 17, 2018

After reviewing the GCC documentation on warning options, it looks like this will be fine for -Wimplicit-fallthrough=n where n is anything from 0 to 4. It's not consistent with the other comments introduced in PR #935, but that's a nitpick.

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.

None yet

3 participants