adjust LV2 ringbuffer size according to LV2:resize-port
authorRobin Gareus <robin@gareus.org>
Thu, 12 Dec 2013 13:40:45 +0000 (14:40 +0100)
committerRobin Gareus <robin@gareus.org>
Thu, 12 Dec 2013 13:42:02 +0000 (14:42 +0100)
The message-size itself is part of the message which
stored in the ringbuffer. If the rinbuffer overflows
the message is misinterpreted -> segfault.

Choose a more conservative ring-buffer size and take
the requested LV2 size into account.

libs/ardour/lv2_plugin.cc

index da514f92e4e60a6b3028f0bbd30ed540c844bcd1..a1d9de1e534c6e50388e11ab6e60de5fc0e1e8f7 100644 (file)
@@ -1162,10 +1162,14 @@ LV2Plugin::write_from_ui(uint32_t       index,
                 *  e.g 48kSPS / 128fpp -> audio-periods = 375 Hz
                 *  ui-periods = 25 Hz (SuperRapidScreenUpdate)
                 *  default minimumSize = 32K (see LV2Plugin::allocate_atom_event_buffers()
-                *  -> 15 * 32K
-                * it is safe to overflow (but the plugin state may be inconsistent).
+                *
+                * it is NOT safe to overflow (msg.size will be misinterpreted)
                 */
-               rbs = max((size_t) 32768 * 6, rbs);
+               uint32_t bufsiz = 32768;
+               if (_atom_ev_buffers && _atom_ev_buffers[0]) {
+                       bufsiz =  lv2_evbuf_get_capacity(_atom_ev_buffers[0]);
+               }
+               rbs = max((size_t) bufsiz * 8, rbs);
                _from_ui = new RingBuffer<uint8_t>(rbs);
        }
 
@@ -1194,8 +1198,12 @@ LV2Plugin::enable_ui_emmission()
 {
        if (!_to_ui) {
                /* see note in LV2Plugin::write_from_ui() */
+               uint32_t bufsiz = 32768;
+               if (_atom_ev_buffers && _atom_ev_buffers[0]) {
+                       bufsiz =  lv2_evbuf_get_capacity(_atom_ev_buffers[0]);
+               }
                size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS;
-               rbs = max((size_t) 32768 * 8, rbs);
+               rbs = max((size_t) bufsiz * 8, rbs);
                _to_ui = new RingBuffer<uint8_t>(rbs);
        }
 }