- Home /
How to use multi-threading on Hololens
We're trying to use multi-threading on the Hololens, but fail.
Currently our App is running to many operations in the main-thread that if we start our "live-stream" (working with WebcamTexture) the Holograms don't appear anymore.
So to start of with we want to ask how could we use threads run parts of our photocapture-code (seen below) more efficiently? So we can understand which parts to run in different threads.$
We're using Unity 2018.4.10f1
using UnityEngine;
using System.Linq;
using UnityEngine.XR.WSA.WebCam;
public partial class PhotocaptureFrame : MonoBehaviour
{
public PhotoCapture photoCaptureObject = null;
public GameObject quad;
public static PhotocaptureFrame Instance { get; set; }
private Texture2D imageTexture;
private CameraParameters c;
private Resolution cameraResolution;
private void Start()
{
cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject)
{
photoCaptureObject = captureObject;
//CameraParameters c = new CameraParameters();
c.hologramOpacity = 0.0f;
c.cameraResolutionWidth = cameraResolution.width;
c.cameraResolutionHeight = cameraResolution.height;
c.pixelFormat = CapturePixelFormat.BGRA32;
captureObject.StartPhotoModeAsync(c, delegate (PhotoCapture.PhotoCaptureResult result)
{
photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
});
});
Instance = this;
}
public void MakePhoto()
{
PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject)
{
photoCaptureObject = captureObject;
captureObject.StartPhotoModeAsync(c, delegate (PhotoCapture.PhotoCaptureResult result)
{
photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
});
});
}
public void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
{
Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); // Create our Texture2D for use and set the correct resolution
Texture2D targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
photoCaptureFrame.UploadImageDataToTexture(targetTexture); // Copy the raw image data into our target texture
imageTexture = targetTexture; //Save image to new Texture to not loose it
quad.GetComponent<Renderer>().material.mainTexture = imageTexture; // Do as we wish with the texture such as apply it to a material, etc.
//photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoModeEnd);
// Clean up
photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoModeEnd);
}
public void OnStoppedPhotoModeEnd(PhotoCapture.PhotoCaptureResult result)
{
photoCaptureObject.Dispose();
photoCaptureObject = null;
Debug.Log("Photo object disposed.");
}
}
Thanks allot any help is appreciated
@Spoon92 did you eventually find any Answers (that doesn't involve a payed unity Asset) on this? One year later and I am having the same issue. I am using photoCapture and send the photo through network to a server...this takes time for rendering the graphics.
@sdavari the free solution will be using turbojpeg lib, which supports multi-threading. However, we've spent weeks to make it work properly on HoloLens 2.
Answer by thelghome · Nov 25, 2019 at 02:06 PM
FMETP STREAM supports HoloLens Live Streaming, encoding/decoding with multi-threading. https://youtu.be/1zh3VkwhIag
Asset Store: http://u3d.as/1uHj
Your answer
Follow this Question
Related Questions
Unity Threading Issue: Not able to delegate task 0 Answers
IJobParallelForTransform is not Multi threaded? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Change a gameObject property at runtime from another thread 0 Answers