mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Re-name MIMETypeLibrary to MediaTypeLibrary and update related references
This commit is contained in:
parent
ed1684967f
commit
6ea4769173
9 changed files with 97 additions and 97 deletions
|
@ -1834,14 +1834,14 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr
|
|||
return hfmModelPtr;
|
||||
}
|
||||
|
||||
MIMEType getFBXMIMEType() {
|
||||
MIMEType mimeType("fbx");
|
||||
mimeType.extensions.push_back("fbx");
|
||||
mimeType.fileSignatures.emplace_back("Kaydara FBX Binary \x00", 0);
|
||||
return mimeType;
|
||||
MediaType getFBXMediaType() {
|
||||
MediaType mediaType("fbx");
|
||||
mediaType.extensions.push_back("fbx");
|
||||
mediaType.fileSignatures.emplace_back("Kaydara FBX Binary \x00", 0);
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
std::shared_ptr<hfm::Format> FBXSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<FBXSerializer>>(getFBXMIMEType());
|
||||
std::shared_ptr<hfm::Format> FBXSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<FBXSerializer>>(getFBXMediaType());
|
||||
|
||||
HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
QBuffer buffer(const_cast<QByteArray*>(&data));
|
||||
|
|
|
@ -906,14 +906,14 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) {
|
|||
return true;
|
||||
}
|
||||
|
||||
MIMEType getGLTFMIMEType() {
|
||||
MIMEType mimeType("gltf");
|
||||
mimeType.extensions.push_back("gltf");
|
||||
mimeType.webMediaTypes.push_back("model/gltf+json");
|
||||
return mimeType;
|
||||
MediaType getGLTFMediaType() {
|
||||
MediaType mediaType("gltf");
|
||||
mediaType.extensions.push_back("gltf");
|
||||
mediaType.webMediaTypes.push_back("model/gltf+json");
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
std::shared_ptr<hfm::Format> GLTFSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<GLTFSerializer>>(getGLTFMIMEType());
|
||||
std::shared_ptr<hfm::Format> GLTFSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<GLTFSerializer>>(getGLTFMediaType());
|
||||
|
||||
HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
|
||||
|
|
|
@ -652,13 +652,13 @@ done:
|
|||
return result;
|
||||
}
|
||||
|
||||
MIMEType getOBJMIMEType() {
|
||||
MIMEType mimeType("obj");
|
||||
mimeType.extensions.push_back("obj");
|
||||
return mimeType;
|
||||
MediaType getOBJMediaType() {
|
||||
MediaType mediaType("obj");
|
||||
mediaType.extensions.push_back("obj");
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
std::shared_ptr<hfm::Format> OBJSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<OBJSerializer>>(getOBJMIMEType());
|
||||
std::shared_ptr<hfm::Format> OBJSerializer::FORMAT = std::make_shared<hfm::SimpleFormat<OBJSerializer>>(getOBJMediaType());
|
||||
|
||||
HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) {
|
||||
PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr);
|
||||
|
|
|
@ -13,53 +13,53 @@
|
|||
|
||||
namespace hfm {
|
||||
|
||||
FormatRegistry::MIMETypeID FormatRegistry::registerMIMEType(const MIMEType& mimeType, std::unique_ptr<Serializer::Factory> supportedFactory) {
|
||||
FormatRegistry::MediaTypeID FormatRegistry::registerMediaType(const MediaType& mediaType, std::unique_ptr<Serializer::Factory> supportedFactory) {
|
||||
std::lock_guard<std::mutex> lock(_libraryLock);
|
||||
|
||||
MIMETypeID id = _mimeTypeLibrary.registerMIMEType(mimeType);
|
||||
MediaTypeID id = _mediaTypeLibrary.registerMediaType(mediaType);
|
||||
_supportedFormats.emplace_back(id, supportedFactory);
|
||||
return id;
|
||||
}
|
||||
|
||||
void FormatRegistry::unregisterMIMEType(const MIMETypeID& mimeTypeID) {
|
||||
void FormatRegistry::unregisterMediaType(const MediaTypeID& mediaTypeID) {
|
||||
std::lock_guard<std::mutex> lock(_libraryLock);
|
||||
|
||||
for (auto it = _supportedFormats.begin(); it != _supportedFormats.end(); it++) {
|
||||
if ((*it).mimeTypeID == mimeTypeID) {
|
||||
if ((*it).mediaTypeID == mediaTypeID) {
|
||||
_supportedFormats.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
_mimeTypeLibrary.unregisterMIMEType(mimeTypeID);
|
||||
_mediaTypeLibrary.unregisterMediaType(mediaTypeID);
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializer> FormatRegistry::getSerializerForMIMETypeID(FormatRegistry::MIMETypeID mimeTypeID) const {
|
||||
std::shared_ptr<Serializer> FormatRegistry::getSerializerForMediaTypeID(FormatRegistry::MediaTypeID mediaTypeID) const {
|
||||
// TODO: shared_lock in C++14
|
||||
std::lock_guard<std::mutex> lock(*const_cast<std::mutex*>(&_libraryLock));
|
||||
|
||||
for (auto it = _supportedFormats.begin(); it != _supportedFormats.end(); it++) {
|
||||
if ((*it).mimeTypeID == mimeTypeID) {
|
||||
if ((*it).mediaTypeID == mediaTypeID) {
|
||||
return (*it).factory->get();
|
||||
}
|
||||
}
|
||||
return std::shared_ptr<Serializer>();
|
||||
}
|
||||
|
||||
std::shared_ptr<Serializer> FormatRegistry::getSerializerForMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const {
|
||||
MIMETypeID id;
|
||||
std::shared_ptr<Serializer> FormatRegistry::getSerializerForMediaType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const {
|
||||
MediaTypeID id;
|
||||
{
|
||||
// TODO: shared_lock in C++14
|
||||
std::lock_guard<std::mutex> lock(*const_cast<std::mutex*>(&_libraryLock));
|
||||
|
||||
id = _mimeTypeLibrary.findMIMETypeForData(data);
|
||||
if (id == INVALID_MIME_TYPE_ID) {
|
||||
id = _mimeTypeLibrary.findMIMETypeForURL(url);
|
||||
id = _mediaTypeLibrary.findMediaTypeForData(data);
|
||||
if (id == INVALID_MEDIA_TYPE_ID) {
|
||||
id = _mediaTypeLibrary.findMediaTypeForURL(url);
|
||||
}
|
||||
if (id == INVALID_MIME_TYPE_ID) {
|
||||
id = _mimeTypeLibrary.findMIMETypeForMediaType(webMediaType);
|
||||
if (id == INVALID_MEDIA_TYPE_ID) {
|
||||
id = _mediaTypeLibrary.findMediaTypeForWebID(webMediaType);
|
||||
}
|
||||
}
|
||||
return getSerializerForMIMETypeID(id);
|
||||
return getSerializerForMediaTypeID(id);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -13,32 +13,32 @@
|
|||
#define hifi_HFMFormatRegistry_h
|
||||
|
||||
#include "HFMSerializer.h"
|
||||
#include <shared/MIMETypeLibrary.h>
|
||||
#include <shared/MediaTypeLibrary.h>
|
||||
#include <shared/ReadWriteLockable.h>
|
||||
|
||||
namespace hfm {
|
||||
|
||||
class FormatRegistry {
|
||||
public:
|
||||
using MIMETypeID = MIMETypeLibrary::ID;
|
||||
static const MIMETypeID INVALID_MIME_TYPE_ID { MIMETypeLibrary::INVALID_ID };
|
||||
using MediaTypeID = MediaTypeLibrary::ID;
|
||||
static const MediaTypeID INVALID_MEDIA_TYPE_ID { MediaTypeLibrary::INVALID_ID };
|
||||
|
||||
MIMETypeID registerMIMEType(const MIMEType& mimeType, std::unique_ptr<Serializer::Factory> supportedFactory);
|
||||
void unregisterMIMEType(const MIMETypeID& id);
|
||||
MediaTypeID registerMediaType(const MediaType& mediaType, std::unique_ptr<Serializer::Factory> supportedFactory);
|
||||
void unregisterMediaType(const MediaTypeID& id);
|
||||
|
||||
std::shared_ptr<Serializer> getSerializerForMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const;
|
||||
std::shared_ptr<Serializer> getSerializerForMIMETypeID(MIMETypeID id) const;
|
||||
std::shared_ptr<Serializer> getSerializerForMediaType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const;
|
||||
std::shared_ptr<Serializer> getSerializerForMediaTypeID(MediaTypeID id) const;
|
||||
|
||||
protected:
|
||||
MIMETypeLibrary _mimeTypeLibrary;
|
||||
MediaTypeLibrary _mediaTypeLibrary;
|
||||
std::mutex _libraryLock;
|
||||
class SupportedFormat {
|
||||
public:
|
||||
SupportedFormat(const MIMETypeID& mimeTypeID, std::unique_ptr<Serializer::Factory>& factory) :
|
||||
mimeTypeID(mimeTypeID),
|
||||
SupportedFormat(const MediaTypeID& mediaTypeID, std::unique_ptr<Serializer::Factory>& factory) :
|
||||
mediaTypeID(mediaTypeID),
|
||||
factory(std::move(factory)) {
|
||||
}
|
||||
MIMETypeID mimeTypeID;
|
||||
MediaTypeID mediaTypeID;
|
||||
std::unique_ptr<Serializer::Factory> factory;
|
||||
};
|
||||
std::vector<SupportedFormat> _supportedFormats;
|
||||
|
|
|
@ -26,21 +26,21 @@ namespace hfm {
|
|||
template<typename T> // T is an implementation of hfm::Serializer
|
||||
class SimpleFormat : public Format {
|
||||
public:
|
||||
SimpleFormat(const MIMEType& mimeType) : Format(),
|
||||
_mimeType(mimeType) {
|
||||
SimpleFormat(const MediaType& mediaType) : Format(),
|
||||
_mediaType(mediaType) {
|
||||
}
|
||||
|
||||
void registerFormat(FormatRegistry& registry) override {
|
||||
_mimeTypeID = registry.registerMIMEType(_mimeType, std::make_unique<SimpleFactory<T>>());
|
||||
_mediaTypeID = registry.registerMediaType(_mediaType, std::make_unique<SimpleFactory<T>>());
|
||||
}
|
||||
|
||||
void unregisterFormat(FormatRegistry& registry) override {
|
||||
registry.unregisterMIMEType(_mimeTypeID);
|
||||
_mimeTypeID = hfm::FormatRegistry::INVALID_MIME_TYPE_ID;
|
||||
registry.unregisterMediaType(_mediaTypeID);
|
||||
_mediaTypeID = hfm::FormatRegistry::INVALID_MEDIA_TYPE_ID;
|
||||
}
|
||||
protected:
|
||||
MIMEType _mimeType;
|
||||
hfm::FormatRegistry::MIMETypeID _mimeTypeID;
|
||||
MediaType _mediaType;
|
||||
hfm::FormatRegistry::MediaTypeID _mediaTypeID;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
|
||||
hfm::Model::Pointer ModelLoader::load(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const {
|
||||
auto serializer = DependencyManager::get<ModelFormatRegistry>()->getSerializerForMIMEType(data, url, webMediaType);
|
||||
auto serializer = DependencyManager::get<ModelFormatRegistry>()->getSerializerForMediaType(data, url, webMediaType);
|
||||
if (!serializer) {
|
||||
return hfm::Model::Pointer();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// MIMETypeLibrary.cpp
|
||||
// MediaTypeLibrary.cpp
|
||||
// libraries/shared/src/shared
|
||||
//
|
||||
// Created by Sabrina Shanman on 2018/11/29.
|
||||
|
@ -9,41 +9,41 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "MIMETypeLibrary.h"
|
||||
#include "MediaTypeLibrary.h"
|
||||
|
||||
MIMEType MIMEType::NONE = MIMEType("");
|
||||
MediaType MediaType::NONE = MediaType("");
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::registerMIMEType(const MIMEType& mimeType) {
|
||||
MediaTypeLibrary::ID MediaTypeLibrary::registerMediaType(const MediaType& mediaType) {
|
||||
ID id = nextID++;
|
||||
_mimeTypes.emplace_back(id, mimeType);
|
||||
_mediaTypes.emplace_back(id, mediaType);
|
||||
return id;
|
||||
}
|
||||
|
||||
void MIMETypeLibrary::unregisterMIMEType(const MIMETypeLibrary::ID& id) {
|
||||
for (auto it = _mimeTypes.begin(); it != _mimeTypes.end(); it++) {
|
||||
void MediaTypeLibrary::unregisterMediaType(const MediaTypeLibrary::ID& id) {
|
||||
for (auto it = _mediaTypes.begin(); it != _mediaTypes.end(); it++) {
|
||||
if ((*it).id == id) {
|
||||
_mimeTypes.erase(it);
|
||||
_mediaTypes.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MIMEType MIMETypeLibrary::getMIMEType(const MIMETypeLibrary::ID& id) const {
|
||||
for (auto& supportedFormat : _mimeTypes) {
|
||||
MediaType MediaTypeLibrary::getMediaType(const MediaTypeLibrary::ID& id) const {
|
||||
for (auto& supportedFormat : _mediaTypes) {
|
||||
if (supportedFormat.id == id) {
|
||||
return supportedFormat.mimeType;
|
||||
return supportedFormat.mediaType;
|
||||
}
|
||||
}
|
||||
return MIMEType::NONE;
|
||||
return MediaType::NONE;
|
||||
}
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForData(const hifi::ByteArray& data) const {
|
||||
MediaTypeLibrary::ID MediaTypeLibrary::findMediaTypeForData(const hifi::ByteArray& data) const {
|
||||
// Check file contents
|
||||
for (auto& mimeType : _mimeTypes) {
|
||||
for (auto& fileSignature : mimeType.mimeType.fileSignatures) {
|
||||
for (auto& mediaType : _mediaTypes) {
|
||||
for (auto& fileSignature : mediaType.mediaType.fileSignatures) {
|
||||
auto testBytes = data.mid(fileSignature.byteOffset, (int)fileSignature.bytes.size()).toStdString();
|
||||
if (testBytes == fileSignature.bytes) {
|
||||
return mimeType.id;
|
||||
return mediaType.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForData(const hifi::ByteArray&
|
|||
return INVALID_ID;
|
||||
}
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForURL(const hifi::URL& url) const {
|
||||
MediaTypeLibrary::ID MediaTypeLibrary::findMediaTypeForURL(const hifi::URL& url) const {
|
||||
// Check file extension
|
||||
std::string urlString = url.path().toStdString();
|
||||
std::size_t extensionSeparator = urlString.rfind('.');
|
||||
if (extensionSeparator != std::string::npos) {
|
||||
std::string detectedExtension = urlString.substr(extensionSeparator + 1);
|
||||
for (auto& supportedFormat : _mimeTypes) {
|
||||
for (auto& extension : supportedFormat.mimeType.extensions) {
|
||||
for (auto& supportedFormat : _mediaTypes) {
|
||||
for (auto& extension : supportedFormat.mediaType.extensions) {
|
||||
if (extension == detectedExtension) {
|
||||
return supportedFormat.id;
|
||||
}
|
||||
|
@ -69,11 +69,11 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForURL(const hifi::URL& url) co
|
|||
return INVALID_ID;
|
||||
}
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForMediaType(const std::string& webMediaType) const {
|
||||
MediaTypeLibrary::ID MediaTypeLibrary::findMediaTypeForWebID(const std::string& webMediaType) const {
|
||||
// Check web media type
|
||||
if (webMediaType != "") {
|
||||
for (auto& supportedFormat : _mimeTypes) {
|
||||
for (auto& candidateWebMediaType : supportedFormat.mimeType.webMediaTypes) {
|
||||
for (auto& supportedFormat : _mediaTypes) {
|
||||
for (auto& candidateWebMediaType : supportedFormat.mediaType.webMediaTypes) {
|
||||
if (candidateWebMediaType == webMediaType) {
|
||||
return supportedFormat.id;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// MIMETypeLibrary.h
|
||||
// MediaTypeLibrary.h
|
||||
// libraries/shared/src/shared
|
||||
//
|
||||
// Created by Sabrina Shanman on 2018/11/28.
|
||||
|
@ -9,8 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_MIMETypeLibrary_h
|
||||
#define hifi_MIMETypeLibrary_h
|
||||
#ifndef hifi_MediaTypeLibrary_h
|
||||
#define hifi_MediaTypeLibrary_h
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
@ -36,20 +36,20 @@ public:
|
|||
};
|
||||
|
||||
// A named file extension with a list of known ways to positively identify the file type
|
||||
class MIMEType {
|
||||
class MediaType {
|
||||
public:
|
||||
MIMEType(const std::string& name) :
|
||||
MediaType(const std::string& name) :
|
||||
name(name) {
|
||||
}
|
||||
MIMEType() {};
|
||||
MIMEType(const MIMEType& mimeType) :
|
||||
name(mimeType.name),
|
||||
extensions(mimeType.extensions),
|
||||
webMediaTypes(mimeType.webMediaTypes),
|
||||
fileSignatures(mimeType.fileSignatures) {
|
||||
MediaType() {};
|
||||
MediaType(const MediaType& mediaType) :
|
||||
name(mediaType.name),
|
||||
extensions(mediaType.extensions),
|
||||
webMediaTypes(mediaType.webMediaTypes),
|
||||
fileSignatures(mediaType.fileSignatures) {
|
||||
}
|
||||
|
||||
static MIMEType NONE;
|
||||
static MediaType NONE;
|
||||
|
||||
std::string name;
|
||||
std::vector<std::string> extensions;
|
||||
|
@ -57,34 +57,34 @@ public:
|
|||
std::vector<FileSignature> fileSignatures;
|
||||
};
|
||||
|
||||
class MIMETypeLibrary {
|
||||
class MediaTypeLibrary {
|
||||
public:
|
||||
using ID = unsigned int;
|
||||
static const ID INVALID_ID { 0 };
|
||||
|
||||
ID registerMIMEType(const MIMEType& mimeType);
|
||||
void unregisterMIMEType(const ID& id);
|
||||
ID registerMediaType(const MediaType& mediaType);
|
||||
void unregisterMediaType(const ID& id);
|
||||
|
||||
MIMEType getMIMEType(const ID& id) const;
|
||||
MediaType getMediaType(const ID& id) const;
|
||||
|
||||
ID findMIMETypeForData(const hifi::ByteArray& data) const;
|
||||
ID findMIMETypeForURL(const hifi::URL& url) const;
|
||||
ID findMIMETypeForMediaType(const std::string& webMediaType) const;
|
||||
ID findMediaTypeForData(const hifi::ByteArray& data) const;
|
||||
ID findMediaTypeForURL(const hifi::URL& url) const;
|
||||
ID findMediaTypeForWebID(const std::string& webMediaType) const;
|
||||
|
||||
protected:
|
||||
ID nextID { 1 };
|
||||
|
||||
class Entry {
|
||||
public:
|
||||
Entry(const ID& id, const MIMEType& mimeType) :
|
||||
Entry(const ID& id, const MediaType& mediaType) :
|
||||
id(id),
|
||||
mimeType(mimeType) {
|
||||
mediaType(mediaType) {
|
||||
}
|
||||
ID id;
|
||||
MIMEType mimeType;
|
||||
MediaType mediaType;
|
||||
};
|
||||
|
||||
std::vector<Entry> _mimeTypes;
|
||||
std::vector<Entry> _mediaTypes;
|
||||
};
|
||||
|
||||
#endif // hifi_MIMETypeLibrary_h
|
||||
#endif // hifi_MeidaTypeLibrary_h
|
Loading…
Reference in a new issue