// Copyright (c) 2010-2011 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using System.Runtime.InteropServices; namespace SharpDX.MediaFoundation { /// /// Delegate MediaEngineNotifyDelegate {CC2D43FA-BBC4-448A-9D0B-7B57ADF2655C} /// /// The media event. /// The param1. /// The param2. public delegate void MediaEngineNotifyDelegate(MediaEngineEvent mediaEvent, long param1, int param2); public partial class MediaEngine { private MediaEngineNotifyImpl mediaEngineNotifyImpl; /// /// Initializes an instance of the class. /// /// /// /// /// /// hh447921 /// HRESULT IMFMediaEngineClassFactory::CreateInstance([In] MF_MEDIA_ENGINE_CREATEFLAGS dwFlags,[In] IMFAttributes* pAttr,[Out, Fast] IMFMediaEngine** ppPlayer) /// IMFMediaEngineClassFactory::CreateInstance 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; } } /// /// Media engine playback event. /// public event MediaEngineNotifyDelegate PlaybackEvent; /// ///

[This documentation is preliminary and is subject to change.]

Applies to: desktop apps | Metro style apps

Queries the Media Engine to find out whether a new video frame is ready.

///
///

If a new frame is ready, receives the presentation time of the frame.

/// true if new video frame is ready for display. /// ///

In frame-server mode, the application should call this method whenever a vertical blank occurs in the display device. If the method returns , call to blit the frame to the render target. If the method returns S_FALSE, wait for the next vertical blank and call the method again.

Do not call this method in rendering mode or audio-only mode.

///
/// hh448006 /// HRESULT IMFMediaEngine::OnVideoStreamTick([Out] longlong* pPts) /// IMFMediaEngine::OnVideoStreamTick public bool OnVideoStreamTick(out long ptsRef) { return OnVideoStreamTick_(out ptsRef).Success; } protected override unsafe void Dispose(bool disposing) { if (disposing) { if (mediaEngineNotifyImpl != null) { mediaEngineNotifyImpl.Dispose(); mediaEngineNotifyImpl = null; } } base.Dispose(disposing); } private void OnPlaybackEvent(MediaEngineEvent mediaevent, long param1, int param2) { MediaEngineNotifyDelegate handler = PlaybackEvent; if (handler != null) handler(mediaevent, param1, param2); } private class MediaEngineNotifyImpl : CallbackBase, MediaEngineNotify { private readonly MediaEngine MediaEngine; public MediaEngineNotifyImpl(MediaEngine mediaEngine) { MediaEngine = mediaEngine; } public void OnPlaybackEvent(MediaEngineEvent mediaEngineEvent, long param1, int param2) { MediaEngine.OnPlaybackEvent(mediaEngineEvent, param1, param2); } } /// ///

[This documentation is preliminary and is subject to change.]

Applies to: desktop apps | Metro style apps

Sets the URL of a media resource.

///
///

The URL of the media resource.

///

If this method succeeds, it returns . Otherwise, it returns an error code.

/// ///

This method corresponds to setting the src attribute of the HTMLMediaElement interface in HTML5.

The URL specified by this method takes precedence over media resources specified in the method. To load the URL, call .

This method asynchronously loads the URL. When the operation starts, the Media Engine sends an event. If no errors occur during the Load operation, several other events are generated, including the following.

If the Media Engine is unable to load the URL, the Media Engine sends an event.

For more information about event handling in the Media Engine, see .

///
/// /// hh448017 /// HRESULT IMFMediaEngine::SetSource([In] wchar_t* pUrl) /// IMFMediaEngine::SetSource public string Source { set { SetSource(Utilities.StringToCoTaskMemUni(value)); } } } }