Skip to content

Commit

Permalink
[host] app: cleanup local variables during init.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Oct 21, 2023
1 parent 6b65c7e commit ad65561
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions host/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,45 +815,47 @@ int app_main(int argc, char * argv[])
int throttleUs = throttleFps ? 1000000 / throttleFps : 0;
uint64_t previousFrameTime = 0;

const char * ifaceName = option_get_string("app", "capture");
CaptureInterface * iface = NULL;
for(int i = 0; CaptureInterfaces[i]; ++i)
{
iface = CaptureInterfaces[i];
if (*ifaceName && strcasecmp(ifaceName, iface->shortName))
continue;
const char * ifaceName = option_get_string("app", "capture");
CaptureInterface * iface = NULL;
for(int i = 0; CaptureInterfaces[i]; ++i)
{
iface = CaptureInterfaces[i];
if (*ifaceName && strcasecmp(ifaceName, iface->shortName))
continue;

DEBUG_INFO("Trying : %s", iface->getName());
DEBUG_INFO("Trying : %s", iface->getName());

if (!iface->create(captureGetPointerBuffer, capturePostPointerBuffer))
{
if (!iface->create(captureGetPointerBuffer, capturePostPointerBuffer))
{
iface = NULL;
continue;
}

if (iface->init())
break;

iface->free();
iface = NULL;
continue;
}

if (iface->init())
break;
if (!iface)
{
if (*ifaceName)
DEBUG_ERROR("Specified capture interface not supported");
else
DEBUG_ERROR("Failed to find a supported capture interface");
exitcode = LG_HOST_EXIT_FAILED;
goto fail_lgmp;
}

iface->free();
iface = NULL;
}
DEBUG_INFO("Using : %s", iface->getName());
DEBUG_INFO("Capture Method : %s", iface->asyncCapture ?
"Asynchronous" : "Synchronous");

if (!iface)
{
if (*ifaceName)
DEBUG_ERROR("Specified capture interface not supported");
else
DEBUG_ERROR("Failed to find a supported capture interface");
exitcode = LG_HOST_EXIT_FAILED;
goto fail_lgmp;
app.iface = iface;
}

DEBUG_INFO("Using : %s", iface->getName());
DEBUG_INFO("Capture Method : %s", iface->asyncCapture ?
"Asynchronous" : "Synchronous");

app.iface = iface;

if (!lgmpSetup(&shmDev))
{
exitcode = LG_HOST_EXIT_FATAL;
Expand Down Expand Up @@ -928,14 +930,14 @@ int app_main(int argc, char * argv[])
}

const uint64_t captureStart = microtime();
switch(iface->capture())
switch(app.iface->capture())
{
case CAPTURE_RESULT_OK:
previousFrameTime = captureStart;
break;

case CAPTURE_RESULT_TIMEOUT:
if (!iface->asyncCapture)
if (!app.iface->asyncCapture)
if (app.frameValid && lgmpHostQueueNewSubs(app.frameQueue) > 0)
{
LGMP_STATUS status;
Expand All @@ -956,7 +958,7 @@ int app_main(int argc, char * argv[])
goto fail_capture;
}

if (!iface->asyncCapture)
if (!app.iface->asyncCapture)
sendFrame();
}

Expand Down Expand Up @@ -987,7 +989,7 @@ int app_main(int argc, char * argv[])
captureStop();

fail_capture:
iface->free();
app.iface->free();
LG_LOCK_FREE(app.pointerLock);

fail_lgmp:
Expand Down

0 comments on commit ad65561

Please sign in to comment.