When I updated my SharpDX.MediaFoundation reference, it started giving this error:
Error CS1503 Argument 2: cannot convert from 'System.IntPtr' to 'SharpDX.MediaFoundation.IByteStream'
using (var ma = new MediaAttributes())
{
// note this doesn't mean you *will* have a hardware transform. Intel Media SDK sometimes is not happy with configuration for HDCP issues.
ma.Set(SinkWriterAttributeKeys.ReadwriteEnableHardwareTransforms, Options.EnableHardwareTransforms ? 1 : 0);
ma.Set(SinkWriterAttributeKeys.D3DManager, _devManager.Value);
// by default, the sink writer's WriteSample method limits the data rate by blocking the calling thread.
// this prevents the application from delivering samples too quickly.
// to disable this behavior, set the attribute to 1
ma.Set(SinkWriterAttributeKeys.DisableThrottling, Options.DisableThrottling ? 1 : 0);
ma.Set(SinkWriterAttributeKeys.LowLatency, Options.LowLatency);
Trace("CreateSinkWriterFromURL path:" + RecordFilePath);
writer = MediaFactory.CreateSinkWriterFromURL(RecordFilePath, IntPtr.Zero, ma);
}
The error part of the code is on the line with the CreateSinkWriterFromURL method call, it seems IntPtr.Zero is causing the problem.
problem is solved. : Use null instead of IntPtr.Zero
The underlying Windows API function
MFCreateSinkWriterFromURLis written as the following:It's been quite difficult to find any documentation on the managed libraries for SharpDx (actually, it's here, but it's not pretty). The project is no longer maintained, but if the original writers of the managed code followed any kind of convention, they likely kept the order the same for these parameters when calling the external unmanaged code. Your error essentially is saying "you are passing me an
IntPtrwhen I expect anIByteStream."The only open source code I was able to find on GitHub was this SuperMFLib repository, which is a sort of "adapter/wrapper" as they call it for the SharpDx library. It contains this
CreateSinkWriterFromURLmethod you seem to be calling, however it's method signature only expects two parameters, not four (the file is however almost six years old). You said you recently updated your reference to the library, so I am guessing something changed between the version you were on to the version you upgraded to.