diff --git a/sunshine/platform/windows_dxgi.cpp b/sunshine/platform/windows_dxgi.cpp index 2e5dcb7a..978a2a7b 100644 --- a/sunshine/platform/windows_dxgi.cpp +++ b/sunshine/platform/windows_dxgi.cpp @@ -808,7 +808,7 @@ class display_gpu_t : public display_base_t, public std::enable_shared_from_this return capture_e::error; } - img->row_pitch = 0; + img->row_pitch = width * 4; img->width = width; img->height = height; img->data = (std::uint8_t*)src_p; @@ -833,18 +833,19 @@ class display_gpu_t : public display_base_t, public std::enable_shared_from_this int dummy_img(platf::img_t *img_base, int &dummy_data_p) override { auto img = (img_d3d_t*)img_base; - img->row_pitch = 4; + img->row_pitch = width * 4; D3D11_TEXTURE2D_DESC t {}; - t.Width = 1; - t.Height = 1; + t.Width = width; + t.Height = height; t.MipLevels = 1; t.ArraySize = 1; t.SampleDesc.Count = 1; t.Usage = D3D11_USAGE_DEFAULT; t.Format = format; + auto dummy_data = std::make_unique(width * height); D3D11_SUBRESOURCE_DATA data { - &dummy_data_p, + dummy_data.get(), (UINT)img->row_pitch, 0 }; @@ -857,8 +858,8 @@ class display_gpu_t : public display_base_t, public std::enable_shared_from_this } img->texture.reset(tex_p); - img->height = 1; - img->width = 1; + img->height = height; + img->width = width; img->data = (std::uint8_t*)tex_p; img->pixel_pitch = 4; diff --git a/sunshine/video.cpp b/sunshine/video.cpp index 7896ad01..d2a1fa45 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -250,6 +250,7 @@ void captureThread( next_frame += delay; auto &img = *round_robin++; + while(img.use_count() > 1) {} platf::capture_e status; { auto lg = display_wp.lock(); @@ -626,6 +627,7 @@ void encode_run( // When Moonlight request an IDR frame, send frames even if there is no new captured frame if(frame_nr > (key_frame_nr + config.framerate) || images->peek()) { if(auto img = images->pop(delay)) { + const platf::img_t *img_p; if(encoder.system_memory) { auto new_width = img->width; auto new_height = img->height; @@ -646,17 +648,16 @@ void encode_run( 0, 1 << 16, 1 << 16); } - encoder.img_to_frame(sws, *img, session->frame); + img_p = img; } else { - auto converted_img = hwdevice_ctx->convert(*img); - if(!converted_img) { + img_p = hwdevice_ctx->convert(*img); + if(!img_p) { return; } - - encoder.img_to_frame(sws, *converted_img, session->frame); - } + + encoder.img_to_frame(sws, *img_p, session->frame); } else if(images->running()) { continue; @@ -843,13 +844,8 @@ bool validate_encoder(encoder_t &encoder) { h264.videoFormat = 0; hevc.videoFormat = 1; - if(validate_config(disp, encoder, h264)) { - encoder.h264[flag] = true; - } - - if(validate_config(disp, encoder, hevc)) { - encoder.hevc[flag] = true; - } + encoder.h264[flag] = validate_config(disp, encoder, h264); + encoder.hevc[flag] = validate_config(disp, encoder, hevc); } return true;