private void CreateReaderAndWriter() { object sourceReaderObject = null; object sinkWriterObject = null; IMFAttributes attributes = null; // Create the class factory IMFReadWriteClassFactory factory = (IMFReadWriteClassFactory)(new MFReadWriteClassFactory()); // Create the attributes MFHelper.MFCreateAttributes(out attributes, 1); attributes.SetUINT32(new Guid(Consts.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS), 1); // Use the factory to create the Source Reader factory.CreateInstanceFromURL(new Guid(CLSID.MFSourceReader), this.sourceFilename, attributes, new Guid(IID.IMFSourceReader), out sourceReaderObject); this.sourceReader = (IMFSourceReader)sourceReaderObject; // Use the factory to create the Sink Writer factory.CreateInstanceFromURL(new Guid(CLSID.MFSinkWriter), this.targetFilename, attributes, new Guid(IID.IMFSinkWriter), out sinkWriterObject); this.sinkWriter = (IMFSinkWriter)sinkWriterObject; }
/// <summary> /// Creates an instance of the source reader given a URL. /// </summary> /// <param name="factory">A valid IMFReadWriteClassFactory instance.</param> /// <param name="url">A string that specifies the input file for the source reader.</param> /// <param name="attributes">A instance to the IMFAttributes interface. You can use this parameter to configure the source reader.</param></param> /// <param name="sourceReader">Receives the source reader</param> /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns> public static HResult CreateInstanceFromURL(this IMFReadWriteClassFactory factory, string url, IMFAttributes attributes, out IMFSourceReader sourceReader) { if (factory == null) { throw new ArgumentNullException("factory"); } object tmp; HResult hr = factory.CreateInstanceFromURL(CLSID.CLSID_MFSourceReader, url, attributes, typeof(IMFSourceReader).GUID, out tmp); sourceReader = hr.Succeeded() ? tmp as IMFSourceReader : null; return(hr); }