Skip to content

Instantly share code, notes, and snippets.

@saisasidhar
Created March 23, 2016 10:44
Show Gist options
  • Save saisasidhar/09a8bd24150745600c02 to your computer and use it in GitHub Desktop.
Save saisasidhar/09a8bd24150745600c02 to your computer and use it in GitHub Desktop.
/*
Yep, this is not the reason for improved transfer rate.
Code courtesy of PCO
*/
static void
adapt_camera_memory(UcaPcowinCameraPrivate *priv)
{
gboolean do_adapt = FALSE; // Set to FALSE to prepare for checking valid images
DWORD dwTest;
DWORD dwTest2;
DWORD dwReducedRamSize;
if((priv->strGeneral.dwCamHealthStatus & STATUS_DEFAULT_STATE) || !(priv->strGeneral.dwCamHealthStatus & STATUS_SETTINGS_VALID))
{
g_warning("Power on default");
do_adapt = TRUE; // Power on default detected: Set adapt to TRUE
}
dwReducedRamSize = priv->strSensor.strDescription.wMaxHorzResExtDESC * priv->strSensor.strDescription.wMaxVertResExtDESC;
dwReducedRamSize *= 4; // Buffer für 4 Bilder in Preview
if(priv->strSensor.strDescription.dwGeneralCapsDESC1 & GENERALCAPS1_CDI_MODE)
dwReducedRamSize *= 2; // doubleshutter uses double size
if(priv->strSensor.strDescription.wDoubleImageDESC == 1)
dwReducedRamSize *= 2; // doubleshutter uses double size
if(priv->strStorage.wPageSize == 0)
{
g_warning("Error in AdaptCameraMemory! wPageSize must not be zero!!!\n");
return;
}
if(dwReducedRamSize % priv->strStorage.wPageSize)// Erzwinge Pagesize Granularität
{
g_warning("Force page size granulation");
dwReducedRamSize = dwReducedRamSize / priv->strStorage.wPageSize + 1;
dwReducedRamSize *= priv->strStorage.wPageSize;
}// Previewbuffer reservieren
// Found valid alien configuration and no default state
if((priv->strStorage.dwRamSegSize[3] != dwReducedRamSize / priv->strStorage.wPageSize) && (do_adapt == FALSE))
{
g_warning("Found valid alien configuration and no default state");
DWORD dwValid = 0, dwMax = 0;
gboolean bfound = FALSE;
dwTest= priv->strStorage.dwRamSegSize[0] +
priv->strStorage.dwRamSegSize[1] +
priv->strStorage.dwRamSegSize[2] +
dwReducedRamSize / priv->strStorage.wPageSize;
// found alien configuration
for(WORD i = 4; i > 0; i--)
{
PCO_GetNumberOfImagesInSegment(priv->pcoHandle, i, &dwValid, &dwMax);
if(dwValid != 0)
{
bfound = TRUE;
do_adapt = FALSE;
g_warning("Found external CamRAM configuration with valid images....[etc]\n");
if(dwTest > priv->strStorage.dwRamSize)
g_warning("Adapt to Camware setup and delete all recorded images?\n");
else
{
if(i == 4)
g_warning("Adapt to Camware setup and delete images in segment 4?\n");
else
g_warning("Adapt to Camware setup?\n");
}
if(TRUE) // Force true - pressing yes in camware
{
if(dwTest > priv->strStorage.dwRamSize)
{
g_warning("This will delete all recorded images. Proceed with new memory setup?");
if(TRUE) // again forcing yes
{
do_adapt = TRUE;
}
}
else
{
if(i == 4)
{
g_warning("This will delete all recorded images in segment 4. Proceed with new memory setup?");
if(TRUE) // Forcing yes
{
do_adapt = TRUE;
}
}
else
do_adapt = TRUE;
}
}
if(do_adapt == FALSE) // Equivalent of pressing no when asked for mem setup
{
if(priv->strStorage.dwRamSegSize[3] < dwReducedRamSize / priv->strStorage.wPageSize)
{
g_warning("Preview not possible.CamRAM in segment 4 too small");
}
}
else
{
// Set camera run state to stop
}
break;
}
}// For
if(!bfound)
do_adapt = TRUE;
}
if(do_adapt)
{
g_warning("In adapt routine");
priv->strStorage.dwRamSegSize[3] = dwReducedRamSize / priv->strStorage.wPageSize;
dwTest = priv->strStorage.dwRamSegSize[0] +
priv->strStorage.dwRamSegSize[1] +
priv->strStorage.dwRamSegSize[2] +
priv->strStorage.dwRamSegSize[3];
dwTest2 = priv->strStorage.dwRamSegSize[0] +
priv->strStorage.dwRamSegSize[1] +
priv->strStorage.dwRamSegSize[2];
if((dwTest > priv->strStorage.dwRamSize) || (dwTest2 < priv->strStorage.dwRamSegSize[3]))
{
priv->strStorage.wActSeg = 1;
priv->strStorage.dwRamSegSize[0] =
priv->strStorage.dwRamSize - priv->strStorage.dwRamSegSize[3];
priv->strStorage.dwRamSegSize[1] = 0;
priv->strStorage.dwRamSegSize[2] = 0;
}
//bCameraInitState = FALSE;
}
if(priv->strStorage.dwRamSegSize[priv->strStorage.wActSeg - 1] == 0)
{
priv->strStorage.wActSeg = 1;
while(priv->strStorage.dwRamSegSize[priv->strStorage.wActSeg - 1] == 0)
{
priv->strStorage.wActSeg++;
}
}
int ret_err = PCO_SetStorageStruct(priv->pcoHandle, &priv->strStorage);
if(ret_err)
{
g_warning("Failed to adapt memory. Call to SetStorageStruct failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment