Пример #1
0
        public bool Decode(ref Vp8PictureInfo pictureInfo, ISurface output, ReadOnlySpan <byte> bitstream)
        {
            Surface outSurf = (Surface)output;

            int uncompHeaderSize = pictureInfo.KeyFrame ? 10 : 3;

            byte[] frame = new byte[bitstream.Length + uncompHeaderSize];

            uint firstPartSizeShifted = pictureInfo.FirstPartSize << 5;

            frame[0]  = (byte)(pictureInfo.KeyFrame ? 0 : 1);
            frame[0] |= (byte)((pictureInfo.Version & 7) << 1);
            frame[0] |= 1 << 4;
            frame[0] |= (byte)firstPartSizeShifted;
            frame[1] |= (byte)(firstPartSizeShifted >> 8);
            frame[2] |= (byte)(firstPartSizeShifted >> 16);

            if (pictureInfo.KeyFrame)
            {
                frame[3] = 0x9d;
                frame[4] = 0x01;
                frame[5] = 0x2a;
                frame[6] = (byte)pictureInfo.FrameWidth;
                frame[7] = (byte)((pictureInfo.FrameWidth >> 8) & 0x3F);
                frame[8] = (byte)pictureInfo.FrameHeight;
                frame[9] = (byte)((pictureInfo.FrameHeight >> 8) & 0x3F);
            }

            bitstream.CopyTo(new Span <byte>(frame).Slice(uncompHeaderSize));

            return(_context.DecodeFrame(outSurf, frame) == 0);
        }
Пример #2
0
        public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
        {
            PictureInfo         pictureInfo = rm.Gmm.DeviceRead <PictureInfo>(state.SetPictureInfoOffset);
            ReadOnlySpan <byte> bitstream   = rm.Gmm.DeviceGetSpan(state.SetBitstreamOffset, (int)pictureInfo.VLDBufferSize);

            Decoder decoder = context.GetVp8Decoder();

            ISurface outputSurface = rm.Cache.Get(decoder, 0, 0, pictureInfo.FrameWidth, pictureInfo.FrameHeight);

            Vp8PictureInfo info = pictureInfo.Convert();

            uint lumaOffset   = state.SetSurfaceLumaOffset[3];
            uint chromaOffset = state.SetSurfaceChromaOffset[3];

            if (decoder.Decode(ref info, outputSurface, bitstream))
            {
                SurfaceWriter.Write(rm.Gmm, outputSurface, lumaOffset, chromaOffset);
            }

            rm.Cache.Put(outputSurface);
        }