| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2009, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bsettop_pcm.h $ |
|---|
| 11 | * $brcm_Revision: 4 $ |
|---|
| 12 | * $brcm_Date: 11/19/09 8:02p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /BSEAV/api/include/bsettop_pcm.h $ |
|---|
| 19 | * |
|---|
| 20 | * 4 11/19/09 8:02p jgarrett |
|---|
| 21 | * SW7405-3357: Adding audio output routing for decode and pcm playback |
|---|
| 22 | * prior to start |
|---|
| 23 | * |
|---|
| 24 | * 3 8/14/08 11:46a jgarrett |
|---|
| 25 | * PR32047: PR32047: Example using PCM capture in Brutus. |
|---|
| 26 | * PR32047: Initial PCM capture API implementation, ignores display. |
|---|
| 27 | * |
|---|
| 28 | * PR32047/2 5/19/08 7:24p mward |
|---|
| 29 | * PR32047: Example using PCM capture in Brutus. |
|---|
| 30 | * |
|---|
| 31 | * PR32047/1 5/16/08 3:31p mward |
|---|
| 32 | * PR32047: Initial PCM capture API implementation, ignores display. |
|---|
| 33 | * |
|---|
| 34 | * 2 10/16/06 11:59a vsilyaev |
|---|
| 35 | * PR 24957: Addded FIFO information into the PCM status structure. Added |
|---|
| 36 | * detection and handling for the underflow of PCM FIFO |
|---|
| 37 | * |
|---|
| 38 | * 1 2/7/05 7:05p dlwin |
|---|
| 39 | * Merge down for release 2005_REFSW_MERGETOMAIN: |
|---|
| 40 | * |
|---|
| 41 | * Irvine_BSEAVSW_Devel/12 7/6/04 3:54p erickson |
|---|
| 42 | * PR11771: settop api dataflow redesign |
|---|
| 43 | * |
|---|
| 44 | * Irvine_BSEAVSW_Devel/11 6/29/04 11:28a erickson |
|---|
| 45 | * PR11135: updated deprecation notices for settop api |
|---|
| 46 | * |
|---|
| 47 | * Irvine_BSEAVSW_Devel/10 11/7/03 4:28p erickson |
|---|
| 48 | * PR8583: removing, fixing or implementing TODO's |
|---|
| 49 | * |
|---|
| 50 | * Irvine_BSEAVSW_Devel/9 11/5/03 11:22a erickson |
|---|
| 51 | * documentation changes |
|---|
| 52 | * |
|---|
| 53 | * Irvine_BSEAVSW_Devel/8 10/28/03 11:28a erickson |
|---|
| 54 | * settop api reworks after internal design view |
|---|
| 55 | * |
|---|
| 56 | * Irvine_BSEAVSW_Devel/7 10/10/03 5:33p erickson |
|---|
| 57 | * converted all streaming api's to use size_t instead of unsigned |
|---|
| 58 | * |
|---|
| 59 | * Irvine_BSEAVSW_Devel/6 9/25/03 3:26p erickson |
|---|
| 60 | * added get_status to wait for file to complete |
|---|
| 61 | * |
|---|
| 62 | * Irvine_BSEAVSW_Devel/5 9/25/03 11:22a erickson |
|---|
| 63 | * renamed init_settings functions |
|---|
| 64 | * |
|---|
| 65 | * Irvine_BSEAVSW_Devel/4 9/24/03 11:51a erickson |
|---|
| 66 | * initial pcm play implementation |
|---|
| 67 | * |
|---|
| 68 | * Irvine_BSEAVSW_Devel/3 9/24/03 11:06a erickson |
|---|
| 69 | * pcm work |
|---|
| 70 | * |
|---|
| 71 | * Irvine_BSEAVSW_Devel/2 9/22/03 11:29a erickson |
|---|
| 72 | * updated api |
|---|
| 73 | * |
|---|
| 74 | * Irvine_BSEAVSW_Devel/1 9/19/03 5:29p erickson |
|---|
| 75 | * new api |
|---|
| 76 | * |
|---|
| 77 | ***************************************************************************/ |
|---|
| 78 | #ifndef BSETTOP_PCM_H__ |
|---|
| 79 | #define BSETTOP_PCM_H__ |
|---|
| 80 | |
|---|
| 81 | #ifdef __cplusplus |
|---|
| 82 | extern "C" |
|---|
| 83 | { |
|---|
| 84 | #endif |
|---|
| 85 | |
|---|
| 86 | /*=*********************************** |
|---|
| 87 | The PCM interface is used to write PCM data to a PCM playback |
|---|
| 88 | channel. |
|---|
| 89 | |
|---|
| 90 | PCM playback can be used for sound effects or music (often with a |
|---|
| 91 | CPU-based decoder for formats like MP3). |
|---|
| 92 | |
|---|
| 93 | The API is the minimal needed for streaming data. The BSEAV team also |
|---|
| 94 | provides a file-based API located in BSEAV/lib/pcmfile. The file-based |
|---|
| 95 | API includes WAV file support. |
|---|
| 96 | **************************************/ |
|---|
| 97 | |
|---|
| 98 | /* |
|---|
| 99 | Summary: |
|---|
| 100 | PCM playback handle returned by bpcm_play_open. |
|---|
| 101 | Description: |
|---|
| 102 | The implementation of the handle is private. |
|---|
| 103 | */ |
|---|
| 104 | typedef struct bpcm_play *bpcm_play_t; |
|---|
| 105 | |
|---|
| 106 | /* |
|---|
| 107 | Summary: |
|---|
| 108 | PCM audio settings which are used in bpcm_play_settings and bpcm_record_settings. |
|---|
| 109 | Description: |
|---|
| 110 | The total bitrate of the PCM stream is: |
|---|
| 111 | bits_per_second = bits_per_sample * sample_rate * channels. |
|---|
| 112 | */ |
|---|
| 113 | typedef struct bpcm_settings { |
|---|
| 114 | unsigned bits_per_sample; /* Either 8 or 16 */ |
|---|
| 115 | unsigned sample_rate; /* Samples per channel per second. Either 32000, 44100, 48000. */ |
|---|
| 116 | unsigned channels; /* Either 1 (mono) or 2 (stereo) */ |
|---|
| 117 | } bpcm_settings; |
|---|
| 118 | |
|---|
| 119 | /* |
|---|
| 120 | Summary: |
|---|
| 121 | PCM play settings passed to bpcm_play_start. |
|---|
| 122 | Description: |
|---|
| 123 | Even though there is no more data than just bpcm_settings, we've added this |
|---|
| 124 | to support future API extensions. |
|---|
| 125 | */ |
|---|
| 126 | typedef struct bpcm_play_settings { |
|---|
| 127 | bpcm_settings pcm; /* PCM format */ |
|---|
| 128 | bsettop_callback callback; /* This callback notifies the user that there is |
|---|
| 129 | space available in the pcm playback buffer. The user may call bpcm_play_get_buffer |
|---|
| 130 | but should not call bpcm_play_write_complete. After receiving a callback, |
|---|
| 131 | no additional callback will be received until bpcm_play_write_complete |
|---|
| 132 | is called. */ |
|---|
| 133 | void *callback_context; /* User defined context which is passed into the |
|---|
| 134 | above callback function. */ |
|---|
| 135 | } bpcm_play_settings; |
|---|
| 136 | |
|---|
| 137 | /* |
|---|
| 138 | Summary: |
|---|
| 139 | Required to initialize the bpcm_settings structure. |
|---|
| 140 | */ |
|---|
| 141 | void bpcm_play_settings_init( |
|---|
| 142 | bpcm_play_settings *settings, /* [out] */ |
|---|
| 143 | bpcm_play_t pcmplay /* required for possible resource-dependent defaults */ |
|---|
| 144 | ); |
|---|
| 145 | |
|---|
| 146 | /* |
|---|
| 147 | Summary: |
|---|
| 148 | Open a PCM playback channel. |
|---|
| 149 | */ |
|---|
| 150 | bpcm_play_t bpcm_play_open( |
|---|
| 151 | bobject_t id /* id corresponds to the pcm playback channel. */ |
|---|
| 152 | ); |
|---|
| 153 | |
|---|
| 154 | /* |
|---|
| 155 | Summary: |
|---|
| 156 | Close a PCM playback channel. |
|---|
| 157 | Description: |
|---|
| 158 | Playback must already be stopped. |
|---|
| 159 | */ |
|---|
| 160 | void bpcm_play_close( |
|---|
| 161 | bpcm_play_t pcmplay |
|---|
| 162 | ); |
|---|
| 163 | |
|---|
| 164 | /* |
|---|
| 165 | Summary: |
|---|
| 166 | Start playing PCM audio. |
|---|
| 167 | */ |
|---|
| 168 | bresult bpcm_play_start( |
|---|
| 169 | bpcm_play_t pcmplay, |
|---|
| 170 | bdisplay_t display, /* which output to play to. */ |
|---|
| 171 | const bpcm_play_settings *settings |
|---|
| 172 | ); |
|---|
| 173 | |
|---|
| 174 | /* |
|---|
| 175 | Summary: |
|---|
| 176 | Status information returned by bpcm_play_get_status |
|---|
| 177 | */ |
|---|
| 178 | typedef struct bpcm_play_status { |
|---|
| 179 | bool started; /* Is the pcm playback engine currently played? */ |
|---|
| 180 | unsigned queued_bytes; /* Number of bytes waiting to be played. */ |
|---|
| 181 | unsigned long fifo_size; /* Size in bytes of the pcm buffer */ |
|---|
| 182 | void *buffer_base; /* Pointer to the base of the pcm buffer. |
|---|
| 183 | This can be used for calculating your exact position |
|---|
| 184 | in the buffer for alignment considerations. */ |
|---|
| 185 | } bpcm_play_status; |
|---|
| 186 | |
|---|
| 187 | /* |
|---|
| 188 | Summary: |
|---|
| 189 | Get status information. |
|---|
| 190 | */ |
|---|
| 191 | bresult bpcm_play_get_status( |
|---|
| 192 | bpcm_play_t pcmplay, |
|---|
| 193 | bpcm_play_status *status /* [out] */ |
|---|
| 194 | ); |
|---|
| 195 | |
|---|
| 196 | /** |
|---|
| 197 | Summary: |
|---|
| 198 | Get space available in the pcm playback buffer. |
|---|
| 199 | |
|---|
| 200 | Description: |
|---|
| 201 | This is a non-destructive call. You can call it as many times as you want. |
|---|
| 202 | After writing data into the buffer, you should call bpcm_play_write_complete |
|---|
| 203 | to report how much of the buffer was used. |
|---|
| 204 | **/ |
|---|
| 205 | bresult bpcm_play_get_buffer( |
|---|
| 206 | bpcm_play_t pcmplay, |
|---|
| 207 | void **data, |
|---|
| 208 | size_t *length |
|---|
| 209 | ); |
|---|
| 210 | |
|---|
| 211 | /** |
|---|
| 212 | Summary: |
|---|
| 213 | **/ |
|---|
| 214 | bresult bpcm_play_write_complete( |
|---|
| 215 | bpcm_play_t pcmplay, |
|---|
| 216 | size_t amount_written |
|---|
| 217 | ); |
|---|
| 218 | |
|---|
| 219 | /* |
|---|
| 220 | Summary: |
|---|
| 221 | Stop PCM playback |
|---|
| 222 | */ |
|---|
| 223 | bresult bpcm_play_stop( |
|---|
| 224 | bpcm_play_t pcmplay |
|---|
| 225 | ); |
|---|
| 226 | |
|---|
| 227 | /* |
|---|
| 228 | Summary: |
|---|
| 229 | PCM Playback Output Settings |
|---|
| 230 | */ |
|---|
| 231 | typedef struct bpcm_play_output_settings |
|---|
| 232 | { |
|---|
| 233 | bdisplay_t display; /* The display that will receive audio from this bpcm_play_t. On some chips, audio input/output |
|---|
| 234 | mapping cannot be changed while audio is started, setting this variable prior to start will |
|---|
| 235 | associate the audio decoder with the proper display. Optional, pass NULL to use the display from |
|---|
| 236 | bpcm_play_start() instead. */ |
|---|
| 237 | } bpcm_play_output_settings; |
|---|
| 238 | |
|---|
| 239 | /* |
|---|
| 240 | Summary: |
|---|
| 241 | Get PCM Playback Output Settings |
|---|
| 242 | */ |
|---|
| 243 | void bpcm_play_get_output_settings( |
|---|
| 244 | bpcm_play_t pcmplay, |
|---|
| 245 | bpcm_play_output_settings *settings /* [out] */ |
|---|
| 246 | ); |
|---|
| 247 | |
|---|
| 248 | /* |
|---|
| 249 | Summary: |
|---|
| 250 | Set PCM Playback Output Settings |
|---|
| 251 | */ |
|---|
| 252 | bresult bpcm_play_set_output_settings( |
|---|
| 253 | bpcm_play_t pcmplay, |
|---|
| 254 | const bpcm_play_output_settings *settings |
|---|
| 255 | ); |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | typedef struct bpcm_capture *bpcm_capture_t; |
|---|
| 259 | |
|---|
| 260 | typedef struct bpcm_capture_settings { |
|---|
| 261 | bpcm_settings pcm; /* PCM format */ |
|---|
| 262 | bsettop_callback callback; /* This callback notifies the user that there is |
|---|
| 263 | data available in the capture buffer. The user may call bpcm_capture_get_buffer |
|---|
| 264 | but should not call bpcm_capture_read_complete. After receiving a callback, |
|---|
| 265 | no additional callback will be received until bpcm_capture_read_complete |
|---|
| 266 | is called. */ |
|---|
| 267 | void *callback_context; /* User defined context which is passed into the |
|---|
| 268 | above callback function. */ |
|---|
| 269 | } bpcm_capture_settings; |
|---|
| 270 | |
|---|
| 271 | /* |
|---|
| 272 | Summary: |
|---|
| 273 | Required to initialize the bpcm_capture_settings structure. |
|---|
| 274 | */ |
|---|
| 275 | void bpcm_capture_settings_init( |
|---|
| 276 | bpcm_capture_settings *settings, /* [out] */ |
|---|
| 277 | bpcm_capture_t pcmcapture /* required for possible resource-dependent defaults */ |
|---|
| 278 | ); |
|---|
| 279 | |
|---|
| 280 | /* |
|---|
| 281 | Summary: |
|---|
| 282 | Open a PCM capture channel. |
|---|
| 283 | */ |
|---|
| 284 | bpcm_capture_t bpcm_capture_open( |
|---|
| 285 | bobject_t id /* id corresponds to the pcm capture channel. */ |
|---|
| 286 | ); |
|---|
| 287 | |
|---|
| 288 | /* |
|---|
| 289 | Summary: |
|---|
| 290 | Close a PCM capture channel. |
|---|
| 291 | Description: |
|---|
| 292 | Capture must already be stopped. |
|---|
| 293 | */ |
|---|
| 294 | void bpcm_capture_close( |
|---|
| 295 | bpcm_capture_t pcmcapture |
|---|
| 296 | ); |
|---|
| 297 | |
|---|
| 298 | /* |
|---|
| 299 | Summary: |
|---|
| 300 | Start capturing PCM audio. |
|---|
| 301 | */ |
|---|
| 302 | bresult bpcm_capture_start( |
|---|
| 303 | bpcm_capture_t pcmcapture, |
|---|
| 304 | bdisplay_t display, /* which output to capture from. */ |
|---|
| 305 | const bpcm_capture_settings *settings |
|---|
| 306 | ); |
|---|
| 307 | |
|---|
| 308 | /** |
|---|
| 309 | Summary: |
|---|
| 310 | Get data available in the pcm capture buffer. |
|---|
| 311 | |
|---|
| 312 | Description: |
|---|
| 313 | This is a non-destructive call. You can call it as many times as you want. |
|---|
| 314 | After reading data from the buffer, you should call bpcm_capture_read_complete |
|---|
| 315 | to report how much of the buffer was consumed. |
|---|
| 316 | **/ |
|---|
| 317 | bresult bpcm_capture_get_buffer( |
|---|
| 318 | bpcm_capture_t pcmcapture, |
|---|
| 319 | void **data, |
|---|
| 320 | size_t *length |
|---|
| 321 | ); |
|---|
| 322 | |
|---|
| 323 | /** |
|---|
| 324 | Summary: |
|---|
| 325 | **/ |
|---|
| 326 | bresult bpcm_capture_read_complete( |
|---|
| 327 | bpcm_capture_t pcmcapture, |
|---|
| 328 | size_t amount_read |
|---|
| 329 | ); |
|---|
| 330 | |
|---|
| 331 | /* |
|---|
| 332 | Summary: |
|---|
| 333 | Stop PCM capture |
|---|
| 334 | */ |
|---|
| 335 | bresult bpcm_capture_stop( |
|---|
| 336 | bpcm_capture_t pcmcapture |
|---|
| 337 | ); |
|---|
| 338 | |
|---|
| 339 | #ifdef __cplusplus |
|---|
| 340 | } |
|---|
| 341 | #endif |
|---|
| 342 | |
|---|
| 343 | #endif /* BSETTOP_PCM_H__ */ |
|---|
| 344 | |
|---|