Skip to content

Commit ee1e107

Browse files
committed
Merge branch 'master' into phil-dist_model_v5
* master: Save calibration if local saving is enabled, even if we have no device_id.
2 parents a48292e + 0cdb423 commit ee1e107

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

calib_camera.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,54 +1134,54 @@ static void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg,
11341134

11351135
} else {
11361136

1137-
bool goodWrite = true;
1138-
11391137
// Get main device identifier and focal length from video module.
11401138
char *device_id = NULL;
1139+
char *name = NULL;
11411140
char *focal_length = NULL;
11421141

11431142
AR2VideoParamT *vid = vs->getAR2VideoParam();
11441143
if (ar2VideoGetParams(vid, AR_VIDEO_PARAM_DEVICEID, &device_id) < 0 || !device_id) {
11451144
ARLOGe("Error fetching camera device identification.\n");
1146-
goodWrite = false;
1145+
}
1146+
if (ar2VideoGetParams(vid, AR_VIDEO_PARAM_NAME, &name) < 0 || !name) {
1147+
ARLOGe("Error fetching camera name.\n");
11471148
}
11481149

1149-
if (goodWrite) {
1150-
if (vid->module == AR_VIDEO_MODULE_AVFOUNDATION) {
1151-
int focalPreset;
1152-
ar2VideoGetParami(vid, AR_VIDEO_PARAM_AVFOUNDATION_FOCUS_PRESET, &focalPreset);
1153-
switch (focalPreset) {
1154-
case AR_VIDEO_AVFOUNDATION_FOCUS_MACRO:
1155-
focal_length = strdup("0.01");
1156-
break;
1157-
case AR_VIDEO_AVFOUNDATION_FOCUS_0_3M:
1158-
focal_length = strdup("0.3");
1159-
break;
1160-
case AR_VIDEO_AVFOUNDATION_FOCUS_1_0M:
1161-
focal_length = strdup("1.0");
1162-
break;
1163-
case AR_VIDEO_AVFOUNDATION_FOCUS_INF:
1164-
focal_length = strdup("1000000.0");
1165-
break;
1166-
default:
1167-
break;
1168-
}
1169-
}
1170-
if (!focal_length) {
1171-
// Not known at present, so just send 0.000.
1172-
focal_length = strdup("0.000");
1150+
if (vid->module == AR_VIDEO_MODULE_AVFOUNDATION) {
1151+
int focalPreset;
1152+
ar2VideoGetParami(vid, AR_VIDEO_PARAM_AVFOUNDATION_FOCUS_PRESET, &focalPreset);
1153+
switch (focalPreset) {
1154+
case AR_VIDEO_AVFOUNDATION_FOCUS_MACRO:
1155+
focal_length = strdup("0.01");
1156+
break;
1157+
case AR_VIDEO_AVFOUNDATION_FOCUS_0_3M:
1158+
focal_length = strdup("0.3");
1159+
break;
1160+
case AR_VIDEO_AVFOUNDATION_FOCUS_1_0M:
1161+
focal_length = strdup("1.0");
1162+
break;
1163+
case AR_VIDEO_AVFOUNDATION_FOCUS_INF:
1164+
focal_length = strdup("1000000.0");
1165+
break;
1166+
default:
1167+
break;
11731168
}
11741169
}
1170+
if (!focal_length) {
1171+
// Not known at present, so just send 0.000.
1172+
focal_length = strdup("0.000");
1173+
}
11751174

1176-
if (goodWrite && gCalibrationSave) {
1175+
if (gCalibrationSave) {
11771176

11781177
// Assemble the filename.
11791178
char calibrationSavePathname[SAVEPARAM_PATHNAME_LEN];
11801179
snprintf(calibrationSavePathname, SAVEPARAM_PATHNAME_LEN, "%s/camera_para-", gCalibrationSaveDir);
11811180
size_t len = strlen(calibrationSavePathname);
11821181
int i = 0;
1183-
while (device_id[i] && (len + i + 2 < SAVEPARAM_PATHNAME_LEN)) {
1184-
calibrationSavePathname[len + i] = (device_id[i] == '/' || device_id[i] == '\\' ? '_' : device_id[i]);
1182+
const char *identifier = (device_id ? device_id : (name ? name : ""));
1183+
while (identifier[i] && (len + i + 2 < SAVEPARAM_PATHNAME_LEN)) {
1184+
calibrationSavePathname[len + i] = (identifier[i] == '/' || identifier[i] == '\\' ? '_' : identifier[i]);
11851185
i++;
11861186
}
11871187
calibrationSavePathname[len + i] = '\0';
@@ -1203,7 +1203,7 @@ static void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg,
12031203
}
12041204

12051205
// Check for early exit.
1206-
if (!goodWrite || !gCalibrationServerUploadURL) {
1206+
if (!gCalibrationServerUploadURL || !device_id) {
12071207
if (remove(paramPathname) < 0) {
12081208
ARLOGe("Error removing temporary file '%s'.\n", paramPathname);
12091209
ARLOGperror(NULL);
@@ -1220,6 +1220,7 @@ static void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg,
12201220
// Open the file.
12211221
snprintf(indexPathname, SAVEPARAM_PATHNAME_LEN, "%s/%s/%06d-index", arUtilGetResourcesDirectoryPath(AR_UTIL_RESOURCES_DIRECTORY_BEHAVIOR_USE_APP_CACHE_DIR), QUEUE_DIR, ID);
12221222
FILE *fp;
1223+
bool goodWrite = true;
12231224
if (!(fp = fopen(indexPathname, "wb"))) {
12241225
ARLOGe("Error opening upload index file '%s'.\n", indexPathname);
12251226
goodWrite = false;

0 commit comments

Comments
 (0)