Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
duplex audio over udp
#2
(08-03-2018, 04:08 PM)Madammar Wrote: if 2 or 3 clients send audio at the same time the audio arrived un understandable and have too many cutting i wanted to make it a live conversation with duplex audio but i dont understand where is the problem is is it from idudpserver or from receiver side ?

Well, for one thing, your receiver is synchronizing the entire OnUDPRead event handler, so you may as well have set udprecive.ThreadedEvent=False instead. But more importantly, not everything the event handler is doing needs to be synchronized at all. Do as much processing as you can inside the event handler itself, and synchronize only what is actually needed, like accessing the audio Player.

You might also consider using TThread.Queue() instead of TThread.Synchronize(), so that your event handler is not waiting on the Player on all, so the receiving of UDP packets and the playing of those packets occur in parallel, not in serial.

Try this:

Code:
procedure TForm2.udpreciverUDPRead(AThread: TIdUDPListenerThread;
const AData: TIdBytes; ABinding: TIdSocketHandle);
var
AudioDataSize: Integer;
begin
  AudioDataSize := Length(AData);
  if (AudioDataSize > 10) then
  begin
    if BlockAlign > 1 then
      Dec(AudioDataSize, AudioDataSize mod BlockAlign);

    TThread.Queue(nil,
      procedure
      var
        AudioData : Pointer;
      begin
        try
          if not Player.Active then
          begin
            Player.Active := True;
            Player.WaitForStart;
          end;
        except
        end;

        AudioData := AudioBuffer.BeginUpdate(AudioDataSize);
        try
          BytesToRaw(AData, AudioData^, AudioDataSize);
        finally
          AudioBuffer.EndUpdate;
        end;
      end
    );
  end else
  begin
    TThread.Queue(nil,
      procedure
      begin
        Player.Active := False;
        Player.WaitForStop;
      end
    );
  end;
end;

Reply


Messages In This Thread
duplex audio over udp - by Madammar - 08-03-2018, 04:08 PM
RE: duplex audio over udp - by rlebeau - 08-03-2018, 05:37 PM
RE: duplex audio over udp - by Madammar - 08-04-2018, 02:59 PM
RE: duplex audio over udp - by kudzu - 08-05-2018, 04:06 PM
RE: duplex audio over udp - by Madammar - 08-05-2018, 05:54 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)