Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DON'T MERGE) Fix/no return codes #36

Closed
wants to merge 132 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
5589c98
Compression prototype: transparent encoding/decoding into base64 impl…
Dec 1, 2015
b026f8a
methods load/save XMPstructs created
Dec 2, 2015
4468c6d
ICompressor interface added, DummyCompressor added
Dec 3, 2015
7dc2bbe
ICompressor and DummyCompressor moved to vmfcore
Dec 3, 2015
c359e94
design prototype impelemented (except compressor registration and exp…
Dec 4, 2015
8b1c643
ICompressor added to IReader and IWriter
Dec 4, 2015
724446a
Implemented registration of compression algos
Dec 7, 2015
f8ccd27
ZLibCompressor added
Dec 8, 2015
44a0506
Exceptions added on compression and XMP saving
Dec 9, 2015
05e1e24
fixed: incorrect size of output buffer in zlib compressor
Dec 9, 2015
6e4c518
XMP serializes more compactly
Dec 9, 2015
09cda21
ski_resort_fake_creator sample now uses zlib compression, headers add…
Dec 9, 2015
db33e0a
compressor samples added (bugs)
Dec 9, 2015
f242100
compression samples fixed
Dec 10, 2015
21672c5
minor changes
Dec 11, 2015
e222d28
"Time" field removed, use timestamp of vmf::Metadata instead
Dec 15, 2015
a415c61
use macros for schema creation instead of code
Dec 15, 2015
ff42daa
compression sample: MyLZWCompressor moved to separate files
Dec 15, 2015
639a8ef
MetaString replaced with vmf_string
Dec 15, 2015
1ec4f7c
now compressors are accessed with their IDs
Dec 16, 2015
bf61f6e
added example of a trial of unregistered compressor use
Dec 16, 2015
d908b47
compression-builtin and compression-custom moved to the same folder
Dec 16, 2015
af66c4e
common parts of compression samples moved to separate file
Dec 16, 2015
8477924
ICompressor renamed to Compressor
Dec 16, 2015
761f320
classes (and corresponding files) were renamed: from XXXCompressor to…
Dec 16, 2015
aaf8d6d
Compressor classes: default constructors added
Dec 16, 2015
afb1431
CompressorZlib: source data size is vmf_integer instead of size_t now
Dec 16, 2015
fb03831
compressor registration functions were transformed into static methods
Dec 16, 2015
e34a691
Compressor::getId() now returns hardcoded values
Dec 16, 2015
d78168b
using base64 from XMP, not from libbase64++
Dec 16, 2015
09feead
ReaderBase class created (IReader <- ReaderBase <- XXXReader)
Dec 16, 2015
48babbe
WriterBase class created
Dec 16, 2015
6c2fdad
throw exception added if the compression algo is not given
Dec 16, 2015
523828b
all implementation details moved to Reader/Writer Base classes
Dec 17, 2015
84b89d5
base64 encoding/decoding added to Reader/Writer Base classes
Dec 17, 2015
b87169d
compressorId is used in Reader/Writer Base instead of pointer to comp…
Dec 17, 2015
301bf73
compression-custom sample: unregister() call added
Dec 22, 2015
fda603f
minors; XMP data source: no extra args in some internal funcs
Dec 25, 2015
d095268
XMP data source: pointer to compressor instead of its id
Dec 25, 2015
d3421b4
compilation fixed
Dec 28, 2015
8784fa3
compressor is called 2 times on saving instead of 5 times (on data re…
Dec 28, 2015
f6609bb
no more compression on data removal
Dec 28, 2015
783787c
compilation fixed: no u_char type
Dec 29, 2015
e93e347
compilation fixed: type cast from size* to uLongf*
Dec 29, 2015
6a3d5da
compilation fixed: cast to size_t
Dec 29, 2015
edd7973
compilation fixed: M_PI
Dec 29, 2015
0971a15
compilation fixed: M_PI, long long
Dec 29, 2015
f430fbe
compilation fixed: double to float conversion
Dec 29, 2015
633371b
compilation fixed: conversion to uLong
Dec 29, 2015
89bb64c
compilation fixed: new vmf_rawbuffer
Dec 30, 2015
405f1ab
commented out code removed
Dec 30, 2015
55ed04c
IDataSource::setCompressor() instead of setCompressorById()
Dec 30, 2015
6c5e5c3
added VMF_ to macro names
Dec 30, 2015
2d3eee6
Compressor::getById() renamed to getInstance()
Dec 30, 2015
5e42142
impl -> compressor renamed
Dec 30, 2015
43aeea0
Compressor::getId(): no const
Dec 30, 2015
135c6f3
now we use new instance of compressor on each compression/decompression
Dec 30, 2015
1cb1ac6
no more Compressor::unregister(ICompressor*) method
Dec 30, 2015
8854e81
exception is thrown if trying to unregister algo with incorrect id
Dec 30, 2015
9d99ea1
CompressorDummy: no more std::move() calls
Dec 30, 2015
d340ae3
compressors: shared pointers
Dec 30, 2015
cebe878
extra std::move() calls removed
Jan 12, 2016
0e0afe2
compressors my_lzw and zlib: check for empty input added
Jan 12, 2016
8b24eda
tests added for built-in compessors
Jan 12, 2016
bd6dec5
data source tests added for compression
Jan 12, 2016
85559a3
try to fix tests
Jan 13, 2016
1092eec
try to fix tests (no nullptr)
Jan 13, 2016
71f514c
tests: added test for compressor creation, minors
Jan 13, 2016
e765b77
fixed: standard compressors registration on static linking
Jan 14, 2016
0b6754a
standard compressors registration: cleaning up public interface
Jan 14, 2016
36813a3
more doxy comments added
Jan 14, 2016
b1ac5e9
builtin compressors were put into separate map and were prevented fro…
Jan 14, 2016
786f674
Compressor::getRegisteredIds() method added with test
Jan 14, 2016
9780237
doxy comments: minors
Jan 15, 2016
133eb5a
serialization tests added: standard compression algorithms
Jan 15, 2016
e23f9db
comments on PullRQ fixed
Jan 15, 2016
705f7d1
docs updated, minors
Jan 15, 2016
004ef73
minor fixes to tests
Jan 18, 2016
a39b7cf
typo fixed
Jan 18, 2016
4afe94b
doxy fixed
Jan 18, 2016
ccddfdd
minor fix
Jan 18, 2016
e89404d
now Compressor class throws an exception on incorrect ID, extra check…
Jan 18, 2016
8cfdcd3
TODO added, comments fixed
Jan 18, 2016
367ab82
Compressor::create(): minor refactoring
Jan 18, 2016
af3f92f
Compressor::unregister(): check if user tries to remove built-in comp…
Jan 18, 2016
5caffb4
tabs removed
Jan 18, 2016
641995d
typo fixed
Jan 19, 2016
9b5425a
minor: enums in Compressor
Jan 19, 2016
720764f
Compressor::unregister(): bug fixed
Jan 19, 2016
0c371ba
readers/writers XML/JSON: compessed data is wrapped into container ha…
Jan 20, 2016
1478029
tests for compressed serialization added
Jan 20, 2016
5bed2fd
ReaderBase class removed
Jan 20, 2016
b1e4ee3
MetadataStream::save...() signatures changed
Jan 20, 2016
14ddd64
compression samples file names changed
Jan 20, 2016
eb85ca5
file name fixed: test_seriAlization.cpp
Jan 20, 2016
d5295c8
comments edited
Jan 20, 2016
0730b8f
compression example: code clearified
Jan 20, 2016
cec9512
compression sample: writeMetadataStream -> generateMetadata
Jan 20, 2016
140b88f
compress_common.cpp rewritten
Jan 20, 2016
bb26ce8
compilation fixed
Jan 22, 2016
ea55d8a
compression sample: remove all previous metadata on loading new file
Jan 25, 2016
548bcac
workaround added to fix fails of dataSource->saveSchema() after remov…
Jan 25, 2016
575fc96
compressed metadata saving implemented (no loading yet)
Jan 26, 2016
dff7234
MetadataStream::OpenMode is a bit mask now; compilation fixed (no loa…
Jan 26, 2016
988579f
MetadataStream::OpenMode: flags fixed
Jan 26, 2016
7cdeeca
loading compressed data implemented
Jan 26, 2016
88a31fb
test added for the Ignore flag
Jan 26, 2016
d662fd7
warning fixed
Jan 26, 2016
e6da31e
VMF-2.0-compatible XML serialization added (tests needed)
Jan 27, 2016
c7211bd
serialization rewritten, VMF-2.0-compatible JSON serialization added …
Jan 27, 2016
078a69f
flag added to ignore unknown compression algorithm at serialization, …
Jan 27, 2016
fba71f5
compressor tests: made simplier, faster
Jan 28, 2016
e41e3e0
XMP data source, compressed data writing: no checksum is written
Jan 28, 2016
f46ab02
MetadataStream::ReadWrite renamed to Update
Jan 28, 2016
5ef7716
CompressorDummy removed
Jan 29, 2016
26bb1a8
Zlib compressor removed from public interface
Jan 29, 2016
a0f720d
tabs, minors
Feb 1, 2016
fb960b3
Serialization+Compression: interface rewritten, CompressionReader/Wri…
Feb 1, 2016
1722b3e
Fake compressor duplication fixed
Feb 1, 2016
07021b8
ReaderCompressed at decompress: parseSchemas() and parseMetadata() in…
Feb 1, 2016
5a0f67e
joining samples, output improvements
Feb 2, 2016
cc80629
typo fixed
Feb 2, 2016
6386f39
return codes removed in MetadataStream::save(), need to fix tests
Feb 2, 2016
8a49eea
fixed all tests except OneToOneReference
Feb 2, 2016
b0d0126
compession sample: compilation fixed
Feb 2, 2016
7951869
small optimization of removal from XMP data source
Feb 3, 2016
b35a1ad
return codes removed from MetadataStream::save(), some tests fixed
Feb 5, 2016
486c89a
temporary debugging code
Feb 6, 2016
3431031
merged minor changes
Feb 8, 2016
4265746
forgotten files added
Feb 8, 2016
01395cc
debugging code removed
Feb 8, 2016
e4d1fcb
std-schema sample fixed
Feb 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ notifications:
email: false
webhooks: https://coveralls.io/webhook?repo_token=kXDrxzQdBiK3aEgUSlsbL3IVMP0Mvr4oH


Binary file modified docs/VMF_SAD.doc
Binary file not shown.
Binary file modified docs/VMF_SAD.pdf
Binary file not shown.
Binary file modified docs/VMF_User_guide.docx
Binary file not shown.
Binary file modified docs/VMF_User_guide.pdf
Binary file not shown.
11 changes: 7 additions & 4 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ endif()
set(XMP_PUBLIC_DIR "${VMF_3PTY_DIR}/xmp/public/include")
set(LIBXML2_PUBLIC_DIR "${VMF_3PTY_DIR}/libxml2/src/include")
set(LIBJSON_PUBLIC_DIR "${VMF_3PTY_DIR}/libjson/src" "${VMF_3PTY_DIR}/libjson/src/_internal/Source")
set(ZLIB_PUBLIC_DIR "${VMF_3PTY_DIR}/xmp/third-party/zlib")
set(XMPCORE_SOURCE_DIR "${VMF_3PTY_DIR}/xmp/XMPCore/source")
set(XMP_ROOT_DIR "${VMF_3PTY_DIR}/xmp")

if(CODE_COVERAGE)
add_definitions(--coverage)
Expand All @@ -46,7 +49,7 @@ file(GLOB VMFCORE_SOURCES "${VMFCORE_SOURCE_DIR}/*.hpp" "${VMFCORE_SOURCE_DIR}/
file(GLOB VMFCORE_DETAILS "${VMFCORE_DETAILS_DIR}/*.hpp" "${VMFCORE_DETAILS_DIR}/*.cpp")
file(GLOB VMFCORE_TESTS "${VMFCORE_TESTS_DIR}/*.hpp" "${VMFCORE_TESTS_DIR}/*.cpp")

source_group(vmfcore\\include\\vmf FILES ${VMFCORE_HEADERS})
source_group(vmfcore\\include FILES ${VMFCORE_HEADERS})
source_group(vmfcore\\src FILES ${VMFCORE_SOURCES})
source_group(vmfcore\\src\\details FILES ${VMFCORE_DETAILS})

Expand All @@ -61,9 +64,9 @@ file(GLOB VMDATASOURCE_SOURCES "${VMDATASOURCE_SOURCE_DIR}/*.hpp" "${VMDATASOURC
file(GLOB VMDATASOURCE_TESTS "${VMDATASOURCE_TESTS_DIR}/*.hpp" "${VMDATASOURCE_TESTS_DIR}/*.cpp")

source_group(vmdatasource\\src FILES ${VMDATASOURCE_SOURCES})
source_group(vmdatasource\\include\\vmf FILES ${VMDATASOURCE_HEADERS})
source_group(vmdatasource\\include FILES ${VMDATASOURCE_HEADERS})

include_directories(${CMAKE_BINARY_DIR} ${VMFCORE_PUBLIC_DIR} ${VMFCORE_DETAILS_DIR} ${VMDATASOURCE_PUBLIC_DIR} ${XMP_PUBLIC_DIR} ${LIBXML2_PUBLIC_DIR} ${LIBJSON_PUBLIC_DIR})
include_directories(${CMAKE_BINARY_DIR} ${VMFCORE_PUBLIC_DIR} ${VMFCORE_DETAILS_DIR} ${VMDATASOURCE_PUBLIC_DIR} ${XMP_PUBLIC_DIR} ${LIBXML2_PUBLIC_DIR} ${LIBJSON_PUBLIC_DIR} ${ZLIB_PUBLIC_DIR} ${XMPCORE_SOURCE_DIR} ${XMP_ROOT_DIR})

add_library(${VMF_LIBRARY_NAME} ${VMDATASOURCE_HEADERS} ${VMDATASOURCE_SOURCES} ${VMFCORE_HEADERS} ${VMFCORE_SOURCES} ${VMFCORE_DETAILS} ${XMP_SOURCES} ${LIBXML2_SOURCES} ${LIBJSON_SOURCES})
target_compile_definitions(${VMF_LIBRARY_NAME} PRIVATE $<$<CONFIG:Debug>:JSON_DEBUG> PRIVATE $<$<CONFIG:Release>:NDEBUG>)
Expand Down Expand Up @@ -98,7 +101,7 @@ elseif(UNIX)
target_link_libraries(${VMF_LIBRARY_NAME} dl)
endif()

set_target_properties(${VMF_LIBRARY_NAME} PROPERTIES FOLDER "vmf")
set_target_properties(${VMF_LIBRARY_NAME} PROPERTIES FOLDER "vmf library")

include_directories(${GTEST_INCLUDE_DIR})

Expand Down
229 changes: 211 additions & 18 deletions modules/vmdatasource/src/xmpdatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "xmpschemasource.hpp"
#include "xmpmetadatasource.hpp"

#include <XMPUtils.hpp>

#define VMF_GLOBAL_NEXT_ID "next-id"
#define VMF_GLOBAL_CHECKSUM "media-checksum"

Expand Down Expand Up @@ -82,10 +84,179 @@ void XMPDataSource::terminate()
}
}

static const string compressionSchemaName = "com.intel.vmf.compressed-metadata";
static const string compressedDescName = "compressed-metadata";
static const string compressedDataPropName = "data";
static const string compressionAlgoPropName = "algo";

XMPDataSource::XMPDataSource()
: IDataSource(), xmp(nullptr), metadataSource(nullptr)
: IDataSource(), xmp(nullptr), metadataSource(nullptr), compressor(nullptr)
{
schemaCompression = make_shared<vmf::MetadataSchema>(compressionSchemaName);
VMF_METADATA_BEGIN(compressedDescName);
VMF_FIELD_STR(compressionAlgoPropName);
VMF_FIELD_STR(compressedDataPropName);
VMF_METADATA_END(schemaCompression);
}

XMPDataSource::~XMPDataSource()
{

}

void XMPDataSource::setCompressor(const vmf_string &id)
{
if(!id.empty())
{
compressor = Compressor::create(id);
}
else
{
compressor = nullptr;
}
}


void XMPDataSource::loadXMPstructs()
{
std::shared_ptr<SXMPMeta> compressedXMP = make_shared<SXMPMeta>();
xmpFile.GetXMP(compressedXMP.get());

std::shared_ptr<XMPMetadataSource> cMetaSource;
std::shared_ptr<XMPSchemaSource> cSchemaSource;
cSchemaSource = make_shared<XMPSchemaSource>(compressedXMP);
cMetaSource = make_shared<XMPMetadataSource>(compressedXMP);
if (!cMetaSource || !cSchemaSource)
{
VMF_EXCEPTION(DataStorageException, "Failed to create metadata source or schema source");
}

//load standard VMF metadata and decompress them if there is a corresponding schema
//or pass them further
try
{
std::map<MetaString, std::shared_ptr<MetadataSchema> > cSchemas;
cSchemaSource->load(cSchemas);
auto it = cSchemas.find(compressionSchemaName);
if(it != cSchemas.end())
{
MetadataStream cStream;
cStream.addSchema(it->second);
cMetaSource->loadSchema(compressionSchemaName, cStream);
MetadataSet cSet = cStream.queryBySchema(compressionSchemaName);
std::shared_ptr<Metadata> cItem = cSet[0];
vmf_string algo = cItem->getFieldValue(compressionAlgoPropName);
vmf_string encoded = cItem->getFieldValue(compressedDataPropName);
try
{
std::shared_ptr<Compressor> decompressor = Compressor::create(algo);
string decoded;
XMPUtils::DecodeFromBase64(encoded.data(), encoded.length(), &decoded);
vmf_rawbuffer compressed(decoded.c_str(), decoded.size());
string theData;
decompressor->decompress(compressed, theData);
xmp->ParseFromBuffer(theData.c_str(), theData.size(), 0);
schemaSource = make_shared<XMPSchemaSource>(xmp);
metadataSource = make_shared<XMPMetadataSource>(xmp);
}
catch(IncorrectParamException& ce)
{
//if there's no such compressor and we're allowed to ignore that
if(openMode & MetadataStream::OpenModeFlags::IgnoreUnknownCompressor)
{
xmp = compressedXMP;
schemaSource = cSchemaSource;
metadataSource = cMetaSource;
}
else
{
VMF_EXCEPTION(IncorrectParamException, ce.what());
}
}
}
else
{
xmp = compressedXMP;
schemaSource = cSchemaSource;
metadataSource = cMetaSource;
}
}
catch(const XMP_Error& e)
{
VMF_EXCEPTION(DataStorageException, e.GetErrMsg());
}
catch(const std::exception& e)
{
VMF_EXCEPTION(DataStorageException, e.what());
}
}


void XMPDataSource::saveXMPstructs()
{
std::shared_ptr<SXMPMeta> compressedXMP;
//Sometimes compressed&encoded data is bigger than the source data
//but there's no need to compare their sizes and write the smallest one.
//Because due to RDF's verbosity it happens only when the source data is small.
//That's why the economy wouldn't be significant.
if(compressor)
{
compressedXMP = std::make_shared<SXMPMeta>();

string buffer;
XMP_OptionBits options = kXMP_ReadOnlyPacket | kXMP_UseCompactFormat;
xmp->SerializeToBuffer(&buffer, options, 0, NULL);
vmf_rawbuffer compressed;
compressor->compress(buffer, compressed);
string encoded;
XMPUtils::EncodeToBase64 (compressed.data(), compressed.size(), &encoded);

//save compressed data as VMF metadata with corresponding schema
MetadataStream cStream;
cStream.addSchema(schemaCompression);
shared_ptr<Metadata> cMetadata;
cMetadata = make_shared<Metadata>(schemaCompression->findMetadataDesc(compressedDescName));
cMetadata->push_back(FieldValue(compressionAlgoPropName, compressor->getId()));
cMetadata->push_back(FieldValue(compressedDataPropName, encoded));
cStream.add(cMetadata);

std::shared_ptr<XMPMetadataSource> cMetaSource;
std::shared_ptr<XMPSchemaSource> cSchemaSource;
cSchemaSource = make_shared<XMPSchemaSource>(compressedXMP);
cMetaSource = make_shared<XMPMetadataSource>(compressedXMP);
if (!cMetaSource || !cSchemaSource)
{
VMF_EXCEPTION(DataStorageException, "Failed to create compressed metadata source or schema source");
}

try
{
cMetaSource->saveSchema(compressionSchemaName, cStream);
cSchemaSource->save(schemaCompression);
}
catch(const XMP_Error& e)
{
VMF_EXCEPTION(DataStorageException, e.GetErrMsg());
}
catch(const std::exception& e)
{
VMF_EXCEPTION(DataStorageException, e.what());
}
IdType cNextId = 1;
compressedXMP->SetProperty_Int64(VMF_NS, VMF_GLOBAL_NEXT_ID, cNextId);
}
else
{
compressedXMP = xmp;
}
if(xmpFile.CanPutXMP(*compressedXMP))
{
xmpFile.PutXMP(*compressedXMP);
}
else
{
VMF_EXCEPTION(InternalErrorException, "Can't write XMP data to file");
}
}


Expand All @@ -97,7 +268,7 @@ void XMPDataSource::openFile(const MetaString& fileName, MetadataStream::OpenMod
openMode = mode;
metaFileName = fileName;
XMP_OptionBits modeFlags;
if (mode == MetadataStream::ReadWrite)
if (mode & MetadataStream::Update)
{
modeFlags = kXMPFiles_OpenForUpdate;
}
Expand All @@ -116,9 +287,8 @@ void XMPDataSource::openFile(const MetaString& fileName, MetadataStream::OpenMod
VMF_EXCEPTION(DataStorageException, "Could not open XMP file.");
}
}
xmpFile.GetXMP(xmp.get());
schemaSource = make_shared<XMPSchemaSource>(xmp);
metadataSource = make_shared<XMPMetadataSource>(xmp);

loadXMPstructs();
}
catch (const XMP_Error& e)
{
Expand Down Expand Up @@ -195,7 +365,6 @@ void XMPDataSource::saveSchema(const MetaString& schemaName, const MetadataStrea
try
{
metadataSource->saveSchema(schemaName, stream);
pushChanges();
}
catch(const XMP_Error& e)
{
Expand All @@ -219,7 +388,6 @@ void XMPDataSource::save(const std::shared_ptr<vmf::MetadataSchema>& schema)
try
{
schemaSource->save(schema);
pushChanges();
}
catch(const XMP_Error& e)
{
Expand All @@ -231,15 +399,37 @@ void XMPDataSource::save(const std::shared_ptr<vmf::MetadataSchema>& schema)
}
}


void XMPDataSource::serializeAndParse()
{
string tempBuffer;
XMP_OptionBits options = kXMP_ReadOnlyPacket | kXMP_UseCompactFormat;
xmp->SerializeToBuffer(&tempBuffer, options, 0, NULL);

xmp = make_shared<SXMPMeta>();
xmp->ParseFromBuffer(tempBuffer.c_str(), tempBuffer.size(), 0);
schemaSource = make_shared<XMPSchemaSource>(xmp);
metadataSource = make_shared<XMPMetadataSource>(xmp);
}


void XMPDataSource::remove(const vector<IdType>& ids)
{
metadataSourceCheck();
try
{
metadataSource->remove(ids);
xmpFile.PutXMP(*xmp);
closeFile();
openFile(this->metaFileName, this->openMode);

/* TODO:
* Existing implementation requires metadata re-reading here,
* so a quick workaround is made below:
* instead of saving to file we just put everything to buffer and get back.
* To be fixed to eliminate re-reading in long term future.
*/
if(ids.size() > 0)
{
serializeAndParse();
}
}
catch(const XMP_Error& e)
{
Expand Down Expand Up @@ -276,7 +466,6 @@ void XMPDataSource::clear()
{
metadataSource->clear();
schemaSource->clear();
pushChanges();
}
catch(const XMP_Error& e)
{
Expand All @@ -302,13 +491,13 @@ IdType XMPDataSource::loadId()
void XMPDataSource::save(const IdType &id)
{
xmp->SetProperty_Int64(VMF_NS, VMF_GLOBAL_NEXT_ID, id);
pushChanges();
}


void XMPDataSource::pushChanges()
{
xmpFile.PutXMP(*xmp);
saveXMPstructs();

closeFile();
openFile(this->metaFileName, this->openMode);
}
Expand All @@ -331,15 +520,22 @@ void XMPDataSource::schemaSourceCheck()

void XMPDataSource::removeSchema(const MetaString &schemaName)
{
/* TODO:
* Existing implementation requires metadata re-reading here,
* so a quick workaround is made below:
* instead of saving to file we just put everything to buffer and get back.
* To be fixed to eliminate re-reading in long term future.
*/
schemaSource->remove(schemaName);
pushChanges();
serializeAndParse();
}

std::string XMPDataSource::computeChecksum(long long& XMPPacketSize, long long& XMPPacketOffset)
{
try
{
xmpFile.GetXMP(xmp.get());
loadXMPstructs();

MetaString checksum;
xmpFile.ComputeChecksum(&checksum, &XMPPacketSize, &XMPPacketOffset);
return checksum;
Expand Down Expand Up @@ -369,7 +565,6 @@ std::string XMPDataSource::loadChecksum()
void XMPDataSource::saveChecksum(const MetaString& checksum)
{
xmp->SetProperty(VMF_NS, VMF_GLOBAL_CHECKSUM, checksum.c_str());
pushChanges();
}

void XMPDataSource::saveVideoSegments(const std::vector<std::shared_ptr<MetadataStream::VideoSegment>>& segments)
Expand Down Expand Up @@ -422,8 +617,6 @@ void XMPDataSource::saveVideoSegments(const std::vector<std::shared_ptr<Metadata
}
});
}

pushChanges();
}

void XMPDataSource::loadVideoSegments(std::vector<std::shared_ptr<MetadataStream::VideoSegment>>& segments)
Expand Down
Loading