Fix lack of video when starting a session on Windows without wiggling mouse

This commit is contained in:
loki 2020-03-20 15:53:19 +01:00
parent ad87463784
commit 68a7cece49
2 changed files with 37 additions and 19 deletions

View File

@ -730,8 +730,8 @@ void start(std::shared_ptr<safe::signal_t> shutdown_event) {
auto dir = std::filesystem::temp_directory_path() / "Sushine"sv;
config::nvhttp.cert = dir / ("cert-"s + unique_id);
config::nvhttp.pkey = dir / ("pkey-"s + unique_id);
config::nvhttp.cert = (dir / ("cert-"s + unique_id)).string();
config::nvhttp.pkey = (dir / ("pkey-"s + unique_id)).string();
}

View File

@ -351,20 +351,51 @@ void capture(
// Initiate scaling context with correct height and width
sws_t sws;
// Temporary image to ensure something is send to Moonlight even if no frame has been captured yet.
int dummy_data = 0;
auto img = std::make_shared<platf::img_t>();
img->row_pitch = 4;
img->height = 1;
img->width = 1;
img->pixel_pitch = 4;
img->data = (std::uint8_t*)&dummy_data;
auto next_frame = std::chrono::steady_clock::now();
while(true) {
if(shutdown_event->peek()) {
if(shutdown_event->peek() || !images->running()) {
break;
}
if(idr_events->peek()) {
yuv_frame->pict_type = AV_PICTURE_TYPE_I;
auto event = idr_events->pop();
TUPLE_2D_REF(_, end, *event);
frame = end;
key_frame = end + config.framerate;
}
else if(frame == key_frame) {
yuv_frame->pict_type = AV_PICTURE_TYPE_I;
}
std::this_thread::sleep_until(next_frame);
next_frame += delay;
auto img = images->pop();
if(!img) {
break;
// When Moonlight request an IDR frame, send frames even if there is no new captured frame
if(frame > (key_frame + config.framerate) || images->peek()) {
if(auto tmp_img = images->pop(delay)) {
img = std::move(tmp_img);
}
else if(images->running()) {
continue;
}
else {
break;
}
}
auto new_width = img->width;
auto new_height = img->height;
@ -384,19 +415,6 @@ void capture(
0, 1 << 16, 1 << 16);
}
if(idr_events->peek()) {
yuv_frame->pict_type = AV_PICTURE_TYPE_I;
auto event = idr_events->pop();
TUPLE_2D_REF(_, end, *event);
frame = end;
key_frame = end + config.framerate;
}
else if(frame == key_frame) {
yuv_frame->pict_type = AV_PICTURE_TYPE_I;
}
encode(frame++, ctx, sws, yuv_frame, *img, packets, channel_data);
yuv_frame->pict_type = AV_PICTURE_TYPE_NONE;