Eric Laurent | c902d7f | 2013-03-08 14:50:45 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * BSD LICENSE |
| 3 | * |
| 4 | * Copyright (c) 2011-2012, Intel Corporation |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions are met: |
| 9 | * |
| 10 | * Redistributions of source code must retain the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer. |
| 12 | * Redistributions in binary form must reproduce the above copyright notice, |
| 13 | * this list of conditions and the following disclaimer in the documentation |
| 14 | * and/or other materials provided with the distribution. |
| 15 | * Neither the name of Intel Corporation nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this software |
| 17 | * without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 29 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | * |
| 31 | * LGPL LICENSE |
| 32 | * |
| 33 | * tinycompress library for compress audio offload in alsa |
| 34 | * Copyright (c) 2011-2012, Intel Corporation. |
| 35 | * |
| 36 | * |
| 37 | * This program is free software; you can redistribute it and/or modify it |
| 38 | * under the terms and conditions of the GNU Lesser General Public License, |
| 39 | * version 2.1, as published by the Free Software Foundation. |
| 40 | * |
| 41 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 42 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 43 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 44 | * License for more details. |
| 45 | * |
| 46 | * You should have received a copy of the GNU Lesser General Public License |
| 47 | * along with this program; if not, write to |
| 48 | * the Free Software Foundation, Inc., |
| 49 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 50 | */ |
| 51 | |
| 52 | |
| 53 | #ifndef __TINYCOMPRESS_H |
| 54 | #define __TINYCOMPRESS_H |
| 55 | |
| 56 | #if defined(__cplusplus) |
| 57 | extern "C" { |
| 58 | #endif |
| 59 | /* |
| 60 | * struct compr_config: config structure, needs to be filled by app |
| 61 | * If fragment_size or fragments are zero, this means "don't care" |
| 62 | * and tinycompress will choose values that the driver supports |
| 63 | * |
| 64 | * @fragment_size: size of fragment requested, in bytes |
| 65 | * @fragments: number of fragments |
| 66 | * @codec: codec type and parameters requested |
| 67 | */ |
| 68 | struct compr_config { |
| 69 | __u32 fragment_size; |
| 70 | __u32 fragments; |
| 71 | struct snd_codec *codec; |
| 72 | }; |
| 73 | |
| 74 | struct compr_gapless_mdata { |
| 75 | __u32 encoder_delay; |
| 76 | __u32 encoder_padding; |
| 77 | }; |
| 78 | |
| 79 | #define COMPRESS_OUT 0x00000000 |
| 80 | #define COMPRESS_IN 0x10000000 |
| 81 | |
| 82 | struct compress; |
| 83 | struct snd_compr_tstamp; |
| 84 | |
| 85 | /* |
| 86 | * compress_open: open a new compress stream |
| 87 | * returns the valid struct compress on success, NULL on failure |
| 88 | * If config does not specify a requested fragment size, on return |
| 89 | * it will be updated with the size and number of fragments that |
| 90 | * were configured |
| 91 | * |
| 92 | * @card: sound card number |
| 93 | * @device: device number |
| 94 | * @flags: device flags can be COMPRESS_OUT or COMPRESS_IN |
| 95 | * @config: stream config requested. Returns actual fragment config |
| 96 | */ |
| 97 | struct compress *compress_open(unsigned int card, unsigned int device, |
| 98 | unsigned int flags, struct compr_config *config); |
| 99 | |
| 100 | /* |
| 101 | * compress_close: close the compress stream |
| 102 | * |
| 103 | * @compress: compress stream to be closed |
| 104 | */ |
| 105 | void compress_close(struct compress *compress); |
| 106 | |
| 107 | /* |
| 108 | * compress_get_hpointer: get the hw timestamp |
| 109 | * return 0 on success, negative on error |
| 110 | * |
| 111 | * @compress: compress stream on which query is made |
| 112 | * @avail: buffer availble for write/read, in bytes |
| 113 | * @tstamp: hw time |
| 114 | */ |
| 115 | int compress_get_hpointer(struct compress *compress, |
| 116 | unsigned int *avail, struct timespec *tstamp); |
| 117 | |
| 118 | |
| 119 | /* |
| 120 | * compress_get_tstamp: get the raw hw timestamp |
| 121 | * return 0 on success, negative on error |
| 122 | * |
| 123 | * @compress: compress stream on which query is made |
| 124 | * @samples: number of decoded samples played |
| 125 | * @sampling_rate: sampling rate of decoded samples |
| 126 | */ |
| 127 | int compress_get_tstamp(struct compress *compress, |
| 128 | unsigned long *samples, unsigned int *sampling_rate); |
| 129 | |
| 130 | /* |
| 131 | * compress_write: write data to the compress stream |
| 132 | * return bytes written on success, negative on error |
| 133 | * this is a blocking call |
| 134 | * |
| 135 | * @compress: compress stream to be written to |
| 136 | * @buf: pointer to data |
| 137 | * @size: number of bytes to be written |
| 138 | */ |
| 139 | int compress_write(struct compress *compress, const void *buf, unsigned int size); |
| 140 | |
| 141 | /* |
| 142 | * compress_read: read data from the compress stream |
| 143 | * return bytes read on success, negative on error |
| 144 | * |
| 145 | * @compress: compress stream from where data is to be read |
| 146 | * @buf: pointer to data buffer |
| 147 | * @size: size of given buffer |
| 148 | */ |
| 149 | int compress_read(struct compress *compress, void *buf, unsigned int size); |
| 150 | |
| 151 | /* |
| 152 | * compress_start: start the compress stream |
| 153 | * return 0 on success, negative on error |
| 154 | * |
| 155 | * @compress: compress stream to be started |
| 156 | */ |
| 157 | int compress_start(struct compress *compress); |
| 158 | |
| 159 | /* |
| 160 | * compress_stop: stop the compress stream |
| 161 | * return 0 on success, negative on error |
| 162 | * |
| 163 | * @compress: compress stream to be stopped |
| 164 | */ |
| 165 | int compress_stop(struct compress *compress); |
| 166 | |
| 167 | /* |
| 168 | * compress_pause: pause the compress stream |
| 169 | * return 0 on success, negative on error |
| 170 | * |
| 171 | * @compress: compress stream to be paused |
| 172 | */ |
| 173 | int compress_pause(struct compress *compress); |
| 174 | |
| 175 | /* |
| 176 | * compress_resume: resume the compress stream |
| 177 | * return 0 on success, negative on error |
| 178 | * |
| 179 | * @compress: compress stream to be resumed |
| 180 | */ |
| 181 | int compress_resume(struct compress *compress); |
| 182 | |
| 183 | /* |
| 184 | * compress_drain: drain the compress stream |
| 185 | * return 0 on success, negative on error |
| 186 | * |
| 187 | * @compress: compress stream to be drain |
| 188 | */ |
| 189 | int compress_drain(struct compress *compress); |
| 190 | |
| 191 | /* |
| 192 | * compress_next_track: set the next track for stream |
| 193 | * |
| 194 | * return 0 on success, negative on error |
| 195 | * |
| 196 | * @compress: compress stream to be transistioned to next track |
| 197 | */ |
| 198 | int compress_next_track(struct compress *compress); |
| 199 | |
| 200 | /* |
| 201 | * compress_partial_drain: drain will return after the last frame is decoded |
| 202 | * by DSP and will play the , All the data written into compressed |
| 203 | * ring buffer is decoded |
| 204 | * |
| 205 | * return 0 on success, negative on error |
| 206 | * |
| 207 | * @compress: compress stream to be drain |
| 208 | */ |
| 209 | int compress_partial_drain(struct compress *compress); |
| 210 | |
| 211 | /* |
| 212 | * compress_set_gapless_metadata: set gapless metadata of a compress strem |
| 213 | * |
| 214 | * return 0 on success, negative on error |
| 215 | * |
| 216 | * @compress: compress stream for which metadata has to set |
| 217 | * @mdata: metadata encoder delay and padding |
| 218 | */ |
| 219 | |
| 220 | int compress_set_gapless_metadata(struct compress *compress, |
| 221 | struct compr_gapless_mdata *mdata); |
| 222 | |
| 223 | /* |
| 224 | * is_codec_supported:check if the given codec is supported |
| 225 | * returns true when supported, false if not |
| 226 | * |
| 227 | * @card: sound card number |
| 228 | * @device: device number |
| 229 | * @flags: stream flags |
| 230 | * @codec: codec type and parameters to be checked |
| 231 | */ |
| 232 | bool is_codec_supported(unsigned int card, unsigned int device, |
| 233 | unsigned int flags, struct snd_codec *codec); |
| 234 | |
| 235 | /* |
| 236 | * compress_set_max_poll_wait: set the maximum time tinycompress |
| 237 | * will wait for driver to signal a poll(). Interval is in |
| 238 | * milliseconds. |
| 239 | * Pass interval of -1 to disable timeout and make poll() wait |
| 240 | * until driver signals. |
| 241 | * If this function is not used the timeout defaults to 20 seconds. |
| 242 | */ |
| 243 | void compress_set_max_poll_wait(struct compress *compress, int milliseconds); |
| 244 | |
| 245 | int is_compress_running(struct compress *compress); |
| 246 | |
| 247 | int is_compress_ready(struct compress *compress); |
| 248 | |
| 249 | /* Returns a human readable reason for the last error */ |
| 250 | const char *compress_get_error(struct compress *compress); |
| 251 | /* |
| 252 | * since the SNDRV_PCM_RATE_* is not availble anywhere in userspace |
| 253 | * and we have used these to define the sampling rate, we need to define |
| 254 | * then here |
| 255 | */ |
| 256 | #define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */ |
| 257 | #define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */ |
| 258 | #define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */ |
| 259 | #define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */ |
| 260 | #define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */ |
| 261 | #define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */ |
| 262 | #define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */ |
| 263 | #define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */ |
| 264 | #define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */ |
| 265 | #define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */ |
| 266 | #define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */ |
| 267 | #define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */ |
| 268 | #define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */ |
| 269 | |
| 270 | #endif |