Exemplo n.º 1
0
Arquivo: main.cpp Projeto: SSE4/vmf-1
void printMetadataStructure(const string& path)
{
    cout << "\nPrinting metadata structure.\n" << "[stream]: " << path << endl;
    MetadataStream ms;
    if (!ms.open(path, MetadataStream::ReadOnly))
        throw std::runtime_error("Can't open MetadataStream");
    auto sNames = ms.getAllSchemaNames();
    for (unsigned int sNum = 0; sNum < sNames.size(); sNum++)
    {
        auto sName = sNames[sNum];
        cout << "\t* (" << sNum << ") [schema]: " << sName << endl;
        if(!ms.load(sName)) // we need to load schema to get items count
            throw std::runtime_error(string("Error loading schema: ") + sName);
        auto mDescs = ms.getSchema(sName)->getAll();
        for (unsigned int setNum = 0; setNum < mDescs.size(); setNum++)
        {
            auto mDesc = mDescs[setNum];
            string setName = mDesc->getMetadataName();
            auto setSize = ms.queryByName(setName).size();
            string fieldsString;
            const char * separator = "";
            auto fields = mDesc->getFields();
            for (auto fd = fields.begin(); fd != fields.end(); fd++)
            {
                fieldsString += separator + fd->name;
                separator = ",";
            }
            cout << "\t\t* (" << sNum << "." << setNum << ") [set]: " << setName << "(" << setSize << " items)" << " {" << fieldsString << "}" << endl;
        }
    }
}
Exemplo n.º 2
0
Arquivo: main.cpp Projeto: SSE4/vmf-1
// schemaName == "" means all schemas (i.e. all metadata in the stream)
// setName == "" means the whole schema with descriptions
// schemaName and setName specified means removal all the metadata items from the specified set
void removeMetadata(const string& path, const string& schemaName = "", const string& setName = "")
{
    cout << "\nRemoving metadata: " 
         << (schemaName.empty() ? string("*") : schemaName + '/' + 
                                               (setName.empty() ? string("*") : setName) ) 
         << endl;
    MetadataStream ms;
    if (!ms.open(path, MetadataStream::ReadWrite))
        throw std::runtime_error("Can't open MetadataStream");
    vector<string> schemas;
    if(schemaName.empty())
    {
        // remove all metadata
        ms.remove();
    }
    else
    {
        schemas.push_back(schemaName);
        for (unsigned int sNum = 0; sNum < schemas.size(); sNum++)
        {
            auto sName = schemas[sNum];
            cout << "\t* (" << sNum << ") [schema]: " << sName << endl;
            if(!ms.load(sName))
                throw std::runtime_error(string("Error loading schema: ") + sName);
            vector<shared_ptr<MetadataDesc>>mDescs;
            if(setName.empty())
            {
                // remove the whole schema with descriptions
                ms.remove( ms.getSchema(sName) );
            }
            else
            {
                mDescs.push_back(ms.getSchema(sName)->findMetadataDesc(setName));
                for (unsigned int setNum = 0; setNum < mDescs.size(); setNum++)
                {
                    auto mDesc = mDescs[setNum];
                    string setName = mDesc->getMetadataName();
                    MetadataSet set = ms.queryByName(setName);
                    cout << "\t\t* (" << sNum << "." << setNum << ") [set]: " << setName << "(" << set.size() << " items)" << endl;
                    ms.remove(set);
                    set.clear();
                }
            }
        }
    }
    cout << "Saving stream..." << endl;
    ms.save();
    cout << "Done." << endl;
}
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: SSE4/vmf-1
// setName == "" means all sets in the specified schema
// schemaName == "" means all schemas (i.e. all metadata)
void dumpMetadata(const string& path, const string& schemaName = "", const string& setName = "")
{
    cout << "\nDumping metadata: " 
         << (schemaName.empty() ? string("*") : schemaName + '/' + 
                                               (setName.empty() ? string("*") : setName) ) 
         << endl;
    MetadataStream ms;
    if (!ms.open(path, MetadataStream::ReadOnly))
        throw std::runtime_error("Can't open MetadataStream");
    vector<string> schemas;
    if(schemaName.empty()) ms.getAllSchemaNames().swap(schemas);
    else schemas.push_back(schemaName);
    for (unsigned int sNum = 0; sNum < schemas.size(); sNum++)
    {
        auto sName = schemas[sNum];
        cout << "* (" << sNum << ") [schema]: " << sName << endl;
        if(!ms.load(sName))
            throw std::runtime_error(string("Error loading schema: " + sName).c_str());
        vector<shared_ptr<MetadataDesc>>mDescs;
        if(setName.empty()) ms.getSchema(sName)->getAll().swap(mDescs);
        else mDescs.push_back(ms.getSchema(sName)->findMetadataDesc(setName));
        for (unsigned int setNum = 0; setNum < mDescs.size(); setNum++)
        {
            auto mDesc = mDescs[setNum];
            string setName = mDesc->getMetadataName();
            MetadataSet set = ms.queryByName(setName);
            cout << "\t* (" << sNum << "." << setNum << ") [set]: " << setName << "(" << set.size() << " items)" << endl;
            if(set.empty()) continue;
            vector<string> fields(set[0]->getFieldNames());
            int itemNum = 0;
            for (auto item = set.begin(); item != set.end(); item++)
            {
                cout << "\t\t* (" << sNum << "." << setNum << "." << ++itemNum << ") { ";
                const char * separator = "";
                for (auto f = fields.begin(); f != fields.end(); f++)
                {
                    cout << separator << *f << "=";
                    try { cout << (*item)->getFieldValue(*f).toString(); }
                    catch(vmf::Exception& e) { cout << '<' << e.what() << '>'; }
                    separator = ", ";
                }
                cout << " }" << endl;
            }
        }
    }
}
Exemplo n.º 4
0
Arquivo: main.cpp Projeto: 01org/vmf
int main(int argc, char **argv)
{
    QApplication a(argc, argv);

    umf::initialize();

    std::string appPath = argv[0];
#ifdef WIN32
    char delim = '\\';
#else
    char delim = '/';
#endif
    size_t pos = appPath.find_last_of(delim);

    if (pos != std::string::npos)
    {
        workingPath = appPath.substr(0, pos);
    }

    if (QFile::exists(TEST_FILE))
        QFile::remove(TEST_FILE);

    QFile::copy(VIDEO_FILE.c_str(), "global_test.avi");

    const umf_string FILE_NAME = "global_test.avi";
    const umf_string SCHEMA_NAME = "demo-unicode-schema";
    const umf_string STRING_METADATA = "unicode-string-metadata";

    {
        auto schema = make_shared<MetadataSchema>(SCHEMA_NAME);
        auto desc = make_shared<MetadataDesc>(STRING_METADATA, Variant::type_string);
        schema->add(desc);
        MetadataStream stream;
        if (!stream.open(FILE_NAME, MetadataStream::Update))
        {
            cerr << "Failed to open file " << FILE_NAME << endl;
            return -1;
        }
        stream.addSchema(schema);
        auto metadata = make_shared<Metadata>(desc);
        // UTF-8 string with Russian text
        std::string str("\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82\x21");
        metadata->addValue(str);
        stream.add(metadata);
        if (!stream.save())
        {
            cerr << "Failed to save file " << FILE_NAME << endl;
            return -1;
        }
        stream.close();
    }

    {
        MetadataStream stream;
        if (!stream.open(FILE_NAME, MetadataStream::ReadOnly))
        {
            cerr << "Failed to open file " << FILE_NAME << endl;
            return -1;
        }
        if (!stream.load(SCHEMA_NAME))
        {
            cerr << "Failed to load schema " << SCHEMA_NAME << endl;
            return -1;
        }
        auto stringMetadata = stream.queryByName(STRING_METADATA);
        auto savedMetadata = stringMetadata.at(0);
        std::string savedString = savedMetadata->at(0);
        QMessageBox::information(NULL, "UMF Demo Unicode", QString::fromUtf8(savedString.c_str()));
    }

    umf::terminate();
    return 0;
}
Exemplo n.º 5
0
void readAndDumpEncryptedMetadata(const umf_string& videoFile, std::shared_ptr<Encryptor> encryptor)
{
    cout << "Opening file name '" << videoFile << "'" << endl;

    // Open new metadata stream to load and print saved metadata
    MetadataStream loadStream;
    loadStream.setEncryptor(encryptor);
    if (!loadStream.open(videoFile, MetadataStream::ReadOnly))
    {
        cerr << "Can't open file " << videoFile << endl;
        exit(1);
    }

    if(loadStream.getUseEncryption())
    {
        cout << "The whole stream is encrypted" << endl;
    }

    // Get all schemas
    vector<string> schemas = loadStream.getAllSchemaNames();
    // and dump all the related data to console
    for(size_t sNum = 0; sNum < schemas.size(); sNum++)
    {
        string sName = schemas[sNum];
        std::shared_ptr<MetadataSchema> schemaPtr = loadStream.getSchema(sName);
        bool schemaEncrypted = schemaPtr->getUseEncryption();
        cout << "* (" << sNum << ") [schema]: " << sName;
        if(schemaEncrypted)
        {
            cout << ", encrypted";
        }
        cout << endl;

        if(!loadStream.load(sName))
        {
            cerr << "Error loading schema " << sName << endl;
            exit(1);
        }

        vector< shared_ptr<MetadataDesc> > mDescs = schemaPtr->getAll();
        for(size_t setNum = 0; setNum < mDescs.size(); setNum++)
        {
            shared_ptr<MetadataDesc> mDesc = mDescs[setNum];
            string setName = mDesc->getMetadataName();
            bool metadescEncrypted = mDesc->getUseEncryption();
            MetadataSet mdSet = loadStream.queryByName(setName);
            cout << "\t* (" << sNum << "." << setNum << ") [set]: ";
            cout << setName << "(" << mdSet.size() << " items)";


            if(mdSet.empty()) continue;
            vector<string> fields(mdSet[0]->getFieldNames());
            cout << " {";
            const char * separator = "";
            for(FieldDesc fDesc : mDesc->getFields())
            {
                cout << separator << fDesc.name;
                if(fDesc.useEncryption)
                {
                    cout << " encrypted";
                }
                separator = ", ";
            }
            cout << "}";
            if(metadescEncrypted)
            {
                cout << ", encrypted";
            }
            cout << endl;
            int itemNum = 0;
            for(const std::shared_ptr<Metadata>& item : mdSet)
            {
                if (itemNum++ <= 3)
                {
                    cout << "\t\t* (" << sNum << "." << setNum << "." << itemNum << ") { ";
                    separator = "";
                    for (const string& f : fields)
                    {
                        cout << separator << f << "=";
                        try { cout << item->getFieldValue(f).toString(); }
                        catch (umf::Exception& e) { cout << '<' << e.what() << '>'; }
                        if(item->findField(f)->getUseEncryption())
                        {
                            cout << " encrypted";
                        }
                        separator = ", ";
                    }
                    cout << " }";
                    long long t = item->getTime();
                    if (t >= 0) cout << ", time " << t;
                    if(item->getUseEncryption()) cout << ", encrypted";
                    cout << endl;
                }
                else
                    cout << '.';
            }
            cout << "\n\t\t" << itemNum << " items." << endl;
        }
    }

    // Close metadata stream
    loadStream.close();
}