mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
first cut at codec plugins
This commit is contained in:
parent
64771428ec
commit
be37921845
12 changed files with 224 additions and 7 deletions
|
@ -85,6 +85,7 @@
|
|||
#include <PhysicsEngine.h>
|
||||
#include <PhysicsHelpers.h>
|
||||
#include <plugins/PluginManager.h>
|
||||
#include <plugins/CodecPlugin.h>
|
||||
#include <RenderableWebEntityItem.h>
|
||||
#include <RenderShadowTask.h>
|
||||
#include <RenderDeferredTask.h>
|
||||
|
@ -1236,7 +1237,13 @@ QString Application::getUserAgent() {
|
|||
userAgent += " " + formatPluginName(ip->getName());
|
||||
}
|
||||
}
|
||||
// for codecs, we include all of them, even if not active
|
||||
auto codecPlugins = PluginManager::getInstance()->getCodecPlugins();
|
||||
for (auto& cp : codecPlugins) {
|
||||
userAgent += " " + formatPluginName(cp->getName());
|
||||
}
|
||||
|
||||
qDebug() << __FUNCTION__ << ":" << userAgent;
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
|
|
|
@ -813,19 +813,25 @@ void AudioClient::handleRecordedAudioInput(const QByteArray& audio) {
|
|||
emitAudioPacket(audio.data(), audio.size(), _outgoingAvatarAudioSequenceNumber, audioTransform, PacketType::MicrophoneAudioWithEcho);
|
||||
}
|
||||
|
||||
void AudioClient::processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer) {
|
||||
const int numNetworkOutputSamples = inputBuffer.size() / sizeof(int16_t);
|
||||
const int numDeviceOutputSamples = numNetworkOutputSamples * (_outputFormat.sampleRate() * _outputFormat.channelCount())
|
||||
/ (_desiredOutputFormat.sampleRate() * _desiredOutputFormat.channelCount());
|
||||
void AudioClient::processReceivedSamples(const QByteArray& networkBuffer, QByteArray& outputBuffer) {
|
||||
|
||||
// TODO - codec decode goes here
|
||||
QByteArray decodedBuffer = networkBuffer;
|
||||
|
||||
const int numDecodecSamples = decodedBuffer.size() / sizeof(int16_t);
|
||||
const int numDeviceOutputSamples = _outputFrameSize;
|
||||
|
||||
Q_ASSERT(_outputFrameSize == numDecodecSamples * (_outputFormat.sampleRate() * _outputFormat.channelCount())
|
||||
/ (_desiredOutputFormat.sampleRate() * _desiredOutputFormat.channelCount()));
|
||||
|
||||
outputBuffer.resize(numDeviceOutputSamples * sizeof(int16_t));
|
||||
|
||||
const int16_t* receivedSamples = reinterpret_cast<const int16_t*>(inputBuffer.data());
|
||||
const int16_t* decodedSamples = reinterpret_cast<const int16_t*>(decodedBuffer.data());
|
||||
int16_t* outputSamples = reinterpret_cast<int16_t*>(outputBuffer.data());
|
||||
|
||||
// copy the packet from the RB to the output
|
||||
possibleResampling(_networkToOutputResampler, receivedSamples, outputSamples,
|
||||
numNetworkOutputSamples, numDeviceOutputSamples,
|
||||
possibleResampling(_networkToOutputResampler, decodedSamples, outputSamples,
|
||||
numDecodecSamples, numDeviceOutputSamples,
|
||||
_desiredOutputFormat, _outputFormat);
|
||||
|
||||
// apply stereo reverb at the listener, to the received audio
|
||||
|
|
19
libraries/plugins/src/plugins/CodecPlugin.h
Normal file
19
libraries/plugins/src/plugins/CodecPlugin.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
//
|
||||
// CodecPlugin.h
|
||||
// plugins/src/plugins
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 6/9/2016
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "Plugin.h"
|
||||
|
||||
class CodecPlugin : public Plugin {
|
||||
public:
|
||||
virtual void decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) = 0;
|
||||
};
|
||||
|
|
@ -13,10 +13,12 @@
|
|||
enum class PluginType {
|
||||
DISPLAY_PLUGIN,
|
||||
INPUT_PLUGIN,
|
||||
CODEC_PLUGIN,
|
||||
};
|
||||
|
||||
class DisplayPlugin;
|
||||
class InputPlugin;
|
||||
class CodecPlugin;
|
||||
class Plugin;
|
||||
class PluginContainer;
|
||||
class PluginManager;
|
||||
|
@ -25,4 +27,6 @@ using DisplayPluginPointer = std::shared_ptr<DisplayPlugin>;
|
|||
using DisplayPluginList = std::vector<DisplayPluginPointer>;
|
||||
using InputPluginPointer = std::shared_ptr<InputPlugin>;
|
||||
using InputPluginList = std::vector<InputPluginPointer>;
|
||||
using CodecPluginPointer = std::shared_ptr<CodecPlugin>;
|
||||
using CodecPluginList = std::vector<CodecPluginPointer>;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <UserActivityLogger.h>
|
||||
|
||||
#include "RuntimePlugin.h"
|
||||
#include "CodecPlugin.h"
|
||||
#include "DisplayPlugin.h"
|
||||
#include "InputPlugin.h"
|
||||
|
||||
|
@ -117,6 +118,7 @@ PluginManager::PluginManager() {
|
|||
// TODO migrate to a DLL model where plugins are discovered and loaded at runtime by the PluginManager class
|
||||
extern DisplayPluginList getDisplayPlugins();
|
||||
extern InputPluginList getInputPlugins();
|
||||
extern CodecPluginList getCodecPlugins();
|
||||
extern void saveInputPluginSettings(const InputPluginList& plugins);
|
||||
static DisplayPluginList displayPlugins;
|
||||
|
||||
|
@ -202,6 +204,34 @@ const InputPluginList& PluginManager::getInputPlugins() {
|
|||
return inputPlugins;
|
||||
}
|
||||
|
||||
const CodecPluginList& PluginManager::getCodecPlugins() {
|
||||
static CodecPluginList codecPlugins;
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [&] {
|
||||
//codecPlugins = ::getCodecPlugins();
|
||||
|
||||
// Now grab the dynamic plugins
|
||||
for (auto loader : getLoadedPlugins()) {
|
||||
CodecProvider* codecProvider = qobject_cast<CodecProvider*>(loader->instance());
|
||||
if (codecProvider) {
|
||||
for (auto codecPlugin : codecProvider->getCodecPlugins()) {
|
||||
if (codecPlugin->isSupported()) {
|
||||
codecPlugins.push_back(codecPlugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto& container = PluginContainer::getInstance();
|
||||
for (auto plugin : codecPlugins) {
|
||||
plugin->setContainer(&container);
|
||||
plugin->init();
|
||||
}
|
||||
});
|
||||
return codecPlugins;
|
||||
}
|
||||
|
||||
|
||||
void PluginManager::setPreferredDisplayPlugins(const QStringList& displays) {
|
||||
preferredDisplayPlugins = displays;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
|
||||
const DisplayPluginList& getDisplayPlugins();
|
||||
const InputPluginList& getInputPlugins();
|
||||
const CodecPluginList& getCodecPlugins();
|
||||
|
||||
DisplayPluginList getPreferredDisplayPlugins();
|
||||
void setPreferredDisplayPlugins(const QStringList& displays);
|
||||
|
|
|
@ -34,3 +34,12 @@ public:
|
|||
#define InputProvider_iid "com.highfidelity.plugins.input"
|
||||
Q_DECLARE_INTERFACE(InputProvider, InputProvider_iid)
|
||||
|
||||
class CodecProvider {
|
||||
public:
|
||||
virtual ~CodecProvider() {}
|
||||
virtual CodecPluginList getCodecPlugins() = 0;
|
||||
};
|
||||
|
||||
#define CodecProvider_iid "com.highfidelity.plugins.codec"
|
||||
Q_DECLARE_INTERFACE(CodecProvider, CodecProvider_iid)
|
||||
|
||||
|
|
11
plugins/pcmCodec/CMakeLists.txt
Normal file
11
plugins/pcmCodec/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
#
|
||||
# Created by Brad Hefta-Gaub on 6/9/2016
|
||||
# Copyright 2016 High Fidelity, Inc.
|
||||
#
|
||||
# Distributed under the Apache License, Version 2.0.
|
||||
# See the accompanying file LICENSE or http:#www.apache.org/licenses/LICENSE-2.0.html
|
||||
#
|
||||
|
||||
set(TARGET_NAME pcmCodec)
|
||||
setup_hifi_plugin()
|
||||
link_hifi_libraries(shared plugins)
|
45
plugins/pcmCodec/src/PCMCodecManager.cpp
Normal file
45
plugins/pcmCodec/src/PCMCodecManager.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// PCMCodecManager.cpp
|
||||
// plugins/pcmCodec/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 6/9/2016
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <PerfStat.h>
|
||||
|
||||
#include "PCMCodecManager.h"
|
||||
|
||||
const QString PCMCodecManager::NAME = "PCM Codec";
|
||||
|
||||
void PCMCodecManager::init() {
|
||||
}
|
||||
|
||||
void PCMCodecManager::deinit() {
|
||||
}
|
||||
|
||||
bool PCMCodecManager::activate() {
|
||||
CodecPlugin::activate();
|
||||
return true;
|
||||
}
|
||||
|
||||
void PCMCodecManager::deactivate() {
|
||||
CodecPlugin::deactivate();
|
||||
}
|
||||
|
||||
|
||||
bool PCMCodecManager::isSupported() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PCMCodecManager::decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) {
|
||||
// this codec doesn't actually do anything....
|
||||
decodedBuffer = encodedBuffer;
|
||||
}
|
||||
|
40
plugins/pcmCodec/src/PCMCodecManager.h
Normal file
40
plugins/pcmCodec/src/PCMCodecManager.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// PCMCodecManager.h
|
||||
// plugins/pcmCodec/src
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 6/9/2016
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi__PCMCodecManager_h
|
||||
#define hifi__PCMCodecManager_h
|
||||
|
||||
|
||||
#include <plugins/CodecPlugin.h>
|
||||
|
||||
class PCMCodecManager : public CodecPlugin {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Plugin functions
|
||||
bool isSupported() const override;
|
||||
const QString& getName() const override { return NAME; }
|
||||
|
||||
void init() override;
|
||||
void deinit() override;
|
||||
|
||||
/// Called when a plugin is being activated for use. May be called multiple times.
|
||||
bool activate() override;
|
||||
/// Called when a plugin is no longer being used. May be called multiple times.
|
||||
void deactivate() override;
|
||||
|
||||
virtual void decode(const QByteArray& encodedBuffer, QByteArray& decodedBuffer) override;
|
||||
|
||||
private:
|
||||
static const QString NAME;
|
||||
};
|
||||
|
||||
#endif // hifi__PCMCodecManager_h
|
44
plugins/pcmCodec/src/PCMCodecProvider.cpp
Normal file
44
plugins/pcmCodec/src/PCMCodecProvider.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// Created by Brad Hefta-Gaub on 6/9/2016
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#include <plugins/RuntimePlugin.h>
|
||||
#include <plugins/CodecPlugin.h>
|
||||
|
||||
#include "PCMCodecManager.h"
|
||||
|
||||
class PCMCodecProvider : public QObject, public CodecProvider {
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID CodecProvider_iid FILE "plugin.json")
|
||||
Q_INTERFACES(CodecProvider)
|
||||
|
||||
public:
|
||||
PCMCodecProvider(QObject* parent = nullptr) : QObject(parent) {}
|
||||
virtual ~PCMCodecProvider() {}
|
||||
|
||||
virtual CodecPluginList getCodecPlugins() override {
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [&] {
|
||||
CodecPluginPointer plugin(new PCMCodecManager());
|
||||
if (plugin->isSupported()) {
|
||||
_codecPlugins.push_back(plugin);
|
||||
}
|
||||
});
|
||||
return _codecPlugins;
|
||||
}
|
||||
|
||||
private:
|
||||
CodecPluginList _codecPlugins;
|
||||
};
|
||||
|
||||
#include "PCMCodecProvider.moc"
|
1
plugins/pcmCodec/src/plugin.json
Normal file
1
plugins/pcmCodec/src/plugin.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"name":"PCM Codec"}
|
Loading…
Reference in a new issue