Skip to content

Commit 3ce3fd7

Browse files
committed
Add API documentation
1 parent 83305a1 commit 3ce3fd7

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

LinkKit/ABLLink.h

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ extern "C"
117117
bool isEnabled,
118118
void *context);
119119

120+
/*! @brief Called if IsAudioEnabled state changes.
121+
*
122+
* @param isEnabled Whether audio sharing is currently enabled.
123+
*/
120124
typedef void (*ABLLinkIsAudioEnabledCallback)(
121125
bool isEnabled,
122126
void *context);
@@ -400,35 +404,126 @@ extern "C"
400404
double beatTime,
401405
double quantum);
402406

407+
/*! @brief Is audio sharing currently enabled?
408+
*
409+
* @discussion Returns true if audio sharing is currently enabled.
410+
* The audio sharing status is only controllable by the user via the
411+
* Link settings view and is not controllable programmatically.
412+
*
413+
* To expose the audio sharing toggle in the Link settings view, a
414+
* Boolean entry with the key ABLLinkAudioSupported must be added to
415+
* Info.plist and set to YES.
416+
*
417+
* By adding a string entry with the key ABLLinkPeerName to Info.plist,
418+
* a default local peer name for identification in the Link session can
419+
* be set. If the entry is not present the app will be identified by
420+
* the name "Link App". The effective peer name can be changed by the
421+
* user via the Link settings view.
422+
*/
403423
bool ABLLinkIsAudioEnabled(ABLLinkRef);
404424

425+
/*! @brief Invoked on the main thread when the user changes the
426+
* audio sharing enabled state via the Link settings view.
427+
*/
405428
void ABLLinkSetIsAudioEnabledCallback(
406429
ABLLinkRef,
407430
ABLLinkIsAudioEnabledCallback callback,
408431
void* context);
409432

433+
/*! @brief Reference to an audio sink instance.
434+
*
435+
* @discussion An audio sink announces an audio channel to the Link
436+
* session and can be used to send audio samples to other peers.
437+
*/
410438
typedef struct ABLLinkAudioSink *ABLLinkAudioSinkRef;
411439

440+
/*! @brief Reference to an audio sink buffer handle.
441+
*
442+
* @discussion A buffer handle provides access to a buffer for writing
443+
* audio samples that will be sent to other peers.
444+
*/
412445
typedef struct ABLLinkAudioSinkBufferHandle *ABLLinkAudioSinkBufferHandleRef;
413446

447+
/*! @brief Create a new audio sink with a name and maximum buffer size.
448+
*
449+
* @param name The name of the audio channel, visible to other peers.
450+
* @param maxNumSamples Maximum buffer size in samples. This should
451+
* account for the number of channels times the number of samples per
452+
* channel in one audio callback.
453+
*
454+
* @discussion The announced channel is visible to other peers for the
455+
* lifetime of the sink. Audio will only be sent if at least one peer
456+
* in the session has requested it.
457+
*/
414458
ABLLinkAudioSinkRef ABLLinkAudioSinkNew(
415459
ABLLinkRef,
416460
const char *name,
417461
uint32_t maxNumSamples);
418462

463+
/*! @brief Destroy an audio sink and cleanup its associated resources.
464+
*
465+
* @discussion After deletion, the audio channel will no longer be
466+
* visible to other peers in the session.
467+
*/
419468
void ABLLinkAudioSinkDelete(ABLLinkAudioSinkRef);
420469

470+
/*! @brief Get the current maximum number of samples a buffer handle can hold.
471+
*
472+
* @discussion This function is lockfree.
473+
*/
421474
uint32_t ABLLinkAudioSinkMaxNumSamples(ABLLinkAudioSinkRef);
422475

476+
/*! @brief Request a maximum buffer size for future buffers.
477+
*
478+
* @discussion Increase the number of samples retained buffer handles
479+
* can hold. If the requested number of samples is smaller than the
480+
* current maximum number of samples this is a no-op. This function is
481+
* lockfree.
482+
*/
423483
void ABLLinkAudioSinkRequestMaxNumSamples(ABLLinkAudioSinkRef,
424484
uint32_t maxNumSamples);
425485

486+
/*! @brief Retain a buffer for writing audio samples.
487+
*
488+
* @discussion Only one buffer handle can be retained at a time. This
489+
* function is lockfree. A buffer handle should never outlive the audio
490+
* sink it was created from. Returns NULL if no corresponding source
491+
* exists or no buffer is available.
492+
*/
426493
ABLLinkAudioSinkBufferHandleRef ABLLinkAudioRetainBuffer(ABLLinkAudioSinkRef);
427494

495+
/*! @brief Check if the buffer handle is valid.
496+
*
497+
* @discussion Make sure to check this before using the handle. The
498+
* handle may be invalid if no peer has currently requested audio from
499+
* this sink or no buffer is available. This function is lockfree.
500+
*/
428501
bool ABLLinkAudioSinkBufferHandleIsValid(ABLLinkAudioSinkBufferHandleRef);
429502

503+
/*! @brief Get a pointer to the buffer for writing samples.
504+
*
505+
* @discussion Audio buffers are interleaved and samples are represented
506+
* as 16-bit signed integers. This function is lockfree.
507+
*/
430508
int16_t *ABLLinkAudioSinkBufferSamples(ABLLinkAudioSinkBufferHandleRef);
431509

510+
/*! @brief Commit the buffer after writing samples and release the handle.
511+
*
512+
* @param sessionState The current Link session state.
513+
* @param beatsAtBufferBegin Beat at the start of the buffer.
514+
* @param quantum Quantum value for beat mapping.
515+
* @param numFrames Number of frames written.
516+
* @param numChannels Number of channels (1 for mono, 2 for stereo).
517+
* @param sampleRate Sample rate in Hz.
518+
* @return True if the buffer was successfully committed.
519+
*
520+
* @discussion After calling this function, the buffer handle should not
521+
* be used anymore. The Link session state, quantum, and beats at buffer
522+
* begin must be the same as used for rendering the audio locally.
523+
* Changes to the Link session state should always be made before
524+
* rendering and eventually writing the buffer. numFrames * numChannels
525+
* may not exceed maxNumSamples. This function is lockfree.
526+
*/
432527
bool ABLLinkAudioReleaseAndCommitBuffer(ABLLinkAudioSinkRef,
433528
ABLLinkAudioSinkBufferHandleRef,
434529
ABLLinkSessionStateRef,
@@ -438,12 +533,41 @@ extern "C"
438533
uint32_t numChannels,
439534
uint32_t sampleRate);
440535

536+
/*! @brief Release the buffer handle without committing.
537+
*
538+
* @discussion Use this to release a buffer without sending it to other
539+
* peers. After calling this function, the buffer handle should not be
540+
* used anymore. This function is lockfree.
541+
*/
441542
void ABLLinkAudioReleaseBuffer(ABLLinkAudioSinkBufferHandleRef);
442543

544+
/*! @brief Configure audio properties from an AudioStreamBasicDescription.
545+
*
546+
* @param asbd Pointer to an AudioStreamBasicDescription containing
547+
* the audio format properties.
548+
*
549+
* @discussion This is a convenience function for iOS/macOS to configure
550+
* the audio sink with the properties from a Core Audio format description.
551+
*/
443552
void ABLLinkSetPropertiesFromASBD(
444553
ABLLinkAudioSinkRef,
445554
const AudioStreamBasicDescription *asbd);
446555

556+
/*! @brief Convenience function to commit a Core Audio buffer using beat time.
557+
*
558+
* @param sink The audio sink to commit the buffer to.
559+
* @param sessionState The current Link session state.
560+
* @param beatsAtBufferBegin Beat at the start of the buffer.
561+
* @param quantum Quantum value for beat mapping.
562+
* @param numFrames Number of frames in the buffer.
563+
* @param ioData Pointer to the AudioBufferList containing the audio data.
564+
* @return True if the buffer was successfully committed.
565+
*
566+
* @discussion This is a convenience function for iOS/macOS that directly
567+
* commits audio data from a Core Audio AudioBufferList. The Link session
568+
* state, quantum, and beats at buffer begin must be the same as used for
569+
* rendering the audio locally. This function is lockfree.
570+
*/
447571
bool ABLLinkCommitCoreAudioBufferWithBeats(
448572
ABLLinkAudioSinkRef sink,
449573
ABLLinkSessionStateRef sessionState,
@@ -452,6 +576,21 @@ extern "C"
452576
uint32_t numFrames,
453577
AudioBufferList *ioData);
454578

579+
/*! @brief Convenience function to commit a Core Audio buffer using host time.
580+
*
581+
* @param sink The audio sink to commit the buffer to.
582+
* @param sessionState The current Link session state.
583+
* @param hostTimeAtBufferBegin Host time at the start of the buffer.
584+
* @param quantum Quantum value for beat mapping.
585+
* @param numFrames Number of frames in the buffer.
586+
* @param ioData Pointer to the AudioBufferList containing the audio data.
587+
* @return True if the buffer was successfully committed.
588+
*
589+
* @discussion This is a convenience function for iOS/macOS that directly
590+
* commits audio data from a Core Audio AudioBufferList. The Link session
591+
* state and quantum must be the same as used for rendering the audio
592+
* locally. This function is lockfree.
593+
*/
455594
bool ABLLinkCommitCoreAudioBufferWithHostTime(
456595
ABLLinkAudioSinkRef sink,
457596
ABLLinkSessionStateRef sessionState,

0 commit comments

Comments
 (0)