Skip to content
Permalink
Browse files

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

  • Loading branch information...
gnif committed May 28, 2019
1 parent 3d426cc commit 7d260277521b27d9a259e0c09a67def31c556fd6
Showing with 45 additions and 28 deletions.
  1. +1 −1 VERSION
  2. +2 −5 c-host/platform/Windows/capture/DXGI/src/dxgi.c
  3. +2 −5 c-host/platform/Windows/capture/NVFBC/src/nvfbc.c
  4. +40 −17 c-host/src/app.c
@@ -1 +1 @@
B1-rc3-5-gb31e8e1cee+1
B1-rc3-6-g3d426ccef8+1
@@ -774,11 +774,8 @@ static CaptureResult dxgi_getFrame(CaptureFrame * frame)
assert(this->initialized);

Texture * tex = &this->texture[this->texRIndex];
if (!os_waitEvent(tex->mapped, TIMEOUT_INFINITE))
{
DEBUG_ERROR("Failed to wait on the texture map event");
return CAPTURE_RESULT_ERROR;
}
if (!os_waitEvent(tex->mapped, 1000))
return CAPTURE_RESULT_TIMEOUT;

if (this->stop)
return CAPTURE_RESULT_REINIT;
@@ -238,11 +238,8 @@ static CaptureResult nvfbc_capture()

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

if (this->stop)
return CAPTURE_RESULT_REINIT;
@@ -86,13 +86,14 @@ static int pointerThread(void * opaque)
case CAPTURE_RESULT_REINIT:
{
app.reinit = true;
break;
DEBUG_INFO("Pointer thread reinit");
return 0;
}

case CAPTURE_RESULT_ERROR:
{
DEBUG_ERROR("Failed to get the pointer");
break;
return 0;
}

case CAPTURE_RESULT_TIMEOUT:
@@ -155,30 +156,51 @@ static int frameThread(void * opaque)
{
DEBUG_INFO("Frame thread started");

int frameIndex = 0;
volatile KVMFRFrame * fi = &(app.shmHeader->frame);

bool frameValid = false;
int frameIndex = 0;
unsigned int clientInstance = 0;
CaptureFrame frame = { 0 };

while(app.running)
{
CaptureResult result;
CaptureFrame frame =
{
.data = app.frame[frameIndex]
};
frame.data = app.frame[frameIndex];

result = app.iface->getFrame(&frame);
if (result == CAPTURE_RESULT_REINIT)
switch(app.iface->getFrame(&frame))
{
app.reinit = true;
break;
}
case CAPTURE_RESULT_OK:
break;

if (result == CAPTURE_RESULT_ERROR)
{
DEBUG_ERROR("Failed to get the frame");
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;
}
}

clientInstance = app.clientInstance;

// wait for the client to finish with the previous frame
while(fi->flags & KVMFR_FRAME_FLAG_UPDATE && app.running)
usleep(1000);
@@ -199,6 +221,7 @@ static int frameThread(void * opaque)
fi->stride = frame.stride;
fi->pitch = frame.pitch;
fi->dataPos = app.frameOffset[frameIndex];
frameValid = true;

INTERLOCKED_OR8(&fi->flags, KVMFR_FRAME_FLAG_UPDATE);

0 comments on commit 7d26027

Please sign in to comment.
You can’t perform that action at this time.