⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unavcide.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    }
    function getFormatExchangeData(out data: pointer): unsigned; override;
  public
    {DP:METHOD
      Creates Riff wave device.
    }
    procedure AfterConstruction(); override;
    {DP:METHOD
      Loads data from specified WAV file.
      If asynchronous = false (default), does not return until whole file is loaded, and closes the device after that.
      Otherwise returns immediately after opening the device.
      If autoCloseOnDone property is true (default) device will be closed automatically when reading from file is complete.
      Otherwise use onStreamIsDone() event to be notified when reading from file is complete.
      <BR>This function sets realTime property to false and isInput property to true.
    }
    function loadFromFile(const fileName: string; asynchronous: bool = false): bool;
    {DP:METHOD
      Saves data into specified WAV file.
      If asynchronous = false (default), does not return until whole data block is written, and closes the device after that.
      Otherwise returns immediately after opening the device and writing the data into it.
      Use the following code to verify if writing is complete: <CODE>if (waveStream.getDataAvailable(true) > chunkSize) then ...</CODE>
      <BR>This function sets realTime and isInput properties to false.
    }
    function saveToFile(const fileName: string; data: pointer; size: unsigned; asynchronous: bool = false): bool;
    //
    {DP:METHOD
      Returns Riff wave device.
    }
    property waveStream: unaRiffStream read getRiff;
  published
    //
    {DP:METHOD
      Specifies whether reading and writing should be done in real time.
    }
    property realTime;
    {DP:METHOD
      Specifies whether reading should continue from the start upon reaching the end of file.
    }
    property loop;
    {DP:METHOD
      WaveWriter usually does not use the format tag provided by other PCM devices.
    }
    property formatTagImmunable default true;
    {DP:METHOD
      Use this property to specify wave format of non-PCM WAVe files you wish to create.
    }
    property formatTag;
    property calcVolume;
    //
    {DP:METHOD
      Specifies whether Riff wave device is used for reading or writing the audio.
    }
    property isInput: bool read f_isInput write setIsInput default true;
    {DP:METHOD
      Specifies file to use with Riff wave device.
    }
    property fileName: string read f_fileName write setFileName;
    {DP:METHOD
      When true, closes the device automatically when reading from file is complete.
    }
    property autoCloseOnDone: bool read f_acod write f_acod default true;
    {DP:METHOD
      Specifies whether the component would produce or accept any data.
    }
    property enableDataProcessing;
    {DP:METHOD
      Specifies how component should detect silence.
    }
    property silenceDetectionMode;
    {DP:METHOD
      Fired when reading from file is complete.
      Never fired if loop property is set to true.
    }
    property onStreamIsDone: unaOnRiffStreamIsDone read f_onStreamIsDone write f_onStreamIsDone;
  end;


  //
  // -- TunavclWaveMixer --
  //

  {DP:CLASS
    <P /><I>Purpose</I>: mixes two or more PCM audio streams. No ACM codecs are used by this component.
    <P /><I>Usage</I>: If components has no provider component with formatProvider=true, specify PCM stream parameters before activating: set pcm_SamplesPerSec, pcm_BitsPerSample and pcm_NumChannels to specify the audio format parameters.
    Set realTime to true if you wish the mixing to be made in real time manner.
    This component will mix as many streams as it has providers.
    Provider is any VC component, which has consumer property set to mixer component.
    Alternatively you can use addStream() and removeStream() method to add and remove streams (see Example B below).
    <P /><I>Example A</I>: c_mixer_client and c_mixer_server components are used in vcNetTalk demo to mix PCM streams coming from live recording device and WAVe file stored on disk.
    <P /><I>Example B</I>: mixer is used in vcPulseGen demo to mix unlimited number of sine waves. Refer to demo sources for details.
  }
  TunavclWaveMixer = class(unavclInOutWavePipe)
  private
    f_providerStreams: unaList;
    //
    function getMixer(): unaWaveMixerDevice;
    function getStream(provider: unavclInOutPipe): unaAbstractStream;
    procedure setStream(provider: unavclInOutPipe; stream: unaAbstractStream);
    //
  protected
    procedure doSetAddSilence(value: bool); override;
    //
    {DP:METHOD
      Writes data into mixer.
    }
    function doWrite(data: pointer; len: unsigned; provider: unavclInOutPipe = nil): int; override;
    {DP:METHOD
      Creates PCM wave mixer device.
    }
    procedure createNewDevice(); override;
    {DP:METHOD
      Applies audio stream format on PCM wave mixer device.
    }
    function applyDeviceFormat(const format: WAVEFORMATEX; isSrc: bool = true): bool; override;
    {DP:METHOD
    }
    function doAddProvider(provider: unavclInOutPipe): bool; override;
    {DP:METHOD
    }
    procedure doRemoveProvider(provider: unavclInOutPipe); override;
  public
    {DP:METHOD
    }
    procedure AfterConstruction(); override;
    {DP:METHOD
    }
    procedure BeforeDestruction(); override;
    {DP:METHOD
      Returns PCM wave mixer device class instance.
    }
    property mixer: unaWaveMixerDevice read getMixer;
  published
    property addSilence;
    property realTime;
    property calcVolume;
    {DP:METHOD
      Specifies whether the component would perform any data mixing.
    }
    property enableDataProcessing;
    {DP:METHOD
      Specifies how component should detect silence.
    }
    property silenceDetectionMode;
  end;


  //
  // -- TunavclWaveResampler --
  //

  {DP:CLASS
    <P /><I>Purpose</I>: audio stream conversion from one PCM format to another. No ACM codecs are used by this component.
    <P /><I>Usage</I>: If components has no provider component with formatProvider=true, specify PCM stream parameters before activating: set pcm_SamplesPerSec, pcm_BitsPerSample and pcm_NumChannels to specify the source format parameters.
    Set dst_SamplesPerSec, dst_BitsPerSample and dst_NumChannels properties to specify the destination stream format parameters.
    Set realTime to true if you wish the resampling to be made in real time manner.
    <P /><I>Example</I>: c_resampler_client and c_resampler_server components are used in vcNetTalk demo for resampling the streams produced by WAV-reading components to PCM parameters required by mixers.
  }
  TunavclWaveResampler = class(unavclInOutWavePipe)
  private
    f_dstFormat: WAVEFORMATEX;
    //
    function getResampler(): unaWaveResampler;
    function getDstSamplingParam(index: int): unsigned;
    procedure setDstSamplingParam(index: int; value: unsigned);
    function getDstFormat(): pWAVEFORMATEX;
    procedure setDstFormat(value: pWAVEFORMATEX);
  protected
    {DP:METHOD
      Creates PCM wave resampler device.
    }
    procedure createNewDevice(); override;
    {DP:METHOD
      Applies new audio format for PCM wave resampler device.
    }
    function applyDeviceFormat(const format: WAVEFORMATEX; isSrc: bool = true): bool; override;
    {}
    function getFormatExchangeData(out data: pointer): unsigned; override;
  public
    {DP:METHOD
    }
    procedure AfterConstruction(); override;
    {DP:METHOD
      Returns PCM resampler device.
    }
    property resampler: unaWaveResampler read getResampler;
    {DP:METHOD
      Specifies destination PCM format of resampler device.
    }
    property dstFormat: pWAVEFORMATEX read getDstFormat write setDstFormat;
  published
    //
    property addSilence;
    property realTime;
    property calcVolume;
    //
    {DP:METHOD
      Specifies number of sampler per second for destination PCM format of resampler device.
    }
    property dst_SamplesPerSec: unsigned index 0 read getDstSamplingParam write setDstSamplingParam default c_defSamplingSamplesPerSec;
    {DP:METHOD
      Specifies number of bits per sample for destination PCM format of resampler device.
    }
    property dst_BitsPerSample: unsigned index 1 read getDstSamplingParam write setDstSamplingParam default c_defSamplingBitsPerSample;
    {DP:METHOD
      Specifies number of channels per sample for destination PCM format of resampler device.
    }
    property dst_NumChannels: unsigned index 2 read getDstSamplingParam write setDstSamplingParam default c_defSamplingNumChannels;
    {DP:METHOD
      Specifies whether the component would perform any data modifications.
    }
    property enableDataProcessing;
    {DP:METHOD
      Specifies how component should detect silence.
    }
    property silenceDetectionMode;
  end;


// ---------------------
//  -- IP components --
// ---------------------

const
  cmd_inOutIPPacket_hello	= $01;
  cmd_inOutIPPacket_bye		= $02;
  cmd_inOutIPPacket_outOfSeats	= $03;
  //
  cmd_inOutIPPacket_formatAudio	= $10;
  cmd_inOutIPPacket_formatVideo	= $11;
  //
  cmd_inOutIPPacket_audio	= $20;
  cmd_inOutIPPacket_video	= $21;
  cmd_inOutIPPacket_text	= $22;
  cmd_inOutIPPacket_userData	= $23;


type
  //
  // -- unavclInOutIPPacket --
  //
  punavclInOutIPPacket = ^unavclInOutIPPacket;
  unavclInOutIPPacket = packed record
    //
    r_command: byte;
    r_crc16: word;
    r_seqNum: word;
    r_curLast: byte;
    r_dataSize: word;
    r_data: record end;
  end;


  //
  // --  --
  tunavclProtoType = (unapt_TCP, unapt_UDP);


  //
  // --  --
  tunavclStreamingMode = (unasm_VC, unasm_RAW);

  //
  tsendResult = unsigned;

  //
  // --  --
  tunavclTextDataEvent = procedure (sender: tObject; connectionId: unsigned; const data: string) of object;
  tunavclUserDataEvent = procedure (sender: tObject; connectionId: unsigned; data: pointer; len: unsigned) of object;
  tunavclPacketEvent = procedure (sender: tObject; connectionId: unsigned; const packet: unavclInOutIPPacket) of object;
  tunavclSocketEvent = procedure (sender: tObject; connectionId: unsigned; event: unaSocketEvent; data: pointer; len: unsigned) of object;


  //
  // -- unavclInOutIpPipe --
  //

  {DP:CLASS
    Base abstract class for TCP/IP stream devices.
  }
  unavclInOutIpPipe = class(unavclInOutPipe)
  private
    f_socksId: unsigned;
    f_errorCode: unsigned;
    f_host: string;
    f_port: string;
    f_proto: tunavclProtoType;
    f_bindToIP: string;
    f_bindToPort: string;
    //
    // --  --
    f_localFormat: punavclWavePipeFormatExchange;
    f_localFormatSize: unsigned;
    f_remoteFormat: punavclWavePipeFormatExchange;
    f_remoteFormatSize: unsigned;
    //
{$IFDEF PACKET_TCP_DELAY_EMULATE }
    f_windowFillSize: unsigned;
{$ENDIF}
    f_crcErrors: unsigned;
    f_dupCount: unsigned;
    f_outOfSeq: unsigned;
    //
    f_insideOnPacket: bool;
    //
    f_packetSendGate: unaInProcessGate;
    f_packetToSendData: punavclInOutIPPacket;
    f_packetToSendSize: unsigned;
    //
    f_inPacketsCount: int64;
    f_outPacketsCount: int64;
    f_bytesSent: int64;
    f_bytesReceived: int64;
    f_streamingMode: tunavclStreamingMode;
    //
    f_socks: unaSocks;
    f_sockOpComplete: unaEvent;
    //
    f_onTextData: tunavclTextDataEvent;
    f_onUserData: tunavclUserDataEvent;
    f_onPacketEvent: tunavclPacketEvent;
    f_onSocketEvent: tunavclSocketEvent;
    f_onDataSent: tunavclUserDataEvent;
    //
    function getProto(): unsigned;
    procedure sendFormat(connId: unsigned);
    procedure adjustSocketOption(id, connId: unsigned);
    //
    function sendPacketToSocket(connId, seqNum, cmd: unsigned; data: pointer = nil; len: unsigned = 0): tsendResult;
  protected
    {DP:METHOD
      Sends a packet to remote side.
    }
    function doSendPacket(connId: unsigned; cmd: unsigned; data: pointer = nil; len: unsigned = 0): tsendResult; virtual; abstract;
    {DP:METHOD
      Fired by underlying socket provider.
      See also handleSocketEvent().
    }
    procedure doOnSocketEvent(sender: tObject; event: unaSocketEvent; id, connId: unsigned; data: pointer; len: unsigned); virtual;
    {DP:METHOD
      Returns active state of the TCP/IP stream.
    }
    function isActive(): bool; override;
    {DP:METHOD
      Should write data into the TCP/IP stream.
    }
    function doWrite(data: pointer; len: unsigned; provider: unavclInOutPipe = nil): int; override;
    {DP:METHOD
      You cannot read from a socket.
      <BR />Use onDataAvailable event or override the onNewData() method to be notified when new data arrives.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -