mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 05:44:44 +02:00
Templated read/write in Packet
This commit is contained in:
parent
10f843b197
commit
7329ad6334
5 changed files with 23 additions and 13 deletions
|
@ -856,22 +856,22 @@ void AudioClient::handleAudioInput() {
|
|||
_audioPacket->reset();
|
||||
|
||||
// write sequence number
|
||||
_audioPacket->write(reinterpret_cast<char*>(&_outgoingAvatarAudioSequenceNumber), sizeof(quint16));
|
||||
_audioPacket->write(_outgoingAvatarAudioSequenceNumber);
|
||||
|
||||
if (_audioPacket->getPacketType() == PacketType::SilentAudioFrame) {
|
||||
// pack num silent samples
|
||||
quint16 numSilentSamples = numNetworkSamples;
|
||||
_audioPacket->write(reinterpret_cast<char*>(&numSilentSamples), sizeof(quint16));
|
||||
_audioPacket->write(numSilentSamples);
|
||||
} else {
|
||||
// set the mono/stereo byte
|
||||
_audioPacket->write(reinterpret_cast<char*>(&isStereo), sizeof(isStereo));
|
||||
_audioPacket->write(isStereo);
|
||||
}
|
||||
|
||||
// pack the three float positions
|
||||
_audioPacket->write(reinterpret_cast<char*>(&headPosition), sizeof(headPosition));
|
||||
_audioPacket->write(headPosition);
|
||||
|
||||
// pack the orientation
|
||||
_audioPacket->write(reinterpret_cast<char*>(&headOrientation), sizeof(headOrientation));
|
||||
_audioPacket->write(headOrientation);
|
||||
|
||||
if (_audioPacket->getPacketType() != PacketType::SilentAudioFrame) {
|
||||
// audio samples have already been packed (written to networkAudioSamples)
|
||||
|
@ -912,12 +912,12 @@ void AudioClient::sendMuteEnvironmentPacket() {
|
|||
|
||||
auto mutePacket = NLPacket::create(PacketType::MuteEnvironment, dataSize);
|
||||
|
||||
float MUTE_RADIUS = 50;
|
||||
const float MUTE_RADIUS = 50;
|
||||
|
||||
glm::vec3 currentSourcePosition = _positionGetter();
|
||||
|
||||
mutePacket->write(reinterpret_cast<char*>(¤tSourcePosition), sizeof(currentSourcePosition));
|
||||
mutePacket->write(reinterpret_cast<char*>(&MUTE_RADIUS), sizeof(MUTE_RADIUS));
|
||||
mutePacket->write(currentSourcePosition);
|
||||
mutePacket->write(MUTE_RADIUS);
|
||||
|
||||
// grab our audio mixer from the NodeList, if it exists
|
||||
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
||||
|
|
|
@ -216,17 +216,17 @@ void AudioInjector::injectToMixer() {
|
|||
_loudness /= (float)(bytesToCopy / sizeof(int16_t));
|
||||
|
||||
audioPacket->seek(positionOptionOffset);
|
||||
audioPacket->write(reinterpret_cast<char*>(&_options.position), sizeof(_options.position));
|
||||
audioPacket->write(reinterpret_cast<char*>(&_options.orientation), sizeof(_options.orientation));
|
||||
audioPacket->write(_options.position);
|
||||
audioPacket->write(_options.orientation);
|
||||
|
||||
volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||
audioPacket->seek(volumeOptionOffset);
|
||||
audioPacket->write(reinterpret_cast<char*>(&volume), sizeof(volume));
|
||||
audioPacket->write(volume);
|
||||
|
||||
audioPacket->seek(audioDataOffset);
|
||||
|
||||
// pack the sequence number
|
||||
audioPacket->write(reinterpret_cast<char*>(&outgoingInjectedAudioSequenceNumber), sizeof(quint16));
|
||||
audioPacket->write(outgoingInjectedAudioSequenceNumber);
|
||||
|
||||
// copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet
|
||||
audioPacket->write(_audioData.data() + _currentSendPosition, bytesToCopy);
|
||||
|
|
|
@ -156,6 +156,14 @@ void Packet::writeSequenceNumber(SequenceNumber seqNum) {
|
|||
&seqNum, sizeof(seqNum));
|
||||
}
|
||||
|
||||
template<typename T> qint64 Packet::read(T* data) {
|
||||
return QIODevice::read(reinterpret_cast<char*>(data), sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T> qint64 Packet::write(const T& data) {
|
||||
return QIODevice::write(reinterpret_cast<const char*>(&data), sizeof(T));
|
||||
}
|
||||
|
||||
static const qint64 PACKET_WRITE_ERROR = -1;
|
||||
qint64 Packet::writeData(const char* data, qint64 maxSize) {
|
||||
// make sure we have the space required to write this block
|
||||
|
|
|
@ -59,6 +59,9 @@ public:
|
|||
virtual bool reset() { setSizeUsed(0); return QIODevice::reset(); }
|
||||
virtual qint64 size() const { return _capacity; }
|
||||
|
||||
template<typename T> qint64 read(T* data);
|
||||
template<typename T> qint64 write(const T& data);
|
||||
|
||||
protected:
|
||||
Packet(PacketType::Value type, int64_t size);
|
||||
Packet(const Packet& other);
|
||||
|
|
|
@ -28,7 +28,6 @@ JurisdictionSender::JurisdictionSender(JurisdictionMap* map, NodeType_t type) :
|
|||
JurisdictionSender::~JurisdictionSender() {
|
||||
}
|
||||
|
||||
|
||||
void JurisdictionSender::processPacket(const SharedNodePointer& sendingNode, const QByteArray& packet) {
|
||||
if (packetTypeForPacket(packet) == PacketType::JurisdictionRequest) {
|
||||
if (sendingNode) {
|
||||
|
|
Loading…
Reference in a new issue