[c-host] resend the last on client reconnect if a timeout occurs

This commit is contained in:
Geoffrey McRae 2019-05-28 14:24:48 +10:00
parent 3d426ccef8
commit 7d26027752
4 changed files with 45 additions and 28 deletions

View File

@ -1 +1 @@
B1-rc3-5-gb31e8e1cee+1 B1-rc3-6-g3d426ccef8+1

View File

@ -774,11 +774,8 @@ static CaptureResult dxgi_getFrame(CaptureFrame * frame)
assert(this->initialized); assert(this->initialized);
Texture * tex = &this->texture[this->texRIndex]; Texture * tex = &this->texture[this->texRIndex];
if (!os_waitEvent(tex->mapped, TIMEOUT_INFINITE)) if (!os_waitEvent(tex->mapped, 1000))
{ return CAPTURE_RESULT_TIMEOUT;
DEBUG_ERROR("Failed to wait on the texture map event");
return CAPTURE_RESULT_ERROR;
}
if (this->stop) if (this->stop)
return CAPTURE_RESULT_REINIT; return CAPTURE_RESULT_REINIT;

View File

@ -238,11 +238,8 @@ static CaptureResult nvfbc_capture()
static CaptureResult nvfbc_getFrame(CaptureFrame * frame) static CaptureResult nvfbc_getFrame(CaptureFrame * frame)
{ {
if (!os_waitEvent(this->frameEvent, TIMEOUT_INFINITE)) if (!os_waitEvent(this->frameEvent, 1000))
{ return CAPTURE_RESULT_TIMEOUT;
DEBUG_ERROR("Failed to wait on the frame event");
return CAPTURE_RESULT_ERROR;
}
if (this->stop) if (this->stop)
return CAPTURE_RESULT_REINIT; return CAPTURE_RESULT_REINIT;

View File

@ -86,13 +86,14 @@ static int pointerThread(void * opaque)
case CAPTURE_RESULT_REINIT: case CAPTURE_RESULT_REINIT:
{ {
app.reinit = true; app.reinit = true;
break; DEBUG_INFO("Pointer thread reinit");
return 0;
} }
case CAPTURE_RESULT_ERROR: case CAPTURE_RESULT_ERROR:
{ {
DEBUG_ERROR("Failed to get the pointer"); DEBUG_ERROR("Failed to get the pointer");
break; return 0;
} }
case CAPTURE_RESULT_TIMEOUT: case CAPTURE_RESULT_TIMEOUT:
@ -155,29 +156,50 @@ static int frameThread(void * opaque)
{ {
DEBUG_INFO("Frame thread started"); DEBUG_INFO("Frame thread started");
int frameIndex = 0;
volatile KVMFRFrame * fi = &(app.shmHeader->frame); volatile KVMFRFrame * fi = &(app.shmHeader->frame);
bool frameValid = false;
int frameIndex = 0;
unsigned int clientInstance = 0;
CaptureFrame frame = { 0 };
while(app.running) while(app.running)
{ {
CaptureResult result; frame.data = app.frame[frameIndex];
CaptureFrame frame =
{
.data = app.frame[frameIndex]
};
result = app.iface->getFrame(&frame); switch(app.iface->getFrame(&frame))
if (result == CAPTURE_RESULT_REINIT)
{ {
app.reinit = true; case CAPTURE_RESULT_OK:
break; break;
case CAPTURE_RESULT_REINIT:
{
app.reinit = true;
DEBUG_INFO("Frame thread reinit");
return 0;
}
case CAPTURE_RESULT_ERROR:
{
DEBUG_ERROR("Failed to get the frame");
return 0;
}
case CAPTURE_RESULT_TIMEOUT:
{
if (frameValid && clientInstance != app.clientInstance)
{
// resend the last frame
if (--frameIndex < 0)
frameIndex = MAX_FRAMES - 1;
break;
}
continue;
}
} }
if (result == CAPTURE_RESULT_ERROR) clientInstance = app.clientInstance;
{
DEBUG_ERROR("Failed to get the frame");
break;
}
// wait for the client to finish with the previous frame // wait for the client to finish with the previous frame
while(fi->flags & KVMFR_FRAME_FLAG_UPDATE && app.running) while(fi->flags & KVMFR_FRAME_FLAG_UPDATE && app.running)
@ -199,6 +221,7 @@ static int frameThread(void * opaque)
fi->stride = frame.stride; fi->stride = frame.stride;
fi->pitch = frame.pitch; fi->pitch = frame.pitch;
fi->dataPos = app.frameOffset[frameIndex]; fi->dataPos = app.frameOffset[frameIndex];
frameValid = true;
INTERLOCKED_OR8(&fi->flags, KVMFR_FRAME_FLAG_UPDATE); INTERLOCKED_OR8(&fi->flags, KVMFR_FRAME_FLAG_UPDATE);