public IMFMediaEngine CreateInstance(
        MediaEngineCreateFlags createFlags         = MediaEngineCreateFlags.None,
        IMFAttributes?attributes                   = default,
        MediaEngineNotifyDelegate?playbackCallback = default)
    {
        attributes ??= MFCreateAttributes(1);

        MediaEngineNotifyImpl mediaEngineNotifyImpl = new();

        try
        {
            attributes.Set(MediaEngineAttributeKeys.Callback, mediaEngineNotifyImpl);
            CreateInstance(createFlags, attributes, out IMFMediaEngine engine).CheckError();

            mediaEngineNotifyImpl.MediaEngine = engine;
            engine.mediaEngineNotifyImpl      = mediaEngineNotifyImpl;
            if (playbackCallback != null)
            {
                engine.PlaybackEvent += playbackCallback;
            }

            return(engine);
        }
        catch
        {
            mediaEngineNotifyImpl.Dispose();
            throw;
        }
    }
Exemple #2
0
        /// <summary>
        /// Initializes an instance of the <see cref="MediaEngine"/> class.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="attributes"></param>
        /// <param name="createFlags"> </param>
        public MediaEngine(MediaEngineClassFactory factory, MediaEngineAttributes attributes = null, MediaEngineCreateFlags createFlags = MediaEngineCreateFlags.None, MediaEngineNotifyDelegate playbackCallback = null)
        {
            // Create engine attributes if null
            attributes = attributes ?? new MediaEngineAttributes();

            PlaybackEvent = playbackCallback;

            // Setup by default the MediaEngine notify as it is mandatory
            mediaEngineNotifyImpl = new MediaEngineNotifyImpl(this);
            try
            {
                attributes.Set(MediaEngineAttributeKeys.Callback, new ComObject(MediaEngineNotifyShadow.ToIntPtr(mediaEngineNotifyImpl)));
                factory.CreateInstance(createFlags, attributes, this);
            } catch
            {
                mediaEngineNotifyImpl.Dispose();
                mediaEngineNotifyImpl = null;
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes an instance of the <see cref="MediaEngine"/> class.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="attributes"></param>
        /// <param name="createFlags"> </param>
        /// <param name="playbackCallback"></param>
        /// <msdn-id>hh447921</msdn-id>
        /// <unmanaged>HRESULT IMFMediaEngineClassFactory::CreateInstance([In] MF_MEDIA_ENGINE_CREATEFLAGS dwFlags,[In] IMFAttributes* pAttr,[Out, Fast] IMFMediaEngine** ppPlayer)</unmanaged>
        /// <unmanaged-short>IMFMediaEngineClassFactory::CreateInstance</unmanaged-short>
        public MediaEngine(MediaEngineClassFactory factory, MediaEngineAttributes attributes = null, MediaEngineCreateFlags createFlags = MediaEngineCreateFlags.None, MediaEngineNotifyDelegate playbackCallback = null)
        {
            // Create engine attributes if null
            attributes = attributes ?? new MediaEngineAttributes();

            if (playbackCallback != null)
            {
                PlaybackEvent += playbackCallback;
            }

            // Setup by default the MediaEngine notify as it is mandatory
            mediaEngineNotifyImpl = new MediaEngineNotifyImpl(this);
            try
            {
                attributes.Set(MediaEngineAttributeKeys.Callback, new ComObject(MediaEngineNotifyShadow.ToIntPtr(mediaEngineNotifyImpl)));
                factory.CreateInstance(createFlags, attributes, this);
            } catch
            {
                mediaEngineNotifyImpl.Dispose();
                mediaEngineNotifyImpl = null;
                throw;
            }
        }