mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 21:18:06 +02:00
allow switchover to new audio mixer received from audio server
This commit is contained in:
parent
c28ace9c15
commit
aa9f4f966e
8 changed files with 49 additions and 34 deletions
|
@ -84,8 +84,13 @@ int audioCallback (const void *inputBuffer,
|
|||
// int16_t *inputRight = ((int16_t **) inputBuffer)[1];
|
||||
|
||||
if (inputLeft != NULL) {
|
||||
if (data->mixerAddress != NULL) {
|
||||
data->audioSocket->send(data->mixerAddress, data->mixerPort, (void *)inputLeft, BUFFER_LENGTH_BYTES);
|
||||
|
||||
if (data->mixerAddress != 0) {
|
||||
sockaddr_in audioMixerSocket;
|
||||
audioMixerSocket.sin_family = AF_INET;
|
||||
audioMixerSocket.sin_addr.s_addr = data->mixerAddress;
|
||||
audioMixerSocket.sin_port = data->mixerPort;
|
||||
data->audioSocket->send((sockaddr *)&audioMixerSocket, (void *)inputLeft, BUFFER_LENGTH_BYTES);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -162,15 +167,9 @@ int audioCallback (const void *inputBuffer,
|
|||
return paContinue;
|
||||
}
|
||||
|
||||
void Audio::updateMixerParams(char *newAddress, unsigned short newPort) {
|
||||
if (audioData->mixerAddress == NULL) {
|
||||
audioData->mixerAddress = new char[255];
|
||||
}
|
||||
|
||||
strcpy(audioData->mixerAddress, newAddress);
|
||||
audioData->mixerPort = newPort;
|
||||
|
||||
std::cout << "Audio Mixer now at " << audioData->mixerAddress << ":" << newPort << ".\n";
|
||||
void Audio::updateMixerParams(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
||||
audioData->mixerAddress = newMixerAddress;
|
||||
audioData->mixerPort = newMixerPort;
|
||||
}
|
||||
|
||||
struct AudioRecThreadStruct {
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
void render(int screenWidth, int screenHeight);
|
||||
|
||||
void getInputLoudness(float * lastLoudness, float * averageLoudness);
|
||||
void updateMixerParams(char *mixerAddress, unsigned short mixerPort);
|
||||
void updateMixerParams(in_addr_t mixerAddress, in_port_t mixerPort);
|
||||
|
||||
// terminates audio I/O
|
||||
bool terminate();
|
||||
|
@ -35,10 +35,6 @@ private:
|
|||
// protects constructor so that public init method is used
|
||||
Audio();
|
||||
|
||||
// store current mixer address and port
|
||||
char *mixerAddress;
|
||||
int mixerPort;
|
||||
|
||||
// hold potential error returned from PortAudio functions
|
||||
PaError paError;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "AudioData.h"
|
||||
|
||||
AudioData::AudioData(int bufferLength) {
|
||||
mixerAddress = NULL;
|
||||
mixerAddress = 0;
|
||||
mixerPort = 0;
|
||||
|
||||
samplesToQueue = new int16_t[bufferLength / sizeof(int16_t)];
|
||||
|
|
|
@ -22,8 +22,9 @@ class AudioData {
|
|||
|
||||
int16_t *samplesToQueue;
|
||||
|
||||
char *mixerAddress;
|
||||
unsigned short mixerPort;
|
||||
// store current mixer address and port
|
||||
in_addr_t mixerAddress;
|
||||
in_port_t mixerPort;
|
||||
|
||||
timeval lastCallback;
|
||||
float averagedLatency;
|
||||
|
|
|
@ -876,6 +876,10 @@ void attachNewHeadToAgent(Agent *newAgent) {
|
|||
}
|
||||
}
|
||||
|
||||
void audioMixerUpdate(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
||||
audio.updateMixerParams(newMixerAddress, newMixerPort);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
struct ifaddrs * ifAddrStruct=NULL;
|
||||
|
@ -930,6 +934,7 @@ int main(int argc, char** argv)
|
|||
|
||||
// the callback for our instance of AgentList is attachNewHeadToAgent
|
||||
agentList.linkedDataCreateCallback = &attachNewHeadToAgent;
|
||||
agentList.audioMixerSocketUpdate = &audioMixerUpdate;
|
||||
|
||||
// create thread for receipt of data via UDP
|
||||
pthread_t networkReceiveThread;
|
||||
|
|
|
@ -224,14 +224,14 @@ int addAgent(sockaddr_in *newAddress, void *audioData) {
|
|||
void *reportAliveToDS(void *args) {
|
||||
|
||||
timeval lastSend, now;
|
||||
char output[100];
|
||||
unsigned char output[7];
|
||||
|
||||
while (true) {
|
||||
gettimeofday(&lastSend, NULL);
|
||||
|
||||
sprintf(output, "%c %f,%f,%f,54.241.92.53 %hd", 'M', 0.f, 0.f, 0.f, MIXER_LISTEN_PORT);
|
||||
int packetSize = strlen(output);
|
||||
audioSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, packetSize);
|
||||
*output = 'M';
|
||||
packSocket(output + 1, 895283510, htons(MIXER_LISTEN_PORT));
|
||||
audioSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
|
||||
linkedDataCreateCallback = NULL;
|
||||
audioMixerSocketUpdate = NULL;
|
||||
}
|
||||
|
||||
AgentList::AgentList(int socketListenPort) : agentSocket(socketListenPort) {
|
||||
|
@ -123,6 +124,14 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
|||
newAgent.activeSocket = newAgent.localSocket;
|
||||
}
|
||||
|
||||
if (newAgent.type == 'M' && audioMixerSocketUpdate != NULL) {
|
||||
// this is an audio mixer
|
||||
// for now that means we need to tell the audio class
|
||||
// to use the local socket information the domain server gave us
|
||||
sockaddr_in *localSocketIn = (sockaddr_in *)localSocket;
|
||||
audioMixerSocketUpdate(localSocketIn->sin_addr.s_addr, localSocketIn->sin_port);
|
||||
}
|
||||
|
||||
std::cout << "Added agent - " << &newAgent << "\n";
|
||||
|
||||
agents.push_back(newAgent);
|
||||
|
@ -136,7 +145,9 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
|||
|
||||
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||
if (agent->activeSocket != NULL) {
|
||||
// for now assume we only want to send to other interface clients
|
||||
// until the Audio class uses the AgentList
|
||||
if (agent->activeSocket != NULL && agent->type == 'I') {
|
||||
// we know which socket is good for this agent, send there
|
||||
agentSocket.send((sockaddr *)agent->activeSocket, broadcastData, dataBytes);
|
||||
}
|
||||
|
@ -145,17 +156,19 @@ void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
|||
|
||||
|
||||
void AgentList::pingAgents() {
|
||||
char payload[] = "P";
|
||||
|
||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||
char payload[] = "P";
|
||||
|
||||
if (agent->activeSocket != NULL) {
|
||||
// we know which socket is good for this agent, send there
|
||||
agentSocket.send((sockaddr *)agent->activeSocket, payload, 1);
|
||||
} else {
|
||||
// ping both of the sockets for the agent so we can figure out
|
||||
// which socket we can use
|
||||
agentSocket.send(agent->publicSocket, payload, 1);
|
||||
agentSocket.send(agent->localSocket, payload, 1);
|
||||
if (agent->type == 'I') {
|
||||
if (agent->activeSocket != NULL) {
|
||||
// we know which socket is good for this agent, send there
|
||||
agentSocket.send((sockaddr *)agent->activeSocket, payload, 1);
|
||||
} else {
|
||||
// ping both of the sockets for the agent so we can figure out
|
||||
// which socket we can use
|
||||
agentSocket.send(agent->publicSocket, payload, 1);
|
||||
agentSocket.send(agent->localSocket, payload, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ class AgentList {
|
|||
AgentList(int socketListenPort);
|
||||
std::vector<Agent> agents;
|
||||
void(*linkedDataCreateCallback)(Agent *);
|
||||
void(*audioMixerSocketUpdate)(in_addr_t, in_port_t);
|
||||
|
||||
UDPSocket* getAgentSocket();
|
||||
|
||||
|
|
Loading…
Reference in a new issue