📄 unaconfclient.pas
字号:
(*
----------------------------------------------
unaConfClient.pas - ConfClient class
Voice Communicator components version 2.5
----------------------------------------------
This source code cannot be used without
proper license granted to you as a private
person or an entity by the Lake of Soft, Ltd
Visit http://lakeofsoft.com/ for more information.
Copyright (c) 2001, 2005 Lake of Soft, Ltd
All rights reserved
----------------------------------------------
created by:
Lake, 08 Jul 2003
modified by:
Lake, Jul, Dec 2003
Lake, May-Oct 2005
Lake, Apr 2007
----------------------------------------------
*)
{$I unaDef.inc }
unit
unaConfClient;
interface
uses
Windows, unaTypes, unaClasses, unaSockets, unaVcIDE,
MMSystem;
const
// -- --
c_unaConf_SD_useNone = -1;
c_unaConf_SD_useDSP = -2;
type
//
// -- unaConfClientClass --
//
unaConfClientClass = class
private
f_ipClient: TunavclIPOutStream;
f_waveIn: TunavclWaveInDevice;
f_codecIn: TunavclWaveCodecDevice;
f_codecOut: TunavclWaveCodecDevice;
f_waveOut: TunavclWaveOutDevice;
f_onSE: tunavclSocketEvent;
f_onPE: tunavclPacketEvent;
//
f_recMuted: bool;
f_playEnabled: bool;
f_recEnabled: bool;
//
procedure onClientSocketEvent(sender: tObject; connectionId: unsigned; event: unaSocketEvent; data: pointer; len: unsigned);
procedure onClientPacketEvent(sender: tObject; connectionId: unsigned; const packet: unavclInOutIPPacket);
procedure setRecMuted(value: bool);
procedure setPlayEnabled(value: bool);
procedure setRecEnabled(value: bool);
public
procedure afterConstruction(); override;
procedure beforeDestruction(); override;
//
function connect(const addr, port: string; connType: tunavclProtoType = unapt_UDP): HRESULT;
procedure disconnect();
//
function setConfig(pcmRate, pcmBits, pcmChannels, codecTag: unsigned; waveInDev: unsigned = WAVE_MAPPER; waveOutDev: unsigned = WAVE_MAPPER): HRESULT;
function sendText(const text: wideString): HRESULT;
procedure setSilenceDetectionParams(minVolumeLevel: int = 0; minActiveTime: int = 100);
procedure getSilenceDetectionParams(out minVolumeLevel, minActiveTime: int);
function getVolume(isIn: bool; channel: int = 0): int;
//
property ipClient: TunavclIPOutStream read f_ipClient;
property waveIn: TunavclWaveInDevice read f_waveIn;
property codecIn: TunavclWaveCodecDevice read f_codecIn;
property codecOut: TunavclWaveCodecDevice read f_codecOut;
property waveOut: TunavclWaveOutDevice read f_waveOut;
//
property recordingMuted: bool read f_recMuted write setRecMuted;
property recordingEnabled: bool read f_recEnabled write setRecEnabled;
property playbackEnabled: bool read f_playEnabled write setPlayEnabled;
//
property onSocketEvent: tunavclSocketEvent read f_onSE write f_onSE;
property onPacketEvent: tunavclPacketEvent read f_onPE write f_onPE;
end;
implementation
uses
unaUtils, unaWave, unaMsAcmClasses;
{ unaConfClientClass }
// -- --
procedure unaConfClientClass.afterConstruction();
begin
f_ipClient := TunavclIPOutStream.create(nil);
f_waveIn := TunavclWaveInDevice.create(nil);
f_codecIn := TunavclWaveCodecDevice.create(nil);
f_codecOut := TunavclWaveCodecDevice.create(nil);
f_waveOut := TunavclWaveOutDevice.create(nil);
//
f_waveIn.consumer := f_codecIn;
f_codecIn.consumer := f_ipClient;
f_ipClient.consumer := f_codecOut;
f_codecOut.consumer := f_waveOut;
//
f_waveIn.calcVolume := true;
f_waveOut.calcVolume := true;
//
f_codecIn.inputIsPcm := true;
f_codecIn.formatTagImmunable := true;
//
f_ipClient.isFormatProvider := true;
f_ipClient.onSocketEvent := onClientSocketEvent;
f_ipClient.onPacketEvent := onClientPacketEvent;
//
f_codecOut.inputIsPcm := false;
f_codecOut.formatTagImmunable := false;
//
inherited;
end;
// -- --
procedure unaConfClientClass.beforeDestruction();
begin
disconnect();
//
freeAndNil(f_waveIn);
freeAndNil(f_codecIn);
freeAndNil(f_ipClient);
freeAndNil(f_codecOut);
freeAndNil(f_waveOut);
//
inherited;
end;
// -- --
function unaConfClientClass.connect(const addr, port: string; connType: tunavclProtoType): HRESULT;
begin
disconnect();
//
f_ipClient.host := addr;
f_ipClient.port := port;
f_ipClient.proto := connType;
//
recordingEnabled := true;
playbackEnabled := true;
//
f_waveIn.open();
//
result := S_OK;
end;
// -- --
procedure unaConfClientClass.disconnect();
begin
f_waveIn.close();
f_codecIn.close();
f_waveOut.close();
end;
// -- --
procedure unaConfClientClass.getSilenceDetectionParams(out minVolumeLevel, minActiveTime: int);
begin
minVolumeLevel := f_waveIn.minVolumeLevel;
minActiveTime := f_waveIn.minActiveTime;
end;
// -- --
function unaConfClientClass.getVolume(isIn: bool; channel: int): int;
begin
if (isIn) then
result := waveGetLogVolume(f_waveIn.getVolume(channel))
else
result := waveGetLogVolume(f_waveOut.getVolume(channel));
end;
// -- --
procedure unaConfClientClass.onClientPacketEvent(sender: tObject; connectionId: unsigned; const packet: unavclInOutIPPacket);
begin
if (assigned(f_onPE)) then
f_onPE(self, connectionId, packet);
end;
// -- --
procedure unaConfClientClass.onClientSocketEvent(sender: tObject; connectionId: unsigned; event: unaSocketEvent; data: pointer; len: unsigned);
begin
if (assigned(f_onSE)) then
f_onSE(self, connectionId, event, data, len);
end;
// -- --
function unaConfClientClass.sendText(const text: wideString): HRESULT;
begin
result := f_ipClient.sendData(0, @text[1], length(text) * 2);
end;
// -- --
function unaConfClientClass.setConfig(pcmRate, pcmBits, pcmChannels, codecTag, waveInDev, waveOutDev: unsigned): HRESULT;
begin
f_waveIn.deviceId := int(waveInDev);
f_waveOut.deviceId := int(waveOutDev);
//
f_waveIn.pcm_samplesPerSec := pcmRate;
f_waveIn.pcm_bitsPerSample := pcmBits;
f_waveIn.pcm_numChannels := pcmChannels;
//
f_codecIn.formatTag := codecTag;
f_codecIn.pcm_samplesPerSec := pcmRate;
f_codecIn.pcm_bitsPerSample := pcmBits;
f_codecIn.pcm_numChannels := pcmChannels;
//
result := S_OK;
end;
// -- --
procedure unaConfClientClass.setPlayEnabled(value: bool);
var
oldFP: bool;
begin
f_playEnabled := value;
oldFP := codecOut.isFormatProvider;
//
if (value) then begin
//
codecOut.isFormatProvider := false;
codecOut.addConsumer(waveOut);
end
else
codecOut.removeConsumer(waveOut);
//
codecOut.isFormatProvider := oldFP;
end;
// -- --
procedure unaConfClientClass.setRecEnabled(value: bool);
var
oldFP: bool;
begin
f_recEnabled := value;
oldFP := waveIn.isFormatProvider;
//
if (value) then begin
//
waveIn.isFormatProvider := false;
waveIn.addConsumer(codecIn);
end
else
waveIn.removeConsumer(codecIn);
//
waveIn.isFormatProvider := oldFP;
end;
// -- --
procedure unaConfClientClass.setRecMuted(value: bool);
begin
f_waveIn.enableDataProcessing := not value;
end;
// -- --
procedure unaConfClientClass.setSilenceDetectionParams(minVolumeLevel, minActiveTime: int);
begin
case (minVolumeLevel) of
c_unaConf_SD_useNone: begin
//
f_waveIn.silenceDetectionMode := unasdm_none;
end;
c_unaConf_SD_useDSP: begin
//
f_waveIn.silenceDetectionMode := unasdm_DSP;
end;
else begin
//
f_waveIn.silenceDetectionMode := unasdm_VC;
//
f_waveIn.minVolumeLevel := minVolumeLevel;
f_waveIn.minActiveTime := minActiveTime;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -