Starboard Module Reference: audio_sink.h

Provides an interface to output raw audio data.

Structs

SbAudioSink

An opaque handle to an implementation-private structure representing an audio sink.

Functions

SbAudioSinkCreate

Description

Creates an audio sink for the specified channels and sampling_frequency_hz, acquires all resources needed to operate the audio sink, and returns an opaque handle to the audio sink.
If the particular platform doesn't support the requested audio sink, the function returns kSbAudioSinkInvalid without calling any of the callbacks.

Declaration and definitions

SB_EXPORT SbAudioSink
SbAudioSinkCreate(int channels,
                  int sampling_frequency_hz,
                  SbMediaAudioSampleType audio_sample_type,
                  SbMediaAudioFrameStorageType audio_frame_storage_type,
                  SbAudioSinkFrameBuffers frame_buffers,
                  int frames_per_channel,
                  SbAudioSinkUpdateSourceStatusFunc update_source_status_func,
                  SbAudioSinkConsumeFramesFunc consume_frames_func,
                  void* context);

#include "starboard/audio_sink.h"

SbAudioSink SbAudioSinkCreate(
    int channels,
    int sampling_frequency_hz,
    SbMediaAudioSampleType audio_sample_type,
    SbMediaAudioFrameStorageType audio_frame_storage_type,
    SbAudioSinkFrameBuffers frame_buffers,
    int frames_per_channel,
    SbAudioSinkUpdateSourceStatusFunc update_source_status_func,
    SbAudioSinkConsumeFramesFunc consume_frames_func,
    void* context) {
  return kSbAudioSinkInvalid;
}

Parameters

Parameters
int
channels
The number of audio channels, such as left and right channels in stereo audio.
int
sampling_frequency_hz
The sample frequency of the audio data being streamed. For example, 22,000 Hz means 22,000 sample elements represents one second of audio data.
SbMediaAudioSampleType
audio_sample_type
The type of each sample of the audio data -- int16, float32, etc.
SbMediaAudioFrameStorageType
audio_frame_storage_type
Indicates whether frames are interleaved or planar.
SbAudioSinkFrameBuffers
frame_buffers
An array of pointers to sample data.
  • If the sink is operating in interleaved mode, the array contains only one element, which is an array containing (frames_per_channel * channels) samples.
  • If the sink is operating in planar mode, the number of elements in the array is the same as channels, and each element is an array of frames_per_channel samples. The caller has to ensure that frame_buffers is valid until SbAudioSinkDestroy is called.
int
frames_per_channel
The size of the frame buffers, in units of the number of samples per channel. The frame, in this case, represents a group of samples at the same media time, one for each channel.
SbAudioSinkUpdateSourceStatusFunc
update_source_status_func
The audio sink calls this function on an internal thread to query the status of the source. The value cannot be NULL. A function that the audio sink starts to call immediately after SbAudioSinkCreate is called, even before it returns. The caller has to ensure that the callback functions above return meaningful values in this case.
SbAudioSinkConsumeFramesFunc
consume_frames_func
The audio sink calls this function on an internal thread to report consumed frames. The value cannot be NULL.
void*
context
A value that is passed back to all callbacks and is generally used to point at a class or struct that contains state associated with the audio sink.

SbAudioSinkDestroy

Description

Destroys audio_sink, freeing all associated resources. Before returning, the function waits until all callbacks that are in progress have finished. After the function returns, no further calls are made callbacks passed into SbAudioSinkCreate. In addition, you can not pass audio_sink to any other SbAudioSink functions after SbAudioSinkDestroy has been called on it.
This function can be called on any thread. However, it cannot be called within any of the callbacks passed into SbAudioSinkCreate.

Declaration and definitions

SB_EXPORT void SbAudioSinkDestroy(SbAudioSink audio_sink);

#include "starboard/audio_sink.h"

void SbAudioSinkDestroy(SbAudioSink /*audio_sink*/) {}

Parameters

Parameters
SbAudioSink
audio_sink
The audio sink to destroy.

SbAudioSinkGetMaxChannels

Description

Returns the maximum number of channels supported on the platform. For example, the number would be 2 if the platform only supports stereo.

Declaration and definitions

SB_EXPORT int SbAudioSinkGetMaxChannels();

#include "starboard/audio_sink.h"

int SbAudioSinkGetMaxChannels() {
  return 0;
}

SbAudioSinkGetNearestSupportedSampleFrequency

Description

Returns the supported sample rate closest to sampling_frequency_hz. On platforms that don't support all sample rates, it is the caller's responsibility to resample the audio frames into the supported sample rate returned by this function.

Declaration and definitions

SB_EXPORT int SbAudioSinkGetNearestSupportedSampleFrequency(
    int sampling_frequency_hz);

#include "starboard/audio_sink.h"

int SbAudioSinkGetNearestSupportedSampleFrequency(
    int /*sampling_frequency_hz*/) {
  return 0;
}

Parameters

Parameters
int
sampling_frequency_hz

SbAudioSinkIsAudioFrameStorageTypeSupported

Description

Indicates whether audio_frame_storage_type is supported on this platform.

Declaration and definitions

SB_EXPORT bool SbAudioSinkIsAudioFrameStorageTypeSupported(
    SbMediaAudioFrameStorageType audio_frame_storage_type);

#include "starboard/audio_sink.h"

bool SbAudioSinkIsAudioFrameStorageTypeSupported(
    SbMediaAudioFrameStorageType audio_frame_storage_type) {
  return false;
}

Parameters

Parameters
SbMediaAudioFrameStorageType
audio_frame_storage_type

SbAudioSinkIsAudioSampleTypeSupported

Description

Indicates whether audio_sample_type is supported on this platform.

Declaration and definitions

SB_EXPORT bool SbAudioSinkIsAudioSampleTypeSupported(
    SbMediaAudioSampleType audio_sample_type);

#include "starboard/audio_sink.h"

bool SbAudioSinkIsAudioSampleTypeSupported(
    SbMediaAudioSampleType /*audio_sample_type*/) {
  return false;
}

Parameters

Parameters
SbMediaAudioSampleType
audio_sample_type

SbAudioSinkIsValid

Description

Indicates whether the given audio sink handle is valid.

Declaration and definitions

SB_EXPORT bool SbAudioSinkIsValid(SbAudioSink audio_sink);

#include "starboard/audio_sink.h"

bool SbAudioSinkIsValid(SbAudioSink /*audio_sink*/) {
  return false;
}

Parameters

Parameters
SbAudioSink
audio_sink
The audio sink handle to check.