OLD | NEW |
(Empty) | |
| 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. |
| 4 */ |
| 5 |
| 6 /* From ppb_audio_encoder.idl modified Mon Sep 7 10:17:53 2015. */ |
| 7 |
| 8 #ifndef PPAPI_C_PPB_AUDIO_ENCODER_H_ |
| 9 #define PPAPI_C_PPB_AUDIO_ENCODER_H_ |
| 10 |
| 11 #include "ppapi/c/pp_array_output.h" |
| 12 #include "ppapi/c/pp_bool.h" |
| 13 #include "ppapi/c/pp_codecs.h" |
| 14 #include "ppapi/c/pp_completion_callback.h" |
| 15 #include "ppapi/c/pp_instance.h" |
| 16 #include "ppapi/c/pp_macros.h" |
| 17 #include "ppapi/c/pp_resource.h" |
| 18 #include "ppapi/c/pp_stdint.h" |
| 19 #include "ppapi/c/ppb_audio_buffer.h" |
| 20 |
| 21 #define PPB_AUDIOENCODER_INTERFACE_0_1 "PPB_AudioEncoder;0.1" /* dev */ |
| 22 /** |
| 23 * @file |
| 24 * This file defines the <code>PPB_AudioEncoder</code> interface. |
| 25 */ |
| 26 |
| 27 |
| 28 /** |
| 29 * @addtogroup Interfaces |
| 30 * @{ |
| 31 */ |
| 32 /** |
| 33 * Audio encoder interface. |
| 34 * |
| 35 * Typical usage: |
| 36 * - Call Create() to create a new audio encoder resource. |
| 37 * - Call GetSupportedProfiles() to determine which codecs and profiles are |
| 38 * available. |
| 39 * - Call Initialize() to initialize the encoder for a supported profile. |
| 40 * - Call GetBuffer() to get an empty buffer and fill it in, or get an audio |
| 41 * buffer from another resource, e.g. <code>PPB_MediaStreamAudioTrack</code>. |
| 42 * - Call Encode() to push the audio buffer to the encoder. If an external |
| 43 * buffer is pushed, wait for completion to recycle the buffer. |
| 44 * - Call GetBitstreamBuffer() continuously (waiting for each previous call to |
| 45 * complete) to pull encoded buffers from the encoder. |
| 46 * - Call RecycleBitstreamBuffer() after consuming the data in the bitstream |
| 47 * buffer. |
| 48 * - To destroy the encoder, the plugin should release all of its references to |
| 49 * it. Any pending callbacks will abort before the encoder is destroyed. |
| 50 * |
| 51 * Available audio codecs vary by platform. |
| 52 * All: opus. |
| 53 */ |
| 54 struct PPB_AudioEncoder_0_1 { /* dev */ |
| 55 /** |
| 56 * Creates a new audio encoder resource. |
| 57 * |
| 58 * @param[in] instance A <code>PP_Instance</code> identifying the instance |
| 59 * with the audio encoder. |
| 60 * |
| 61 * @return A <code>PP_Resource</code> corresponding to an audio encoder if |
| 62 * successful or 0 otherwise. |
| 63 */ |
| 64 PP_Resource (*Create)(PP_Instance instance); |
| 65 /** |
| 66 * Determines if the given resource is an audio encoder. |
| 67 * |
| 68 * @param[in] resource A <code>PP_Resource</code> identifying a resource. |
| 69 * |
| 70 * @return <code>PP_TRUE</code> if the resource is a |
| 71 * <code>PPB_AudioEncoder</code>, <code>PP_FALSE</code> if the resource is |
| 72 * invalid or some other type. |
| 73 */ |
| 74 PP_Bool (*IsAudioEncoder)(PP_Resource resource); |
| 75 /** |
| 76 * Gets an array of supported audio encoder profiles. |
| 77 * These can be used to choose a profile before calling Initialize(). |
| 78 * |
| 79 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 80 * encoder. |
| 81 * @param[in] output A <code>PP_ArrayOutput</code> to receive the supported |
| 82 * <code>PP_AudioProfileDescription</code> structs. |
| 83 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 84 * completion. |
| 85 * |
| 86 * @return If >= 0, the number of supported profiles returned, otherwise an |
| 87 * error code from <code>pp_errors.h</code>. |
| 88 */ |
| 89 int32_t (*GetSupportedProfiles)(PP_Resource audio_encoder, |
| 90 struct PP_ArrayOutput output, |
| 91 struct PP_CompletionCallback callback); |
| 92 /** |
| 93 * Initializes an audio encoder resource. The plugin should call Initialize() |
| 94 * successfully before calling any of the functions below. |
| 95 * |
| 96 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 97 * encoder. |
| 98 * @param[in] channels The number of audio channels to encode. |
| 99 * @param[in] input_sampling_rate The sampling rate of the input audio buffer. |
| 100 * @param[in] input_sample_size The sample size of the input audio buffer. |
| 101 * @param[in] output_profile A <code>PP_AudioProfile</code> specifying the |
| 102 * codec profile of the encoded output stream. |
| 103 * @param[in] initial_bitrate The initial bitrate for the encoder. |
| 104 * @param[in] acceleration A <code>PP_HardwareAcceleration</code> specifying |
| 105 * whether to use a hardware accelerated or a software implementation. |
| 106 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 107 * completion. |
| 108 * |
| 109 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 110 * Returns PP_ERROR_NOTSUPPORTED if audio encoding is not available, or the |
| 111 * requested codec profile is not supported. |
| 112 */ |
| 113 int32_t (*Initialize)(PP_Resource audio_encoder, |
| 114 uint32_t channels, |
| 115 PP_AudioBuffer_SampleRate input_sample_rate, |
| 116 PP_AudioBuffer_SampleSize input_sample_size, |
| 117 PP_AudioProfile output_profile, |
| 118 uint32_t initial_bitrate, |
| 119 PP_HardwareAcceleration acceleration, |
| 120 struct PP_CompletionCallback callback); |
| 121 /** |
| 122 * Gets the number of audio samples per channel that audio buffers must |
| 123 * contain in order to be processed by the encoder. This will be the number of |
| 124 * samples per channels contained in buffers returned by GetBuffer(). |
| 125 * |
| 126 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 127 * encoder. |
| 128 * @return An int32_t containing the number of samples required, or an error |
| 129 * code from <code>pp_errors.h</code>. |
| 130 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 131 */ |
| 132 int32_t (*GetNumberOfSamples)(PP_Resource audio_encoder); |
| 133 /** |
| 134 * Gets a blank audio buffer (with metadata given by the Initialize() |
| 135 * call) which can be filled with audio data and passed to the encoder. |
| 136 * |
| 137 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 138 * encoder. |
| 139 * @param[out] audio_buffer A blank <code>PPB_AudioBuffer</code> resource. |
| 140 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 141 * completion. |
| 142 * |
| 143 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 144 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 145 */ |
| 146 int32_t (*GetBuffer)(PP_Resource audio_encoder, |
| 147 PP_Resource* audio_buffer, |
| 148 struct PP_CompletionCallback callback); |
| 149 /** |
| 150 * Encodes an audio buffer. |
| 151 * |
| 152 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 153 * encoder. |
| 154 * @param[in] audio_buffer The <code>PPB_AudioBuffer</code> to be encoded. |
| 155 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 156 * completion. Plugins that pass <code>PPB_AudioBuffer</code> resources owned |
| 157 * by other resources should wait for completion before reusing them. |
| 158 * |
| 159 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 160 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 161 */ |
| 162 int32_t (*Encode)(PP_Resource audio_encoder, |
| 163 PP_Resource audio_buffer, |
| 164 struct PP_CompletionCallback callback); |
| 165 /** |
| 166 * Gets the next encoded bitstream buffer from the encoder. |
| 167 * |
| 168 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 169 * encoder. |
| 170 * @param[out] bitstream_buffer A <code>PP_BitstreamBuffer</code> containing |
| 171 * encoded audio data. |
| 172 * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon |
| 173 * completion. The plugin can call GetBitstreamBuffer from the callback in |
| 174 * order to continuously "pull" bitstream buffers from the encoder. |
| 175 * |
| 176 * @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 177 * Returns PP_ERROR_FAILED if Initialize() has not successfully completed. |
| 178 * Returns PP_ERROR_INPROGRESS if a prior call to GetBitstreamBuffer() has |
| 179 * not completed. |
| 180 */ |
| 181 int32_t (*GetBitstreamBuffer)( |
| 182 PP_Resource audio_encoder, |
| 183 struct PP_AudioBitstreamBuffer* bitstream_buffer, |
| 184 struct PP_CompletionCallback callback); |
| 185 /** |
| 186 * Recycles a bitstream buffer back to the encoder. |
| 187 * |
| 188 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 189 * encoder. |
| 190 * @param[in] bitstream_buffer A <code>PP_BitstreamBuffer</code> that is no |
| 191 * longer needed by the plugin. |
| 192 */ |
| 193 void (*RecycleBitstreamBuffer)( |
| 194 PP_Resource audio_encoder, |
| 195 const struct PP_AudioBitstreamBuffer* bitstream_buffer); |
| 196 /** |
| 197 * Requests a change to the encoding bitrate. This is only a request, |
| 198 * fulfilled on a best-effort basis. |
| 199 * |
| 200 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 201 * encoder. |
| 202 * @param[in] bitrate The requested new bitrate, in bits per second. |
| 203 */ |
| 204 void (*RequestBitrateChange)(PP_Resource audio_encoder, uint32_t bitrate); |
| 205 /** |
| 206 * Closes the audio encoder, and cancels any pending encodes. Any pending |
| 207 * callbacks will still run, reporting <code>PP_ERROR_ABORTED</code> . It is |
| 208 * not valid to call any encoder functions after a call to this method. |
| 209 * <strong>Note:</strong> Destroying the audio encoder closes it implicitly, |
| 210 * so you are not required to call Close(). |
| 211 * |
| 212 * @param[in] audio_encoder A <code>PP_Resource</code> identifying the audio |
| 213 * encoder. |
| 214 */ |
| 215 void (*Close)(PP_Resource audio_encoder); |
| 216 }; |
| 217 /** |
| 218 * @} |
| 219 */ |
| 220 |
| 221 #endif /* PPAPI_C_PPB_AUDIO_ENCODER_H_ */ |
| 222 |
OLD | NEW |