-
Notifications
You must be signed in to change notification settings - Fork 41
/
esp_decoder.h
196 lines (181 loc) · 8.07 KB
/
esp_decoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
// All rights reserved.
/**
* @brief ESP_Decoder is a decoder library Espressif develops which could automatically
* recognize audio formats based on the input audio streams.
*/
#ifndef _ESP_DECODER_H_
#define _ESP_DECODER_H_
#include "esp_err.h"
#include "audio_element.h"
#include "audio_common.h"
#include "auto_wav_dec.h"
#include "auto_aac_dec.h"
#include "auto_mp3_dec.h"
#include "auto_amr_dec.h"
#include "auto_flac_dec.h"
#include "auto_ogg_dec.h"
#include "auto_opus_dec.h"
#include "auto_pcm_dec.h"
#include "audio_type_def.h"
#include "esp_id3_parse.h"
#ifdef __cplusplus
extern "C"
{
#endif
#define ESP_DECODER_TASK_STACK_SIZE (3 * 1024)
#define ESP_DECODER_TASK_CORE (0)
#define ESP_DECODER_TASK_PRIO (5)
#define ESP_DECODER_RINGBUFFER_SIZE (10 * 1024)
/**
* @brief To provide audio stream element
*/
typedef struct{
esp_err_t (*decoder_open)(audio_element_handle_t el); /*!< Open an Audio Element type data */
esp_codec_err_t (*decoder_process)(audio_element_handle_t el); /*!< Audio data to decoding */
esp_err_t (*decoder_close)(audio_element_handle_t el); /*!< Close an Audio Element type data */
esp_err_t (*decoder_seek)(audio_element_handle_t self, void *in_data, int in_size, void *out_data, int *out_size); /*!< Seek Audio data in `timePos` to decode */
esp_codec_type_t decoder_type; /*!< Type of Audio file */
} audio_decoder_t;
/**
* @brief The audio formats list
*/
typedef struct decoder_node{
audio_decoder_t audio_decoder; /*!< Audio stream element */
struct decoder_node *next; /*!< The audio formats list */
} audio_decoder_node_t;
/**
* @brief Auto audio decoder configuration
*/
typedef struct{
int out_rb_size; /*!< Size of output ringbuffer */
int task_stack; /*!< Task stack size */
int task_core; /*!< CPU core number (0 or 1) where decoder task in running */
int task_prio; /*!< Task priority (based on freeRTOS priority) */
bool stack_in_ext; /*!< Try to allocate stack in external memory */
bool plus_enable; /*!< Dynamically enable HE-AAC (v1 v2) decoding */
bool id3_parse_enable; /*!< True: parse ID3. False: Don't parse ID3 */
} esp_decoder_cfg_t;
#define DEFAULT_ESP_WAV_DECODER_CONFIG() \
{ \
.decoder_open = wav_decoder_open, \
.decoder_process = wav_decoder_process, \
.decoder_close = wav_decoder_close, \
.decoder_seek = wav_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_WAV, \
}
#define DEFAULT_ESP_MP3_DECODER_CONFIG() \
{ \
.decoder_open = mp3_decoder_open, \
.decoder_process = mp3_decoder_process, \
.decoder_close = mp3_decoder_close, \
.decoder_seek = mp3_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_MP3, \
}
#define DEFAULT_ESP_AMRNB_DECODER_CONFIG() \
{ \
.decoder_open = amr_decoder_open, \
.decoder_process = amr_decoder_process, \
.decoder_close = amr_decoder_close, \
.decoder_seek = amr_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_AMRNB, \
}
#define DEFAULT_ESP_AMRWB_DECODER_CONFIG() \
{ \
.decoder_open = amr_decoder_open, \
.decoder_process = amr_decoder_process, \
.decoder_close = amr_decoder_close, \
.decoder_seek = amr_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_AMRWB, \
}
#define DEFAULT_ESP_AAC_DECODER_CONFIG() \
{ \
.decoder_open = aac_decoder_open, \
.decoder_process = aac_decoder_process, \
.decoder_close = aac_decoder_close, \
.decoder_seek = aac_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_AAC, \
}
#define DEFAULT_ESP_M4A_DECODER_CONFIG() \
{ \
.decoder_open = aac_decoder_open, \
.decoder_process = aac_decoder_process, \
.decoder_close = aac_decoder_close, \
.decoder_seek = aac_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_M4A, \
}
#define DEFAULT_ESP_TS_DECODER_CONFIG() \
{ \
.decoder_open = aac_decoder_open, \
.decoder_process = aac_decoder_process, \
.decoder_close = aac_decoder_close, \
.decoder_seek = aac_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_TSAAC, \
}
#define DEFAULT_ESP_OGG_DECODER_CONFIG() \
{ \
.decoder_open = ogg_decoder_open, \
.decoder_process = ogg_decoder_process, \
.decoder_close = ogg_decoder_close, \
.decoder_seek = ogg_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_OGG, \
}
#define DEFAULT_ESP_OPUS_DECODER_CONFIG() \
{ \
.decoder_open = opus_decoder_open, \
.decoder_process = opus_decoder_process, \
.decoder_close = opus_decoder_close, \
.decoder_seek = opus_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_OPUS, \
}
#define DEFAULT_ESP_FLAC_DECODER_CONFIG() \
{ \
.decoder_open = flac_decoder_open, \
.decoder_process = flac_decoder_process, \
.decoder_close = flac_decoder_close, \
.decoder_seek = flac_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_FLAC, \
}
#define DEFAULT_ESP_PCM_DECODER_CONFIG() \
{ \
.decoder_open = pcm_decoder_open, \
.decoder_process = pcm_decoder_process, \
.decoder_close = pcm_decoder_close, \
.decoder_seek = pcm_decoder_get_pos, \
.decoder_type = ESP_CODEC_TYPE_PCM, \
}
#define DEFAULT_ESP_DECODER_CONFIG() \
{ \
.out_rb_size = ESP_DECODER_RINGBUFFER_SIZE, \
.task_stack = ESP_DECODER_TASK_STACK_SIZE, \
.task_core = ESP_DECODER_TASK_CORE, \
.task_prio = ESP_DECODER_TASK_PRIO, \
.stack_in_ext = true, \
.plus_enable = false, \
.id3_parse_enable = false, \
}
/**
* @brief Create an Audio Element handler to decode incoming audio data.
* - The handler is created to automatically recognize audio formats.
* - The creation of the handler is dependent on the array of user’s audio decoder list.
*
* @param config The configuration
* @param audio_decoder_list The audio formats list
* @param list_size The number of audio formats
*
* @return The audio element handle
*/
audio_element_handle_t esp_decoder_init(esp_decoder_cfg_t *config, audio_decoder_t *audio_decoder_list, int list_size);
/**
* @brief Get ID3 information
*
* @param self The audio element handle
*
* @return esp_id3_info_t: success
* NULL: ID3 is not exist or memory aloocation failed.
*/
const esp_id3_info_t* esp_decoder_get_id3_info(audio_element_handle_t self);
#ifdef __cplusplus
}
#endif
#endif