public override Status StartRun(Texture texture)
    {
        Debug.Log("This graph is for testing official examples. You can customize the graph by editing `official_demo_android.txt` (default is `hand_tracking_mobile.pbtxt`)");

        sidePacket = new SidePacket();
        sidePacket.Emplace("num_hands", new IntPacket(2));

#if UNITY_ANDROID
        var       glTextureName = texture.GetNativeTexturePtr();
        var       textureWidth  = texture.width;
        var       textureHeight = texture.height;
        GpuBuffer gpuBuffer     = null;

        gpuHelper.RunInGlContext(() => {
            var glContext       = GlContext.GetCurrent();
            var glTextureBuffer = new GlTextureBuffer((UInt32)glTextureName, textureWidth, textureHeight,
                                                      GpuBufferFormat.kBGRA32, OnReleaseDestinationTexture, glContext);
            gpuBuffer = new GpuBuffer(glTextureBuffer);
            return(Status.Ok());
        }).AssertOk();

        outputPacket = new GpuBufferPacket(gpuBuffer);
        sidePacket.Emplace(destinationBufferName, outputPacket);
#endif

        return(graph.StartRun(sidePacket));
    }
Example #2
0
        public GpuBuffer BuildGpuBuffer(GlContext glContext)
        {
#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID
            var glTextureBuffer = new GlTextureBuffer(GetTextureName(), width, height, gpuBufferformat, OnReleaseTextureFrame, glContext);
            return(new GpuBuffer(glTextureBuffer));
#else
            throw new NotSupportedException("This method is only supported on Linux or Android");
#endif
        }
    static IntPtr BuildDestination()
    {
        var glContext       = GlContext.GetCurrent();
        var glTextureBuffer = new GlTextureBuffer((UInt32)destinationNativeTexturePtr, destinationWidth, destinationHeight,
                                                  GpuBufferFormat.kBGRA32, OnReleaseDestinationTexture, glContext);

        outputPacket = new GpuBufferPacket(new GpuBuffer(glTextureBuffer));

        return(Status.Ok().mpPtr);
    }
    static IntPtr PushInputInGlContext()
    {
        try {
            var glContext       = GlContext.GetCurrent();
            var glTextureBuffer = new GlTextureBuffer((UInt32)currentTextureName, currentTextureFrame.width, currentTextureFrame.height,
                                                      currentTextureFrame.gpuBufferformat, currentTextureFrame.OnRelease, glContext);
            var gpuBuffer = new GpuBuffer(glTextureBuffer);

            // TODO: ensure the returned status won't be garbage collected prematurely.
            return(graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, currentTimestamp)).mpPtr);
        } catch (Exception e) {
            return(Status.FailedPrecondition(e.ToString()).mpPtr);
        }
    }
    /// <summary>
    ///   Convert <paramref name="colors" /> to a packet and send it to the input stream.
    /// </summary>
    public Status PushInput(TextureFrame textureFrame)
    {
        var        timestamp  = new Timestamp(System.Environment.TickCount & System.Int32.MaxValue);
        ImageFrame imageFrame = null;

        if (!IsGpuEnabled())
        {
            imageFrame = new ImageFrame(
                ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray());
            textureFrame.Release();
            var packet = new ImageFramePacket(imageFrame, timestamp);

            return(graph.AddPacketToInputStream(inputStream, packet));
        }

#if UNITY_ANDROID
        var glTextureName = textureFrame.GetNativeTexturePtr();

        return(gpuHelper.RunInGlContext(() => {
            var glContext = GlContext.GetCurrent();
            var glTextureBuffer = new GlTextureBuffer((UInt32)glTextureName, textureFrame.width, textureFrame.height,
                                                      textureFrame.gpuBufferformat, textureFrame.OnRelease, glContext);
            var gpuBuffer = new GpuBuffer(glTextureBuffer);

            return graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, timestamp));
        }));
#else
        imageFrame = new ImageFrame(
            ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray());
        textureFrame.Release();

        return(gpuHelper.RunInGlContext(() => {
            var texture = gpuHelper.CreateSourceTexture(imageFrame);
            var gpuBuffer = texture.GetGpuBufferFrame();

            Gl.Flush();
            texture.Release();

            return graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, timestamp));
        }));
#endif
    }