@@ -0,0 +1,488 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO., LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_gmf_afe_manager.h"
|
||||
#include "esp_audio_simple_player_advance.h"
|
||||
#include "av_processor_type.h"
|
||||
|
||||
/* Brief: Default audio manager configuration
|
||||
* Note: When use OPUS decoder or OPUS encoder, the recorder_task_config and feeder_task_config
|
||||
* task stack size need be set to more than 4096 * 10 bytes.
|
||||
*/
|
||||
#define DEFAULT_AUDIO_MANAGER_CONFIG() { \
|
||||
.play_dev = NULL, \
|
||||
.rec_dev = NULL, \
|
||||
.mic_layout = {0}, \
|
||||
.board_sample_rate = 16000, \
|
||||
.board_bits = 32, \
|
||||
.board_channels = 2, \
|
||||
}
|
||||
|
||||
#define DEFAULT_AUDIO_FEEDER_CONFIG() { \
|
||||
.feeder_task_config = { \
|
||||
.task_stack = 0, \
|
||||
.task_prio = 0, \
|
||||
.task_core = 0, \
|
||||
.task_stack_in_ext = true, \
|
||||
}, \
|
||||
.feeder_mixer_gain = { \
|
||||
.initial_gain = 0.0, \
|
||||
.target_gain = 0.5, \
|
||||
.transition_time = 1500 \
|
||||
}, \
|
||||
}
|
||||
|
||||
#define DEFAULT_AUDIO_PLAYBACK_CONFIG() { \
|
||||
.playback_task_config = { \
|
||||
.task_stack = 4096, \
|
||||
.task_prio = 5, \
|
||||
.task_core = 0, \
|
||||
.task_stack_in_ext = true, \
|
||||
}, \
|
||||
.playback_mixer_gain = { \
|
||||
.initial_gain = 0.0, \
|
||||
.target_gain = 1.0, \
|
||||
.transition_time = 1500 \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_AUDIO_PROMPT_CONFIG() { \
|
||||
.prompt_task_config = { \
|
||||
.task_stack = 4096, \
|
||||
.task_prio = 5, \
|
||||
.task_core = 0, \
|
||||
.task_stack_in_ext = true \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_AUDIO_RECORDER_CONFIG() { \
|
||||
.afe_feed_task_config = { \
|
||||
.task_stack = 40 * 1024, \
|
||||
.task_prio = 5, \
|
||||
.task_core = 0, \
|
||||
.task_stack_in_ext = true, \
|
||||
}, \
|
||||
.afe_fetch_task_config = { \
|
||||
.task_stack = 6 * 1024, \
|
||||
.task_prio = 5, \
|
||||
.task_core = 1, \
|
||||
.task_stack_in_ext = true \
|
||||
}, \
|
||||
.recorder_task_config = { \
|
||||
.task_stack = 4096, \
|
||||
.task_prio = 5, \
|
||||
.task_core = 0, \
|
||||
.task_stack_in_ext = true \
|
||||
}, \
|
||||
.recorder_event_cb = NULL, \
|
||||
.recorder_ctx = NULL, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default AFE configuration macro
|
||||
*/
|
||||
#define DEFAULT_AV_PROCESSOR_AFE_CONFIG() { \
|
||||
.model = "model", \
|
||||
.ai_mode_wakeup = false, \
|
||||
.vad_enable = true, \
|
||||
.vad_mode = 4, \
|
||||
.vad_min_speech_ms = 64, \
|
||||
.vad_min_noise_ms = 1000, \
|
||||
.agc_enable = true, \
|
||||
.afe_type = AFE_TYPE_SR, \
|
||||
.enable_vcmd_detect = false, \
|
||||
.vcmd_timeout_ms = 5000, \
|
||||
.mn_language = "cn", \
|
||||
.wakeup_end_time_ms = 2000, \
|
||||
.wakeup_time_ms = 10000 \
|
||||
}
|
||||
/**
|
||||
* @brief Type definition for the audio recorder event callback function
|
||||
*
|
||||
* @param[in] event Pointer to the event data, which can contain information about the recorder's state
|
||||
* @param[in] ctx User-defined context pointer, passed when registering the callback
|
||||
*/
|
||||
typedef void (*recorder_event_callback_t)(void *event, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief AFE (Audio Front-End) configuration structure
|
||||
*
|
||||
* This structure contains all AFE-related configuration parameters that were previously
|
||||
* configured via Kconfig. These parameters control the behavior of the audio front-end
|
||||
* processing including wake word detection, VAD, AGC, and other audio processing features.
|
||||
*/
|
||||
typedef struct {
|
||||
const char *model; /*!< Model path/name for SR model initialization */
|
||||
bool ai_mode_wakeup; /*!< AI mode: true for WAKEUP mode, false for DIRECT mode */
|
||||
bool vad_enable; /*!< Enable Voice Activity Detection (VAD) */
|
||||
int vad_mode; /*!< VAD mode value (1-4), larger values are more sensitive to human voice */
|
||||
int vad_min_speech_ms; /*!< Minimum speech duration in milliseconds */
|
||||
int vad_min_noise_ms; /*!< Minimum noise duration in milliseconds */
|
||||
bool agc_enable; /*!< Enable Automatic Gain Control (AGC) */
|
||||
afe_type_t afe_type; /*!< AFE type: AFE_TYPE_SR (0) or AFE_TYPE_VC (1) */
|
||||
bool enable_vcmd_detect; /*!< Enable Voice Command Detection */
|
||||
int vcmd_timeout_ms; /*!< Voice command detection timeout in milliseconds */
|
||||
const char *mn_language; /*!< Model language (e.g., "cn", "en") */
|
||||
int wakeup_end_time_ms; /*!< Wakeup end time in milliseconds */
|
||||
int wakeup_time_ms; /*!< Wakeup time in milliseconds */
|
||||
} av_processor_afe_config_t;
|
||||
|
||||
/* Brief: Audio mixer gain configuration */
|
||||
typedef struct {
|
||||
float initial_gain; /*!< Initial gain value (0.0 - 1.0) */
|
||||
float target_gain; /*!< Target gain value (0.0 - 1.0) */
|
||||
int transition_time; /*!< Transition time in milliseconds */
|
||||
} audio_mixer_gain_config_t;
|
||||
|
||||
/* Brief: Common task configuration */
|
||||
typedef struct {
|
||||
int task_stack; /*!< Task stack size (0 means use default) */
|
||||
int task_prio; /*!< Task priority */
|
||||
int task_core; /*!< Task core ID */
|
||||
bool task_stack_in_ext; /*!< Whether to allocate task stack in external memory */
|
||||
} audio_task_config_t;
|
||||
|
||||
typedef struct {
|
||||
audio_task_config_t feeder_task_config; /*!< Feeder task configuration */
|
||||
av_processor_decoder_config_t decoder_cfg; /*!< Decoder configuration */
|
||||
audio_mixer_gain_config_t feeder_mixer_gain; /*!< Feeder mixer gain configuration */
|
||||
} audio_feeder_config_t;
|
||||
|
||||
typedef struct {
|
||||
audio_task_config_t playback_task_config; /*!< Playback task configuration */
|
||||
audio_mixer_gain_config_t playback_mixer_gain; /*!< Playback mixer gain configuration */
|
||||
} audio_playback_config_t;
|
||||
|
||||
typedef struct {
|
||||
audio_task_config_t prompt_task_config; /*!< Prompt task configuration */
|
||||
} audio_prompt_config_t;
|
||||
|
||||
typedef struct {
|
||||
audio_task_config_t afe_feed_task_config; /*!< AFE feed task configuration */
|
||||
av_processor_afe_config_t afe_config; /*!< AFE configuration */
|
||||
audio_task_config_t afe_fetch_task_config; /*!< AFE fetch task configuration */
|
||||
audio_task_config_t recorder_task_config; /*!< Recorder task configuration */
|
||||
av_processor_encoder_config_t encoder_cfg; /*!< Encoder configuration */
|
||||
recorder_event_callback_t recorder_event_cb; /*!< Recorder event callback */
|
||||
void *recorder_ctx; /*!< Recorder context */
|
||||
} audio_recorder_config_t;
|
||||
|
||||
/* Brief: Audio manager configuration */
|
||||
typedef struct {
|
||||
void *play_dev;
|
||||
void *rec_dev;
|
||||
char mic_layout[8];
|
||||
int board_sample_rate;
|
||||
int board_bits;
|
||||
int board_channels;
|
||||
} audio_manager_config_t;
|
||||
|
||||
/**
|
||||
* @brief Audio focus control mode - determines which audio stream gets priority
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_MIXER_FOCUS_FEEDER = 0, /*!< Focus on FEEDER stream - boost feeder, reduce playback */
|
||||
AUDIO_MIXER_FOCUS_PLAYBACK = 1, /*!< Focus on PLAYBACK stream - boost playback, reduce feeder */
|
||||
AUDIO_MIXER_FOCUS_BALANCED = 2, /*!< Balanced mode - both streams at equal levels */
|
||||
} audio_mixer_focus_mode_t;
|
||||
|
||||
enum audio_player_state_e {
|
||||
AUDIO_RUN_STATE_IDLE,
|
||||
AUDIO_RUN_STATE_PLAYING,
|
||||
AUDIO_RUN_STATE_CLOSED,
|
||||
AUDIO_RUN_STATE_PAUSED,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Initializes the audio manager module.
|
||||
*
|
||||
* @param[in] config Pointer to the audio manager configuration structure
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_manager_init(audio_manager_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Deinitializes the audio manager component
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_manager_deinit();
|
||||
|
||||
/**
|
||||
* @brief Opens the audio recorder and registers an event callback
|
||||
*
|
||||
* @param[in] config Pointer to the audio recorder configuration structure.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_recorder_open(audio_recorder_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Pauses the audio recorder system
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_recorder_pause(void);
|
||||
|
||||
/**
|
||||
* @brief Resumes the audio recorder system
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_recorder_resume(void);
|
||||
|
||||
/**
|
||||
* @brief Get the AFE manager handle of the audio recorder
|
||||
*
|
||||
* @param[out] afe_manager_handle Pointer to the AFE manager handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_recorder_get_afe_manager_handle(esp_gmf_afe_manager_handle_t *afe_manager_handle);
|
||||
|
||||
/**
|
||||
* @brief Closes the audio recorder
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_recorder_close(void);
|
||||
|
||||
/**
|
||||
* @brief Reads audio data from the recorder.
|
||||
*
|
||||
* @param[out] data Pointer to the buffer where the audio data will be stored
|
||||
* @param[in] data_size Size of the buffer to store the audio data.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_recorder_read_data(uint8_t *data, int data_size);
|
||||
|
||||
/**
|
||||
* @brief Opens the audio feeder system
|
||||
*
|
||||
* @param[in] config Pointer to the audio feeder configuration structure.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_feeder_open(audio_feeder_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Closes the audio feeder module
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_feeder_close(void);
|
||||
|
||||
/**
|
||||
* @brief Starts the audio feeder operation.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_feeder_run(void);
|
||||
|
||||
/**
|
||||
* @brief Stops the ongoing audio feeder
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On successfully stopping the audio playback
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_feeder_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Feeds audio data into the feeder system
|
||||
*
|
||||
* @param[in] data Pointer to the audio data to be fed into the feeder system
|
||||
* @param[in] data_size Size of the audio data to be fed into the feeder system
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_feeder_feed_data(uint8_t *data, int data_size);
|
||||
|
||||
/**
|
||||
* @brief Open the audio playback module
|
||||
*
|
||||
* @param[in] config Pointer to the audio playback configuration structure.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_playback_open(audio_playback_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Close the audio playback module
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_playback_close(void);
|
||||
|
||||
/**
|
||||
* @brief Play an audio playback from the specified URL. Eg: "http://192.168.1.100:8000/audio.mp3", "file:///sdcard/audio.mp3"
|
||||
*
|
||||
* @param[in] url URL pointing to the audio playback file to be played
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_playback_play(const char *url);
|
||||
|
||||
/**
|
||||
* @brief Wait for the audio playback to end. This function will block until the audio playback is ended.
|
||||
*
|
||||
* @param[in] url URL pointing to the audio playback file to be played
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_playback_play_wait_end(const char *url);
|
||||
|
||||
/**
|
||||
* @brief Pauses the audio playback module
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_playback_pause(void);
|
||||
/**
|
||||
* @brief Resumes the audio playback module
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_playback_resume(void);
|
||||
|
||||
/**
|
||||
* @brief Get the state of the audio playback module
|
||||
*
|
||||
* @return
|
||||
* - enum audio_player_state_e Playback state
|
||||
*/
|
||||
enum audio_player_state_e audio_playback_get_state(void);
|
||||
|
||||
/**
|
||||
* @brief Stop the currently playing audio playback module
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_playback_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Open the audio prompt module
|
||||
* @note This function not provide pause and resume functionality, because the prompt is played to end automatically.
|
||||
* This function's priority is higher than the audio playback and feeder, so when the prompt is playing, the audio playback
|
||||
* and feeder decoded data will be ignored.
|
||||
*
|
||||
* @param[in] config Pointer to the audio prompt configuration structure.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_prompt_open(audio_prompt_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Close the audio prompt module
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_prompt_close(void);
|
||||
|
||||
/**
|
||||
* @brief Play an audio prompt from the specified URL.
|
||||
*
|
||||
* @param[in] url URL pointing to the audio prompt file to be played
|
||||
* @note Audio prompt is not supported mixer, so when play prompt, the audio playback and feeder decoded data will be ignored.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_prompt_play(const char *url);
|
||||
|
||||
/**
|
||||
* @brief Open the audio mixer module
|
||||
*
|
||||
* @note This function must be called after audio_playback_open and audio_feeder_open and the audio_mixer must be enabled
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_processor_mixer_open(void);
|
||||
|
||||
/**
|
||||
* @brief Close the audio mixer module
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t audio_processor_mixer_close(void);
|
||||
|
||||
/**
|
||||
* @brief Control audio focus between FEEDER and PLAYBACK streams
|
||||
*
|
||||
* @note This function controls the fade processors for both feeder and playback streams
|
||||
* to create smooth volume transitions and focus on the desired audio source.
|
||||
*
|
||||
* @param[in] mode The focus control mode:
|
||||
* - AUDIO_FOCUS_FEEDER: Focus on FEEDER stream (boost feeder, reduce playback)
|
||||
* - AUDIO_FOCUS_PLAYBACK: Focus on PLAYBACK stream (boost playback, reduce feeder)
|
||||
* - AUDIO_FOCUS_BALANCED: Balanced mode (both streams at equal levels)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - ESP_ERR_INVALID_ARG Invalid mode parameter
|
||||
* - ESP_ERR_INVALID_STATE Audio render not initialized or streams not available
|
||||
* - ESP_FAIL Failed to control fade processors
|
||||
*/
|
||||
esp_err_t audio_processor_ramp_control(audio_mixer_focus_mode_t mode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO., LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_afe_config.h"
|
||||
|
||||
/**
|
||||
* @brief AV Processor FourCC definition
|
||||
*/
|
||||
#define AV_PROCESSOR_FOURCC(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
|
||||
|
||||
/**
|
||||
* @brief AV Processor format ID definition
|
||||
*
|
||||
* @note Aligned with GMF FourCC definition for audio video codecs and formats
|
||||
* Detailed info refer to `https://github.com/espressif/esp-gmf/blob/main/gmf_core/helpers/include/esp_fourcc.h`
|
||||
*/
|
||||
typedef enum {
|
||||
AV_PROCESSOR_FORMAT_ID_PCM = AV_PROCESSOR_FOURCC('P', 'C', 'M', ' '), /*!< PCM (Uncompressed) encoder */
|
||||
AV_PROCESSOR_FORMAT_ID_G711A = AV_PROCESSOR_FOURCC('A', 'L', 'A', 'U'), /*!< G.711 A-law encoder */
|
||||
AV_PROCESSOR_FORMAT_ID_G711U = AV_PROCESSOR_FOURCC('U', 'L', 'A', 'W'), /*!< G.711 μ-law encoder */
|
||||
AV_PROCESSOR_FORMAT_ID_OPUS = AV_PROCESSOR_FOURCC('O', 'P', 'U', 'S'), /*!< OPUS encoder */
|
||||
AV_PROCESSOR_FORMAT_ID_AAC = AV_PROCESSOR_FOURCC('A', 'A', 'C', ' '), /*!< AAC encoder */
|
||||
} av_processor_format_id_t;
|
||||
|
||||
/**
|
||||
* @brief Audio encoder format type
|
||||
*/
|
||||
typedef enum {
|
||||
AV_PROCESSOR_ENCODER_PCM = 0, /*!< PCM (Uncompressed) encoder */
|
||||
AV_PROCESSOR_ENCODER_G711A, /*!< G.711 A-law encoder */
|
||||
AV_PROCESSOR_ENCODER_G711U, /*!< G.711 μ-law encoder */
|
||||
AV_PROCESSOR_ENCODER_OPUS, /*!< OPUS encoder */
|
||||
AV_PROCESSOR_ENCODER_MAX, /*!< Maximum encoder type */
|
||||
} av_processor_encoder_format_t;
|
||||
|
||||
/**
|
||||
* @brief Audio decoder format type
|
||||
*/
|
||||
typedef enum {
|
||||
AV_PROCESSOR_DECODER_PCM = 0, /*!< PCM (Uncompressed) decoder */
|
||||
AV_PROCESSOR_DECODER_G711A, /*!< G.711 A-law decoder */
|
||||
AV_PROCESSOR_DECODER_G711U, /*!< G.711 μ-law decoder */
|
||||
AV_PROCESSOR_DECODER_OPUS, /*!< OPUS decoder */
|
||||
AV_PROCESSOR_DECODER_AAC, /*!< AAC decoder */
|
||||
AV_PROCESSOR_DECODER_MAX, /*!< Maximum decoder type */
|
||||
} av_processor_decoder_format_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t sample_rate; /*!< Sample rate in Hz (e.g., 8000, 16000, 24000, 32000, 44100, 48000) */
|
||||
uint8_t sample_bits; /*!< Sample bits in bits (e.g., 8, 16, 24, 32) */
|
||||
uint8_t channels; /*!< Number of audio channels (1-4) */
|
||||
int frame_duration; /*!< Frame duration in milliseconds */
|
||||
} av_processor_audio_info_t;
|
||||
|
||||
/**
|
||||
* @brief PCM encoder/decoder configuration
|
||||
*/
|
||||
typedef struct {
|
||||
av_processor_audio_info_t audio_info;
|
||||
} av_processor_pcm_config_t;
|
||||
|
||||
/**
|
||||
* @brief OPUS encoder configuration
|
||||
*/
|
||||
typedef struct {
|
||||
av_processor_audio_info_t audio_info;
|
||||
bool enable_vbr; /*!< Enable Variable Bit Rate (VBR) */
|
||||
int bitrate; /*!< Bitrate in bps */
|
||||
} av_processor_opus_encoder_config_t;
|
||||
|
||||
/**
|
||||
* @brief OPUS decoder configuration
|
||||
*/
|
||||
typedef struct {
|
||||
av_processor_audio_info_t audio_info;
|
||||
} av_processor_opus_decoder_config_t;
|
||||
|
||||
/**
|
||||
* @brief AAC decoder configuration
|
||||
*/
|
||||
typedef struct {
|
||||
av_processor_audio_info_t audio_info;
|
||||
bool no_adts_header; /*!< Set if AAC frame data not contain ADTS header */
|
||||
bool aac_plus_enable; /*!< Set if need AAC-Plus support */
|
||||
} av_processor_aac_decoder_config_t;
|
||||
|
||||
/**
|
||||
* @brief G.711 encoder/decoder configuration
|
||||
*/
|
||||
typedef struct {
|
||||
av_processor_audio_info_t audio_info;
|
||||
} av_processor_g711_config_t;
|
||||
|
||||
typedef struct {
|
||||
av_processor_audio_info_t audio_info;
|
||||
int bitrate; /*!< Bitrate in bps */
|
||||
bool adts_used; /*!< Whether write ADTS header: true - add ADTS header, false - raw aac data only */
|
||||
} av_processor_aac_encoder_config_t;
|
||||
|
||||
/**
|
||||
* @brief Audio encoder configuration structure
|
||||
*
|
||||
* This structure contains the encoder format type and corresponding format-specific parameters.
|
||||
* Only the parameters for the selected format (indicated by format) should be used.
|
||||
*/
|
||||
typedef struct {
|
||||
av_processor_format_id_t format; /*!< Encoder format ID */
|
||||
union {
|
||||
av_processor_pcm_config_t pcm; /*!< PCM encoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_PCM) */
|
||||
av_processor_opus_encoder_config_t opus; /*!< OPUS encoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_OPUS) */
|
||||
av_processor_g711_config_t g711; /*!< G.711 encoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_G711A or AV_PROCESSOR_FORMAT_ID_G711U) */
|
||||
av_processor_aac_encoder_config_t aac; /*!< AAC encoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_AAC) */
|
||||
} params; /*!< Format-specific encoder parameters */
|
||||
} av_processor_encoder_config_t;
|
||||
|
||||
/**
|
||||
* @brief Audio decoder configuration structure
|
||||
*
|
||||
* This structure contains the decoder format type and corresponding format-specific parameters.
|
||||
* Only the parameters for the selected format (indicated by format) should be used.
|
||||
*/
|
||||
typedef struct {
|
||||
av_processor_format_id_t format; /*!< Decoder format ID */
|
||||
union {
|
||||
av_processor_pcm_config_t pcm; /*!< PCM decoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_PCM) */
|
||||
av_processor_opus_decoder_config_t opus; /*!< OPUS decoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_OPUS) */
|
||||
av_processor_g711_config_t g711; /*!< G.711 decoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_G711A or AV_PROCESSOR_FORMAT_ID_G711U) */
|
||||
av_processor_aac_decoder_config_t aac; /*!< AAC decoder configuration (used when format == AV_PROCESSOR_FORMAT_ID_AAC) */
|
||||
} params; /*!< Format-specific decoder parameters */
|
||||
} av_processor_decoder_config_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO., LTD
|
||||
* SPDX-License-Identifier: LicenseRef-Espressif-Modified-MIT
|
||||
*
|
||||
* See LICENSE file for details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include "esp_capture_sink.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_video_dec.h"
|
||||
|
||||
/**
|
||||
* @brief Default maximum number of video paths
|
||||
*/
|
||||
#define DEFAULT_VID_MAX_PATH 2
|
||||
|
||||
/**
|
||||
* @brief Video capture handle type
|
||||
*/
|
||||
typedef void *video_capture_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Video render handle type
|
||||
*/
|
||||
typedef void *video_render_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Video frame structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t *data; /*!< Frame data buffer */
|
||||
size_t size; /*!< Frame data size */
|
||||
} video_frame_t;
|
||||
|
||||
/**
|
||||
* @brief Video render decode callback function type
|
||||
*
|
||||
* @param[in] ctx User context pointer
|
||||
* @param[in] data Decoded frame data
|
||||
* @param[in] size Size of decoded frame data
|
||||
*/
|
||||
typedef void (*video_render_decode_callback_t)(void *ctx, const uint8_t *data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Video capture frame callback function type
|
||||
*
|
||||
* @param[in] ctx User context pointer
|
||||
* @param[in] index Frame index
|
||||
* @param[in] vid_frame Captured video frame
|
||||
*/
|
||||
typedef void (*video_capture_frame_callback_t)(void *ctx, int index, video_frame_t *vid_frame);
|
||||
|
||||
/**
|
||||
* @brief Video render configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
esp_video_dec_cfg_t decode_cfg; /*!< Video decoder configuration */
|
||||
esp_video_codec_resolution_t resolution; /*!< Video resolution */
|
||||
video_render_decode_callback_t decode_cb; /*!< Decode callback function */
|
||||
void *decode_cb_ctx; /*!< Decode callback context */
|
||||
} video_render_config_t;
|
||||
|
||||
/**
|
||||
* @brief Video capture configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
void *camera_config; /*!< Camera configuration */
|
||||
int sink_num; /*!< Number of sinks */
|
||||
esp_capture_sink_cfg_t sink_cfg[DEFAULT_VID_MAX_PATH]; /*!< Sink configurations */
|
||||
video_capture_frame_callback_t capture_frame_cb; /*!< Capture frame callback function */
|
||||
void *capture_frame_cb_ctx; /*!< Capture frame callback context */
|
||||
} video_capture_config_t;
|
||||
|
||||
/**
|
||||
* @brief Opens a video capture session
|
||||
*
|
||||
* @param[in] config Video capture configuration
|
||||
*
|
||||
* @return
|
||||
* - video_capture_handle On success
|
||||
* - NULL On failure
|
||||
*/
|
||||
video_capture_handle_t video_capture_open(video_capture_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Closes a video capture session
|
||||
*
|
||||
* @param[in] handle Video capture handle
|
||||
*/
|
||||
void video_capture_close(video_capture_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Starts video capture
|
||||
*
|
||||
* @param[in] handle Video capture handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t video_capture_start(video_capture_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Stops video capture
|
||||
*
|
||||
* @param[in] handle Video capture handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t video_capture_stop(video_capture_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Opens a video render session
|
||||
*
|
||||
* @param[in] config Video render configuration
|
||||
*
|
||||
* @return
|
||||
* - video_render_handle On success
|
||||
* - NULL On failure
|
||||
*/
|
||||
video_render_handle_t video_render_open(video_render_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Closes a video render session
|
||||
*
|
||||
* @param[in] handle Video render handle
|
||||
*/
|
||||
void video_render_close(video_render_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Starts video rendering
|
||||
*
|
||||
* @param[in] handle Video render handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t video_render_start(video_render_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Stops video rendering
|
||||
*
|
||||
* @param[in] handle Video render handle
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t video_render_stop(video_render_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Feeds a video frame to the render pipeline
|
||||
*
|
||||
* @param[in] handle Video render handle
|
||||
* @param[in] frame Video frame to feed
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK On success
|
||||
* - Other Appropriate esp_err_t error code on failure
|
||||
*/
|
||||
esp_err_t video_render_frame_feed(video_render_handle_t handle, video_frame_t *frame);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
Reference in New Issue
Block a user