Merge pull request #14255 from zfox23/textToSpeech

Text to Speech App
This commit is contained in:
Zach Fox 2018-11-08 09:44:59 -08:00 committed by GitHub
commit b97fd6eb95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 608 additions and 35 deletions

View file

@ -216,7 +216,7 @@ void Agent::requestScript() {
}
// make sure this is not a script request for the file scheme
if (scriptURL.scheme() == URL_SCHEME_FILE) {
if (scriptURL.scheme() == HIFI_URL_SCHEME_FILE) {
qWarning() << "Cannot load script for Agent from local filesystem.";
scriptRequestFinished();
return;

View file

@ -0,0 +1,314 @@
//
// TTS.qml
//
// TTS App
//
// Created by Zach Fox on 2018-10-10
// Copyright 2018 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
//
import Hifi 1.0 as Hifi
import QtQuick 2.10
import QtQuick.Controls 2.3
import "qrc:////qml//styles-uit" as HifiStylesUit
import "qrc:////qml//controls-uit" as HifiControlsUit
import "qrc:////qml//controls" as HifiControls
Rectangle {
HifiStylesUit.HifiConstants { id: hifi; }
id: root;
// Style
color: hifi.colors.darkGray;
property bool keyboardRaised: false;
//
// TITLE BAR START
//
Item {
id: titleBarContainer;
// Size
width: root.width;
height: 50;
// Anchors
anchors.left: parent.left;
anchors.top: parent.top;
// Title bar text
HifiStylesUit.RalewaySemiBold {
id: titleBarText;
text: "Text-to-Speech";
// Text size
size: hifi.fontSizes.overlayTitle;
// Anchors
anchors.top: parent.top;
anchors.bottom: parent.bottom;
anchors.left: parent.left;
anchors.leftMargin: 16;
width: paintedWidth;
// Style
color: hifi.colors.lightGrayText;
// Alignment
horizontalAlignment: Text.AlignHLeft;
verticalAlignment: Text.AlignVCenter;
}
// Separator
HifiControlsUit.Separator {
anchors.left: parent.left;
anchors.right: parent.right;
anchors.bottom: parent.bottom;
}
}
//
// TITLE BAR END
//
Item {
id: tagButtonContainer;
anchors.top: titleBarContainer.bottom;
anchors.topMargin: 2;
anchors.left: parent.left;
anchors.right: parent.right;
height: 70;
HifiStylesUit.RalewaySemiBold {
id: tagButtonTitle;
text: "Insert Tag:";
// Text size
size: 18;
// Anchors
anchors.top: parent.top;
anchors.left: parent.left;
anchors.right: parent.right;
height: 35;
// Style
color: hifi.colors.lightGrayText;
// Alignment
horizontalAlignment: Text.AlignHCenter;
verticalAlignment: Text.AlignVCenter;
}
HifiControlsUit.Button {
id: pitch10Button;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.none;
colorScheme: hifi.colorSchemes.dark;
anchors.top: tagButtonTitle.bottom;
anchors.left: parent.left;
anchors.leftMargin: 3;
width: parent.width/6 - 6;
height: 30;
text: "Pitch 10";
onClicked: {
messageToSpeak.insert(messageToSpeak.cursorPosition, "<pitch absmiddle='10'/>");
}
}
HifiControlsUit.Button {
id: pitch0Button;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.none;
colorScheme: hifi.colorSchemes.dark;
anchors.top: tagButtonTitle.bottom;
anchors.left: pitch10Button.right;
anchors.leftMargin: 6;
width: parent.width/6 - anchors.leftMargin;
height: 30;
text: "Pitch 0";
onClicked: {
messageToSpeak.insert(messageToSpeak.cursorPosition, "<pitch absmiddle='0'/>");
}
}
HifiControlsUit.Button {
id: pitchNeg10Button;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.none;
colorScheme: hifi.colorSchemes.dark;
anchors.top: tagButtonTitle.bottom;
anchors.left: pitch0Button.right;
anchors.leftMargin: 6;
width: parent.width/6 - anchors.leftMargin;
height: 30;
text: "Pitch -10";
onClicked: {
messageToSpeak.insert(messageToSpeak.cursorPosition, "<pitch absmiddle='-10'/>");
}
}
HifiControlsUit.Button {
id: speed5Button;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.none;
colorScheme: hifi.colorSchemes.dark;
anchors.top: tagButtonTitle.bottom;
anchors.left: pitchNeg10Button.right;
anchors.leftMargin: 6;
width: parent.width/6 - anchors.leftMargin;
height: 30;
text: "Speed 5";
onClicked: {
messageToSpeak.insert(messageToSpeak.cursorPosition, "<rate absspeed='5'/>");
}
}
HifiControlsUit.Button {
id: speed0Button;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.none;
colorScheme: hifi.colorSchemes.dark;
anchors.top: tagButtonTitle.bottom;
anchors.left: speed5Button.right;
anchors.leftMargin: 6;
width: parent.width/6 - anchors.leftMargin;
height: 30;
text: "Speed 0";
onClicked: {
messageToSpeak.insert(messageToSpeak.cursorPosition, "<rate absspeed='0'/>");
}
}
HifiControlsUit.Button {
id: speedNeg10Button;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.none;
colorScheme: hifi.colorSchemes.dark;
anchors.top: tagButtonTitle.bottom;
anchors.left: speed0Button.right;
anchors.leftMargin: 6;
width: parent.width/6 - anchors.leftMargin;
height: 30;
text: "Speed -10";
onClicked: {
messageToSpeak.insert(messageToSpeak.cursorPosition, "<rate absspeed='-10'/>");
}
}
}
Item {
anchors.top: tagButtonContainer.bottom;
anchors.topMargin: 8;
anchors.bottom: keyboardContainer.top;
anchors.bottomMargin: 16;
anchors.left: parent.left;
anchors.leftMargin: 16;
anchors.right: parent.right;
anchors.rightMargin: 16;
TextArea {
id: messageToSpeak;
font.family: "Fira Sans SemiBold";
font.pixelSize: 20;
// Anchors
anchors.top: parent.top;
anchors.left: parent.left;
anchors.right: parent.right;
anchors.bottom: speakButton.top;
anchors.bottomMargin: 8;
// Style
background: Rectangle {
anchors.fill: parent;
color: parent.activeFocus ? hifi.colors.black : hifi.colors.baseGrayShadow;
border.width: parent.activeFocus ? 1 : 0;
border.color: parent.activeFocus ? hifi.colors.primaryHighlight : hifi.colors.textFieldLightBackground;
}
color: hifi.colors.white;
textFormat: TextEdit.PlainText;
wrapMode: TextEdit.Wrap;
activeFocusOnPress: true;
activeFocusOnTab: true;
Keys.onPressed: {
if (event.key == Qt.Key_Return || event.key == Qt.Key_Enter) {
TextToSpeech.speakText(messageToSpeak.text, 480, 10, 24000, 16, true);
event.accepted = true;
}
}
HifiStylesUit.FiraSansRegular {
text: "<i>Input Text to Speak...</i>";
size: 20;
anchors.fill: parent;
anchors.topMargin: 4;
anchors.leftMargin: 4;
color: hifi.colors.lightGrayText;
visible: !parent.activeFocus && messageToSpeak.text === "";
verticalAlignment: Text.AlignTop;
}
}
HifiControlsUit.Button {
id: speakButton;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.blue;
colorScheme: hifi.colorSchemes.dark;
anchors.right: parent.right;
anchors.bottom: parent.bottom;
width: 215;
height: 40;
text: "Speak";
onClicked: {
TextToSpeech.speakText(messageToSpeak.text, 480, 10, 24000, 16, true);
}
}
HifiControlsUit.Button {
id: clearButton;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.white;
colorScheme: hifi.colorSchemes.dark;
anchors.right: speakButton.left;
anchors.rightMargin: 16;
anchors.bottom: parent.bottom;
width: 100;
height: 40;
text: "Clear";
onClicked: {
messageToSpeak.text = "";
}
}
HifiControlsUit.Button {
id: stopButton;
focusPolicy: Qt.NoFocus;
color: hifi.buttons.red;
colorScheme: hifi.colorSchemes.dark;
anchors.right: clearButton.left;
anchors.rightMargin: 16;
anchors.bottom: parent.bottom;
width: 100;
height: 40;
text: "Stop Last";
onClicked: {
TextToSpeech.stopLastSpeech();
}
}
}
Item {
id: keyboardContainer;
z: 998;
visible: keyboard.raised;
property bool punctuationMode: false;
anchors {
bottom: parent.bottom;
left: parent.left;
right: parent.right;
}
HifiControlsUit.Keyboard {
id: keyboard;
raised: HMD.mounted && root.keyboardRaised;
numeric: parent.punctuationMode;
anchors {
bottom: parent.bottom;
left: parent.left;
right: parent.right;
}
}
}
}

View file

@ -186,6 +186,7 @@
#include "scripting/RatesScriptingInterface.h"
#include "scripting/SelectionScriptingInterface.h"
#include "scripting/WalletScriptingInterface.h"
#include "scripting/TTSScriptingInterface.h"
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
#include "SpeechRecognizer.h"
#endif
@ -533,11 +534,11 @@ bool isDomainURL(QUrl url) {
if (url.scheme() == URL_SCHEME_HIFI) {
return true;
}
if (url.scheme() != URL_SCHEME_FILE) {
if (url.scheme() != HIFI_URL_SCHEME_FILE) {
// TODO -- once Octree::readFromURL no-longer takes over the main event-loop, serverless-domain urls can
// be loaded over http(s)
// && url.scheme() != URL_SCHEME_HTTP &&
// url.scheme() != URL_SCHEME_HTTPS
// && url.scheme() != HIFI_URL_SCHEME_HTTP &&
// url.scheme() != HIFI_URL_SCHEME_HTTPS
return false;
}
if (url.path().endsWith(".json", Qt::CaseInsensitive) ||
@ -948,6 +949,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
DependencyManager::set<Ledger>();
DependencyManager::set<Wallet>();
DependencyManager::set<WalletScriptingInterface>();
DependencyManager::set<TTSScriptingInterface>();
DependencyManager::set<FadeEffect>();
DependencyManager::set<ResourceRequestObserver>();
@ -1032,8 +1034,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
// If the URL scheme is http(s) or ftp, then use as is, else - treat it as a local file
// This is done so as not break previous command line scripts
if (testScriptPath.left(URL_SCHEME_HTTP.length()) == URL_SCHEME_HTTP ||
testScriptPath.left(URL_SCHEME_FTP.length()) == URL_SCHEME_FTP) {
if (testScriptPath.left(HIFI_URL_SCHEME_HTTP.length()) == HIFI_URL_SCHEME_HTTP ||
testScriptPath.left(HIFI_URL_SCHEME_FTP.length()) == HIFI_URL_SCHEME_FTP) {
setProperty(hifi::properties::TEST, QUrl::fromUserInput(testScriptPath));
} else if (QFileInfo(testScriptPath).exists()) {
@ -2927,7 +2929,7 @@ void Application::initializeUi() {
LoginDialog::registerType();
Tooltip::registerType();
UpdateDialog::registerType();
QmlContextCallback callback = [](QQmlContext* context) {
QmlContextCallback commerceCallback = [](QQmlContext* context) {
context->setContextProperty("Commerce", new QmlCommerce());
};
OffscreenQmlSurface::addWhitelistContextHandler({
@ -2953,7 +2955,13 @@ void Application::initializeUi() {
QUrl{ "hifi/dialogs/security/SecurityImageChange.qml" },
QUrl{ "hifi/dialogs/security/SecurityImageModel.qml" },
QUrl{ "hifi/dialogs/security/SecurityImageSelection.qml" },
}, callback);
}, commerceCallback);
QmlContextCallback ttsCallback = [](QQmlContext* context) {
context->setContextProperty("TextToSpeech", DependencyManager::get<TTSScriptingInterface>().data());
};
OffscreenQmlSurface::addWhitelistContextHandler({
QUrl{ "hifi/tts/TTS.qml" }
}, ttsCallback);
qmlRegisterType<ResourceImageItem>("Hifi", 1, 0, "ResourceImageItem");
qmlRegisterType<Preference>("Hifi", 1, 0, "Preference");
qmlRegisterType<WebBrowserSuggestionsEngine>("HifiWeb", 1, 0, "WebBrowserSuggestionsEngine");

View file

@ -122,8 +122,8 @@ void ATPAssetMigrator::loadEntityServerFile() {
QUrl migrationURL = QUrl(migrationURLString);
if (!_ignoredUrls.contains(migrationURL)
&& (migrationURL.scheme() == URL_SCHEME_HTTP || migrationURL.scheme() == URL_SCHEME_HTTPS
|| migrationURL.scheme() == URL_SCHEME_FILE || migrationURL.scheme() == URL_SCHEME_FTP)) {
&& (migrationURL.scheme() == HIFI_URL_SCHEME_HTTP || migrationURL.scheme() == HIFI_URL_SCHEME_HTTPS
|| migrationURL.scheme() == HIFI_URL_SCHEME_FILE || migrationURL.scheme() == HIFI_URL_SCHEME_FTP)) {
if (_pendingReplacements.contains(migrationURL)) {
// we already have a request out for this asset, just store the QJsonValueRef

View file

@ -0,0 +1,163 @@
//
// TTSScriptingInterface.cpp
// libraries/audio-client/src/scripting
//
// Created by Zach Fox on 2018-10-10.
// Copyright 2018 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 "TTSScriptingInterface.h"
#include "avatar/AvatarManager.h"
TTSScriptingInterface::TTSScriptingInterface() {
#ifdef WIN32
//
// Create text to speech engine
//
HRESULT hr = m_tts.CoCreateInstance(CLSID_SpVoice);
if (FAILED(hr)) {
qDebug() << "Text-to-speech engine creation failed.";
}
//
// Get token corresponding to default voice
//
hr = SpGetDefaultTokenFromCategoryId(SPCAT_VOICES, &m_voiceToken, FALSE);
if (FAILED(hr)) {
qDebug() << "Can't get default voice token.";
}
//
// Set default voice
//
hr = m_tts->SetVoice(m_voiceToken);
if (FAILED(hr)) {
qDebug() << "Can't set default voice.";
}
_lastSoundAudioInjectorUpdateTimer.setSingleShot(true);
connect(&_lastSoundAudioInjectorUpdateTimer, &QTimer::timeout, this, &TTSScriptingInterface::updateLastSoundAudioInjector);
#endif
}
TTSScriptingInterface::~TTSScriptingInterface() {
}
#ifdef WIN32
class ReleaseOnExit {
public:
ReleaseOnExit(IUnknown* p) : m_p(p) {}
~ReleaseOnExit() {
if (m_p) {
m_p->Release();
}
}
private:
IUnknown* m_p;
};
#endif
const int INJECTOR_INTERVAL_MS = 100;
void TTSScriptingInterface::updateLastSoundAudioInjector() {
if (_lastSoundAudioInjector) {
AudioInjectorOptions options;
options.position = DependencyManager::get<AvatarManager>()->getMyAvatarPosition();
_lastSoundAudioInjector->setOptions(options);
_lastSoundAudioInjectorUpdateTimer.start(INJECTOR_INTERVAL_MS);
}
}
void TTSScriptingInterface::speakText(const QString& textToSpeak) {
#ifdef WIN32
WAVEFORMATEX fmt;
fmt.wFormatTag = WAVE_FORMAT_PCM;
fmt.nSamplesPerSec = AudioConstants::SAMPLE_RATE;
fmt.wBitsPerSample = 16;
fmt.nChannels = 1;
fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8;
fmt.nAvgBytesPerSec = fmt.nSamplesPerSec * fmt.nBlockAlign;
fmt.cbSize = 0;
IStream* pStream = NULL;
ISpStream* pSpStream = nullptr;
HRESULT hr = CoCreateInstance(CLSID_SpStream, nullptr, CLSCTX_ALL, __uuidof(ISpStream), (void**)&pSpStream);
if (FAILED(hr)) {
qDebug() << "CoCreateInstance failed.";
}
ReleaseOnExit rSpStream(pSpStream);
pStream = SHCreateMemStream(NULL, 0);
if (nullptr == pStream) {
qDebug() << "SHCreateMemStream failed.";
}
hr = pSpStream->SetBaseStream(pStream, SPDFID_WaveFormatEx, &fmt);
if (FAILED(hr)) {
qDebug() << "Can't set base stream.";
}
hr = m_tts->SetOutput(pSpStream, true);
if (FAILED(hr)) {
qDebug() << "Can't set output stream.";
}
ReleaseOnExit rStream(pStream);
ULONG streamNumber;
hr = m_tts->Speak(reinterpret_cast<LPCWSTR>(textToSpeak.utf16()), SPF_IS_XML | SPF_ASYNC | SPF_PURGEBEFORESPEAK,
&streamNumber);
if (FAILED(hr)) {
qDebug() << "Speak failed.";
}
m_tts->WaitUntilDone(-1);
hr = pSpStream->GetBaseStream(&pStream);
if (FAILED(hr)) {
qDebug() << "Couldn't get base stream.";
}
hr = IStream_Reset(pStream);
if (FAILED(hr)) {
qDebug() << "Couldn't reset stream.";
}
ULARGE_INTEGER StreamSize;
StreamSize.LowPart = 0;
hr = IStream_Size(pStream, &StreamSize);
DWORD dwSize = StreamSize.QuadPart;
_lastSoundByteArray.resize(dwSize);
hr = IStream_Read(pStream, _lastSoundByteArray.data(), dwSize);
if (FAILED(hr)) {
qDebug() << "Couldn't read from stream.";
}
AudioInjectorOptions options;
options.position = DependencyManager::get<AvatarManager>()->getMyAvatarPosition();
if (_lastSoundAudioInjector) {
_lastSoundAudioInjector->stop();
_lastSoundAudioInjectorUpdateTimer.stop();
}
_lastSoundAudioInjector = AudioInjector::playSoundAndDelete(_lastSoundByteArray, options);
_lastSoundAudioInjectorUpdateTimer.start(INJECTOR_INTERVAL_MS);
#else
qDebug() << "Text-to-Speech isn't currently supported on non-Windows platforms.";
#endif
}
void TTSScriptingInterface::stopLastSpeech() {
if (_lastSoundAudioInjector) {
_lastSoundAudioInjector->stop();
_lastSoundAudioInjector = NULL;
}
}

View file

@ -0,0 +1,88 @@
// TTSScriptingInterface.h
// libraries/audio-client/src/scripting
//
// Created by Zach Fox on 2018-10-10.
// Copyright 2018 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_SpeechScriptingInterface_h
#define hifi_SpeechScriptingInterface_h
#include <QtCore/QObject>
#include <QTimer>
#include <DependencyManager.h>
#ifdef WIN32
#pragma warning(disable : 4996)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <sapi.h> // SAPI
#include <sphelper.h> // SAPI Helper
#endif
#include <AudioInjector.h>
#include <AudioConstants.h>
class TTSScriptingInterface : public QObject, public Dependency {
Q_OBJECT
public:
TTSScriptingInterface();
~TTSScriptingInterface();
Q_INVOKABLE void speakText(const QString& textToSpeak);
Q_INVOKABLE void stopLastSpeech();
private:
#ifdef WIN32
class CComAutoInit {
public:
// Initializes COM using CoInitialize.
// On failure, signals error using AtlThrow.
CComAutoInit() {
HRESULT hr = ::CoInitialize(NULL);
if (FAILED(hr)) {
ATLTRACE(TEXT("CoInitialize() failed in CComAutoInit constructor (hr=0x%08X).\n"), hr);
AtlThrow(hr);
}
}
// Initializes COM using CoInitializeEx.
// On failure, signals error using AtlThrow.
explicit CComAutoInit(__in DWORD dwCoInit) {
HRESULT hr = ::CoInitializeEx(NULL, dwCoInit);
if (FAILED(hr)) {
ATLTRACE(TEXT("CoInitializeEx() failed in CComAutoInit constructor (hr=0x%08X).\n"), hr);
AtlThrow(hr);
}
}
// Uninitializes COM using CoUninitialize.
~CComAutoInit() { ::CoUninitialize(); }
//
// Ban copy
//
private:
CComAutoInit(const CComAutoInit&);
};
// COM initialization and cleanup (must precede other COM related data members)
CComAutoInit m_comInit;
// Text to speech engine
CComPtr<ISpVoice> m_tts;
// Default voice token
CComPtr<ISpObjectToken> m_voiceToken;
#endif
QByteArray _lastSoundByteArray;
AudioInjectorPointer _lastSoundAudioInjector;
QTimer _lastSoundAudioInjectorUpdateTimer;
void updateLastSoundAudioInjector();
};
#endif // hifi_SpeechScriptingInterface_h

View file

@ -54,7 +54,7 @@ WebEntityRenderer::ContentType WebEntityRenderer::getContentType(const QString&
const QUrl url(urlString);
auto scheme = url.scheme();
if (scheme == URL_SCHEME_ABOUT || scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS ||
if (scheme == HIFI_URL_SCHEME_ABOUT || scheme == HIFI_URL_SCHEME_HTTP || scheme == HIFI_URL_SCHEME_HTTPS ||
urlString.toLower().endsWith(".htm") || urlString.toLower().endsWith(".html")) {
return ContentType::HtmlContent;
}

View file

@ -183,7 +183,7 @@ void EntityEditFilters::addFilter(EntityItemID entityID, QString filterURL) {
}
// The following should be abstracted out for use in Agent.cpp (and maybe later AvatarMixer.cpp)
if (scriptURL.scheme().isEmpty() || (scriptURL.scheme() == URL_SCHEME_FILE)) {
if (scriptURL.scheme().isEmpty() || (scriptURL.scheme() == HIFI_URL_SCHEME_FILE)) {
qWarning() << "Cannot load script from local filesystem, because assignment may be on a different computer.";
scriptRequestFinished(entityID);
return;

View file

@ -329,7 +329,7 @@ _maxNumPixels(100)
static bool isLocalUrl(const QUrl& url) {
auto scheme = url.scheme();
return (scheme == URL_SCHEME_FILE || scheme == URL_SCHEME_QRC || scheme == RESOURCE_SCHEME);
return (scheme == HIFI_URL_SCHEME_FILE || scheme == URL_SCHEME_QRC || scheme == RESOURCE_SCHEME);
}
NetworkTexture::NetworkTexture(const QUrl& url, image::TextureUsage::Type type, const QByteArray& content, int maxNumPixels) :
@ -503,7 +503,7 @@ void NetworkTexture::handleLocalRequestCompleted() {
void NetworkTexture::makeLocalRequest() {
const QString scheme = _activeUrl.scheme();
QString path;
if (scheme == URL_SCHEME_FILE) {
if (scheme == HIFI_URL_SCHEME_FILE) {
path = PathUtils::expandToLocalDataAbsolutePath(_activeUrl).toLocalFile();
} else {
path = ":" + _activeUrl.path();

View file

@ -155,12 +155,12 @@ void AddressManager::goForward() {
void AddressManager::storeCurrentAddress() {
auto url = currentAddress();
if (url.scheme() == URL_SCHEME_FILE ||
if (url.scheme() == HIFI_URL_SCHEME_FILE ||
(url.scheme() == URL_SCHEME_HIFI && !url.host().isEmpty())) {
// TODO -- once Octree::readFromURL no-longer takes over the main event-loop, serverless-domain urls can
// be loaded over http(s)
// url.scheme() == URL_SCHEME_HTTP ||
// url.scheme() == URL_SCHEME_HTTPS ||
// url.scheme() == HIFI_URL_SCHEME_HTTP ||
// url.scheme() == HIFI_URL_SCHEME_HTTPS ||
bool isInErrorState = DependencyManager::get<NodeList>()->getDomainHandler().isInErrorState();
if (isConnected()) {
if (isInErrorState) {
@ -331,11 +331,11 @@ bool AddressManager::handleUrl(const QUrl& lookupUrl, LookupTrigger trigger) {
emit lookupResultsFinished();
return true;
} else if (lookupUrl.scheme() == URL_SCHEME_FILE) {
} else if (lookupUrl.scheme() == HIFI_URL_SCHEME_FILE) {
// TODO -- once Octree::readFromURL no-longer takes over the main event-loop, serverless-domain urls can
// be loaded over http(s)
// lookupUrl.scheme() == URL_SCHEME_HTTP ||
// lookupUrl.scheme() == URL_SCHEME_HTTPS ||
// lookupUrl.scheme() == HIFI_URL_SCHEME_HTTPS ||
// TODO once a file can return a connection refusal if there were to be some kind of load error, we'd
// need to store the previous domain tried in _lastVisitedURL. For now , do not store it.

View file

@ -196,7 +196,7 @@ void DomainHandler::setURLAndID(QUrl domainURL, QUuid domainID) {
_sockAddr.clear();
// if this is a file URL we need to see if it has a ~ for us to expand
if (domainURL.scheme() == URL_SCHEME_FILE) {
if (domainURL.scheme() == HIFI_URL_SCHEME_FILE) {
domainURL = PathUtils::expandToLocalDataAbsolutePath(domainURL);
}
}

View file

@ -30,14 +30,14 @@ namespace NetworkingConstants {
QUrl METAVERSE_SERVER_URL();
}
const QString URL_SCHEME_ABOUT = "about";
const QString HIFI_URL_SCHEME_ABOUT = "about";
const QString URL_SCHEME_HIFI = "hifi";
const QString URL_SCHEME_HIFIAPP = "hifiapp";
const QString URL_SCHEME_QRC = "qrc";
const QString URL_SCHEME_FILE = "file";
const QString URL_SCHEME_HTTP = "http";
const QString URL_SCHEME_HTTPS = "https";
const QString URL_SCHEME_FTP = "ftp";
const QString HIFI_URL_SCHEME_FILE = "file";
const QString HIFI_URL_SCHEME_HTTP = "http";
const QString HIFI_URL_SCHEME_HTTPS = "https";
const QString HIFI_URL_SCHEME_FTP = "ftp";
const QString URL_SCHEME_ATP = "atp";
#endif // hifi_NetworkingConstants_h

View file

@ -118,7 +118,7 @@ QSharedPointer<Resource> ResourceCacheSharedItems::getHighestPendingRequest() {
// Check load priority
float priority = resource->getLoadPriority();
bool isFile = resource->getURL().scheme() == URL_SCHEME_FILE;
bool isFile = resource->getURL().scheme() == HIFI_URL_SCHEME_FILE;
if (priority >= highestPriority && (isFile || !currentHighestIsFile)) {
highestPriority = priority;
highestIndex = i;

View file

@ -82,10 +82,10 @@ const QSet<QString>& getKnownUrls() {
static std::once_flag once;
std::call_once(once, [] {
knownUrls.insert(URL_SCHEME_QRC);
knownUrls.insert(URL_SCHEME_FILE);
knownUrls.insert(URL_SCHEME_HTTP);
knownUrls.insert(URL_SCHEME_HTTPS);
knownUrls.insert(URL_SCHEME_FTP);
knownUrls.insert(HIFI_URL_SCHEME_FILE);
knownUrls.insert(HIFI_URL_SCHEME_HTTP);
knownUrls.insert(HIFI_URL_SCHEME_HTTPS);
knownUrls.insert(HIFI_URL_SCHEME_FTP);
knownUrls.insert(URL_SCHEME_ATP);
});
return knownUrls;
@ -97,7 +97,7 @@ QUrl ResourceManager::normalizeURL(const QUrl& originalUrl) {
if (!getKnownUrls().contains(scheme)) {
// check the degenerative file case: on windows we can often have urls of the form c:/filename
// this checks for and works around that case.
QUrl urlWithFileScheme{ URL_SCHEME_FILE + ":///" + url.toString() };
QUrl urlWithFileScheme{ HIFI_URL_SCHEME_FILE + ":///" + url.toString() };
if (!urlWithFileScheme.toLocalFile().isEmpty()) {
return urlWithFileScheme;
}
@ -124,9 +124,9 @@ ResourceRequest* ResourceManager::createResourceRequest(
ResourceRequest* request = nullptr;
if (scheme == URL_SCHEME_FILE || scheme == URL_SCHEME_QRC) {
if (scheme == HIFI_URL_SCHEME_FILE || scheme == URL_SCHEME_QRC) {
request = new FileResourceRequest(normalizedURL, isObservable, callerId, extra);
} else if (scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP) {
} else if (scheme == HIFI_URL_SCHEME_HTTP || scheme == HIFI_URL_SCHEME_HTTPS || scheme == HIFI_URL_SCHEME_FTP) {
request = new HTTPResourceRequest(normalizedURL, isObservable, callerId, extra);
} else if (scheme == URL_SCHEME_ATP) {
if (!_atpSupportEnabled) {
@ -149,10 +149,10 @@ ResourceRequest* ResourceManager::createResourceRequest(
bool ResourceManager::resourceExists(const QUrl& url) {
auto scheme = url.scheme();
if (scheme == URL_SCHEME_FILE) {
if (scheme == HIFI_URL_SCHEME_FILE) {
QFileInfo file{ url.toString() };
return file.exists();
} else if (scheme == URL_SCHEME_HTTP || scheme == URL_SCHEME_HTTPS || scheme == URL_SCHEME_FTP) {
} else if (scheme == HIFI_URL_SCHEME_HTTP || scheme == HIFI_URL_SCHEME_HTTPS || scheme == HIFI_URL_SCHEME_FTP) {
auto& networkAccessManager = NetworkAccessManager::getInstance();
QNetworkRequest request{ url };