コード例 #1
0
        /// <inheritdoc cref="LibCuVideo.MapVideoFrame64(CuVideoDecoder, int, out CuDevicePtr, out int, ref CuVideoProcParams)"/>
        public CuVideoFrame MapVideoFrame(
            int picIndex, ref CuVideoProcParams param,
            out int pitch)
        {
            CuDevicePtr devicePtr;

            var result = Environment.Is64BitProcess
                ? LibCuVideo.MapVideoFrame64(
                    this, picIndex, out devicePtr,
                    out pitch, ref param)
                : LibCuVideo.MapVideoFrame(
                    this, picIndex, out devicePtr,
                    out pitch, ref param);

            CheckResult(result);

            return new CuVideoFrame(devicePtr, this);
        }
コード例 #2
0
ファイル: LibCuVideo.cs プロジェクト: jlennox/NvEncSharp
 public static extern CuResult MapVideoFrame64(CuVideoDecoder decoder, int nPicIdx,
                                               out CuDevicePtr devPtr, out int pitch, ref CuVideoProcParams vpp);
コード例 #3
0
ファイル: Program.cs プロジェクト: jlennox/NvEncSharp
        private CuCallbackResult VideoDisplayCallback(
            IntPtr data, IntPtr infoPtr)
        {
            using var _ = _context.Push();

            if (CuVideoParseDisplayInfo.IsFinalFrame(infoPtr, out var info))
            {
                if (!_framesChannel.Writer.TryWrite(
                        FrameInformation.FinalFrame))
                {
                    _renderingCompleted.Set();
                }

                return(CuCallbackResult.Success);
            }

            var processingParam = new CuVideoProcParams
            {
                ProgressiveFrame = info.ProgressiveFrame,
                SecondField      = info.RepeatFirstField + 1,
                TopFieldFirst    = info.TopFieldFirst,
                UnpairedField    = info.RepeatFirstField < 0 ? 1 : 0
            };

            using var frame = _decoder.MapVideoFrame(
                      info.PictureIndex, ref processingParam,
                      out var pitch);

            var yuvInfo = _info.GetYuvInformation(pitch);
            var status  = _decoder.GetDecodeStatus(info.PictureIndex);

            if (status != CuVideoDecodeStatus.Success)
            {
                // TODO: Determine what to do in this situation. This condition
                // is non-exceptional but may require different handling?
            }

            var frameByteSize = _info.GetFrameByteSize(
                pitch, out var chromaHeight);

            var destMemoryType = _useHostMemory
                ? CuMemoryType.Host
                : CuMemoryType.Device;

            AllocateNv12FrameBuffer(
                destMemoryType, frameByteSize,
                out var frameDevicePtr, out var frameLocalPtr);

            var byteWidth = _info.Width * _info.GetBytesPerPixel();

            // Copy luma
            var memcopy = new CuMemcopy2D
            {
                SrcMemoryType = CuMemoryType.Device,
                SrcDevice     = frame,
                SrcPitch      = (IntPtr)pitch,
                DstMemoryType = destMemoryType,
                DstDevice     = frameDevicePtr,
                DstHost       = frameLocalPtr,
                DstPitch      = (IntPtr)byteWidth,
                WidthInBytes  = (IntPtr)byteWidth,
                Height        = (IntPtr)_info.Height
            };

            memcopy.Memcpy2D();

            // Copy chroma
            memcopy.SrcDevice = new CuDevicePtr(frame.Handle + pitch * _info.Height);
            memcopy.DstDevice = new CuDevicePtr(frameDevicePtr.Handle + byteWidth * _info.Height);
            memcopy.DstHost   = frameLocalPtr + byteWidth * _info.Height;
            memcopy.Height    = (IntPtr)chromaHeight;
            memcopy.Memcpy2D();

            var bufferStorage = new BufferStorage(
                frameLocalPtr, destMemoryType,
                frameDevicePtr, frameByteSize);

            var frameInfo = new FrameInformation(
                bufferStorage, pitch, _info, yuvInfo);

            if (!_framesChannel.Writer.TryWrite(frameInfo))
            {
                _nv12BufferPool.Free(ref bufferStorage);
            }

            return(CuCallbackResult.Success);
        }