AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Wave audio component live stream problem using indy 10
Thema durchsuchen
Ansicht
Themen-Optionen

Wave audio component live stream problem using indy 10

Ein Thema von drama22 · begonnen am 29. Jun 2014 · letzter Beitrag vom 15. Jul 2014
Antwort Antwort
drama22

Registriert seit: 12. Jan 2013
88 Beiträge
 
#1

Wave audio component live stream problem using indy 10

  Alt 29. Jun 2014, 09:15
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 Erroneous_Type on Sendbuffer and RawToBytes any help would suggested ?
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#2

AW: Wave audio component live stream problem using indy 10

  Alt 2. Jul 2014, 10:01
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.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
drama22

Registriert seit: 12. Jan 2013
88 Beiträge
 
#3

AW: Wave audio component live stream problem using indy 10

  Alt 3. Jul 2014, 00:14
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 sendtocl.SendBuffer(setserver.server, Port.UdpPort, RawToBytes(Buffer^, Buffersize)) started from Sendbuffer i checked the type of each feild it come like this 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.
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#4

AW: Wave audio component live stream problem using indy 10

  Alt 3. Jul 2014, 02:23
buffer const parameter = system.pointer
You call the function like this: 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: 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.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
drama22

Registriert seit: 12. Jan 2013
88 Beiträge
 
#5

AW: Wave audio component live stream problem using indy 10

  Alt 3. Jul 2014, 03:46
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^procedure recorderData(Sender: TObject; const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);

Buffersize

 procedure recorderData(Sender: TObject; const Buffer: Pointer; BufferSize: Cardinal; var FreeIt: Boolean);
  Mit Zitat antworten Zitat
drama22

Registriert seit: 12. Jan 2013
88 Beiträge
 
#6

AW: Wave audio component live stream problem using indy 10

  Alt 15. Jul 2014, 02:50
spend days try to fix it but i fail ,, this thread maybe closed or uneeded .
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:33 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