annotate vamp-client/client.cpp @ 82:fa2c0358c2b6

Plan
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 11 Oct 2016 16:52:48 +0100
parents c6b6051b1b1a
children 154e94ea84d4
rev   line source
c@78 1
c@78 2 #include "stub.h"
c@78 3
c@80 4 #include "vamp-capnp/VampnProto.h"
c@80 5
c@80 6 #include "vamp-support/AssignedPluginHandleMapper.h"
c@80 7
c@82 8 // First cut plan: this is to be client-qt.cpp, using a QProcess, so
c@82 9 // we're using pipes and the server is completely synchronous,
c@82 10 // handling only one call at once. Our PiperClient will fire off a
c@82 11 // QProcess and refer to its io device. Each request message is
c@82 12 // serialised into memory using capnp::MallocMessageBuilder and
c@82 13 // shunted into the process pipe; we then wait for some bytes to come
c@82 14 // back and use capnp::expectedSizeInWordsFromPrefix to work out when
c@82 15 // a whole message is available, reading only that amount from the
c@82 16 // device and using FlatArrayMessageReader to convert to a response
c@82 17 // message. If the response message's id does not match the request
c@82 18 // message's, then the server has gone wrong (it should never be
c@82 19 // servicing more than one request at a time).
c@82 20
c@82 21 // Next level: Capnp RPC, but I want to get the first level to work
c@82 22 // first.
c@82 23
c@81 24 namespace piper { //!!! probably something different
c@80 25
c@80 26 class PiperClient : public PiperClientBase
c@80 27 {
c@81 28 // unsigned to avoid undefined behaviour on possible wrap
c@81 29 typedef uint32_t ReqId;
c@81 30
c@80 31 public:
c@81 32
c@81 33 PiperClient() { }
c@81 34
c@81 35 Vamp::Plugin *
c@81 36 load(std::string key, float inputSampleRate, int adapterFlags) {
c@81 37
c@81 38 Vamp::HostExt::LoadRequest request;
c@81 39 request.pluginKey = key;
c@81 40 request.inputSampleRate = inputSampleRate;
c@81 41 request.adapterFlags = adapterFlags;
c@81 42
c@81 43 ::capnp::MallocMessageBuilder message;
c@81 44 RpcRequest::Builder builder = message.initRoot<RpcRequest>();
c@81 45
c@81 46 VampnProto::buildRpcRequest_Load(builder, request);
c@81 47 ReqId id = getId();
c@81 48 builder.getId().setNumber(id);
c@81 49 };
c@80 50
c@80 51 virtual
c@80 52 Vamp::Plugin::OutputList
c@80 53 configure(PiperStubPlugin *plugin,
c@80 54 Vamp::HostExt::PluginConfiguration config) {
c@80 55
c@80 56 Vamp::HostExt::ConfigurationRequest request;
c@80 57 request.plugin = plugin;
c@80 58 request.configuration = config;
c@80 59
c@80 60 ::capnp::MallocMessageBuilder message;
c@80 61 RpcRequest::Builder builder = message.initRoot<RpcRequest>();
c@80 62
c@80 63 VampnProto::buildRpcRequest_Configure(builder, request, m_mapper);
c@81 64 ReqId id = getId();
c@81 65 builder.getId().setNumber(id);
c@80 66
c@80 67 //!!! now what?
c@81 68 };
c@80 69
c@80 70
c@80 71 virtual
c@80 72 Vamp::Plugin::FeatureSet
c@80 73 process(PiperStubPlugin *plugin,
c@80 74 const float *const *inputBuffers,
c@80 75 Vamp::RealTime timestamp) = 0;
c@80 76
c@80 77 virtual Vamp::Plugin::FeatureSet
c@80 78 finish(PiperStubPlugin *plugin) = 0;
c@80 79
c@80 80 private:
c@80 81 AssignedPluginHandleMapper m_mapper;
c@81 82 int getId() {
c@81 83 //!!! todo: mutex
c@81 84 static ReqId m_nextId = 0;
c@81 85 return m_nextId++;
c@81 86 }
c@80 87 };
c@80 88
c@80 89 }
c@80 90