You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

517 lines
22 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Service.Sound.SoundClient;
public class NAudioClientDll
{
/**************************************常量定义**************************************/
/*返回值定义*/
public const int RET_SUCCESS = 0;
public const int RET_INIT_CLIENT_FAIL = 1; //初始化客户端失败
public const int RET_OPEN_AUDIOFILE_FAIL = 2; //打开音频文件失败
public const int RET_INIT_PAGING_FAIL = 3; //初始化寻呼失败
public const int RET_START_RECORD_FAIL = 4; //启动录音失败
public const int RET_RESPONSE_TIMEOUT = 5; //响应超时
public const int RET_LOCAL_IS_CALLING = 6; //正在进行本地对讲
public const int RET_DEV_EXIST_IN_CALLINST = 7; //对讲实例中已存在该设备
public const int RET_BOTH_DEV_IS_LOCALIP = 8; //对讲实例中双方都是本地IP
public const int RET_CALLINST_NOT_EXIST = 9; //对讲实例不存在
/*设备状态定义*/
public const ushort DEVS_OFFLINE = 0; //离线状态
public const ushort DEVS_IDLE = 1; //空闲状态
public const ushort DEVS_PLAYING = 2; //播放状态
public const ushort DEVS_INTERCOM = 3; //对讲状态
public const ushort DEVS_SAMPLER = 4; //采集状态
/*播放状态*/
public const int PS_STOP = 0; //播放停止状态
public const int PS_PLAYING = 1; //播放中
public const int PS_PAUSE = 2; //播放暂停状态
/*场景类型定义*/
public const byte SCENE_PLAY_AUDIOFILE = 0; //播放音频文件
public const byte SCENE_PLAY_TTS = 1; //文字转语音播放
public const byte SCENE_PLAY_PAGING = 2; //话筒寻呼播放
public const byte SCENE_PLAY_STREAM = 3; //音频流播放
//播放实例
public const byte PLAY_INST1 = 0; //播放实例1
public const byte PLAY_INST2 = 1; //播放实例2
public const byte PLAY_INST3 = 2; //播放实例3
public const byte PLAY_INST4 = 3; //播放实例4
public const byte PLAY_INST5 = 4; //播放实例5
//呼叫状态
public const int CALLS_IDLE = 0; //空闲状态
public const int CALLS_START = 1; //启动对讲
public const int CALLS_RING = 2; //响铃状态
public const int CALLS_CALLING = 3; //呼叫状态
public const int CALLS_HANGUP = 4; //挂断状态
//呼叫回调类型
public const uint CALLCB_NONE = 0;
public const uint CALLCB_STATUS_CHANGE = 1; //对讲状态改变
public const uint CALLCB_SEND_AUDIO_DATA = 2; //发送到设备的语音数据
public const uint CALLCB_RECV_AUDIO_DATA = 3; //接收到的语音数据
public const uint CALLCB_CMD_REQ_TIMEOUT = 4; //命令请求超时
//命令请求超时类型
public const int START_CALL_TMO = 1; //启动呼叫超时
public const int PING_CALL_TMO = 2; //PING超时
public const int ANSWER_CALL_TMO = 3; //接听呼叫超时
public const int STOP_CALL_TMO = 4; //停止呼叫超时
public const int RECV_DATA_TMO = 5; //接收数据超时
//音频流格式
public const int ASF_PCM = 0; //PCM格式
public const int ASF_MP3 = 1; //mp3格式
public const int ASF_IMA_ADPCM = 2; //IMA-ADPCM格式
//网络话筒的音源
public const byte NM_AS_MIC = 0; //前置MIC
public const byte NM_AS_LINEIN = 1; //后置LINEIN
//网络话筒广播采样率定义
public const ushort NM_SMPR_8KHZ = 0;
public const ushort NM_SMPR_16KHZ = 1;
public const ushort NM_SMPR_24KHZ = 1;
public const ushort NM_SMPR_32KHZ = 1;
//回调类型定义
public const int CBT_NONE = 0;
public const int CBT_RECV_AUDIOSTREAM = 1; //收到音频流
/*播放信息*/
[StructLayout(LayoutKind.Sequential)]
public struct sPlayInfo
{
public uint playStatus; //播放状态
public int progress; //播放进度0-100
public uint totalTime; //总播放时间(单位s)
public uint samplerate; //采样率
public uint bitrate; //比特率
}
/*对讲实例信息*/
[StructLayout(LayoutKind.Sequential)]
public struct sCallInstInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string call_devip; // //主叫IP
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string called_devip; // //被叫IP
uint call_status; //呼叫状态
}
/*设备信息*/
[StructLayout(LayoutKind.Sequential)]
public struct sDeviceInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string devip; // //设备IP
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string devname; // //设备名称
}
/*分组信息*/
[StructLayout(LayoutKind.Sequential)]
public struct sGroupInfo
{
public byte groupno; // //组编号
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] reserve; //设备名称
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
public string devname; // //设备名称
}
/*广播信息*/
[StructLayout(LayoutKind.Sequential)]
public struct sCastPara
{
public byte audio_src; //音源,只对网络话筒有效(NM_AS_MIC \NM_AS_LINEIN)
public byte priority; //优先级 (1-255)
public ushort samplerate; //采样率
public byte input_gain; //输入增益
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] reserve; //reserve
}
/*音频流格式*/
[StructLayout(LayoutKind.Sequential)]
public struct sAudioFrame
{
public uint audio_head; //音频包头标记
public byte scene_type; //场景,0:广播,1:对讲,2
public byte instance; //实例
public byte priority; //帧优先级
public byte audiofmt; //音频格式
public uint sampleRate; //采样率
public uint bitrate; //比特率
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] reserve; //保留
public byte addr_type; //地址类型,0:编号,1:IP地址
public uint audio_src; //音源(设备编号/IP
public uint audio_dst; //目标(设备编号/IP),仅对讲时用
public uint frame_no; //帧序号
public ushort frame_len; //数据帧长度
public ushort reserve1; //保留
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1200)]
public byte[] data; //帧数据
}
/*播放状态改变回调函数*/
public delegate void PlayStatusChange(byte scene, byte inst, uint status);
/*对讲回调函数*/
public delegate void CallCallback(IntPtr call_inst, uint cbtype, IntPtr data, uint len);
public delegate void ClientCallBack(string devip, uint cbtype, IntPtr data, uint len);
/*********************通用控制函数*********************/
/*()
localIP:IP
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_client_init(string devip);
/*()
funcPlayStatusChange:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_client_start(PlayStatusChange funcPlayStatusChange);
/*
client_cb:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_callback(ClientCallBack funcClientCB);
/*
退
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_client_stop();
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
devip:IP
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_add_play_device(byte scene, byte inst, string devip);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
devip:IP
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_remove_play_device(byte scene, byte inst, string devip);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_clear_play_device(byte scene, byte inst);
/*
devip:IP
devname:,32byte
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_device_name(string devip, IntPtr devname);
/*
devno:
status:,DEVS_OFFLINEDEVS_IDLE....
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_device_status(string devip, ref ushort status);
/*
devip:IP
volume:,0-100....
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_device_volume(string devip, ref byte volume);
/*
devip:IP
volume:,0-100....
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_device_volume(string devip, byte volume);
/*()
devip:IP
group:,0-255....
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_device_temp_group(string devip, ref byte group);
/*()
devno:IP
group:,0-255....
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_device_temp_group(string devip, byte group);
/*()
devno:IP
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_remove_device_temp_group(string devip);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
pdevlist:
devcnt:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_play_device(byte scene, byte inst, IntPtr[] devip, ref int devcnt);
/*()
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
volume:(0-100)
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_play_volume(byte scene, byte inst, int volume);
/*()
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
volume:(0-100)
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_play_volume(byte scene, byte inst, ref int volume);
/*TTS
inst:PLAY_INST1PLAY_INST2...
speed:(-10~+10,0)
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_tts_speed(byte inst, int speed);
/*
inst:PLAY_INST1PLAY_INST2...
audiofmt:,ASF_PCMASF_MP3
channelnbr:(PCM)
samplerate:(PCM)
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_audio_stream_para(byte inst, int audiofmt, int channelnbr, int samplerate);
/*
inst:PLAY_INST1PLAY_INST2...
data:
len:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_send_play_data(byte inst, byte[] data, int len);
/*TTS
inst:PLAY_INST1PLAY_INST2...
speed:(-10~+10,0)
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_tts_speed(byte inst, ref int speed);
/*,
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
audiosrc:
:audiosrc,mp3wmawav
:audiosrc
:
priority:(0-255),
pdevlist:
devcnt:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_start_play(byte scene, byte inst, string audiosrc, int priority, IntPtr[] devip,
ref int devcnt);
/*,,,()
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
audiosrc:
:audiosrc,mp3wmawav
:audiosrc
:
priority:(0-255),
pdevlist:
devcnt:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_start_play_sync(byte scene, byte inst, string audiosrc, int priority, IntPtr[] devip,
ref int devcnt);
/*,na_add_play_devicena_remove_play_device
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
audiosrc:
:audiosrc,mp3wmawav
:audiosrc
:
priority:(0-255),
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_start_play_1(byte scene, byte inst, string audiosrc, int priority);
/*,na_add_play_devicena_remove_play_device,,()
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
audiosrc:
:audiosrc,mp3wmawav
:audiosrc
:
priority:(0-255),
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_start_play_sync_1(byte scene, byte inst, string audiosrc, int priority);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_pause_play(byte scene, byte inst);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_restore_play(byte scene, byte inst);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_stop_play(byte scene, byte inst);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
playinfo:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_playinfo(byte scene, byte inst, ref sPlayInfo playinfo);
/*
scene:,SCENE_PLAY_AUDIOFILESCENE_PLAY_TTSSCENE_PLAY_PAGING
inst:PLAY_INST1PLAY_INST2...
status:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_play_status(byte scene, byte inst, ref uint status);
/**************************************对讲接口*******************************************/
/*
talk_cb:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_call_callback(CallCallback funcCallCallback);
/*
call_inst:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_start_call(out IntPtr call_inst, string called_devip);
/*
call_inst:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_stop_call(IntPtr call_inst);
/*
call_inst:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_answer_call(IntPtr call_inst);
/*
call_inst:
p_inst_info:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_call_inst_info(IntPtr call_inst, ref sCallInstInfo instinfo);
/**************************************网络话筒相关接口*******************************************/
/*广
devip:IP
devinfo:
devcnt:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_nm_set_castdev(string devip, IntPtr devinfo, int devcnt);
/*广
devip:IP
groupinfo:
groupcnt:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_nm_set_castgroup(string devip, IntPtr groupinfo, int groupcnt);
/*广
devip:IP
groupinfo:
groupcnt:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_nm_start_cast(string devip, sCastPara cast_para);
/*广
devip:IP
groupinfo:
groupcnt:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_nm_stop_cast(string devip);
/**************************************端口控制接口*******************************************/
/*
devip:IP
iomode:,2bit,0:1:;2:;3:
ioval:
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_get_iostatus(string devip, ref uint iomode, ref uint ioval);
/*
devip:IP
ioval:16bit16bit
*/
[DllImport("NAudioClientDll.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern int na_set_ioval(string devip, uint ioval);
}