Sample CodeDriverKit, macOSReviewed 2026-07-21View on Apple Developer

Building an Audio Server Plug-in and Driver Extension

At a glance

Item Summary
Purpose Create a plug-in and driver extension to support an audio device in macOS.
App architecture A C++, C/Objective-C header, Shell sample centered on CAMutex, with direct use of CoreAudio, CoreFoundation, IOKit, mach.
Main patterns No named application pattern supported by the extracted structure
Project style 39 scanned source file(s) across C++, C/Objective-C header, Shell, organized around ranked entry, type, and file boundaries.
Execution model No structured execution marker indexed; callback threading requires source review.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages CoreAudio, CoreAudioTypes.h, CoreFoundation, stdio.h, CoreFoundation.h; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── PublicUtility/
│   ├── CAMutex.h
│   ├── CACFArray.h
│   ├── CACFDictionary.h
│   ├── CAVolumeCurve.h
│   ├── CACFNumber.h
│   ├── CACFString.h
│   ├── CADispatchQueue.h
│   └── CAGuard.h
└── SimpleAudio/
    ├── ASP/
    │   ├── SA_Object.h
    │   ├── SA_PlugIn.h
    │   └── SA_Device.h
    └── DriverExtension/
        └── SimpleAudioDriverUserClient.cpp

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: C++, C/Objective-C header, Shell.
  • The verified tree contains 7 project/configuration file(s) and 42 source declaration(s).

Overall architecture

Reference code

PublicUtility/CAMutex.h:33 — architecture anchor

#ifndef __CAMutex_h__
class   CAMutex
{
    // ...
                    CAMutex(const char* inName);
    // ...
};
#endif // __CAMutex_h__

Interpretation

The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Core Audio.

Ownership and state

Ownership evidence

SimpleAudio/ASP/SA_Object.h:100 — stored dependency or nearest verified ownership anchor

#if !defined(__SA_ObjectMap_h__)
class SA_Object
{
    // ...
};
#endif  //  __SA_ObjectMap_h__
Owner Object or state Relationship Mutation authority
CAMutex Core Audio APIs Uses framework types; no stored lifecycle relationship was detected in the architecture anchor. The declaring implementation controls calls.

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Concurrency, scheduling, and thread safety

Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.

No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.

@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.

State propagation, frameworks, and dependencies

Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.

Category Mechanism or module Verified role Evidence
Source import CoreAudio The cited file imports this module; runtime use and architectural role are not inferred. PublicUtility/CACFArray.h:16
Source import CoreAudioTypes.h The cited file imports this module; runtime use and architectural role are not inferred. PublicUtility/CACFArray.h:19
Source import CoreFoundation The cited file imports this module; runtime use and architectural role are not inferred. PublicUtility/CACFArray.h:17
Source import stdio.h The cited file imports this module; runtime use and architectural role are not inferred. PublicUtility/CADebugMacros.cpp:8
Source import CoreFoundation.h The cited file imports this module; runtime use and architectural role are not inferred. PublicUtility/CACFArray.h:20
Source import IOKit The cited file imports this module; runtime use and architectural role are not inferred. SimpleAudio/ASP/SA_IOKit.h:23

receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.

Class and protocol design

PublicUtility/CAMutex.h:33 — representative type boundary

#ifndef __CAMutex_h__
class   CAMutex
{
    // ...
};
#endif // __CAMutex_h__
Type Responsibility Depends on or conforms to
CAMutex Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
Locker Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
Unlocker Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
Tryer Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
SA_Object Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
SA_ObjectMap Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
ObjectInfo Represents feature data Concrete collaborators/imported frameworks
SA_ObjectReleaser Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
SimpleAudioDriverUserClient_IVars Represents a feature value or composable behavior Concrete collaborators/imported frameworks
CACFDictionary Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
CAMutex (PublicUtility/CAMutex.h:33) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
Locker (PublicUtility/CAMutex.h:62) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
Unlocker (PublicUtility/CAMutex.h:86) header-visible The declaration is exposed to translation units that import the header. Inference: declare a contract needed by other Objective-C/C translation units.
SimpleAudioDriverUserClient_IVars (SimpleAudio/DriverExtension/SimpleAudioDriverUserClient.cpp:22) language/file boundary Visibility follows header/implementation and language linkage rules. Inference: the language’s file or module boundary is sufficient for this sample collaboration.

Reference code

PublicUtility/CAMutex.h:33 — representative boundary

#ifndef __CAMutex_h__
class   CAMutex
{
    // ...
};
#endif // __CAMutex_h__

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
Feature and framework orchestration CAMutex The sample keeps the demonstrated path in its primary concrete type.

Design patterns

Pattern Source evidence Purpose or tradeoff
No named application pattern PublicUtility/CAMutex.h:33 The verified source directly composes concrete framework types; this document avoids forcing a pattern name.

Naming conventions

  • Types: feature-specific names rather than reusable layer suffixes.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: no representative method name extracted from the architectural files.
  • Files: PublicUtility/CAMutex.h, SimpleAudio/ASP/SA_Object.h, PublicUtility/CACFArray.h, PublicUtility/CACFDictionary.h, PublicUtility/CAVolumeCurve.h, SimpleAudio/ASP/SA_PlugIn.h.

Architecture takeaways

  • CAMutex is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches CoreAudio, CoreFoundation, IOKit, mach through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
PublicUtility/CAMutex.h CAMutex, Locker, Unlocker, Tryer
SimpleAudio/ASP/SA_Object.h SA_Object, SA_ObjectMap, ObjectInfo, SA_ObjectReleaser
SimpleAudio/DriverExtension/SimpleAudioDriverUserClient.cpp SimpleAudioDriverUserClient, SimpleAudioDriverUserClient_IVars
PublicUtility/CACFArray.h CoreAudio, CoreAudioTypes.h, CoreFoundation, CoreFoundation.h, CACFDictionary, CACFString, CACFArray
PublicUtility/CADebugMacros.cpp stdio.h, Feature implementation
SimpleAudio/ASP/SA_IOKit.h IOKit, SA_IOKitObject, SA_IOKitIterator
PublicUtility/CACFDictionary.h CACFArray, CACFString, CACFDictionary
PublicUtility/CAVolumeCurve.h CARawPoint, CADBPoint, CAVolumeCurve
SimpleAudio/ASP/SA_PlugIn.h SA_Device, SA_PlugIn, DeviceInfo
PublicUtility/CACFNumber.h CACFBoolean, CACFNumber
PublicUtility/CACFString.h CACFString, CACFMutableString
PublicUtility/CADispatchQueue.h CADispatchQueue, EventSource
PublicUtility/CAGuard.h CAGuard, Locker
SimpleAudio/ASP/SA_Device.h SimpleAudioDriverStatus, SA_Device
SimpleAudio/DriverExtension/SimpleAudioDriver.cpp SimpleAudioDriver_IVars, mach_timebase_info
PublicUtility/CACFObject.h CACFObject