Fix bug causing a crash when changing resolution of the monitor while in a session
This commit is contained in:
@@ -86,13 +86,17 @@ std::string get_local_ip() { return get_local_ip(AF_INET); }
|
|||||||
|
|
||||||
struct display_attr_t {
|
struct display_attr_t {
|
||||||
display_attr_t() : display { XOpenDisplay(nullptr) }, window { DefaultRootWindow(display) }, attr {} {
|
display_attr_t() : display { XOpenDisplay(nullptr) }, window { DefaultRootWindow(display) }, attr {} {
|
||||||
XGetWindowAttributes(display, window, &attr);
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
~display_attr_t() {
|
~display_attr_t() {
|
||||||
XCloseDisplay(display);
|
XCloseDisplay(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
XGetWindowAttributes(display, window, &attr);
|
||||||
|
}
|
||||||
|
|
||||||
Display *display;
|
Display *display;
|
||||||
Window window;
|
Window window;
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
@@ -110,6 +114,7 @@ display_t display() {
|
|||||||
img_t snapshot(display_t &display_void) {
|
img_t snapshot(display_t &display_void) {
|
||||||
auto &display = *((display_attr_t*)display_void.get());
|
auto &display = *((display_attr_t*)display_void.get());
|
||||||
|
|
||||||
|
display.refresh();
|
||||||
XImage *img { XGetImage(
|
XImage *img { XGetImage(
|
||||||
display.display,
|
display.display,
|
||||||
display.window,
|
display.window,
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ void encodeThread(
|
|||||||
ctx->flags |= (AV_CODEC_FLAG_CLOSED_GOP | AV_CODEC_FLAG_LOW_DELAY);
|
ctx->flags |= (AV_CODEC_FLAG_CLOSED_GOP | AV_CODEC_FLAG_LOW_DELAY);
|
||||||
ctx->flags2 |= AV_CODEC_FLAG2_FAST;
|
ctx->flags2 |= AV_CODEC_FLAG2_FAST;
|
||||||
|
|
||||||
auto fromformat = AV_PIX_FMT_BGR0;
|
|
||||||
auto lg = open_codec(ctx, codec, &options);
|
auto lg = open_codec(ctx, codec, &options);
|
||||||
|
|
||||||
yuv_frame->format = ctx->pix_fmt;
|
yuv_frame->format = ctx->pix_fmt;
|
||||||
@@ -136,18 +135,27 @@ void encodeThread(
|
|||||||
|
|
||||||
int64_t frame = 1;
|
int64_t frame = 1;
|
||||||
|
|
||||||
|
auto img_width = 0;
|
||||||
|
auto img_height = 0;
|
||||||
|
|
||||||
// Initiate scaling context with correct height and width
|
// Initiate scaling context with correct height and width
|
||||||
sws_t sws;
|
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()) {
|
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()) {
|
if(idr_events->peek()) {
|
||||||
yuv_frame->pict_type = AV_PICTURE_TYPE_I;
|
yuv_frame->pict_type = AV_PICTURE_TYPE_I;
|
||||||
frame = idr_events->pop()->first;
|
frame = idr_events->pop()->first;
|
||||||
|
|||||||
Reference in New Issue
Block a user