moved the AvatarMixer to a class the assignment-client can handle

This commit is contained in:
Stephen Birarda 2013-09-05 14:01:05 -07:00
parent 9dc3ddc84a
commit 8b601cac0a
7 changed files with 51 additions and 71 deletions

View file

@ -14,4 +14,5 @@ setup_hifi_project(${TARGET_NAME} TRUE)
# link in the shared library
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(audio ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})

View file

@ -11,6 +11,7 @@
#include <Assignment.h>
#include <AudioMixer.h>
#include <AvatarMixer.h>
#include <NodeList.h>
#include <PacketHeaders.h>
#include <SharedUtil.h>
@ -19,6 +20,8 @@ const int ASSIGNMENT_REQUEST_INTERVAL_USECS = 1 * 1000 * 1000;
int main(int argc, char* const argv[]) {
setvbuf(stdout, NULL, _IOLBF, 0);
// create a NodeList as an unassigned client
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_UNASSIGNED);
nodeList->getNodeSocket()->setBlocking(false);
@ -72,8 +75,11 @@ int main(int argc, char* const argv[]) {
qDebug() << "Changed domain IP to " << inet_ntoa(domainSocketAddr);
}
// run the AudioMixer, it's the only possible assignment for now
AudioMixer::run();
if (deployedAssignment.getType() == Assignment::AudioMixer) {
AudioMixer::run();
} else {
AvatarMixer::run();
}
// reset our NodeList by switching back to unassigned and clearing the list
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);

View file

@ -1,22 +0,0 @@
cmake_minimum_required(VERSION 2.8)
set(TARGET_NAME "avatar-mixer")
set(ROOT_DIR ..)
set(MACRO_DIR ${ROOT_DIR}/cmake/macros)
# setup for find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
# setup the project
include(${MACRO_DIR}/SetupHifiProject.cmake)
setup_hifi_project(${TARGET_NAME} TRUE)
# include glm
include(${MACRO_DIR}/IncludeGLM.cmake)
include_glm(${TARGET_NAME} ${ROOT_DIR})
# link required hifi libraries
include(${MACRO_DIR}/LinkHifiLibrary.cmake)
link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR})
link_hifi_library(avatars ${TARGET_NAME} ${ROOT_DIR})

View file

@ -107,6 +107,10 @@ int main(int argc, char* const argv[])
// create an assignment to send, ask for an audio mixer, pass the assignment pool if it exists
Assignment mixerAssignment(Assignment::Create, Assignment::AudioMixer, assignmentPool);
nodeList->sendAssignment(mixerAssignment);
} else if (!nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER)) {
// create an assignment to send, ask for an avatar mixer, pass the assignment pool if it exists
Assignment avatarAssignment(Assignment::Create, Assignment::AvatarMixer, assignmentPool);
nodeList->sendAssignment(avatarAssignment);
}

View file

@ -1,44 +1,26 @@
//
// main.cpp
// Avatar Mixer
// AvatarMixer.cpp
// hifi
//
// Created by Leonardo Murillo on 03/25/13.
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved
// Created by Stephen Birarda on 9/5/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
// Original avatar-mixer main created by Leonardo Murillo on 03/25/13.
//
// The avatar mixer receives head, hand and positional data from all connected
// nodes, and broadcasts that data back to them, every BROADCAST_INTERVAL ms.
//
//
#include <iostream>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <pthread.h>
#include <errno.h>
#include <fstream>
#include <limits>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <NodeList.h>
#include <SharedUtil.h>
#include <PacketHeaders.h>
#include <NodeTypes.h>
#include <StdDev.h>
#include <UDPSocket.h>
#include <SharedUtil.h>
#include "AvatarData.h"
const int AVATAR_LISTEN_PORT = 55444;
#include "AvatarMixer.h"
unsigned char* addNodeToBroadcastPacket(unsigned char *currentPosition, Node *nodeToAdd) {
currentPosition += packNodeId(currentPosition, nodeToAdd->getNodeID());
AvatarData *nodeData = (AvatarData *)nodeToAdd->getLinkedData();
currentPosition += nodeData->getBroadcastData(currentPosition);
@ -55,7 +37,7 @@ void attachAvatarDataToNode(Node* newNode) {
// 1) use the view frustum to cull those avatars that are out of view. Since avatar data doesn't need to be present
// if the avatar is not in view or in the keyhole.
// 2) after culling for view frustum, sort order the avatars by distance, send the closest ones first.
// 3) if we need to rate limit the amount of data we send, we can use a distance weighted "semi-random" function to
// 3) if we need to rate limit the amount of data we send, we can use a distance weighted "semi-random" function to
// determine which avatars are included in the packet stream
// 4) we should optimize the avatar data format to be more compact (100 bytes is pretty wasteful).
void broadcastAvatarData(NodeList* nodeList, sockaddr* nodeAddress) {
@ -66,13 +48,13 @@ void broadcastAvatarData(NodeList* nodeList, sockaddr* nodeAddress) {
unsigned char* currentBufferPosition = broadcastPacket + numHeaderBytes;
int packetLength = currentBufferPosition - broadcastPacket;
int packetsSent = 0;
// send back a packet with other active node data to this node
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
if (node->getLinkedData() && !socketMatch(nodeAddress, node->getActiveSocket())) {
unsigned char* avatarDataEndpoint = addNodeToBroadcastPacket((unsigned char*)&avatarDataBuffer[0], &*node);
int avatarDataLength = avatarDataEndpoint - (unsigned char*)&avatarDataBuffer;
if (avatarDataLength + packetLength <= MAX_PACKET_SIZE) {
memcpy(currentBufferPosition, &avatarDataBuffer[0], avatarDataLength);
packetLength += avatarDataLength;
@ -98,17 +80,9 @@ void broadcastAvatarData(NodeList* nodeList, sockaddr* nodeAddress) {
nodeList->getNodeSocket()->send(nodeAddress, broadcastPacket, currentBufferPosition - broadcastPacket);
}
int main(int argc, const char* argv[]) {
NodeList* nodeList = NodeList::createInstance(NODE_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT);
setvbuf(stdout, NULL, _IOLBF, 0);
// Handle Local Domain testing with the --local command line
const char* local = "--local";
if (cmdOptionExists(argc, argv, local)) {
printf("Local Domain MODE!\n");
nodeList->setDomainIPToLocalhost();
}
void AvatarMixer::run() {
NodeList* nodeList = NodeList::getInstance();
nodeList->setOwnerType(NODE_TYPE_AVATAR_MIXER);
nodeList->linkedDataCreateCallback = attachAvatarDataToNode;
@ -119,13 +93,12 @@ int main(int argc, const char* argv[]) {
unsigned char* packetData = new unsigned char[MAX_PACKET_SIZE];
uint16_t nodeID = 0;
Node* avatarNode = NULL;
timeval lastDomainServerCheckIn = {};
// we only need to hear back about avatar nodes from the DS
NodeList::getInstance()->setNodeTypesOfInterest(&NODE_TYPE_AGENT, 1);
nodeList->setNodeTypesOfInterest(&NODE_TYPE_AGENT, 1);
while (true) {
@ -174,6 +147,4 @@ int main(int argc, const char* argv[]) {
}
nodeList->stopSilentNodeRemovalThread();
return 0;
}
}

View file

@ -0,0 +1,19 @@
//
// AvatarMixer.h
// hifi
//
// Created by Stephen Birarda on 9/5/13.
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
//
#ifndef __hifi__AvatarMixer__
#define __hifi__AvatarMixer__
#include <iostream>
class AvatarMixer {
public:
static void run();
};
#endif /* defined(__hifi__AvatarMixer__) */

View file

@ -16,6 +16,7 @@ public:
enum Type {
AudioMixer,
AvatarMixer,
All
};