1 /* Copyright 2015 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
7 * This file defines the <code>PPB_AudioEncoder</code> interface.
13 [channel
=dev
] M47
= 0.1
17 * Audio encoder interface.
20 * - Call Create() to create a new audio encoder resource.
21 * - Call GetSupportedProfiles() to determine which codecs and profiles are
23 * - Call Initialize() to initialize the encoder for a supported profile.
24 * - Call GetBuffer() to get an empty buffer and fill it in, or get an audio
25 * buffer from another resource, e.g. <code>PPB_MediaStreamAudioTrack</code>.
26 * - Call Encode() to push the audio buffer to the encoder. If an external
27 * buffer is pushed, wait for completion to recycle the buffer.
28 * - Call GetBitstreamBuffer() continuously (waiting for each previous call to
29 * complete) to pull encoded buffers from the encoder.
30 * - Call RecycleBitstreamBuffer() after consuming the data in the bitstream
32 * - To destroy the encoder, the plugin should release all of its references to
33 * it. Any pending callbacks will abort before the encoder is destroyed.
35 * Available audio codecs vary by platform.
38 interface PPB_AudioEncoder
{
40 * Creates a new audio encoder resource.
42 * @param[in] instance A <code>PP_Instance</code> identifying the instance
43 * with the audio encoder.
45 * @return A <code>PP_Resource</code> corresponding to an audio encoder if
46 * successful or 0 otherwise.
48 PP_Resource Create
([in] PP_Instance instance
);
51 * Determines if the given resource is an audio encoder.
53 * @param[in] resource A <code>PP_Resource</code> identifying a resource.
55 * @return <code>PP_TRUE</code> if the resource is a
56 * <code>PPB_AudioEncoder</code>, <code>PP_FALSE</code> if the resource is
57 * invalid or some other type.
59 PP_Bool IsAudioEncoder
([in] PP_Resource resource
);
62 * Gets an array of supported audio encoder profiles.
63 * These can be used to choose a profile before calling Initialize().
65 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
67 * @param[in] output A <code>PP_ArrayOutput</code> to receive the supported
68 * <code>PP_AudioProfileDescription</code> structs.
69 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
72 * @return If >= 0, the number of supported profiles returned, otherwise an
73 * error code from <code>pp_errors.h</code>.
75 int32_t GetSupportedProfiles
([in] PP_Resource audio_encoder
,
76 [in] PP_ArrayOutput output
,
77 [in] PP_CompletionCallback
callback);
80 * Initializes an audio encoder resource. The plugin should call Initialize()
81 * successfully before calling any of the functions below.
83 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
85 * @param[in] channels The number of audio channels to encode.
86 * @param[in] input_sampling_rate The sampling rate of the input audio buffer.
87 * @param[in] input_sample_size The sample size of the input audio buffer.
88 * @param[in] output_profile A <code>PP_AudioProfile</code> specifying the
89 * codec profile of the encoded output stream.
90 * @param[in] initial_bitrate The initial bitrate for the encoder.
91 * @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying
92 * whether to use a hardware accelerated or a software implementation.
93 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
96 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
97 * Returns PP_ERROR_NOTSUPPORTED if audio encoding is not available, or the
98 * requested codec profile is not supported.
100 int32_t Initialize
([in] PP_Resource audio_encoder
,
101 [in] uint32_t channels
,
102 [in] PP_AudioBuffer_SampleRate input_sample_rate
,
103 [in] PP_AudioBuffer_SampleSize input_sample_size
,
104 [in] PP_AudioProfile output_profile
,
105 [in] uint32_t initial_bitrate
,
106 [in] PP_HardwareAcceleration acceleration
,
107 [in] PP_CompletionCallback
callback);
110 * Gets the number of audio samples per channel that audio buffers must
111 * contain in order to be processed by the encoder. This will be the number of
112 * samples per channels contained in buffers returned by GetBuffer().
114 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
116 * @return An int32_t containing the number of samples required, or an error
117 * code from <code>pp_errors.h</code>.
118 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
120 int32_t GetNumberOfSamples
([in] PP_Resource audio_encoder
);
123 * Gets a blank audio buffer (with metadata given by the Initialize()
124 * call) which can be filled with audio data and passed to the encoder.
126 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
128 * @param[out] audio_buffer A blank <code>PPB_AudioBuffer</code> resource.
129 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
132 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
133 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
135 int32_t GetBuffer
([in] PP_Resource audio_encoder
,
136 [out] PP_Resource audio_buffer
,
137 [in] PP_CompletionCallback
callback);
140 * Encodes an audio buffer.
142 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
144 * @param[in] audio_buffer The <code>PPB_AudioBuffer</code> to be encoded.
145 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
146 * completion. Plugins that pass <code>PPB_AudioBuffer</code> resources owned
147 * by other resources should wait for completion before reusing them.
149 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
150 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
152 int32_t Encode
([in] PP_Resource audio_encoder
,
153 [in] PP_Resource audio_buffer
,
154 [in] PP_CompletionCallback
callback);
157 * Gets the next encoded bitstream buffer from the encoder.
159 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
161 * @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing
162 * encoded audio data.
163 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
164 * completion. The plugin can call GetBitstreamBuffer from the callback in
165 * order to continuously "pull" bitstream buffers from the encoder.
167 * @return An int32_t containing an error code from <code>pp_errors.h</code>.
168 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed.
169 * Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has
172 int32_t GetBitstreamBuffer
([in] PP_Resource audio_encoder
,
173 [out] PP_AudioBitstreamBuffer bitstream_buffer
,
174 [in] PP_CompletionCallback
callback);
177 * Recycles a bitstream buffer back to the encoder.
179 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
181 * @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no
182 * longer needed by the plugin.
184 void RecycleBitstreamBuffer
([in] PP_Resource audio_encoder
,
185 [in] PP_AudioBitstreamBuffer bitstream_buffer
);
188 * Requests a change to the encoding bitrate. This is only a request,
189 * fulfilled on a best-effort basis.
191 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
193 * @param[in] bitrate The requested new bitrate, in bits per second.
195 void RequestBitrateChange
([in] PP_Resource audio_encoder
,
196 [in] uint32_t bitrate
);
199 * Closes the audio encoder, and cancels any pending encodes. Any pending
200 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> . It is
201 * not valid to call any encoder functions after a call to this method.
202 * <strong>Note:</strong> Destroying the audio encoder closes it implicitly,
203 * so you are not required to call Close().
205 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio
208 void Close
([in] PP_Resource audio_encoder
);