sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.7k stars 639 forks source link

SharpDX.MediaFoundation.Transform.GetInputAvailableType is missing return value #859

Open andrekoehler opened 7 years ago

andrekoehler commented 7 years ago

The methods commentary states "The method returns an SharpDX.Result" but the method actually returns void. Ideally, there would be a helper method like "TryGetOutputAvailableType" that is called "TryGetInputAvailableType"

xoofx commented 7 years ago

PR is welcome

hozuki commented 7 years ago

I tried to solve this. The problem is, I don't know why GetInputAvailableType never has a return value in wrapper code (Interfaces.cs, line 33542). I tried to copy the configuration of GetOutputAvailableType, but GetOutputAvailableType has a return value (type: HRESULT->ResultCode) and GetInputAvailableType still doesn't.

Then I read T4 templates and source code of the C# code generator. It turns out that using return attribute in XML mapping forces the generator to generate return __result__ statement.

So here's my current approach:

First in Mapping-core.xml, under the entry of GetOutputAvailableType, add an entry for GetInputAvailableType:

<map method="IMFTransform::GetInputAvailableType" visibility="internal" check ="false" return="true"/>

Notice the return attribute.

Then, in Transform.cs:

/// <summary>
/// Gets an available media type for an input stream on this Media Foundation transform (MFT).
/// </summary>
/// <param name="dwInputStreamID">Input stream identifier. To get the list of stream identifiers, call <strong><see cref="SharpDX.MediaFoundation.Transform.GetStreamIDs" /></strong>.</param>
/// <param name="dwTypeIndex">Index of the media type to retrieve. Media types are indexed from zero and returned in approximate order of preference.</param>
/// <param name="typeOut">Receives a pointer to the <strong><see cref="SharpDX.MediaFoundation.MediaType" /></strong> interface. The caller must release the interface.</param>
/// <returns><c>true</c> if A media type for an input stream is available, <c>false</c> otherwise</returns>
/// <msdn-id>ms704814</msdn-id> 
/// <unmanaged>HRESULT IMFTransform::GetInputAvailableType([In] unsigned int dwInputStreamID,[In] unsigned int dwTypeIndex,[Out] IMFMediaType** ppType)</unmanaged> 
/// <unmanaged-short>IMFTransform::GetInputAvailableType</unmanaged-short>  
public bool TryGetInputAvailableType(int dwInputStreamID, int dwTypeIndex, out MediaType typeOut)
{
    bool mediaTypeAvailable = true;
    var result = GetInputAvailableType(dwInputStreamID, dwTypeIndex, out typeOut);

    //An object ran out of media types
    if (result == ResultCode.NoMoreTypes)
    {
        mediaTypeAvailable = false;
    }
    else
    {
        result.CheckError();
    }

    return mediaTypeAvailable;
}

It is almost a copy-and-paste of TryGetOutputAvailableType.

Now it should work.

It is not an elegant solution, just a workaround. So I am posting it here, but I am not making it a PR before myself or other people find out the true cause. HTH.

Santoidyp0p commented 6 years ago

The same issue exists on MediaFoundation.MediaSession.SetTopology, it is Void but should return SharpDx.Result . i am unable to verify if the topology has been set properly by return result.