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+
6072typedef 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+
531560static 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+
808860int esp_webrtc_start (esp_webrtc_handle_t handle )
809861{
810862 if (handle == NULL ) {
0 commit comments