mirror of
https://github.com/lubosz/overte.git
synced 2025-08-17 05:42:08 +02:00
use sendUnreliablePacket for repeated send in AI
This commit is contained in:
parent
9a31b22243
commit
e1c098233a
2 changed files with 33 additions and 31 deletions
|
@ -153,54 +153,56 @@ void AudioInjector::injectToMixer() {
|
||||||
// make sure we actually have samples downloaded to inject
|
// make sure we actually have samples downloaded to inject
|
||||||
if (_audioData.size()) {
|
if (_audioData.size()) {
|
||||||
|
|
||||||
|
auto audioPacket { NLPacket::create(PacketType::InjectAudio); }
|
||||||
|
|
||||||
// setup the packet for injected audio
|
// setup the packet for injected audio
|
||||||
QByteArray injectAudioPacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeInjectAudio);
|
QDataStream audioPacketStream(&audioPacket);
|
||||||
QDataStream packetStream(&injectAudioPacket, QIODevice::Append);
|
|
||||||
|
|
||||||
// pack some placeholder sequence number for now
|
// pack some placeholder sequence number for now
|
||||||
int numPreSequenceNumberBytes = injectAudioPacket.size();
|
audioPacketStream << (quint16) 0;
|
||||||
packetStream << (quint16)0;
|
|
||||||
|
|
||||||
// pack stream identifier (a generated UUID)
|
// pack stream identifier (a generated UUID)
|
||||||
packetStream << QUuid::createUuid();
|
audioPacketStream << QUuid::createUuid();
|
||||||
|
|
||||||
// pack the stereo/mono type of the stream
|
// pack the stereo/mono type of the stream
|
||||||
packetStream << _options.stereo;
|
audioPacketStream << _options.stereo;
|
||||||
|
|
||||||
// pack the flag for loopback
|
// pack the flag for loopback
|
||||||
uchar loopbackFlag = (uchar) true;
|
uchar loopbackFlag = (uchar) true;
|
||||||
packetStream << loopbackFlag;
|
audioPacketStream << loopbackFlag;
|
||||||
|
|
||||||
// pack the position for injected audio
|
// pack the position for injected audio
|
||||||
int positionOptionOffset = injectAudioPacket.size();
|
int positionOptionOffset = audioPacket.pos();
|
||||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.position),
|
audioPacketStream.writeRawData(reinterpret_cast<const char*>(&_options.position),
|
||||||
sizeof(_options.position));
|
sizeof(_options.position));
|
||||||
|
|
||||||
// pack our orientation for injected audio
|
// pack our orientation for injected audio
|
||||||
int orientationOptionOffset = injectAudioPacket.size();
|
int orientationOptionOffset = audioPacket.pos();
|
||||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation),
|
audioPacketStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation),
|
||||||
sizeof(_options.orientation));
|
sizeof(_options.orientation));
|
||||||
|
|
||||||
// pack zero for radius
|
// pack zero for radius
|
||||||
float radius = 0;
|
float radius = 0;
|
||||||
packetStream << radius;
|
audioPacketStream << radius;
|
||||||
|
|
||||||
// pack 255 for attenuation byte
|
// pack 255 for attenuation byte
|
||||||
int volumeOptionOffset = injectAudioPacket.size();
|
int volumeOptionOffset = audioPacket.pos();
|
||||||
quint8 volume = MAX_INJECTOR_VOLUME * _options.volume;
|
quint8 volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||||
packetStream << volume;
|
audioPacketStream << volume;
|
||||||
|
|
||||||
packetStream << _options.ignorePenumbra;
|
audioPacketStream << _options.ignorePenumbra;
|
||||||
|
|
||||||
|
int audioDataOffset = audioPacket.pos();
|
||||||
|
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
timer.start();
|
timer.start();
|
||||||
int nextFrame = 0;
|
int nextFrame = 0;
|
||||||
|
|
||||||
int numPreAudioDataBytes = injectAudioPacket.size();
|
|
||||||
bool shouldLoop = _options.loop;
|
bool shouldLoop = _options.loop;
|
||||||
|
|
||||||
// loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks
|
// loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks
|
||||||
quint16 outgoingInjectedAudioSequenceNumber = 0;
|
quint16 outgoingInjectedAudioSequenceNumber = 0;
|
||||||
|
|
||||||
while (_currentSendPosition < _audioData.size() && !_shouldStop) {
|
while (_currentSendPosition < _audioData.size() && !_shouldStop) {
|
||||||
|
|
||||||
int bytesToCopy = std::min(((_options.stereo) ? 2 : 1) * AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL,
|
int bytesToCopy = std::min(((_options.stereo) ? 2 : 1) * AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL,
|
||||||
|
@ -214,31 +216,29 @@ void AudioInjector::injectToMixer() {
|
||||||
}
|
}
|
||||||
_loudness /= (float)(bytesToCopy / sizeof(int16_t));
|
_loudness /= (float)(bytesToCopy / sizeof(int16_t));
|
||||||
|
|
||||||
memcpy(injectAudioPacket.data() + positionOptionOffset,
|
audioPacket.seek(positionOptionOffset);
|
||||||
&_options.position,
|
audioPacket.write(&_options.position, sizeof(_options.position));
|
||||||
sizeof(_options.position));
|
|
||||||
memcpy(injectAudioPacket.data() + orientationOptionOffset,
|
|
||||||
&_options.orientation,
|
|
||||||
sizeof(_options.orientation));
|
|
||||||
volume = MAX_INJECTOR_VOLUME * _options.volume;
|
|
||||||
memcpy(injectAudioPacket.data() + volumeOptionOffset, &volume, sizeof(volume));
|
|
||||||
|
|
||||||
// resize the QByteArray to the right size
|
audioPacket.seek(orientationOptionOffset);
|
||||||
injectAudioPacket.resize(numPreAudioDataBytes + bytesToCopy);
|
audioPacket.write(&_options.orientation, sizeof(_options.orientation));
|
||||||
|
|
||||||
|
volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||||
|
audioPacket.seek(volumeOptionOffset);
|
||||||
|
audioPacket.write(&volume, sizeof(volume));
|
||||||
|
|
||||||
|
audioPacket.seek(audioDataOffset);
|
||||||
|
|
||||||
// pack the sequence number
|
// pack the sequence number
|
||||||
memcpy(injectAudioPacket.data() + numPreSequenceNumberBytes,
|
audioPacket.write(&outgoingInjectedAudioSequenceNumber, sizeof(quint16));
|
||||||
&outgoingInjectedAudioSequenceNumber, sizeof(quint16));
|
|
||||||
|
|
||||||
// copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet
|
// copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet
|
||||||
memcpy(injectAudioPacket.data() + numPreAudioDataBytes,
|
audioPacket.write(_audioData.data() + _currentSendPosition, bytesToCopy);
|
||||||
_audioData.data() + _currentSendPosition, bytesToCopy);
|
|
||||||
|
|
||||||
// grab our audio mixer from the NodeList, if it exists
|
// grab our audio mixer from the NodeList, if it exists
|
||||||
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
||||||
|
|
||||||
// send off this audio packet
|
// send off this audio packet
|
||||||
nodeList->writeDatagram(injectAudioPacket, audioMixer);
|
nodeList->sendUnreliablePacket(audioPacket, audioMixer);
|
||||||
outgoingInjectedAudioSequenceNumber++;
|
outgoingInjectedAudioSequenceNumber++;
|
||||||
|
|
||||||
_currentSendPosition += bytesToCopy;
|
_currentSendPosition += bytesToCopy;
|
||||||
|
|
|
@ -142,6 +142,8 @@ public:
|
||||||
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
|
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
|
||||||
//
|
//
|
||||||
|
|
||||||
|
qint64 sendUnreliablePacket(NLPacket& packet, const SharedNodePointer& destinationNode) {};
|
||||||
|
qint64 sendUnreliablePacket(NLPacket& packet, const HifiSockAddr& sockAddr) {};
|
||||||
qint64 sendPacket(NLPacket&& packet, const SharedNodePointer& destinationNode) {};
|
qint64 sendPacket(NLPacket&& packet, const SharedNodePointer& destinationNode) {};
|
||||||
qint64 sendPacket(NLPacket&& packet, const HifiSockAddr& sockAddr) {};
|
qint64 sendPacket(NLPacket&& packet, const HifiSockAddr& sockAddr) {};
|
||||||
qint64 sendPacketList(PacketList& packetList, const SharedNodePointer& destinationNode) {};
|
qint64 sendPacketList(PacketList& packetList, const SharedNodePointer& destinationNode) {};
|
||||||
|
|
Loading…
Reference in a new issue