/* 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)); }
/// <summary>Create a .NET exception from errno global variable</summary> public static Exception exception(string what, int returnedValue) { if (returnedValue == -1) { int errno = Marshal.GetLastWin32Error(); string message = NativeErrorMessages.lookupLinuxError(errno); if (null != message) { return(new COMException($"{ what }: { message }", hresultFromLinux(errno))); } return(new COMException($"{ what }: undocumented Linux error code { errno }", hresultFromLinux(errno))); } return(new ApplicationException($"{ what }: unexpected result { returnedValue }")); }
static Exception getExceptionForHResult(int hr) { // Windows version is in C++ (an OS component, really) and it defines quite a few custom error codes for various MediaEngine errors. string msg = NativeErrorMessages.customErrorMessage(hr); if (null != msg) { return(new COMException(msg, hr)); } msg = ErrorCodes.tryLookupCode(hr); if (null != msg) { return(new COMException(msg, hr)); } return(Marshal.GetExceptionForHR(hr)); }
/// <summary>Get a clock reading, measured since Unix epoch</summary> /// <seealso cref="LinuxTime.getTime(TimeSpan)" /> public static TimeSpan gettime(eClock clock) { int ret = clock_gettime(clock, out var time); if (ret >= 0) { return(time); } int errno = Marshal.GetLastWin32Error(); if (0 != errno) { NativeErrorMessages.throwForHR(hresultFromLinux(errno)); } throw new ApplicationException(); }
static Exception exception(int hr) { string msg; if ((hr & NativeErrorMessages.facilityMask) == FACILITY_DECODER_DTS) { IntPtr ptr = DTS.AudioDecoder.formatMessage(hr & 0xFFFF); msg = Marshal.PtrToStringUTF8(ptr); return(new ApplicationException($"DTS decoder failed: { msg }")); } msg = NativeErrorMessages.customErrorMessage(hr); if (null != msg) { return(new ApplicationException($"DTS decoder failed: { msg }")); } ComLight.ErrorCodes.throwForHR(hr); return(null); }