📄 u_mgclient_main.pas
字号:
(*
----------------------------------------------
u_mgClient_main.pas
MediaGate demo application - Client main form source
----------------------------------------------
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) 2002, 2007 Lake of Soft, Ltd
All rights reserved
----------------------------------------------
created by:
Lake, 04 Apr 2003
modified by:
Lake, Apr-Oct 2003
----------------------------------------------
*)
{$I unaDef.inc }
unit
u_mgClient_main;
interface
uses
Windows, unaTypes, unaClasses, Forms,
unaVcIDE, StdCtrls, Controls, Classes, ExtCtrls, CheckLst, ActnList,
ComCtrls;
type
Tc_form_main = class(TForm)
c_edit_host: TEdit;
Label1: TLabel;
c_edit_speakPort: TEdit;
Label2: TLabel;
c_rb_speak: TRadioButton;
c_rb_listen: TRadioButton;
c_button_go: TButton;
waveIn: TunavclWaveInDevice;
c_button_stop: TButton;
codecIn: TunavclWaveCodecDevice;
ipClient: TunavclIPOutStream;
codecOut: TunavclWaveCodecDevice;
waveOut: TunavclWaveOutDevice;
c_clb_debug: TCheckListBox;
c_timer_update: TTimer;
c_edit_listenPort: TEdit;
Label3: TLabel;
Label4: TLabel;
Bevel1: TBevel;
Bevel2: TBevel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Bevel3: TBevel;
c_statusBar_main: TStatusBar;
c_actionList_main: TActionList;
a_cln_start: TAction;
a_cln_stop: TAction;
c_label_stat: TLabel;
Label8: TLabel;
Label9: TLabel;
c_checkBox_random: TCheckBox;
c_comboBox_speakProto: TComboBox;
Label10: TLabel;
c_comboBox_listenProto: TComboBox;
Label11: TLabel;
//
procedure formCreate(sender: tObject);
procedure formDestroy(sender: tObject);
procedure formCloseQuery(sender: tObject; var canClose: boolean);
procedure formShow(sender: tObject);
//
procedure c_timer_updateTimer(sender: tObject);
//
procedure a_cln_startExecute(sender: tObject);
procedure a_cln_stopExecute(sender: tObject);
procedure ipClientClientDisconnect(sender: TObject; connectionId: Cardinal; connected: LongBool);
private
{ Private declarations }
f_ini: unaIniFile;
public
{ Public declarations }
end;
var
c_form_main: Tc_form_main;
implementation
{$R *.dfm}
uses
unaUtils, unaVCLUtils, SysUtils;
// -- --
procedure Tc_form_main.formCreate(sender: tObject);
begin
f_ini := unaIniFile.create();
//
randomize();
//
c_edit_host.text := f_ini.get('server.addr', '192.168.1.1');
//
c_edit_speakPort.text := f_ini.get('server.speak.port', '17860');
c_edit_listenPort.text := f_ini.get('server.listen.port', '17861');
//
c_comboBox_speakProto.itemIndex := f_ini.get('speak.proto', int(0));
c_comboBox_listenProto.itemIndex := f_ini.get('listen.proto', int(0));
//
if (f_ini.get('client.mode.isSpeak', true)) then
c_rb_speak.checked := true
else
c_rb_listen.checked := true;
end;
// -- --
procedure Tc_form_main.formDestroy(sender: tObject);
begin
with (f_ini) do begin
setValue('server.addr', c_edit_host.text);
//
setValue('server.speak.port', c_edit_speakPort.text);
setValue('server.listen.port', c_edit_listenPort.text);
//
setValue('speak.proto', c_comboBox_speakProto.itemIndex);
setValue('listen.proto', c_comboBox_listenProto.itemIndex);
//
setValue('client.mode.isSpeak', c_rb_speak.checked);
end;
//
freeAndNil(f_ini);
end;
// -- --
procedure Tc_form_main.formCloseQuery(sender: tObject; var canClose: boolean);
begin
c_timer_update.enabled := false;
a_cln_stop.execute();
//
saveControlPosition(self, f_ini);
end;
// -- --
procedure Tc_form_main.formShow(sender: tObject);
begin
loadControlPosition(self, f_ini);
//
c_clb_debug.visible := {$IFDEF DEBUG}true{$ELSE}false{$ENDIF};
c_checkBox_random.visible := c_clb_debug.visible;
//
c_timer_update.enabled := true;
end;
// -- --
procedure Tc_form_main.c_timer_updateTimer(Sender: TObject);
var
sampleSize: unsigned;
begin
if (not (csDestroying in componentState)) then begin
//
{$IFDEF DEBUG}
c_clb_debug.checked[0] := waveIn.active;
c_clb_debug.checked[1] := codecIn.active;
c_clb_debug.checked[2] := ipClient.active;
c_clb_debug.checked[3] := codecOut.active;
c_clb_debug.checked[4] := waveOut.active;
//
c_statusBar_main.panels[0].text := 'Mem: ' + int2str(ams() shr 10, 10, 3) + ' KB';
{$ENDIF}
//
if (c_rb_speak.checked) then begin
//
sampleSize := codecIn.pcm_bitsPerSample shr 3 * codecIn.pcm_numChannels;
if (1 < sampleSize) then
c_label_stat.caption := 'Sent: ' + int2str(waveIn.outBytes div sampleSize, 10, 3) + ' samples / ' + int2str((waveIn.outBytes div sampleSize) div codecIn.pcm_samplesPerSec) + ' seconds.';
end
else begin
//
sampleSize := codecOut.pcm_bitsPerSample shr 3 * codecOut.pcm_numChannels;
if (1 < sampleSize) then
c_label_stat.caption := 'Received: ' + int2str(waveOut.inBytes div sampleSize, 10, 3) + ' samples / ' + int2str((waveOut.inBytes div sampleSize) div codecOut.pcm_samplesPerSec) + ' seconds.';
end;
//
a_cln_start.enabled := not ipClient.active;
a_cln_stop.enabled := not a_cln_start.enabled;
c_rb_speak.enabled := a_cln_start.enabled;
c_rb_listen.enabled := c_rb_speak.enabled;
//
if (c_checkBox_random.checked) then
//
if (25 = random(30)) then begin
//
if (a_cln_start.enabled) then
a_cln_start.execute()
else
a_cln_stop.execute()
end;
end;
end;
// -- --
procedure Tc_form_main.a_cln_startExecute(Sender: TObject);
begin
a_cln_start.enabled := false;
//
ipClient.host := c_edit_host.text;
//
if (c_rb_speak.checked) then begin
// speak
ipClient.proto := tunavclProtoType(choice(0 = c_comboBox_speakProto.ItemIndex, ord(unapt_UDP), ord(unapt_TCP)));
ipClient.port := c_edit_speakPort.text;
ipClient.consumer := nil; // no need to playback
//
if (not waveIn.open()) then begin
waveIn.close();
//
raise exception.create('Unable to open waveIn device, error text: '#13#10 + waveIn.waveErrorAsString);
end;
end
else begin
// listen
ipClient.proto := tunavclProtoType(choice(0 = c_comboBox_listenProto.ItemIndex, ord(unapt_UDP), ord(unapt_TCP)));
ipClient.port := c_edit_listenPort.text;
ipClient.consumer := codecOut; // restore playback chain
ipClient.open();
end;
end;
// -- --
procedure Tc_form_main.a_cln_stopExecute(sender: tObject);
begin
a_cln_stop.enabled := false;
// stop everything
waveIn.close();
end;
// -- --
procedure Tc_form_main.ipClientClientDisconnect(sender: tObject; connectionId: cardinal; connected: LongBool);
begin
// stop everything
waveIn.close();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -