0

I have a device which is sending RGB32 encoded color image frames as byte arrays at 30 FPS.

I'd like to send these frames to the browser in the most performant manner possible via a websocket connection.

I'm assuming that the best way to get the image data through the websocket is as a base64 string that I interpret as a URI in the browser, but base64 encoding raw RGB32 data obviously doesn't work, as it's not interpretable by the browser.

Therefore, I need to encode the RGB32 data as jpg before encoding into base64 and sending down the pipe, but all of the solutions I have been able to find for encoding byte arrays involve saving to the disk, which is obviously a performance killer.

Can anyone explain to me a performant manner to convert these RGB32 byte arrays to jpgs on the fly so I can push them down the pipe?

Alternately, if anyone has any ideas on an alternate high performance manner to get these RGBA frames down a websocket to a browser, I'd love to hear.

Thanks!

Code looks something like this:

private void ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
    using (ColorImageFrame frame = e.OpenColorImageFrame())
    {
        if (frame != null)
        {
            byte[] pixelData = new byte[frame.PixelDataLength];
            frame.CopyPixelDataTo(pixelData);
            //display in wpf   
            this._ColorImageBitmap.WritePixels(this._ColorImageBitmapRect, pixelData, this._ColorImageStride, 0);

            //send via websocket to chrome
            //how do we create a base64 encoded jpg here and pass it off to chrome?
            MainWindow.Broadcast(DataForChromeGoesHere);

        }
    }
}
4

0 回答 0