mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-01-27 03:35:36 +00:00
Fix bug causing a crash when changing resolution of the monitor while in a session
This commit is contained in:
parent
072fc00aca
commit
5541f9dca8
@ -86,13 +86,17 @@ std::string get_local_ip() { return get_local_ip(AF_INET); }
|
||||
|
||||
struct display_attr_t {
|
||||
display_attr_t() : display { XOpenDisplay(nullptr) }, window { DefaultRootWindow(display) }, attr {} {
|
||||
XGetWindowAttributes(display, window, &attr);
|
||||
refresh();
|
||||
}
|
||||
|
||||
~display_attr_t() {
|
||||
XCloseDisplay(display);
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
XGetWindowAttributes(display, window, &attr);
|
||||
}
|
||||
|
||||
Display *display;
|
||||
Window window;
|
||||
XWindowAttributes attr;
|
||||
@ -110,6 +114,7 @@ display_t display() {
|
||||
img_t snapshot(display_t &display_void) {
|
||||
auto &display = *((display_attr_t*)display_void.get());
|
||||
|
||||
display.refresh();
|
||||
XImage *img { XGetImage(
|
||||
display.display,
|
||||
display.window,
|
||||
|
@ -125,7 +125,6 @@ void encodeThread(
|
||||
ctx->flags |= (AV_CODEC_FLAG_CLOSED_GOP | AV_CODEC_FLAG_LOW_DELAY);
|
||||
ctx->flags2 |= AV_CODEC_FLAG2_FAST;
|
||||
|
||||
auto fromformat = AV_PIX_FMT_BGR0;
|
||||
auto lg = open_codec(ctx, codec, &options);
|
||||
|
||||
yuv_frame->format = ctx->pix_fmt;
|
||||
@ -136,18 +135,27 @@ void encodeThread(
|
||||
|
||||
int64_t frame = 1;
|
||||
|
||||
auto img_width = 0;
|
||||
auto img_height = 0;
|
||||
|
||||
// Initiate scaling context with correct height and width
|
||||
sws_t sws;
|
||||
if(auto img = images->pop()) {
|
||||
sws.reset(
|
||||
sws_getContext(
|
||||
platf::img_width(img), platf::img_height(img), fromformat,
|
||||
ctx->width, ctx->height, ctx->pix_fmt,
|
||||
SWS_LANCZOS | SWS_ACCURATE_RND,
|
||||
nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
while (auto img = images->pop()) {
|
||||
auto new_width = platf::img_width(img);
|
||||
auto new_height = platf::img_height(img);
|
||||
|
||||
if(img_width != new_width || img_height != new_height) {
|
||||
img_width = new_width;
|
||||
img_height = new_height;
|
||||
|
||||
sws.reset(
|
||||
sws_getContext(
|
||||
img_width, img_height, AV_PIX_FMT_BGR0,
|
||||
ctx->width, ctx->height, ctx->pix_fmt,
|
||||
SWS_LANCZOS | SWS_ACCURATE_RND,
|
||||
nullptr, nullptr, nullptr));
|
||||
}
|
||||
|
||||
if(idr_events->peek()) {
|
||||
yuv_frame->pict_type = AV_PICTURE_TYPE_I;
|
||||
frame = idr_events->pop()->first;
|
||||
|
Loading…
x
Reference in New Issue
Block a user