/// <summary>
        /// Transmit data from current video frame of a <see cref="DecodeContext"/> to a buffer.
        /// The buffer holds data for a <see cref="Texture2D"/>. It must have enough capacity to hold the data from a buffer with specified width and height, and format <see cref="SurfaceFormat.Color"/>.
        /// </summary>
        /// <param name="context">The <see cref="DecodeContext"/> </param>
        /// <param name="textureWidth">Width of the texture.</param>
        /// <param name="textureHeight">Height of the texture.</param>
        /// <param name="buffer">The data buffer.</param>
        /// <returns><see langword="true"/> if all successful, otherwise <see langword="false"/>.</returns>
        /// <seealso cref="RequiredPixelFormat"/>
        internal static bool TransmitVideoFrame([NotNull] DecodeContext context, int textureWidth, int textureHeight, [NotNull] uint[] buffer)
        {
            Trace.Assert(textureWidth > 0 && textureHeight > 0);

            var videoContext = context.VideoContext;

            if (videoContext == null)
            {
                return(false);
            }

            // Fetch the latest decoded frame.
            // You should use a synchronizing mechanism to avoid race condition. See DecodeContext.VideoFrameTransmissionLock.
            var videoFrame = context.FetchAvailableVideoFrame();

            if (videoFrame == null)
            {
                return(false);
            }

            // Here we use the function in FFmpeg to calculate it for us.
            // Note the pixel format parameter. We assume that the texture uses the same format.
            var requiredBufferSize = ffmpeg.av_image_get_buffer_size(RequiredPixelFormat, textureWidth, textureHeight, 0);

            if (buffer.Length * sizeof(uint) < requiredBufferSize)
            {
                return(false);
            }

            // Get the SWS context.
            var scaleContext = videoContext.GetSuitableScaleContext(textureWidth, textureHeight);

            // The type conversion here provided by FFmpeg.AutoGen is invalid, so we have to write a little code...
            fixed(uint *pBuffer = buffer)
            {
                var dstData   = new[] { (byte *)pBuffer };
                var dstStride = new[] { textureWidth *sizeof(uint) };

                // Perform scaling (if needed) and pixel format conversion (if needed), and copy the data to our buffer.
                // Thanks @Slow for pointing out the return value of sws_scale.
                // This contributes to the correct version of Verify() method. I should have read the docs more carefully.
                Verify(ffmpeg.sws_scale(scaleContext, videoFrame->data, videoFrame->linesize, 0, videoContext.CodecContext->height, dstData, dstStride));
            }

            return(true);
        }