@@ -645,6 +645,11 @@ int main(int argc, char *argv[])
645
645
if (ar2VideoGetParami (vid, AR_VIDEO_PARAM_AVFOUNDATION_CAMERA_POSITION, &frontCamera) >= 0 ) {
646
646
gCameraIsFrontFacing = (frontCamera == AR_VIDEO_AVFOUNDATION_CAMERA_POSITION_FRONT);
647
647
}
648
+ } else if (vid->module == AR_VIDEO_MODULE_ANDROID) {
649
+ int frontCamera;
650
+ if (ar2VideoGetParami (vid, AR_VIDEO_PARAM_ANDROID_CAMERA_FACE, &frontCamera) >= 0 ) {
651
+ gCameraIsFrontFacing = (frontCamera == AR_VIDEO_ANDROID_CAMERA_FACE_FRONT);
652
+ }
648
653
}
649
654
bool contentRotate90, contentFlipV, contentFlipH;
650
655
if (gDisplayOrientation == 1 ) { // Landscape with top of device at left.
@@ -1238,30 +1243,23 @@ static void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg,
1238
1243
1239
1244
AR2VideoParamT *vid = vs->getAR2VideoParam ();
1240
1245
if (ar2VideoGetParams (vid, AR_VIDEO_PARAM_DEVICEID, &device_id) < 0 || !device_id) {
1241
- ARLOGe (" Error fetching camera device identification.\n " );
1246
+ ARLOGe (" Video input module does not support fetching device identification.\n " );
1242
1247
}
1243
1248
if (ar2VideoGetParams (vid, AR_VIDEO_PARAM_NAME, &name) < 0 || !name) {
1244
- ARLOGe (" Error fetching camera name.\n " );
1249
+ ARLOGi (" Video input module does not support fetching input name.\n " );
1250
+ }
1251
+ if (!device_id && !name) {
1252
+ ARLOGw (" Neither video input device identification nor name available.\n " );
1245
1253
}
1246
1254
1247
- if (vid->module == AR_VIDEO_MODULE_AVFOUNDATION) {
1248
- int focalPreset;
1249
- ar2VideoGetParami (vid, AR_VIDEO_PARAM_AVFOUNDATION_FOCUS_PRESET, &focalPreset);
1250
- switch (focalPreset) {
1251
- case AR_VIDEO_AVFOUNDATION_FOCUS_MACRO:
1252
- focal_length = strdup (" 0.01" );
1253
- break ;
1254
- case AR_VIDEO_AVFOUNDATION_FOCUS_0_3M:
1255
- focal_length = strdup (" 0.3" );
1256
- break ;
1257
- case AR_VIDEO_AVFOUNDATION_FOCUS_1_0M:
1258
- focal_length = strdup (" 1.0" );
1259
- break ;
1260
- case AR_VIDEO_AVFOUNDATION_FOCUS_INF:
1261
- focal_length = strdup (" 1000000.0" );
1262
- break ;
1263
- default :
1264
- break ;
1255
+ double f;
1256
+ if (ar2VideoGetParamd (vid, AR_VIDEO_PARAM_CAMERA_FOCAL_LENGTH, &f) < 0 ) {
1257
+ ARLOGi (" Video input module does not support fetching focal length.\n " );
1258
+ } else {
1259
+ if (f > 0.0 ) {
1260
+ if (asprintf (&focal_length, " %.3f" , f) < 0 ) {
1261
+ ARLOGe (" Error writing focal length.\n " );
1262
+ }
1265
1263
}
1266
1264
}
1267
1265
if (!focal_length) {
@@ -1270,7 +1268,11 @@ static void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg,
1270
1268
}
1271
1269
1272
1270
if (gCalibrationSave ) {
1273
-
1271
+ #ifdef ANDROID
1272
+ if (SDL_AndroidRequestPermission (" android.permission.WRITE_EXTERNAL_STORAGE" ) != SDL_TRUE) {
1273
+ ARLOGe (" Error: Unable to write to external storage.\n " );
1274
+ } else {
1275
+ #endif
1274
1276
// Assemble the filename.
1275
1277
char calibrationSavePathname[SAVEPARAM_PATHNAME_LEN];
1276
1278
snprintf (calibrationSavePathname, SAVEPARAM_PATHNAME_LEN, " %s/camera_para-" , gCalibrationSaveDir );
@@ -1297,6 +1299,10 @@ static void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg,
1297
1299
} else {
1298
1300
ARLOGi (" Saved calibration to '%s'.\n " , calibrationSavePathname);
1299
1301
}
1302
+ #ifdef ANDROID
1303
+ }
1304
+ #endif
1305
+
1300
1306
}
1301
1307
1302
1308
// Check for early exit.
@@ -1448,31 +1454,3 @@ static void saveParam(const ARParam *param, ARdouble err_min, ARdouble err_avg,
1448
1454
}
1449
1455
free (cachePath);
1450
1456
}
1451
-
1452
- #ifdef ANDROID
1453
- #include < jni.h>
1454
- #define JNIFUNCTION_CC (sig ) Java_org_artoolkitx_utilities_cameracalibration_CameraCalibrationJNI_##sig
1455
-
1456
- extern " C" JNIEXPORT void JNICALL JNIFUNCTION_CC (handleBackButton (void ))
1457
- {
1458
- flowHandleEvent (EVENT_BACK_BUTTON);
1459
- }
1460
-
1461
- extern " C" JNIEXPORT void JNICALL JNIFUNCTION_CC (handleAddButton (void ))
1462
- {
1463
- flowHandleEvent (EVENT_TOUCH);
1464
- }
1465
-
1466
- extern " C" JNIEXPORT void JNICALL JNIFUNCTION_CC (sendPreferencesChangedEvent (void ))
1467
- {
1468
- SDL_Event event;
1469
- SDL_zero (event);
1470
- event.type = gSDLEventPreferencesChanged ;
1471
- event.user .code = (Sint32)0 ;
1472
- event.user .data1 = NULL ;
1473
- event.user .data2 = NULL ;
1474
- SDL_PushEvent (&event);
1475
- }
1476
-
1477
- #endif
1478
-
0 commit comments