Example #1
0
 public FrameBufferInfo()
 {
     rotation = TRTCVideoRotation.TRTCVideoRotation0;
     newFrame = false;
     width    = 0;
     height   = 0;
     data     = null;
 }
Example #2
0
        public bool AppendVideoFrame(byte[] data, int width, int height, TRTCVideoPixelFormat videoFormat, TRTCVideoRotation rotation)
        {
            if (!mFirstFrame)
            {
                mFirstFrame = true;
            }
            if (mPause)
            {
                return(false);
            }
            if (data == null || data.Length <= 0)
            {
                return(false);
            }
            // data 数据有误
            if (videoFormat == TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32 && width * height * 4 != data.Length)
            {
                return(false);
            }
            // 暂时不支持其他 YUV 类型
            if (videoFormat == TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420 && width * height * 3 / 2 != data.Length)
            {
                return(false);
            }

            // 目前只实现了 BGRA32 的数据类型,如需其他类型请重写,并设置回调的数据类型
            if (videoFormat == TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32)
            {
                lock (mArgbFrame)
                {
                    if (mArgbFrame.data == null || mArgbFrame.width != width || mArgbFrame.height != height)
                    {
                        ReleaseBuffer(mArgbFrame);
                        mArgbFrame.width  = width;
                        mArgbFrame.height = height;
                        mArgbFrame.data   = new byte[data.Length];
                    }
                    Buffer.BlockCopy(data, 0, mArgbFrame.data, 0, (int)data.Length);
                    mArgbFrame.newFrame = true;
                    mArgbFrame.rotation = rotation;
                }
            }

            // 回到主线程刷新当前画面
            this.InvokeOnUiThreadIfRequired(new Action(() =>
            {
                this.Refresh();
            }));
            return(true);
        }
Example #3
0
        /// <summary>
        /// 支持rbga数据处理,如需自定义数据,需重载此函数。
        /// </summary>
        private void AppendVideoFrame(byte[] data, uint length, uint width, uint height, TRTCVideoPixelFormat videoFormat, TRTCVideoRotation rotation)
        {
            if (data == null)
            {
                return;
            }
            // 当下不支持YUV
            if (videoFormat == TRTCVideoPixelFormat.TRTCVideoPixelFormat_I420 && length != width * height * 3 / 2)
            {
                return;
            }
            if (videoFormat == TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32 && length != width * height * 4)
            {
                return;
            }

            if (videoFormat == TRTCVideoPixelFormat.TRTCVideoPixelFormat_BGRA32)
            {
                lock (locker)
                {
                    if (mArgbRenderFrame.data == null || mArgbRenderFrame.width != width || mArgbRenderFrame.height != height)
                    {
                        ReleaseBuffer(mArgbRenderFrame);
                        mArgbRenderFrame.width  = (int)width;
                        mArgbRenderFrame.height = (int)height;
                        mArgbRenderFrame.data   = new byte[length];
                    }
                    Buffer.BlockCopy(data, 0, mArgbRenderFrame.data, 0, (int)length);
                    mArgbRenderFrame.newFrame = true;
                    mArgbRenderFrame.rotation = rotation;
                }
            }
        }