@@ -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 */
7080typedef 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 */
8292typedef 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 */
96131esp_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 */
123166esp_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 */
137181esp_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 *
0 commit comments