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

fix(nvenc): Enable opt-in client refresh by client #3415

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

Conversation

TheElixZammuto
Copy link
Contributor

@TheElixZammuto TheElixZammuto commented Nov 24, 2024

Description

Context in TheElixZammuto/moonlight-xbox#117

This type of degradation can be fixed on nvidia cards by implementing intra-refresh.
I do not have an nvidia card so I wasn't be able to test, but this change has been validated by the commenters in the issue above using a custom Sunshine build made by me and by other forks of Sunshine made by other people, and it seems to fix the issue.

This change is completely opt-in by the client, so this change should only apply to the Xbox/UWP Client

Related to:

moonlight-xbox: TheElixZammuto/moonlight-xbox#155
moonlight-common-c: moonlight-stream/moonlight-common-c#97

Screenshot

Issues Fixed or Closed

TheElixZammuto/moonlight-xbox#117

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

@TheElixZammuto TheElixZammuto changed the title [nvenc] Enable opt-in client refresh by client fix(nvenc): Enable opt-in client refresh by client Nov 24, 2024
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 11.12%. Comparing base (d5854ae) to head (e99be0f).

Files with missing lines Patch % Lines
src/nvenc/nvenc_base.cpp 0.00% 5 Missing ⚠️
src/rtsp.cpp 0.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3415      +/-   ##
==========================================
- Coverage   11.13%   11.12%   -0.01%     
==========================================
  Files          99       99              
  Lines       17253    17261       +8     
  Branches     8045     8048       +3     
==========================================
  Hits         1921     1921              
- Misses      12639    12785     +146     
+ Partials     2693     2555     -138     
Flag Coverage Δ
Linux 8.36% <0.00%> (-0.01%) ⬇️
Windows 5.31% <0.00%> (-0.01%) ⬇️
macOS-13 13.60% <0.00%> (-0.03%) ⬇️
macOS-14 12.64% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/video.h 54.94% <ø> (ø)
src/rtsp.cpp 2.76% <0.00%> (-0.01%) ⬇️
src/nvenc/nvenc_base.cpp 1.94% <0.00%> (-0.03%) ⬇️

... and 20 files with indirect coverage changes

@ReenigneArcher
Copy link
Member

Do we need to wait for the moonlight-common-c PR to be merged for this?

@cgutman
Copy link
Collaborator

cgutman commented Nov 26, 2024

Do we need to wait for the moonlight-common-c PR to be merged for this?

Not really. The SDP attribute looks fine and that's the only part of the network protocol that's affected by this change.

If we wanted to do this for real, I would suggest allowing the client to specify the parameters of the intra-refresh period, but since this is basically a hack, I'm fine just having a single flag to indicate it.

I'm pretty convinced we (or FFmpeg) probably have a bug here though because I've seen this "artifacting on mostly static images" pop up on other clients too. It's just really tricky to catch in a way that can actually be analyzed. We would need to write the whole video stream to disk, so we could run it through a bitstream analyzer it after the fact. Maybe it's feasible to do on Xbox where it occurs relatively soon, but in other cases it can take hours of streaming for it to happen.

@@ -321,6 +321,12 @@ namespace nvenc {
set_ref_frames(format_config.maxNumRefFramesInDPB, format_config.numRefL0, 5);
set_minqp_if_enabled(config.min_qp_hevc);
fill_h264_hevc_vui(format_config.hevcVUIParameters);
if (client_config.enableIntraRefresh == 1) {
format_config.enableIntraRefresh = 1;
format_config.singleSliceIntraRefresh = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think singleSliceIntraRefresh is a special feature that's not supported by all NVENC encoders. Do we need that?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible to check for NV_ENC_CAPS_SINGLE_SLICE_INTRA_REFRESH cap and enable single slice conditionally.

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.

4 participants