在tcp indy中发送音频流 [英] Send audio stream in tcp indy
问题描述
我正在制作一个简单的聊天应用程序,它已经有了网络摄像头或实时视频流,现在我想从麦克风添加实时音频流。我目前正在使用TCP indy 10.我听说你可以使用ACMout.pas / ACMin.pas等(ACM)来做到这一点。问题是我在网上找不到任何示例,我已经有了ACM标题。
如果有人可以分享任何这方面的例子,或者可以制作一个,请。非常感谢你。
编辑:
我正在使用来自 torry.net [ ^ ]
在演示中使用UDP,我试图将其转换为TCP,这是我的代码
// 发送
程序TSendFrm.ACMIn1Data(发件人:TACMComponent; aDataPtr:指针;
aDataSize:Cardinal);
开始
// 袜子.SendBuffer(aDataPtr ^,aDataSize); //< -udp
// IdTCPClient1.IOHandler.WriteBufferOpen;
try
IdTCPClient1.IOHandler.Write(RawToBytes(aDataPtr ^,aDataSize));
最后
// IdTCPClient1 .IOHandler.WriteBufferClose;
end ;
Bytes:= Bytes + aDataSize;
BytesLbl.Caption:=格式(' %u',[Bytes]);
UpDate;
end ;
// 收货结束
程序TRecvFrm .IdTCPServer1Execute(AContext:TIdContext);
var
Ms:TMemoryStream;
// Ms:TStream;
开始
Ms:= TMemoryStream.Create;
AContext.Connection.IOHandler.ReadStream(Ms);
Ms.Position:= 0 ;
ACMOut1.PlayBack(Ms);
字节:= Bytes + Ms.Size;
BytesLbl.Caption:=格式(' %u',[Bytes]);
UpDate;
Ms.Free;
end ;
仍然不适合我。我正在使用indy 10
看看: https: //code.google.com/p/siapen/ [ ^ ]
你会发现 VFrames.pas [ ^ ]如果你深入研究代码。
[更新]
1.从ACM获取原始数据>
2.将数据写入MemoryStream
3.使用Indy发送MemoryStream。
与此类似的东西:
with Owner.PeerThread.Connection do
begin
如果已连接则
开始
OpenWriteBuffer;
try
WriteStream(memoryStream,True,True,LStreamPacket.Size);
最后
CloseWriteBuffer;
结束;
结束;
结束;
祝你好运
Espen Harlinn
< blockquote>好吧我终于使用了indy tcp
如果不是InputBufferIsEmpty 然后
开始
Ms:= TMemoryStream.Create;
InputBuffer.ExtractToStream(Ms);
Ms.Position:= 0 ;
ACMOut1.PlayBack(Ms);
字节:= Bytes + Ms.Size;
BytesLbl.Caption:=格式(' %u',[Bytes]);
UpDate;
Ms.Free;
结束;
Hi, I am making a simple chat application where it has already a webcam or live video stream, now I want to add a live audio streaming from microphone. I am currently using TCP indy 10. I heard that you can do this using ACMout.pas / ACMin.pas etc(ACM). Problem is I can't find any example online, I already have the ACM headers.
If somebody can share any example of this, or could make one, please. Thank you so much.
EDIT:
I am using ACM Components v.1.6 from torry.net[^]
in the demo it is using UDP,I tried to convert it to TCP, here is my code
//sending
procedure TSendFrm.ACMIn1Data(Sender: TACMComponent; aDataPtr: Pointer;
aDataSize: Cardinal);
begin
//Sock.SendBuffer(aDataPtr^,aDataSize); // <-udp
//IdTCPClient1.IOHandler.WriteBufferOpen;
try
IdTCPClient1.IOHandler.Write( RawToBytes(aDataPtr^,aDataSize ) );
finally
//IdTCPClient1.IOHandler.WriteBufferClose;
end;
Bytes:=Bytes+aDataSize;
BytesLbl.Caption:=Format ('%u',[Bytes]);
UpDate;
end;
//receiving end
procedure TRecvFrm.IdTCPServer1Execute(AContext: TIdContext);
var
Ms : TMemoryStream;
//Ms : TStream;
begin
Ms := TMemoryStream.Create;
AContext.Connection.IOHandler.ReadStream(Ms);
Ms.Position := 0;
ACMOut1.PlayBack(Ms);
Bytes:=Bytes+Ms.Size;
BytesLbl.Caption:=Format ('%u',[Bytes]);
UpDate;
Ms.Free;
end;
Still not working well for me. I am using indy 10
Have a look at: https://code.google.com/p/siapen/[^]
You'll find VFrames.pas[^] if you dig into the code.
[Update]
1. Get raw data from ACM
2. Write the data to a MemoryStream
3. Send the MemoryStream using Indy.
Somthing similar to this:
with Owner.PeerThread.Connection do begin if Connected then begin OpenWriteBuffer; try WriteStream(memoryStream,True,True,LStreamPacket.Size); finally CloseWriteBuffer; end; end; end;
Best regards
Espen Harlinn
Ok i finally made it work with indy tcp
if not InputBufferIsEmpty then begin Ms := TMemoryStream.Create; InputBuffer.ExtractToStream(Ms); Ms.Position := 0; ACMOut1.PlayBack(Ms); Bytes:=Bytes+Ms.Size; BytesLbl.Caption:=Format ('%u',[Bytes]); UpDate; Ms.Free; end;
这篇关于在tcp indy中发送音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!