# HG changeset patch # User Chris Cannam # Date 1473344868 -3600 # Node ID 5e6ff69b420970301308c46df75a595185215019 # Parent 8f2cf0e26510ea83214ca8e916b1d1e15a4ca43a Make base64/text selectable when serialising process and feature blocks; add base64 version as an output format for vampipe-convert; make VamPipePluginLibrary switch to returning base64 encoding as soon as it is fed any as input diff -r 8f2cf0e26510 -r 5e6ff69b4209 Makefile.example.emscripten --- a/Makefile.example.emscripten Wed Sep 07 16:38:24 2016 +0100 +++ b/Makefile.example.emscripten Thu Sep 08 15:27:48 2016 +0100 @@ -31,13 +31,13 @@ EMFLAGS := \ --memory-init-file 0 \ - -s NO_FILESYSTEM=1 \ -s MODULARIZE=1 \ -s ERROR_ON_UNDEFINED_SYMBOLS=1 \ -s DISABLE_EXCEPTION_CATCHING=0 \ -s EXPORT_NAME="'ExampleModule'" \ -s EXPORTED_FUNCTIONS="['_vampipeRequestJson','_vampipeFreeJson']" +# -s NO_FILESYSTEM=1 \ # no longer exists? -s NO_BROWSER=1 EXAMPLE_EXT := .js diff -r 8f2cf0e26510 -r 5e6ff69b4209 VamPipePluginLibrary.cpp --- a/VamPipePluginLibrary.cpp Wed Sep 07 16:38:24 2016 +0100 +++ b/VamPipePluginLibrary.cpp Thu Sep 08 15:27:48 2016 +0100 @@ -64,7 +64,8 @@ return j; } -VamPipePluginLibrary::VamPipePluginLibrary(vector pp) +VamPipePluginLibrary::VamPipePluginLibrary(vector pp) : + m_useBase64(false) { for (VamPipeAdapterBase *p: pp) { string key = p->getStaticData().pluginKey; @@ -73,7 +74,7 @@ } RequestOrResponse -VamPipePluginLibrary::readRequest(string req) const +VamPipePluginLibrary::readRequest(string req) { RequestOrResponse rr; rr.direction = RequestOrResponse::Request; @@ -82,6 +83,7 @@ //!!! reduce, reduce rr.type = VampJson::getRequestResponseType(j); + VampJson::BufferSerialisation serialisation = VampJson::BufferSerialisation::Text; switch (rr.type) { @@ -95,7 +97,7 @@ rr.configurationRequest = VampJson::toVampRequest_Configure(j, m_mapper); break; case RRType::Process: - rr.processRequest = VampJson::toVampRequest_Process(j, m_mapper); + rr.processRequest = VampJson::toVampRequest_Process(j, m_mapper, serialisation); break; case RRType::Finish: rr.finishPlugin = VampJson::toVampRequest_Finish(j, m_mapper); @@ -104,6 +106,10 @@ break; } + if (serialisation == VampJson::BufferSerialisation::Base64) { + m_useBase64 = true; + } + return rr; } @@ -112,6 +118,11 @@ { Json j; + VampJson::BufferSerialisation serialisation = + (m_useBase64 ? + VampJson::BufferSerialisation::Base64 : + VampJson::BufferSerialisation::Text); + switch (rr.type) { case RRType::List: @@ -124,10 +135,10 @@ j = VampJson::fromVampResponse_Configure(rr.configurationResponse); break; case RRType::Process: - j = VampJson::fromVampResponse_Process(rr.processResponse); + j = VampJson::fromVampResponse_Process(rr.processResponse, serialisation); break; case RRType::Finish: - j = VampJson::fromVampResponse_Finish(rr.finishResponse); + j = VampJson::fromVampResponse_Finish(rr.finishResponse, serialisation); break; case RRType::NotValid: break; @@ -189,6 +200,7 @@ try { request = readRequest(req); } catch (const std::exception &e) { + std::cerr << "FAILURE" << std::endl; return VampJson::fromException(e, RRType::NotValid).dump(); } @@ -253,7 +265,7 @@ } response.processResponse.features = - preq.plugin->process(fbuffers, preq.timestamp); + preq.plugin->process(fbuffers, preq.timestamp); response.success = true; delete[] fbuffers; diff -r 8f2cf0e26510 -r 5e6ff69b4209 VamPipePluginLibrary.h --- a/VamPipePluginLibrary.h Wed Sep 07 16:38:24 2016 +0100 +++ b/VamPipePluginLibrary.h Thu Sep 08 15:27:48 2016 +0100 @@ -65,7 +65,7 @@ private: std::string requestJsonImpl(std::string req); - RequestOrResponse readRequest(std::string req) const; + RequestOrResponse readRequest(std::string req); std::string writeResponse(const RequestOrResponse &resp) const; //!!! no type for this in RequestResponse.h in vamp sdk, should there be? @@ -76,6 +76,7 @@ std::map m_adapters; // pluginKey -> adapter CountingPluginHandleMapper m_mapper; + bool m_useBase64; }; } diff -r 8f2cf0e26510 -r 5e6ff69b4209 quick-test.cpp --- a/quick-test.cpp Wed Sep 07 16:38:24 2016 +0100 +++ b/quick-test.cpp Thu Sep 08 15:27:48 2016 +0100 @@ -49,11 +49,15 @@ const char *processResponse = reqFn(processRequest.c_str()); cout << processResponse << endl; freeFn(processResponse); + + string b64processRequest = "{\"type\":\"process\",\"content\":{\"pluginHandle\":1,\"processInput\":{\"timestamp\":{\"s\":0,\"n\":0},\"inputBuffers\":[{\"b64values\":\"AAAAAAAAgD8AAAAAAACAvwAAAAAAAIA/AAAAAAAAgL8\"}]}}}"; + const char *b64processResponse = reqFn(b64processRequest.c_str()); + cout << b64processResponse << endl; + freeFn(b64processResponse); string finishRequest = "{\"type\":\"finish\",\"content\":{\"pluginHandle\":1}}"; const char *finishResponse = reqFn(finishRequest.c_str()); cout << finishResponse << endl; freeFn(finishResponse); - }