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

Mitigate corruption, ask for an IDR every X frames #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Streaming/FFmpegDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ extern "C" {
#include<libswscale/swscale.h>
#include<libavutil/hwcontext_d3d11va.h>
}

#define DECODER_BUFFER_SIZE 1048576
#define MAX_DELAY_BETWEEN_IDR_FRAMES 1000
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a reason for the 1000 value or it's just due to empircal tests?


namespace moonlight_xbox_dx {

Expand Down Expand Up @@ -163,6 +165,9 @@ namespace moonlight_xbox_dx {
Utils::Log("Using hack for Xbox One Consoles");
hackWait = true;
}

framesSinceLastIDR = 0;

return 0;
}

Expand Down Expand Up @@ -205,12 +210,30 @@ namespace moonlight_xbox_dx {
entry = entry->next;
}
int err;


if (decodeUnit->frameType == FRAME_TYPE_IDR) {
framesSinceLastIDR = 0;
pkt.flags |= AV_PKT_FLAG_KEY;
}

err = Decode(ffmpeg_buffer, length);
if (err < 0) {
LiCompleteVideoFrame(frameHandle, DR_NEED_IDR);
return false;
}

LiCompleteVideoFrame(frameHandle, DR_OK);

// Mitigate the issue where the video slowly gets more corrupt by periodically
// requesting an IDR frame
#ifdef MAX_DELAY_BETWEEN_IDR_FRAMES
if (framesSinceLastIDR++ >= MAX_DELAY_BETWEEN_IDR_FRAMES) {
LiRequestIdrFrame();
framesSinceLastIDR = 0;
}
#endif // #MAX_DELAY_BETWEEN_IDR_FRAMES

return true;
}

Expand Down
1 change: 1 addition & 0 deletions Streaming/FFmpegDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace moonlight_xbox_dx
AVFrame** dec_frames;
AVFrame** ready_frames;
int next_frame, current_frame;
int framesSinceLastIDR;
std::shared_ptr<DX::DeviceResources> resources;
};
}