Camera configs

ArCameraConfig provides details of the camera configuration that ARCore uses to access the camera sensor for a given session. These details include, for example, the targeted capture frame rate, whether the front or back camera is used, and whether a depth sensor is enabled.

When creating a new ARCore session, ARCore uses ArSession_setCameraConfig() to set the camera config that best matches the list of available configs returned by ArSession_getSupportedCameraConfigsWithFilter(). Your app can use ArCameraConfigFilter to narrow down the available camera configs for a given device at runtime by filtering based on your app's needs.

Two common use cases for filtering are:

  • Limiting camera capture frame rate to 30 fps. On devices that support 60 fps, ARCore will prioritize camera configs that support that frame rate. To filter out all camera configs that support 60 fps, apply a filter with ArCameraConfigFilter_setTargetFps() using AR_CAMERA_CONFIG_TARGET_FPS_30.

    // Return only camera configs that target 30 fps camera capture frame rate.
    ArCameraConfigFilter_setTargetFps(AR_CAMERA_CONFIG_TARGET_FPS_30);
    
  • Prevent ARCore from using the depth sensor. On devices that have a supported depth sensor, ARCore prioritizes camera configs that use the depth sensor. To filter out all camera configs that use the depth sensor, apply the ArCameraConfigFilter_setDepthSensorUsage() filter using AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_DO_NOT_USE.

    // Return only camera configs that will not use the depth sensor.
    ArCameraConfigFilter_setDepthSensorUsage(AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_DO_NOT_USE);
    

Using camera config filters

Follow these steps to enable your app to filter camera configs.

// Create an ARCore session.
ArSession* session;
ArSession_create(env, context, &session);

// Create a camera config list and filter for the session.
ArCameraConfig* selected_config;
ArCameraConfigList* configs;
ArCameraConfigFilter* filter;
ArCameraConfig_create(session, &selected_config);
ArCameraConfigList_create(session, &configs);
ArCameraConfigFilter_create(session, &filter);

// Return only camera configs that target 30 fps camera capture frame rate.
ArCameraConfigFilter_setTargetFps(AR_CAMERA_CONFIG_TARGET_FPS_30);

// Return only camera configs that will not use the depth sensor.
ArCameraConfigFilter_setDepthSensorUsage(AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_DO_NOT_USE);

// Get list of configs that match filter settings.
// In this case, this list is guaranteed to contain at least one element,
// because both TargetFps.TARGET_FPS_30 and DepthSensorUsage.DO_NOT_USE
// are supported on all ARCore supported devices.
ArSession_getSupportedCameraConfigsWithFilter(session, filter, configs);

// Use element 0 from the list of returned camera configs. This is because
// it contains the camera config that best matches the specified filter
// settings.
ArCameraConfigList_getItem(session, configs, 0, selected_config);

// Set the camera config to use selected_config.
ArSession_setCameraConfig(session, selected_config)

// Free memory.
ArCameraConfigFilter_destroy(filter);
ArCameraConfigList_destroy(configs);