unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, VideoDisp, Videocap, Contnrs, variable, DataPack, vfw, ExtCtrls,
ScktComp, ACMOut, ACMIn, ACMConvertor, Menus, IdTCPConnection,
IdTCPClient, IdBaseComponent, IdComponent, IdTCPServer;
type
TMainForm = class(TForm)
VideoCap: TVideoCap;
VideoDisp: TVideoDisp;
btnStart: TButton;
btnStop: TButton;
Memo: TMemo;
Timer1: TTimer;
Timer2: TTimer;
AddrEdit: TEdit;
btnConnect: TButton;
ACMIn: TACMIn;
ACMOut: TACMOut;
MainMenu1: TMainMenu;
mmFile: TMenuItem;
lReceive: TLabel;
lPreview: TLabel;
btnExit: TButton;
btnDisconnect: TButton;
btnPause: TButton;
IdTCPServer: TIdTCPServer;
IdTCPClient: TIdTCPClient;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure btnStartClick(Sender: TObject);
procedure VideoCapVideoStream(sender: TObject;
lpVhdr: PVIDEOHDR);
procedure btnStopClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure btnConnectClick(Sender: TObject);
procedure ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketAccept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ACMInBufferFull(Sender: TObject;
Data: Pointer;
Size: Integer);
procedure btnExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
Uses Player,Compress,Send;
procedure TMainForm.FormCreate(Sender: TObject);
Var
Vheader:TBitmapInfoHeader;
begin
VideoCap.DriverOpen:=False;
VideoCap.DriverIndex:=0;
HasVideo:=True;
Try
VideoCap.VideoPreview:=True;
Except
On ENotConnectExceptiondo
HasVideo:=False;
end;
If HasVideo then
begin
VHeader:=Videocap.BitMapInfoHeader;
VHeader.bicompression:=bi_RGB;
// Always RGB-Data
VHeader.biBitCount:= 24;
VideoCap.BitMapInfoHeader:= VHeader;
End
else
With VHeaderdo
begin
biSize:=40;
biWidth:=200;
biHeight:=150;
biPlanes:=1;
biBitCount:=24;
biCompression:=0;
biSizeImage:=57600;
biXPelsPerMeter:=0;
biYPelsPerMeter:=0;
biClrUsed:=0;
biClrImportant:=0;
end;
OriBMH:=VHeader;
CodedBMH:=QueryVideoCodec(OriBMH);
ACMOut.Open(ACMWaveFormat);
VideoDisp.Streaming:= true;
VideoDisp.BitMapInfoHeader:= VHeader;
If HasVideo then
VideoCap.DriverOpen:=True;
// ServerSocket.Open;
OriFrame:=TQueue.Create;
CodedFrame:=TQueue.Create;
OriFrame1:=TQueue.Create;
CodedFrame1:=TQueue.Create;
OriAudio:=TQueue.Create;
OriAudio1:=TQueue.Create;
D2Q:=Data2Queue.Create(OriFrame);
// Q2D:=Queue2Data.Create(OriFrame);
myPlayer:=TPlayer.Create(OriFrame1,OriAudio,HasVideo);
VC:=VideoCompressor.Create(OriBMH,CodedBMH,OriFrame,CodedFrame);
VDC:=VideoDeCompressor.Create(OriBMH,CodedBMH,CodedFrame,OriFrame1);
end;
procedure TMainForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
VDC.Terminate;
VC.Terminate;
VDC.Free;
VC.Free;
myPlayer.Free;
// Q2D.Free;
D2Q.Free;
OriAudio1.Free;
OriAudio.Free;
CodedFrame1.Free;
OriFrame1.Free;
CodedFrame.Free;
OriFrame.Free;
// ServerSocket.Close;
VideoDisp.Streaming:= false;
VideoCap.DriverOpen:=False;
ACMOut.Close;
end;
procedure TMainForm.btnStartClick(Sender: TObject);
begin
Timer1.Enabled:=True;
Timer2.Enabled:=True;
If HasVideo then
VideoCap.StartCapture;
ACMIn.Open(ACMWaveFormat);
end;
procedure TMainForm.VideoCapVideoStream(sender: TObject;
lpVhdr: PVIDEOHDR);
Const
KeyFrame:Boolean=True;
begin
D2Q.Convert(lpVhdr^.lpData^,lpVhdr^.dwBytesUsed);
VC.Execute;
end;
procedure TMainForm.btnStopClick(Sender: TObject);
begin
ACMIn.Close;
If HasVideo then
VideoCap.StopCapture;
// Sleep(500);
Timer1.Enabled:=False;
// Sleep(500);
Timer2.Enabled:=False;
FreeResource;
end;
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
VDC.Execute;
end;
procedure TMainForm.Timer2Timer(Sender: TObject);
begin
myPlayer.Execute;
end;
procedure TMainForm.ACMInBufferFull(Sender: TObject;
Data: Pointer;
Size: Integer);
Var
p:^DataBuf;
i:Byte;
ap
BufferType;
begin
ap:=Data;
For i:=1 to 20do
begin
GetMem(p,400+4);
p^.Size:=400;
Move(ap^[(i-1)*400+1],p^.Data,400);
OriAudio.Push(p);
end;
end;
end.