Type
TBufferType=Array [1..1] of Byte;
PBufferType=^TBufferType;
DataBuf=Record
Size:LongWord;
Data:TBufferType;
End;
procedure SendQueue.SendBoth;
Var
s:LongWord;
DataStream:TWinSocketStream;
p,p1:^DataBuf;
Temp:Array[1..20*1024] of Byte;
begin
If NOT Terminated Then
Begin
If (FVideoQueue.Count>0) Then//AND (FAudioQueue.Count>0) Then
Begin
p:=FVideoQueue.Pop;
//p1:=FAudioQueue.Pop;
Try
If IsConnected Then
Begin
s:=p^.Size ;//+p1^.Size+8;
Move(p^,Temp,p^.Size+4);
//Move(p1^,Temp[P^.Size+4+1],p1^.Size+4);
//Combine data
DataStream:=TWinSocketStream.Create(ComSocket,100);
If DataStream.Write(s,4)=4 Then Datastream.Write(Temp,s);
DataStream.Free;
End;
Finally
FreeMem(p);
// FreeMem(p1);
End;
End;
End;
end;
procedure TMainForm.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
Var
p,p1:^DataBuf;
Temp:Array[1..20*1024] of Byte;
DataStream:TWinSocketStream;
s,s1:LongWord;
begin
If Socket.Connected Then
Begin
Try
DataStream:=TWinSocketStream.Create(Socket,1000);
Try
If DataStream.WaitForData(1000) Then
Begin
If DataStream.Read(s,4)=0 Then Socket.Close;
If DataStream.Read(Temp,s)=0 Then Socket.Close;
Move(Temp,s,4); //Size of the video block
If s<>0 Then
Begin
GetMem(p,s+4);
p^.Size:=s;
Move(Temp[5],p^.Data,s); //Data of the video block
CodedFrame1.Push(p);
VDC.Execute; //unpack
End;
{ Move(Temp[4+s+1],s1,4); //Size of the audio block
GetMem(p1,s1+4);
p1^.Size:=s1;
Move(Temp[4+s+4+1],p1^.Data,s1);
CodedAudio1.Push(p1);
ADC.Execute; //unpack}
End
Else
Socket.Close;
Finally
End;
Finally
DataStream.Free;
End;
End;
end;
够简单吧?!