Mercurial > hg > piper-cpp
comparison vamp-json/VampJson.h @ 97:427c4c725085
Bring in the Request/Response classes that were in the Vamp SDK, adding them to vamp-support in here instead
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 13 Oct 2016 18:05:35 +0100 |
parents | 5a80e00375b1 |
children | 491a4bc10a01 |
comparison
equal
deleted
inserted
replaced
96:215c9fb6b7a4 | 97:427c4c725085 |
---|---|
42 #include <json11/json11.hpp> | 42 #include <json11/json11.hpp> |
43 #include <base-n/include/basen.hpp> | 43 #include <base-n/include/basen.hpp> |
44 | 44 |
45 #include <vamp-hostsdk/Plugin.h> | 45 #include <vamp-hostsdk/Plugin.h> |
46 #include <vamp-hostsdk/PluginLoader.h> | 46 #include <vamp-hostsdk/PluginLoader.h> |
47 #include <vamp-hostsdk/PluginStaticData.h> | 47 |
48 #include <vamp-hostsdk/PluginConfiguration.h> | 48 #include "vamp-support/PluginStaticData.h" |
49 #include <vamp-hostsdk/RequestResponse.h> | 49 #include "vamp-support/PluginConfiguration.h" |
50 #include "vamp-support/RequestResponse.h" | |
50 | 51 |
51 #include "vamp-support/PluginHandleMapper.h" | 52 #include "vamp-support/PluginHandleMapper.h" |
52 #include "vamp-support/PluginOutputIdMapper.h" | 53 #include "vamp-support/PluginOutputIdMapper.h" |
53 #include "vamp-support/RequestResponseType.h" | 54 #include "vamp-support/RequestResponseType.h" |
54 | 55 |
55 namespace piper { | 56 namespace piper_vamp { |
56 | 57 |
57 /** | 58 /** |
58 * Convert the structures laid out in the Vamp SDK classes into JSON | 59 * Convert the structures laid out in the Vamp SDK classes into JSON |
59 * (and back again) following the schema in the vamp-json-schema | 60 * (and back again) following the schema in the vamp-json-schema |
60 * project repo. | 61 * project repo. |
532 return {}; | 533 return {}; |
533 } | 534 } |
534 } | 535 } |
535 | 536 |
536 static json11::Json | 537 static json11::Json |
537 fromPluginStaticData(const Vamp::HostExt::PluginStaticData &d) { | 538 fromPluginStaticData(const PluginStaticData &d) { |
538 | 539 |
539 json11::Json::object jo; | 540 json11::Json::object jo; |
540 jo["key"] = d.pluginKey; | 541 jo["key"] = d.pluginKey; |
541 jo["basic"] = fromBasicDescriptor(d.basic); | 542 jo["basic"] = fromBasicDescriptor(d.basic); |
542 jo["maker"] = d.maker; | 543 jo["maker"] = d.maker; |
568 jo["basicOutputInfo"] = outinfo; | 569 jo["basicOutputInfo"] = outinfo; |
569 | 570 |
570 return json11::Json(jo); | 571 return json11::Json(jo); |
571 } | 572 } |
572 | 573 |
573 static Vamp::HostExt::PluginStaticData | 574 static PluginStaticData |
574 toPluginStaticData(json11::Json j, std::string &err) { | 575 toPluginStaticData(json11::Json j, std::string &err) { |
575 | 576 |
576 if (!j.has_shape({ | 577 if (!j.has_shape({ |
577 { "key", json11::Json::STRING }, | 578 { "key", json11::Json::STRING }, |
578 { "version", json11::Json::NUMBER }, | 579 { "version", json11::Json::NUMBER }, |
620 | 621 |
621 err = "array expected for basicOutputInfo"; | 622 err = "array expected for basicOutputInfo"; |
622 | 623 |
623 } else { | 624 } else { |
624 | 625 |
625 Vamp::HostExt::PluginStaticData psd; | 626 PluginStaticData psd; |
626 | 627 |
627 psd.pluginKey = j["key"].string_value(); | 628 psd.pluginKey = j["key"].string_value(); |
628 | 629 |
629 toBasicDescriptor(j["basic"], psd.basic, err); | 630 toBasicDescriptor(j["basic"], psd.basic, err); |
630 if (failed(err)) return {}; | 631 if (failed(err)) return {}; |
660 | 661 |
661 psd.inputDomain = toInputDomain(j["inputDomain"].string_value(), err); | 662 psd.inputDomain = toInputDomain(j["inputDomain"].string_value(), err); |
662 if (failed(err)) return {}; | 663 if (failed(err)) return {}; |
663 | 664 |
664 for (const auto &bo : j["basicOutputInfo"].array_items()) { | 665 for (const auto &bo : j["basicOutputInfo"].array_items()) { |
665 Vamp::HostExt::PluginStaticData::Basic b; | 666 PluginStaticData::Basic b; |
666 toBasicDescriptor(bo, b, err); | 667 toBasicDescriptor(bo, b, err); |
667 if (failed(err)) return {}; | 668 if (failed(err)) return {}; |
668 psd.basicOutputInfo.push_back(b); | 669 psd.basicOutputInfo.push_back(b); |
669 } | 670 } |
670 | 671 |
674 // fallthrough error case | 675 // fallthrough error case |
675 return {}; | 676 return {}; |
676 } | 677 } |
677 | 678 |
678 static json11::Json | 679 static json11::Json |
679 fromPluginConfiguration(const Vamp::HostExt::PluginConfiguration &c) { | 680 fromPluginConfiguration(const PluginConfiguration &c) { |
680 | 681 |
681 json11::Json::object jo; | 682 json11::Json::object jo; |
682 | 683 |
683 json11::Json::object paramValues; | 684 json11::Json::object paramValues; |
684 for (auto &vp: c.parameterValues) { | 685 for (auto &vp: c.parameterValues) { |
695 jo["blockSize"] = c.blockSize; | 696 jo["blockSize"] = c.blockSize; |
696 | 697 |
697 return json11::Json(jo); | 698 return json11::Json(jo); |
698 } | 699 } |
699 | 700 |
700 static Vamp::HostExt::PluginConfiguration | 701 static PluginConfiguration |
701 toPluginConfiguration(json11::Json j, std::string &err) { | 702 toPluginConfiguration(json11::Json j, std::string &err) { |
702 | 703 |
703 if (!j.has_shape({ | 704 if (!j.has_shape({ |
704 { "channelCount", json11::Json::NUMBER }, | 705 { "channelCount", json11::Json::NUMBER }, |
705 { "stepSize", json11::Json::NUMBER }, | 706 { "stepSize", json11::Json::NUMBER }, |
725 !j["currentProgram"].is_string()) { | 726 !j["currentProgram"].is_string()) { |
726 err = "string expected for program name"; | 727 err = "string expected for program name"; |
727 return {}; | 728 return {}; |
728 } | 729 } |
729 | 730 |
730 Vamp::HostExt::PluginConfiguration config; | 731 PluginConfiguration config; |
731 | 732 |
732 config.channelCount = j["channelCount"].number_value(); | 733 config.channelCount = j["channelCount"].number_value(); |
733 config.stepSize = j["stepSize"].number_value(); | 734 config.stepSize = j["stepSize"].number_value(); |
734 config.blockSize = j["blockSize"].number_value(); | 735 config.blockSize = j["blockSize"].number_value(); |
735 | 736 |
798 | 799 |
799 return Vamp::HostExt::PluginLoader::AdapterFlags(flags); | 800 return Vamp::HostExt::PluginLoader::AdapterFlags(flags); |
800 } | 801 } |
801 | 802 |
802 static json11::Json | 803 static json11::Json |
803 fromLoadRequest(const Vamp::HostExt::LoadRequest &req) { | 804 fromLoadRequest(const LoadRequest &req) { |
804 | 805 |
805 json11::Json::object jo; | 806 json11::Json::object jo; |
806 jo["key"] = req.pluginKey; | 807 jo["key"] = req.pluginKey; |
807 jo["inputSampleRate"] = req.inputSampleRate; | 808 jo["inputSampleRate"] = req.inputSampleRate; |
808 jo["adapterFlags"] = fromAdapterFlags(req.adapterFlags); | 809 jo["adapterFlags"] = fromAdapterFlags(req.adapterFlags); |
809 return json11::Json(jo); | 810 return json11::Json(jo); |
810 } | 811 } |
811 | 812 |
812 static Vamp::HostExt::LoadRequest | 813 static LoadRequest |
813 toLoadRequest(json11::Json j, std::string &err) { | 814 toLoadRequest(json11::Json j, std::string &err) { |
814 | 815 |
815 if (!j.has_shape({ | 816 if (!j.has_shape({ |
816 { "key", json11::Json::STRING }, | 817 { "key", json11::Json::STRING }, |
817 { "inputSampleRate", json11::Json::NUMBER } }, err)) { | 818 { "inputSampleRate", json11::Json::NUMBER } }, err)) { |
818 err = "malformed load request: " + err; | 819 err = "malformed load request: " + err; |
819 return {}; | 820 return {}; |
820 } | 821 } |
821 | 822 |
822 Vamp::HostExt::LoadRequest req; | 823 LoadRequest req; |
823 req.pluginKey = j["key"].string_value(); | 824 req.pluginKey = j["key"].string_value(); |
824 req.inputSampleRate = j["inputSampleRate"].number_value(); | 825 req.inputSampleRate = j["inputSampleRate"].number_value(); |
825 if (!j["adapterFlags"].is_null()) { | 826 if (!j["adapterFlags"].is_null()) { |
826 req.adapterFlags = toAdapterFlags(j["adapterFlags"], err); | 827 req.adapterFlags = toAdapterFlags(j["adapterFlags"], err); |
827 if (failed(err)) return {}; | 828 if (failed(err)) return {}; |
828 } | 829 } |
829 return req; | 830 return req; |
830 } | 831 } |
831 | 832 |
832 static json11::Json | 833 static json11::Json |
833 fromLoadResponse(const Vamp::HostExt::LoadResponse &resp, | 834 fromLoadResponse(const LoadResponse &resp, |
834 const PluginHandleMapper &pmapper) { | 835 const PluginHandleMapper &pmapper) { |
835 | 836 |
836 json11::Json::object jo; | 837 json11::Json::object jo; |
837 jo["handle"] = double(pmapper.pluginToHandle(resp.plugin)); | 838 jo["handle"] = double(pmapper.pluginToHandle(resp.plugin)); |
838 jo["staticData"] = fromPluginStaticData(resp.staticData); | 839 jo["staticData"] = fromPluginStaticData(resp.staticData); |
839 jo["defaultConfiguration"] = | 840 jo["defaultConfiguration"] = |
840 fromPluginConfiguration(resp.defaultConfiguration); | 841 fromPluginConfiguration(resp.defaultConfiguration); |
841 return json11::Json(jo); | 842 return json11::Json(jo); |
842 } | 843 } |
843 | 844 |
844 static Vamp::HostExt::LoadResponse | 845 static LoadResponse |
845 toLoadResponse(json11::Json j, | 846 toLoadResponse(json11::Json j, |
846 const PluginHandleMapper &pmapper, std::string &err) { | 847 const PluginHandleMapper &pmapper, std::string &err) { |
847 | 848 |
848 if (!j.has_shape({ | 849 if (!j.has_shape({ |
849 { "handle", json11::Json::NUMBER }, | 850 { "handle", json11::Json::NUMBER }, |
851 { "defaultConfiguration", json11::Json::OBJECT } }, err)) { | 852 { "defaultConfiguration", json11::Json::OBJECT } }, err)) { |
852 err = "malformed load response: " + err; | 853 err = "malformed load response: " + err; |
853 return {}; | 854 return {}; |
854 } | 855 } |
855 | 856 |
856 Vamp::HostExt::LoadResponse resp; | 857 LoadResponse resp; |
857 resp.plugin = pmapper.handleToPlugin(j["handle"].int_value()); | 858 resp.plugin = pmapper.handleToPlugin(j["handle"].int_value()); |
858 resp.staticData = toPluginStaticData(j["staticData"], err); | 859 resp.staticData = toPluginStaticData(j["staticData"], err); |
859 if (failed(err)) return {}; | 860 if (failed(err)) return {}; |
860 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"], | 861 resp.defaultConfiguration = toPluginConfiguration(j["defaultConfiguration"], |
861 err); | 862 err); |
862 if (failed(err)) return {}; | 863 if (failed(err)) return {}; |
863 return resp; | 864 return resp; |
864 } | 865 } |
865 | 866 |
866 static json11::Json | 867 static json11::Json |
867 fromConfigurationRequest(const Vamp::HostExt::ConfigurationRequest &cr, | 868 fromConfigurationRequest(const ConfigurationRequest &cr, |
868 const PluginHandleMapper &pmapper) { | 869 const PluginHandleMapper &pmapper) { |
869 | 870 |
870 json11::Json::object jo; | 871 json11::Json::object jo; |
871 | 872 |
872 jo["handle"] = double(pmapper.pluginToHandle(cr.plugin)); | 873 jo["handle"] = double(pmapper.pluginToHandle(cr.plugin)); |
873 jo["configuration"] = fromPluginConfiguration(cr.configuration); | 874 jo["configuration"] = fromPluginConfiguration(cr.configuration); |
874 | 875 |
875 return json11::Json(jo); | 876 return json11::Json(jo); |
876 } | 877 } |
877 | 878 |
878 static Vamp::HostExt::ConfigurationRequest | 879 static ConfigurationRequest |
879 toConfigurationRequest(json11::Json j, | 880 toConfigurationRequest(json11::Json j, |
880 const PluginHandleMapper &pmapper, std::string &err) { | 881 const PluginHandleMapper &pmapper, std::string &err) { |
881 | 882 |
882 if (!j.has_shape({ | 883 if (!j.has_shape({ |
883 { "handle", json11::Json::NUMBER }, | 884 { "handle", json11::Json::NUMBER }, |
884 { "configuration", json11::Json::OBJECT } }, err)) { | 885 { "configuration", json11::Json::OBJECT } }, err)) { |
885 err = "malformed configuration request: " + err; | 886 err = "malformed configuration request: " + err; |
886 return {}; | 887 return {}; |
887 } | 888 } |
888 | 889 |
889 Vamp::HostExt::ConfigurationRequest cr; | 890 ConfigurationRequest cr; |
890 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value()); | 891 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value()); |
891 cr.configuration = toPluginConfiguration(j["configuration"], err); | 892 cr.configuration = toPluginConfiguration(j["configuration"], err); |
892 if (failed(err)) return {}; | 893 if (failed(err)) return {}; |
893 return cr; | 894 return cr; |
894 } | 895 } |
895 | 896 |
896 static json11::Json | 897 static json11::Json |
897 fromConfigurationResponse(const Vamp::HostExt::ConfigurationResponse &cr, | 898 fromConfigurationResponse(const ConfigurationResponse &cr, |
898 const PluginHandleMapper &pmapper) { | 899 const PluginHandleMapper &pmapper) { |
899 | 900 |
900 json11::Json::object jo; | 901 json11::Json::object jo; |
901 | 902 |
902 jo["handle"] = double(pmapper.pluginToHandle(cr.plugin)); | 903 jo["handle"] = double(pmapper.pluginToHandle(cr.plugin)); |
908 jo["outputList"] = outs; | 909 jo["outputList"] = outs; |
909 | 910 |
910 return json11::Json(jo); | 911 return json11::Json(jo); |
911 } | 912 } |
912 | 913 |
913 static Vamp::HostExt::ConfigurationResponse | 914 static ConfigurationResponse |
914 toConfigurationResponse(json11::Json j, | 915 toConfigurationResponse(json11::Json j, |
915 const PluginHandleMapper &pmapper, std::string &err) { | 916 const PluginHandleMapper &pmapper, std::string &err) { |
916 | 917 |
917 Vamp::HostExt::ConfigurationResponse cr; | 918 ConfigurationResponse cr; |
918 | 919 |
919 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value()); | 920 cr.plugin = pmapper.handleToPlugin(j["handle"].int_value()); |
920 | 921 |
921 if (!j["outputList"].is_array()) { | 922 if (!j["outputList"].is_array()) { |
922 err = "array expected for output list"; | 923 err = "array expected for output list"; |
930 | 931 |
931 return cr; | 932 return cr; |
932 } | 933 } |
933 | 934 |
934 static json11::Json | 935 static json11::Json |
935 fromProcessRequest(const Vamp::HostExt::ProcessRequest &r, | 936 fromProcessRequest(const ProcessRequest &r, |
936 const PluginHandleMapper &pmapper, | 937 const PluginHandleMapper &pmapper, |
937 BufferSerialisation serialisation) { | 938 BufferSerialisation serialisation) { |
938 | 939 |
939 json11::Json::object jo; | 940 json11::Json::object jo; |
940 jo["handle"] = double(pmapper.pluginToHandle(r.plugin)); | 941 jo["handle"] = double(pmapper.pluginToHandle(r.plugin)); |
956 | 957 |
957 jo["processInput"] = io; | 958 jo["processInput"] = io; |
958 return json11::Json(jo); | 959 return json11::Json(jo); |
959 } | 960 } |
960 | 961 |
961 static Vamp::HostExt::ProcessRequest | 962 static ProcessRequest |
962 toProcessRequest(json11::Json j, | 963 toProcessRequest(json11::Json j, |
963 const PluginHandleMapper &pmapper, | 964 const PluginHandleMapper &pmapper, |
964 BufferSerialisation &serialisation, std::string &err) { | 965 BufferSerialisation &serialisation, std::string &err) { |
965 | 966 |
966 if (!j.has_shape({ | 967 if (!j.has_shape({ |
977 { "inputBuffers", json11::Json::ARRAY } }, err)) { | 978 { "inputBuffers", json11::Json::ARRAY } }, err)) { |
978 err = "malformed process request: " + err; | 979 err = "malformed process request: " + err; |
979 return {}; | 980 return {}; |
980 } | 981 } |
981 | 982 |
982 Vamp::HostExt::ProcessRequest r; | 983 ProcessRequest r; |
983 r.plugin = pmapper.handleToPlugin(j["handle"].int_value()); | 984 r.plugin = pmapper.handleToPlugin(j["handle"].int_value()); |
984 | 985 |
985 r.timestamp = toRealTime(input["timestamp"], err); | 986 r.timestamp = toRealTime(input["timestamp"], err); |
986 if (failed(err)) return {}; | 987 if (failed(err)) return {}; |
987 | 988 |
1058 addId(jo, id); | 1059 addId(jo, id); |
1059 return json11::Json(jo); | 1060 return json11::Json(jo); |
1060 } | 1061 } |
1061 | 1062 |
1062 static json11::Json | 1063 static json11::Json |
1063 fromRpcResponse_List(const Vamp::HostExt::ListResponse &resp, | 1064 fromRpcResponse_List(const ListResponse &resp, |
1064 const json11::Json &id) { | 1065 const json11::Json &id) { |
1065 | 1066 |
1066 json11::Json::object jo; | 1067 json11::Json::object jo; |
1067 markRPC(jo); | 1068 markRPC(jo); |
1068 | 1069 |
1078 addId(jo, id); | 1079 addId(jo, id); |
1079 return json11::Json(jo); | 1080 return json11::Json(jo); |
1080 } | 1081 } |
1081 | 1082 |
1082 static json11::Json | 1083 static json11::Json |
1083 fromRpcRequest_Load(const Vamp::HostExt::LoadRequest &req, | 1084 fromRpcRequest_Load(const LoadRequest &req, |
1084 const json11::Json &id) { | 1085 const json11::Json &id) { |
1085 | 1086 |
1086 json11::Json::object jo; | 1087 json11::Json::object jo; |
1087 markRPC(jo); | 1088 markRPC(jo); |
1088 | 1089 |
1091 addId(jo, id); | 1092 addId(jo, id); |
1092 return json11::Json(jo); | 1093 return json11::Json(jo); |
1093 } | 1094 } |
1094 | 1095 |
1095 static json11::Json | 1096 static json11::Json |
1096 fromRpcResponse_Load(const Vamp::HostExt::LoadResponse &resp, | 1097 fromRpcResponse_Load(const LoadResponse &resp, |
1097 const PluginHandleMapper &pmapper, | 1098 const PluginHandleMapper &pmapper, |
1098 const json11::Json &id) { | 1099 const json11::Json &id) { |
1099 | 1100 |
1100 if (resp.plugin) { | 1101 if (resp.plugin) { |
1101 | 1102 |
1111 return fromError("Failed to load plugin", RRType::Load, id); | 1112 return fromError("Failed to load plugin", RRType::Load, id); |
1112 } | 1113 } |
1113 } | 1114 } |
1114 | 1115 |
1115 static json11::Json | 1116 static json11::Json |
1116 fromRpcRequest_Configure(const Vamp::HostExt::ConfigurationRequest &req, | 1117 fromRpcRequest_Configure(const ConfigurationRequest &req, |
1117 const PluginHandleMapper &pmapper, | 1118 const PluginHandleMapper &pmapper, |
1118 const json11::Json &id) { | 1119 const json11::Json &id) { |
1119 | 1120 |
1120 json11::Json::object jo; | 1121 json11::Json::object jo; |
1121 markRPC(jo); | 1122 markRPC(jo); |
1125 addId(jo, id); | 1126 addId(jo, id); |
1126 return json11::Json(jo); | 1127 return json11::Json(jo); |
1127 } | 1128 } |
1128 | 1129 |
1129 static json11::Json | 1130 static json11::Json |
1130 fromRpcResponse_Configure(const Vamp::HostExt::ConfigurationResponse &resp, | 1131 fromRpcResponse_Configure(const ConfigurationResponse &resp, |
1131 const PluginHandleMapper &pmapper, | 1132 const PluginHandleMapper &pmapper, |
1132 const json11::Json &id) { | 1133 const json11::Json &id) { |
1133 | 1134 |
1134 if (!resp.outputs.empty()) { | 1135 if (!resp.outputs.empty()) { |
1135 | 1136 |
1145 return fromError("Failed to configure plugin", RRType::Configure, id); | 1146 return fromError("Failed to configure plugin", RRType::Configure, id); |
1146 } | 1147 } |
1147 } | 1148 } |
1148 | 1149 |
1149 static json11::Json | 1150 static json11::Json |
1150 fromRpcRequest_Process(const Vamp::HostExt::ProcessRequest &req, | 1151 fromRpcRequest_Process(const ProcessRequest &req, |
1151 const PluginHandleMapper &pmapper, | 1152 const PluginHandleMapper &pmapper, |
1152 BufferSerialisation serialisation, | 1153 BufferSerialisation serialisation, |
1153 const json11::Json &id) { | 1154 const json11::Json &id) { |
1154 | 1155 |
1155 json11::Json::object jo; | 1156 json11::Json::object jo; |
1160 addId(jo, id); | 1161 addId(jo, id); |
1161 return json11::Json(jo); | 1162 return json11::Json(jo); |
1162 } | 1163 } |
1163 | 1164 |
1164 static json11::Json | 1165 static json11::Json |
1165 fromRpcResponse_Process(const Vamp::HostExt::ProcessResponse &resp, | 1166 fromRpcResponse_Process(const ProcessResponse &resp, |
1166 const PluginHandleMapper &pmapper, | 1167 const PluginHandleMapper &pmapper, |
1167 BufferSerialisation serialisation, | 1168 BufferSerialisation serialisation, |
1168 const json11::Json &id) { | 1169 const json11::Json &id) { |
1169 | 1170 |
1170 json11::Json::object jo; | 1171 json11::Json::object jo; |
1180 addId(jo, id); | 1181 addId(jo, id); |
1181 return json11::Json(jo); | 1182 return json11::Json(jo); |
1182 } | 1183 } |
1183 | 1184 |
1184 static json11::Json | 1185 static json11::Json |
1185 fromRpcRequest_Finish(const Vamp::HostExt::FinishRequest &req, | 1186 fromRpcRequest_Finish(const FinishRequest &req, |
1186 const PluginHandleMapper &pmapper, | 1187 const PluginHandleMapper &pmapper, |
1187 const json11::Json &id) { | 1188 const json11::Json &id) { |
1188 | 1189 |
1189 json11::Json::object jo; | 1190 json11::Json::object jo; |
1190 markRPC(jo); | 1191 markRPC(jo); |
1197 addId(jo, id); | 1198 addId(jo, id); |
1198 return json11::Json(jo); | 1199 return json11::Json(jo); |
1199 } | 1200 } |
1200 | 1201 |
1201 static json11::Json | 1202 static json11::Json |
1202 fromRpcResponse_Finish(const Vamp::HostExt::ProcessResponse &resp, | 1203 fromRpcResponse_Finish(const FinishResponse &resp, |
1203 const PluginHandleMapper &pmapper, | 1204 const PluginHandleMapper &pmapper, |
1204 BufferSerialisation serialisation, | 1205 BufferSerialisation serialisation, |
1205 const json11::Json &id) { | 1206 const json11::Json &id) { |
1206 | 1207 |
1207 json11::Json::object jo; | 1208 json11::Json::object jo; |
1271 static void | 1272 static void |
1272 toRpcRequest_List(json11::Json j, std::string &err) { | 1273 toRpcRequest_List(json11::Json j, std::string &err) { |
1273 checkTypeField(j, "list", err); | 1274 checkTypeField(j, "list", err); |
1274 } | 1275 } |
1275 | 1276 |
1276 static Vamp::HostExt::ListResponse | 1277 static ListResponse |
1277 toRpcResponse_List(json11::Json j, std::string &err) { | 1278 toRpcResponse_List(json11::Json j, std::string &err) { |
1278 | 1279 |
1279 Vamp::HostExt::ListResponse resp; | 1280 ListResponse resp; |
1280 if (successful(j, err) && !failed(err)) { | 1281 if (successful(j, err) && !failed(err)) { |
1281 for (const auto &a: j["result"]["available"].array_items()) { | 1282 for (const auto &a: j["result"]["available"].array_items()) { |
1282 resp.available.push_back(toPluginStaticData(a, err)); | 1283 resp.available.push_back(toPluginStaticData(a, err)); |
1283 if (failed(err)) return {}; | 1284 if (failed(err)) return {}; |
1284 } | 1285 } |
1285 } | 1286 } |
1286 | 1287 |
1287 return resp; | 1288 return resp; |
1288 } | 1289 } |
1289 | 1290 |
1290 static Vamp::HostExt::LoadRequest | 1291 static LoadRequest |
1291 toRpcRequest_Load(json11::Json j, std::string &err) { | 1292 toRpcRequest_Load(json11::Json j, std::string &err) { |
1292 | 1293 |
1293 checkTypeField(j, "load", err); | 1294 checkTypeField(j, "load", err); |
1294 if (failed(err)) return {}; | 1295 if (failed(err)) return {}; |
1295 return toLoadRequest(j["params"], err); | 1296 return toLoadRequest(j["params"], err); |
1296 } | 1297 } |
1297 | 1298 |
1298 static Vamp::HostExt::LoadResponse | 1299 static LoadResponse |
1299 toRpcResponse_Load(json11::Json j, | 1300 toRpcResponse_Load(json11::Json j, |
1300 const PluginHandleMapper &pmapper, | 1301 const PluginHandleMapper &pmapper, |
1301 std::string &err) { | 1302 std::string &err) { |
1302 | 1303 |
1303 Vamp::HostExt::LoadResponse resp; | 1304 LoadResponse resp; |
1304 if (successful(j, err) && !failed(err)) { | 1305 if (successful(j, err) && !failed(err)) { |
1305 resp = toLoadResponse(j["result"], pmapper, err); | 1306 resp = toLoadResponse(j["result"], pmapper, err); |
1306 } | 1307 } |
1307 return resp; | 1308 return resp; |
1308 } | 1309 } |
1309 | 1310 |
1310 static Vamp::HostExt::ConfigurationRequest | 1311 static ConfigurationRequest |
1311 toRpcRequest_Configure(json11::Json j, | 1312 toRpcRequest_Configure(json11::Json j, |
1312 const PluginHandleMapper &pmapper, | 1313 const PluginHandleMapper &pmapper, |
1313 std::string &err) { | 1314 std::string &err) { |
1314 | 1315 |
1315 checkTypeField(j, "configure", err); | 1316 checkTypeField(j, "configure", err); |
1316 if (failed(err)) return {}; | 1317 if (failed(err)) return {}; |
1317 return toConfigurationRequest(j["params"], pmapper, err); | 1318 return toConfigurationRequest(j["params"], pmapper, err); |
1318 } | 1319 } |
1319 | 1320 |
1320 static Vamp::HostExt::ConfigurationResponse | 1321 static ConfigurationResponse |
1321 toRpcResponse_Configure(json11::Json j, | 1322 toRpcResponse_Configure(json11::Json j, |
1322 const PluginHandleMapper &pmapper, | 1323 const PluginHandleMapper &pmapper, |
1323 std::string &err) { | 1324 std::string &err) { |
1324 | 1325 |
1325 Vamp::HostExt::ConfigurationResponse resp; | 1326 ConfigurationResponse resp; |
1326 if (successful(j, err) && !failed(err)) { | 1327 if (successful(j, err) && !failed(err)) { |
1327 resp = toConfigurationResponse(j["result"], pmapper, err); | 1328 resp = toConfigurationResponse(j["result"], pmapper, err); |
1328 } | 1329 } |
1329 return resp; | 1330 return resp; |
1330 } | 1331 } |
1331 | 1332 |
1332 static Vamp::HostExt::ProcessRequest | 1333 static ProcessRequest |
1333 toRpcRequest_Process(json11::Json j, const PluginHandleMapper &pmapper, | 1334 toRpcRequest_Process(json11::Json j, const PluginHandleMapper &pmapper, |
1334 BufferSerialisation &serialisation, std::string &err) { | 1335 BufferSerialisation &serialisation, std::string &err) { |
1335 | 1336 |
1336 checkTypeField(j, "process", err); | 1337 checkTypeField(j, "process", err); |
1337 if (failed(err)) return {}; | 1338 if (failed(err)) return {}; |
1338 return toProcessRequest(j["params"], pmapper, serialisation, err); | 1339 return toProcessRequest(j["params"], pmapper, serialisation, err); |
1339 } | 1340 } |
1340 | 1341 |
1341 static Vamp::HostExt::ProcessResponse | 1342 static ProcessResponse |
1342 toRpcResponse_Process(json11::Json j, | 1343 toRpcResponse_Process(json11::Json j, |
1343 const PluginHandleMapper &pmapper, | 1344 const PluginHandleMapper &pmapper, |
1344 BufferSerialisation &serialisation, std::string &err) { | 1345 BufferSerialisation &serialisation, std::string &err) { |
1345 | 1346 |
1346 Vamp::HostExt::ProcessResponse resp; | 1347 ProcessResponse resp; |
1347 if (successful(j, err) && !failed(err)) { | 1348 if (successful(j, err) && !failed(err)) { |
1348 auto jc = j["result"]; | 1349 auto jc = j["result"]; |
1349 auto h = jc["handle"].int_value(); | 1350 auto h = jc["handle"].int_value(); |
1350 resp.plugin = pmapper.handleToPlugin(h); | 1351 resp.plugin = pmapper.handleToPlugin(h); |
1351 resp.features = toFeatureSet(jc["features"], | 1352 resp.features = toFeatureSet(jc["features"], |
1353 serialisation, err); | 1354 serialisation, err); |
1354 } | 1355 } |
1355 return resp; | 1356 return resp; |
1356 } | 1357 } |
1357 | 1358 |
1358 static Vamp::HostExt::FinishRequest | 1359 static FinishRequest |
1359 toRpcRequest_Finish(json11::Json j, const PluginHandleMapper &pmapper, | 1360 toRpcRequest_Finish(json11::Json j, const PluginHandleMapper &pmapper, |
1360 std::string &err) { | 1361 std::string &err) { |
1361 | 1362 |
1362 checkTypeField(j, "finish", err); | 1363 checkTypeField(j, "finish", err); |
1363 if (failed(err)) return {}; | 1364 if (failed(err)) return {}; |
1364 Vamp::HostExt::FinishRequest req; | 1365 FinishRequest req; |
1365 req.plugin = pmapper.handleToPlugin | 1366 req.plugin = pmapper.handleToPlugin |
1366 (j["params"]["handle"].int_value()); | 1367 (j["params"]["handle"].int_value()); |
1367 return req; | 1368 return req; |
1368 } | 1369 } |
1369 | 1370 |
1370 static Vamp::HostExt::ProcessResponse | 1371 static FinishResponse |
1371 toRpcResponse_Finish(json11::Json j, | 1372 toRpcResponse_Finish(json11::Json j, |
1372 const PluginHandleMapper &pmapper, | 1373 const PluginHandleMapper &pmapper, |
1373 BufferSerialisation &serialisation, std::string &err) { | 1374 BufferSerialisation &serialisation, std::string &err) { |
1374 | 1375 |
1375 Vamp::HostExt::ProcessResponse resp; | 1376 FinishResponse resp; |
1376 if (successful(j, err) && !failed(err)) { | 1377 if (successful(j, err) && !failed(err)) { |
1377 auto jc = j["result"]; | 1378 auto jc = j["result"]; |
1378 auto h = jc["handle"].int_value(); | 1379 auto h = jc["handle"].int_value(); |
1379 resp.plugin = pmapper.handleToPlugin(h); | 1380 resp.plugin = pmapper.handleToPlugin(h); |
1380 resp.features = toFeatureSet(jc["features"], | 1381 resp.features = toFeatureSet(jc["features"], |