Skip to content

Instantly share code, notes, and snippets.

@mbondaru
Created May 22, 2024 18:29
Show Gist options
  • Save mbondaru/90bb2ac34334f0ee259c691309b02c66 to your computer and use it in GitHub Desktop.
Save mbondaru/90bb2ac34334f0ee259c691309b02c66 to your computer and use it in GitHub Desktop.
void * cdi_camera_open(int *param_1,int *param_2)
{
cdi_camera_ctrl_struct *__ptr;
int iVar1;
uint uVar2;
undefined4 uVar3;
int iVar4;
int iVar5;
uint *puVar6;
undefined4 local_50;
undefined4 local_4c;
logging_message(0x400,"cdi_camera_open: enter");
if ((*param_1 < 3) &&
(__ptr = (cdi_camera_ctrl_struct *)rtos_malloc_priority(0x784c,4,1,0),
__ptr != (cdi_camera_ctrl_struct *)0x0)) {
memset((uint *)__ptr,0,0x784c);
__ptr->a_const_'0d' = 0;
iVar4 = 0;
*param_2 = 0;
__ptr->a_const_'FFFFFFFFh' = 0xffffffff;
while( true ) {
/* as we start with *param_1=1, we skip the do-while loop on the first pass */
if (*param_1 <= iVar4) {
open_flash_driver((int *)__ptr);
iVar4 = 0;
if ((int)__ptr->num_cameras < 1) goto LAB_0ecaa1f2;
do {
puVar6 = &__ptr->num_cameras + iVar4 * 0xf04;
puVar6[9] = 0xff;
puVar6[0xe] = 0x100;
uVar2 = rtos_malloc_priority(0x8000,0x10,1,0);
puVar6[0x45] = uVar2;
uVar2 = rtos_malloc_priority(0x8000,0x10,1,0);
puVar6[0x46] = uVar2;
local_4c = 0;
local_50 = 0;
(**(code **)(puVar6[0x73] + 0x2c))(puVar6[0x72],&local_4c,&local_50);
delayed_values_reset((int)(puVar6 + 6),1,local_4c,0);
delayed_values_reset((int)(puVar6 + 6),0,local_50,0);
delayed_values_reset((int)(puVar6 + 6),2,0x100,0);
while( true ) {
puVar6[0x593] = 0;
uVar3 = _tx_event_flags_create(puVar6 + 0x7a);
vcos_threadx_map_error(uVar3);
vcos_thread_create_classic
((int)(puVar6 + 0x8e),"CDI CAMERA",cdi_camera_task_func,__ptr,
(int)(puVar6 + 0x15c),0x864,1);
uVar3 = _tx_event_flags_create(puVar6 + 0x84);
vcos_threadx_map_error(uVar3);
vcos_thread_create_classic
((int)(puVar6 + 0xf5),"CDI CAMERA",cdi_camera_data_task_func,__ptr,
(int)(puVar6 + 0x375),0x864,1);
iVar4 = iVar4 + 1;
if (1 < iVar4) {
iVar5 = cdi_camera_change_state(__ptr,0,2,2);
iVar4 = *param_2;
*param_2 = iVar4 + iVar5;
if (iVar4 + iVar5 != 0) {
logging_message(0x400,"cdi_camera_open: change state failed");
__ptr = (cdi_camera_ctrl_struct *)0x0;
cdi_camera_close();
}
logging_message(0x400,"cdi_camera_open: exit");
return __ptr;
}
if (iVar4 < (int)__ptr->num_cameras) break;
LAB_0ecaa1f2:
puVar6 = &__ptr->num_cameras + iVar4 * 0xf04;
memcpy(puVar6 + 6,&__ptr->f_number,0x3c10);
}
} while( true );
}
iVar1 = open_camera_driver(__ptr,iVar4,param_1);
iVar5 = *param_2;
*param_2 = iVar5 + iVar1;
if (iVar5 + iVar1 != 0) break;
iVar4 = iVar4 + 1;
}
iVar5 = 0;
if (-1 < iVar4) {
if (0 < (int)__ptr->num_cameras) goto LAB_0ecaa10c;
do {
puVar6 = &__ptr->num_cameras + iVar5 * 0xf04;
while( true ) {
camera_driver_unload(puVar6[0x73],(undefined *)puVar6[0x78]);
lens_driver_unload(puVar6[0x74],(undefined *)puVar6[0x79]);
iVar5 = iVar5 + 1;
if (iVar4 < iVar5) goto LAB_0ecaa134;
if ((int)__ptr->num_cameras <= iVar5) break;
LAB_0ecaa10c:
puVar6 = &__ptr->num_cameras + iVar5 * 0xf04;
(**(code **)(puVar6[0x73] + 0x10))(puVar6[0x72]);
}
} while( true );
}
LAB_0ecaa134:
free(__ptr);
}
else {
*param_2 = -1;
}
return (void *)0x0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment