1 /* Copyright (c) 2012 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_config.idl modified Mon Oct 23 15:24:19 2017. */ 7 8 #ifndef PPAPI_C_PPB_AUDIO_CONFIG_H_ 9 #define PPAPI_C_PPB_AUDIO_CONFIG_H_ 10 11 #include "ppapi/c/pp_bool.h" 12 #include "ppapi/c/pp_instance.h" 13 #include "ppapi/c/pp_macros.h" 14 #include "ppapi/c/pp_resource.h" 15 #include "ppapi/c/pp_stdint.h" 16 17 #define PPB_AUDIO_CONFIG_INTERFACE_1_0 "PPB_AudioConfig;1.0" 18 #define PPB_AUDIO_CONFIG_INTERFACE_1_1 "PPB_AudioConfig;1.1" 19 #define PPB_AUDIO_CONFIG_INTERFACE PPB_AUDIO_CONFIG_INTERFACE_1_1 20 21 /** 22 * @file 23 * This file defines the PPB_AudioConfig interface for establishing an 24 * audio configuration resource within the browser. 25 */ 26 27 28 /** 29 * @addtogroup Enums 30 * @{ 31 */ 32 /** 33 * This enumeration contains audio frame count constants. 34 * <code>PP_AUDIOMINSAMPLEFRAMECOUNT</code> is the minimum possible frame 35 * count. <code>PP_AUDIOMAXSAMPLEFRAMECOUNT</code> is the maximum possible 36 * frame count. 37 */ 38 enum { 39 PP_AUDIOMINSAMPLEFRAMECOUNT = 64, 40 PP_AUDIOMAXSAMPLEFRAMECOUNT = 32768 41 }; 42 43 /** 44 * PP_AudioSampleRate is an enumeration of the different audio sampling rates. 45 * <code>PP_AUDIOSAMPLERATE_44100</code> is the sample rate used on CDs and 46 * <code>PP_AUDIOSAMPLERATE_48000</code> is the sample rate used on DVDs and 47 * Digital Audio Tapes. 48 */ 49 typedef enum { 50 PP_AUDIOSAMPLERATE_NONE = 0, 51 PP_AUDIOSAMPLERATE_44100 = 44100, 52 PP_AUDIOSAMPLERATE_48000 = 48000, 53 PP_AUDIOSAMPLERATE_LAST = PP_AUDIOSAMPLERATE_48000 54 } PP_AudioSampleRate; 55 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_AudioSampleRate, 4); 56 /** 57 * @} 58 */ 59 60 /** 61 * @addtogroup Interfaces 62 * @{ 63 */ 64 /** 65 * The <code>PPB_AudioConfig</code> interface contains pointers to several 66 * functions for establishing your audio configuration within the browser. 67 * This interface only supports 16-bit stereo output. 68 * 69 * Refer to the 70 * <a href="/native-client/devguide/coding/audio.html">Audio 71 * </a> chapter in the Developer's Guide for information on using this 72 * interface. 73 */ 74 struct PPB_AudioConfig_1_1 { 75 /** 76 * CreateStereo16bit() creates a 16 bit audio configuration resource. The 77 * <code>sample_rate</code> should be the result of calling 78 * <code>RecommendSampleRate</code> and <code>sample_frame_count</code> should 79 * be the result of calling <code>RecommendSampleFrameCount</code>. If the 80 * sample frame count or bit rate isn't supported, this function will fail and 81 * return a null resource. 82 * 83 * A single sample frame on a stereo device means one value for the left 84 * channel and one value for the right channel. 85 * 86 * Buffer layout for a stereo int16 configuration: 87 * <code>int16_t *buffer16;</code> 88 * <code>buffer16[0]</code> is the first left channel sample. 89 * <code>buffer16[1]</code> is the first right channel sample. 90 * <code>buffer16[2]</code> is the second left channel sample. 91 * <code>buffer16[3]</code> is the second right channel sample. 92 * ... 93 * <code>buffer16[2 * (sample_frame_count - 1)]</code> is the last left 94 * channel sample. 95 * <code>buffer16[2 * (sample_frame_count - 1) + 1]</code> is the last 96 * right channel sample. 97 * Data will always be in the native endian format of the platform. 98 * 99 * @param[in] instance A <code>PP_Instance</code> identifying one instance 100 * of a module. 101 * @param[in] sample_rate A <code>PP_AudioSampleRate</code> which is either 102 * <code>PP_AUDIOSAMPLERATE_44100</code> or 103 * <code>PP_AUDIOSAMPLERATE_48000</code>. 104 * @param[in] sample_frame_count A <code>uint32_t</code> frame count returned 105 * from the <code>RecommendSampleFrameCount</code> function. 106 * 107 * @return A <code>PP_Resource</code> containing the 108 * <code>PPB_Audio_Config</code> if successful or a null resource if the 109 * sample frame count or bit rate are not supported. 110 */ 111 PP_Resource (*CreateStereo16Bit)(PP_Instance instance, 112 PP_AudioSampleRate sample_rate, 113 uint32_t sample_frame_count); 114 /** 115 * RecommendSampleFrameCount() returns the supported sample frame count 116 * closest to the requested count. The sample frame count determines the 117 * overall latency of audio. Since one "frame" is always buffered in advance, 118 * smaller frame counts will yield lower latency, but higher CPU utilization. 119 * 120 * Supported sample frame counts will vary by hardware and system (consider 121 * that the local system might be anywhere from a cell phone or a high-end 122 * audio workstation). Sample counts less than 123 * <code>PP_AUDIOMINSAMPLEFRAMECOUNT</code> and greater than 124 * <code>PP_AUDIOMAXSAMPLEFRAMECOUNT</code> are never supported on any 125 * system, but values in between aren't necessarily valid. This function 126 * will return a supported count closest to the requested frame count. 127 * 128 * RecommendSampleFrameCount() result is intended for audio output devices. 129 * 130 * @param[in] instance 131 * @param[in] sample_rate A <code>PP_AudioSampleRate</code> which is either 132 * <code>PP_AUDIOSAMPLERATE_44100</code> or 133 * <code>PP_AUDIOSAMPLERATE_48000.</code> 134 * @param[in] requested_sample_frame_count A <code>uint_32t</code> requested 135 * frame count. 136 * 137 * @return A <code>uint32_t</code> containing the recommended sample frame 138 * count if successful. 139 */ 140 uint32_t (*RecommendSampleFrameCount)( 141 PP_Instance instance, 142 PP_AudioSampleRate sample_rate, 143 uint32_t requested_sample_frame_count); 144 /** 145 * IsAudioConfig() determines if the given resource is a 146 * <code>PPB_Audio_Config</code>. 147 * 148 * @param[in] resource A <code>PP_Resource</code> corresponding to an audio 149 * config resource. 150 * 151 * @return A <code>PP_Bool</code> containing <code>PP_TRUE</code> if the given 152 * resource is an <code>AudioConfig</code> resource, otherwise 153 * <code>PP_FALSE</code>. 154 */ 155 PP_Bool (*IsAudioConfig)(PP_Resource resource); 156 /** 157 * GetSampleRate() returns the sample rate for the given 158 * <code>PPB_Audio_Config</code>. 159 * 160 * @param[in] config A <code>PP_Resource</code> corresponding to a 161 * <code>PPB_Audio_Config</code>. 162 * 163 * @return A <code>PP_AudioSampleRate</code> containing sample rate or 164 * <code>PP_AUDIOSAMPLERATE_NONE</code> if the resource is invalid. 165 */ 166 PP_AudioSampleRate (*GetSampleRate)(PP_Resource config); 167 /** 168 * GetSampleFrameCount() returns the sample frame count for the given 169 * <code>PPB_Audio_Config</code>. 170 * 171 * @param[in] config A <code>PP_Resource</code> corresponding to an audio 172 * config resource. 173 * 174 * @return A <code>uint32_t</code> containing sample frame count or 175 * 0 if the resource is invalid. Refer to 176 * RecommendSampleFrameCount() for more on sample frame counts. 177 */ 178 uint32_t (*GetSampleFrameCount)(PP_Resource config); 179 /** 180 * RecommendSampleRate() returns the native sample rate that the browser 181 * is using in the backend. Applications that use the recommended sample 182 * rate will have potentially better latency and fidelity. The return value 183 * is intended for audio output devices. If the output sample rate cannot be 184 * determined, this function can return PP_AUDIOSAMPLERATE_NONE. 185 * 186 * @param[in] instance 187 * 188 * @return A <code>uint32_t</code> containing the recommended sample frame 189 * count if successful. 190 */ 191 PP_AudioSampleRate (*RecommendSampleRate)(PP_Instance instance); 192 }; 193 194 typedef struct PPB_AudioConfig_1_1 PPB_AudioConfig; 195 196 struct PPB_AudioConfig_1_0 { 197 PP_Resource (*CreateStereo16Bit)(PP_Instance instance, 198 PP_AudioSampleRate sample_rate, 199 uint32_t sample_frame_count); 200 uint32_t (*RecommendSampleFrameCount)( 201 PP_AudioSampleRate sample_rate, 202 uint32_t requested_sample_frame_count); 203 PP_Bool (*IsAudioConfig)(PP_Resource resource); 204 PP_AudioSampleRate (*GetSampleRate)(PP_Resource config); 205 uint32_t (*GetSampleFrameCount)(PP_Resource config); 206 }; 207 /** 208 * @} 209 */ 210 211 #endif /* PPAPI_C_PPB_AUDIO_CONFIG_H_ */ 212 213