Example #1
0
        /// <summary>
        /// This method gets called when an encoded video sample has been received from the remote call party.
        /// The sample needs to be decoded and then handed off to the UI for display.
        /// </summary>
        /// <param name="sample">The encoded video sample.</param>
        public void EncodedVideoSampleReceived(byte[] sample, int length)
        {
            IntPtr encodedBufferPtr = Marshal.AllocHGlobal(length);

            Marshal.Copy(sample, 0, encodedBufferPtr, length);

            byte[] decodedBuffer    = null;
            uint   decodedImgWidth  = 0;
            uint   decodedImgHeight = 0;

            unsafe
            {
                _vpxDecoder.Decode((byte *)encodedBufferPtr, length, ref decodedBuffer, ref decodedImgWidth, ref decodedImgHeight);
            }

            Marshal.FreeHGlobal(encodedBufferPtr);

            if (decodedBuffer != null && decodedBuffer.Length > 0)
            {
                IntPtr decodedSamplePtr = Marshal.AllocHGlobal(decodedBuffer.Length);
                Marshal.Copy(decodedBuffer, 0, decodedSamplePtr, decodedBuffer.Length);

                byte[] bmp = null;

                unsafe
                {
                    _imageConverter.ConvertYUVToRGB((byte *)decodedSamplePtr, VideoSubTypesEnum.I420, Convert.ToInt32(decodedImgWidth), Convert.ToInt32(decodedImgHeight), VideoSubTypesEnum.RGB24, ref bmp);
                }

                Marshal.FreeHGlobal(decodedSamplePtr);

                OnRemoteVideoSampleReady?.Invoke(bmp, Convert.ToInt32(decodedImgWidth), Convert.ToInt32(decodedImgHeight));
            }
        }