Add LV2 option/extension for plugin thread sched priority
[ardour.git] / libs / ardour / lv2_plugin.cc
index 79bef11cdde146bb9170f406d56800eafbbb5342..15c96ac83ee988b4005c9d9c86b7661b5c624b24 100644 (file)
@@ -37,6 +37,7 @@
 #include "pbd/compose.h"
 #include "pbd/error.h"
 #include "pbd/locale_guard.h"
+#include "pbd/pthread_utils.h"
 #include "pbd/replace_all.h"
 #include "pbd/xml++.h"
 
@@ -495,6 +496,8 @@ LV2Plugin::init(const void* c_plugin, samplecnt_t rate)
        LV2_URID atom_Int = _uri_map.uri_to_id(LV2_ATOM__Int);
        static const int32_t _min_block_length = 1;   // may happen during split-cycles
        static const int32_t _max_block_length = 8192; // max possible (with all engines and during export)
+       static const int32_t rt_policy = PBD_SCHED_FIFO;
+       static const int32_t rt_priority = pbd_absolute_rt_priority (PBD_SCHED_FIFO, AudioEngine::instance()->client_real_time_priority () - 2);
        /* Consider updating max-block-size whenever the buffersize changes.
         * It requires re-instantiating the plugin (which is a non-realtime operation),
         * so it should be done lightly and only for plugins that require it.
@@ -511,6 +514,10 @@ LV2Plugin::init(const void* c_plugin, samplecnt_t rate)
                  sizeof(int32_t), atom_Int, &_seq_size },
                { LV2_OPTIONS_INSTANCE, 0, _uri_map.uri_to_id("http://lv2plug.in/ns/ext/buf-size#nominalBlockLength"),
                  sizeof(int32_t), atom_Int, &_impl->block_length },
+               { LV2_OPTIONS_INSTANCE, 0, _uri_map.uri_to_id("http://ardour.org/lv2/threads/#schedPolicy"),
+                 sizeof(int32_t), atom_Int, &rt_policy },
+               { LV2_OPTIONS_INSTANCE, 0, _uri_map.uri_to_id("http://ardour.org/lv2/threads/#schedPriority"),
+                 sizeof(int32_t), atom_Int, &rt_priority },
                { LV2_OPTIONS_INSTANCE, 0, 0, 0, 0, NULL }
        };