split "files" into "flash_files" and "sdram_files", as cameras might pretend to be both

and this is confusing the driver (AFL)
This commit is contained in:
Marcus Meissner
2020-02-29 17:36:42 +01:00
parent b62b70e908
commit 4a24bc4d7f
4 changed files with 57 additions and 53 deletions

View File

@@ -243,9 +243,13 @@ camera_exit (Camera *camera, GPContext *context)
free (camera->pl->fats);
camera->pl->fats = NULL;
}
if (camera->pl->files) {
free (camera->pl->files);
camera->pl->files = NULL;
if (camera->pl->flash_files) {
free (camera->pl->flash_files);
camera->pl->flash_files = NULL;
}
if (camera->pl->sdram_files) {
free (camera->pl->sdram_files);
camera->pl->sdram_files = NULL;
}
if (camera->pl->flash_toc) {
free (camera->pl->flash_toc);
@@ -330,8 +334,8 @@ file_list_func (CameraFilesystem *fs, const char *folder,
CHECK (spca50x_sdram_get_info (camera->pl));
for (i = 0; i < camera->pl->num_files_on_sdram; i++) {
if (camera->pl->files[i].name)
strncpy (temp_file, camera->pl->files[i].name, 12);
if (camera->pl->sdram_files[i].name)
strncpy (temp_file, camera->pl->sdram_files[i].name, 12);
else
strcpy (temp_file, "BAD.BAD");
temp_file[12] = 0;
@@ -573,10 +577,9 @@ camera_init (Camera *camera, GPContext *context)
break;
}
camera->pl = malloc (sizeof (CameraPrivateLibrary));
camera->pl = calloc (sizeof (CameraPrivateLibrary), 1);
if (!camera->pl)
return (GP_ERROR_NO_MEMORY);
memset (camera->pl, 0, sizeof (CameraPrivateLibrary));
camera->pl->gpdev = camera->port;
camera->pl->dirty_sdram = 1;
camera->pl->dirty_flash = 1;

View File

@@ -57,12 +57,12 @@ static void
free_files (CameraPrivateLibrary *pl)
{
int i;
if (pl->files) {
for (i = 0; i < pl->num_files_on_flash; i++){
if(pl->files[i].thumb) free (pl->files[i].thumb);
if (pl->flash_files) {
for (i = 0; i < pl->num_files_on_flash; i++) {
if(pl->flash_files[i].thumb) free (pl->flash_files[i].thumb);
}
free(pl->files);
pl->files = NULL;
free(pl->flash_files);
pl->flash_files = NULL;
}
}
@@ -196,8 +196,8 @@ spca50x_flash_get_TOC(CameraPrivateLibrary *pl, int *filecount)
/* Now, create the files info buffer */
free_files(pl);
/* NOTE: using calloc to ensure new block is "empty" */
pl->files = calloc (*filecount , sizeof (struct SPCA50xFile));
if (!pl->files)
pl->flash_files = calloc (*filecount , sizeof (struct SPCA50xFile));
if (!pl->flash_files)
return GP_ERROR_NO_MEMORY;
} else { /* all other cams with flash... */
/* read the TOC from the cam */
@@ -397,12 +397,12 @@ spca500_flash_84D_get_file_info (CameraPrivateLibrary * pl, int index,
/* First, check if the info. is already buffered in the cam private lib
* We DO NOT want to be fetching the entire thumbnail just to get the file size...*/
if ((pl->dirty_flash == 0) && (pl->files[index].type != 0)){
if ((pl->dirty_flash == 0) && (pl->flash_files[index].type != 0)){
/* This file must have been checked before */
*w = pl->files[index].width ;
*h = pl->files[index].height ;
*t = pl->files[index].type ;
*sz = pl->files[index].size ;
*w = pl->flash_files[index].width ;
*h = pl->flash_files[index].height ;
*t = pl->flash_files[index].type ;
*sz = pl->flash_files[index].size ;
return GP_OK;
} else if (pl->dirty_flash != 0){ /* should never happen, but just in case... */
CHECK(spca50x_flash_get_TOC (pl, &i));
@@ -437,9 +437,9 @@ spca500_flash_84D_get_file_info (CameraPrivateLibrary * pl, int index,
{
int j;
uint8_t * buf;
if (pl->files[index].thumb){
free (pl->files[index].thumb); /* discard any previous thumbnail data */
pl->files[index].thumb = NULL;
if (pl->flash_files[index].thumb){
free (pl->flash_files[index].thumb); /* discard any previous thumbnail data */
pl->flash_files[index].thumb = NULL;
}
buf = malloc (38 * 256); /* create a new buffer to hold the thumbnail data */
if (buf){
@@ -449,12 +449,12 @@ spca500_flash_84D_get_file_info (CameraPrivateLibrary * pl, int index,
CHECK (gp_port_read (pl->gpdev, (char *)&buf[j], 256));
j += 256;
}
pl->files[index].thumb = buf;
pl->flash_files[index].thumb = buf;
} else { /* couldn't get a buffer - read in the data anyway and discard it */
for (i = 0; i < 38; i++) {/* Thumbnails ALWAYS download 38 blocks...*/
CHECK (gp_port_read (pl->gpdev, waste, 256));
}
pl->files[index].thumb = NULL;
pl->flash_files[index].thumb = NULL;
}
} /* end of thumbnail storing loop */
@@ -526,10 +526,10 @@ spca500_flash_84D_get_file_info (CameraPrivateLibrary * pl, int index,
if (pl->dirty_flash == 0){
/* Only update the files cache if it exists, i.e. if dirty is zero */
/* We should never get here if dirty is set, however ! */
pl->files[index].type = *t;
pl->files[index].width = *w;
pl->files[index].height = *h;
pl->files[index].size = *sz;
pl->flash_files[index].type = *t;
pl->flash_files[index].width = *w;
pl->flash_files[index].height = *h;
pl->flash_files[index].size = *sz;
}
return GP_OK;
@@ -617,8 +617,8 @@ spca50x_flash_process_image (CameraPrivateLibrary *pl, /* context */
uint8_t qIndex = 0, format;
int file_size;
int w = pl->files[index].width;
int h = pl->files[index].height;
int w = pl->flash_files[index].width;
int h = pl->flash_files[index].height;
/* qindex == 2 seems to be right for all the dsc350 images - so far!!! */
qIndex = 2 ; /* FIXME - what to do about Qtable stuff? */
@@ -670,11 +670,11 @@ spca500_flash_84D_get_file (CameraPrivateLibrary * pl,
}
/* OK, we've decided what type of file it is, now lets upload it... */
if ((thumbnail != 0) && (pl->files[index].thumb != NULL)){
if ((thumbnail != 0) && (pl->flash_files[index].thumb != NULL)){
/* We can cheat here - we already have the thumbnail data in a cache, so don't load it again */
blks = 38;
buf = pl->files[index].thumb;
pl->files[index].thumb = NULL; /* we will release buf, so this pointer must be "emptied" */
buf = pl->flash_files[index].thumb;
pl->flash_files[index].thumb = NULL; /* we will release buf, so this pointer must be "emptied" */
}
else {
/* We need to download this data from the cam... */

View File

@@ -725,7 +725,7 @@ spca50x_sdram_get_info (CameraPrivateLibrary * lib)
if (lib->num_files_on_sdram > 0) {
CHECK (spca50x_get_FATs (lib, dramtype));
index = lib->files[lib->num_files_on_sdram - 1].fat_end;
index = lib->sdram_files[lib->num_files_on_sdram - 1].fat_end;
if (index >= lib->num_fats) {
gp_log(GP_LOG_ERROR, "spca50x", "%d exceeds num_fats %d", index, lib->num_fats);
return GP_ERROR;
@@ -756,7 +756,7 @@ spca50x_sdram_get_file_info (CameraPrivateLibrary * lib, unsigned int index,
{
if (lib->dirty_sdram)
CHECK (spca50x_sdram_get_info (lib));
*g_file = &(lib->files[index]);
*g_file = &(lib->sdram_files[index]);
return GP_OK;
}
static int
@@ -869,13 +869,13 @@ spca50x_get_FATs (CameraPrivateLibrary * lib, int dramtype)
lib->fats = NULL;
}
if (lib->files) {
free (lib->files);
lib->files = NULL;
if (lib->sdram_files) {
free (lib->sdram_files);
lib->sdram_files = NULL;
}
lib->fats = calloc (lib->num_fats , SPCA50X_FAT_PAGE_SIZE);
lib->files = calloc (lib->num_files_on_sdram , sizeof (struct SPCA50xFile));
lib->sdram_files = calloc (lib->num_files_on_sdram , sizeof (struct SPCA50xFile));
p = lib->fats;
if (lib->bridge == BRIDGE_SPCA504) {
@@ -907,7 +907,7 @@ spca50x_get_FATs (CameraPrivateLibrary * lib, int dramtype)
while (index < lib->num_fats) {
if (file_index >= lib->num_files_on_sdram) {
free (lib->fats); lib->fats = NULL;
free (lib->files); lib->files = NULL;
free (lib->sdram_files); lib->sdram_files = NULL;
return GP_ERROR;
}
@@ -919,32 +919,32 @@ spca50x_get_FATs (CameraPrivateLibrary * lib, int dramtype)
/* continuation of an avi */
if (!file_index)
return GP_ERROR;
lib->files[file_index - 1].fat_end = index;
lib->sdram_files[file_index - 1].fat_end = index;
} else {
/* its an image */
if (type == 0x00 || type == 0x01) {
snprintf (buf, sizeof(buf), "Image%03d.jpg",
++lib->num_images);
lib->files[file_index].mime_type =
lib->sdram_files[file_index].mime_type =
SPCA50X_FILE_TYPE_IMAGE;
} else if ((type == 0x08) || (type == 0x03)) {
/* its the start of an avi */
snprintf (buf, sizeof(buf), "Movie%03d.avi",
++lib->num_movies);
lib->files[file_index].mime_type =
lib->sdram_files[file_index].mime_type =
SPCA50X_FILE_TYPE_AVI;
} else {
gp_log(GP_LOG_ERROR, "spca50x", "type %d unhandled - error", type);
return GP_ERROR;
}
lib->files[file_index].fat = p;
lib->files[file_index].fat_start = index;
lib->files[file_index].fat_end = index;
lib->files[file_index].name = strdup ((char*)buf);
lib->sdram_files[file_index].fat = p;
lib->sdram_files[file_index].fat_start = index;
lib->sdram_files[file_index].fat_end = index;
lib->sdram_files[file_index].name = strdup ((char*)buf);
if (lib->bridge == BRIDGE_SPCA504) {
lib->files[file_index].width =
lib->sdram_files[file_index].width =
(p[8] & 0xFF) * 16;
lib->files[file_index].height =
lib->sdram_files[file_index].height =
(p[9] & 0xFF) * 16;
} else if (lib->bridge == BRIDGE_SPCA500) {
int w, h;
@@ -956,10 +956,10 @@ spca50x_get_FATs (CameraPrivateLibrary * lib, int dramtype)
w = 640;
h = 480;
}
lib->files[file_index].width = w;
lib->files[file_index].height = h;
lib->sdram_files[file_index].width = w;
lib->sdram_files[file_index].height = h;
}
lib->files[file_index].thumb = NULL;
lib->sdram_files[file_index].thumb = NULL;
file_index++;
}
p += SPCA50X_FAT_PAGE_SIZE;

View File

@@ -72,7 +72,8 @@ struct _CameraPrivateLibrary
int size_free;
uint8_t *flash_toc;
uint8_t *fats;
struct SPCA50xFile *files;
struct SPCA50xFile *flash_files;
struct SPCA50xFile *sdram_files;
};
#define SPCA50X_SDRAM 0x01