Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Wave audio component live stream problem using indy 10 (https://www.delphipraxis.net/180896-wave-audio-component-live-stream-problem-using-indy-10-a.html)

drama22 29. Jun 2014 08:15

Wave audio component live stream problem using indy 10
 
iam using indy10 Udp client and server

i have problem with send buffer from the client to the server here is my code
Delphi-Quellcode:
procedure TForm1.recorderData(Sender: TObject; const Buffer: Pointer;
  BufferSize: Cardinal; var FreeIt: Boolean);
begin
Freeit :=True;
if sendtocl.active then
sendtocl.SendBuffer(RawToBytes(Buffer^, Buffersize))
else
micstop.Caption := 'busy';
end;
server on read

Delphi-Quellcode:
procedure TForm1.UDPReceiverUDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle);
var
  AudioDataSize: Integer;
  AudioData : Pointer;
begin
  try
    EnterCriticalSection(Section);
    try
      AudioDataSize := Length(AData);
      if AudioDataSize > 10 then
      begin
        try
          if not Player.Active then
          begin
            Player.Active := True;
            Player.WaitForStart;
          end;
        except
        end;
        if BlockAlign > 1 then Dec(AudioDataSize, AudioDataSize mod BlockAlign);
        AudioData := AudioBuffer.BeginUpdate(AudioDataSize);
        try
          BytesToRaw(AData, AudioData^, AudioDataSize);
        finally
          AudioBuffer.EndUpdate;
        end;
      end else
      begin
        Player.Active := False;
        Player.WaitForStop;
      end;
    finally
      LeaveCriticalSection(Section);
    end;
  except
  end;
end;
also iam trying to debug the project

i got
Delphi-Quellcode:
Erroneous_Type
on
Delphi-Quellcode:
Sendbuffer
and
Delphi-Quellcode:
RawToBytes
any help would suggested ?

Medium 2. Jul 2014 09:01

AW: Wave audio component live stream problem using indy 10
 
Ah, here we are! Okay, the same as in your other thread still applies here: We miss information. The implementation of RawToBytes() would be crucial for us to be able to help you, since there appears to be a mismatch of types in both, it's parameters and the type it returns (if fed back into SendBuffer). In fact, just the function header would be enough, but the whole thing would be good to assess if it's better to convert your parameters or change the converter function to accommodate your data.

drama22 2. Jul 2014 23:14

AW: Wave audio component live stream problem using indy 10
 
Zitat:

Zitat von Medium (Beitrag 1264040)
Ah, here we are! Okay, the same as in your other thread still applies here: We miss information. The implementation of RawToBytes() would be crucial for us to be able to help you, since there appears to be a mismatch of types in both, it's parameters and the type it returns (if fed back into SendBuffer). In fact, just the function header would be enough, but the whole thing would be good to assess if it's better to convert your parameters or change the converter function to accommodate your data.

i debug the project and i found the problem on that line
Delphi-Quellcode:
sendtocl.SendBuffer(setserver.server, Port.UdpPort, RawToBytes(Buffer^, Buffersize))
started from
Delphi-Quellcode:
Sendbuffer
i checked the type of each feild it come like this
Delphi-Quellcode:
Buffersize parameter = system,cardinal buffer const parameter = system.pointer rawtobytes field = erroneous_type also sendbuffer the same , sendtocl field = Unit1.Form1.TIdUDPClient
if there any example on how to do this i will appreciate that ,, here is my full sorce code in advanced to get more help

Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvGlowButton, Vcl.StdCtrls, HTMListB,
  Vcl.ExtCtrls, mmSystem, WaveUtils, WaveStorage, WaveOut, WavePlayers, WaveIO,
  WaveIn, WaveRecorders, IdSocketHandle, IdBaseComponent, IdComponent,
  IdUDPBase, IdUDPServer, Vcl.Menus, Vcl.ComCtrls, IdGlobal, IdUDPClient,
  PictureContainer, Vcl.ImgList, Unit2;

  const
  WAVE_FORMAT_GSM610 = $0031;

    type
    PGSM610WaveFormat = ^TGSM610WaveFormat;
    TGSM610WaveFormat = record
    wfx: TWaveFormatEx;
    wSamplesPerBlock: Word;
    end;

type
  TAudioBuffer = class
  private
    CS: RTL_CRITICAL_SECTION;
    Data: Pointer;
    Size: Cardinal;
  public
    EnterCritial : Boolean;
    constructor Create;
    destructor Destroy; override;
    procedure Clear;
    function BeginUpdate(ExtraSize: Cardinal): Pointer;
    procedure EndUpdate;
    function Get(out Buffer: Pointer; out BufferSize: Cardinal): Boolean;
  end;

type
  TForm1 = class(TForm)
    micbutton: TAdvGlowButton;
    usertype: TMemo;
    listusers: THTMListBox;
    onmic: THTMListBox;
    recorder: TLiveAudioRecorder;
    player: TLiveAudioPlayer;
    UDPReceiver: TIdUDPServer;
    chatboxmsg: TMemo;
    Send: TAdvGlowButton;
    mictest: TPopupMenu;
    estmicrophone1: TMenuItem;
    adminsendmenu: TPopupMenu;
    SendToall1: TMenuItem;
    Sendtoadmins1: TMenuItem;
    pbLevel: TProgressBar;
    sendtocl: TIdUDPClient;
    micstop: TAdvGlowButton;
    camerabtn: TAdvGlowButton;
    usedimg: TImageList;
    Smilebtn: TAdvGlowButton;
    fontbtn: TAdvGlowButton;
    Panel1: TPanel;
    addoabout: TImage;
    Panel2: TPanel;


    procedure playerError(Sender: TObject);
    procedure recorderData(Sender: TObject; const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);
    procedure estmicrophone1Click(Sender: TObject);
    procedure recorderLevel(Sender: TObject; Level: Integer);
    procedure SendClick(Sender: TObject);
    procedure usertypeKeyPress(Sender: TObject; var Key: Char);
    procedure recorderActivate(Sender: TObject);
    procedure recorderDeactivate(Sender: TObject);
    procedure micstopClick(Sender: TObject);
    procedure addoaboutClick(Sender: TObject);
    function playerDataPtr(Sender: TObject; var Buffer: Pointer;
      var NumLoops: Cardinal; var FreeIt: Boolean): Cardinal;
    procedure playerFormat(Sender: TObject; var pWaveFormat: PWaveFormatEx;
      var FreeIt: Boolean);
    procedure playerLevel(Sender: TObject; Level: Integer);
    procedure UDPReceiverUDPRead(AThread: TIdUDPListenerThread;
      const AData: TIdBytes; ABinding: TIdSocketHandle);
    procedure micbuttonClick(Sender: TObject);
    procedure recorderFormat(Sender: TObject; var pWaveFormat: PWaveFormatEx;
      var FreeIt: Boolean);
  private
    AudioLevel: Integer;
    AudioBuffer : TAudioBuffer;
    BlockAlign : Integer;

  end;

var
  Form1: TForm1;
  Section : TRTLCriticalSection;

implementation

{$R *.dfm}

{ TAudioBuffers }

constructor TAudioBuffer.Create;
begin
  InitializeCriticalSection(CS);
end;

destructor TAudioBuffer.Destroy;
begin
  Clear;
  DeleteCriticalSection(CS);
  inherited Destroy;
end;

procedure TAudioBuffer.Clear;
begin
  EnterCriticalSection(CS);
  try
    ReallocMem(Data, 0);
    Size := 0;
  finally
    LeaveCriticalSection(CS);
  end;
end;

function TAudioBuffer.BeginUpdate(ExtraSize: Cardinal): Pointer;
begin
  EnterCriticalSection(CS);
  EnterCritial := True;
  ReallocMem(Data, Size + ExtraSize);
  Result := Pointer(Cardinal(Data) + Size);
  Inc(Size, ExtraSize);
end;

procedure TAudioBuffer.EndUpdate;
begin
  LeaveCriticalSection(CS);
  EnterCritial := False;
end;

function TAudioBuffer.Get(out Buffer: Pointer; out BufferSize: Cardinal): Boolean;
begin
  EnterCriticalSection(CS);
  try
    Result := False;
    if Assigned(Data) then
    begin
      Buffer := Data;
      BufferSize := Size;
      Data := nil;
      Size := 0;
      Result := True;
    end;
  finally
    LeaveCriticalSection(CS);
  end;
end;

procedure TForm1.addoaboutClick(Sender: TObject);
begin
Aboutus.FormStyle := fsStayOnTop;
Aboutus.Show;
end;

procedure TForm1.estmicrophone1Click(Sender: TObject);
begin
  estmicrophone1.Checked := True;
end;

procedure TForm1.micbuttonClick(Sender: TObject);
begin
recorder.Active := True;
end;

procedure TForm1.micstopClick(Sender: TObject);
begin
recorder.Active := False;
end;

function TForm1.playerDataPtr(Sender: TObject; var Buffer: Pointer;
  var NumLoops: Cardinal; var FreeIt: Boolean): Cardinal;
begin
  try
    if AudioBuffer.Get(Buffer, Result) then
      FreeIt := True
    else
    begin
      Buffer := nil; // When Buffer is nil,
      Result := 1000;  // Result will be considered as silence milliseconds.
    end
  except
    Result := 1000;
  end;
end;

procedure TForm1.playerError(Sender: TObject);
begin
player.Active := False;
end;

procedure TForm1.playerFormat(Sender: TObject; var pWaveFormat: PWaveFormatEx;
  var FreeIt: Boolean);
var
  GSM610: PGSM610WaveFormat;
begin
  GetMem(GSM610, SizeOf(TGSM610WaveFormat));
  GSM610^.wfx.wFormatTag := WAVE_FORMAT_GSM610;
  GSM610^.wfx.nChannels := 1;
  GSM610^.wfx.nSamplesPerSec := 44100;
  GSM610^.wfx.nAvgBytesPerSec := 8957; { 8000 / 320 * 65 }
  GSM610^.wfx.nBlockAlign := 65;
  GSM610^.wfx.wBitsPerSample := 0;
  GSM610^.wfx.cbSize := 2;
  GSM610^.wSamplesPerBlock := 320;
  pWaveFormat := PWaveFormatEx(GSM610);
  BlockAlign := pWaveFormat^.nBlockAlign;
  FreeIt := True;
end;

procedure TForm1.playerLevel(Sender: TObject; Level: Integer);
begin
pbLevel.Position := Level;
end;

procedure TForm1.recorderActivate(Sender: TObject);
begin
micstop.Visible := True;
micbutton.Visible := False;
end;

procedure TForm1.recorderData(Sender: TObject; const Buffer: Pointer;
  BufferSize: Cardinal; var FreeIt: Boolean);
begin
Freeit :=True;
if sendtocl.active then
sendtocl.SendBuffer('192.168.1.100',12000, RawToBytes(Buffer^, Buffersize))
else
micstop.Caption := 'You are not connected';
end;

procedure TForm1.recorderDeactivate(Sender: TObject);
begin
  micbutton.Visible := True;
  micstop.Visible := False;
end;

procedure TForm1.recorderFormat(Sender: TObject; var pWaveFormat: PWaveFormatEx;
  var FreeIt: Boolean);
begin
FreeIt := True;
end;

procedure TForm1.recorderLevel(Sender: TObject; Level: Integer);
begin
  AudioLevel := Level;
  pbLevel.Position := Level;
end;

procedure TForm1.SendClick(Sender: TObject);
begin
sendtocl.Broadcast(usertype.Text, 12000);
usertype.Clear;
end;

procedure TForm1.UDPReceiverUDPRead(AThread: TIdUDPListenerThread; const AData: TIdBytes; ABinding: TIdSocketHandle);
var
  AudioDataSize: Integer;
  AudioData : Pointer;
begin
  try
    EnterCriticalSection(Section);
    try
      AudioDataSize := Length(AData);
      if AudioDataSize > 10 then
      begin
        try
          if not Player.Active then
          begin
            Player.Active := True;
            Player.WaitForStart;
          end;
        except
        end;
        if BlockAlign > 1 then Dec(AudioDataSize, AudioDataSize mod BlockAlign);
        AudioData := AudioBuffer.BeginUpdate(AudioDataSize);
        try
          BytesToRaw(AData, AudioData^, AudioDataSize);
        finally
          AudioBuffer.EndUpdate;
        end;
      end else
      begin
        Player.Active := False;
        Player.WaitForStop;
      end;
    finally
      LeaveCriticalSection(Section);
    end;
  except
  end;
end;

procedure TForm1.usertypeKeyPress(Sender: TObject; var Key: Char);
begin
if Key=chr(13) then SendClick(Self);
if Key = #13 then
Key := #0;
end;

end.

Medium 3. Jul 2014 01:23

AW: Wave audio component live stream problem using indy 10
 
Zitat:

Zitat von drama22 (Beitrag 1264177)
Delphi-Quellcode:
buffer const parameter = system.pointer

You call the function like this:
Delphi-Quellcode:
RawToBytes(Buffer^, Buffersize)
. The "^" after a pointer dereferences it, but the function does expect a plain pointer. You would just have to not dereference it:
Delphi-Quellcode:
RawToBytes(Buffer, Buffersize)
As for the returning type, we still do not see the proper signature of the function. It seems to be in one of your used units, but not in the one you pasted here. If those units came with source, just make a Ctrl-Click on the function name, and the IDE should take you straight to that function's header. If you could paste that line, it would probably help a lot. If it came without source, you'd have to rely on the accompanying documentation for a proper parameter list.

drama22 3. Jul 2014 02:46

AW: Wave audio component live stream problem using indy 10
 
SendBuffer unit procedure

Delphi-Quellcode:
procedure TIdUDPClient.SendBuffer(const AHost: string; const APort: TIdPort;
  const ABuffer: TIdBytes);
begin
  if UseProxy then begin
    if not FProxyOpened then begin
      RaiseUseProxyError;
    end;
    FTransparentProxy.SendToUDP(Binding, AHost, APort, IPVersion, ABuffer);
  end else begin
    inherited SendBuffer(AHost, APort, ABuffer);
  end;
end;
Rawtobytes function
Delphi-Quellcode:
{$IFNDEF DOTNET}
function RawToBytes(const AValue; const ASize: Integer): TIdBytes;
{$IFDEF USE_INLINE}inline;{$ENDIF}
begin
  SetLength(Result, ASize);
  if ASize > 0 then begin
    Move(AValue, Result[0], ASize);
  end;
end;
{$ENDIF}
Buffer^
Delphi-Quellcode:
procedure recorderData(Sender: TObject; const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);


Buffersize

Delphi-Quellcode:
 procedure recorderData(Sender: TObject; const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);

drama22 15. Jul 2014 01:50

AW: Wave audio component live stream problem using indy 10
 
spend days try to fix it but i fail ,, this thread maybe closed or uneeded .


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:25 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz