add global proxy / cache settings to httpget class. This removes the need of passing...
[Rockbox.git] / firmware / export / enc_base.h
blobba8573a4f17445072c30074d61e5c2217fbb4b28
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Base declarations for working with software encoders
12 * Copyright (C) 2006 Michael Sevakis
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef ENC_BASE_H
23 #define ENC_BASE_H
25 /** encoder config structures **/
27 /** aiff_enc.codec **/
28 struct aiff_enc_config
30 #if 0
31 unsigned long sample_depth;
32 #endif
35 /** mp3_enc.codec **/
36 #define MP3_BITR_CAP_8 (1 << 0)
37 #define MP3_BITR_CAP_16 (1 << 1)
38 #define MP3_BITR_CAP_24 (1 << 2)
39 #define MP3_BITR_CAP_32 (1 << 3)
40 #define MP3_BITR_CAP_40 (1 << 4)
41 #define MP3_BITR_CAP_48 (1 << 5)
42 #define MP3_BITR_CAP_56 (1 << 6)
43 #define MP3_BITR_CAP_64 (1 << 7)
44 #define MP3_BITR_CAP_80 (1 << 8)
45 #define MP3_BITR_CAP_96 (1 << 9)
46 #define MP3_BITR_CAP_112 (1 << 10)
47 #define MP3_BITR_CAP_128 (1 << 11)
48 #define MP3_BITR_CAP_144 (1 << 12)
49 #define MP3_BITR_CAP_160 (1 << 13)
50 #define MP3_BITR_CAP_192 (1 << 14)
51 #define MP3_BITR_CAP_224 (1 << 15)
52 #define MP3_BITR_CAP_256 (1 << 16)
53 #define MP3_BITR_CAP_320 (1 << 17)
54 #define MP3_ENC_NUM_BITR 18
56 /* MPEG 1 */
57 #define MPEG1_SAMPR_CAPS (SAMPR_CAP_32 | SAMPR_CAP_48 | SAMPR_CAP_44)
58 #define MPEG1_BITR_CAPS (MP3_BITR_CAP_32 | MP3_BITR_CAP_40 | MP3_BITR_CAP_48 | \
59 MP3_BITR_CAP_56 | MP3_BITR_CAP_64 | MP3_BITR_CAP_80 | \
60 MP3_BITR_CAP_96 | MP3_BITR_CAP_112 | MP3_BITR_CAP_128 | \
61 MP3_BITR_CAP_160 | MP3_BITR_CAP_192 | MP3_BITR_CAP_224 | \
62 MP3_BITR_CAP_256 | MP3_BITR_CAP_320)
64 /* MPEG 2 */
65 #define MPEG2_SAMPR_CAPS (SAMPR_CAP_22 | SAMPR_CAP_24 | SAMPR_CAP_16)
66 #define MPEG2_BITR_CAPS (MP3_BITR_CAP_8 | MP3_BITR_CAP_16 | MP3_BITR_CAP_24 | \
67 MP3_BITR_CAP_32 | MP3_BITR_CAP_40 | MP3_BITR_CAP_48 | \
68 MP3_BITR_CAP_56 | MP3_BITR_CAP_64 | MP3_BITR_CAP_80 | \
69 MP3_BITR_CAP_96 | MP3_BITR_CAP_112 | MP3_BITR_CAP_128 | \
70 MP3_BITR_CAP_144 | MP3_BITR_CAP_160)
72 #if 0
73 /* MPEG 2.5 */
74 #define MPEG2_5_SAMPR_CAPS (SAMPR_CAP_8 | SAMPR_CAP_12 | SAMPR_CAP_11)
75 #define MPEG2_5_BITR_CAPS MPEG2_BITR_CAPS
76 #endif
78 /* HAVE_MPEG* defines mainly apply to the bitrate menu */
79 #if (REC_SAMPR_CAPS & MPEG1_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
80 #define HAVE_MPEG1_SAMPR
81 #endif
83 #if (REC_SAMPR_CAPS & MPEG2_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
84 #define HAVE_MPEG2_SAMPR
85 #endif
87 #if 0
88 #if (REC_SAMPR_CAPS & MPEG2_5_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
89 #define HAVE_MPEG2_5_SAMPR
90 #endif
91 #endif /* 0 */
93 #define MP3_ENC_SAMPR_CAPS (MPEG1_SAMPR_CAPS | MPEG2_SAMPR_CAPS)
95 /* This number is count of full encoder set */
96 #define MP3_ENC_NUM_SAMPR 6
98 extern const unsigned long mp3_enc_sampr[MP3_ENC_NUM_SAMPR];
99 extern const unsigned long mp3_enc_bitr[MP3_ENC_NUM_BITR];
101 struct mp3_enc_config
103 unsigned long bitrate;
106 #define MP3_ENC_BITRATE_CFG_DEFAULT 11 /* 128 */
107 #define MP3_ENC_BITRATE_CFG_VALUE_LIST "8,16,24,32,40,48,56,64,80,96," \
108 "112,128,144,160,192,224,256,320"
110 /** wav_enc.codec **/
111 #define WAV_ENC_SAMPR_CAPS SAMPR_CAP_ALL
113 struct wav_enc_config
115 #if 0
116 unsigned long sample_depth;
117 #endif
120 /** wavpack_enc.codec **/
121 #define WAVPACK_ENC_SAMPR_CAPS SAMPR_CAP_ALL
123 struct wavpack_enc_config
125 #if 0
126 unsigned long sample_depth;
127 #endif
130 struct encoder_config
132 union
134 /* states which *_enc_config member is valid */
135 int rec_format; /* REC_FORMAT_* value */
136 int afmt; /* AFMT_* value */
139 union
141 struct mp3_enc_config mp3_enc;
142 struct wavpack_enc_config wavpack_enc;
143 struct wav_enc_config wav_enc;
147 /** Encoder chunk macros and definitions **/
148 #define CHUNKF_START_FILE 0x0001ul /* This chunk starts a new file */
149 #define CHUNKF_END_FILE 0x0002ul /* This chunk ends the current file */
150 #define CHUNKF_PRERECORD 0x0010ul /* This chunk is prerecord data,
151 a new file could start anytime */
152 #define CHUNKF_ABORT 0x0020ul /* Encoder should not finish this
153 chunk */
154 #define CHUNKF_ERROR (~0ul ^ (~0ul >> 1)) /* An error has occured
155 (passed to/from encoder). Use the
156 sign bit to check (long)flags < 0. */
157 #define CHUNKF_ALLFLAGS (0x0033ul | CHUNKF_ERROR)
159 /* Header at the beginning of every encoder chunk */
160 #ifdef DEBUG
161 #define ENC_CHUNK_MAGIC H_TO_BE32(('P' << 24) | ('T' << 16) | ('Y' << 8) | 'R')
162 #endif
163 struct enc_chunk_hdr
165 #ifdef DEBUG
166 unsigned long id; /* overflow detection - 'PTYR' - acronym for
167 "PTYR Tells You Right" ;) */
168 #endif
169 unsigned long flags; /* in/out: flags used by encoder and file
170 writing */
171 size_t enc_size; /* out: amount of encoder data written to
172 chunk */
173 unsigned long num_pcm; /* out: number of PCM samples eaten during
174 processing
175 (<= size of allocated buffer) */
176 unsigned char *enc_data; /* out: pointer to enc_size_written bytes
177 of encoded audio data in chunk */
178 /* Encoder defined data follows header. Can be audio data + any other
179 stuff the encoder needs to handle on a per chunk basis */
182 /* Paranoia: be sure header size is 4-byte aligned */
183 #define ENC_CHUNK_HDR_SIZE \
184 ALIGN_UP_P2(sizeof (struct enc_chunk_hdr), 2)
185 /* Skip the chunk header and return data */
186 #define ENC_CHUNK_SKIP_HDR(t, hdr) \
187 ((typeof (t))((char *)hdr + ENC_CHUNK_HDR_SIZE))
188 /* Cast p to struct enc_chunk_hdr * */
189 #define ENC_CHUNK_HDR(p) \
190 ((struct enc_chunk_hdr *)(p))
192 enum enc_events
194 /* File writing events - data points to enc_file_event_data */
195 ENC_START_FILE = 0, /* a new file has been opened and no data has yet
196 been written */
197 ENC_WRITE_CHUNK, /* write the current chunk to disk */
198 ENC_END_FILE, /* current file about to be closed and all valid
199 data has been written */
200 /* Encoder buffer events - data points to enc_buffer_event_data */
201 ENC_REC_NEW_STREAM, /* Take steps to finish current stream and start
202 new */
206 * encoder can write extra data to the file such as headers or more encoded
207 * samples and must update sizes and samples accordingly.
209 struct enc_file_event_data
211 struct enc_chunk_hdr *chunk; /* Current chunk */
212 size_t new_enc_size; /* New size of chunk */
213 unsigned long new_num_pcm; /* New number of pcm in chunk */
214 const char *filename; /* filename to open if ENC_START_FILE */
215 int rec_file; /* Current file or < 0 if none */
216 unsigned long num_pcm_samples; /* Current pcm sample count written to
217 file so far. */
221 * encoder may add some data to the end of the last and start of the next
222 * but must never yield when called so any encoding done should be absolutely
223 * minimal.
225 struct enc_buffer_event_data
227 unsigned long flags; /* in: One or more of:
228 * CHUNKF_PRERECORD
229 * CHUNKF_END_FILE
230 * CHUNKF_START_FILE
232 struct enc_chunk_hdr *pre_chunk; /* in: pointer to first prerecord
233 * chunk
235 struct enc_chunk_hdr *chunk; /* in,out: chunk were split occurs -
236 * first chunk of start
240 /** Callbacks called by encoder codec **/
242 /* parameters passed to encoder by enc_get_inputs */
243 struct enc_inputs
245 unsigned long sample_rate; /* out - pcm frequency */
246 int num_channels; /* out - number of audio channels */
247 struct encoder_config *config; /* out - encoder settings */
250 void enc_get_inputs(struct enc_inputs *inputs);
252 /* parameters pass from encoder to enc_set_parameters */
253 struct enc_parameters
255 /* IN parameters */
256 int afmt; /* AFMT_* id - sanity checker */
257 size_t chunk_size; /* max chunk size required */
258 unsigned long enc_sample_rate; /* actual sample rate used by encoder
259 (for recorded time calculation) */
260 size_t reserve_bytes; /* number of bytes to reserve immediately
261 following chunks */
262 void (*events_callback)(enum enc_events event,
263 void *data); /* pointer to events callback */
264 /* OUT parameters */
265 unsigned char *enc_buffer; /* pointer to enc_buffer */
266 size_t buf_chunk_size; /* size of chunks in enc_buffer */
267 int num_chunks; /* number of chunks allotted to encoder */
268 unsigned char *reserve_buffer; /* pointer to reserve_bytes bytes */
271 /* set the encoder dimensions - called by encoder codec at initialization
272 and termination */
273 void enc_set_parameters(struct enc_parameters *params);
274 /* returns pointer to next write chunk in circular buffer */
275 struct enc_chunk_hdr * enc_get_chunk(void);
276 /* releases the current chunk into the available chunks */
277 void enc_finish_chunk(void);
279 #define PCM_MAX_FEED_SIZE 20000 /* max pcm size passed to encoder */
281 /* passes a pointer to next chunk of unprocessed wav data */
282 unsigned char * enc_get_pcm_data(size_t size);
283 /* puts some pcm data back in the queue */
284 size_t enc_unget_pcm_data(size_t size);
286 #endif /* ENC_BASE_H */