using Whisper.Internal;
namespace Whisper
{
/// Implement this abstract class to provide callbacks for audio capture method
public abstract class CaptureCallbacks
{
/// Override this method to support cancellation
protected virtual bool shouldCancel( Context sender ) { return false; }
/// Override this method to get notified about status changes
protected virtual void captureStatusChanged( Context sender, eCaptureStatus status ) { }
internal pfnShouldCancel cancel( Context sender )
{
const int S_OK = 0;
const int S_FALSE = 1;
return delegate ( IntPtr pv )
{
try
{
return shouldCancel( sender ) ? S_FALSE : S_OK;
}
catch( Exception ex )
{
NativeLogger.captureException( ex );
return ex.HResult;
}
};
}
internal pfnCaptureStatus status( Context sender )
{
return delegate ( IntPtr pv, eCaptureStatus status )
{
try
{
captureStatusChanged( sender, status );
return 0;
}
catch( Exception ex )
{
NativeLogger.captureException( ex );
return ex.HResult;
}
};
}
}
}