summaryrefslogtreecommitdiffstats
path: root/WhisperNet/Callbacks.cs
blob: db387187cf059ab85b9a06b7a6dabda85255f0bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Whisper.Internal;

namespace Whisper
{
	/// <summary>Implement this abstract class to receive callbacks from the native code</summary>
	public abstract class Callbacks
	{
		/// <summary>The callback is called before every encoder run.</summary>
		/// <remarks>If it returns false, the processing is aborted.</remarks>
		protected virtual bool onEncoderBegin( Context sender ) { return true; }

		/// <summary>This callback is called on each new segment</summary>
		protected virtual void onNewSegment( Context sender, int countNew ) { }

		const int S_OK = 0;
		const int S_FALSE = 1;
		internal int encoderBegin( Context sender )
		{
			try
			{
				return onEncoderBegin( sender ) ? S_OK : S_FALSE;
			}
			catch( Exception ex )
			{
				NativeLogger.captureException( ex );
				return ex.HResult;
			}
		}

		internal int newSegment( Context sender, int countNew )
		{
			try
			{
				onNewSegment( sender, countNew );
				return S_OK;
			}
			catch( Exception ex )
			{
				NativeLogger.captureException( ex );
				return ex.HResult;
			}
		}
	}
}