/// <summary> /// Retrieves the length of a string value associated with a key. /// </summary> public int GetStringLength(Guid key) { int result; MediaFoundationException.Try(GetStringLength(key, out result), c, "GetStringLength"); return(result); }
/// <summary> /// Retrieves a GUID value associated with a key. /// </summary> public Guid GetGuid(Guid key) { Guid result; MediaFoundationException.Try(GetGuid(key, out result), c, "GetGuid"); return(result); }
/// <summary> /// Retrieves a double value associated with a key. /// </summary> public double GetDouble(Guid key) { double result; MediaFoundationException.Try(GetDouble(key, out result), c, "GetDouble"); return(result); }
/// <summary> /// Retrieves a UINT64 value associated with a key. /// </summary> public long GetUINT64(Guid key) { long result; MediaFoundationException.Try(GetUINT64(key, out result), c, "GetUINT64"); return(result); }
/// <summary> /// Retrieves the length of a byte array associated with a key. /// </summary> public int GetBlobSize(Guid key) { int result; MediaFoundationException.Try(GetBlobSize(key, out result), c, "GetBlobSize"); return(result); }
/// <summary> /// Currently no flags are defined. Instead, metadata for samples is defined using /// attributes. To get attibutes from a sample, use the IMFAttributes interface, which /// IMFSample inherits. /// </summary> public MFSampleFlags GetSampleFlags() { MFSampleFlags flags; MediaFoundationException.Try(GetSampleFlagsNative(out flags), c, "GetSampleFlags"); return(flags); }
/// <summary> /// Retrieves the data type of the value associated with a key. /// </summary> /// <returns>HRESULT</returns> public MFAttributeType GetItemType(Guid key) { MFAttributeType type; MediaFoundationException.Try(GetItemType(key, out type), c, "GetItemType"); return(type); }
public int GetTotalLength() { int res; MediaFoundationException.Try(GetTotalLengthNative(out res), c, "GetTotalLength"); return(res); }
/// <summary> /// Retrieves a UINT32 value associated with a key. /// </summary> public int GetUINT32(Guid key) { int result; MediaFoundationException.Try(GetUINT32(key, out result), c, "GetUINT32"); return(result); }
public MFMediaBuffer GetBufferByIndex(int index) { MFMediaBuffer buffer; MediaFoundationException.Try(GetBufferByIndexNative(index, out buffer), c, "GetBufferByIndex"); return(buffer); }
public MFMediaBuffer ConvertToContinousBuffer() { MFMediaBuffer buffer; MediaFoundationException.Try(ConvertToContinousBufferNative(out buffer), c, "ConvertToContinousBuffer"); return(buffer); }
public int GetBufferCount() { int res; MediaFoundationException.Try(GetBufferCountNative(out res), c, "GetBufferCount"); return(res); }
public long GetSampleDuration() { long res; MediaFoundationException.Try(GetSampleDurationNative(out res), c, "GetSampleDuration"); return(res); }
/// <summary> /// Retrieves an attribute at the specified index. /// </summary> public unsafe PropertyVariant GetItemByIndex(int index, out Guid key) { PropertyVariant value = default(PropertyVariant); MediaFoundationException.Try(GetItemByIndexNative(index, out key, new IntPtr(&value)), c, "GetItemByIndex"); return(value); }
/// <summary> /// Retrieves the presentation time of the sample. /// </summary> /// <returns>Presentation time, in 100-nanosecond units.</returns> public long GetSampleTime() { long res; MediaFoundationException.Try(GetSampleTimeNative(out res), c, "GetSampleTime"); return(res); }
/// <summary> /// Enumerates Mediafoundation-Transforms that match the specified search criteria. /// </summary> /// <param name="category">A <see cref="Guid" /> that specifies the category of MFTs to enumerate. /// For a list of MFT categories, see <see cref="MFTCategories" />.</param> /// <param name="flags">The bitwise OR of zero or more flags from the <see cref="MFTEnumFlags" /> enumeration.</param> /// <param name="inputType">Specifies an input media type to match. This parameter can be <c>null</c>. If <c>null</c>, all input types are matched.</param> /// <param name="outputType">Specifies an output media type to match. This parameter can be <c>null</c>. If <c>null</c>, all output types are matched.</param> /// <returns> A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the MFTs.</returns> public static IEnumerable <MFActivate> EnumerateTransformsEx(Guid category, MFTEnumFlags flags, MFTRegisterTypeInfo inputType = null, MFTRegisterTypeInfo outputType = null) { if (!(Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1)) { throw new PlatformNotSupportedException("The EnumerateTransformsEx method requires Windows 7/Windows Server 2008 R2 or above."); } IntPtr ptr; int count; int res = NativeMethods.MFTEnumEx(category, flags, inputType, outputType, out ptr, out count); try { MediaFoundationException.Try(res, "Interops", "MFTEnumEx"); for (int i = 0; i < count; i++) { var ptr0 = ptr; var ptr1 = Marshal.ReadIntPtr(new IntPtr(ptr0.ToInt64() + i * Marshal.SizeOf(ptr0))); yield return(new MFActivate(ptr1)); } } finally { Marshal.FreeCoTaskMem(ptr); } }
/// <summary> /// Reads data from the stream. /// </summary> /// <param name="buffer">The buffer that receives the data.</param> /// <param name="count">The number of bytes to read.</param> /// <returns>HRESULT</returns> /// <exception cref="ArgumentNullException">buffer is null.</exception> /// <exception cref="ArgumentOutOfRangeException">count is bigger than the length of the buffer.</exception> public unsafe int Read(byte[] buffer, int count) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (count > buffer.Length) { throw new ArgumentOutOfRangeException("count"); } if (count == 0) { return(0); } int read; fixed(void *pBuffer = &buffer[0]) { int result = ReadNative((IntPtr)pBuffer, count, out read); MediaFoundationException.Try(result, InterfaceName, "Read"); } return(read); }
public IntPtr Lock(out int maxLength, out int currentLength) { IntPtr p = IntPtr.Zero; MediaFoundationException.Try(LockNative(out p, out maxLength, out currentLength), c, "Lock"); return(p); }
/// <summary> /// Writes data to the stream. /// </summary> /// <param name="buffer">Buffer that contains the data to write.</param> /// <param name="count">The number of bytes to write.</param> /// <returns>The number of bytes that were written.</returns> /// <exception cref="ArgumentNullException">buffer is null.</exception> /// <exception cref="ArgumentOutOfRangeException">count is bigger than the length of the buffer.</exception> public unsafe int Write(byte[] buffer, int count) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (count > buffer.Length) { throw new ArgumentOutOfRangeException("count"); } if (count == 0) { return(0); } int written; fixed(void *p = &buffer[0]) { int result = WriteNative((IntPtr)p, count, out written); MediaFoundationException.Try(result, InterfaceName, "Write"); } return(written); }
/// <summary> /// Retrieves the number of attributes that are set on this object. /// </summary> public int GetCount() { int count; MediaFoundationException.Try(GetCountNative(out count), c, "GetCount"); return(count); }
public static void Shutdown() { if (_isstarted) { MediaFoundationException.Try(NativeMethods.MFShutdown(), "Interops", "MFShutdown"); _isstarted = false; } }
public static void Startup() { if (!_isstarted) { MediaFoundationException.Try(NativeMethods.MFStartup(NativeMethods.MF_VERSION, 0), "Interops", "MFStartup"); _isstarted = true; } }
public static IntPtr CreateSourceReaderFromUrlNative(string url) { IntPtr ptr = IntPtr.Zero; int result = NativeMethods.MFCreateSourceReaderFromURL(url, IntPtr.Zero, out ptr); MediaFoundationException.Try(result, "Interops", "MFCreateSourceReaderFromURL"); return(ptr); }
/// <summary> /// Moves the current position in the stream by a specified offset. /// </summary> /// <param name="seekOrigin">Specifies the origin of the seek as a member of the <see cref="MFByteStreamSeekOrigin"/> enumeration. The offset is calculated relative to this position.</param> /// <param name="seekOffset">Specifies the new position, as a byte offset from the seek origin.</param> /// <param name="cancelPendingIO">Specifies whether all pending I/O requests are canceled after the seek request completes successfully.</param> /// <returns>The new position after the seek.</returns> public long Seek(MFByteStreamSeekOrigin seekOrigin, long seekOffset, bool cancelPendingIO) { long v; MediaFoundationException.Try(SeekNative(seekOrigin, seekOffset, cancelPendingIO, out v), InterfaceName, "Seek"); return(v); }
public static MFSourceReader CreateSourceReaderFromUrl(string url) { IntPtr ptr = IntPtr.Zero; int result = MFInterops.MFCreateSourceReaderFromURL(url, IntPtr.Zero, out ptr); MediaFoundationException.Try(result, "Interops", "MFCreateSourceReaderFromURL"); return(new MFSourceReader(ptr)); }
public static MFSinkWriter CreateSinkWriterFromMFByteStream(IMFByteStream byteStream, IMFAttributes attributes) { IntPtr p; int result = MFInterops.ExternMFCreateSinkWriterFromURL(null, byteStream, attributes, out p); MediaFoundationException.Try(result, "Interops", "MFCreateSinkWriterFromURL"); return(new MFSinkWriter(p)); }
/// <summary> /// Gets statistics about the performance of the sink writer. /// </summary> /// <param name="streamIndex">The zero-based index of a stream to query, or <see cref="MF_SINK_WRITER_ALL_STREAMS"/> to query the media sink itself.</param> /// <returns>Statistics about the performance of the sink writer.</returns> public MFSinkWriterStatistics GetStatistics(int streamIndex) { MFSinkWriterStatistics s; s.Cb = Marshal.SizeOf(typeof(MFSinkWriterStatistics)); MediaFoundationException.Try(GetStatisticsNative(streamIndex, out s), InterfaceName, "GetStatistics"); return(s); }
public static MFMediaType MediaTypeFromWaveFormat(WaveFormat waveFormat) { var mediaType = MFMediaType.CreateEmpty(); int result = NativeMethods.MFInitMediaTypeFromWaveFormatEx(mediaType.BasePtr, waveFormat, Marshal.SizeOf(waveFormat)); MediaFoundationException.Try(result, "Interops", "MFInitMediaTypeFromWaveFormatEx"); return(mediaType); }
public static IntPtr CreateSinkWriterFromMFByteStreamNative(MFByteStream byteStream, MFAttributes attributes) { IntPtr p; int result = NativeMethods.ExternMFCreateSinkWriterFromURL(null, byteStream.BasePtr, attributes.BasePtr, out p); MediaFoundationException.Try(result, "Interops", "MFCreateSinkWriterFromURL"); return(p); }
public unsafe MFAttributes(int initialSize) { IntPtr zero = IntPtr.Zero; int result = MFCreateAttributes_(new IntPtr((void *)(&zero)), initialSize); MediaFoundationException.Try(result, "interop", "MFCreateAttributes"); _basePtr = zero.ToPointer(); }