Skip to content

Commit 71beeca

Browse files
committed
Merge branch 'feature/add_bitrate_support' into 'main'
Update esp_codec_dev version, add bitrate setting support See merge request adf/esp-webrtc-solution!54
2 parents 8151836 + 2f731eb commit 71beeca

File tree

6 files changed

+86
-4
lines changed

6 files changed

+86
-4
lines changed

components/av_render/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ dependencies:
1515
espressif/esp_audio_codec: "~2.3.0"
1616
espressif/esp_video_codec: "~0.5.2"
1717
espressif/esp_audio_effects: "~1.1.0"
18-
espressif/esp_codec_dev: "~1.4"
18+
espressif/esp_codec_dev: "~1.5"
1919
tempotian/media_lib_sal: "~0.9"

components/codec_board/CHANGELOG.md

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

3+
## v1.0.1
4+
5+
- Upgrade dependency of `esp_codev_dev` to v1.5.x
6+
37
## v1.0.0
48

59
- Upgrade dependency of `esp_codev_dev` to v1.4.0

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: "1.0.0"
2+
version: "1.0.1"
33
description: Simple ESP32 series codec board realization
44
dependencies:
5-
espressif/esp_codec_dev: "~1.4"
5+
espressif/esp_codec_dev: "~1.5"
66
esp_lcd_ek79007:
77
version: "~1.0.2"
88
rules:

components/esp_webrtc/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version: 0.9.0
55
dependencies:
66
espressif/nghttp: "~1.65.0"
77
espressif/esp_websocket_client: "~1.4.0"
8-
espressif/esp_codec_dev: "~1.4"
8+
espressif/esp_codec_dev: "~1.5"
99
espressif/esp_capture: "~0.7"
1010
esp_peer:
1111
override_path: ../esp_peer

components/esp_webrtc/include/esp_webrtc.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,32 @@ int esp_webrtc_set_event_handler(esp_webrtc_handle_t rtc_handle, esp_webrtc_even
227227
*/
228228
int esp_webrtc_enable_peer_connection(esp_webrtc_handle_t rtc_handle, bool enable);
229229

230+
/**
231+
* @brief Set audio capture bitrate (specially for audio encoder)
232+
*
233+
* @param[in] rtc_handle WebRTC handle
234+
* @param[in] bitrate Audio bitrate to set
235+
*
236+
* @return
237+
* - ESP_PEER_ERR_NONE On success
238+
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
239+
* - Others Fail to set
240+
*/
241+
int esp_webrtc_set_video_bitrate(esp_webrtc_handle_t rtc_handle, uint32_t bitrate);
242+
243+
/**
244+
* @brief Set video capture bitrate (specially for video encoder)
245+
*
246+
* @param[in] rtc_handle WebRTC handle
247+
* @param[in] bitrate Video bitrate to set
248+
*
249+
* @return
250+
* - ESP_PEER_ERR_NONE On success
251+
* - ESP_PEER_ERR_INVALID_ARG Invalid argument
252+
* - Others Fail to set
253+
*/
254+
int esp_webrtc_set_audio_bitrate(esp_webrtc_handle_t rtc_handle, uint32_t bitrate);
255+
230256
/**
231257
* @brief Start WebRTC
232258
*

components/esp_webrtc/src/esp_webrtc.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@
5757
media_lib_event_group_wait_bits(rtc->wait_event, bit, MEDIA_LIB_MAX_LOCK_TIME); \
5858
media_lib_event_group_clr_bits(rtc->wait_event, bit)
5959

60+
typedef enum {
61+
WEBRTC_PRE_SETTING_MASK_AUDIO_BITRATE = (1 << 0),
62+
WEBRTC_PRE_SETTING_MASK_VIDEO_BITRATE = (1 << 1),
63+
WEBRTC_PRE_SETTING_MASK_ALL = 0xFF,
64+
} webrtc_pre_setting_mask_t;
65+
66+
typedef struct {
67+
uint32_t audio_bitrate;
68+
uint32_t video_bitrate;
69+
uint16_t preset_mask;
70+
} webrtc_pre_setting_t;
71+
6072
typedef struct {
6173
esp_webrtc_cfg_t rtc_cfg;
6274
esp_peer_handle_t pc;
@@ -82,6 +94,7 @@ typedef struct {
8294
bool ice_info_loaded;
8395
bool signaling_connected;
8496
bool no_auto_capture;
97+
webrtc_pre_setting_t pre_setting;
8598

8699
uint8_t *aud_fifo;
87100
uint32_t aud_fifo_size;
@@ -528,6 +541,22 @@ static int pc_on_channel_close(esp_peer_data_channel_info_t *ch, void *ctx)
528541
return 0;
529542
}
530543

544+
static int pc_apply_capture_pre_setting(webrtc_t *rtc, uint16_t set_mask)
545+
{
546+
if (rtc->capture_path == NULL) {
547+
return ESP_PEER_ERR_NONE;
548+
}
549+
int ret = ESP_PEER_ERR_NONE;
550+
// TODO we not clear in case stop and start again can use pre-setting also
551+
if (rtc->pre_setting.preset_mask & (set_mask & WEBRTC_PRE_SETTING_MASK_AUDIO_BITRATE)) {
552+
ret |= esp_capture_sink_set_bitrate(rtc->capture_path, ESP_CAPTURE_STREAM_TYPE_AUDIO, rtc->pre_setting.audio_bitrate);
553+
}
554+
if (rtc->pre_setting.preset_mask & (set_mask & WEBRTC_PRE_SETTING_MASK_VIDEO_BITRATE)) {
555+
ret |= esp_capture_sink_set_bitrate(rtc->capture_path, ESP_CAPTURE_STREAM_TYPE_VIDEO, rtc->pre_setting.video_bitrate);
556+
}
557+
return ret;
558+
}
559+
531560
static int pc_start(webrtc_t *rtc, esp_peer_ice_server_cfg_t *server_info, int server_num)
532561
{
533562
if (rtc->pc) {
@@ -597,6 +626,7 @@ static int pc_start(webrtc_t *rtc, esp_peer_ice_server_cfg_t *server_info, int s
597626
sink_cfg.video_info.format_id = ESP_CAPTURE_FMT_ID_NONE;
598627
}
599628
esp_capture_sink_setup(rtc->media_provider.capture, 0, &sink_cfg, &rtc->capture_path);
629+
pc_apply_capture_pre_setting(rtc, WEBRTC_PRE_SETTING_MASK_ALL);
600630
esp_capture_sink_enable(rtc->capture_path, ESP_CAPTURE_RUN_MODE_ALWAYS);
601631
return ret;
602632
}
@@ -805,6 +835,28 @@ int esp_webrtc_set_no_auto_capture(esp_webrtc_handle_t handle, bool no_auto_capt
805835
return ESP_PEER_ERR_NONE;
806836
}
807837

838+
int esp_webrtc_set_audio_bitrate(esp_webrtc_handle_t rtc_handle, uint32_t bitrate)
839+
{
840+
if (rtc_handle == NULL) {
841+
return ESP_PEER_ERR_INVALID_ARG;
842+
}
843+
webrtc_t *rtc = (webrtc_t *)rtc_handle;
844+
rtc->pre_setting.audio_bitrate = bitrate;
845+
rtc->pre_setting.preset_mask |= WEBRTC_PRE_SETTING_MASK_AUDIO_BITRATE;
846+
return pc_apply_capture_pre_setting(rtc, WEBRTC_PRE_SETTING_MASK_AUDIO_BITRATE);
847+
}
848+
849+
int esp_webrtc_set_video_bitrate(esp_webrtc_handle_t rtc_handle, uint32_t bitrate)
850+
{
851+
if (rtc_handle == NULL) {
852+
return ESP_PEER_ERR_INVALID_ARG;
853+
}
854+
webrtc_t *rtc = (webrtc_t *)rtc_handle;
855+
rtc->pre_setting.video_bitrate = bitrate;
856+
rtc->pre_setting.preset_mask |= WEBRTC_PRE_SETTING_MASK_VIDEO_BITRATE;
857+
return pc_apply_capture_pre_setting(rtc, WEBRTC_PRE_SETTING_MASK_VIDEO_BITRATE);
858+
}
859+
808860
int esp_webrtc_start(esp_webrtc_handle_t handle)
809861
{
810862
if (handle == NULL) {

0 commit comments

Comments
 (0)