mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 23:54:14 +02:00
fix audio and audio-client compile for android
This commit is contained in:
parent
6efa47a04e
commit
dae40c944b
3 changed files with 50 additions and 44 deletions
|
@ -1,3 +1,8 @@
|
||||||
set(TARGET_NAME audio)
|
set(TARGET_NAME audio)
|
||||||
setup_hifi_library(Network)
|
setup_hifi_library(Network)
|
||||||
|
|
||||||
|
if (ANDROID)
|
||||||
|
add_definitions("-D__STDC_CONSTANT_MACROS")
|
||||||
|
endif ()
|
||||||
|
|
||||||
link_hifi_libraries(networking shared plugins)
|
link_hifi_libraries(networking shared plugins)
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "AudioInjector.h"
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
#include <QtCore/QDataStream>
|
#include <QtCore/QDataStream>
|
||||||
|
|
||||||
|
@ -24,8 +26,6 @@
|
||||||
#include "SoundCache.h"
|
#include "SoundCache.h"
|
||||||
#include "AudioSRC.h"
|
#include "AudioSRC.h"
|
||||||
|
|
||||||
#include "AudioInjector.h"
|
|
||||||
|
|
||||||
int audioInjectorPtrMetaTypeId = qRegisterMetaType<AudioInjector*>();
|
int audioInjectorPtrMetaTypeId = qRegisterMetaType<AudioInjector*>();
|
||||||
|
|
||||||
AudioInjectorState operator& (AudioInjectorState lhs, AudioInjectorState rhs) {
|
AudioInjectorState operator& (AudioInjectorState lhs, AudioInjectorState rhs) {
|
||||||
|
@ -52,7 +52,7 @@ AudioInjector::AudioInjector(const Sound& sound, const AudioInjectorOptions& inj
|
||||||
|
|
||||||
AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions) :
|
AudioInjector::AudioInjector(const QByteArray& audioData, const AudioInjectorOptions& injectorOptions) :
|
||||||
_audioData(audioData),
|
_audioData(audioData),
|
||||||
_options(injectorOptions)
|
_options(injectorOptions)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ bool AudioInjector::stateHas(AudioInjectorState state) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::setOptions(const AudioInjectorOptions& options) {
|
void AudioInjector::setOptions(const AudioInjectorOptions& options) {
|
||||||
// since options.stereo is computed from the audio stream,
|
// since options.stereo is computed from the audio stream,
|
||||||
// we need to copy it from existing options just in case.
|
// we need to copy it from existing options just in case.
|
||||||
bool currentlyStereo = _options.stereo;
|
bool currentlyStereo = _options.stereo;
|
||||||
_options = options;
|
_options = options;
|
||||||
|
@ -71,7 +71,7 @@ void AudioInjector::setOptions(const AudioInjectorOptions& options) {
|
||||||
|
|
||||||
void AudioInjector::finishNetworkInjection() {
|
void AudioInjector::finishNetworkInjection() {
|
||||||
_state |= AudioInjectorState::NetworkInjectionFinished;
|
_state |= AudioInjectorState::NetworkInjectionFinished;
|
||||||
|
|
||||||
// if we are already finished with local
|
// if we are already finished with local
|
||||||
// injection, then we are finished
|
// injection, then we are finished
|
||||||
if(stateHas(AudioInjectorState::LocalInjectionFinished)) {
|
if(stateHas(AudioInjectorState::LocalInjectionFinished)) {
|
||||||
|
@ -154,13 +154,13 @@ void AudioInjector::restart() {
|
||||||
_hasSetup = false;
|
_hasSetup = false;
|
||||||
_shouldStop = false;
|
_shouldStop = false;
|
||||||
_state = AudioInjectorState::NotFinished;
|
_state = AudioInjectorState::NotFinished;
|
||||||
|
|
||||||
// call inject audio to start injection over again
|
// call inject audio to start injection over again
|
||||||
setupInjection();
|
setupInjection();
|
||||||
|
|
||||||
// inject locally
|
// inject locally
|
||||||
if(injectLocally()) {
|
if(injectLocally()) {
|
||||||
|
|
||||||
// if not localOnly, wake the AudioInjectorManager back up if it is stuck waiting
|
// if not localOnly, wake the AudioInjectorManager back up if it is stuck waiting
|
||||||
if (!_options.localOnly) {
|
if (!_options.localOnly) {
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ qint64 writeStringToStream(const QString& string, QDataStream& stream) {
|
||||||
stream << static_cast<quint32>(length);
|
stream << static_cast<quint32>(length);
|
||||||
} else {
|
} else {
|
||||||
// http://doc.qt.io/qt-5/datastreamformat.html
|
// http://doc.qt.io/qt-5/datastreamformat.html
|
||||||
// QDataStream << QByteArray -
|
// QDataStream << QByteArray -
|
||||||
// If the byte array is null : 0xFFFFFFFF (quint32)
|
// If the byte array is null : 0xFFFFFFFF (quint32)
|
||||||
// Otherwise : the array size(quint32) followed by the array bytes, i.e.size bytes
|
// Otherwise : the array size(quint32) followed by the array bytes, i.e.size bytes
|
||||||
stream << data;
|
stream << data;
|
||||||
|
@ -239,7 +239,7 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
static int positionOptionOffset = -1;
|
static int positionOptionOffset = -1;
|
||||||
static int volumeOptionOffset = -1;
|
static int volumeOptionOffset = -1;
|
||||||
static int audioDataOffset = -1;
|
static int audioDataOffset = -1;
|
||||||
|
|
||||||
if (!_currentPacket) {
|
if (!_currentPacket) {
|
||||||
if (_currentSendOffset < 0 ||
|
if (_currentSendOffset < 0 ||
|
||||||
_currentSendOffset >= _audioData.size()) {
|
_currentSendOffset >= _audioData.size()) {
|
||||||
|
@ -277,7 +277,7 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
|
|
||||||
// current injectors don't use codecs, so pack in the unknown codec name
|
// current injectors don't use codecs, so pack in the unknown codec name
|
||||||
QString noCodecForInjectors("");
|
QString noCodecForInjectors("");
|
||||||
writeStringToStream(noCodecForInjectors, audioPacketStream);
|
writeStringToStream(noCodecForInjectors, audioPacketStream);
|
||||||
|
|
||||||
// pack stream identifier (a generated UUID)
|
// pack stream identifier (a generated UUID)
|
||||||
audioPacketStream << QUuid::createUuid();
|
audioPacketStream << QUuid::createUuid();
|
||||||
|
@ -286,7 +286,7 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
audioPacketStream << _options.stereo;
|
audioPacketStream << _options.stereo;
|
||||||
|
|
||||||
// pack the flag for loopback. Now, we don't loopback
|
// pack the flag for loopback. Now, we don't loopback
|
||||||
// and _always_ play locally, so loopbackFlag should be
|
// and _always_ play locally, so loopbackFlag should be
|
||||||
// false always.
|
// false always.
|
||||||
uchar loopbackFlag = (uchar)false;
|
uchar loopbackFlag = (uchar)false;
|
||||||
audioPacketStream << loopbackFlag;
|
audioPacketStream << loopbackFlag;
|
||||||
|
@ -365,7 +365,7 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
_currentSendOffset = 0;
|
_currentSendOffset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME -- good place to call codec encode here. We need to figure out how to tell the AudioInjector which
|
// FIXME -- good place to call codec encode here. We need to figure out how to tell the AudioInjector which
|
||||||
// codec to use... possible through AbstractAudioInterface.
|
// codec to use... possible through AbstractAudioInterface.
|
||||||
QByteArray encodedAudio = decodedAudio;
|
QByteArray encodedAudio = decodedAudio;
|
||||||
_currentPacket->write(encodedAudio.data(), encodedAudio.size());
|
_currentPacket->write(encodedAudio.data(), encodedAudio.size());
|
||||||
|
@ -407,7 +407,7 @@ int64_t AudioInjector::injectNextFrame() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t playNextFrameAt = ++_nextFrame * AudioConstants::NETWORK_FRAME_USECS;
|
int64_t playNextFrameAt = ++_nextFrame * AudioConstants::NETWORK_FRAME_USECS;
|
||||||
|
|
||||||
return std::max(INT64_C(0), playNextFrameAt - currentTime);
|
return std::max(INT64_C(0), playNextFrameAt - currentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,7 +491,7 @@ AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInj
|
||||||
|
|
||||||
// we always inject locally, except when there is no localInterface
|
// we always inject locally, except when there is no localInterface
|
||||||
injector->injectLocally();
|
injector->injectLocally();
|
||||||
|
|
||||||
// if localOnly, we are done, just return injector.
|
// if localOnly, we are done, just return injector.
|
||||||
if (!options.localOnly) {
|
if (!options.localOnly) {
|
||||||
|
|
||||||
|
|
|
@ -115,12 +115,42 @@ const LoaderList& getLoadedPlugins() {
|
||||||
PluginManager::PluginManager() {
|
PluginManager::PluginManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern CodecPluginList getCodecPlugins();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto plugin : codecPlugins) {
|
||||||
|
plugin->setContainer(_container);
|
||||||
|
plugin->init();
|
||||||
|
|
||||||
|
qDebug() << "init codec:" << plugin->getName();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return codecPlugins;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#ifndef Q_OS_ANDROID
|
||||||
|
|
||||||
// TODO migrate to a DLL model where plugins are discovered and loaded at runtime by the PluginManager class
|
// TODO migrate to a DLL model where plugins are discovered and loaded at runtime by the PluginManager class
|
||||||
extern DisplayPluginList getDisplayPlugins();
|
extern DisplayPluginList getDisplayPlugins();
|
||||||
extern InputPluginList getInputPlugins();
|
extern InputPluginList getInputPlugins();
|
||||||
extern CodecPluginList getCodecPlugins();
|
|
||||||
extern void saveInputPluginSettings(const InputPluginList& plugins);
|
extern void saveInputPluginSettings(const InputPluginList& plugins);
|
||||||
static DisplayPluginList displayPlugins;
|
static DisplayPluginList displayPlugins;
|
||||||
|
|
||||||
|
@ -207,35 +237,6 @@ const InputPluginList& PluginManager::getInputPlugins() {
|
||||||
return inputPlugins;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto plugin : codecPlugins) {
|
|
||||||
plugin->setContainer(_container);
|
|
||||||
plugin->init();
|
|
||||||
|
|
||||||
qDebug() << "init codec:" << plugin->getName();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return codecPlugins;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PluginManager::setPreferredDisplayPlugins(const QStringList& displays) {
|
void PluginManager::setPreferredDisplayPlugins(const QStringList& displays) {
|
||||||
preferredDisplayPlugins = displays;
|
preferredDisplayPlugins = displays;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue