mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:38:02 +02:00
more codec plumbing
This commit is contained in:
parent
38f0cd218b
commit
3c6447326e
8 changed files with 68 additions and 11 deletions
|
@ -477,21 +477,39 @@ void AudioMixer::handleNegotiateAudioFormat(QSharedPointer<ReceivedMessage> mess
|
||||||
}
|
}
|
||||||
qDebug() << "all requested codecs:" << codecList;
|
qDebug() << "all requested codecs:" << codecList;
|
||||||
|
|
||||||
|
CodecPluginPointer selectedCoded;
|
||||||
|
QString selectedCodecName;
|
||||||
auto codecPlugins = PluginManager::getInstance()->getCodecPlugins();
|
auto codecPlugins = PluginManager::getInstance()->getCodecPlugins();
|
||||||
if (codecPlugins.size() > 0) {
|
if (codecPlugins.size() > 0) {
|
||||||
for (auto& plugin : codecPlugins) {
|
for (auto& plugin : codecPlugins) {
|
||||||
qDebug() << "Codec available:" << plugin->getName();
|
qDebug() << "Codec available:" << plugin->getName();
|
||||||
|
|
||||||
|
// choose first codec
|
||||||
|
if (!selectedCoded) {
|
||||||
|
selectedCoded = plugin;
|
||||||
|
selectedCodecName = plugin->getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "No Codecs available...";
|
qDebug() << "No Codecs available...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto clientData = dynamic_cast<AudioMixerClientData*>(sendingNode->getLinkedData());
|
||||||
|
|
||||||
|
clientData->_codec = selectedCoded;
|
||||||
|
clientData->_selectedCodecName = selectedCodecName;
|
||||||
|
qDebug() << "selectedCodecName:" << selectedCodecName;
|
||||||
|
|
||||||
|
auto avatarAudioStream = clientData->getAvatarAudioStream();
|
||||||
|
if (avatarAudioStream) {
|
||||||
|
avatarAudioStream->_codec = selectedCoded;
|
||||||
|
avatarAudioStream->_selectedCodecName = selectedCodecName;
|
||||||
|
}
|
||||||
|
|
||||||
auto replyPacket = NLPacket::create(PacketType::SelectedAudioFormat);
|
auto replyPacket = NLPacket::create(PacketType::SelectedAudioFormat);
|
||||||
|
|
||||||
// write them to our packet
|
// write them to our packet
|
||||||
QString selectedCodec = codecList.front();
|
replyPacket->writeString(selectedCodecName);
|
||||||
qDebug() << "selectedCodec:" << selectedCodec;
|
|
||||||
replyPacket->writeString(selectedCodec);
|
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
nodeList->sendPacket(std::move(replyPacket), *sendingNode);
|
nodeList->sendPacket(std::move(replyPacket), *sendingNode);
|
||||||
|
@ -720,9 +738,17 @@ void AudioMixer::broadcastMixes() {
|
||||||
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
||||||
mixPacket->writePrimitive(sequence);
|
mixPacket->writePrimitive(sequence);
|
||||||
|
|
||||||
|
// TODO - codec encode goes here
|
||||||
|
QByteArray decocedBuffer(reinterpret_cast<char*>(_clampedSamples), AudioConstants::NETWORK_FRAME_BYTES_STEREO);
|
||||||
|
QByteArray encodedBuffer;
|
||||||
|
if (nodeData->_codec) {
|
||||||
|
nodeData->_codec->encode(decocedBuffer, encodedBuffer);
|
||||||
|
} else {
|
||||||
|
encodedBuffer = decocedBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
// pack mixed audio samples
|
// pack mixed audio samples
|
||||||
mixPacket->write(reinterpret_cast<char*>(_clampedSamples),
|
mixPacket->write(encodedBuffer.constData(), encodedBuffer.size());
|
||||||
AudioConstants::NETWORK_FRAME_BYTES_STEREO);
|
|
||||||
} else {
|
} else {
|
||||||
int silentPacketBytes = sizeof(quint16) + sizeof(quint16);
|
int silentPacketBytes = sizeof(quint16) + sizeof(quint16);
|
||||||
mixPacket = NLPacket::create(PacketType::SilentAudioFrame, silentPacketBytes);
|
mixPacket = NLPacket::create(PacketType::SilentAudioFrame, silentPacketBytes);
|
||||||
|
|
|
@ -101,9 +101,14 @@ int AudioMixerClientData::parseData(ReceivedMessage& message) {
|
||||||
|
|
||||||
bool isStereo = channelFlag == 1;
|
bool isStereo = channelFlag == 1;
|
||||||
|
|
||||||
|
auto avatarAudioStream = new AvatarAudioStream(isStereo, AudioMixer::getStreamSettings());
|
||||||
|
avatarAudioStream->_codec = _codec;
|
||||||
|
avatarAudioStream->_selectedCodecName = _selectedCodecName;
|
||||||
|
qDebug() << "creating new AvatarAudioStream... codec:" << avatarAudioStream->_selectedCodecName;
|
||||||
|
|
||||||
auto emplaced = _audioStreams.emplace(
|
auto emplaced = _audioStreams.emplace(
|
||||||
QUuid(),
|
QUuid(),
|
||||||
std::unique_ptr<PositionalAudioStream> { new AvatarAudioStream(isStereo, AudioMixer::getStreamSettings()) }
|
std::unique_ptr<PositionalAudioStream> { avatarAudioStream }
|
||||||
);
|
);
|
||||||
|
|
||||||
micStreamIt = emplaced.first;
|
micStreamIt = emplaced.first;
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include <AudioLimiter.h>
|
#include <AudioLimiter.h>
|
||||||
#include <UUIDHasher.h>
|
#include <UUIDHasher.h>
|
||||||
|
|
||||||
|
#include <plugins/CodecPlugin.h>
|
||||||
|
|
||||||
#include "PositionalAudioStream.h"
|
#include "PositionalAudioStream.h"
|
||||||
#include "AvatarAudioStream.h"
|
#include "AvatarAudioStream.h"
|
||||||
|
|
||||||
|
@ -65,6 +67,11 @@ public:
|
||||||
|
|
||||||
AudioLimiter audioLimiter;
|
AudioLimiter audioLimiter;
|
||||||
|
|
||||||
|
// FIXME -- maybe make these private
|
||||||
|
CodecPluginPointer _codec;
|
||||||
|
QString _selectedCodecName;
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void injectorStreamFinished(const QUuid& streamIdentifier);
|
void injectorStreamFinished(const QUuid& streamIdentifier);
|
||||||
|
|
||||||
|
|
|
@ -837,7 +837,7 @@ void AudioClient::handleRecordedAudioInput(const QByteArray& audio) {
|
||||||
audioTransform.setTranslation(_positionGetter());
|
audioTransform.setTranslation(_positionGetter());
|
||||||
audioTransform.setRotation(_orientationGetter());
|
audioTransform.setRotation(_orientationGetter());
|
||||||
|
|
||||||
// TODO - codec decode goes here
|
// TODO - codec encode goes here
|
||||||
QByteArray encodedBuffer;
|
QByteArray encodedBuffer;
|
||||||
if (_codec) {
|
if (_codec) {
|
||||||
_codec->encode(audio, encodedBuffer);
|
_codec->encode(audio, encodedBuffer);
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
set(TARGET_NAME audio)
|
set(TARGET_NAME audio)
|
||||||
setup_hifi_library(Network)
|
setup_hifi_library(Network)
|
||||||
link_hifi_libraries(networking shared)
|
link_hifi_libraries(networking shared plugins)
|
||||||
|
|
|
@ -178,7 +178,16 @@ int InboundAudioStream::parseStreamProperties(PacketType type, const QByteArray&
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) {
|
int InboundAudioStream::parseAudioData(PacketType type, const QByteArray& packetAfterStreamProperties, int numAudioSamples) {
|
||||||
return _ringBuffer.writeData(packetAfterStreamProperties.data(), numAudioSamples * sizeof(int16_t));
|
|
||||||
|
// codec decode goes here
|
||||||
|
QByteArray decodedBuffer;
|
||||||
|
if (_codec) {
|
||||||
|
_codec->decode(packetAfterStreamProperties, decodedBuffer);
|
||||||
|
} else {
|
||||||
|
decodedBuffer = packetAfterStreamProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _ringBuffer.writeData(decodedBuffer.data(), numAudioSamples * sizeof(int16_t)); // FIXME?
|
||||||
}
|
}
|
||||||
|
|
||||||
int InboundAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
int InboundAudioStream::writeDroppableSilentSamples(int silentSamples) {
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include <ReceivedMessage.h>
|
#include <ReceivedMessage.h>
|
||||||
#include <StDev.h>
|
#include <StDev.h>
|
||||||
|
|
||||||
|
#include <plugins/CodecPlugin.h>
|
||||||
|
|
||||||
#include "AudioRingBuffer.h"
|
#include "AudioRingBuffer.h"
|
||||||
#include "MovingMinMaxAvg.h"
|
#include "MovingMinMaxAvg.h"
|
||||||
#include "SequenceNumberStats.h"
|
#include "SequenceNumberStats.h"
|
||||||
|
@ -174,6 +176,10 @@ public:
|
||||||
void setReverb(float reverbTime, float wetLevel);
|
void setReverb(float reverbTime, float wetLevel);
|
||||||
void clearReverb() { _hasReverb = false; }
|
void clearReverb() { _hasReverb = false; }
|
||||||
|
|
||||||
|
// FIXME -- maybe make these private
|
||||||
|
CodecPluginPointer _codec;
|
||||||
|
QString _selectedCodecName;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/// This function should be called every second for all the stats to function properly. If dynamic jitter buffers
|
/// This function should be called every second for all the stats to function properly. If dynamic jitter buffers
|
||||||
/// is enabled, those stats are used to calculate _desiredJitterBufferFrames.
|
/// is enabled, those stats are used to calculate _desiredJitterBufferFrames.
|
||||||
|
|
|
@ -39,13 +39,17 @@ bool PCMCodecManager::isSupported() const {
|
||||||
|
|
||||||
|
|
||||||
void PCMCodecManager::decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) {
|
void PCMCodecManager::decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) {
|
||||||
qDebug() << __FUNCTION__ << "encodedBuffer:" << encodedBuffer.size();
|
|
||||||
// this codec doesn't actually do anything....
|
// this codec doesn't actually do anything....
|
||||||
decodedBuffer = encodedBuffer;
|
decodedBuffer = encodedBuffer;
|
||||||
|
|
||||||
|
//decodedBuffer = qUncompress(encodedBuffer);
|
||||||
|
//qDebug() << __FUNCTION__ << "from:" << encodedBuffer.size() << " to:" << decodedBuffer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCMCodecManager::encode(const QByteArray& decodedBuffer, QByteArray& encodedBuffer) {
|
void PCMCodecManager::encode(const QByteArray& decodedBuffer, QByteArray& encodedBuffer) {
|
||||||
qDebug() << __FUNCTION__ << "decodedBuffer:" << decodedBuffer.size();
|
|
||||||
// this codec doesn't actually do anything....
|
// this codec doesn't actually do anything....
|
||||||
encodedBuffer = decodedBuffer;
|
encodedBuffer = decodedBuffer;
|
||||||
|
|
||||||
|
//encodedBuffer = qCompress(decodedBuffer);
|
||||||
|
//qDebug() << __FUNCTION__ << "from:" << decodedBuffer.size() << " to:" << encodedBuffer.size();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue