A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Base declarations for working with software encoders
11 *
12 * Copyright (C) 2006-2013 Michael Sevakis
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#ifndef ENC_BASE_H
25#define ENC_BASE_H
26
27#include <sys/types.h>
28
29/** Encoder config structures **/
30
31/** aiff_enc.codec **/
32struct aiff_enc_config
33{
34#if 0
35 unsigned long sample_depth;
36#endif
37};
38
39/** mp3_enc.codec **/
40#define MP3_BITR_CAP_8 (1 << 0)
41#define MP3_BITR_CAP_16 (1 << 1)
42#define MP3_BITR_CAP_24 (1 << 2)
43#define MP3_BITR_CAP_32 (1 << 3)
44#define MP3_BITR_CAP_40 (1 << 4)
45#define MP3_BITR_CAP_48 (1 << 5)
46#define MP3_BITR_CAP_56 (1 << 6)
47#define MP3_BITR_CAP_64 (1 << 7)
48#define MP3_BITR_CAP_80 (1 << 8)
49#define MP3_BITR_CAP_96 (1 << 9)
50#define MP3_BITR_CAP_112 (1 << 10)
51#define MP3_BITR_CAP_128 (1 << 11)
52#define MP3_BITR_CAP_144 (1 << 12)
53#define MP3_BITR_CAP_160 (1 << 13)
54#define MP3_BITR_CAP_192 (1 << 14)
55#define MP3_BITR_CAP_224 (1 << 15)
56#define MP3_BITR_CAP_256 (1 << 16)
57#define MP3_BITR_CAP_320 (1 << 17)
58#define MP3_ENC_NUM_BITR 18
59
60/* MPEG 1 */
61#define MPEG1_SAMPR_CAPS (SAMPR_CAP_32 | SAMPR_CAP_48 | SAMPR_CAP_44)
62#define MPEG1_BITR_CAPS (MP3_BITR_CAP_32 | MP3_BITR_CAP_40 | \
63 MP3_BITR_CAP_48 | MP3_BITR_CAP_56 | \
64 MP3_BITR_CAP_64 | MP3_BITR_CAP_80 | \
65 MP3_BITR_CAP_96 | MP3_BITR_CAP_112 | \
66 MP3_BITR_CAP_128 | MP3_BITR_CAP_160 | \
67 MP3_BITR_CAP_192 | MP3_BITR_CAP_224 | \
68 MP3_BITR_CAP_256 | MP3_BITR_CAP_320)
69
70/* MPEG 2 */
71#define MPEG2_SAMPR_CAPS (SAMPR_CAP_22 | SAMPR_CAP_24 | SAMPR_CAP_16)
72#define MPEG2_BITR_CAPS (MP3_BITR_CAP_8 | MP3_BITR_CAP_16 | \
73 MP3_BITR_CAP_24 | MP3_BITR_CAP_32 | \
74 MP3_BITR_CAP_40 | MP3_BITR_CAP_48 | \
75 MP3_BITR_CAP_56 | MP3_BITR_CAP_64 | \
76 MP3_BITR_CAP_80 | MP3_BITR_CAP_96 | \
77 MP3_BITR_CAP_112 | MP3_BITR_CAP_128 | \
78 MP3_BITR_CAP_144 | MP3_BITR_CAP_160)
79
80#if 0
81/* MPEG 2.5 */
82#define MPEG2_5_SAMPR_CAPS (SAMPR_CAP_8 | SAMPR_CAP_12 | SAMPR_CAP_11)
83#define MPEG2_5_BITR_CAPS MPEG2_BITR_CAPS
84#endif
85
86/* HAVE_MPEG* defines mainly apply to the bitrate menu */
87#if (REC_SAMPR_CAPS & MPEG1_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
88#define HAVE_MPEG1_SAMPR
89#endif
90
91#if (REC_SAMPR_CAPS & MPEG2_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
92#define HAVE_MPEG2_SAMPR
93#endif
94
95#if 0
96#if (REC_SAMPR_CAPS & MPEG2_5_SAMPR_CAPS) || defined (HAVE_SPDIF_REC)
97#define HAVE_MPEG2_5_SAMPR
98#endif
99#endif /* 0 */
100
101#define MP3_ENC_SAMPR_CAPS (MPEG1_SAMPR_CAPS | MPEG2_SAMPR_CAPS)
102
103/* This number is count of full encoder set */
104#define MP3_ENC_NUM_SAMPR 6
105
106#if 0
107extern const unsigned long mp3_enc_sampr[MP3_ENC_NUM_SAMPR];
108#endif
109extern const unsigned long mp3_enc_bitr[MP3_ENC_NUM_BITR];
110
111struct mp3_enc_config
112{
113 unsigned long bitrate;
114};
115
116#define MP3_ENC_BITRATE_CFG_DEFAULT 11 /* 128 */
117#define MP3_ENC_BITRATE_CFG_VALUE_LIST "8,16,24,32,40,48,56,64,80,96," \
118 "112,128,144,160,192,224,256,320"
119
120/** wav_enc.codec **/
121#define WAV_ENC_SAMPR_CAPS SAMPR_CAP_ALL
122
123struct wav_enc_config
124{
125#if 0
126 unsigned long sample_depth;
127#endif
128};
129
130/** wavpack_enc.codec **/
131#define WAVPACK_ENC_SAMPR_CAPS SAMPR_CAP_ALL
132
133struct wavpack_enc_config
134{
135#if 0
136 unsigned long sample_depth;
137#endif
138};
139
140/* General config information about any encoder */
141struct encoder_config
142{
143 union
144 {
145 /* states which *_enc_config member is valid */
146 int rec_format; /* REC_FORMAT_* value */
147 int afmt; /* AFMT_* value */
148 };
149
150 union
151 {
152 struct mp3_enc_config mp3_enc;
153 struct wavpack_enc_config wavpack_enc;
154 struct wav_enc_config wav_enc;
155 };
156};
157
158/** Encoder chunk macros and definitions **/
159
160/* What sort of data does the header describe? */
161enum CHUNK_T
162{
163 CHUNK_T_DATA = 0x0, /* Encoded audio data */
164 CHUNK_T_STREAM_START = 0x1, /* Stream start marker */
165 CHUNK_T_STREAM_END = 0x2, /* Stream end marker */
166 CHUNK_T_WRAP = 0x3 /* Buffer early wrap marker */
167};
168
169/* Header for every buffer slot and chunk */
170union enc_chunk_hdr
171{
172 struct
173 {
174 uint32_t type : 2; /* Chunk type (CHUNK_T_*) */
175 uint32_t err : 1; /* Encoder error */
176 uint32_t pre : 1; /* Chunk is prerecorded data */
177 uint32_t aux0 : 1; /* Aux flag 0 - for encoder */
178 uint32_t unused : 3; /* */
179 uint32_t size : 24; /* size of data */
180 };
181 uint32_t zero; /* Zero-out struct access */
182 intptr_t reserved1; /* Want it at least pointer-sized */
183} __attribute__((__may_alias__));
184
185#define ENC_HDR_SIZE (sizeof (union enc_chunk_hdr))
186
187/* When hdr.type is CHUNK_T_STREAM_START */
188struct enc_chunk_file
189{
190 union enc_chunk_hdr hdr; /* This chunk's header */
191 /* hdr.size = slot count of chunk */
192 char path[]; /* NULL-terminated path of file */
193} __attribute__((__may_alias__));
194
195/* If flags = CHUNK_T_STREAM_END, just the header exists */
196
197/* When hdr.type is CHUNK_T_DATA */
198struct enc_chunk_data
199{
200 union enc_chunk_hdr hdr; /* IN,OUT: This chunk's header */
201 /* hdr.size = total size of data[] */
202 uint32_t pcm_count; /* OUT: number of PCM samples encoded */
203 uint8_t data[]; /* OUT: encoded audio data */
204} __attribute__((__may_alias__));
205
206/* CHUNK_T_STREAM_END and CHUNK_T_WRAP consist of only the header */
207
208#define ENC_FILE_HDR(hdr) ((struct enc_chunk_file *)(hdr))
209#define ENC_DATA_HDR(hdr) ((struct enc_chunk_data *)(hdr))
210
211/* Audio and encoder stream parameters */
212struct enc_inputs
213{
214 /* IN parameters */
215 unsigned long sample_rate; /* PCM samplerate setting */
216 int num_channels; /* Number of audio channels */
217 struct encoder_config *config; /* Encoder settings */
218
219 /* IN,OUT parameters */
220 unsigned long enc_sample_rate; /* Actual sample rate accepted by encoder
221 (for recorded time calculation) */
222};
223
224enum enc_callback_reason
225{
226 ENC_CB_INPUTS, /* 'params' is struct enc_inputs * */
227 ENC_CB_STREAM, /* 'params' is union enc_chunk_hdr * */
228};
229
230typedef int (* enc_callback_t)(enum enc_callback_reason reason, void *params);
231
232#endif /* ENC_BASE_H */