/// <summary> /// Compares the attributes on this object with the attributes on another object. /// </summary> /// <returns>HRESULT</returns> public unsafe int Compare(MFAttributes theirs, MFAttributeMatchType matchType, out NativeBool result) { fixed(NativeBool *pr = &result) { return(InteropCalls.CalliMethodPtr(_basePtr, (void *)((theirs == null) ? IntPtr.Zero : theirs.BasePtr), matchType, pr, ((void **)(*(void **)_basePtr))[6])); } }
/// <summary> /// Sets and initializes the targetstream for the encoding process. /// </summary> /// <param name="stream">Stream which should be used as the targetstream.</param> /// <param name="inputMediaType">Mediatype of the raw input data to encode.</param> /// <param name="targetMediaType">Mediatype of the encoded data.</param> /// <param name="containerType">Container type which should be used.</param> protected void SetTargetStream(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType) { MFAttributes attributes = null; try { _targetBaseStream = new ComStream(stream); _targetStream = MediaFoundationCore.IStreamToByteStream(_targetBaseStream); attributes = new MFAttributes(2); attributes.SetUINT32(MediaFoundationAttributes.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1); attributes.SetGuid(MediaFoundationAttributes.MF_TRANSCODE_CONTAINERTYPE, containerType); _sinkWriter = new MFSinkWriter(_targetStream, attributes); _streamIndex = _sinkWriter.AddStream(targetMediaType); _sinkWriter.SetInputMediaType(_streamIndex, inputMediaType, null); _targetMediaType = targetMediaType; _sourceBytesPerSecond = inputMediaType.AverageBytesPerSecond; //initialize the sinkwriter _sinkWriter.BeginWriting(); } catch (Exception) { if (_sinkWriter != null) { _sinkWriter.Dispose(); _sinkWriter = null; } if (_targetStream != null) { _targetStream.Dispose(); _targetStream = null; } throw; } finally { if (attributes != null) { attributes.Dispose(); } } }
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); }
/// <summary> /// Sets the input format for a stream on the sink writer. /// </summary> /// <param name="streamIndex">The zero-based index of the stream. The index is returned by the <see cref="AddStream"/> method.</param> /// <param name="inputMediaType">The input media type that specifies the input format.</param> /// <param name="encodingParameters">An attribute store. Use the attribute store to configure the encoder. This parameter can be NULL.</param> public void SetInputMediaType(int streamIndex, MFMediaType inputMediaType, MFAttributes encodingParameters) { MediaFoundationException.Try(SetInputMediaTypeNative(streamIndex, inputMediaType, encodingParameters), InterfaceName, "SetInputMediaType"); }
/// <summary> /// Sets the input format for a stream on the sink writer. /// <seealso cref="SetInputMediaType"/> /// </summary> /// <param name="streamIndex">The zero-based index of the stream. The index is returned by the <see cref="AddStream"/> method.</param> /// <param name="inputMediaType">The input media type that specifies the input format.</param> /// <param name="encodingParameters">An attribute store. Use the attribute store to configure the encoder. This parameter can be NULL.</param> /// <returns>HRESULT</returns> public unsafe int SetInputMediaTypeNative(int streamIndex, MFMediaType inputMediaType, MFAttributes encodingParameters) { void *imt = (void *)(inputMediaType == null ? IntPtr.Zero : inputMediaType.BasePtr); void *ep = (void *)(encodingParameters == null ? IntPtr.Zero : encodingParameters.BasePtr); return(InteropCalls.CalliMethodPtr(UnsafeBasePtr, streamIndex, imt, ep, ((void **)(*(void **)UnsafeBasePtr))[4])); }
/// <summary> /// Initializes a new instance of the <see cref="MFSinkWriter"/> class with a underlying <paramref name="byteStream"/>. /// </summary> /// <param name="byteStream">The underlying <see cref="MFByteStream"/> to use.</param> /// <param name="attributes">Attributes to configure the <see cref="MFSinkWriter"/>. For more information, see <see href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd389284(v=vs.85).aspx"/>. Use null/nothing as the default value.</param> public MFSinkWriter(MFByteStream byteStream, MFAttributes attributes = null) : this(MediaFoundationCore.CreateSinkWriterFromMFByteStreamNative(byteStream, attributes)) { }
/// <summary> /// Copies all of the attributes from this object into another attribute store. /// </summary> /// <returns>HRESULT</returns> public unsafe int CopyAllItems(MFAttributes destination) { return(InteropCalls.CalliMethodPtr(_basePtr, (void *)((destination == null) ? IntPtr.Zero : destination.BasePtr), ((void **)(*(void **)_basePtr))[32])); }