Skip to content

Commit

Permalink
ARCore Android SDK v1.26.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bsanjin committed Aug 12, 2021
1 parent 16324af commit e12a49b
Show file tree
Hide file tree
Showing 65 changed files with 334 additions and 182 deletions.
60 changes: 60 additions & 0 deletions libraries/include/arcore_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,10 @@ AR_DEFINE_ENUM(ArTrackingFailureReason){
AR_TRACKING_FAILURE_REASON_BAD_STATE = 1,
/// Motion tracking lost due to poor lighting conditions. Ask the user to
/// move to a more brightly lit area.
/// On Android 12 (API level 31) or later, the user may have <a
/// href="https://developer.android.com/about/versions/12/behavior-changes-all#mic-camera-toggles">
/// disabled camera access</a>, causing ARCore to receive a blank camera
/// feed.
AR_TRACKING_FAILURE_REASON_INSUFFICIENT_LIGHT = 2,
/// Motion tracking lost due to excessive motion. Ask the user to move the
/// device more slowly.
Expand Down Expand Up @@ -2012,6 +2016,9 @@ void ArRecordingConfig_destroy(ArRecordingConfig *config);
/// @ingroup ArRecordingConfig
/// Gets the file path to save an MP4 dataset file for the recording.
///
/// This will be null if @c ::ArRecordingConfig_setMp4DatasetUri was used to set
/// the output.
///
/// @param[in] session The ARCore session
/// @param[in] config The config object to query
/// @param[out] out_mp4_dataset_file_path Pointer to an @c char* to receive
Expand All @@ -2030,6 +2037,35 @@ void ArRecordingConfig_setMp4DatasetFilePath(const ArSession *session,
ArRecordingConfig *config,
const char *mp4_dataset_file_path);

/// @ingroup ArRecordingConfig
/// Gets the uri that the MP4 dataset will be recorded to.
///
/// This will be null if @c ::ArRecordingConfig_setMp4DatasetFilePath was used
/// to set the output.
///
/// @param[in] session The ARCore session
/// @param[in] config The config object to query
/// @param[out] out_mp4_dataset_uri Pointer to a @c char* to receive
///     the address of the newly allocated uri.
void ArRecordingConfig_getMp4DatasetUri(const ArSession *session,
const ArRecordingConfig *config,
char **out_mp4_dataset_uri);

/// @ingroup ArRecordingConfig
/// Sets the file path to save an MP4 dataset file for the recording.
///
/// The uri must be able to be opened as a file descriptor for reading and
/// writing that supports @c lseek or @c #AR_ERROR_INVALID_ARGUMENT will be
/// returned when @c ::ArSession_startRecording is called.
///
/// @param[in] session The ARCore session
/// @param[in, out] config The config object to change
/// @param[in] mp4_dataset_uri The percent encoded, null terminated, uri to
/// write data to.
void ArRecordingConfig_setMp4DatasetUri(const ArSession *session,
ArRecordingConfig *config,
const char *mp4_dataset_uri);

/// @ingroup ArRecordingConfig
/// Gets the setting that indicates whether the recording should stop
/// automatically when the ARCore session is paused.
Expand Down Expand Up @@ -2721,6 +2757,30 @@ void ArSession_getSupportedCameraConfigsWithFilter(
ArStatus ArSession_setPlaybackDataset(ArSession *session,
const char *mp4_dataset_file_path);

/// Sets a MP4 dataset file to play back instead of using the live camera feed
/// and IMU sensor data.
///
/// This overrides the last path set by @c ::ArSession_setPlaybackDataset.
//
/// The uri must point to a resource that supports @c lseek.
//
/// See @c ::ArSession_setPlaybackDataset for more restrictions and details.
///
/// @param[in] session The ARCore session
/// @param[in] mp4_dataset_uri The percent encoded, null terminated uri for the
/// dataset
///
/// @return @c #AR_SUCCESS or any of:
/// - @c #AR_ERROR_INVALID_ARGUMENT if the file descriptor is not seekable.
/// - @c #AR_ERROR_SESSION_NOT_PAUSED if called when session is not paused.
/// - @c #AR_ERROR_SESSION_UNSUPPORTED if playback is incompatible with selected
/// features.
/// - @c #AR_ERROR_PLAYBACK_FAILED if an error occurred with the MP4 dataset
/// such as not being able to open the resource or the resource is unable to
/// be decoded.
ArStatus ArSession_setPlaybackDatasetUri(ArSession *session,
const char *mp4_dataset_uri);

/// @ingroup ArRecordingConfig
/// Describe the current playback status.
AR_DEFINE_ENUM(ArPlaybackStatus){
Expand Down
6 changes: 3 additions & 3 deletions samples/augmented_faces_java/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
applicationId "com.google.ar.core.examples.java.augmentedfaces"

// AR Optional apps must declare minSdkVersion >= 14.
// AR Required apps must declare minSdkVersion >= 24.
minSdkVersion 24
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName '1.0'
}
Expand All @@ -26,7 +26,7 @@ android {

dependencies {
// ARCore (Google Play Services for AR) library.
implementation 'com.google.ar:core:1.25.0'
implementation 'com.google.ar:core:1.26.0'

// Obj - a simple Wavefront OBJ file loader
// https://github.com/javagl/Obj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ public final class TrackingStateHelper {
private static final String EXCESSIVE_MOTION_MESSAGE = "Moving too fast. Slow down.";
private static final String INSUFFICIENT_LIGHT_MESSAGE =
"Too dark. Try moving to a well-lit area.";
private static final String INSUFFICIENT_LIGHT_ANDROID_S_MESSAGE =
"Too dark. Try moving to a well-lit area."
+ " Also, make sure the Block Camera is set to off in system settings.";
private static final String BAD_STATE_MESSAGE =
"Tracking lost due to bad internal state. Please try restarting the AR experience.";
private static final String CAMERA_UNAVAILABLE_MESSAGE =
"Another app is using the camera. Tap on this app or try closing the other one.";
private static final int ANDROID_S_SDK_VERSION = 31;

private final Activity activity;

Expand Down Expand Up @@ -69,7 +73,11 @@ public static String getTrackingFailureReasonString(Camera camera) {
case BAD_STATE:
return BAD_STATE_MESSAGE;
case INSUFFICIENT_LIGHT:
return INSUFFICIENT_LIGHT_MESSAGE;
if (android.os.Build.VERSION.SDK_INT < ANDROID_S_SDK_VERSION) {
return INSUFFICIENT_LIGHT_MESSAGE;
} else {
return INSUFFICIENT_LIGHT_ANDROID_S_MESSAGE;
}
case EXCESSIVE_MOTION:
return EXCESSIVE_MOTION_MESSAGE;
case INSUFFICIENT_FEATURES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.TreeMap;

/** Shader helper functions. */
public class ShaderUtil {
public final class ShaderUtil {
/**
* Converts a raw text file, saved as a resource, into an OpenGL ES shader.
*
Expand Down Expand Up @@ -125,4 +125,6 @@ private static String readShaderFileFromAssets(Context context, String filename)
return sb.toString();
}
}

private ShaderUtil() {}
}
2 changes: 1 addition & 1 deletion samples/augmented_faces_java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.android.tools.build:gradle:4.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
8 changes: 4 additions & 4 deletions samples/augmented_image_c/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ def arcore_libpath = "${buildDir}/arcore-native"
configurations { natives }

android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
applicationId "com.google.ar.core.examples.c.augmentedimage"

// "AR Optional" apps must declare minSdkVersion >= 14.
// "AR Required" apps must declare minSdkVersion >= 24.
minSdkVersion 24
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName '1.0'

Expand Down Expand Up @@ -53,8 +53,8 @@ android {

dependencies {
// ARCore (Google Play Services for AR) library.
implementation 'com.google.ar:core:1.25.0'
natives 'com.google.ar:core:1.25.0'
implementation 'com.google.ar:core:1.26.0'
natives 'com.google.ar:core:1.26.0'

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ void AugmentedImageApplication::OnPause() {
}
}

void AugmentedImageApplication::OnResume(void* env, void* context,
void* activity) {
void AugmentedImageApplication::OnResume(JNIEnv* env, jobject context,
jobject activity) {
LOGI("OnResume()");

if (ar_session_ == nullptr) {
Expand All @@ -75,8 +75,10 @@ void AugmentedImageApplication::OnResume(void* env, void* context,
// This method can and will fail in user-facing situations. Your
// application must handle these cases at least somewhat gracefully. See
// HelloAR Java sample code for reasonable behavior.
CHECK(ArCoreApk_requestInstall(env, activity, user_requested_install,
&install_status) == AR_SUCCESS);
CHECKANDTHROW(
ArCoreApk_requestInstall(env, activity, user_requested_install,
&install_status) == AR_SUCCESS,
env, "Please install Google Play Services for AR (ARCore).");

switch (install_status) {
case AR_INSTALL_STATUS_INSTALLED:
Expand All @@ -90,8 +92,8 @@ void AugmentedImageApplication::OnResume(void* env, void* context,
// This method can and will fail in user-facing situations. Your
// application must handle these cases at least somewhat gracefully. See
// HelloAR Java sample code for reasonable behavior.
CHECK(ArSession_create(env, context, &ar_session_) == AR_SUCCESS);
CHECK(ar_session_);
CHECKANDTHROW(ArSession_create(env, context, &ar_session_) == AR_SUCCESS,
env, "Failed to create AR session.");

ArConfig* ar_config = nullptr;
ArConfig_create(ar_session_, &ar_config);
Expand All @@ -103,20 +105,20 @@ void AugmentedImageApplication::OnResume(void* env, void* context,
ar_augmented_image_database);

ArConfig_setFocusMode(ar_session_, ar_config, AR_FOCUS_MODE_AUTO);
CHECK(ArSession_configure(ar_session_, ar_config) == AR_SUCCESS);
CHECKANDTHROW(ArSession_configure(ar_session_, ar_config) == AR_SUCCESS,
env, "Failed to configure AR session");

ArAugmentedImageDatabase_destroy(ar_augmented_image_database);
ArConfig_destroy(ar_config);

ArFrame_create(ar_session_, &ar_frame_);
CHECK(ar_frame_);

ArSession_setDisplayGeometry(ar_session_, display_rotation_, width_,
height_);
}

const ArStatus status = ArSession_resume(ar_session_);
CHECK(status == AR_SUCCESS);
CHECKANDTHROW(status == AR_SUCCESS, env, "Failed to resume AR session.");
}

ArAugmentedImageDatabase*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AugmentedImageApplication {
void OnPause();

// OnResume is called on the UI thread from the Activity's onResume method.
void OnResume(void* env, void* context, void* activity);
void OnResume(JNIEnv* env, jobject context, jobject activity);

// OnSurfaceCreated is called on the OpenGL thread when GLSurfaceView
// is created.
Expand Down
6 changes: 6 additions & 0 deletions samples/augmented_image_c/app/src/main/cpp/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ static void CallJavaHideFitToScanImage(jobject activity) {
activity);
}

void ThrowJavaException(JNIEnv* env, const char* msg) {
LOGE("Throw Java exception: %s", msg);
jclass c = env->FindClass("java/lang/RuntimeException");
env->ThrowNew(c, msg);
}

// Convenience function used in CreateProgram below.
static GLuint LoadShader(GLenum shader_type, const char* shader_source) {
GLuint shader = glCreateShader(shader_type);
Expand Down
15 changes: 15 additions & 0 deletions samples/augmented_image_c/app/src/main/cpp/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
}
#endif // CHECK

#ifndef CHECKANDTHROW
#define CHECKANDTHROW(condition, env, msg, ...) \
if (!(condition)) { \
LOGE("*** CHECK FAILED at %s:%d: %s", __FILE__, __LINE__, #condition); \
util::ThrowJavaException(env, msg); \
return ##__VA_ARGS__; \
}
#endif // CHECKANDTHROW

namespace augmented_image {

// Utilities for C AugmentedImage AR project.
Expand Down Expand Up @@ -83,6 +92,12 @@ void ReleaseJavaMethodIDs();
// @param operation, the name of the GL function call.
void CheckGlError(const char* operation);

// Throw a Java exception.
//
// @param env, the JNIEnv.
// @param msg, the message of this exception.
void ThrowJavaException(JNIEnv* env, const char* msg);

// Creates a shader program ID.
//
// @param vertex_source, the vertex shader source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.google.android.material.snackbar.Snackbar;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

Expand All @@ -48,6 +50,7 @@ public class AugmentedImageActivity extends AppCompatActivity
private GLSurfaceView surfaceView;
private ImageView fitToScanView;
private RequestManager glideRequestManager;
private Snackbar snackbar;

private boolean viewportChanged = false;
private int viewportWidth;
Expand Down Expand Up @@ -90,8 +93,14 @@ protected void onResume() {
return;
}

JniInterface.onResume(nativeApplication, getApplicationContext(), this);
surfaceView.onResume();
try {
JniInterface.onResume(nativeApplication, getApplicationContext(), this);
surfaceView.onResume();
} catch (Exception e) {
Log.e(TAG, "Exception resuming session", e);
displayInSnackbar(e.getMessage());
return;
}

fitToScanView.setVisibility(View.VISIBLE);

Expand Down Expand Up @@ -203,4 +212,11 @@ public void run() {
}
});
}

/** Display the message in the snackbar. */
private void displayInSnackbar(String message) {
snackbar =
Snackbar.make(findViewById(android.R.id.content), message, Snackbar.LENGTH_INDEFINITE);
snackbar.show();
}
}
2 changes: 1 addition & 1 deletion samples/augmented_image_c/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.android.tools.build:gradle:4.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
Loading

0 comments on commit e12a49b

Please sign in to comment.