Exemple #1
0
        /* public sBuffersSet allocateEncodedBuffers( int encodedBuffers, ref sPixelFormatMP format )
         * {
         *      sCreateBuffers buffers = new sCreateBuffers()
         *      {
         *              count = encodedBuffers,
         *              memory = eMemory.MemoryMap,
         *      };
         *      buffers.format.bufferType = eBufferType.VideoOutputMPlane;
         *      buffers.format.pix_mp = format;
         *      Logger.logVerbose( "allocateEncodedBuffers: {0} buffers\n{1}", encodedBuffers, format );
         *      file.call( eControlCode.CREATE_BUFS, ref buffers );
         *      return new sBuffersSet( buffers.index, buffers.count );
         * } */

        /* internal sBuffersSet allocateDecodedBuffers( int decodedBuffersCount, ref VideoTextureDesc desc, ref DmaBuffers dma )
         * {
         *      sCreateBuffers buffers = new sCreateBuffers()
         *      {
         *              count = decodedBuffersCount,
         *              memory = eMemory.MemoryMap,
         *      };
         *      buffers.format.bufferType = eBufferType.VideoCaptureMPlane;
         *
         *      sPixelFormatMP pf = default;
         *      pf.size = desc.lumaSize;
         *      pf.pixelFormat = ePixelFormat.NV12;
         *      pf.field = eField.Progressive;
         *      pf.numPlanes = 2;
         *
         *      sPlanePixelFormat ppf = default;
         *      ppf.bytesPerLine = dma.luma.stride;
         *      ppf.sizeImage = dma.luma.stride * desc.lumaSize.cy;
         *      pf.setPlaneFormat( 0, ppf );
         *
         *      ppf.bytesPerLine = dma.chroma.stride;
         *      ppf.sizeImage = dma.chroma.stride * desc.chromaSize.cy;
         *      pf.setPlaneFormat( 1, ppf );
         *
         *      buffers.format.pix_mp = pf;
         *      file.call( eControlCode.CREATE_BUFS, ref buffers );
         *      return new sBuffersSet( buffers.index, buffers.count );
         * } */

        public bool tryGetEvent(out sEvent evt)
        {
            int res;

            unsafe
            {
                fixed(sEvent *pointer = &evt)
                res = LibC.ioctl(file, (uint)eControlCode.DQEVENT, pointer);
            }
            if (0 == res)
            {
                // Got an event
                return(true);
            }
            // Got no event, check errno
            int errno = Marshal.GetLastWin32Error();

            if (errno == LibC.ENOENT)
            {
                // Undocumented behavior, BTW, kernel.org docs never say the "no events" condition generates ENOENT code.
                evt = default;
                return(false);
            }

            string message = NativeErrorMessages.lookupLinuxError(errno);

            if (null != message)
            {
                throw new COMException($"I/O control code DQEVENT failed: { message }", LibC.hresultFromLinux(errno));
            }
            throw new COMException($"I/O control code DQEVENT failed: undocumented Linux error code { errno }", LibC.hresultFromLinux(errno));
        }