AU: fix optional buffers

The spec [1] says:
 "If the mData pointers are null, the audio unit can
  provide pointers to its own buffers. In this case,
  the audio unit must keep those buffers valid for
  the duration of the calling thread’s I/O cycle."

A plugin *can* do this, but it does not need to. An extra
NULL test is required.

furthermore [2] specifies

 "mDataByteSize -  The number of bytes in the buffer pointed
  at by the mData field."

In case the host does not provide any buffers, this is obviously zero.


[1] https://developer.apple.com/documentation/audiotoolbox/1438430-audiounitrender?language=objc
[2] https://developer.apple.com/documentation/coreaudiotypes/audiobuffer?language=objc
This commit is contained in:
Robin Gareus 2019-09-11 02:40:57 +02:00
parent 8dc0c84ba4
commit 9f668ceed2
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04

View file

@ -1667,17 +1667,19 @@ AUPlugin::connect_and_run (BufferSet& bufs,
for (uint32_t i = 0; i < cnt; ++i) {
buffers->mBuffers[i].mNumberChannels = 1;
buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample);
/* setting this to 0 indicates to the AU that it can provide buffers here
/* setting this to 0 indicates to the AU that it *can* provide buffers here
* if necessary. if it can process in-place, it will use the buffers provided
* as input by ::render_callback() above.
*
* a non-null values tells the plugin to render into the buffer pointed
* at by the value.
* https://developer.apple.com/documentation/audiotoolbox/1438430-audiounitrender?language=objc
*/
if (inplace) {
buffers->mBuffers[i].mDataByteSize = 0;
buffers->mBuffers[i].mData = 0;
} else {
buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample);
bool valid = false;
uint32_t idx = out_map.get (DataType::AUDIO, i + busoff, &valid);
if (valid) {
@ -1704,7 +1706,12 @@ AUPlugin::connect_and_run (BufferSet& bufs,
for (uint32_t i = 0; i < limit; ++i) {
bool valid = false;
uint32_t idx = out_map.get (DataType::AUDIO, i + busoff, &valid);
if (!valid) continue;
if (!valid) {
continue;
}
if (buffers->mBuffers[i].mData == 0 || buffers->mBuffers[i].mNumberChannels != 1) {
continue
}
used_outputs.set (i + busoff);
Sample* expected_buffer_address = bufs.get_audio (idx).data (offset);
if (expected_buffer_address != buffers->mBuffers[i].mData) {