mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 13:09:52 +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];
|
// int16_t *inputRight = ((int16_t **) inputBuffer)[1];
|
||||||
|
|
||||||
if (inputLeft != NULL) {
|
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;
|
return paContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::updateMixerParams(char *newAddress, unsigned short newPort) {
|
void Audio::updateMixerParams(in_addr_t newMixerAddress, in_port_t newMixerPort) {
|
||||||
if (audioData->mixerAddress == NULL) {
|
audioData->mixerAddress = newMixerAddress;
|
||||||
audioData->mixerAddress = new char[255];
|
audioData->mixerPort = newMixerPort;
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(audioData->mixerAddress, newAddress);
|
|
||||||
audioData->mixerPort = newPort;
|
|
||||||
|
|
||||||
std::cout << "Audio Mixer now at " << audioData->mixerAddress << ":" << newPort << ".\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AudioRecThreadStruct {
|
struct AudioRecThreadStruct {
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
void render(int screenWidth, int screenHeight);
|
void render(int screenWidth, int screenHeight);
|
||||||
|
|
||||||
void getInputLoudness(float * lastLoudness, float * averageLoudness);
|
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
|
// terminates audio I/O
|
||||||
bool terminate();
|
bool terminate();
|
||||||
|
@ -35,10 +35,6 @@ private:
|
||||||
// protects constructor so that public init method is used
|
// protects constructor so that public init method is used
|
||||||
Audio();
|
Audio();
|
||||||
|
|
||||||
// store current mixer address and port
|
|
||||||
char *mixerAddress;
|
|
||||||
int mixerPort;
|
|
||||||
|
|
||||||
// hold potential error returned from PortAudio functions
|
// hold potential error returned from PortAudio functions
|
||||||
PaError paError;
|
PaError paError;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "AudioData.h"
|
#include "AudioData.h"
|
||||||
|
|
||||||
AudioData::AudioData(int bufferLength) {
|
AudioData::AudioData(int bufferLength) {
|
||||||
mixerAddress = NULL;
|
mixerAddress = 0;
|
||||||
mixerPort = 0;
|
mixerPort = 0;
|
||||||
|
|
||||||
samplesToQueue = new int16_t[bufferLength / sizeof(int16_t)];
|
samplesToQueue = new int16_t[bufferLength / sizeof(int16_t)];
|
||||||
|
|
|
@ -22,8 +22,9 @@ class AudioData {
|
||||||
|
|
||||||
int16_t *samplesToQueue;
|
int16_t *samplesToQueue;
|
||||||
|
|
||||||
char *mixerAddress;
|
// store current mixer address and port
|
||||||
unsigned short mixerPort;
|
in_addr_t mixerAddress;
|
||||||
|
in_port_t mixerPort;
|
||||||
|
|
||||||
timeval lastCallback;
|
timeval lastCallback;
|
||||||
float averagedLatency;
|
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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
struct ifaddrs * ifAddrStruct=NULL;
|
struct ifaddrs * ifAddrStruct=NULL;
|
||||||
|
@ -930,6 +934,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
// the callback for our instance of AgentList is attachNewHeadToAgent
|
// the callback for our instance of AgentList is attachNewHeadToAgent
|
||||||
agentList.linkedDataCreateCallback = &attachNewHeadToAgent;
|
agentList.linkedDataCreateCallback = &attachNewHeadToAgent;
|
||||||
|
agentList.audioMixerSocketUpdate = &audioMixerUpdate;
|
||||||
|
|
||||||
// create thread for receipt of data via UDP
|
// create thread for receipt of data via UDP
|
||||||
pthread_t networkReceiveThread;
|
pthread_t networkReceiveThread;
|
||||||
|
|
|
@ -224,14 +224,14 @@ int addAgent(sockaddr_in *newAddress, void *audioData) {
|
||||||
void *reportAliveToDS(void *args) {
|
void *reportAliveToDS(void *args) {
|
||||||
|
|
||||||
timeval lastSend, now;
|
timeval lastSend, now;
|
||||||
char output[100];
|
unsigned char output[7];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
gettimeofday(&lastSend, NULL);
|
gettimeofday(&lastSend, NULL);
|
||||||
|
|
||||||
sprintf(output, "%c %f,%f,%f,54.241.92.53 %hd", 'M', 0.f, 0.f, 0.f, MIXER_LISTEN_PORT);
|
*output = 'M';
|
||||||
int packetSize = strlen(output);
|
packSocket(output + 1, 895283510, htons(MIXER_LISTEN_PORT));
|
||||||
audioSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, packetSize);
|
audioSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, 7);
|
||||||
|
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
|
AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
|
||||||
linkedDataCreateCallback = NULL;
|
linkedDataCreateCallback = NULL;
|
||||||
|
audioMixerSocketUpdate = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AgentList::AgentList(int socketListenPort) : agentSocket(socketListenPort) {
|
AgentList::AgentList(int socketListenPort) : agentSocket(socketListenPort) {
|
||||||
|
@ -123,6 +124,14 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
newAgent.activeSocket = newAgent.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";
|
std::cout << "Added agent - " << &newAgent << "\n";
|
||||||
|
|
||||||
agents.push_back(newAgent);
|
agents.push_back(newAgent);
|
||||||
|
@ -136,7 +145,9 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
||||||
|
|
||||||
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
||||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
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
|
// we know which socket is good for this agent, send there
|
||||||
agentSocket.send((sockaddr *)agent->activeSocket, broadcastData, dataBytes);
|
agentSocket.send((sockaddr *)agent->activeSocket, broadcastData, dataBytes);
|
||||||
}
|
}
|
||||||
|
@ -145,17 +156,19 @@ void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes) {
|
||||||
|
|
||||||
|
|
||||||
void AgentList::pingAgents() {
|
void AgentList::pingAgents() {
|
||||||
|
char payload[] = "P";
|
||||||
|
|
||||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
char payload[] = "P";
|
if (agent->type == 'I') {
|
||||||
|
if (agent->activeSocket != NULL) {
|
||||||
if (agent->activeSocket != NULL) {
|
// we know which socket is good for this agent, send there
|
||||||
// we know which socket is good for this agent, send there
|
agentSocket.send((sockaddr *)agent->activeSocket, payload, 1);
|
||||||
agentSocket.send((sockaddr *)agent->activeSocket, payload, 1);
|
} else {
|
||||||
} else {
|
// 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
|
agentSocket.send(agent->publicSocket, payload, 1);
|
||||||
agentSocket.send(agent->publicSocket, payload, 1);
|
agentSocket.send(agent->localSocket, payload, 1);
|
||||||
agentSocket.send(agent->localSocket, payload, 1);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ class AgentList {
|
||||||
AgentList(int socketListenPort);
|
AgentList(int socketListenPort);
|
||||||
std::vector<Agent> agents;
|
std::vector<Agent> agents;
|
||||||
void(*linkedDataCreateCallback)(Agent *);
|
void(*linkedDataCreateCallback)(Agent *);
|
||||||
|
void(*audioMixerSocketUpdate)(in_addr_t, in_port_t);
|
||||||
|
|
||||||
UDPSocket* getAgentSocket();
|
UDPSocket* getAgentSocket();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue