Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/esp_webrtc/include/esp_webrtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ typedef struct {
int (*on_channel_open)(esp_peer_data_channel_info_t *ch, void *ctx); /*!< Callback invoked when a data channel is opened */
int (*on_data)(esp_peer_data_frame_t *frame, void *ctx); /*!< Callback invoked when data is received on the channel */
int (*on_channel_close)(esp_peer_data_channel_info_t *ch, void *ctx); /*!< Callback invoked when a data channel is closed */
/**
* @brief Video frame send callback (for frame modification/SEI injection)
* @param[in] frame Video frame information before sending
* @param[in] ctx User context
* @return Modified frame data or NULL to use original
* @note This callback allows intercepting and modifying outgoing video frames
* Return the original frame->data to pass through unchanged
* Return modified data (caller must manage memory) to send modified frame
* Return NULL to drop the frame
*/
uint8_t* (*on_video_send)(esp_peer_video_frame_t* frame, void* ctx); /*!< Callback invoked when a video frame is sent */
} esp_webrtc_peer_cfg_t;

/**
Expand Down
20 changes: 19 additions & 1 deletion components/esp_webrtc/src/esp_webrtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,25 @@ static void _media_send(void *ctx)
.data = video_frame.data,
.size = video_frame.size,
};
esp_peer_send_video(rtc->pc, &video_send_frame);
// Call the video send callback if provided (for SEI injection, etc.)
bool should_send = true;
if (rtc->rtc_cfg.peer_cfg.on_video_send) {
uint8_t *modified_data = rtc->rtc_cfg.peer_cfg.on_video_send(&video_send_frame, rtc->rtc_cfg.peer_cfg.ctx);
if (modified_data == NULL) {
// Callback returned NULL - drop the frame
should_send = false;
} else if (modified_data != video_send_frame.data) {
// Callback returned modified data - create a copy of the frame info
// to avoid modifying the original capture frame
video_send_frame.data = modified_data;
// Size might have changed - callback should update video_send_frame.size if needed
}
// If modified_data == video_send_frame.data, original frame is unchanged
}

if (should_send) {
esp_peer_send_video(rtc->pc, &video_send_frame);
}
}
esp_capture_release_path_frame(rtc->capture_path, &video_frame);
rtc->vid_send_pts = video_frame.pts;
Expand Down