Skip to content

Commit 611914b

Browse files
committed
Merge branch 'feature/add_new_function_in_encoder' into 'master'
Add new function in esp_audio_codec See merge request adf/esp-adf-libs!283
2 parents 35c37e1 + f368fa3 commit 611914b

38 files changed

+883
-78
lines changed

esp_audio_codec/include/decoder/esp_audio_dec.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ typedef struct {
122122
*/
123123
typedef void *esp_audio_dec_handle_t;
124124

125+
/**
126+
* @brief Query whether the audio type is supported in decoder
127+
*
128+
* @param[in] type Audio decoder type
129+
*
130+
* @return
131+
* - ESP_AUDIO_ERR_OK On success
132+
* - ESP_AUDIO_ERR_NOT_SUPPORT Not support the audio type
133+
*/
134+
esp_audio_err_t esp_audio_dec_check_audio_type(esp_audio_type_t type);
135+
125136
/**
126137
* @brief Open audio decoder
127138
*

esp_audio_codec/include/encoder/esp_audio_enc.h

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,57 @@ typedef struct {
6464
uint64_t pts; /*!< Presentation time stamp(PTS) calculated from accumulated input raw frame unit ms */
6565
} esp_audio_enc_out_frame_t;
6666

67+
/**
68+
* @brief Audio encoder frame information structure
69+
*/
70+
typedef struct {
71+
int in_frame_size; /*!< One input frame size */
72+
uint8_t in_frame_align; /*!< The required alignment number for the input buffer */
73+
int out_frame_size; /*!< The recommended out buffer size to store one encoded frame */
74+
uint8_t out_frame_align; /*!< The required alignment number for the output buffer */
75+
} esp_audio_enc_frame_info_t;
76+
6777
/**
6878
* @brief Encoder configuration
6979
*/
7080
typedef struct {
7181
esp_audio_type_t type; /*!< Audio encoder type which from 'esp_audio_type_t'. */
7282
void *cfg; /*!< Audio encoder configuration. For example, if choose AAC encoder,
73-
user need to config 'esp_aac_enc_config_t' and set the pointer
74-
of this configuration to 'cfg'. */
83+
user need to config 'esp_aac_enc_config_t' and set the pointer
84+
of this configuration to 'cfg'. */
7585
uint32_t cfg_sz; /*!< Size of "cfg". For example, if choose AAC encoder, the 'cfg_sz'
76-
is sizeof 'esp_aac_enc_config_t'*/
86+
is sizeof 'esp_aac_enc_config_t'*/
7787
} esp_audio_enc_config_t;
7888

7989
/**
8090
* @brief Handle for audio encoder instance
8191
*/
8292
typedef void *esp_audio_enc_handle_t;
8393

94+
/**
95+
* @brief Query frame information with encoder configuration
96+
*
97+
* @param[in] config Audio encoder configuration
98+
* @param[out] frame_info The structure of frame information
99+
*
100+
* @return
101+
* - ESP_AUDIO_ERR_OK On success
102+
* - ESP_AUDIO_ERR_NOT_SUPPORT Not support the audio type
103+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
104+
*/
105+
esp_audio_err_t esp_audio_enc_get_frame_info_by_cfg(esp_audio_enc_config_t *config, esp_audio_enc_frame_info_t *frame_info);
106+
107+
/**
108+
* @brief Query whether the audio type is supported
109+
*
110+
* @param[in] type Audio encoder type
111+
*
112+
* @return
113+
* - ESP_AUDIO_ERR_OK On success
114+
* - ESP_AUDIO_ERR_NOT_SUPPORT Not support the audio type
115+
*/
116+
esp_audio_err_t esp_audio_enc_check_audio_type(esp_audio_type_t type);
117+
84118
/**
85119
* @brief Create encoder handle through encoder configuration
86120
*
@@ -91,21 +125,29 @@ typedef void *esp_audio_enc_handle_t;
91125
* - ESP_AUDIO_ERR_OK On success
92126
* - ESP_AUDIO_ERR_FAIL Encoder initialize failed
93127
* - ESP_AUDIO_ERR_MEM_LACK Fail to allocate memory
128+
* - ESP_AUDIO_ERR_NOT_SUPPORT Encoder not register yet
94129
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
95130
*/
96131
esp_audio_err_t esp_audio_enc_open(esp_audio_enc_config_t *config, esp_audio_enc_handle_t *enc_hd);
97132

98133
/**
99-
* @brief Get audio encoder information from encoder handle
134+
* @brief Set audio encoder bitrate
100135
*
101-
* @param[in] enc_hd The encoder handle
102-
* @param[in] enc_info The encoder information
136+
* @note 1. The current set function and processing function do not have lock protection, so when performing
137+
* asynchronous processing, special attention in needed to ensure data consistency and thread safety,
138+
* avoiding race conditions and resource conflicts.
139+
* 2. The bitrate value can be get by `esp_audio_enc_get_info`
140+
*
141+
* @param[in] enc_hd The audio encoder handle
142+
* @param[in] bitrate The bitrate of audio
103143
*
104144
* @return
105145
* - ESP_AUDIO_ERR_OK On success
146+
* - ESP_AUDIO_ERR_FAIL Fail to set bitrate
147+
* - ESP_AUDIO_ERR_NOT_SUPPORT Not support to set bitrate function
106148
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
107149
*/
108-
esp_audio_err_t esp_audio_enc_get_info(esp_audio_enc_handle_t enc_hd, esp_audio_enc_info_t *enc_info);
150+
esp_audio_err_t esp_audio_enc_set_bitrate(void *enc_hd, int bitrate);
109151

110152
/**
111153
* @brief Get the input PCM data length and recommended output buffer length needed by encoding one frame
@@ -118,6 +160,7 @@ esp_audio_err_t esp_audio_enc_get_info(esp_audio_enc_handle_t enc_hd, esp_audio_
118160
*
119161
* @return
120162
* - ESP_AUDIO_ERR_OK On success
163+
* - ESP_AUDIO_ERR_NOT_SUPPORT Encoder not register yet
121164
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
122165
*/
123166
esp_audio_err_t esp_audio_enc_get_frame_size(esp_audio_enc_handle_t enc_hd, int *in_size, int *out_size);
@@ -132,11 +175,25 @@ esp_audio_err_t esp_audio_enc_get_frame_size(esp_audio_enc_handle_t enc_hd, int
132175
* @return
133176
* - ESP_AUDIO_ERR_OK On success
134177
* - ESP_AUDIO_ERR_FAIL Encode error
178+
* - ESP_AUDIO_ERR_NOT_SUPPORT Encoder not register yet
135179
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
136180
*/
137181
esp_audio_err_t esp_audio_enc_process(esp_audio_enc_handle_t enc_hd, esp_audio_enc_in_frame_t *in_frame,
138182
esp_audio_enc_out_frame_t *out_frame);
139183

184+
/**
185+
* @brief Get audio encoder information from encoder handle
186+
*
187+
* @param[in] enc_hd The encoder handle
188+
* @param[in] enc_info The encoder information
189+
*
190+
* @return
191+
* - ESP_AUDIO_ERR_OK On success
192+
* - ESP_AUDIO_ERR_NOT_SUPPORT Encoder not register yet
193+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
194+
*/
195+
esp_audio_err_t esp_audio_enc_get_info(esp_audio_enc_handle_t enc_hd, esp_audio_enc_info_t *enc_info);
196+
140197
/**
141198
* @brief Close an encoder handle
142199
*

esp_audio_codec/include/encoder/esp_audio_enc_reg.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ extern "C" {
3434
* @brief Audio encoder operations to be registered
3535
*/
3636
typedef struct {
37-
esp_audio_err_t (*open)(void *cfg, uint32_t cfg_sz, void **enc_hd); /*!< Create an encoder handle which
38-
according to user configuration. */
39-
esp_audio_err_t (*get_info)(void *enc_hd, esp_audio_enc_info_t *enc_info); /*!< Get encoder information. */
40-
esp_audio_err_t (*get_frame_size)(void *enc_hd, int *in_size, int *out_size); /*!< Get in buffer and out buffer size. */
37+
esp_audio_err_t (*get_frame_info_by_cfg)(void *cfg, esp_audio_enc_frame_info_t *frame_info); /*!< Query frame information with encoder configuration. */
38+
esp_audio_err_t (*open)(void *cfg, uint32_t cfg_sz, void **enc_hd); /*!< Create an encoder handle which
39+
according to user configuration. */
40+
esp_audio_err_t (*set_bitrate)(void *enc_hd, int bitrate); /*!< Set encoder bitrate. */
41+
esp_audio_err_t (*get_info)(void *enc_hd, esp_audio_enc_info_t *enc_info); /*!< Get encoder information. */
42+
esp_audio_err_t (*get_frame_size)(void *enc_hd, int *in_size, int *out_size); /*!< Get in buffer and out buffer size. */
4143
esp_audio_err_t (*process)(void *enc_hd, esp_audio_enc_in_frame_t *in_frame,
42-
esp_audio_enc_out_frame_t *out_frame); /*!< Encode pcm data. */
43-
void (*close)(void *enc_hd); /*!< Close an encoder handle. */
44+
esp_audio_enc_out_frame_t *out_frame); /*!< Encode pcm data. */
45+
void (*close)(void *enc_hd); /*!< Close an encoder handle. */
4446
} esp_audio_enc_ops_t;
4547

4648
/**

esp_audio_codec/include/encoder/impl/esp_aac_enc.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ typedef struct {
8282
*/
8383
esp_audio_err_t esp_aac_enc_register(void);
8484

85+
/**
86+
* @brief Query frame information with encoder configuration
87+
*
88+
* @param[in] cfg AAC encoder configuration
89+
* @param[out] frame_info The structure of frame information
90+
*
91+
* @return
92+
* - ESP_AUDIO_ERR_OK On success
93+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
94+
*/
95+
esp_audio_err_t esp_aac_enc_get_frame_info_by_cfg(void *cfg, esp_audio_enc_frame_info_t *frame_info);
96+
8597
/**
8698
* @brief Create AAC encoder handle through encoder configuration
8799
*
@@ -97,6 +109,24 @@ esp_audio_err_t esp_aac_enc_register(void);
97109
*/
98110
esp_audio_err_t esp_aac_enc_open(void *cfg, uint32_t cfg_sz, void **enc_hd);
99111

112+
/**
113+
* @brief Set AAC encoder bitrate
114+
*
115+
* @note 1. The current set function and processing function do not have lock protection, so when performing
116+
* asynchronous processing, special attention in needed to ensure data consistency and thread safety,
117+
* avoiding race conditions and resource conflicts.
118+
* 2. The bitrate value can be get by `esp_aac_enc_get_info`
119+
*
120+
* @param[in] enc_hd The AAC encoder handle
121+
* @param[in] bitrate The bitrate of AAC
122+
*
123+
* @return
124+
* - ESP_AUDIO_ERR_OK On success
125+
* - ESP_AUDIO_ERR_FAIL Fail to set bitrate
126+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
127+
*/
128+
esp_audio_err_t esp_aac_enc_set_bitrate(void *enc_hd, int bitrate);
129+
100130
/**
101131
* @brief Get the input PCM data length and recommended output buffer length needed by encoding one frame
102132
*
@@ -120,6 +150,7 @@ esp_audio_err_t esp_aac_enc_get_frame_size(void *enc_hd, int *in_size, int *out_
120150
* @return
121151
* - ESP_AUDIO_ERR_OK On success
122152
* - ESP_AUDIO_ERR_FAIL Encode error
153+
* - ESP_AUDIO_ERR_DATA_LACK Not enough input data to encode one or several frames
123154
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
124155
*/
125156
esp_audio_err_t esp_aac_enc_process(void *enc_hd, esp_audio_enc_in_frame_t *in_frame, esp_audio_enc_out_frame_t *out_frame);

esp_audio_codec/include/encoder/impl/esp_adpcm_enc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ typedef struct {
6161
*/
6262
esp_audio_err_t esp_adpcm_enc_register(void);
6363

64+
/**
65+
* @brief Query frame information with encoder configuration
66+
*
67+
* @param[in] cfg ADPCM encoder configuration
68+
* @param[out] frame_info The structure of frame information
69+
*
70+
* @return
71+
* - ESP_AUDIO_ERR_OK On success
72+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
73+
*/
74+
esp_audio_err_t esp_adpcm_enc_get_frame_info_by_cfg(void *cfg, esp_audio_enc_frame_info_t *frame_info);
75+
6476
/**
6577
* @brief Create ADPCM encoder handle through encoder configuration
6678
*
@@ -99,6 +111,7 @@ esp_audio_err_t esp_adpcm_enc_get_frame_size(void *enc_hd, int *in_size, int *ou
99111
* @return
100112
* - ESP_AUDIO_ERR_OK On success
101113
* - ESP_AUDIO_ERR_FAIL Encode error
114+
* - ESP_AUDIO_ERR_DATA_LACK Not enough input data to encode one or several frames
102115
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
103116
*/
104117
esp_audio_err_t esp_adpcm_enc_process(void *enc_hd, esp_audio_enc_in_frame_t *in_frame,

esp_audio_codec/include/encoder/impl/esp_alac_enc.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ typedef struct {
6666
*/
6767
esp_audio_err_t esp_alac_enc_register(void);
6868

69+
/**
70+
* @brief Query frame information with encoder configuration
71+
*
72+
* @param[in] cfg ALAC encoder configuration
73+
* @param[out] frame_info The structure of frame information
74+
*
75+
* @return
76+
* - ESP_AUDIO_ERR_OK On success
77+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
78+
*/
79+
esp_audio_err_t esp_alac_enc_get_frame_info_by_cfg(void *cfg, esp_audio_enc_frame_info_t *frame_info);
80+
6981
/**
7082
* @brief Create ALAC encoder handle through encoder configuration
7183
*
@@ -104,6 +116,7 @@ esp_audio_err_t esp_alac_enc_get_frame_size(void *enc_hd, int *in_size, int *out
104116
* @return
105117
* - ESP_AUDIO_ERR_OK On success
106118
* - ESP_AUDIO_ERR_FAIL Encode error
119+
* - ESP_AUDIO_ERR_DATA_LACK Not enough input data to encode one or several frames
107120
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
108121
*/
109122
esp_audio_err_t esp_alac_enc_process(void *enc_hd, esp_audio_enc_in_frame_t *in_frame,

esp_audio_codec/include/encoder/impl/esp_amrnb_enc.h

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ extern "C" {
3535
* @brief Enum of AMRNB Encoder bitrate choose
3636
*/
3737
typedef enum {
38-
ESP_AMRNB_ENC_BITRATE_UNKNOW = -1, /*!< Invalid mode */
39-
ESP_AMRNB_ENC_BITRATE_MR475 = 0, /*!< 4.75 Kbps */
40-
ESP_AMRNB_ENC_BITRATE_MR515 = 1, /*!< 5.15 Kbps */
41-
ESP_AMRNB_ENC_BITRATE_MR59 = 2, /*!< 5.90 Kbps */
42-
ESP_AMRNB_ENC_BITRATE_MR67 = 3, /*!< 6.70 Kbps */
43-
ESP_AMRNB_ENC_BITRATE_MR74 = 4, /*!< 7.40 Kbps */
44-
ESP_AMRNB_ENC_BITRATE_MR795 = 5, /*!< 7.95 Kbps */
45-
ESP_AMRNB_ENC_BITRATE_MR102 = 6, /*!< 10.2 Kbps */
46-
ESP_AMRNB_ENC_BITRATE_MR122 = 7, /*!< 12.2 Kbps */
38+
ESP_AMRNB_ENC_BITRATE_UNKNOW = -1, /*!< Invalid mode */
39+
ESP_AMRNB_ENC_BITRATE_MR475 = 4750, /*!< 4.75 Kbps */
40+
ESP_AMRNB_ENC_BITRATE_MR515 = 5150, /*!< 5.15 Kbps */
41+
ESP_AMRNB_ENC_BITRATE_MR59 = 5900, /*!< 5.90 Kbps */
42+
ESP_AMRNB_ENC_BITRATE_MR67 = 6700, /*!< 6.70 Kbps */
43+
ESP_AMRNB_ENC_BITRATE_MR74 = 7400, /*!< 7.40 Kbps */
44+
ESP_AMRNB_ENC_BITRATE_MR795 = 7950, /*!< 7.95 Kbps */
45+
ESP_AMRNB_ENC_BITRATE_MR102 = 10200, /*!< 10.2 Kbps */
46+
ESP_AMRNB_ENC_BITRATE_MR122 = 12200, /*!< 12.2 Kbps */
4747
} esp_amrnb_enc_bitrate_t;
4848

4949
/**
@@ -82,6 +82,18 @@ typedef struct {
8282
*/
8383
esp_audio_err_t esp_amrnb_enc_register(void);
8484

85+
/**
86+
* @brief Query frame information with encoder configuration
87+
*
88+
* @param[in] cfg AMRNB encoder configuration
89+
* @param[out] frame_info The structure of frame information
90+
*
91+
* @return
92+
* - ESP_AUDIO_ERR_OK On success
93+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
94+
*/
95+
esp_audio_err_t esp_amrnb_enc_get_frame_info_by_cfg(void *cfg, esp_audio_enc_frame_info_t *frame_info);
96+
8597
/**
8698
* @brief Create AMRNB encoder handle through encoder configuration
8799
*
@@ -97,6 +109,25 @@ esp_audio_err_t esp_amrnb_enc_register(void);
97109
*/
98110
esp_audio_err_t esp_amrnb_enc_open(void *cfg, uint32_t cfg_sz, void **enc_hd);
99111

112+
/**
113+
* @brief Set AMRNB encoder bitrate
114+
*
115+
* @note 1. The current set function and processing function do not have lock protection, so when performing
116+
* asynchronous processing, special attention in needed to ensure data consistency and thread safety,
117+
* avoiding race conditions and resource conflicts.
118+
* 2. The bitrate value can be get by `esp_amrnb_enc_get_info`
119+
* 3. The value of bitrate must be the value in `esp_amrnb_enc_bitrate_t`
120+
*
121+
* @param[in] enc_hd The AMRNB encoder handle
122+
* @param[in] bitrate The bitrate of AMRNB
123+
*
124+
* @return
125+
* - ESP_AUDIO_ERR_OK On success
126+
* - ESP_AUDIO_ERR_FAIL Fail to set bitrate
127+
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
128+
*/
129+
esp_audio_err_t esp_amrnb_enc_set_bitrate(void *enc_hd, int bitrate);
130+
100131
/**
101132
* @brief Get the input PCM data length and recommended output buffer length needed by encoding one frame
102133
*
@@ -120,6 +151,7 @@ esp_audio_err_t esp_amrnb_enc_get_frame_size(void *enc_hd, int *in_size, int *ou
120151
* @return
121152
* - ESP_AUDIO_ERR_OK On success
122153
* - ESP_AUDIO_ERR_FAIL Encode error
154+
* - ESP_AUDIO_ERR_DATA_LACK Not enough input data to encode one or several frames
123155
* - ESP_AUDIO_ERR_INVALID_PARAMETER Invalid parameter
124156
*/
125157
esp_audio_err_t esp_amrnb_enc_process(void *enc_hd, esp_audio_enc_in_frame_t *in_frame,

0 commit comments

Comments
 (0)