This commit is contained in:
Andrzej Kapolka 2013-05-15 16:22:47 -07:00
commit cb2acb58e7
19 changed files with 253 additions and 255 deletions

View file

@ -94,7 +94,7 @@ int main(int argc, const char* argv[]) {
sockaddr* agentAddress = new sockaddr; sockaddr* agentAddress = new sockaddr;
// make sure our agent socket is non-blocking // make sure our agent socket is non-blocking
agentList->getAgentSocket().setBlocking(false); agentList->getAgentSocket()->setBlocking(false);
int nextFrame = 0; int nextFrame = 0;
timeval startTime; timeval startTime;
@ -114,10 +114,10 @@ int main(int argc, const char* argv[]) {
if (agentBuffer->getEndOfLastWrite()) { if (agentBuffer->getEndOfLastWrite()) {
if (!agentBuffer->isStarted() if (!agentBuffer->isStarted()
&& agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) { && agentBuffer->diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + JITTER_BUFFER_SAMPLES) {
printf("Held back buffer for agent with ID %d.\n", agent->getAgentId()); printf("Held back buffer for agent with ID %d.\n", agent->getAgentID());
agentBuffer->setShouldBeAddedToMix(false); agentBuffer->setShouldBeAddedToMix(false);
} else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) { } else if (agentBuffer->diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
printf("Buffer from agent with ID %d starved.\n", agent->getAgentId()); printf("Buffer from agent with ID %d starved.\n", agent->getAgentID());
agentBuffer->setStarted(false); agentBuffer->setStarted(false);
agentBuffer->setShouldBeAddedToMix(false); agentBuffer->setShouldBeAddedToMix(false);
} else { } else {
@ -256,7 +256,7 @@ int main(int argc, const char* argv[]) {
} }
memcpy(clientPacket + 1, clientSamples, sizeof(clientSamples)); memcpy(clientPacket + 1, clientSamples, sizeof(clientSamples));
agentList->getAgentSocket().send(agent->getPublicSocket(), clientPacket, BUFFER_LENGTH_BYTES + 1); agentList->getAgentSocket()->send(agent->getPublicSocket(), clientPacket, BUFFER_LENGTH_BYTES + 1);
} }
// push forward the next output pointers for any audio buffers we used // push forward the next output pointers for any audio buffers we used
@ -274,7 +274,7 @@ int main(int argc, const char* argv[]) {
} }
// pull any new audio data from agents off of the network stack // pull any new audio data from agents off of the network stack
while (agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { while (agentList->getAgentSocket()->receive(agentAddress, packetData, &receivedBytes)) {
if (packetData[0] == PACKET_HEADER_INJECT_AUDIO || packetData[0] == PACKET_HEADER_MICROPHONE_AUDIO) { if (packetData[0] == PACKET_HEADER_INJECT_AUDIO || packetData[0] == PACKET_HEADER_MICROPHONE_AUDIO) {
char agentType = (packetData[0] == PACKET_HEADER_MICROPHONE_AUDIO) char agentType = (packetData[0] == PACKET_HEADER_MICROPHONE_AUDIO)
? AGENT_TYPE_AVATAR ? AGENT_TYPE_AVATAR

View file

@ -37,7 +37,7 @@
const int AVATAR_LISTEN_PORT = 55444; const int AVATAR_LISTEN_PORT = 55444;
unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) { unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *agentToAdd) {
currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); currentPosition += packAgentId(currentPosition, agentToAdd->getAgentID());
AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData(); AvatarData *agentData = (AvatarData *)agentToAdd->getLinkedData();
currentPosition += agentData->getBroadcastData(currentPosition); currentPosition += agentData->getBroadcastData(currentPosition);
@ -72,7 +72,7 @@ int main(int argc, const char* argv[]) {
uint16_t agentID = 0; uint16_t agentID = 0;
while (true) { while (true) {
if (agentList->getAgentSocket().receive(agentAddress, packetData, &receivedBytes)) { if (agentList->getAgentSocket()->receive(agentAddress, packetData, &receivedBytes)) {
switch (packetData[0]) { switch (packetData[0]) {
case PACKET_HEADER_HEAD_DATA: case PACKET_HEADER_HEAD_DATA:
// grab the agent ID from the packet // grab the agent ID from the packet
@ -93,7 +93,7 @@ int main(int argc, const char* argv[]) {
} }
} }
agentList->getAgentSocket().send(agentAddress, broadcastPacket, currentBufferPosition - broadcastPacket); agentList->getAgentSocket()->send(agentAddress, broadcastPacket, currentBufferPosition - broadcastPacket);
break; break;
case PACKET_HEADER_DOMAIN: case PACKET_HEADER_DOMAIN:

View file

@ -50,7 +50,7 @@ int lastActiveCount = 0;
unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) { unsigned char* addAgentToBroadcastPacket(unsigned char* currentPosition, Agent* agentToAdd) {
*currentPosition++ = agentToAdd->getType(); *currentPosition++ = agentToAdd->getType();
currentPosition += packAgentId(currentPosition, agentToAdd->getAgentId()); currentPosition += packAgentId(currentPosition, agentToAdd->getAgentID());
currentPosition += packSocket(currentPosition, agentToAdd->getPublicSocket()); currentPosition += packSocket(currentPosition, agentToAdd->getPublicSocket());
currentPosition += packSocket(currentPosition, agentToAdd->getLocalSocket()); currentPosition += packSocket(currentPosition, agentToAdd->getLocalSocket());
@ -97,7 +97,7 @@ int main(int argc, const char * argv[])
uint16_t packetAgentID = 0; uint16_t packetAgentID = 0;
while (true) { while (true) {
if (agentList->getAgentSocket().receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) && if (agentList->getAgentSocket()->receive((sockaddr *)&agentPublicAddress, packetData, &receivedBytes) &&
(packetData[0] == PACKET_HEADER_DOMAIN_RFD || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) { (packetData[0] == PACKET_HEADER_DOMAIN_RFD || packetData[0] == PACKET_HEADER_DOMAIN_LIST_REQUEST)) {
std::map<char, Agent *> newestSoloAgents; std::map<char, Agent *> newestSoloAgents;
@ -149,7 +149,7 @@ int main(int argc, const char * argv[])
agent->setLastHeardMicrostamp(timeNow); agent->setLastHeardMicrostamp(timeNow);
// grab the ID for this agent so we can send it back with the packet // grab the ID for this agent so we can send it back with the packet
packetAgentID = agent->getAgentId(); packetAgentID = agent->getAgentID();
if (packetData[0] == PACKET_HEADER_DOMAIN_RFD if (packetData[0] == PACKET_HEADER_DOMAIN_RFD
&& memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) { && memchr(SOLO_AGENT_TYPES, agentType, sizeof(SOLO_AGENT_TYPES))) {
@ -169,7 +169,7 @@ int main(int argc, const char * argv[])
currentBufferPos += packAgentId(currentBufferPos, packetAgentID); currentBufferPos += packAgentId(currentBufferPos, packetAgentID);
// send the constructed list back to this agent // send the constructed list back to this agent
agentList->getAgentSocket().send((sockaddr*) &agentPublicAddress, agentList->getAgentSocket()->send((sockaddr*) &agentPublicAddress,
broadcastPacket, broadcastPacket,
(currentBufferPos - startPointer) + 1); (currentBufferPos - startPointer) + 1);
} }

View file

@ -34,7 +34,6 @@ const float EVE_PELVIS_HEIGHT = 0.565925f;
const float AUDIO_INJECT_PROXIMITY = 0.4f; const float AUDIO_INJECT_PROXIMITY = 0.4f;
bool stopReceiveAgentDataThread; bool stopReceiveAgentDataThread;
bool injectAudioThreadRunning = false;
int TEMP_AUDIO_LISTEN_PORT = 55439; int TEMP_AUDIO_LISTEN_PORT = 55439;
UDPSocket audioSocket(TEMP_AUDIO_LISTEN_PORT); UDPSocket audioSocket(TEMP_AUDIO_LISTEN_PORT);
@ -47,7 +46,7 @@ void *receiveAgentData(void *args) {
AgentList* agentList = AgentList::getInstance(); AgentList* agentList = AgentList::getInstance();
while (!::stopReceiveAgentDataThread) { while (!::stopReceiveAgentDataThread) {
if (agentList->getAgentSocket().receive(&senderAddress, incomingPacket, &bytesReceived)) { if (agentList->getAgentSocket()->receive(&senderAddress, incomingPacket, &bytesReceived)) {
switch (incomingPacket[0]) { switch (incomingPacket[0]) {
case PACKET_HEADER_BULK_AVATAR_DATA: case PACKET_HEADER_BULK_AVATAR_DATA:
// this is the positional data for other agents // this is the positional data for other agents
@ -67,29 +66,6 @@ void *receiveAgentData(void *args) {
return NULL; return NULL;
} }
void *injectAudio(void *args) {
::injectAudioThreadRunning = true;
AudioInjector* eveAudioInjector = (AudioInjector *)args;
// look for an audio mixer in our agent list
Agent* audioMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER);
if (audioMixer) {
// until the audio mixer is setup for ping-reply, activate the public socket if it's not active
if (!audioMixer->getActiveSocket()) {
audioMixer->activatePublicSocket();
}
// we have an active audio mixer we can send data to
eveAudioInjector->injectAudio(&::audioSocket, audioMixer->getActiveSocket());
}
::injectAudioThreadRunning = false;
pthread_exit(0);
return NULL;
}
void createAvatarDataForAgent(Agent* agent) { void createAvatarDataForAgent(Agent* agent) {
if (!agent->getLinkedData()) { if (!agent->getLinkedData()) {
agent->setLinkedData(new AvatarData()); agent->setLinkedData(new AvatarData());
@ -138,6 +114,14 @@ int main(int argc, const char* argv[]) {
// lower Eve's volume by setting the attentuation modifier (this is a value out of 255) // lower Eve's volume by setting the attentuation modifier (this is a value out of 255)
eveAudioInjector.setAttenuationModifier(190); eveAudioInjector.setAttenuationModifier(190);
// pass the agentList UDPSocket pointer to the audio injector
eveAudioInjector.setInjectorSocket(agentList->getAgentSocket());
// set the position of the audio injector
float injectorPosition[3];
memcpy(injectorPosition, &eve.getPosition(), sizeof(injectorPosition));
eveAudioInjector.setPosition(injectorPosition);
// register the callback for agent data creation // register the callback for agent data creation
agentList->linkedDataCreateCallback = createAvatarDataForAgent; agentList->linkedDataCreateCallback = createAvatarDataForAgent;
@ -147,8 +131,6 @@ int main(int argc, const char* argv[]) {
timeval thisSend; timeval thisSend;
double numMicrosecondsSleep = 0; double numMicrosecondsSleep = 0;
pthread_t injectAudioThread;
int handStateTimer = 0; int handStateTimer = 0;
while (true) { while (true) {
@ -167,10 +149,10 @@ int main(int argc, const char* argv[]) {
packetPosition += eve.getBroadcastData(packetPosition); packetPosition += eve.getBroadcastData(packetPosition);
// use the UDPSocket instance attached to our agent list to send avatar data to mixer // use the UDPSocket instance attached to our agent list to send avatar data to mixer
agentList->getAgentSocket().send(avatarMixer->getActiveSocket(), broadcastPacket, packetPosition - broadcastPacket); agentList->getAgentSocket()->send(avatarMixer->getActiveSocket(), broadcastPacket, packetPosition - broadcastPacket);
} }
if (!::injectAudioThreadRunning) { if (!eveAudioInjector.isInjectingAudio()) {
// enumerate the other agents to decide if one is close enough that eve should talk // enumerate the other agents to decide if one is close enough that eve should talk
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
AvatarData* avatarData = (AvatarData*) agent->getLinkedData(); AvatarData* avatarData = (AvatarData*) agent->getLinkedData();
@ -180,7 +162,20 @@ int main(int argc, const char* argv[]) {
float squareDistance = glm::dot(tempVector, tempVector); float squareDistance = glm::dot(tempVector, tempVector);
if (squareDistance <= AUDIO_INJECT_PROXIMITY) { if (squareDistance <= AUDIO_INJECT_PROXIMITY) {
pthread_create(&injectAudioThread, NULL, injectAudio, (void*) &eveAudioInjector); // look for an audio mixer in our agent list
Agent* audioMixer = AgentList::getInstance()->soloAgentOfType(AGENT_TYPE_AUDIO_MIXER);
if (audioMixer) {
// until the audio mixer is setup for ping-reply, activate the public socket if it's not active
if (!audioMixer->getActiveSocket()) {
audioMixer->activatePublicSocket();
}
eveAudioInjector.setDestinationSocket(audioMixer->getActiveSocket());
// we have an active audio mixer we can send data to
eveAudioInjector.threadInjectionOfAudio();
}
} }
} }
} }

View file

@ -105,12 +105,15 @@ int main(int argc, char* argv[]) {
mixerSocket.sin_addr.s_addr = inet_addr(EC2_WEST_AUDIO_SERVER); mixerSocket.sin_addr.s_addr = inet_addr(EC2_WEST_AUDIO_SERVER);
mixerSocket.sin_port = htons((uint16_t)AUDIO_UDP_LISTEN_PORT); mixerSocket.sin_port = htons((uint16_t)AUDIO_UDP_LISTEN_PORT);
if (processParameters(argc, argv)) { if (processParameters(argc, argv)) {
if (::sourceAudioFile == NULL) { if (::sourceAudioFile == NULL) {
std::cout << "[FATAL] Source audio file not specified" << std::endl; std::cout << "[FATAL] Source audio file not specified" << std::endl;
exit(-1); exit(-1);
} else { } else {
AudioInjector injector(sourceAudioFile); AudioInjector injector(sourceAudioFile);
injector.setInjectorSocket(&streamSocket);
injector.setDestinationSocket((sockaddr*) &mixerSocket);
injector.setPosition(::floatArguments); injector.setPosition(::floatArguments);
injector.setBearing(*(::floatArguments + 3)); injector.setBearing(*(::floatArguments + 3));
@ -120,7 +123,7 @@ int main(int argc, char* argv[]) {
int usecDelay = 0; int usecDelay = 0;
while (true) { while (true) {
injector.injectAudio(&streamSocket, (sockaddr*) &mixerSocket); injector.injectAudio();
if (!::loopAudio) { if (!::loopAudio) {
delay = randFloatInRange(::sleepIntervalMin, ::sleepIntervalMax); delay = randFloatInRange(::sleepIntervalMin, ::sleepIntervalMax);

Binary file not shown.

BIN
interface/interface.icns Normal file

Binary file not shown.

View file

@ -179,7 +179,7 @@ Application::Application(int& argc, char** argv) :
AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort); AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort);
_enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking"); _enableNetworkThread = !cmdOptionExists(argc, constArgv, "--nonblocking");
if (!_enableNetworkThread) { if (!_enableNetworkThread) {
AgentList::getInstance()->getAgentSocket().setBlocking(false); AgentList::getInstance()->getAgentSocket()->setBlocking(false);
} }
const char* domainIP = getCmdOption(argc, constArgv, "--domain"); const char* domainIP = getCmdOption(argc, constArgv, "--domain");
@ -2025,7 +2025,7 @@ void* Application::networkReceive(void* args) {
app->_wantToKillLocalVoxels = false; app->_wantToKillLocalVoxels = false;
} }
if (AgentList::getInstance()->getAgentSocket().receive(&senderAddress, app->_incomingPacket, &bytesReceived)) { if (AgentList::getInstance()->getAgentSocket()->receive(&senderAddress, app->_incomingPacket, &bytesReceived)) {
app->_packetCount++; app->_packetCount++;
app->_bytesCount += bytesReceived; app->_bytesCount += bytesReceived;

View file

@ -146,7 +146,7 @@ int audioCallback (const void* inputBuffer,
// copy the audio data to the last BUFFER_LENGTH_BYTES bytes of the data packet // copy the audio data to the last BUFFER_LENGTH_BYTES bytes of the data packet
memcpy(currentPacketPtr, inputLeft, BUFFER_LENGTH_BYTES); memcpy(currentPacketPtr, inputLeft, BUFFER_LENGTH_BYTES);
agentList->getAgentSocket().send(audioMixer->getActiveSocket(), dataPacket, BUFFER_LENGTH_BYTES + leadingBytes); agentList->getAgentSocket()->send(audioMixer->getActiveSocket(), dataPacket, BUFFER_LENGTH_BYTES + leadingBytes);
} }
} }

View file

@ -19,7 +19,7 @@ const int PAIRING_SERVER_PORT = 7247;
void PairingHandler::sendPairRequest() { void PairingHandler::sendPairRequest() {
// grab the agent socket from the AgentList singleton // grab the agent socket from the AgentList singleton
UDPSocket *agentSocket = &AgentList::getInstance()->getAgentSocket(); UDPSocket *agentSocket = AgentList::getInstance()->getAgentSocket();
// prepare the pairing request packet // prepare the pairing request packet

View file

@ -32,69 +32,60 @@ int packAgentId(unsigned char *packStore, uint16_t agentId) {
return sizeof(uint16_t); return sizeof(uint16_t);
} }
Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) : Agent::Agent(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t agentID) :
_type(type),
_agentID(agentID),
_wakeMicrostamp(usecTimestampNow()),
_lastHeardMicrostamp(usecTimestampNow()),
_activeSocket(NULL),
_bytesReceivedMovingAverage(NULL),
_linkedData(NULL),
_isAlive(true) _isAlive(true)
{ {
if (agentPublicSocket != NULL) { if (publicSocket) {
publicSocket = new sockaddr; _publicSocket = new sockaddr(*publicSocket);
memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr));
} else { } else {
publicSocket = NULL; _publicSocket = NULL;
} }
if (agentLocalSocket != NULL) { if (localSocket) {
localSocket = new sockaddr; _localSocket = new sockaddr(*localSocket);
memcpy(localSocket, agentLocalSocket, sizeof(sockaddr));
} else { } else {
localSocket = NULL; _localSocket = NULL;
}
} }
type = agentType; Agent::Agent(const Agent &otherAgent) :
agentId = thisAgentId; _type(otherAgent._type),
_agentID(otherAgent._agentID),
_wakeMicrostamp = usecTimestampNow(); _wakeMicrostamp(otherAgent._wakeMicrostamp),
_lastHeardMicrostamp = usecTimestampNow(); _lastHeardMicrostamp(otherAgent._lastHeardMicrostamp),
_isAlive(otherAgent._isAlive)
activeSocket = NULL; {
linkedData = NULL; if (otherAgent._publicSocket) {
_bytesReceivedMovingAverage = NULL; _publicSocket = new sockaddr(*otherAgent._localSocket);
} else {
_publicSocket = NULL;
} }
Agent::Agent(const Agent &otherAgent) { if (otherAgent._localSocket) {
_isAlive = otherAgent._isAlive; _localSocket = new sockaddr(*otherAgent._localSocket);
if (otherAgent.publicSocket != NULL) {
publicSocket = new sockaddr;
memcpy(publicSocket, otherAgent.publicSocket, sizeof(sockaddr));
} else { } else {
publicSocket = NULL; _localSocket = NULL;
} }
if (otherAgent.localSocket != NULL) { if (otherAgent._activeSocket == otherAgent._publicSocket) {
localSocket = new sockaddr; _activeSocket = _publicSocket;
memcpy(localSocket, otherAgent.localSocket, sizeof(sockaddr)); } else if (otherAgent._activeSocket == otherAgent._localSocket) {
_activeSocket = _localSocket;
} else { } else {
localSocket = NULL; _activeSocket = NULL;
} }
agentId = otherAgent.agentId; if (otherAgent._linkedData) {
_linkedData = otherAgent._linkedData->clone();
if (otherAgent.activeSocket == otherAgent.publicSocket) {
activeSocket = publicSocket;
} else if (otherAgent.activeSocket == otherAgent.localSocket) {
activeSocket = localSocket;
} else { } else {
activeSocket = NULL; _linkedData = NULL;
}
_wakeMicrostamp = otherAgent._wakeMicrostamp;
_lastHeardMicrostamp = otherAgent._lastHeardMicrostamp;
type = otherAgent.type;
if (otherAgent.linkedData != NULL) {
linkedData = otherAgent.linkedData->clone();
} else {
linkedData = NULL;
} }
if (otherAgent._bytesReceivedMovingAverage != NULL) { if (otherAgent._bytesReceivedMovingAverage != NULL) {
@ -114,115 +105,69 @@ void Agent::swap(Agent &first, Agent &second) {
using std::swap; using std::swap;
swap(first._isAlive, second._isAlive); swap(first._isAlive, second._isAlive);
swap(first.publicSocket, second.publicSocket); swap(first._publicSocket, second._publicSocket);
swap(first.localSocket, second.localSocket); swap(first._localSocket, second._localSocket);
swap(first.activeSocket, second.activeSocket); swap(first._activeSocket, second._activeSocket);
swap(first.type, second.type); swap(first._type, second._type);
swap(first.linkedData, second.linkedData); swap(first._linkedData, second._linkedData);
swap(first.agentId, second.agentId); swap(first._agentID, second._agentID);
swap(first._wakeMicrostamp, second._wakeMicrostamp); swap(first._wakeMicrostamp, second._wakeMicrostamp);
swap(first._lastHeardMicrostamp, second._lastHeardMicrostamp); swap(first._lastHeardMicrostamp, second._lastHeardMicrostamp);
swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage); swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage);
} }
Agent::~Agent() { Agent::~Agent() {
delete publicSocket; delete _publicSocket;
delete localSocket; delete _localSocket;
delete linkedData; delete _linkedData;
delete _bytesReceivedMovingAverage; delete _bytesReceivedMovingAverage;
} }
char Agent::getType() const {
return type;
}
// Names of Agent Types // Names of Agent Types
const char* AGENT_TYPE_NAME_DOMAIN = "Domain"; const char* AGENT_TYPE_NAME_DOMAIN = "Domain";
const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server"; const char* AGENT_TYPE_NAME_VOXEL = "Voxel Server";
const char* AGENT_TYPE_NAME_INTERFACE = "Client Interface"; const char* AGENT_TYPE_NAME_INTERFACE = "Client Interface";
const char* AGENT_TYPE_NAME_AUDIO_MIXER = "Audio Mixer"; const char* AGENT_TYPE_NAME_AUDIO_MIXER = "Audio Mixer";
const char* AGENT_TYPE_NAME_AVATAR_MIXER = "Avatar Mixer"; const char* AGENT_TYPE_NAME_AVATAR_MIXER = "Avatar Mixer";
const char* AGENT_TYPE_NAME_AUDIO_INJECTOR = "Audio Injector";
const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown"; const char* AGENT_TYPE_NAME_UNKNOWN = "Unknown";
const char* Agent::getTypeName() const { const char* Agent::getTypeName() const {
const char* name = AGENT_TYPE_NAME_UNKNOWN; switch (this->_type) {
switch (this->type) {
case AGENT_TYPE_DOMAIN: case AGENT_TYPE_DOMAIN:
name = AGENT_TYPE_NAME_DOMAIN; return AGENT_TYPE_NAME_DOMAIN;
break;
case AGENT_TYPE_VOXEL: case AGENT_TYPE_VOXEL:
name = AGENT_TYPE_NAME_VOXEL; return AGENT_TYPE_NAME_VOXEL;
break;
case AGENT_TYPE_AVATAR: case AGENT_TYPE_AVATAR:
name = AGENT_TYPE_NAME_INTERFACE; return AGENT_TYPE_NAME_INTERFACE;
break;
case AGENT_TYPE_AUDIO_MIXER: case AGENT_TYPE_AUDIO_MIXER:
name = AGENT_TYPE_NAME_AUDIO_MIXER; return AGENT_TYPE_NAME_AUDIO_MIXER;
break;
case AGENT_TYPE_AVATAR_MIXER: case AGENT_TYPE_AVATAR_MIXER:
name = AGENT_TYPE_NAME_AVATAR_MIXER; return AGENT_TYPE_NAME_AVATAR_MIXER;
break; case AGENT_TYPE_AUDIO_INJECTOR:
return AGENT_TYPE_NAME_AUDIO_INJECTOR;
default:
return AGENT_TYPE_NAME_UNKNOWN;
} }
return name;
}
void Agent::setType(char newType) {
type = newType;
}
uint16_t Agent::getAgentId() {
return agentId;
}
void Agent::setAgentId(uint16_t thisAgentId) {
agentId = thisAgentId;
}
sockaddr* Agent::getPublicSocket() {
return publicSocket;
}
void Agent::setPublicSocket(sockaddr *newSocket) {
publicSocket = newSocket;
}
sockaddr* Agent::getLocalSocket() {
return localSocket;
}
void Agent::setLocalSocket(sockaddr *newSocket) {
publicSocket = newSocket;
}
sockaddr* Agent::getActiveSocket() {
return activeSocket;
} }
void Agent::activateLocalSocket() { void Agent::activateLocalSocket() {
activeSocket = localSocket; _activeSocket = _localSocket;
} }
void Agent::activatePublicSocket() { void Agent::activatePublicSocket() {
activeSocket = publicSocket; _activeSocket = _publicSocket;
}
AgentData* Agent::getLinkedData() {
return linkedData;
}
void Agent::setLinkedData(AgentData *newData) {
linkedData = newData;
} }
bool Agent::operator==(const Agent& otherAgent) { bool Agent::operator==(const Agent& otherAgent) {
return matches(otherAgent.publicSocket, otherAgent.localSocket, otherAgent.type); return matches(otherAgent._publicSocket, otherAgent._localSocket, otherAgent._type);
} }
bool Agent::matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType) { bool Agent::matches(sockaddr *otherPublicSocket, sockaddr *otherLocalSocket, char otherAgentType) {
// checks if two agent objects are the same agent (same type + local + public address) // checks if two agent objects are the same agent (same type + local + public address)
return type == otherAgentType return _type == otherAgentType
&& socketMatch(publicSocket, otherPublicSocket) && socketMatch(_publicSocket, otherPublicSocket)
&& socketMatch(localSocket, otherLocalSocket); && socketMatch(_localSocket, otherLocalSocket);
} }
void Agent::recordBytesReceived(int bytesReceived) { void Agent::recordBytesReceived(int bytesReceived) {
@ -252,15 +197,15 @@ float Agent::getAverageKilobitsPerSecond() {
void Agent::printLog(Agent const& agent) { void Agent::printLog(Agent const& agent) {
char publicAddressBuffer[16] = {'\0'}; char publicAddressBuffer[16] = {'\0'};
unsigned short publicAddressPort = loadBufferWithSocketInfo(publicAddressBuffer, agent.publicSocket); unsigned short publicAddressPort = loadBufferWithSocketInfo(publicAddressBuffer, agent._publicSocket);
//char localAddressBuffer[16] = {'\0'}; //char localAddressBuffer[16] = {'\0'};
//unsigned short localAddressPort = loadBufferWithSocketInfo(localAddressBuffer, agent.localSocket); //unsigned short localAddressPort = loadBufferWithSocketInfo(localAddressBuffer, agent.localSocket);
::printLog("# %d %s (%c) @ %s:%d\n", ::printLog("# %d %s (%c) @ %s:%d\n",
agent.agentId, agent._agentID,
agent.getTypeName(), agent.getTypeName(),
agent.type, agent._type,
publicAddressBuffer, publicAddressBuffer,
publicAddressPort); publicAddressPort);
} }

View file

@ -23,7 +23,7 @@
class Agent { class Agent {
public: public:
Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId); Agent(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t agentID);
Agent(const Agent &otherAgent); Agent(const Agent &otherAgent);
~Agent(); ~Agent();
Agent& operator=(Agent otherAgent); Agent& operator=(Agent otherAgent);
@ -31,12 +31,12 @@ public:
bool matches(sockaddr* otherPublicSocket, sockaddr* otherLocalSocket, char otherAgentType); bool matches(sockaddr* otherPublicSocket, sockaddr* otherLocalSocket, char otherAgentType);
char getType() const; char getType() const { return _type; }
void setType(char type) { _type = type; }
const char* getTypeName() const; const char* getTypeName() const;
void setType(char newType);
uint16_t getAgentId(); uint16_t getAgentID() const { return _agentID; }
void setAgentId(uint16_t thisAgentId); void setAgentID(uint16_t agentID) { _agentID = agentID;}
double getWakeMicrostamp() const { return _wakeMicrostamp; } double getWakeMicrostamp() const { return _wakeMicrostamp; }
void setWakeMicrostamp(double wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } void setWakeMicrostamp(double wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; }
@ -44,17 +44,18 @@ public:
double getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } double getLastHeardMicrostamp() const { return _lastHeardMicrostamp; }
void setLastHeardMicrostamp(double lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } void setLastHeardMicrostamp(double lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; }
sockaddr* getPublicSocket(); sockaddr* getPublicSocket() const { return _publicSocket; }
void setPublicSocket(sockaddr *newSocket); void setPublicSocket(sockaddr* publicSocket) { _publicSocket = publicSocket; }
sockaddr* getLocalSocket(); sockaddr* getLocalSocket() const { return _localSocket; }
void setLocalSocket(sockaddr *newSocket); void setLocalSocket(sockaddr* localSocket) { _localSocket = localSocket; }
sockaddr* getActiveSocket();
sockaddr* getActiveSocket() const { return _activeSocket; }
void activatePublicSocket(); void activatePublicSocket();
void activateLocalSocket(); void activateLocalSocket();
AgentData* getLinkedData(); AgentData* getLinkedData() const { return _linkedData; }
void setLinkedData(AgentData *newData); void setLinkedData(AgentData* linkedData) { _linkedData = linkedData; }
bool isAlive() const { return _isAlive; }; bool isAlive() const { return _isAlive; };
void setAlive(bool isAlive) { _isAlive = isAlive; }; void setAlive(bool isAlive) { _isAlive = isAlive; };
@ -67,13 +68,15 @@ public:
private: private:
void swap(Agent &first, Agent &second); void swap(Agent &first, Agent &second);
sockaddr *publicSocket, *localSocket, *activeSocket; char _type;
char type; uint16_t _agentID;
uint16_t agentId;
double _wakeMicrostamp; double _wakeMicrostamp;
double _lastHeardMicrostamp; double _lastHeardMicrostamp;
sockaddr* _publicSocket;
sockaddr* _localSocket;
sockaddr* _activeSocket;
SimpleMovingAverage* _bytesReceivedMovingAverage; SimpleMovingAverage* _bytesReceivedMovingAverage;
AgentData* linkedData; AgentData* _linkedData;
bool _isAlive; bool _isAlive;
}; };

View file

@ -78,10 +78,6 @@ AgentList::~AgentList() {
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
} }
UDPSocket& AgentList::getAgentSocket() {
return agentSocket;
}
unsigned int AgentList::getSocketListenPort() { unsigned int AgentList::getSocketListenPort() {
return socketListenPort; return socketListenPort;
} }
@ -184,7 +180,7 @@ Agent* AgentList::agentWithAddress(sockaddr *senderAddress) {
Agent* AgentList::agentWithID(uint16_t agentID) { Agent* AgentList::agentWithID(uint16_t agentID) {
for(AgentList::iterator agent = begin(); agent != end(); agent++) { for(AgentList::iterator agent = begin(); agent != end(); agent++) {
if (agent->getAgentId() == agentID) { if (agent->getAgentID() == agentID) {
return &(*agent); return &(*agent);
} }
} }
@ -337,8 +333,8 @@ void *pingUnknownAgents(void *args) {
&& (agent->getPublicSocket() != NULL && agent->getLocalSocket() != NULL)) { && (agent->getPublicSocket() != NULL && agent->getLocalSocket() != NULL)) {
// ping both of the sockets for the agent so we can figure out // ping both of the sockets for the agent so we can figure out
// which socket we can use // which socket we can use
agentList->getAgentSocket().send(agent->getPublicSocket(), &PACKET_HEADER_PING, 1); agentList->getAgentSocket()->send(agent->getPublicSocket(), &PACKET_HEADER_PING, 1);
agentList->getAgentSocket().send(agent->getLocalSocket(), &PACKET_HEADER_PING, 1); agentList->getAgentSocket()->send(agent->getLocalSocket(), &PACKET_HEADER_PING, 1);
} }
} }
@ -433,7 +429,7 @@ void *checkInWithDomainServer(void *args) {
packSocket(packet + 2, localAddress, htons(parentAgentList->getSocketListenPort())); packSocket(packet + 2, localAddress, htons(parentAgentList->getSocketListenPort()));
parentAgentList->getAgentSocket().send(DOMAIN_IP, DOMAINSERVER_PORT, packet, sizeof(packet)); parentAgentList->getAgentSocket()->send(DOMAIN_IP, DOMAINSERVER_PORT, packet, sizeof(packet));
packet[0] = PACKET_HEADER_DOMAIN_LIST_REQUEST; packet[0] = PACKET_HEADER_DOMAIN_LIST_REQUEST;

View file

@ -49,7 +49,7 @@ public:
int size() { return _numAgents; } int size() { return _numAgents; }
UDPSocket& getAgentSocket(); UDPSocket* getAgentSocket() { return &agentSocket; }
void lock() { pthread_mutex_lock(&mutex); } void lock() { pthread_mutex_lock(&mutex); }
void unlock() { pthread_mutex_unlock(&mutex); } void unlock() { pthread_mutex_unlock(&mutex); }

View file

@ -21,30 +21,43 @@ const float SAMPLE_RATE = 22050.0f;
const float BUFFER_SEND_INTERVAL_USECS = (BUFFER_LENGTH_SAMPLES / SAMPLE_RATE) * 1000000; const float BUFFER_SEND_INTERVAL_USECS = (BUFFER_LENGTH_SAMPLES / SAMPLE_RATE) * 1000000;
AudioInjector::AudioInjector(const char* filename) : AudioInjector::AudioInjector(const char* filename) :
_numTotalBytesAudio(0),
_position(), _position(),
_bearing(0), _bearing(0),
_attenuationModifier(255) { _attenuationModifier(255),
_indexOfNextSlot(0),
_isInjectingAudio(false)
{
std::fstream sourceFile; std::fstream sourceFile;
sourceFile.open(filename, std::ios::in | std::ios::binary); sourceFile.open(filename, std::ios::in | std::ios::binary);
sourceFile.seekg(0, std::ios::end); sourceFile.seekg(0, std::ios::end);
_numTotalBytesAudio = sourceFile.tellg(); int totalBytes = sourceFile.tellg();
if (_numTotalBytesAudio == -1) { if (totalBytes == -1) {
printf("Error reading audio data from file %s\n", filename); printf("Error reading audio data from file %s\n", filename);
_audioSampleArray = NULL; _audioSampleArray = NULL;
} else { } else {
printf("Read %d bytes from audio file\n", _numTotalBytesAudio); printf("Read %d bytes from audio file\n", totalBytes);
sourceFile.seekg(0, std::ios::beg); sourceFile.seekg(0, std::ios::beg);
long sizeOfShortArray = _numTotalBytesAudio / 2; _numTotalSamples = totalBytes / 2;
_audioSampleArray = new int16_t[sizeOfShortArray]; _audioSampleArray = new int16_t[_numTotalSamples];
sourceFile.read((char *)_audioSampleArray, _numTotalBytesAudio); sourceFile.read((char *)_audioSampleArray, _numTotalSamples);
} }
} }
AudioInjector::AudioInjector(int maxNumSamples) :
_numTotalSamples(maxNumSamples),
_position(),
_bearing(0),
_attenuationModifier(255),
_indexOfNextSlot(0),
_isInjectingAudio(false)
{
_audioSampleArray = new int16_t[maxNumSamples];
memset(_audioSampleArray, 0, _numTotalSamples * sizeof(int16_t));
}
AudioInjector::~AudioInjector() { AudioInjector::~AudioInjector() {
delete[] _audioSampleArray; delete[] _audioSampleArray;
} }
@ -55,8 +68,25 @@ void AudioInjector::setPosition(float* position) {
_position[2] = position[2]; _position[2] = position[2];
} }
void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destinationSocket) const { void AudioInjector::addSample(const int16_t sample) {
if (_indexOfNextSlot != _numTotalSamples) {
// only add this sample if we actually have space for it
_audioSampleArray[_indexOfNextSlot++] = sample;
}
}
void AudioInjector::addSamples(int16_t* sampleBuffer, int numSamples) {
if (_audioSampleArray + _indexOfNextSlot + numSamples <= _audioSampleArray + (_numTotalSamples / sizeof(int16_t))) {
// only copy the audio from the sample buffer if there's space
memcpy(_audioSampleArray + _indexOfNextSlot, sampleBuffer, numSamples * sizeof(int16_t));
_indexOfNextSlot += numSamples;
}
}
void AudioInjector::injectAudio() {
if (_audioSampleArray != NULL) { if (_audioSampleArray != NULL) {
_isInjectingAudio = true;
timeval startTime; timeval startTime;
// one byte for header, 3 positional floats, 1 bearing float, 1 attenuation modifier byte // one byte for header, 3 positional floats, 1 bearing float, 1 attenuation modifier byte
@ -77,24 +107,38 @@ void AudioInjector::injectAudio(UDPSocket* injectorSocket, sockaddr* destination
memcpy(currentPacketPtr, &_bearing, sizeof(float)); memcpy(currentPacketPtr, &_bearing, sizeof(float));
currentPacketPtr += sizeof(float); currentPacketPtr += sizeof(float);
for (int i = 0; i < _numTotalBytesAudio; i += BUFFER_LENGTH_BYTES) { for (int i = 0; i < _numTotalSamples; i += BUFFER_LENGTH_SAMPLES) {
gettimeofday(&startTime, NULL); gettimeofday(&startTime, NULL);
int numBytesToCopy = BUFFER_LENGTH_BYTES; int numSamplesToCopy = BUFFER_LENGTH_SAMPLES;
if (_numTotalBytesAudio - i < BUFFER_LENGTH_BYTES) { if (_numTotalSamples - i < BUFFER_LENGTH_SAMPLES) {
numBytesToCopy = _numTotalBytesAudio - i; numSamplesToCopy = _numTotalSamples - i;
memset(currentPacketPtr + numBytesToCopy, 0, BUFFER_LENGTH_BYTES - numBytesToCopy); memset(currentPacketPtr + numSamplesToCopy, 0, BUFFER_LENGTH_BYTES - (numSamplesToCopy * sizeof(int16_t)));
} }
memcpy(currentPacketPtr, _audioSampleArray + (i / 2), numBytesToCopy); memcpy(currentPacketPtr, _audioSampleArray + i, numSamplesToCopy * sizeof(int16_t));
injectorSocket->send(destinationSocket, dataPacket, sizeof(dataPacket)); _injectorSocket->send(&_destinationSocket, dataPacket, sizeof(dataPacket));
double usecToSleep = BUFFER_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&startTime)); double usecToSleep = BUFFER_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&startTime));
if (usecToSleep > 0) { if (usecToSleep > 0) {
usleep(usecToSleep); usleep(usecToSleep);
} }
} }
_isInjectingAudio = false;
} }
} }
void* injectAudioViaThread(void* args) {
AudioInjector* parentInjector = (AudioInjector*) args;
parentInjector->injectAudio();
pthread_exit(0);
}
void AudioInjector::threadInjectionOfAudio() {
pthread_t audioInjectThread;
pthread_create(&audioInjectThread, NULL, injectAudioViaThread, (void*) this);
}

View file

@ -17,19 +17,32 @@
class AudioInjector { class AudioInjector {
public: public:
AudioInjector(const char* filename); AudioInjector(const char* filename);
AudioInjector(int maxNumSamples);
~AudioInjector(); ~AudioInjector();
bool isInjectingAudio() const { return _isInjectingAudio; }
void setPosition(float* position); void setPosition(float* position);
void setBearing(float bearing) { _bearing = bearing; } void setBearing(float bearing) { _bearing = bearing; }
void setAttenuationModifier(unsigned char attenuationModifier) { _attenuationModifier = attenuationModifier; } void setAttenuationModifier(unsigned char attenuationModifier) { _attenuationModifier = attenuationModifier; }
void setInjectorSocket(UDPSocket* injectorSocket) { _injectorSocket = injectorSocket; }
void setDestinationSocket(sockaddr* destinationSocket) { _destinationSocket = *destinationSocket; }
void injectAudio(UDPSocket* injectorSocket, sockaddr* destinationSocket) const; void addSample(const int16_t sample);
void addSamples(int16_t* sampleBuffer, int numSamples);
void injectAudio();
void threadInjectionOfAudio();
private: private:
int16_t* _audioSampleArray; int16_t* _audioSampleArray;
int _numTotalBytesAudio; int _numTotalSamples;
float _position[3]; float _position[3];
float _bearing; float _bearing;
unsigned char _attenuationModifier; unsigned char _attenuationModifier;
int _indexOfNextSlot;
UDPSocket* _injectorSocket;
sockaddr _destinationSocket;
bool _isInjectingAudio;
}; };
#endif /* defined(__hifi__AudioInjector__) */ #endif /* defined(__hifi__AudioInjector__) */

View file

@ -204,13 +204,12 @@ void UDPSocket::setBlocking(bool blocking) {
} }
// Receive data on this socket with retrieving address of sender // Receive data on this socket with retrieving address of sender
bool UDPSocket::receive(void *receivedData, ssize_t *receivedBytes) { bool UDPSocket::receive(void* receivedData, ssize_t* receivedBytes) const {
return receive((sockaddr*) &senderAddress, receivedData, receivedBytes); return receive((sockaddr*) &senderAddress, receivedData, receivedBytes);
} }
// Receive data on this socket with the address of the sender // Receive data on this socket with the address of the sender
bool UDPSocket::receive(sockaddr *recvAddress, void *receivedData, ssize_t *receivedBytes) { bool UDPSocket::receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const {
#ifdef _WIN32 #ifdef _WIN32
int addressSize = sizeof(*recvAddress); int addressSize = sizeof(*recvAddress);
@ -223,7 +222,7 @@ bool UDPSocket::receive(sockaddr *recvAddress, void *receivedData, ssize_t *rece
return (*receivedBytes > 0); return (*receivedBytes > 0);
} }
int UDPSocket::send(sockaddr *destAddress, const void *data, size_t byteLength) { int UDPSocket::send(sockaddr* destAddress, const void* data, size_t byteLength) const {
// send data via UDP // send data via UDP
int sent_bytes = sendto(handle, (const char*)data, byteLength, int sent_bytes = sendto(handle, (const char*)data, byteLength,
0, (sockaddr *) destAddress, sizeof(sockaddr_in)); 0, (sockaddr *) destAddress, sizeof(sockaddr_in));
@ -236,7 +235,7 @@ int UDPSocket::send(sockaddr *destAddress, const void *data, size_t byteLength)
return sent_bytes; return sent_bytes;
} }
int UDPSocket::send(char * destAddress, int destPort, const void *data, size_t byteLength) { int UDPSocket::send(char* destAddress, int destPort, const void* data, size_t byteLength) const {
// change address and port on reusable global to passed variables // change address and port on reusable global to passed variables
destSockaddr.sin_addr.s_addr = inet_addr(destAddress); destSockaddr.sin_addr.s_addr = inet_addr(destAddress);

View file

@ -25,10 +25,10 @@ class UDPSocket {
bool init(); bool init();
void setBlocking(bool blocking); void setBlocking(bool blocking);
bool isBlocking() { return blocking; } bool isBlocking() { return blocking; }
int send(sockaddr *destAddress, const void *data, size_t byteLength); int send(sockaddr* destAddress, const void* data, size_t byteLength) const;
int send(char *destAddress, int destPort, const void *data, size_t byteLength); int send(char* destAddress, int destPort, const void* data, size_t byteLength) const;
bool receive(void *receivedData, ssize_t *receivedBytes); bool receive(void* receivedData, ssize_t* receivedBytes) const;
bool receive(sockaddr *recvAddress, void *receivedData, ssize_t *receivedBytes); bool receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const;
private: private:
int handle; int handle;
bool blocking; bool blocking;

View file

@ -168,7 +168,7 @@ void resInVoxelDistributor(AgentList* agentList,
if (agentData->getAvailable() >= bytesWritten) { if (agentData->getAvailable() >= bytesWritten) {
agentData->writeToPacket(&tempOutputBuffer[0], bytesWritten); agentData->writeToPacket(&tempOutputBuffer[0], bytesWritten);
} else { } else {
agentList->getAgentSocket().send(agent->getActiveSocket(), agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength()); agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength(); trueBytesSent += agentData->getPacketLength();
truePacketsSent++; truePacketsSent++;
@ -178,7 +178,7 @@ void resInVoxelDistributor(AgentList* agentList,
} }
} else { } else {
if (agentData->isPacketWaiting()) { if (agentData->isPacketWaiting()) {
agentList->getAgentSocket().send(agent->getActiveSocket(), agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength()); agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength(); trueBytesSent += agentData->getPacketLength();
truePacketsSent++; truePacketsSent++;
@ -190,7 +190,7 @@ void resInVoxelDistributor(AgentList* agentList,
} }
// send the environment packet // send the environment packet
int envPacketLength = environmentData.getBroadcastData(tempOutputBuffer); int envPacketLength = environmentData.getBroadcastData(tempOutputBuffer);
agentList->getAgentSocket().send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength); agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
trueBytesSent += envPacketLength; trueBytesSent += envPacketLength;
truePacketsSent++; truePacketsSent++;
@ -288,7 +288,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
if (agentData->getAvailable() >= bytesWritten) { if (agentData->getAvailable() >= bytesWritten) {
agentData->writeToPacket(&tempOutputBuffer[0], bytesWritten); agentData->writeToPacket(&tempOutputBuffer[0], bytesWritten);
} else { } else {
agentList->getAgentSocket().send(agent->getActiveSocket(), agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength()); agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength(); trueBytesSent += agentData->getPacketLength();
truePacketsSent++; truePacketsSent++;
@ -298,7 +298,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
} }
} else { } else {
if (agentData->isPacketWaiting()) { if (agentData->isPacketWaiting()) {
agentList->getAgentSocket().send(agent->getActiveSocket(), agentList->getAgentSocket()->send(agent->getActiveSocket(),
agentData->getPacket(), agentData->getPacketLength()); agentData->getPacket(), agentData->getPacketLength());
trueBytesSent += agentData->getPacketLength(); trueBytesSent += agentData->getPacketLength();
truePacketsSent++; truePacketsSent++;
@ -310,7 +310,7 @@ void deepestLevelVoxelDistributor(AgentList* agentList,
} }
// send the environment packet // send the environment packet
int envPacketLength = environmentData.getBroadcastData(tempOutputBuffer); int envPacketLength = environmentData.getBroadcastData(tempOutputBuffer);
agentList->getAgentSocket().send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength); agentList->getAgentSocket()->send(agent->getActiveSocket(), tempOutputBuffer, envPacketLength);
trueBytesSent += envPacketLength; trueBytesSent += envPacketLength;
truePacketsSent++; truePacketsSent++;
@ -501,7 +501,7 @@ int main(int argc, const char * argv[])
// check to see if we need to persist our voxel state // check to see if we need to persist our voxel state
persistVoxelsWhenDirty(); persistVoxelsWhenDirty();
if (agentList->getAgentSocket().receive(&agentPublicAddress, packetData, &receivedBytes)) { if (agentList->getAgentSocket()->receive(&agentPublicAddress, packetData, &receivedBytes)) {
// XXXBHG: Hacked in support for 'S' SET command // XXXBHG: Hacked in support for 'S' SET command
if (packetData[0] == PACKET_HEADER_SET_VOXEL || packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) { if (packetData[0] == PACKET_HEADER_SET_VOXEL || packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE) {
bool destructive = (packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE); bool destructive = (packetData[0] == PACKET_HEADER_SET_VOXEL_DESTRUCTIVE);