Exemplo n.º 1
0
        public bool TryGetValues(CameraMetadataTag metadataTag, List <CameraMetadataValue> outMetadataList)
        {
            if (m_ArCameraMetadataHandle == IntPtr.Zero)
            {
                // Intentionally ignored logging as the camera metadata is expected to be
                // unavailable in between frames.
                return(false);
            }

            return(m_NativeApi.CameraMetadata.TryGetValues(m_ArCameraMetadataHandle,
                                                           metadataTag, outMetadataList));
        }
Exemplo n.º 2
0
            /// <summary>
            /// Get camera image metadata value. The querying value type needs to match the returned type.
            /// The type could be checked in CameraMetadata.cs.
            /// </summary>
            /// <param name="metadataTag">Metadata type.</param>
            /// <param name="outMetadataList">Result list of the requested values.</param>
            /// <returns><c>true</c> if getting metadata value successfully, otherwise <c>false</c>.</returns>
            public static bool TryGetValues(CameraMetadataTag metadataTag, List <CameraMetadataValue> outMetadataList)
            {
                outMetadataList.Clear();
                var nativeSession = LifecycleManager.Instance.NativeSession;

                if (nativeSession == null)
                {
                    return(false);
                }

                var metadataHandle = nativeSession.FrameApi.AcquireImageMetadata();
                var isSuccess      = nativeSession.CameraMetadataApi.TryGetValues(metadataHandle, metadataTag, outMetadataList);

                nativeSession.CameraMetadataApi.Release(metadataHandle);
                return(isSuccess);
            }
Exemplo n.º 3
0
        public bool TryGetValues(IntPtr cameraMetadataHandle,
                                 CameraMetadataTag tag, List <CameraMetadataValue> resultList)
        {
            IntPtr ndkMetadataHandle = IntPtr.Zero;

            ExternApi.ArImageMetadata_getNdkCameraMetadata(m_NativeSession.SessionHandle,
                                                           cameraMetadataHandle, ref ndkMetadataHandle);

            resultList.Clear();
            NdkCameraMetadata entry  = new NdkCameraMetadata();
            NdkCameraStatus   status = ExternApi.ACameraMetadata_getConstEntry(ndkMetadataHandle, tag, ref entry);

            if (status != NdkCameraStatus.Ok)
            {
                ARDebug.LogErrorFormat("ACameraMetadata_getConstEntry error with native camera error code: {0}",
                                       status);
                return(false);
            }

            for (int i = 0; i < entry.Count; i++)
            {
                switch (entry.Type)
                {
                case NdkCameraMetadataType.Byte:
                    sbyte byteValue = (sbyte)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <sbyte>(entry.Value, i),
                        typeof(sbyte));
                    resultList.Add(new CameraMetadataValue(byteValue));
                    break;

                case NdkCameraMetadataType.Int32:
                    int intValue = (int)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <int>(entry.Value, i),
                        typeof(int));
                    resultList.Add(new CameraMetadataValue(intValue));
                    break;

                case NdkCameraMetadataType.Float:
                    float floatValue = (float)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <float>(entry.Value, i),
                        typeof(float));
                    resultList.Add(new CameraMetadataValue(floatValue));
                    break;

                case NdkCameraMetadataType.Int64:
                    long longValue = (long)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <long>(entry.Value, i),
                        typeof(long));
                    resultList.Add(new CameraMetadataValue(longValue));
                    break;

                case NdkCameraMetadataType.Double:
                    double doubleValue = (double)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <double>(entry.Value, i),
                        typeof(double));
                    resultList.Add(new CameraMetadataValue(doubleValue));
                    break;

                case NdkCameraMetadataType.Rational:
                    CameraMetadataRational rationalValue = (CameraMetadataRational)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <CameraMetadataRational>(entry.Value, i),
                        typeof(CameraMetadataRational));
                    resultList.Add(new CameraMetadataValue(rationalValue));
                    break;

                default:
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
 public static extern NdkCameraStatus ACameraMetadata_getConstEntry(IntPtr ndkCameraMetadata,
                                                                    CameraMetadataTag tag, ref NdkCameraMetadata entry);
Exemplo n.º 5
0
        public bool TryGetValues(IntPtr cameraMetadataHandle,
                                 CameraMetadataTag tag, List <CameraMetadataValue> resultList)
        {
            resultList.Clear();
            uint             utag   = (uint)tag;
            ArCameraMetadata entry  = new ArCameraMetadata();
            ApiArStatus      status =
                ExternApi.ArImageMetadata_getConstEntry(_nativeSession.SessionHandle,
                                                        cameraMetadataHandle, utag,
                                                        ref entry);

            if (status != ApiArStatus.Success)
            {
                ARDebug.LogErrorFormat(
                    "ArImageMetadata_getConstEntry error with native camera error code: {0}",
                    status);
                return(false);
            }

            if (entry.Count > _maximumTagCountForWarning && !_warningTags.Contains((int)tag))
            {
                Debug.LogWarningFormat(
                    "TryGetValues for tag {0} has {1} values. Accessing tags with a large " +
                    "number of values may impede performance.", tag, entry.Count);
                _warningTags.Add((int)tag);
            }

            for (int i = 0; i < entry.Count; i++)
            {
                switch (entry.Type)
                {
                case ArCameraMetadataType.Byte:
                    sbyte byteValue = (sbyte)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <sbyte>(entry.Value, i),
                        typeof(sbyte));
                    resultList.Add(new CameraMetadataValue(byteValue));
                    break;

                case ArCameraMetadataType.Int32:
                    int intValue = (int)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <int>(entry.Value, i),
                        typeof(int));
                    resultList.Add(new CameraMetadataValue(intValue));
                    break;

                case ArCameraMetadataType.Float:
                    float floatValue = (float)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <float>(entry.Value, i),
                        typeof(float));
                    resultList.Add(new CameraMetadataValue(floatValue));
                    break;

                case ArCameraMetadataType.Int64:
                    long longValue = (long)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <long>(entry.Value, i),
                        typeof(long));
                    resultList.Add(new CameraMetadataValue(longValue));
                    break;

                case ArCameraMetadataType.Double:
                    double doubleValue = (double)Marshal.PtrToStructure(
                        MarshalingHelper.GetPtrToUnmanagedArrayElement <double>(entry.Value, i),
                        typeof(double));
                    resultList.Add(new CameraMetadataValue(doubleValue));
                    break;

                case ArCameraMetadataType.Rational:
                    CameraMetadataRational rationalValue =
                        (CameraMetadataRational)Marshal.PtrToStructure(
                            MarshalingHelper
                            .GetPtrToUnmanagedArrayElement <CameraMetadataRational>(
                                entry.Value, i),
                            typeof(CameraMetadataRational));
                    resultList.Add(new CameraMetadataValue(rationalValue));
                    break;

                default:
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Get camera image metadata value. The querying value type needs to match the returned type.
 /// The type could be checked in CameraMetadata.cs.
 /// </summary>
 /// <param name="metadataTag">Metadata type.</param>
 /// <param name="outMetadataList">Result list of the requested values.</param>
 /// <returns><c>true</c> if getting metadata value successfully, otherwise <c>false</c>.</returns>
 public static bool TryGetValues(CameraMetadataTag metadataTag,
                                 List <CameraMetadataValue> outMetadataList)
 {
     return(Frame.s_FrameManager.CameraMetadataManager.TryGetValues(metadataTag, outMetadataList));
 }