OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2017 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 /** |
| 7 * This file defines the <code>PPB_AudioOutput_dev</code> interface, which |
| 8 * provides realtime stereo audio streaming capabilities. |
| 9 */ |
| 10 |
| 11 [generate_thunk] |
| 12 |
| 13 label Chrome { |
| 14 M59 = 0.1 |
| 15 }; |
| 16 |
| 17 /** |
| 18 * <code>PPB_AudioOutput_Callback</code> defines the type of an audio callback |
| 19 * function used to fill the audio buffer with data. Please see the |
| 20 * Create() function in the <code>PPB_AudioOutput</code> interface for |
| 21 * more details on this callback. |
| 22 * |
| 23 * @param[out] sample_buffer A buffer to fill with audio data. |
| 24 * @param[in] buffer_size_in_bytes The size of the buffer in bytes. |
| 25 * @param[in] latency How long before the audio data is to be presented. |
| 26 * @param[inout] user_data An opaque pointer that was passed into |
| 27 * <code>PPB_AudioOutput.Create()</code>. |
| 28 */ |
| 29 typedef void PPB_AudioOutput_Callback([out] mem_t sample_buffer, |
| 30 [in] uint32_t buffer_size_in_bytes, |
| 31 [in] PP_TimeDelta latency, |
| 32 [inout] mem_t user_data); |
| 33 |
| 34 /** |
| 35 * The <code>PPB_AudioOutput</code> interface contains pointers to several |
| 36 * functions for handling audio resources. |
| 37 * Please see descriptions for each <code>PPB_AudioOutput</code> and |
| 38 * <code>PPB_AudioConfig</code> function for more details. A C example using |
| 39 * <code>PPB_AudioOutput</code> and <code>PPB_AudioConfig</code> follows. |
| 40 * |
| 41 * <strong>Example: </strong> |
| 42 * |
| 43 * @code |
| 44 * void audio_output_callback(void* sample_buffer, |
| 45 * uint32_t buffer_size_in_bytes, |
| 46 * PP_TimeDelta latency, |
| 47 * void* user_data) { |
| 48 * ... quickly fill in the buffer with samples and return to caller ... |
| 49 * } |
| 50 * |
| 51 * ...Assume the application has cached the audio configuration interface in |
| 52 * audio_config_interface and the audio interface in |
| 53 * audio_output_interface... |
| 54 * |
| 55 * uint32_t count = audio_config_interface->RecommendSampleFrameCount( |
| 56 * PP_AUDIOSAMPLERATE_44100, 4096); |
| 57 * PP_Resource pp_audio_config = audio_config_interface->CreateStereo16Bit( |
| 58 * pp_instance, PP_AUDIOSAMPLERATE_44100, count); |
| 59 * PP_Resource pp_audio_output = audio_interface->Create(pp_instance, |
| 60 * pp_audio_config, audio_callback, NULL); |
| 61 * audio_interface->EnumerateDevices(pp_audio_output, output_device_list, |
| 62 * callback); |
| 63 * audio_interface->Open(pp_audio_output, device_ref, pp_audio_config, |
| 64 * audio_output_callback, user_data, callback); |
| 65 * audio_output_interface->StartPlayback(pp_audio_output); |
| 66 * |
| 67 * ...audio_output_callback() will now be periodically invoked on a separate |
| 68 * thread... |
| 69 * @endcode |
| 70 */ |
| 71 |
| 72 [macro="PPB_AUDIO_OUTPUT_DEV_INTERFACE"] |
| 73 interface PPB_AudioOutput_Dev { |
| 74 /** |
| 75 * Creates an audio output resource. |
| 76 * |
| 77 * @param[in] instance A <code>PP_Instance</code> identifying one instance of |
| 78 * a module. |
| 79 * |
| 80 * @return A <code>PP_Resource</code> corresponding to an audio output resourc
e |
| 81 * if successful, 0 if failed. |
| 82 */ |
| 83 PP_Resource Create( |
| 84 [in] PP_Instance instance); |
| 85 |
| 86 /** |
| 87 * Determines if the given resource is an audio output resource. |
| 88 * |
| 89 * @param[in] resource A <code>PP_Resource</code> containing a resource. |
| 90 * |
| 91 * @return A <code>PP_Bool</code> containing <code>PP_TRUE</code> if the given |
| 92 * resource is an audio output resource, otherwise <code>PP_FALSE</code>. |
| 93 */ |
| 94 PP_Bool IsAudioOutput( |
| 95 [in] PP_Resource resource); |
| 96 |
| 97 /** |
| 98 * Enumerates audio output devices. |
| 99 * |
| 100 * @param[in] audio_output A <code>PP_Resource</code> corresponding to an audi
o |
| 101 * output resource. |
| 102 * @param[in] output An output array which will receive |
| 103 * <code>PPB_DeviceRef_Dev</code> resources on success. Please note that the |
| 104 * ref count of those resources has already been increased by 1 for the |
| 105 * caller. |
| 106 * @param[in] callback A <code>PP_CompletionCallback</code> to run on |
| 107 * completion. |
| 108 * |
| 109 * @return An error code from <code>pp_errors.h</code>. |
| 110 */ |
| 111 int32_t EnumerateDevices( |
| 112 [in] PP_Resource audio_output, |
| 113 [in] PP_ArrayOutput output, |
| 114 [in] PP_CompletionCallback callback); |
| 115 |
| 116 /** |
| 117 * Requests device change notifications. |
| 118 * |
| 119 * @param[in] audio_output A <code>PP_Resource</code> corresponding to an audi
o |
| 120 * output resource. |
| 121 * @param[in] callback The callback to receive notifications. If not NULL, it |
| 122 * will be called once for the currently available devices, and then every |
| 123 * time the list of available devices changes. All calls will happen on the |
| 124 * same thread as the one on which MonitorDeviceChange() is called. It will |
| 125 * receive notifications until <code>audio_output</code> is destroyed or |
| 126 * <code>MonitorDeviceChange()</code> is called to set a new callback for |
| 127 * <code>audio_output</code>. You can pass NULL to cancel sending |
| 128 * notifications. |
| 129 * @param[inout] user_data An opaque pointer that will be passed to |
| 130 * <code>callback</code>. |
| 131 * |
| 132 * @return An error code from <code>pp_errors.h</code>. |
| 133 */ |
| 134 int32_t MonitorDeviceChange( |
| 135 [in] PP_Resource audio_output, |
| 136 [in] PP_MonitorDeviceChangeCallback callback, |
| 137 [inout] mem_t user_data); |
| 138 |
| 139 /** |
| 140 * Open() opens an audio output device. No sound will be heard until |
| 141 * StartPlayback() is called. The callback is called with the buffer address |
| 142 * and given user data whenever the buffer needs to be filled. From within the |
| 143 * callback, you should not call <code>PPB_AudioOutput</code> functions. The |
| 144 * callback will be called on a different thread than the one which created |
| 145 * the interface. For performance-critical applications (i.e. low-latency |
| 146 * audio), the callback should avoid blocking or calling functions that can |
| 147 * obtain locks, such as malloc. The layout and the size of the buffer passed |
| 148 * to the audio callback will be determined by the device configuration and is |
| 149 * specified in the <code>AudioConfig</code> documentation. |
| 150 * |
| 151 * @param[in] audio_output A <code>PP_Resource</code> corresponding to an audi
o |
| 152 * output resource. |
| 153 * @param[in] device_ref Identifies an audio output device. It could be one of |
| 154 * the resource in the array returned by EnumerateDevices(), or 0 which means |
| 155 * the default device. |
| 156 * @param[in] config A <code>PPB_AudioConfig</code> audio configuration |
| 157 * resource. |
| 158 * @param[in] audio_output_callback A <code>PPB_AudioOutput_Callback</code> |
| 159 * function that will be called when audio buffer needs to be filled. |
| 160 * @param[inout] user_data An opaque pointer that will be passed into |
| 161 * <code>audio_output_callback</code>. |
| 162 * @param[in] callback A <code>PP_CompletionCallback</code> to run when this |
| 163 * open operation is completed. |
| 164 * |
| 165 * @return An error code from <code>pp_errors.h</code>. |
| 166 */ |
| 167 int32_t Open( |
| 168 [in] PP_Resource audio_output, |
| 169 [in] PP_Resource device_ref, |
| 170 [in] PP_Resource config, |
| 171 [in] PPB_AudioOutput_Callback audio_output_callback, |
| 172 [inout] mem_t user_data, |
| 173 [in] PP_CompletionCallback callback); |
| 174 |
| 175 /** |
| 176 * GetCurrrentConfig() returns an audio config resource for the given audio |
| 177 * output resource. |
| 178 * |
| 179 * @param[in] config A <code>PP_Resource</code> corresponding to an audio |
| 180 * output resource. |
| 181 * |
| 182 * @return A <code>PP_Resource</code> containing the audio config resource if |
| 183 * successful. |
| 184 */ |
| 185 PP_Resource GetCurrentConfig( |
| 186 [in] PP_Resource audio_output); |
| 187 |
| 188 /** |
| 189 * StartPlayback() starts the playback of the audio output resource and begins |
| 190 * periodically calling the callback. |
| 191 * |
| 192 * @param[in] config A <code>PP_Resource</code> corresponding to an audio |
| 193 * output resource. |
| 194 * |
| 195 * @return A <code>PP_Bool</code> containing <code>PP_TRUE</code> if |
| 196 * successful, otherwise <code>PP_FALSE</code>. Also returns |
| 197 * <code>PP_TRUE</code> (and be a no-op) if called while playback is already |
| 198 * in progress. |
| 199 */ |
| 200 PP_Bool StartPlayback( |
| 201 [in] PP_Resource audio_output); |
| 202 |
| 203 /** |
| 204 * StopPlayback() stops the playback of the audio resource. |
| 205 * |
| 206 * @param[in] config A <code>PP_Resource</code> corresponding to an audio |
| 207 * output resource. |
| 208 * |
| 209 * @return A <code>PP_Bool</code> containing <code>PP_TRUE</code> if |
| 210 * successful, otherwise <code>PP_FALSE</code>. Also returns |
| 211 * <code>PP_TRUE</code> (and is a no-op) if called while playback is already |
| 212 * stopped. If a callback is in progress, StopPlayback() will block until the |
| 213 * callback completes. |
| 214 */ |
| 215 PP_Bool StopPlayback( |
| 216 [in] PP_Resource audio_output); |
| 217 |
| 218 /** |
| 219 * Close() closes the audio output device, and stops playback if necessary. It
is |
| 220 * not valid to call Open() again after a call to this method. |
| 221 * If an audio output resource is destroyed while a device is still open, then |
| 222 * it will be implicitly closed, so you are not required to call this method. |
| 223 * |
| 224 * @param[in] audio_output A <code>PP_Resource</code> corresponding to an audi
o |
| 225 * output resource. |
| 226 */ |
| 227 void Close( |
| 228 [in] PP_Resource audio_output); |
| 229 }; |
OLD | NEW |