0

我正在使用 WPF 中的增强型视频渲染器,在创建 IEVRPresenterRegisterCallback 的实例时,有时会收到令人讨厌的 D3DERR_DRIVERINVALIDCALL 错误。

使用 MVVM 设计,当我切换视图时……一个视图中专门有这个演示者……并且在视图之间切换时运行大约 80% 的时间。当一个视图关闭时,一切都被释放了……所以回到同一个视图将重新创建对象。

问题是有时它确实有效......我已经确定了原因,但无法找到解决方案。

        int hr;
        object comObject;
        Exception exception = null;

        // A COM object we query form our native library.
        IClassFactory factory = null;

        // Create our 'helper' class.
        var evrPresenter = new EVRPresenter();

        // Call the DLL export to create the class factory.
        if (ProcessBits == 64)
        {
            hr = DllGetClassObject64(EVR_PRESENTER_CLSID, IUNKNOWN_GUID, out comObject);
        }
        else
        {
            exception = new Exception(string.Format("{0} bit processes are unsupported", ProcessBits));
            goto bottom;
        }

        // Check if our call to our DLL failed.
        if (hr != 0 || comObject == null)
        {
            exception = new COMException("Could not create a new class factory.", hr);
            goto bottom;
        }

        // Cast the COM object that was returned to a COM interface type.
        factory = comObject as IClassFactory;

        if (factory == null)
        {
            exception = new Exception("Could not QueryInterface for the IClassFactory interface.");
            goto bottom;
        }

        // Get the GUID of the IMFVideoPresenter.
        Guid guidVideoPresenter = typeof(IMFVideoPresenter).GUID;

        // Creates a new instance of the IMFVideoPresenter.
        hr = factory.CreateInstance(null, ref guidVideoPresenter, out comObject);

        // QueryInterface for the IMFVideoPresenter.
        var presenter = comObject as IMFVideoPresenter;

        // QueryInterface for our callback registration interface.
        var registerCb = comObject as IEVRPresenterRegisterCallback;

        if (registerCb == null)
        {
            exception = new Exception("Could not QueryInterface for IEVRPresenterRegisterCallback.");
            goto bottom;
        }

        // Register the callback to the 'helper' class.
        registerCb.RegisterCallback(evrPresenter);

        // Populate the IMFVideoPresenter.
        evrPresenter.VideoPresenter = presenter;

    bottom:
        if (factory != null)
        {
            Marshal.FinalReleaseComObject(factory);
        }

        if (exception != null)
        {
            throw exception;
        }

        return evrPresenter;

当 facotry.CreateInstance(null, ref guidVideoPresenter, out comObject) 运行时...... comObject 大多数时候返回 IEVRPresenterRegisterCallback,但其他时候,它会吐出 null 并且 HRESULT 是 D3DERR_DRIVERINVALIDCALL ,这恰好是一个非常模糊的错误代码。

发生这种情况时,我的应用程序最终会捕获异常并继续运行而不显示任何视频。

有没有人在这种类型的设计中看到过类似的东西?

干杯。

4

0 回答 0