使用tcp indy10实时音频流

时间:2013-12-29 07:28:02

标签: delphi delphi-7 audio-streaming

来自他们的例子http://www.delphiarea.com/products/delphi-packages/waveaudio/(TLiveAudioRecorder)

//sender
    procedure TMainForm.LiveAudioRecorderData(Sender: TObject;
      const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);
    var
      I: Integer;
    begin
      FreeIt := True;
      for I := tcpServer.Socket.ActiveConnections - 1 downto 0 do
        with tcpServer.Socket.Connections[I] do
          if Data = Self then // the client is ready
            SendBuf(Buffer^, BufferSize);

    end;

如何使用TCP indy10发送音频流? 像Connection.IOHandler.Write(Buffer, 0, true);

这样的东西

1 个答案:

答案 0 :(得分:2)

你可以:

  1. 使用RawToBytes()将缓冲区数据复制到TIdBytes,然后将其传递给TIdIOHandler.Write(TIdBytes)

    Connection.IOHandler.Write(RawToBytes(Buffer^, BufferSize));
    
  2. 使用TIdMemoryBufferStream将缓冲区换成TStream并将其传递给TIdIOHandler.Write(TStream)

    Strm := TIdMemoryBufferStream.Create(Buffer, BufferSize);
    Connection.IOHandler.Write(Strm);
    Strm.Free;