more codec plumbing

This commit is contained in:
Brad Hefta-Gaub 2016-07-07 21:24:24 -07:00
parent 38f0cd218b
commit 3c6447326e
8 changed files with 68 additions and 11 deletions

View file

@ -477,21 +477,39 @@ void AudioMixer::handleNegotiateAudioFormat(QSharedPointer<ReceivedMessage> mess
}
qDebug() << "all requested codecs:" << codecList;
CodecPluginPointer selectedCoded;
QString selectedCodecName;
auto codecPlugins = PluginManager::getInstance()->getCodecPlugins();
if (codecPlugins.size() > 0) {
for (auto& plugin : codecPlugins) {
qDebug() << "Codec available:" << plugin->getName();
// choose first codec
if (!selectedCoded) {
selectedCoded = plugin;
selectedCodecName = plugin->getName();
}
}
} else {
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);
// write them to our packet
QString selectedCodec = codecList.front();
qDebug() << "selectedCodec:" << selectedCodec;
replyPacket->writeString(selectedCodec);
replyPacket->writeString(selectedCodecName);
auto nodeList = DependencyManager::get<NodeList>();
nodeList->sendPacket(std::move(replyPacket), *sendingNode);
@ -720,9 +738,17 @@ void AudioMixer::broadcastMixes() {
quint16 sequence = nodeData->getOutgoingSequenceNumber();
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
mixPacket->write(reinterpret_cast<char*>(_clampedSamples),
AudioConstants::NETWORK_FRAME_BYTES_STEREO);
mixPacket->write(encodedBuffer.constData(), encodedBuffer.size());
} else {
int silentPacketBytes = sizeof(quint16) + sizeof(quint16);
mixPacket = NLPacket::create(PacketType::SilentAudioFrame, silentPacketBytes);

View file

@ -101,9 +101,14 @@ int AudioMixerClientData::parseData(ReceivedMessage& message) {
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(
QUuid(),
std::unique_ptr<PositionalAudioStream> { new AvatarAudioStream(isStereo, AudioMixer::getStreamSettings()) }
std::unique_ptr<PositionalAudioStream> { avatarAudioStream }
);
micStreamIt = emplaced.first;

View file

@ -19,6 +19,8 @@
#include <AudioLimiter.h>
#include <UUIDHasher.h>
#include <plugins/CodecPlugin.h>
#include "PositionalAudioStream.h"
#include "AvatarAudioStream.h"
@ -65,6 +67,11 @@ public:
AudioLimiter audioLimiter;
// FIXME -- maybe make these private
CodecPluginPointer _codec;
QString _selectedCodecName;
signals:
void injectorStreamFinished(const QUuid& streamIdentifier);

View file

@ -837,7 +837,7 @@ void AudioClient::handleRecordedAudioInput(const QByteArray& audio) {
audioTransform.setTranslation(_positionGetter());
audioTransform.setRotation(_orientationGetter());
// TODO - codec decode goes here
// TODO - codec encode goes here
QByteArray encodedBuffer;
if (_codec) {
_codec->encode(audio, encodedBuffer);

View file

@ -1,3 +1,3 @@
set(TARGET_NAME audio)
setup_hifi_library(Network)
link_hifi_libraries(networking shared)
link_hifi_libraries(networking shared plugins)

View file

@ -178,7 +178,16 @@ int InboundAudioStream::parseStreamProperties(PacketType type, const QByteArray&
}
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) {

View file

@ -18,6 +18,8 @@
#include <ReceivedMessage.h>
#include <StDev.h>
#include <plugins/CodecPlugin.h>
#include "AudioRingBuffer.h"
#include "MovingMinMaxAvg.h"
#include "SequenceNumberStats.h"
@ -174,6 +176,10 @@ public:
void setReverb(float reverbTime, float wetLevel);
void clearReverb() { _hasReverb = false; }
// FIXME -- maybe make these private
CodecPluginPointer _codec;
QString _selectedCodecName;
public slots:
/// 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.

View file

@ -39,13 +39,17 @@ bool PCMCodecManager::isSupported() const {
void PCMCodecManager::decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) {
qDebug() << __FUNCTION__ << "encodedBuffer:" << encodedBuffer.size();
// this codec doesn't actually do anything....
decodedBuffer = encodedBuffer;
//decodedBuffer = qUncompress(encodedBuffer);
//qDebug() << __FUNCTION__ << "from:" << encodedBuffer.size() << " to:" << decodedBuffer.size();
}
void PCMCodecManager::encode(const QByteArray& decodedBuffer, QByteArray& encodedBuffer) {
qDebug() << __FUNCTION__ << "decodedBuffer:" << decodedBuffer.size();
// this codec doesn't actually do anything....
encodedBuffer = decodedBuffer;
//encodedBuffer = qCompress(decodedBuffer);
//qDebug() << __FUNCTION__ << "from:" << decodedBuffer.size() << " to:" << encodedBuffer.size();
}