// Thread safe
        internal void UpdateBuffer(long bufferId)
        {
            lock (mutex)
            {
                bool success = VarjoPluginMR.LockDataStreamBuffer(bufferId);
                if (!success)
                {
                    Debug.LogErrorFormat("Failed to lock data stream buffer {0}", bufferId);
                    return;
                }

                success = VarjoPluginMR.GetBufferMetadata(bufferId, out metadata);
                if (!success)
                {
                    Debug.LogErrorFormat("Failed to get buffer metadata {0}", bufferId);
                    return;
                }

                success = VarjoPluginMR.GetBufferCPUData(bufferId, out cpuData);
                if (!success)
                {
                    Debug.LogErrorFormat("Failed to get buffer CPU data {0}", bufferId);
                    return;
                }

                if (data == null || data.Length != metadata.byteSize)
                {
                    data = new byte[metadata.byteSize];
                }

                CopyCpuData(metadata, cpuData, invertRowOrder);
                VarjoPluginMR.UnlockDataStreamBuffer(bufferId);
                changed = true;
            }
        }
        internal override void NewFrameCallback(VarjoStreamFrame streamData, IntPtr userdata)
        {
            lock (mutex)
            {
                Debug.Assert(streamData.type == StreamType);
                data = streamData.distortedColorData;

                long leftBufferId = 0;
                if (!VarjoPluginMR.GetDataStreamBufferId(streamData.id, streamData.frameNumber, 0 /* varjo_ChannelIndex_Left */, out leftBufferId))
                {
                    Debug.LogErrorFormat("Failed to get distorted color left buffer id {0}", streamData.frameNumber);
                    return;
                }

                long rightBufferId = 0;
                if (!VarjoPluginMR.GetDataStreamBufferId(streamData.id, streamData.frameNumber, 1 /* varjo_ChannelIndex_Right */, out rightBufferId))
                {
                    Debug.LogErrorFormat("Failed to get distorted color right buffer id {0}", streamData.frameNumber);
                    return;
                }

                leftBuffer.UpdateBuffer(leftBufferId);
                rightBuffer.UpdateBuffer(rightBufferId);
            }
        }
Example #3
0
 /// <summary>
 /// Starts the frame stream.
 /// </summary>
 /// <returns>True, if frame stream supported and successfully started.</returns>
 public bool Start()
 {
     if (callback != null)
     {
         return(true);
     }
     callback = new VarjoStreamCallback(NewFrameCallback);
     return(VarjoPluginMR.StartDataStream(StreamType, callback));
 }
Example #4
0
        internal override void NewFrameCallback(VarjoStreamFrame streamData, IntPtr userdata)
        {
            lock (mutex)
            {
                Debug.Assert(streamData.type == StreamType);
                data = streamData.environmentCubemapData;

                long bufferId = 0;
                if (!VarjoPluginMR.GetDataStreamBufferId(streamData.id, streamData.frameNumber, 0 /* varjo_ChannelIndex_First */, out bufferId))
                {
                    Debug.LogErrorFormat("Failed to get cubemap buffer id {0}", streamData.frameNumber);
                    return;
                }
                buffer.UpdateBuffer(bufferId);
            }
        }
Example #5
0
 /// <summary>
 /// Stops the frame stream.
 /// </summary>
 public void Stop()
 {
     VarjoPluginMR.StopDataStream(StreamType);
     callback = null;
 }
Example #6
0
 /// <summary>
 /// Check if device supports the frame stream.
 /// </summary>
 /// <returns>True, if device supports this type of frame stream.</returns>
 public bool IsSupported()
 {
     return(VarjoPluginMR.SupportsDataStream(StreamType));
 }