# HG changeset patch # User Chris Cannam # Date 1473432095 -3600 # Node ID 5bd5d48a1c2149f258073b53fb3f5ed6b6cea4cd # Parent 5e6ff69b420970301308c46df75a595185215019 Introduce "raw" process call in which the input is not serialised diff -r 5e6ff69b4209 -r 5bd5d48a1c21 Makefile.example.emscripten --- a/Makefile.example.emscripten Thu Sep 08 15:27:48 2016 +0100 +++ b/Makefile.example.emscripten Fri Sep 09 15:41:35 2016 +0100 @@ -35,7 +35,7 @@ -s ERROR_ON_UNDEFINED_SYMBOLS=1 \ -s DISABLE_EXCEPTION_CATCHING=0 \ -s EXPORT_NAME="'ExampleModule'" \ - -s EXPORTED_FUNCTIONS="['_vampipeRequestJson','_vampipeFreeJson']" + -s EXPORTED_FUNCTIONS="['_vampipeRequestJson','_vampipeProcess','_vampipeFreeJson']" # -s NO_FILESYSTEM=1 \ # no longer exists? -s NO_BROWSER=1 diff -r 5e6ff69b4209 -r 5bd5d48a1c21 VamPipePluginLibrary.cpp --- a/VamPipePluginLibrary.cpp Thu Sep 08 15:27:48 2016 +0100 +++ b/VamPipePluginLibrary.cpp Fri Sep 09 15:41:35 2016 +0100 @@ -193,6 +193,36 @@ } string +VamPipePluginLibrary::processImpl(int pluginHandle, + const float *const *inputBuffers, + int sec, + int nsec) +{ + RequestOrResponse response; + response.direction = RequestOrResponse::Response; + response.type = RRType::Process; + + try { + if (!m_mapper.isConfigured(pluginHandle)) { + throw runtime_error("plugin has not been configured"); + } + + Vamp::Plugin *plugin = m_mapper.handleToPlugin(pluginHandle); + Vamp::RealTime timestamp(sec, nsec); + + response.processResponse.features = plugin->process(inputBuffers, timestamp); + response.success = true; + + return writeResponse(response); + + } catch (const std::exception &e) { + return VampJson::fromException(e, RRType::Process).dump(); + } + + m_useBase64 = true; //!!! todo: return something raw as well! +} + +string VamPipePluginLibrary::requestJsonImpl(string req) { RequestOrResponse request; @@ -200,7 +230,6 @@ try { request = readRequest(req); } catch (const std::exception &e) { - std::cerr << "FAILURE" << std::endl; return VampJson::fromException(e, RRType::NotValid).dump(); } @@ -254,7 +283,7 @@ if (channels != m_mapper.getChannelCount(h)) { throw runtime_error("wrong number of channels supplied to process"); } - + const float **fbuffers = new const float *[channels]; for (int i = 0; i < channels; ++i) { if (int(preq.inputBuffers[i].size()) != m_mapper.getBlockSize(h)) { diff -r 5e6ff69b4209 -r 5bd5d48a1c21 VamPipePluginLibrary.h --- a/VamPipePluginLibrary.h Thu Sep 08 15:27:48 2016 +0100 +++ b/VamPipePluginLibrary.h Fri Sep 09 15:41:35 2016 +0100 @@ -58,12 +58,18 @@ return strdup(requestJsonImpl(request).c_str()); } + const char *process(int handle, const float *const *inputBuffers, + int sec, int nsec) { + return strdup(processImpl(handle, inputBuffers, sec, nsec).c_str()); + } + void freeJson(const char *json) { free(const_cast(json)); } private: std::string requestJsonImpl(std::string req); + std::string processImpl(int, const float *const *, int, int); RequestOrResponse readRequest(std::string req); std::string writeResponse(const RequestOrResponse &resp) const; diff -r 5e6ff69b4209 -r 5bd5d48a1c21 example.cpp --- a/example.cpp Thu Sep 08 15:27:48 2016 +0100 +++ b/example.cpp Fri Sep 09 15:41:35 2016 +0100 @@ -69,6 +69,15 @@ return library.requestJson(request); } + //!!! naming problem -- returns json as well, it's just that + //!!! unlike the others, it doesn't take json as input +const char *vampipeProcess(int pluginHandle, + const float *const *inputBuffers, + int sec, + int nsec) { + return library.process(pluginHandle, inputBuffers, sec, nsec); +} + void vampipeFreeJson(const char *json) { return library.freeJson(json); } diff -r 5e6ff69b4209 -r 5bd5d48a1c21 vampipe.map --- a/vampipe.map Thu Sep 08 15:27:48 2016 +0100 +++ b/vampipe.map Fri Sep 09 15:41:35 2016 +0100 @@ -1,4 +1,4 @@ { - global: vampipeRequestJson; vampipeFreeJson; + global: vampipeRequestJson; vampipeProcess; vampipeFreeJson; local: *; };