Sunshine master
Self-hosted game stream host for Moonlight.
av_audio.h
Go to the documentation of this file.
1
12#pragma once
13
14// platform includes
15#import <AudioToolbox/AudioToolbox.h>
16#import <AVFoundation/AVFoundation.h>
17#import <CoreAudio/AudioHardwareTapping.h>
18#import <CoreAudio/CoreAudio.h>
19
20// lib includes
21#include "third-party/TPCircularBuffer/TPCircularBuffer.h"
22
23NS_ASSUME_NONNULL_BEGIN
24
25// Forward declarations
26@class AVAudio;
27@class CATapDescription;
28
29namespace platf {
30 OSStatus audioConverterComplexInputProc(AudioConverterRef _Nullable inAudioConverter, UInt32 *_Nonnull ioNumberDataPackets, AudioBufferList *_Nonnull ioData, AudioStreamPacketDescription *_Nullable *_Nullable outDataPacketDescription, void *_Nonnull inUserData);
31 OSStatus systemAudioIOProc(AudioObjectID inDevice, const AudioTimeStamp *_Nullable inNow, const AudioBufferList *_Nullable inInputData, const AudioTimeStamp *_Nullable inInputTime, AudioBufferList *_Nullable outOutputData, const AudioTimeStamp *_Nullable inOutputTime, void *_Nullable inClientData);
32} // namespace platf
33
45
61
67@interface AVAudio: NSObject <AVCaptureAudioDataOutputSampleBufferDelegate> {
68@public
69 TPCircularBuffer audioSampleBuffer;
70 dispatch_semaphore_t audioSemaphore;
71@private
72 // System-wide audio tap components (Core Audio)
73 AudioObjectID tapObjectID;
74 AudioObjectID aggregateDeviceID;
75 AudioDeviceIOProcID ioProcID;
76 AVAudioIOProcData *_Nullable ioProcData;
77}
78
79// AVFoundation microphone capture properties
80@property (nonatomic, assign, nullable) AVCaptureSession *audioCaptureSession;
81@property (nonatomic, assign, nullable) AVCaptureConnection *audioConnection;
82@property (nonatomic, assign) BOOL hostAudioEnabled;
83
88+ (NSArray<AVCaptureDevice *> *)microphones;
89
94+ (NSArray<NSString *> *)microphoneNames;
95
101+ (nullable AVCaptureDevice *)findMicrophone:(nullable NSString *)name;
102
111- (int)setupMicrophone:(nullable AVCaptureDevice *)device sampleRate:(UInt32)sampleRate frameSize:(UInt32)frameSize channels:(UInt8)channels;
112
121- (int)setupSystemTap:(UInt32)sampleRate frameSize:(UInt32)frameSize channels:(UInt8)channels;
122
123// Buffer management methods for testing and internal use
128- (void)initializeAudioBuffer:(UInt8)channels;
129
133- (void)cleanupAudioBuffer;
134
139- (void)cleanupSystemTapContext:(nullable id)tapDescription;
140
148- (int)initializeSystemTapContext:(UInt32)sampleRate frameSize:(UInt32)frameSize channels:(UInt8)channels;
149
155- (nullable CATapDescription *)createSystemTapDescriptionForChannels:(UInt8)channels;
156
164- (OSStatus)createAggregateDeviceWithTapDescription:(CATapDescription *)tapDescription sampleRate:(UInt32)sampleRate frameSize:(UInt32)frameSize;
165
166@end
167
168NS_ASSUME_NONNULL_END
Core Audio capture class for macOS audio input and system-wide audio tapping. Provides functionality ...
Definition av_audio.h:67
TPCircularBuffer audioSampleBuffer
Shared circular buffer for both audio capture paths.
Definition av_audio.h:69
dispatch_semaphore_t audioSemaphore
Real-time safe semaphore for signaling audio sample availability.
Definition av_audio.h:70
IOProc client data structure for Core Audio system taps. Contains configuration and conversion data f...
Definition av_audio.h:50
UInt32 conversionBufferSize
Size of the conversion buffer in bytes.
Definition av_audio.h:59
UInt32 aggregateDeviceSampleRate
Sample rate of the aggregate device.
Definition av_audio.h:55
UInt32 clientRequestedFrameSize
Frame size requested by client.
Definition av_audio.h:54
UInt32 aggregateDeviceChannels
Number of channels in aggregate device.
Definition av_audio.h:56
UInt32 clientRequestedSampleRate
Sample rate requested by client.
Definition av_audio.h:53
UInt32 clientRequestedChannels
Number of channels requested by client.
Definition av_audio.h:52
AVAudio * avAudio
Reference to AVAudio instance.
Definition av_audio.h:51
float *_Nullable conversionBuffer
Pre-allocated buffer for audio conversion.
Definition av_audio.h:58
AudioConverterRef _Nullable audioConverter
Audio converter for format conversion.
Definition av_audio.h:57
Data structure for AudioConverter input callback. Contains audio data and metadata needed for format ...
Definition av_audio.h:38
UInt32 inputFrames
Total number of input frames available.
Definition av_audio.h:40
UInt32 deviceChannels
Number of channels in the device audio.
Definition av_audio.h:42
AVAudio * avAudio
Reference to the AVAudio instance.
Definition av_audio.h:43
UInt32 framesProvided
Number of frames already provided to converter.
Definition av_audio.h:41
float * inputData
Pointer to input audio data.
Definition av_audio.h:39