www.pudn.com > AVideoCapture.rar > AVideoFunctionUnt.pas
unit AVideoFunctionUnt;
interface
uses
LogonUnt, LiveSrvCastUnt, MainUnt, SockUnt, AVideoStatusUnt, SFLIVESERVERLib_TLB, Windows, Forms, CoolTrayIcon,
Controls, Messages, Sysutils, Variants, Classes, Graphics, Dialogs, Menus,
ImgList, StdCtrls, ComCtrls, ExtCtrls, ScktComp, OleCtrls, ToolWin, Inifiles, Buttons;
procedure TrayIconHint(i: Integer); //系统托盘提示信息
procedure GetAVideoCardsource(LiveSDK: TSFLiveServer); //捕获音视频卡,并初始化设备
procedure GetLocalIP(); //得到本机IP列表
procedure AppliInitialize(); //系统初始化
procedure iniCreate(); //默认创建Ini文件
procedure ShwMainForm();
function Mygetfilename(filename: string): string;
procedure MySetForm(ChNO: Integer; LiveSDK: TSFLiveServer; SourceStr: string; Fps: Integer);
procedure MySharePath(UserName: string; PassWrd: string; Pathname: string);
function FindSharePath(Pathname: string): Boolean;
procedure livesrvdefaultpar(iChannelNO: Integer; LiveSDK: TSFLiveServer);
procedure appliexit();
function BackBoolToStr(BL: Boolean): string;
function BackStrToBool(Str: string): Boolean;
implementation
uses CastOprUnt, UserPowerUnt;
function BackBoolToStr(BL: Boolean): string;
begin
//result := IntToStr(abs(StrToInt(booltostr(BL))));
if BL = True then
result := '1'
else
result := '0';
end;
function BackStrToBool(Str: string): Boolean;
begin
if Str = '1' then
result := True
else
result := False;
end;
procedure GetAVideoCardsource(LiveSDK: TSFLiveServer); //捕获音视频卡,并初始化设备
var
i, j: Integer;
VideoStr, AudeoStr: string;
begin
//发送AVideo卡源信息的格式为: AVideoCapture-AV_CardSource/*//A/0:>C-MediaWave->,WaveMax,WaveMic,1:>AudeoFt->ABSDeo,|/V/0:>ConexantVideo->VideoSVideo,VideoComposite,|DataEnd#13
cardcount := 0;
for i := 0 to 2 do begin
videoCard[i].Name := LiveSDK.GetvideoCapName(i); //得到指定序号的视频捕捉设备名称,任何时间有效。
if videoCard[i].Name <> '' then begin
cardcount := cardcount + 1;
LiveSDK.CapVideoDevice[0] := i; //设定要捕捉的视频设备序号(捕捉设备名称),-1表示不捕捉视频,100表示使用桌面作为视频源。运行之前设置有效
VideoStr := LiveSDK.GetvideoSupportSource(i); //得到指定频道设置的视频捕捉设备支持的视频源名称,以SubItemOpr分隔。当指定的频道已经选择了捕捉源(不是广播文件)后有效。
for j := 0 to 9 do
if Pos(SubItemOpr, VideoStr) > 0 then begin
videoCard[i].Source[j] := Copy(VideoStr, 1, Pos(SubItemOpr, VideoStr) - 1);
videoCard[i].VideoSrcList := videoCard[i].VideoSrcList + videoCard[i].Source[j] + DBSrcEnd;
Delete(VideoStr, 1, Pos(SubItemOpr, VideoStr));
end;
end;
audeoCard[i].Name := LiveSDK.GetAudioCapName(i); //得到指定序号的音频捕捉设备名称,任何时间有效。
if audeoCard[i].Name <> '' then begin
if audeoCard[i].Name <> '' then begin
LiveSDK.CapAudioDevice[0] := i; //设定要捕捉的音频设备序号(捕捉设备名称),- 1 表示不捕捉音频。运行之前设置有效}
AudeoStr := LiveSDK.GetAudioSupportSource(i); //得到指定频道设置的音频捕捉设备支持的音频源名称,以SubItemOpr分隔。当指定的频道已经选择了捕捉源(不是广播文件)后有效.注:当处于"Preview"状态时此接口无效 }
for j := 0 to 9 do
if Pos(SubItemOpr, AudeoStr) > 0 then begin
audeoCard[i].Source[j] := Copy(AudeoStr, 1, Pos(SubItemOpr, AudeoStr) - 1);
audeoCard[i].AudeoSrcList := audeoCard[i].AudeoSrcList + audeoCard[i].Source[j] + DBSrcEnd;
Delete(AudeoStr, 1, Pos(SubItemOpr, AudeoStr));
end;
end;
end;
end;
end;
procedure GetLocalIP(); //得到本机IP列表
var
i: Integer;
IPStr: string;
begin
IPStr := LiveSrvCast.LiveSrv.GetLocalIPList;
{GetLocalIPList 得到本机IP列表,IP间以以SubItemOpr分隔。任何时间有效。}
for i := 0 to 2 do
if Pos(SubItemOpr, IPStr) > 0 then
if Copy(IPStr, 1, Pos(SubItemOpr, IPStr) - 1) <> '127.0.0.1' then begin
localIPSrc[i].Addr := Copy(IPStr, 1, Pos(SubItemOpr, IPStr) - 1);
Delete(IPStr, 1, Pos(SubItemOpr, IPStr));
end;
end;
procedure AppliInitialize(); //系统初始化
begin
iniCreate;
with Main do begin
TrayIconHint(4);
ClientSocket.Address := appliini.ReadString('Server_Socket', 'Addr', '192.168.0.1');
ClientSocket.Port := appliini.ReadInteger('Server_Socket', 'Port', 9908);
QueryTimer.Interval := appliini.ReadInteger('Timer', 'Query', 3000);
LogoTimer.Interval := appliini.ReadInteger('Timer', 'Logo', 4000);
ActiveTimer.Interval := appliini.ReadInteger('Timer', 'Active', 200);
UserPowerTimer.Interval := appliini.ReadInteger('Timer', 'UserPower', 5000);
DesktopTimer.Interval := appliini.ReadInteger('Timer', 'Desktop', 900000);
AudioBps.ItemIndex := 2;
ScreenModeBox.ItemIndex := appliini.ReadInteger('Desktop', 'ScreenMode', 0);
ScreenQualityEdit.Text := IntToStr(appliini.ReadInteger('Desktop', 'ScreenQuality', 25));
RunModel.ItemIndex := appliini.ReadInteger('Desktop', 'RunModel', 2);
VideoBps.Text := IntToStr(appliini.ReadInteger('Desktop', 'VideoBps', 700));
Teacherch.Checked := appliini.ReadBool('Desktop', 'TeacherCh', True);
VideoBox.ItemIndex := appliini.ReadInteger('Desktop', 'TeacherDrv', 0);
VideoSource.ItemIndex := appliini.ReadInteger('Desktop', 'TeacherSrc', 0);
TVFormat.ItemIndex := appliini.ReadInteger('Desktop', 'TVFormat', 2);
AutoCBox.Checked := appliini.ReadBool('Desktop', 'Auto', True);
TSWWidth.Text := IntToStr(appliini.ReadInteger('Desktop', 'TSWWidth', 174));
TSWHeigth.Text := IntToStr(appliini.ReadInteger('Desktop', 'TSWHeigth', 144));
FpsEdit.Text := IntToStr(appliini.ReadInteger('Desktop', 'Fps', 10));
Otherch.Checked := appliini.ReadBool('Desktop', 'OtherCh', False);
OtherCBox.ItemIndex := appliini.ReadInteger('Desktop', 'OtherDrv', -1);
OVideoSource.ItemIndex := appliini.ReadInteger('Desktop', 'OtherSrc', -1);
OVFormat.ItemIndex := appliini.ReadInteger('Desktop', 'OVFormat', 2);
end;
end;
procedure iniCreate(); //默认创建Ini文件
begin
iniphysicsname := ExtractFileDir(Application.ExeName) + '\' + Copy(Application.ExeName, Length(ExtractFileDir(Application.ExeName)) + 2, Pos('.exe', Application.ExeName) - Length(ExtractFileDir(Application.ExeName)) - 2) + '.ini';
//ExtractFileDir()最后无\
appliini := Tinifile.Create(iniphysicsname);
if not FileExists(iniphysicsname) then begin
TrayIconHint(3);
appliini.Writestring('Setup', 'AppliName', Application.ExeName);
appliini.Writestring('Setup', 'ReadMe', '[Timer]~[Desktop]之间的参数需和实际相符...');
appliini.Writestring('User', 'Name', 'Admin');
appliini.Writestring('User', 'Password', 'Admin');
appliini.WriteInteger('Timer', 'Active', 200);
appliini.WriteInteger('Timer', 'Query', 3000);
appliini.WriteInteger('Timer', 'Logo', 4000);
appliini.WriteInteger('Timer', 'UserPower', 5000);
appliini.WriteInteger('Timer', 'Desktop', 900000);
appliini.Writestring('Server_Socket', 'Addr', '192.168.0.1');
appliini.WriteInteger('Server_Socket', 'Port', 9908);
appliini.Writestring('Client_SFLive', 'SendIP', '192.168.0.2');
appliini.WriteInteger('Client_SFLive', 'TCPListenPort', 554);
appliini.WriteInteger('Client_SFLive', 'TCPSendPort', 8090);
appliini.WriteInteger('Scroll', 'Interval', 56);
appliini.WriteInteger('Scroll', 'Speed', 2);
appliini.WriteInteger('Scroll', 'Height', 30);
appliini.WriteInteger('Desktop', 'ScreenMode', 0);
appliini.WriteInteger('Desktop', 'ScreenQuality', 25);
appliini.WriteInteger('Desktop', 'RunModel', 2);
appliini.WriteInteger('Desktop', 'VideoBps', 700);
appliini.WriteInteger('Desktop', 'AudioBps', 32);
appliini.WriteBool('Desktop', 'Auto', True);
appliini.WriteInteger('Desktop', 'Fps', 10);
appliini.WriteBool('Desktop', 'TeacherCh', True);
appliini.WriteInteger('Desktop', 'TeacherDrv', 0);
appliini.WriteInteger('Desktop', 'TeacherSrc', 0);
appliini.WriteInteger('Desktop', 'TVFormat', 2);
appliini.WriteInteger('Desktop', 'TSWWidth', 174);
appliini.WriteInteger('Desktop', 'TSWHeigth', 144);
appliini.WriteBool('Desktop', 'OtherCh', False);
appliini.WriteInteger('Desktop', 'OtherDrv', -1);
appliini.WriteInteger('Desktop', 'OtherSrc', -1);
appliini.WriteInteger('Desktop', 'OVFormat', 2);
end;
end;
procedure ShwMainForm();
begin
with Main do
if Desktop then
TrayIcon.Showmainform
else
UserPower.MySerOpr_Query;
end;
function Mygetfilename(filename: string): string;
var
i: Integer;
begin
result := filename;
for i := Length(filename) downto 1 do
if filename[i] = '.' then begin
result := Copy(filename, 1, i - 1);
Break;
end;
end;
procedure MySetForm(ChNO: Integer; LiveSDK: TSFLiveServer; SourceStr: string; Fps: Integer);
var
CapHeight, CapWidth: Integer;
begin
CapWidth := StrToInt(Copy(SourceStr, 1, Pos(':', SourceStr) - 1));
CapHeight := StrToInt(Copy(SourceStr, Pos(':', SourceStr) + 1, Length(SourceStr) - Pos(':', SourceStr)));
LiveSDK.SetVideoFormat(ChNO, CapWidth, CapHeight, Fps);
end;
procedure MySharePath(UserName, PassWrd, Pathname: string);
var
Nr: netresource;
begin
try
Nr.dwType := RESOURCETYPE_ANY;
Nr.lpLocalName := nil;
Nr.lpRemoteName := PAnsiChar(Pathname);
Nr.lpProvider := nil;
WNetAddConnection2(Nr, PChar(PassWrd), PChar(UserName), CONNECT_TEMPORARY);
Share_Path.Add(Pathname);
except
end;
end;
function FindSharePath(Pathname: string): Boolean;
var
i: Integer;
begin
result := False;
if Share_Path.Count > 0 then
for i := 0 to Share_Path.Count - 1 do
if Share_Path.Strings[i] = Pathname then begin
result := True;
Break;
end;
end;
procedure appliexit();
var
i: Integer;
begin
with Main do begin
TrayIcon.Free;
appliini.WriteInteger('Desktop', 'ScreenMode', ScreenModeBox.ItemIndex);
appliini.WriteInteger('Desktop', 'ScreenQuality', StrToInt(ScreenQualityEdit.Text));
appliini.WriteInteger('Desktop', 'RunModel', RunModel.ItemIndex);
appliini.WriteInteger('Desktop', 'VideoBps', StrToInt(VideoBps.Text));
appliini.WriteInteger('Desktop', 'AudioBps', StrToInt(AudioBps.Text));
appliini.WriteBool('Desktop', 'Auto', AutoCBox.Checked);
appliini.WriteInteger('Desktop', 'Fps', StrToInt(FpsEdit.Text));
appliini.WriteBool('Desktop', 'TeacherCh', Teacherch.Checked);
appliini.WriteInteger('Desktop', 'TeacherDrv', VideoBox.ItemIndex);
appliini.WriteInteger('Desktop', 'TeacherSrc', VideoSource.ItemIndex);
appliini.WriteInteger('Desktop', 'TVFormat', TVFormat.ItemIndex);
appliini.WriteInteger('Desktop', 'TSWWidth', StrToInt(TSWWidth.Text));
appliini.WriteInteger('Desktop', 'TSWHeigth', StrToInt(TSWHeigth.Text));
appliini.WriteBool('Desktop', 'OtherCh', Otherch.Checked);
appliini.WriteInteger('Desktop', 'OtherDrv', OtherCBox.ItemIndex);
appliini.WriteInteger('Desktop', 'OtherSrc', OVideoSource.ItemIndex);
appliini.WriteInteger('Desktop', 'OVFormat', OVFormat.ItemIndex);
if Desktop then begin
for i := 0 to 2 do
if LiveSrvCast.LiveSrv.IsChannelRunning(i) then
LiveSrvCast.LiveSrv.StopCast(i)
end
else
for i := 0 to 2 do
if LiveSrvCast.LiveSrv.IsChannelRunning(i) then
myStopCast(IntToStr(i));
end;
Application.Terminate;
end;
procedure livesrvdefaultpar(iChannelNO: Integer; LiveSDK: TSFLiveServer);
begin
try
with LiveSDK do begin
CapVideoDevice[iChannelNO] := -1; //指定视频卡 - 1 不捕捉,100桌面 运行之前
CapAudioDevice[iChannelNO] := -1; //指定视频卡 - 1 ~ 10 - 1 不捕捉 运行之前
ChannelDescribe[iChannelNO] := ''; //直播描述信息 长度0~100 任何时间
SaveFileName[iChannelNO] := ''; //长度255 为0不录像,反之要录像 任何时间
CastFileName[iChannelNO] := ''; //设置广播文件路径 不广播文件 为空运行之前
ShowVideo[iChannelNO] := False; //播放画面 运行之前
showaudio[iChannelNO] := False; //播放声音 运行之前
sendvideo[iChannelNO] := False; //发送视频 任何时间
sendaudio[iChannelNO] := False; //发送音频 任何时间
SendIP[iChannelNO] := appliini.ReadString('Client_SFLive', 'SendIP', '192.168.0.2'); //发送数据用的IP网卡 运行之前
TCPListenPort := appliini.ReadInteger('Client_SFLive', 'TCPListenPort', 554); ; //系统接入监听端口 - 1(默认)不使用TCP监听模式 任何时间
TcpSendPort[iChannelNO] := appliini.ReadInteger('Client_SFLive', 'TCPSendPort', 8090) + iChannelNO; //远程接入模式时的发送数据端口 运行之前
end;
except
end;
end;
procedure TrayIconHint(i: Integer); //系统托盘提示信息
var
InforStr: string;
begin
if not Desktop then begin
case i of
0: InforStr := '已连接服务器...';
1: InforStr := '采集本地音视频卡信息...';
2: InforStr := '赋予远程服务器操控权...';
3: InforStr := '配置信息不存在,默认创建。如仍不能' + #13 + '运行,请到程序安装路径修改相关数据...';
4: InforStr := '初始化运行参数...';
5: InforStr := '获取本地网卡及IP' + #13 + '地址、端口设置信息...';
6: InforStr := '登陆服务器失败,请检查配置' + #13 + '信息、网络设施及服务器状态...';
7: InforStr := '登陆服务器...';
8: InforStr := '请求数据库中采集卡、通道信息...';
9: InforStr := '数据库中无采集卡、通道信息,默认' + #13 + '按本地音视频卡及源资源配置数据库...';
10: InforStr := '修正数据库中音视频卡及源信息...';
11: InforStr := '请求资源服务器列表,设置共享路径...';
12: InforStr := '请求组播地址、端口参数设置...';
13: InforStr := '请求桌面直播操作权...';
14: InforStr := '初始化完成...';
15: InforStr := '采集音视频卡信息失败,请' + #13 + '检查音视频卡硬件设备...';
16: InforStr := '采集网卡信息失败,请检查网卡...';
17: InforStr := '删除数据库中音视频卡及源信息...';
18: InforStr := '操作权:服务器->桌面...';
19: InforStr := '操作权:桌面->服务器...';
end;
Main.TrayIcon.ShowBalloonHint('AVideo采集端', InforStr, bitInfo, 10);
Sleep(1000);
end;
end;
end.