/* HawkNL cross platform network library Copyright (C) 2000-2001 Phil Frisbie, Jr. (phil@hawksoft.com) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or go to http://www.gnu.org/copyleft/lgpl.html */ #ifndef HAWKVOICE_H #define HAWKVOICE_H #include "nl.h" #ifdef __cplusplus extern "C" { #endif #define HV_MAJOR_VERSION 0 #define HV_MINOR_VERSION 5 #define HV_VERSION_STRING "HawkVoice 0.5 alpha" /* We will use HV or hv to prefix all HawkVoice defines and functions */ #define HV_MAX_NAME_LEN 32 /* max string length (including NULL) for server, game, and player names */ typedef struct { NLlong serverType; /* Type of server */ NLlong maxPlayers; /* Max number of players allowed in this game */ NLlong currentPlayers; /* Current number of players in this game */ NLlong codecs; /* bitmask of supported codecs */ NLbyte *gameName; /* Name of this game/app */ NLlong gameVersion; /* Version number of game */ NLbyte *serverName; /* Name of this server */ NLushort port; /* port number to use, or 0 for default port */ NLbyte *password; /* Password for server */ NLbyte *key; /* string to use to generate encryption key, or NULL for no encryption */ NLlong user1; /* For application use */ NLlong user2; NLlong user3; NLlong user4; } hv_server_t; typedef struct { NLbyte *gameName; /* Name of this game/app */ NLlong gameVersion; /* Version number of game */ NLlong playerID; /* Player ID number, provided by the server */ NLbyte *playerName; /* Name of client */ NLlong codecs; /* bitmask of codecs player will accept */ NLlong user1; /* For application use */ NLlong user2; NLlong user3; NLlong user4; } hv_player_t; /* callback functions */ /* returns NL_TRUE for more, or NL_FALSE to stop enumerating */ typedef NLboolean (NL_CALLBACK *HVenumServersCB)(NLbyte *description, NLint serverType, NLint maxPlayers, NLint currentPlayers, address_t address); typedef NLboolean (NL_CALLBACK *HVenumPlayersCB)(NLint playerID, NLbyte *name); /* returns a code relevant to the event processed */ typedef NLint (NL_CALLBACK *HVeventCB)(NLint event, void *data); #define HV_ALL 0xffff /* send to all clients */ #define HV_SERVER 0 /* send to server */ /* hvEnable, hvDisable */ #define HV_VOICE_PLAYBACK 0x1001 /* enable/disable voice playback, default enabled, incoming voice packets are dropped, and not even decoded */ #define HV_VOICE_RECORD 0x1002 /* enable/disable voice recording/sending, default enabled, outgoing voice packets are not encoded or sent */ /* Server types */ #define HV_PEER_TO_PEER 0x1010 /* The server only provides the addresses of all players */ /* so that each player can send to the others directly */ #define HV_FORWARD_SERVER 0x1020 /* Server forwards or relays received messages to players */ #define HV_MIXING_SERVER 0x1021 /* Server mixes voice streams before resending, very CPU intensive, but lowest bandwidth */ /* Server type modifiers */ #define HV_DEDICATED 0x80000000 /* The server is a dedicated server, there is no player */ /* The basic codecs */ #define HV_2_4K_CODEC 0x0001 /* LPC-10 2.4 Kbps codec */ #define HV_4_5K_CODEC 0x0002 /* LPC 4.5 Kbps codec */ #define HV_13_2K_CODEC 0x0004 /* GSM 13.2 Kbps codec */ #define HV_32K_CODEC 0x0008 /* Intel/DVI ADPCM 32 Kbps codec */ #define HV_64K_CODEC 0x0010 /* G.711 u-law 64 Kbps codec */ /* Alternate codec names */ #define HV_LPC10_CODEC HV_2_4K_CODEC #define HV_LPC_CODEC HV_4_5K_CODEC #define HV_GSM_CODEC HV_13_2K_CODEC #define HV_ADPCM_32_CODEC HV_32K_CODEC #define HV_PCM_64_CODEC HV_64K_CODEC #define HV_G_711_CODEC HV_64K_CODEC /* HV events */ #define HV_NEW_PLAYER 0x1200 /* A new player has joined the game, sends hv_player_t */ #define HV_DEL_PLAYER 0x1201 /* The player has left the game, sends playerID */ #define HV_PACKET 0x1202 /* A sound packet has arrived, sends playerID */ #define HV_ANSWER 0x1203 /* For chat API, the other end has answered the connect */ /* Common API */ NL_EXP NLboolean NL_APIENTRY hvInit(HVeventCB func); NL_EXP void NL_APIENTRY hvShutdown(void); NL_EXP void NL_APIENTRY hvGetMessages(void); /* should be called frequently, every frame or at least 20-30 times per second */ NL_EXP void NL_APIENTRY hvEnable(NLenum name); NL_EXP void NL_APIENTRY hvDisable(NLenum name); NL_EXP NLboolean NL_APIENTRY hvGetBoolean(NLenum name); /* Voice server API */ NL_EXP NLboolean NL_APIENTRY hvServerCreate(hv_server_t *server); /* Starts a new thread to handle server functions */ NL_EXP void NL_APIENTRY hvServerDestroy(void); /* Voice client API */ NL_EXP NLboolean NL_APIENTRY hvCreate(hv_player_t *player); NL_EXP NLboolean NL_APIENTRY hvConnect(address_t *address, NLbyte *password); NL_EXP void NL_APIENTRY hvEnumerateServers(HVenumServersCB func, NLint timeout); NL_EXP void NL_APIENTRY hvEnumeratePlayers(HVenumPlayersCB func, NLint timeout); NL_EXP void NL_APIENTRY hvDisconnect(void); NL_EXP void NL_APIENTRY hvDestroy(void); NL_EXP NLint NL_APIENTRY hvSend(NLshort *buffer, NLint length); /* our sound from our microphone */ NL_EXP NLint NL_APIENTRY hvReceive(NLshort *buffer, NLint length, NLint *player); /* sound stream(s) from server or directly from other players */ NL_EXP NLlong NL_APIENTRY hvGetCodecs(void); /* codecs that the server will accept */ NL_EXP NLboolean NL_APIENTRY hvSetCodec(NLenum codec); /* bitmask of our outgoing codec, can be updated at any time */ NL_EXP void NL_APIENTRY hvSetTarget(NLint target); /* player or group to send to */ /* Voice chat API, also use hvSend and hvReceive for sound packets */ NL_EXP NLboolean NL_APIENTRY hvChatCreate(hv_player_t *player, NLbyte *password); NL_EXP NLboolean NL_APIENTRY hvChatConnect(address_t *address, NLbyte *password); NL_EXP void NL_APIENTRY hvChatDisconnect(void); NL_EXP void NL_APIENTRY hvChatDestroy(void); #ifdef __cplusplus } /* extern "C" */ #endif #endif /* HAWKVOICE_H */