smourier / DirectN

Direct interop Code for .NET Framework, .NET Core and .NET 5+ : DXGI, WIC, DirectX 9 to 12, Direct2D, Direct Write, Direct Composition, Media Foundation, WASAPI, CodecAPI, GDI, Spatial Audio, DVD, Windows Media Player, UWP DXInterop, WinUI3, etc.
MIT License
315 stars 28 forks source link

Some Media Foundation helper functions are not mapped #42

Closed EzeKees closed 1 year ago

EzeKees commented 1 year ago

Hello. First, thanks again for this great library, I am using it extensively in my project. Something I noticed or didn't find is that some media foundation helper functions were not mapped, for example:

MFGetAttributeSize
MFSetAttributeSize

This is so? In case they are not, is there any interest in mapping them? Thank you

smourier commented 1 year ago

Hi,

These are not DLL exports but C inline utility/wrapper functions, actually defined as this in mfapi.h:

inline
HRESULT
MFGetAttributeSize(
    IMFAttributes*  pAttributes,
    REFGUID         guidKey,
    _Out_ UINT32*   punWidth,
    _Out_ UINT32*   punHeight
    )
{
    return MFGetAttribute2UINT32asUINT64(pAttributes, guidKey, punWidth, punHeight);
}

inline
HRESULT
MFGetAttribute2UINT32asUINT64(
    IMFAttributes*  pAttributes,
    REFGUID         guidKey,
    _Out_ UINT32*   punHigh32,
    _Out_ UINT32*   punLow32
    )
{
    UINT64 unPacked;
    HRESULT hr = S_OK;

    hr = pAttributes->GetUINT64(guidKey, &unPacked);
    if (FAILED(hr)) {
        return hr;
    }
    Unpack2UINT32AsUINT64(unPacked, punHigh32, punLow32);

    return hr;
}

inline
void
Unpack2UINT32AsUINT64(UINT64 unPacked, _Out_ UINT32* punHigh, _Out_ UINT32* punLow)
{
    *punHigh = HI32(unPacked);
    *punLow = LO32(unPacked);
}

So they cannot be used from C# at all. However, with the extensions functions, you can easily do the same, for example:

IComObject<IMFAttributes> atts = get from somewhere...

var MF_MT_FRAME_SIZE = new Guid("1652c33d-d6b2-4012-b834-72030849a37d"); // https://www.magnumdb.com/search?q=MF_MT_FRAME_SIZE

var size = atts.GetUInt64(MF_MT_FRAME_SIZE);
var width = (uint)(size >> 32);
var height = (uint)(size & 0xFFFFFFFF);
EzeKees commented 1 year ago

I'll write the functions manually then. Thank you so much!!