Data Fields

PP_Resource(* Create )(PP_Instance instance)
PP_Bool(* IsAudioEncoder )(PP_Resource resource)
int32_t(* GetSupportedProfiles )(PP_Resource audio_encoder, struct PP_ArrayOutput output, struct PP_CompletionCallback callback)
int32_t(* Initialize )(PP_Resource audio_encoder, uint32_t channels, PP_AudioBuffer_SampleRate input_sample_rate, PP_AudioBuffer_SampleSize input_sample_size, PP_AudioProfile output_profile, uint32_t initial_bitrate, PP_HardwareAcceleration acceleration, struct PP_CompletionCallback callback)
int32_t(* GetNumberOfSamples )(PP_Resource audio_encoder)
int32_t(* GetBuffer )(PP_Resource audio_encoder, PP_Resource *audio_buffer, struct PP_CompletionCallback callback)
int32_t(* Encode )(PP_Resource audio_encoder, PP_Resource audio_buffer, struct PP_CompletionCallback callback)
int32_t(* GetBitstreamBuffer )(PP_Resource audio_encoder, struct PP_AudioBitstreamBuffer *bitstream_buffer, struct PP_CompletionCallback callback)
void(* RecycleBitstreamBuffer )(PP_Resource audio_encoder, const struct PP_AudioBitstreamBuffer *bitstream_buffer)
void(* RequestBitrateChange )(PP_Resource audio_encoder, uint32_t bitrate)
void(* Close )(PP_Resource audio_encoder)

Detailed Description

Audio encoder interface.

Typical usage:

  • Call Create() to create a new audio encoder resource.
  • Call GetSupportedProfiles() to determine which codecs and profiles are available.
  • Call Initialize() to initialize the encoder for a supported profile.
  • Call GetBuffer() to get an empty buffer and fill it in, or get an audio buffer from another resource, e.g. PPB_MediaStreamAudioTrack.
  • Call Encode() to push the audio buffer to the encoder. If an external buffer is pushed, wait for completion to recycle the buffer.
  • Call GetBitstreamBuffer() continuously (waiting for each previous call to complete) to pull encoded buffers from the encoder.
  • Call RecycleBitstreamBuffer() after consuming the data in the bitstream buffer.
  • To destroy the encoder, the plugin should release all of its references to it. Any pending callbacks will abort before the encoder is destroyed.

Available audio codecs vary by platform. All: opus.


Field Documentation

void(* PPB_AudioEncoder::Close)(PP_Resource audio_encoder)

Closes the audio encoder, and cancels any pending encodes.

Any pending callbacks will still run, reporting PP_ERROR_ABORTED . It is not valid to call any encoder functions after a call to this method. Note: Destroying the audio encoder closes it implicitly, so you are not required to call Close().

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.

Creates a new audio encoder resource.

Parameters:
[in]instanceA PP_Instance identifying the instance with the audio encoder.
Returns:
A PP_Resource corresponding to an audio encoder if successful or 0 otherwise.
int32_t(* PPB_AudioEncoder::Encode)(PP_Resource audio_encoder, PP_Resource audio_buffer, struct PP_CompletionCallback callback)

Encodes an audio buffer.

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
[in]audio_bufferThe PPB_AudioBuffer to be encoded.
[in]callbackA PP_CompletionCallback to be called upon completion. Plugins that pass PPB_AudioBuffer resources owned by other resources should wait for completion before reusing them.
Returns:
An int32_t containing an error code from pp_errors.h. Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
int32_t(* PPB_AudioEncoder::GetBitstreamBuffer)(PP_Resource audio_encoder, struct PP_AudioBitstreamBuffer *bitstream_buffer, struct PP_CompletionCallback callback)

Gets the next encoded bitstream buffer from the encoder.

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
[out]bitstream_bufferA PP_BitstreamBuffer containing encoded audio data.
[in]callbackA PP_CompletionCallback to be called upon completion. The plugin can call GetBitstreamBuffer from the callback in order to continuously "pull" bitstream buffers from the encoder.
Returns:
An int32_t containing an error code from pp_errors.h. Returns PP_ERROR_FAILED if Initialize() has not successfully completed. Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has not completed.
int32_t(* PPB_AudioEncoder::GetBuffer)(PP_Resource audio_encoder, PP_Resource *audio_buffer, struct PP_CompletionCallback callback)

Gets a blank audio buffer (with metadata given by the Initialize() call) which can be filled with audio data and passed to the encoder.

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
[out]audio_bufferA blank PPB_AudioBuffer resource.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
An int32_t containing an error code from pp_errors.h. Returns PP_ERROR_FAILED if Initialize() has not successfully completed.

Gets the number of audio samples per channel that audio buffers must contain in order to be processed by the encoder.

This will be the number of samples per channels contained in buffers returned by GetBuffer().

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
Returns:
An int32_t containing the number of samples required, or an error code from pp_errors.h. Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
int32_t(* PPB_AudioEncoder::GetSupportedProfiles)(PP_Resource audio_encoder, struct PP_ArrayOutput output, struct PP_CompletionCallback callback)

Gets an array of supported audio encoder profiles.

These can be used to choose a profile before calling Initialize().

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
[in]outputA PP_ArrayOutput to receive the supported PP_AudioProfileDescription structs.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
If >= 0, the number of supported profiles returned, otherwise an error code from pp_errors.h.
int32_t(* PPB_AudioEncoder::Initialize)(PP_Resource audio_encoder, uint32_t channels, PP_AudioBuffer_SampleRate input_sample_rate, PP_AudioBuffer_SampleSize input_sample_size, PP_AudioProfile output_profile, uint32_t initial_bitrate, PP_HardwareAcceleration acceleration, struct PP_CompletionCallback callback)

Initializes an audio encoder resource.

The plugin should call Initialize() successfully before calling any of the functions below.

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
[in]channelsThe number of audio channels to encode.
[in]input_sampling_rateThe sampling rate of the input audio buffer.
[in]input_sample_sizeThe sample size of the input audio buffer.
[in]output_profileA PP_AudioProfile specifying the codec profile of the encoded output stream.
[in]initial_bitrateThe initial bitrate for the encoder.
[in]accelerationA PP_HardwareAcceleration specifying whether to use a hardware accelerated or a software implementation.
[in]callbackA PP_CompletionCallback to be called upon completion.
Returns:
An int32_t containing an error code from pp_errors.h. Returns PP_ERROR_NOTSUPPORTED if audio encoding is not available, or the requested codec profile is not supported.

Determines if the given resource is an audio encoder.

Parameters:
[in]resourceA PP_Resource identifying a resource.
Returns:
PP_TRUE if the resource is a PPB_AudioEncoder, PP_FALSE if the resource is invalid or some other type.
void(* PPB_AudioEncoder::RecycleBitstreamBuffer)(PP_Resource audio_encoder, const struct PP_AudioBitstreamBuffer *bitstream_buffer)

Recycles a bitstream buffer back to the encoder.

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
[in]bitstream_bufferA PP_BitstreamBuffer that is no longer needed by the plugin.
void(* PPB_AudioEncoder::RequestBitrateChange)(PP_Resource audio_encoder, uint32_t bitrate)

Requests a change to the encoding bitrate.

This is only a request, fulfilled on a best-effort basis.

Parameters:
[in]audio_encoderA PP_Resource identifying the audio encoder.
[in]bitrateThe requested new bitrate, in bits per second.

The documentation for this struct was generated from the following file:
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.