From 2ac280b17cba4a5295519ecd59bb25dff8bf45ce Mon Sep 17 00:00:00 2001 From: Noel Victor Date: Tue, 29 Oct 2019 12:31:53 -0400 Subject: [PATCH] ARCore Android SDK v1.13.0 --- libraries/include/arcore_c_api.h | 80 +++++++---- samples/augmented_image_c/app/build.gradle | 4 +- .../main/cpp/augmented_image_application.h | 3 +- samples/augmented_image_c/build.gradle | 2 +- samples/augmented_image_java/app/build.gradle | 2 +- .../AugmentedImageActivity.java | 5 +- samples/augmented_image_java/build.gradle | 2 +- samples/cloud_anchor_java/app/build.gradle | 2 +- .../java/cloudanchor/CloudAnchorActivity.java | 3 - .../app/src/main/res/values/strings.xml | 2 +- samples/computervision_c/app/build.gradle | 4 +- .../main/cpp/computer_vision_application.h | 2 +- samples/computervision_c/build.gradle | 2 +- samples/computervision_java/app/build.gradle | 2 +- .../ComputerVisionActivity.java | 129 +++++++++--------- samples/computervision_java/build.gradle | 2 +- samples/hello_ar_c/app/build.gradle | 4 +- .../app/src/main/cpp/hello_ar_application.h | 3 +- samples/hello_ar_c/build.gradle | 2 +- samples/hello_ar_java/app/build.gradle | 2 +- .../java/helloar/HelloArActivity.java | 5 +- samples/hello_ar_java/build.gradle | 2 +- samples/shared_camera_java/app/build.gradle | 2 +- samples/shared_camera_java/build.gradle | 2 +- 24 files changed, 136 insertions(+), 132 deletions(-) diff --git a/libraries/include/arcore_c_api.h b/libraries/include/arcore_c_api.h index fdca18cad..11e62c2e1 100644 --- a/libraries/include/arcore_c_api.h +++ b/libraries/include/arcore_c_api.h @@ -779,9 +779,9 @@ AR_DEFINE_ENUM(ArCloudAnchorState){ /// error. The app should not attempt to recover from this error. AR_CLOUD_ANCHOR_STATE_ERROR_INTERNAL = -1, - /// The app cannot communicate with the ARCore Cloud because of an invalid - /// or unauthorized API key in the manifest, or because there was no API key - /// present in the manifest. + /// The app cannot communicate with the ARCore Cloud Anchor service because + /// of an invalid or unauthorized API key in the manifest, or because there + /// was no API key present in the manifest. AR_CLOUD_ANCHOR_STATE_ERROR_NOT_AUTHORIZED = -2, AR_CLOUD_ANCHOR_STATE_ERROR_SERVICE_UNAVAILABLE AR_DEPRECATED( @@ -790,7 +790,8 @@ AR_DEFINE_ENUM(ArCloudAnchorState){ /// The application has exhausted the request quota allotted to the given /// API key. The developer should request additional quota for the ARCore - /// Cloud for their API key from the Google Developers Console. + /// Cloud Anchor service for their API key from the Google Developers + /// Console. AR_CLOUD_ANCHOR_STATE_ERROR_RESOURCE_EXHAUSTED = -4, /// Hosting failed, because the server could not successfully process the @@ -798,8 +799,8 @@ AR_DEFINE_ENUM(ArCloudAnchorState){ /// device has gathered more data from the environment. AR_CLOUD_ANCHOR_STATE_ERROR_HOSTING_DATASET_PROCESSING_FAILED = -5, - /// Resolving failed, because the ARCore Cloud could not find the provided - /// cloud anchor ID. + /// Resolving failed, because the ARCore Cloud Anchor service could not find + /// the provided cloud anchor ID. AR_CLOUD_ANCHOR_STATE_ERROR_CLOUD_ID_NOT_FOUND = -6, AR_CLOUD_ANCHOR_STATE_ERROR_RESOLVING_LOCALIZATION_NO_MATCH AR_DEPRECATED( @@ -816,12 +817,12 @@ AR_DEFINE_ENUM(ArCloudAnchorState){ /// it. AR_CLOUD_ANCHOR_STATE_ERROR_RESOLVING_SDK_VERSION_TOO_NEW = -9, - /// The ARCore Cloud Anchor Service was unreachable. This can happen because - /// of a number of reasons. The device may is in airplane mode or does not - /// have a working internet connection. The request sent to the server could - /// have timed out with no response, there could be a bad network - /// connection, DNS unavailability, firewall issues, or anything that could - /// affect the device's ability to connect to the ARCore Cloud Anchor + /// The ARCore Cloud Anchor Service was unreachable. This can happen for + /// a number of reasons. The device might be in airplane mode or does not + /// have a working internet connection. The request sent to the server might + /// have timed out with no response, or there might be a bad network + /// connection, DNS unavailability, firewall issues, or anything else that + /// might affect the device's ability to connect to the ARCore Cloud Anchor /// service. AR_CLOUD_ANCHOR_STATE_ERROR_HOSTING_SERVICE_UNAVAILABLE = -10, }; @@ -1851,8 +1852,10 @@ void ArSession_getSupportedCameraConfigs(const ArSession *session, /// before calling resume(). Failure to do so will cause resume() to return /// AR_ERROR_ILLEGAL_STATE error. /// -/// Starting in ARCore 1.12, changing the active camera config will make -/// existing anchors and trackables fail to regain tracking. +/// Note: Starting in ARCore 1.12, changing the active camera config may cause +/// the tracking state on certain devices to become permanently PAUSED. For +/// consistent behavior across all supported devices, release any previously +/// created anchors and trackables when setting a new camera config. /// /// @param[in] session The ARCore session /// @param[in] camera_config The provided ArCameraConfig must be from a @@ -2029,6 +2032,12 @@ void ArCamera_getViewMatrix(const ArSession *session, /// anything other than #AR_TRACKING_STATE_TRACKING the pose should not be /// considered useful. Use ArCamera_getTrackingFailureReason() to determine the /// best recommendation to provide to the user to restore motion tracking. +/// +/// Note: Starting in ARCore 1.12, changing the active camera config using +/// {@link ArSession_setCameraConfig()} may cause the tracking state on certain +/// devices to become permanently PAUSED. For consistent behavior across all +/// supported devices, release any previously created anchors and trackables +/// when setting a new camera config. void ArCamera_getTrackingState(const ArSession *session, const ArCamera *camera, ArTrackingState *out_tracking_state); @@ -2092,7 +2101,7 @@ void ArCamera_getTextureIntrinsics(const ArSession *session, /// Releases a reference to the camera. This must match a call to /// ArFrame_acquireCamera(). /// -/// This method may safely be called with @c nullptr - it will do nothing. +/// This method may safely be called with @c NULL - it will do nothing. void ArCamera_release(ArCamera *camera); /// @} @@ -2283,7 +2292,8 @@ void ArFrame_transformCoordinates2d(const ArSession *session, /// @param[in] frame The current frame. /// @param[in] pixel_x Logical X position within the view, as from an /// Android UI event. -/// @param[in] pixel_y Logical X position within the view. +/// @param[in] pixel_y Logical Y position within the view, as from an +/// Android UI event. /// @param[inout] hit_result_list The list to fill. This list must have been /// previously allocated using ArHitResultList_create(). If the list has /// been previously used, it will first be cleared. @@ -2471,7 +2481,7 @@ void ArPointCloud_getTimestamp(const ArSession *session, /// Releases a reference to the point cloud. This must match a call to /// ArFrame_acquirePointCloud(). /// -/// This method may safely be called with @c nullptr - it will do nothing. +/// This method may safely be called with @c NULL - it will do nothing. void ArPointCloud_release(ArPointCloud *point_cloud); /// @} @@ -2496,7 +2506,7 @@ void ArImageMetadata_getNdkCameraMetadata( /// Releases a reference to the metadata. This must match a call to /// ArFrame_acquireImageMetadata(). /// -/// This method may safely be called with @c nullptr - it will do nothing. +/// This method may safely be called with @c NULL - it will do nothing. void ArImageMetadata_release(ArImageMetadata *metadata); /// Image formats produced by ARCore. @@ -2618,7 +2628,7 @@ void ArImage_getPlaneData(const ArSession *session, /// @deprecated in release 1.10.0. Please use the other ArImage_* functions to /// obtain image data. ARCore can produce a wide variety of images, not all of /// which can be represented using Android NDK AImage provided by this function. -/// In those cases, this method will return @c nullptr in out_ndk_image. +/// In those cases, this method will return @c NULL in out_ndk_image. void ArImage_getNdkImage(const ArImage *image, const AImage **out_ndk_image) AR_DEPRECATED( "deprecated in release 1.10.0. Please see function documentation"); @@ -2812,6 +2822,12 @@ void ArAnchor_getPose(const ArSession *session, ArPose *out_pose); /// Retrieves the current state of the pose of this anchor. +/// +/// Note: Starting in ARCore 1.12, changing the active camera config using +/// {@link ArSession_setCameraConfig()} may cause the tracking state on certain +/// devices to become permanently PAUSED. For consistent behavior across all +/// supported devices, release any previously created anchors and trackables +/// when setting a new camera config. void ArAnchor_getTrackingState(const ArSession *session, const ArAnchor *anchor, ArTrackingState *out_tracking_state); @@ -2824,7 +2840,7 @@ void ArAnchor_detach(ArSession *session, ArAnchor *anchor); /// Releases a reference to an anchor. To stop tracking for this anchor, call /// ArAnchor_detach() first. /// -/// This method may safely be called with @c nullptr - it will do nothing. +/// This method may safely be called with @c NULL - it will do nothing. void ArAnchor_release(ArAnchor *anchor); /// Acquires the cloud anchor ID of the anchor. The ID acquired is an ASCII @@ -2885,7 +2901,7 @@ void ArTrackableList_acquireItem(const ArSession *session, /// will necessarily stop tracking. The same trackable may still be included in /// from other calls, for example ArSession_getAllTrackables(). /// -/// This method may safely be called with @c nullptr - it will do nothing. +/// This method may safely be called with @c NULL - it will do nothing. void ArTrackable_release(ArTrackable *trackable); /// Retrieves the type of the trackable. See ::ArTrackableType for valid types. @@ -2895,6 +2911,12 @@ void ArTrackable_getType(const ArSession *session, /// Retrieves the current state of ARCore's knowledge of the pose of this /// trackable. +/// +/// Note: Starting in ARCore 1.12, changing the active camera config using +/// {@link ArSession_setCameraConfig()} may cause the tracking state on certain +/// devices to become permanently PAUSED. For consistent behavior across all +/// supported devices, release any previously created trackables when setting a +/// new camera config. void ArTrackable_getTrackingState(const ArSession *session, const ArTrackable *trackable, ArTrackingState *out_tracking_state); @@ -3057,9 +3079,10 @@ void ArPoint_getOrientationMode(const ArSession *session, /// @addtogroup augmented_image /// @{ -/// Returns the pose of the center of the detected image. The pose's +Y axis -/// will be a normal vector pointing out of the face of the image. The +X and +Z -/// axes represent right and up relative to the image. +/// Returns the pose of the center of the Augmented Image, in world coordinates. +/// The pose's transformed +Y axis will be the normal out of the plane. The +/// pose's transformed +X axis points from left to right on the image, and the +/// transformed +Z axis points from top to bottom on the image. /// /// If the tracking state is PAUSED/STOPPED, this returns the pose when the /// image state was last TRACKING, or the identity pose if the image state has @@ -3152,7 +3175,7 @@ void ArAugmentedImage_getTrackingMethod( /// (x, y, z) packing. /// @param[out] out_number_of_vertices The number of vertices in the mesh. The /// returned pointer will point to an array of size out_number_of_vertices * -/// 3 or @c nullptr if the size is 0. +/// 3 or @c NULL if the size is 0. void ArAugmentedFace_getMeshVertices(const ArSession *session, const ArAugmentedFace *face, const float **out_vertices, @@ -3176,7 +3199,7 @@ void ArAugmentedFace_getMeshVertices(const ArSession *session, /// (x, y, z) packing. /// @param[out] out_number_of_normals The number of normals in the mesh. The /// returned pointer will point to an array of size out_number_of_normals * -/// 3, or @c nullptr if the size is 0. +/// 3, or @c NULL if the size is 0. void ArAugmentedFace_getMeshNormals(const ArSession *session, const ArAugmentedFace *face, const float **out_normals, @@ -3200,8 +3223,7 @@ void ArAugmentedFace_getMeshNormals(const ArSession *session, /// coordinates in (u, v) packing. /// @param[out] out_number_of_texture_coordinates The number of texture /// coordinates in the mesh. The returned pointer will point to an array of -/// size out_number_of_texture_coordinates * 2, or @c nullptr if the size is -/// 0. +/// size out_number_of_texture_coordinates * 2, or @c NULL if the size is 0. void ArAugmentedFace_getMeshTextureCoordinates( const ArSession *session, const ArAugmentedFace *face, @@ -3229,7 +3251,7 @@ void ArAugmentedFace_getMeshTextureCoordinates( /// indices packed in consecutive triplets. /// @param[out] out_number_of_triangles The number of triangles in the mesh. The /// returned pointer will point to an array of size out_number_of_triangles -/// * 3, or @c nullptr if the size is 0. +/// * 3, or @c NULL if the size is 0. void ArAugmentedFace_getMeshTriangleIndices( const ArSession *session, const ArAugmentedFace *face, diff --git a/samples/augmented_image_c/app/build.gradle b/samples/augmented_image_c/app/build.gradle index 503d77521..f40d4fcb7 100644 --- a/samples/augmented_image_c/app/build.gradle +++ b/samples/augmented_image_c/app/build.gradle @@ -62,8 +62,8 @@ android { dependencies { // ARCore library - implementation 'com.google.ar:core:1.12.0' - natives 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' + natives 'com.google.ar:core:1.13.0' implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1' diff --git a/samples/augmented_image_c/app/src/main/cpp/augmented_image_application.h b/samples/augmented_image_c/app/src/main/cpp/augmented_image_application.h index 9015c7653..4e98b3ce9 100644 --- a/samples/augmented_image_c/app/src/main/cpp/augmented_image_application.h +++ b/samples/augmented_image_c/app/src/main/cpp/augmented_image_application.h @@ -38,8 +38,7 @@ namespace augmented_image { class AugmentedImageApplication { public: // Constructor and deconstructor. - AugmentedImageApplication() = default; - AugmentedImageApplication(AAssetManager* asset_manager); + explicit AugmentedImageApplication(AAssetManager* asset_manager); ~AugmentedImageApplication(); // OnPause is called on the UI thread from the Activity's onPause method. diff --git a/samples/augmented_image_c/build.gradle b/samples/augmented_image_c/build.gradle index 6253bd0ed..382bee5be 100644 --- a/samples/augmented_image_c/build.gradle +++ b/samples/augmented_image_c/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/samples/augmented_image_java/app/build.gradle b/samples/augmented_image_java/app/build.gradle index de1c4a497..4f84fad0b 100644 --- a/samples/augmented_image_java/app/build.gradle +++ b/samples/augmented_image_java/app/build.gradle @@ -35,7 +35,7 @@ android { dependencies { // ARCore library - implementation 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' // Obj - a simple Wavefront OBJ file loader // https://github.com/javagl/Obj diff --git a/samples/augmented_image_java/app/src/main/java/com/google/ar/core/examples/java/augmentedimage/AugmentedImageActivity.java b/samples/augmented_image_java/app/src/main/java/com/google/ar/core/examples/java/augmentedimage/AugmentedImageActivity.java index 8f1ef191a..3fdb8818f 100644 --- a/samples/augmented_image_java/app/src/main/java/com/google/ar/core/examples/java/augmentedimage/AugmentedImageActivity.java +++ b/samples/augmented_image_java/app/src/main/java/com/google/ar/core/examples/java/augmentedimage/AugmentedImageActivity.java @@ -177,10 +177,7 @@ protected void onResume() { try { session.resume(); } catch (CameraNotAvailableException e) { - // In some cases (such as another camera app launching) the camera may be given to - // a different app instead. Handle this properly by showing a message and recreate the - // session at the next iteration. - messageSnackbarHelper.showError(this, "Camera not available. Please restart the app."); + messageSnackbarHelper.showError(this, "Camera not available. Try restarting the app."); session = null; return; } diff --git a/samples/augmented_image_java/build.gradle b/samples/augmented_image_java/build.gradle index 6253bd0ed..382bee5be 100644 --- a/samples/augmented_image_java/build.gradle +++ b/samples/augmented_image_java/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/samples/cloud_anchor_java/app/build.gradle b/samples/cloud_anchor_java/app/build.gradle index f3d0126c6..de39e51cd 100644 --- a/samples/cloud_anchor_java/app/build.gradle +++ b/samples/cloud_anchor_java/app/build.gradle @@ -35,7 +35,7 @@ android { dependencies { // ARCore library - implementation 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' // Obj - a simple Wavefront OBJ file loader // https://github.com/javagl/Obj diff --git a/samples/cloud_anchor_java/app/src/main/java/com/google/ar/core/examples/java/cloudanchor/CloudAnchorActivity.java b/samples/cloud_anchor_java/app/src/main/java/com/google/ar/core/examples/java/cloudanchor/CloudAnchorActivity.java index b206699d0..9a9f055de 100644 --- a/samples/cloud_anchor_java/app/src/main/java/com/google/ar/core/examples/java/cloudanchor/CloudAnchorActivity.java +++ b/samples/cloud_anchor_java/app/src/main/java/com/google/ar/core/examples/java/cloudanchor/CloudAnchorActivity.java @@ -246,9 +246,6 @@ private void createSession() { try { session.resume(); } catch (CameraNotAvailableException e) { - // In some cases (such as another camera app launching) the camera may be given to - // a different app instead. Handle this properly by showing a message and recreate the - // session at the next iteration. snackbarHelper.showError(this, getString(R.string.snackbar_camera_unavailable)); session = null; return; diff --git a/samples/cloud_anchor_java/app/src/main/res/values/strings.xml b/samples/cloud_anchor_java/app/src/main/res/values/strings.xml index 10ee6abd9..36f3e2d68 100644 --- a/samples/cloud_anchor_java/app/src/main/res/values/strings.xml +++ b/samples/cloud_anchor_java/app/src/main/res/values/strings.xml @@ -35,7 +35,7 @@ Please update ARCore. Please update the app with a newer version of the ARCore SDK. This device does not support ARCore. - Camera unavailable. Please restart the app. + Camera unavailable. Try restarting the app. The anchor ID was shared via Firebase. Dismiss There was a Firebase Error. Please check Logcat for more details. diff --git a/samples/computervision_c/app/build.gradle b/samples/computervision_c/app/build.gradle index 1e453cfe3..9a5ef9a4e 100644 --- a/samples/computervision_c/app/build.gradle +++ b/samples/computervision_c/app/build.gradle @@ -62,8 +62,8 @@ android { dependencies { // ARCore library - implementation 'com.google.ar:core:1.12.0' - natives 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' + natives 'com.google.ar:core:1.13.0' implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1' diff --git a/samples/computervision_c/app/src/main/cpp/computer_vision_application.h b/samples/computervision_c/app/src/main/cpp/computer_vision_application.h index 1c0755f14..165d86e73 100644 --- a/samples/computervision_c/app/src/main/cpp/computer_vision_application.h +++ b/samples/computervision_c/app/src/main/cpp/computer_vision_application.h @@ -38,7 +38,7 @@ namespace computer_vision { class ComputerVisionApplication { public: // Constructor and deconstructor. - ComputerVisionApplication(AAssetManager* asset_manager); + explicit ComputerVisionApplication(AAssetManager* asset_manager); ~ComputerVisionApplication(); // OnPause is called on the UI thread from the Activity's onPause method. diff --git a/samples/computervision_c/build.gradle b/samples/computervision_c/build.gradle index 6253bd0ed..382bee5be 100644 --- a/samples/computervision_c/build.gradle +++ b/samples/computervision_c/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/samples/computervision_java/app/build.gradle b/samples/computervision_java/app/build.gradle index e69bb511e..03b90e598 100644 --- a/samples/computervision_java/app/build.gradle +++ b/samples/computervision_java/app/build.gradle @@ -35,7 +35,7 @@ android { dependencies { // ARCore library - implementation 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' // Obj - a simple Wavefront OBJ file loader // https://github.com/javagl/Obj diff --git a/samples/computervision_java/app/src/main/java/com/google/ar/core/examples/java/computervision/ComputerVisionActivity.java b/samples/computervision_java/app/src/main/java/com/google/ar/core/examples/java/computervision/ComputerVisionActivity.java index 40a3d2ebe..240a444ea 100644 --- a/samples/computervision_java/app/src/main/java/com/google/ar/core/examples/java/computervision/ComputerVisionActivity.java +++ b/samples/computervision_java/app/src/main/java/com/google/ar/core/examples/java/computervision/ComputerVisionActivity.java @@ -207,10 +207,7 @@ protected void onResume() { try { session.resume(); } catch (CameraNotAvailableException e) { - // In some cases (such as another camera app launching) the camera may be given to - // a different app instead. Handle this properly by showing a message and recreate the - // session at the next iteration. - messageSnackbarHelper.showError(this, "Camera not available. Please restart the app."); + messageSnackbarHelper.showError(this, "Camera not available. Try restarting the app."); session = null; return; } @@ -286,75 +283,74 @@ public void onDrawFrame(GL10 gl) { if (session == null) { return; } - // Notify ARCore session that the view size changed so that the perspective matrix and - // the video background can be properly adjusted. - cpuImageDisplayRotationHelper.updateSessionIfNeeded(session); - try { - session.setCameraTextureName(cpuImageRenderer.getTextureId()); - final Frame frame = session.update(); - final Camera camera = frame.getCamera(); - - // Keep the screen unlocked while tracking, but allow it to lock when tracking stops. - trackingStateHelper.updateKeepScreenOnFlag(camera.getTrackingState()); - - renderFrameTimeHelper.nextFrame(); - - switch (imageAcquisitionPath) { - case CPU_DIRECT_ACCESS: - renderProcessedImageCpuDirectAccess(frame); - break; - case GPU_DOWNLOAD: - renderProcessedImageGpuDownload(frame); - break; - } + // Synchronize here to avoid calling Session.update or Session.acquireCameraImage while paused. + synchronized (frameImageInUseLock) { + // Notify ARCore session that the view size changed so that the perspective matrix and + // the video background can be properly adjusted. + cpuImageDisplayRotationHelper.updateSessionIfNeeded(session); + + try { + session.setCameraTextureName(cpuImageRenderer.getTextureId()); + final Frame frame = session.update(); + final Camera camera = frame.getCamera(); + + // Keep the screen unlocked while tracking, but allow it to lock when tracking stops. + trackingStateHelper.updateKeepScreenOnFlag(camera.getTrackingState()); + + renderFrameTimeHelper.nextFrame(); - // Update the camera intrinsics' text. - runOnUiThread(() -> cameraIntrinsicsTextView.setText(getCameraIntrinsicsText(frame))); - } catch (Exception t) { - // Avoid crashing the application due to unhandled exceptions. - Log.e(TAG, "Exception on the OpenGL thread", t); + switch (imageAcquisitionPath) { + case CPU_DIRECT_ACCESS: + renderProcessedImageCpuDirectAccess(frame); + break; + case GPU_DOWNLOAD: + renderProcessedImageGpuDownload(frame); + break; + } + + // Update the camera intrinsics' text. + runOnUiThread(() -> cameraIntrinsicsTextView.setText(getCameraIntrinsicsText(frame))); + } catch (Exception t) { + // Avoid crashing the application due to unhandled exceptions. + Log.e(TAG, "Exception on the OpenGL thread", t); + } } } /* Demonstrates how to access a CPU image directly from ARCore. */ private void renderProcessedImageCpuDirectAccess(Frame frame) { - // Lock the image use to avoid pausing & resuming session when the image is in use. This is - // because switching resolutions requires all images to be released before session.resume() is - // called. - synchronized (frameImageInUseLock) { - try (Image image = frame.acquireCameraImage()) { - if (image.getFormat() != ImageFormat.YUV_420_888) { - throw new IllegalArgumentException( - "Expected image in YUV_420_888 format, got format " + image.getFormat()); - } - - ByteBuffer processedImageBytesGrayscale = null; - // Do not process the image with edge dectection algorithm if it is not being displayed. - if (isCVModeOn) { - processedImageBytesGrayscale = - edgeDetector.detect( - image.getWidth(), - image.getHeight(), - image.getPlanes()[0].getRowStride(), - image.getPlanes()[0].getBuffer()); - } + try (Image image = frame.acquireCameraImage()) { + if (image.getFormat() != ImageFormat.YUV_420_888) { + throw new IllegalArgumentException( + "Expected image in YUV_420_888 format, got format " + image.getFormat()); + } - cpuImageRenderer.drawWithCpuImage( - frame, - image.getWidth(), - image.getHeight(), - processedImageBytesGrayscale, - cpuImageDisplayRotationHelper.getViewportAspectRatio(), - cpuImageDisplayRotationHelper.getCameraToDisplayRotation()); - - // Measure frame time since last successful execution of drawWithCpuImage(). - cpuImageFrameTimeHelper.nextFrame(); - } catch (NotYetAvailableException e) { - // This exception will routinely happen during startup, and is expected. cpuImageRenderer - // will handle null image properly, and will just render the background. - cpuImageRenderer.drawWithoutCpuImage(); + ByteBuffer processedImageBytesGrayscale = null; + // Do not process the image with edge dectection algorithm if it is not being displayed. + if (isCVModeOn) { + processedImageBytesGrayscale = + edgeDetector.detect( + image.getWidth(), + image.getHeight(), + image.getPlanes()[0].getRowStride(), + image.getPlanes()[0].getBuffer()); } + + cpuImageRenderer.drawWithCpuImage( + frame, + image.getWidth(), + image.getHeight(), + processedImageBytesGrayscale, + cpuImageDisplayRotationHelper.getViewportAspectRatio(), + cpuImageDisplayRotationHelper.getCameraToDisplayRotation()); + + // Measure frame time since last successful execution of drawWithCpuImage(). + cpuImageFrameTimeHelper.nextFrame(); + } catch (NotYetAvailableException e) { + // This exception will routinely happen during startup, and is expected. cpuImageRenderer + // will handle null image properly, and will just render the background. + cpuImageRenderer.drawWithoutCpuImage(); } } @@ -439,10 +435,7 @@ private void onCameraConfigChanged(CameraConfig cameraConfig) { try { session.resume(); } catch (CameraNotAvailableException ex) { - // In a rare case (such as another camera app launching) the camera may be given to a - // different app and so may not be available to this app. Handle this properly by showing - // a message and recreate the session at the next iteration. - messageSnackbarHelper.showError(this, "Camera not available. Please restart the app."); + messageSnackbarHelper.showError(this, "Camera not available. Try restarting the app."); session = null; return; } diff --git a/samples/computervision_java/build.gradle b/samples/computervision_java/build.gradle index 6253bd0ed..382bee5be 100644 --- a/samples/computervision_java/build.gradle +++ b/samples/computervision_java/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/samples/hello_ar_c/app/build.gradle b/samples/hello_ar_c/app/build.gradle index e63b9ae76..cdce80a3d 100644 --- a/samples/hello_ar_c/app/build.gradle +++ b/samples/hello_ar_c/app/build.gradle @@ -62,8 +62,8 @@ android { dependencies { // ARCore library - implementation 'com.google.ar:core:1.12.0' - natives 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' + natives 'com.google.ar:core:1.13.0' implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1' diff --git a/samples/hello_ar_c/app/src/main/cpp/hello_ar_application.h b/samples/hello_ar_c/app/src/main/cpp/hello_ar_application.h index f083e1d6b..54a5c1fe3 100644 --- a/samples/hello_ar_c/app/src/main/cpp/hello_ar_application.h +++ b/samples/hello_ar_c/app/src/main/cpp/hello_ar_application.h @@ -40,8 +40,7 @@ namespace hello_ar { class HelloArApplication { public: // Constructor and deconstructor. - HelloArApplication() = default; - HelloArApplication(AAssetManager* asset_manager); + explicit HelloArApplication(AAssetManager* asset_manager); ~HelloArApplication(); // OnPause is called on the UI thread from the Activity's onPause method. diff --git a/samples/hello_ar_c/build.gradle b/samples/hello_ar_c/build.gradle index 6253bd0ed..382bee5be 100644 --- a/samples/hello_ar_c/build.gradle +++ b/samples/hello_ar_c/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/samples/hello_ar_java/app/build.gradle b/samples/hello_ar_java/app/build.gradle index 62dd5e0a1..f99749fc2 100644 --- a/samples/hello_ar_java/app/build.gradle +++ b/samples/hello_ar_java/app/build.gradle @@ -37,7 +37,7 @@ android { dependencies { // ARCore library // Dependency version is rewritten at build time. - implementation 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' // Obj - a simple Wavefront OBJ file loader // https://github.com/javagl/Obj diff --git a/samples/hello_ar_java/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java b/samples/hello_ar_java/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java index 14ae66dfd..305ac1d78 100644 --- a/samples/hello_ar_java/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java +++ b/samples/hello_ar_java/app/src/main/java/com/google/ar/core/examples/java/helloar/HelloArActivity.java @@ -178,10 +178,7 @@ protected void onResume() { try { session.resume(); } catch (CameraNotAvailableException e) { - // In some cases (such as another camera app launching) the camera may be given to - // a different app instead. Handle this properly by showing a message and recreate the - // session at the next iteration. - messageSnackbarHelper.showError(this, "Camera not available. Please restart the app."); + messageSnackbarHelper.showError(this, "Camera not available. Try restarting the app."); session = null; return; } diff --git a/samples/hello_ar_java/build.gradle b/samples/hello_ar_java/build.gradle index 6253bd0ed..382bee5be 100644 --- a/samples/hello_ar_java/build.gradle +++ b/samples/hello_ar_java/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/samples/shared_camera_java/app/build.gradle b/samples/shared_camera_java/app/build.gradle index 65af87d19..89194da37 100644 --- a/samples/shared_camera_java/app/build.gradle +++ b/samples/shared_camera_java/app/build.gradle @@ -37,7 +37,7 @@ android { dependencies { // ARCore library - implementation 'com.google.ar:core:1.12.0' + implementation 'com.google.ar:core:1.13.0' // Obj - a simple Wavefront OBJ file loader // https://github.com/javagl/Obj diff --git a/samples/shared_camera_java/build.gradle b/samples/shared_camera_java/build.gradle index 6253bd0ed..382bee5be 100644 --- a/samples/shared_camera_java/build.gradle +++ b/samples/shared_camera_java/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }