SafeDispatch/AppServerMobile/MultiVoice.cs
2024-02-22 18:43:59 +02:00

74 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SafeMobileLib;
namespace AppServerMobile
{
class MultiVoice
{
private string ip;
private int gwID;
private int radioGWid;
private int port = 17234;
private UdpMulticast udp4VoiceRecv;
private bool isRecording;
public bool IsRecording
{
get { return isRecording; }
set { isRecording = value; }
}
public MultiVoice(string ip, int gwID, int radiogwID)
{
this.ip = ip;
this.gwID = gwID;
this.radioGWid = radiogwID;
//init voice from multicast
udp4VoiceRecv = new UdpMulticast(ip, port);
udp4VoiceRecv.OnNewDataRecv += new UdpMulticast.newData4Send(udp4VoiceRecv_OnNewDataRecv);
}
void udp4VoiceRecv_OnNewDataRecv(byte[] data, int dataLen)
{
if (this.OnNewDataRecv != null)
this.OnNewDataRecv(data, dataLen,gwID, radioGWid);
}
public void Start()
{
udp4VoiceRecv.StartListen();
isRecording = true;
}
public void Stop()
{
try
{
SM.Debug("UDP4VoiceRecv - Stop Listen " + " MultiVoice Stop");
udp4VoiceRecv.StopListen();
}
catch (Exception ex)
{
SM.Debug(ex.ToString());
}
finally
{
isRecording = false;
}
}
public delegate void newData4Send(byte[] data, int dataLen, int gwID, int radioGWid);
public event newData4Send OnNewDataRecv;
public void SendAudio(byte[] data, int len)
{
//SM.Debug("************* IP : " + this.ip + " | " + this.port + " | " + len);
udp4VoiceRecv.Send(data, len);
}
}
}