-
Notifications
You must be signed in to change notification settings - Fork 281
Expand file tree
/
Copy pathICoreInterop.cs
More file actions
72 lines (59 loc) · 2.52 KB
/
ICoreInterop.cs
File metadata and controls
72 lines (59 loc) · 2.52 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.AI.Foundry.Local.Detail;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
internal interface ICoreInterop
{
internal record Response
{
internal string? Data;
internal string? Error;
}
public delegate void CallbackFn(string callbackData);
[StructLayout(LayoutKind.Sequential)]
protected unsafe struct RequestBuffer
{
public nint Command;
public int CommandLength;
public nint Data;
public int DataLength;
}
[StructLayout(LayoutKind.Sequential)]
protected unsafe struct ResponseBuffer
{
public nint Data;
public int DataLength;
public nint Error;
public int ErrorLength;
}
// native callback function signature
// Return: 0 = continue, 1 = cancel
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
protected unsafe delegate int NativeCallbackFn(nint data, int length, nint userData);
Response ExecuteCommand(string commandName, CoreInteropRequest? commandInput = null);
Response ExecuteCommandWithCallback(string commandName, CoreInteropRequest? commandInput, CallbackFn callback);
Task<Response> ExecuteCommandAsync(string commandName, CoreInteropRequest? commandInput = null,
CancellationToken? ct = null);
Task<Response> ExecuteCommandWithCallbackAsync(string commandName, CoreInteropRequest? commandInput,
CallbackFn callback,
CancellationToken? ct = null);
// --- Audio streaming session support ---
[StructLayout(LayoutKind.Sequential)]
protected unsafe struct StreamingRequestBuffer
{
public nint Command;
public int CommandLength;
public nint Data; // JSON params
public int DataLength;
public nint BinaryData; // raw PCM audio bytes
public int BinaryDataLength;
}
Response StartAudioStream(CoreInteropRequest request);
Response PushAudioData(CoreInteropRequest request, ReadOnlyMemory<byte> audioData);
Response StopAudioStream(CoreInteropRequest request);
}