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

📄 unavcide.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      <P />This method always returns 0.
    }
    function doRead(data: pointer; len: unsigned): unsigned; override;
    {DP:METHOD
      <P />This method always returns 0.
    }
    function getAvailableDataLen(index: int): unsigned; override;
    {DP:METHOD
      Sends goodbye command to all underlying connections.
    }
    procedure sendGoodbye(); virtual; abstract;
    {DP:METHOD
      Opens the TCP/IP stream.
    }
    function doOpen(): bool; override;
    {DP:METHOD
      Closes the TCP/IP stream.
    }
    procedure doClose(); override;
    {DP:METHOD
    }
    function doEnter(timeOut: unsigned = 1000): bool; override;
    {DP:METHOD
    }
    procedure doLeave(); override;
    {DP:METHOD
    }
    function getFormatExchangeData(out data: pointer): unsigned; override;
    {DP:METHOD
      Triggers when new packet is available for the TCP/IP stream.
    }
    function onNewPacket(data: pointer; len: unsigned): bool; overload; virtual;
    function onNewPacket(const packet: unavclInOutIPPacket; connId: unsigned): bool; overload; virtual;
    {DP:METHOD
      Initializes the TCP/IP stream socket.
    }
    function initSocket(): unsigned; virtual; abstract;
    {DP:METHOD
      Handles socket event.
    }
    function handleSocketEvent(event: unaSocketEvent; id, connId: unsigned; data: pointer; len: unsigned): bool; virtual;
    //
    {DP:METHOD
      Since IP components sends and receives format from remote side, we should not bother local consumers,
      as it is done in parent's applyFormat(), unless we had received a remote format
    }
    function applyFormat(data: pointer; len: unsigned; provider: unavclInOutPipe = nil; restoreActiveState: bool = false): bool; override;
    {DP:METHOD
      Specifies host name (or IP address) for the client TCP/IP socket.
    }
    property host: string read f_host write f_host;
    {DP:METHOD
      Specifies port name/number to bind to when socket is about to be open (either for listening or for connection).
      Default is '0' which means socket will bind to first available port.
    }
    property bindToPort: string read f_bindToPort write f_bindToPort;
  public
    {DP:METHOD
    }
    procedure AfterConstruction(); override;
    procedure BeforeDestruction(); override;
    {DP:METHOD
      Returns client connection object.
      NOTE! Connection's release() method must be called when connection object is no longer needed.
    }
    function getClientConnection(connectionId: unsigned = $FFFFFFFF): unaSocksConnection;
    {DP:METHOD
    }
    function getErrorCode(): unsigned;
    {DP:METHOD
      Sends a packet into the IP stream.
    }
    function sendPacket(connId: unsigned; cmd: unsigned; data: pointer = nil; len: unsigned = 0): tsendResult;
    {DP:METHOD
      Sends a text into the IP stream.
    }
    function sendText(connId: unsigned; const data: string): tsendResult;
    {DP:METHOD
      Sends user data into the IP stream.
    }
    function sendData(connId: unsigned; data: pointer; len: unsigned): tsendResult;
    {DP:METHOD
      Returns number of packets received.
    }
    property inPacketsCount: int64 read f_inPacketsCount;
    {DP:METHOD
      Returns number of packets sent.
    }
    property outPacketsCount: int64 read f_outPacketsCount;
    {DP:METHOD
    }
    property inPacketsCrcErrors: unsigned read f_crcErrors;
    property inPacketsDupCount: unsigned read f_dupCount;
    property inPacketsOutOfSeq: unsigned read f_outOfSeq;
    //
    property bytesSent: int64 read f_bytesSent;
    property bytesReceived: int64 read f_bytesReceived;
    //
    property socksId: unsigned read f_socksId;
    {DP:METHOD
    }
    property socks: unaSocks read f_socks;
    //
    property localFormat: punavclWavePipeFormatExchange read f_localFormat;
    property remoteFormat: punavclWavePipeFormatExchange read f_remoteFormat;
  published
    //
    {DP:METHOD
      Specifies port number for the client/server TCP/IP socket.
    }
    property port: string read f_port write f_port;
    //
    {DP:METHOD
      Specifies Proto for the TCP/IP socket (TCP or UDP).
    }
    property proto: tunavclProtoType read f_proto write f_proto default unapt_UDP;
    //
    {DP:METHOD
      Specifies IP address to bind to when socket is about to be open (either for listening or for connection).
      Default is '0.0.0.0' which means socket will bind to first available interface.
    }
    property bindTo: string read f_bindToIP write f_bindToIP;
    //
    {DP:METHOD
      Specifies the low-level streaming mode.
    }
    property streamingMode: tunavclStreamingMode read f_streamingMode write f_streamingMode default unasm_VC;
    //
    {DP:METHOD
      Triggers when text data is available.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onTextData: tunavclTextDataEvent read f_onTextData write f_onTextData;
    //
    {DP:METHOD
      Triggers when user data is available.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onUserData: tunavclUserDataEvent read f_onUserData write f_onUserData;
    //
    {DP:METHOD
      Triggers when new packet is available.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onPacketEvent: tunavclPacketEvent read f_onPacketEvent write f_onPacketEvent;
    //
    {DP:METHOD
      Triggers when socket event occurs.
    }
    property onSocketEvent: tunavclSocketEvent read f_onSocketEvent write f_onSocketEvent;
    //
    {DP:METHOD
      Triggers when new portion of data was sent to remote host.
    }
    property onDataSent: tunavclUserDataEvent read f_onDataSent write f_onDataSent;
  end;


  //
  tunavclConnectEvent = procedure (sender: tObject; connectionId: unsigned; connected: bool) of object;


  //
  // -- unavclIPOutStream --
  //

  {DP:CLASS
    <P>IPClient
    <P /><I>Purpose</I>: connects to remote server, sends and receives audio stream over TCP/IP network.
    <P /><I>Usage</I>: set host, proto and port properties to specify the remote host.
    Set active to true or call the open() method to initiate the connection.
    <P /><I>Example</I>: refer to vcTalkNow demo, with ip_client it is possible to send compressed audio stream over network and receive audio stream from remote server for playback.
  }
  TunavclIPOutStream = class(unavclInOutIpPipe)
  private
    f_clientPacketStack: unaThread;	// client packet processor
    f_connId: unsigned;			// client connection Id
    //
    f_isConnected: bool;	// client is connected
    //
    f_onClientConnect: tunavclConnectEvent;
    f_onClientDisconnect: tunavclConnectEvent;
  protected
    {DP:METHOD
      Writes data into the TCP/IP stream to be sent to server.
    }
    function doWrite(data: pointer; len: unsigned; provider: unavclInOutPipe = nil): int; override;
    {DP:METHOD
      Sends a packet to server.
    }
    function doSendPacket(connId: unsigned; cmd: unsigned; data: pointer = nil; len: unsigned = 0): tsendResult; override;
    {DP:METHOD
      Sends goodbye command to server.
    }
    procedure sendGoodbye(); override;
    {DP:METHOD
    }
    function initSocket(): unsigned; override;
    {DP:METHOD
    }
    function handleSocketEvent(event: unaSocketEvent; id, connId: unsigned; data: pointer; len: unsigned): bool; override;
    {DP:METHOD
    }
    function onNewPacket(const packet: unavclInOutIPPacket; connId: unsigned): bool; override;
    {DP:METHOD
      Returns active state of IP Client.
    }
    function isActive(): bool; override;
  public
    procedure AfterConstruction(); override;
    procedure BeforeDestruction(); override;
    //
    {DP:METHOD
      Client socket connection Id.
    }
    property clientConnId: unsigned read f_connId;
    {DP:METHOD
      Returns true if client socket is connected to remote host
    }
    property isConnected: bool read f_isConnected;
  published
    {DP:METHOD
      Local port number client should bind to. 0 means client will let system to select any free port.
    }
    property bindToPort;
    {DP:METHOD
      Remote host number to connect to.
    }
    property host;
    {DP:METHOD
      Triggers when client has been connected to the server.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onClientConnect: tunavclConnectEvent read f_onClientConnect write f_onClientConnect;
    {DP:METHOD
      Triggers when client has been disconnected from the server.
      <BR /><STRONG>NOTE</STRONG>: VCL is NOT multi-threading safe, and you should avoid using VCL routines and classes in this event.
    }
    property onClientDisconnect: tunavclConnectEvent read f_onClientDisconnect write f_onClientDisconnect;
  end;


  //
  // -- conference mode for IPServer --
  //

  unaIpServerConferenceMode = (
			       uipscm_oneToMany		// vc25pro
			       // more to come
			      );

  // --  --
  tunavclAcceptClient = procedure (sender: tObject; connectionId: unsigned; var accept: bool) of object;

{$IFDEF VCX_DEMO }

  {$DEFINE VCX_DEMO_LIMIT_CLIENTS }
  {$DEFINE VCX_DEMO_LIMIT_DATA }
  {$DEFINE UNA_NO_THREAD_PRIORITY }

{$ENDIF}


const

{$IFDEF VCX_DEMO_LIMIT_CLIENTS }

    unavcide_maxDemoClients = 100;

{$ENDIF}

  // client options for IP server

  c_unaIPServer_co_inbound	= $00000001;
  c_unaIPServer_co_outbound	= $00000002;
  //
  c_unaIPServer_co_default	= c_unaIPServer_co_inbound or c_unaIPServer_co_outbound;
  c_unaIPServer_co_invalid	= $80000000;


type

  //
  // -- unavclIPInStream --
  //
  {DP:CLASS
    IPServer
    <P /><I>Purpose</I>: initiates listening socket for clients to connect to. Receives and sends audio stream to/from client.
    <P /><I>Usage</I>: set proto and port properties to specify the socket parameters.
    Set active to true or call the open() method to initiate the server.
    <P /><I>Example</I>: refer to vcTalkNow demo, with ip_server it is possible to accept client connections, receive compressed audio stream and send audio stream over network.
  }
  TunavclIPInStream = class(unavclInOutIpPipe)
  private
    f_confMode: unaIpServerConferenceMode;
{$IFDEF VCX_DEMO_LIMIT_CLIENTS }
    f_clients: array[0..unavcide_maxDemoClients - 1] of unaThread;
    f_clientCount: unsigned;
    f_clientsLock: unaInProcessGate;
{$ELSE}
    f_clients: unaIdList;	// stack of connected clients
{$ENDIF}
    f_maxClients: int;
    f_udpTimeout: unsigned;
    //
    f_onAcceptClient: tunavclAcceptClient;
    f_onServerNewClient: tunavclConnectEvent;
    f_onServerClientDisconnect: tunavclConnectEvent;
    //
    function addNewClient(connId: unsigned): bool;
    procedure removeClient(connId: unsigned);
    procedure writeClientData(connId: unsigned; data: pointer; len: unsigned);
    //
    function getClientCount(): unsigned;
    procedure setMaxClients(value: int);
    function getPSbyConnId(connId: unsigned): unaThread;
    //
    function lockClients(allowEmpty: bool = false; timeout: unsigned = 102): bool;
    procedure unlockClients();
  protected
    {DP:METHOD
      Writes data into the TCP/IP stream to be sent to client(s).
    }
    function doWrite(data: pointer; len: unsigned; provider: unavclInOutPipe = nil): int; override;
    {DP:METHOD
      Sends a packet to specified client.
    }
    function doSendPacket(connId: unsigned; cmd: unsigned; data: pointer = nil; len: unsigned = 0): tsendResult; override;
    {DP:METHOD
      Sends goodbye command to all active clients.
    }
    procedure sendGoodbye(); override;
    {DP:METHOD
    }
    function initSocket(): unsigned; override;
    {DP:METHOD
    }
    function handleSocketEvent(event: unaSocketEvent; id, connId: unsigned; data: pointer; len: unsigned): bool; override;
    {DP:METHOD
    }
    function onNewPacket(const packet: unavclInOutIPPacket; connId: unsigned): bool; override;
    {DP:METHOD
    }
    procedure doAcceptClient(connId: unsigned; var accept: bool); virtual;
    {DP:METHOD

⌨️ 快捷键说明

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