#if DESKTOP_APP
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SharpDX.MediaFoundation
{
public delegate void CaptureEngineOnEventDelegate(MediaEvent mediaEvent);
public partial class CaptureEngine
{
private CaptureEngineOnEventImpl captureEngineOnEventImpl;
///
/// Creates an instance of the capture engine.
///
///
The CLSID of the object to create. Currently, this parameter must equal .
/// The IID of the requested interface. The capture engine supports the interface.
/// Receives a reference to the requested interface. The caller must release the interface.
/// If this method succeeds, it returns . Otherwise, it returns an error code.
///
/// Before calling this method, call the function.
///
///
/// hh447848
/// HRESULT IMFCaptureEngineClassFactory::CreateInstance([In] const GUID& clsid,[In] const GUID& riid,[Out] void** ppvObject)
/// IMFCaptureEngineClassFactory::CreateInstance
public CaptureEngine(CaptureEngineClassFactory factory)
{
IntPtr native;
factory.CreateInstance(ClsidMFCaptureEngine, Utilities.GetGuidFromType(typeof(CaptureEngine)), out native);
NativePointer = native;
captureEngineOnEventImpl = new CaptureEngineOnEventImpl(this);
}
///
/// Initializes the capture engine.
///
/// A reference to the interface. The caller must implement this interface. The capture engine uses this interface to send asynchronous events to the caller.
/// A reference to the interface. This parameter can be null.
You can use this parameter to configure the capture engine. Call to create an attribute store, and then set any of the following attributes.
/// An reference that specifies an audio-capture device. This parameter can be null.
If you set the attribute to TRUE in pAttributes, the capture engine does not use an audio device, and the pAudioSource parameter is ignored.
Otherwise, if pAudioSource is null, the capture engine selects the microphone that is built into the video camera specified by pVideoSource. If the video camera does not have a microphone, the capture engine enumerates the audio-capture devices on the system and selects the first one.
To override the default audio device, set pAudioSource to an or reference for the device. For more information, see Audio/Video Capture in Media Foundation.
/// An reference that specifies a video-capture device. This parameter can be null.
If you set the attribute to TRUE in pAttributes, the capture engine does not use a video device, and the pVideoSource parameter is ignored.
Otherwise, if pVideoSource is null, the capture engine enumerates the video-capture devices on the system and selects the first one.
To override the default video device, set pVideoSource to an or reference for the device. For more information, see Enumerating Video Capture Devices.
/// This method can return one of these values.
| Return code | Description |
| Success. |
| The Initialize method was already called. |
| No capture devices are available. |
///
/// You must call this method once before using the capture engine. Calling the method a second time returns .
This method is asynchronous. If the method returns a success code, the caller will receive an MF_CAPTURE_ENGINE_INITIALIZED event through the method. The operation can fail asynchronously after the method succeeds. If so, the error code is conveyed through the OnEvent method.
///
///
/// hh447855
/// HRESULT IMFCaptureEngine::Initialize([In] IMFCaptureEngineOnEventCallback* pEventCallback,[In, Optional] IMFAttributes* pAttributes,[In, Optional] IUnknown* pAudioSource,[In, Optional] IUnknown* pVideoSource)
/// IMFCaptureEngine::Initialize
public void Initialize(MediaAttributes attributesRef, ComObject audioSourceRef, ComObject videoSourceRef)
{
Initialize(captureEngineOnEventImpl, attributesRef, audioSourceRef, videoSourceRef);
}
public event CaptureEngineOnEventDelegate CaptureEngineEvent;
private void OnEvent(MediaEvent mediaEvent)
{
CaptureEngineEvent?.Invoke(mediaEvent);
}
private class CaptureEngineOnEventImpl : CallbackBase, CaptureEngineOnEventCallback
{
private CaptureEngine captureEngine;
public CaptureEngineOnEventImpl(CaptureEngine captureEngine)
{
this.captureEngine = captureEngine;
}
public void OnEvent(MediaEvent mediaEvent)
{
captureEngine.OnEvent(mediaEvent);
}
}
}
}
#endif