Skip to content

Ensure audioipc's real-time thread are on the same work group on macOS #156

@padenot

Description

@padenot

See https://developer.apple.com/documentation/audiotoolbox/workgroup_management/understanding_audio_workgroups?language=objc for a lot more context.

This is going to be a bit tricky. In addition to promoting the threads (that audio_thread_priority already does), another API should be called. It's not clear yet to me where it's best to file or put this issue, but clearly it has something to do with audioipc so I'm filing here.

From e.g. cubeb_stream_init (or elsewhere we can access the audio device that is going to be in use):

  os_workgroup_t workgroup;
  size = sizeof(os_workgroup_t);
  r = AudioUnitGetProperty(stm->output_unit, kAudioOutputUnitProperty_OSWorkgroup,
                           kAudioUnitScope_Output, AU_OUT_BUS, &workgroup,
                           &size);

the we stash this workgroup somewhere, and from the audioipc thread that transport audio data, when creating the thread:

  os_workgroup_join_token_s joinToken;
  const int result = os_workgroup_join(workgroup, &joinToken);
  if (result == 0) {
    printf("OK\n");
      // Success.
  }
  else if (result == EALREADY) {
    // The thread is already part of a workgroup that can't be
    // nested in the the specified workgroup.
    printf("Already joined\n");
  }
  else if (result == EINVAL) {
    printf("Already EINVAL\n");
    // The workgroup has been canceled.
  }

and before exiting the thread, leave the group:

os_workgroup_leave(workgroup, joinToken);

One of the issue here is that the workgroup is per audio device, and we only have a single audioipc thread that transports the audio data, regardless of the devices. For now, we generally always use the same audio output device (the default), so it's not terrible, but we might want to take this into consideration.

We might end up being able to implement something by snooping on the actual device in use via https://github.com/mozilla/cubeb/blob/master/include/cubeb/cubeb.h#L637, but this breaks the audioipc layering somewhat.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions