/// <summary> /// Retrieves the device info object from the AbstractApplication. /// </summary> /// <returns> /// <c>VLDeviceInfo</c>, if the device info was acquired successfully; /// <c>null</c> otherwise. /// </returns> public VLDeviceInfo GetDeviceInfo() { if (this.disposed) { throw new ObjectDisposedException("VLAbstractApplicationWrapper"); } string deviceInfo; StringBuilder sb = new StringBuilder(65536); if (!vlAbstractApplicationWrapper_GetDeviceInfo(this.handle, sb, Convert.ToUInt32(sb.Capacity + 1))) { Debug.LogError("No valid device info returned..."); return(null); } deviceInfo = sb.ToString(); Debug.Log("[vlUnitySDK] DeviceInfoJson: " + deviceInfo); VLDeviceInfo devInfo = VLJsonUtility.FromJson <VLDeviceInfo>(deviceInfo); return(devInfo); }
/// <summary> /// Acquires a reference to the VLWorkerBehavioiur and gathers the /// VLDeviceInfo. /// </summary> private void Init() { // VLWorkerBeahaviour not specified explicitly? if (this.workerBehaviour == null) { // Try to get the VLWorkerBehaviour from the current GameObject this.workerBehaviour = GetComponent <VLWorkerBehaviour>(); // If the current GameObject doesn't have a VLWorkerBehaviour // attached, just use the first VLWorkerBehaviour from anywhere in // the scene if (this.workerBehaviour == null) { this.workerBehaviour = FindObjectOfType <VLWorkerBehaviour>(); // Failed to get VLWorkerBehaviour? if (this.workerBehaviour == null) { return; } } } // Try to get the VLDeviceInfo this.deviceInfo = this.workerBehaviour.GetDeviceInfo(); if (this.deviceInfo == null) { return; } this.initialized = true; }
public CameraResolutionSelector(VLDeviceInfo deviceInfo, bool resolutionSelection) { this.deviceInfo = deviceInfo; this.resolutionSelection = resolutionSelection; // Skip camera selection, if only one is available if (this.deviceInfo.availableCameras != null && this.deviceInfo.availableCameras.Length == 1) { SelectCamera(this.deviceInfo.availableCameras[0]); } }
private bool InitDeviceInfo() { if (this.deviceInfo != null) { return(true); } if (this.workerBehaviour == null) { return(false); } this.deviceInfo = this.workerBehaviour.GetDeviceInfo(); if (this.deviceInfo != null) { return(true); } return(false); }
private void Awake() { // Get a handle to the current object and make sure, that the object // doesn't get deleted by the garbage collector. We then use this // handle as client data for the native callbacks. This allows us to // retrieve the current address of the actual object during the // callback execution. GCHandleType.Pinned is not necessary, because we // are accessing the address only through the handle object, which gets // stored in a global handle table. this.gcHandle = GCHandle.Alloc(this); // Print the version of the vlUnitySDK. If this works, then we can be // quite certain, that other things also work. string version; string versionTimestamp; string versionHash; if (VLUnitySdk.GetVersionString(out version) && VLUnitySdk.GetVersionTimestampString(out versionTimestamp) && VLUnitySdk.GetVersionHashString(out versionHash)) { Debug.Log("[vlUnitySDK] v" + version + " (" + versionTimestamp + ", " + versionHash + ")"); } else { Debug.LogWarning("[vlUnitySDK] Failed to get version strings"); } // Construct the path to the directory with the tracking configurations, // if it wasn't specified explicitly if (String.IsNullOrEmpty(this.baseDir)) { #if UNITY_ANDROID && !UNITY_EDITOR this.baseDir = "file:///android_asset/VisionLib"; #else this.baseDir = Path.Combine( Application.streamingAssetsPath, "VisionLib"); #endif } // Construct the path to the Resources folder (the Resource folder is // only used by certain platforms) #if UNITY_ANDROID && !UNITY_EDITOR this.resourceDir = "file:///android_asset/VisionLib/Resources"; #else this.resourceDir = Path.Combine( Application.streamingAssetsPath, "VisionLib/Resources"); #endif // Create an AbstractApplication, which will manage the ActionPipe and // DataSet this.aap = new VLAbstractApplicationWrapper(); this.deviceInfo = this.aap.GetDeviceInfo(); // Set the path to the license file #if UNITY_ANDROID && !UNITY_EDITOR string absoluteLicenseFilePath = Path.Combine( "file:///android_asset/", this.licenseFile.path); #else string absoluteLicenseFilePath = Path.Combine( Application.streamingAssetsPath, this.licenseFile.path); #endif this.aap.SetLicenseFilePath(absoluteLicenseFilePath); // Add a log listener, which will write all VisionLib logs to the // Unity console this.logger = new VLLogger(); #if UNITY_2017_1_OR_NEWER // Unity 2017 with Mono .NET 4.6 as scripting runtime version can't // properly handle callbacks from external threads. Until this is // fixed, we need to buffer the log messages and fetch them from the // main thread inside the update function. this.logger.EnableLogBuffer(); #else this.logger.DisableLogBuffer(); #endif this.logger.SetLogLevel(this.logLevel); // Print the host ID. This ID is needed for generating a license file. string hostID; if (this.aap.GetHostID(out hostID)) { Debug.Log("[vlUnitySDK] HostID=" + hostID); } else { Debug.LogWarning("[vlUnitySDK] Failed to get host ID"); } // Many VisionLib features are implemented as plugins, which we need // to load first string pluginPath = Application.dataPath + Path.DirectorySeparatorChar + "Plugins"; // The plugins are in architecture specific sub-directories before the // deployment #if UNITY_EDITOR pluginPath += Path.DirectorySeparatorChar + VLUnitySdk.subDir; #endif this.aap.AutoLoadPlugins(pluginPath); // Create worker instance and register listeners for it this.worker = new VLWorker(this.aap); if (!this.worker.AddImageListener( dispatchImageCallbackDelegate, GCHandle.ToIntPtr(this.gcHandle))) { Debug.LogWarning("[vlUnitySDK] Failed to add image listener"); } if (!this.worker.AddExtrinsicDataListener( dispatchExtrinsicDataCallbackDelegate, GCHandle.ToIntPtr(this.gcHandle))) { Debug.LogWarning("[vlUnitySDK] Failed to add extrinsic data listener"); } if (!this.worker.AddIntrinsicDataListener( dispatchIntrinsicDataCallbackDelegate, GCHandle.ToIntPtr(this.gcHandle))) { Debug.LogWarning("[vlUnitySDK] Failed to add intrinsic data listener"); } if (!this.worker.AddTrackingStateListener( dispatchTrackingStateCallbackDelegate, GCHandle.ToIntPtr(this.gcHandle))) { Debug.LogWarning("[vlUnitySDK] Failed to add tracking state listener"); } if (!this.worker.AddPerformanceInfoListener( dispatchPerformanceInfoCallbackDelegate, GCHandle.ToIntPtr(this.gcHandle))) { Debug.LogWarning("[vlUnitySDK] Failed to add performance info listener"); } }