Skip to content

Commit 0ad48d5

Browse files
committed
Merge branch 'feature/use_esp_capture' into 'main'
Use new esp_capture for esp-webrtc-solution See merge request adf/esp-webrtc-solution!41
2 parents a1c59f6 + a98da1e commit 0ad48d5

File tree

84 files changed

+451
-13488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+451
-13488
lines changed

components/av_render/include/av_render.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ int av_render_use_data_pool(av_render_handle_t render, av_render_pool_data_free
229229
*/
230230
int av_render_add_audio_data(av_render_handle_t render, av_render_audio_data_t *audio_data);
231231

232+
/**
233+
* @brief Set audio threshold
234+
*
235+
* @note Audio will not render until reach this threshold
236+
*
237+
* @param[in] render AV render handle
238+
* @param[in] audio_threshold Audio threshold
239+
*
240+
* @return
241+
* - 0 On success
242+
* - Others Fail to set
243+
*/
244+
int av_render_set_audio_threshold(av_render_handle_t render, uint32_t audio_threshold);
245+
232246
/**
233247
* @brief Add video data for AV render
234248
*

components/av_render/render_impl/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## IDF Component Manager Manifest File
22
dependencies:
3-
espressif/esp_codec_dev: "~1.3.4"
3+
espressif/esp_codec_dev: "~1.4"
44
espressif/esp_audio_effects: "~1.1.0"
55
av_render:
66
path: ../

components/av_render/src/av_render.c

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ typedef struct _av_render {
144144

145145
media_lib_event_grp_handle_t event_group;
146146
media_lib_mutex_handle_t api_lock;
147+
uint32_t audio_threshold;
147148
av_render_event_cb event_cb;
148149
void *event_ctx;
149150
av_render_pool_data_free pool_free;
@@ -688,6 +689,21 @@ static int a_render_body(av_render_thread_res_t *res, bool drop)
688689
if (data.size) {
689690
int q_num = 0, q_size = 0;
690691
data_queue_query(res->data_q, &q_num, &q_size);
692+
if (res->paused == false && res->render->audio_threshold) {
693+
if (res->render->a_render_res->audio_rendered == false) {
694+
if (q_size < res->render->audio_threshold) {
695+
data_queue_peek_unlock(res->data_q);
696+
// Wait for data reach threshold
697+
media_lib_thread_sleep(10);
698+
return 0;
699+
}
700+
} else if (q_num < 3) {
701+
res->render->a_render_res->audio_rendered = false;
702+
data_queue_peek_unlock(res->data_q);
703+
media_lib_thread_sleep(10);
704+
return 0;
705+
}
706+
}
691707
audio_drop_before_render(res->render, q_size, &skip);
692708
}
693709
if (drop == false && skip == false && (data.size || data.eos)) {
@@ -714,7 +730,7 @@ static int v_render_body(av_render_thread_res_t *res, bool drop)
714730
if (vdec_res && vdec_res->vid_convert) {
715731
// Do color convert firstly
716732
ret = convert_color(vdec_res->vid_convert,
717-
data.data, data.size,
733+
data.data, data.size,
718734
vdec_res->vid_convert_out, vdec_res->vid_convert_out_size);
719735
data.data = vdec_res->vid_convert_out;
720736
data.size = vdec_res->vid_convert_out_size;
@@ -1086,7 +1102,7 @@ static int av_render_video_frame_reached(av_render_video_frame_t *frame, void *c
10861102
if (vdec_res && vdec_res->vid_convert) {
10871103
// Delay to malloc video convert output size
10881104
int image_size = convert_table_get_image_size(vdec_res->out_fmt,
1089-
v_render->video_frame_info.width,
1105+
v_render->video_frame_info.width,
10901106
v_render->video_frame_info.height);
10911107
uint8_t* vid_cvt_out = media_lib_realloc(vdec_res->vid_convert_out, image_size);
10921108
if (vid_cvt_out == NULL) {
@@ -1578,6 +1594,28 @@ int av_render_add_audio_data(av_render_handle_t h, av_render_audio_data_t *audio
15781594
return ret;
15791595
}
15801596

1597+
int av_render_set_audio_threshold(av_render_handle_t h, uint32_t audio_threshold)
1598+
{
1599+
av_render_t *render = (av_render_t *)h;
1600+
if (render == NULL) {
1601+
return -1;
1602+
}
1603+
media_lib_mutex_lock(render->api_lock, MEDIA_LIB_MAX_LOCK_TIME);
1604+
if (render->cfg.audio_render_fifo_size == 0) {
1605+
ESP_LOGW(TAG, "Not support set audio threshold without render fifo");
1606+
} else {
1607+
uint32_t top_limit = render->cfg.audio_render_fifo_size / 2;
1608+
if (audio_threshold > top_limit) {
1609+
render->audio_threshold = top_limit;
1610+
} else {
1611+
render->audio_threshold = audio_threshold;
1612+
}
1613+
ESP_LOGE(TAG, "Set audio threshold %d", (int)render->audio_threshold);
1614+
}
1615+
media_lib_mutex_unlock(render->api_lock);
1616+
return 0;
1617+
}
1618+
15811619
int av_render_add_video_data(av_render_handle_t h, av_render_video_data_t *video_data)
15821620
{
15831621
av_render_t *render = (av_render_t *)h;

components/codec_board/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v1.0.0
4+
5+
- Upgrade dependency of `esp_codev_dev` to v1.4.0
6+
- Added API `codec_board_parse_all_config` for easy customized board which not in `board_cfg.txt`
7+
- Added API `get_playback/record_i2s_channel` to get low level i2s channel
8+
- Fixed build issues on IDFv6.0
9+
310
## v0.5.5
411

512
- Add board support for `ESP32_S3_KORVO_2L`, `ESP32_S3_EchoEar`, `ATOMS3_ECHO_BASE`

components/codec_board/cfg_parse.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ static int fill_codec_cfg(board_cfg_attr_t *attr, uint8_t codec_dir)
421421
}
422422
attr = attr->next;
423423
}
424-
printf("Codec %d dir %d type:%d\n", codec_section->codec_num, codec_dir, codec_cfg->codec_type);
425424
codec_section->codec_num++;
426425
return 0;
427426
}
@@ -451,7 +450,6 @@ static int fill_sdcard_cfg(board_cfg_attr_t *attr)
451450
}
452451
attr = attr->next;
453452
}
454-
printf("Sdcard clk:%d cmd:%d d0:%d\n", sdcard_cfg->clk, sdcard_cfg->cmd, sdcard_cfg->d0);
455453
codec_section->sdcard_num++;
456454
return 0;
457455
}
@@ -570,15 +568,36 @@ static int parse_cfg(const char *section, int size)
570568
return 0;
571569
}
572570

573-
board_section_t *get_codec_section(const char *codec_type)
571+
board_section_t *parse_codec_section(const char *section)
574572
{
575573
if (codec_section) {
576574
free(codec_section);
577575
}
578576
codec_section = calloc(1, sizeof(board_section_t));
577+
if (codec_section == NULL) {
578+
return NULL;
579+
}
580+
int size = strlen(section);
581+
if (parse_cfg(section, size) != 0) {
582+
free(codec_section);
583+
return NULL;
584+
}
585+
return codec_section;
586+
}
587+
588+
board_section_t *get_codec_section(const char *codec_type)
589+
{
579590
if (codec_type == NULL) {
580591
return NULL;
581592
}
593+
if (codec_section) {
594+
free(codec_section);
595+
}
596+
codec_section = calloc(1, sizeof(board_section_t));
597+
if (codec_section == NULL) {
598+
return NULL;
599+
}
600+
582601
int cfg_size = board_cfg_end - board_cfg_start;
583602
do {
584603
const char *section = get_section_data(board_cfg_start, cfg_size, codec_type);

components/codec_board/codec_board.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
#define TAG "BOARD"
55

66
board_section_t *get_codec_section(const char *codec_type);
7+
board_section_t *parse_codec_section(const char *section);
78

89
static board_section_t *codec;
910

1011
#define RET_ON_NOT_INIT() if (codec == NULL) { \
1112
return -1; \
1213
}
1314

15+
int codec_board_parse_all_config(const char *section)
16+
{
17+
if (codec) {
18+
return 0;
19+
}
20+
codec = parse_codec_section(section);
21+
return codec == NULL ? -1 : 0;
22+
}
23+
1424
void set_codec_board_type(const char *codec_type)
1525
{
1626
if (codec) {

components/codec_board/codec_init.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ typedef struct {
3535
const audio_codec_if_t *in_codec_if;
3636
esp_codec_dev_handle_t play_dev;
3737
esp_codec_dev_handle_t record_dev;
38+
uint8_t play_i2s_port;
39+
uint8_t record_i2s_port;
3840
} codec_res_t;
3941

4042
#define USE_I2C_MASTER
@@ -493,10 +495,10 @@ int init_codec(codec_init_cfg_t *cfg)
493495
codec_res.in_ctrl_if = audio_codec_new_i2c_ctrl(&i2c_cfg);
494496
es7210_codec_cfg_t es7210_cfg = {
495497
.ctrl_if = codec_res.in_ctrl_if,
496-
.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC3,
498+
.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC3,
497499
};
498500
if (cfg->in_use_tdm || (cfg->in_mode == CODEC_I2S_MODE_TDM)) {
499-
es7210_cfg.mic_selected |= ES7120_SEL_MIC2 | ES7120_SEL_MIC4;
501+
es7210_cfg.mic_selected |= ES7210_SEL_MIC2 | ES7210_SEL_MIC4;
500502
}
501503
codec_res.in_codec_if = es7210_codec_new(&es7210_cfg);
502504
} break;
@@ -529,9 +531,11 @@ int init_codec(codec_init_cfg_t *cfg)
529531
}
530532
// Set default volume and gain for play and record
531533
if (codec_res.play_dev) {
534+
codec_res.play_i2s_port = out_cfg.i2s_port;
532535
esp_codec_dev_set_out_vol(codec_res.play_dev, 60.0);
533536
}
534537
if (codec_res.record_dev) {
538+
codec_res.record_i2s_port = in_cfg.i2s_port;
535539
esp_codec_dev_set_in_gain(codec_res.record_dev, 30.0);
536540
}
537541
if ((codec_res.play_dev != NULL) || (codec_res.record_dev != NULL)) {
@@ -546,11 +550,31 @@ esp_codec_dev_handle_t get_playback_handle(void)
546550
return codec_res.play_dev;
547551
}
548552

553+
void *get_playback_i2s_channel(void)
554+
{
555+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
556+
if (codec_res.play_dev) {
557+
return i2s_keep[codec_res.play_i2s_port]->tx_handle;
558+
}
559+
return NULL;
560+
#endif
561+
}
562+
549563
esp_codec_dev_handle_t get_record_handle(void)
550564
{
551565
return codec_res.record_dev;
552566
}
553567

568+
void *get_record_i2s_channel(void)
569+
{
570+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
571+
if (codec_res.record_dev) {
572+
return i2s_keep[codec_res.record_i2s_port]->rx_handle;
573+
}
574+
return NULL;
575+
#endif
576+
}
577+
554578
void deinit_codec(void)
555579
{
556580
if (codec_res.play_dev) {
@@ -688,8 +712,6 @@ int mount_sdcard(void)
688712
#if CONFIG_IDF_TARGET_ESP32P4
689713
sdmmc_get_slot(0, &slot_config);
690714
#endif
691-
692-
printf("use %d %d %d %d\n", cfg.d0, cfg.d1, cfg.d2, cfg.d3);
693715
return esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
694716
#else
695717
return -1;

components/codec_board/idf_component.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## IDF Component Manager Manifest File
2-
version: "0.5.5"
2+
version: "1.0.0"
33
description: Simple ESP32 series codec board realization
44
dependencies:
5-
espressif/esp_codec_dev: "~1.3.4"
5+
espressif/esp_codec_dev: "~1.4"
66
esp_lcd_ek79007:
77
version: "~1.0.2"
88
rules:

components/codec_board/include/codec_board.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,26 @@ typedef struct {
253253
uint8_t camera_num;
254254
} board_section_t;
255255

256+
/**
257+
* @brief Parse board all configurations from string
258+
*
259+
* @note Section string like following:
260+
* "i2c: {sda: 2, scl: 1}
261+
* i2s: {bclk: 40, ws: 39, dout: 41, din: 15, mclk: 42}
262+
* out: {codec: ES8311, pa: 4, use_mclk: 1, pa_gain:6}
263+
* in: {codec: ES7210}
264+
* sdcard: {clk: 16, cmd: 38, d0: 17}
265+
* "
266+
*
267+
* @param[in] section Board section string
268+
*
269+
* @return
270+
* - 0 Parse OK
271+
* - -1 Failed to parse
272+
*
273+
*/
274+
int codec_board_parse_all_config(const char *section);
275+
256276
/**
257277
* @brief Set codec board type
258278
*

components/codec_board/include/codec_init.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ int init_codec(codec_init_cfg_t *cfg);
9797
*/
9898
esp_codec_dev_handle_t get_playback_handle(void);
9999

100+
/**
101+
* @brief Get low-level playback i2s channel handle
102+
*
103+
* @return
104+
* - NULL Fail to get playback i2s channel handle
105+
* - Others Playback i2s channel handle
106+
*/
107+
void *get_playback_i2s_channel(void);
108+
100109
/**
101110
* @brief Get `esp_codec_dev` handle for record
102111
*
@@ -106,6 +115,15 @@ esp_codec_dev_handle_t get_playback_handle(void);
106115
*/
107116
esp_codec_dev_handle_t get_record_handle(void);
108117

118+
/**
119+
* @brief Get low-level record i2s channel handle
120+
*
121+
* @return
122+
* - NULL Fail to get record i2s channel handle
123+
* - Others Record i2s channel handle
124+
*/
125+
void *get_record_i2s_channel(void);
126+
109127
/**
110128
* @brief Get I2C master bus handle by port
111129
*

0 commit comments

Comments
 (0)