File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,23 @@ typedef struct {
7979 int (* on_channel_open )(esp_peer_data_channel_info_t * ch , void * ctx ); /*!< Callback invoked when a data channel is opened */
8080 int (* on_data )(esp_peer_data_frame_t * frame , void * ctx ); /*!< Callback invoked when data is received on the channel */
8181 int (* on_channel_close )(esp_peer_data_channel_info_t * ch , void * ctx ); /*!< Callback invoked when a data channel is closed */
82+
83+ /**
84+ * @brief Callback hook for sending video frames (supports modification or SEI injection).
85+ *
86+ * @note This callback is invoked before a video frame is sent, allowing the user to:
87+ * - Send the original video data (leave frame->data unchanged)
88+ * - Send modified video data (update frame->data; user is responsible for managing the new buffer's lifecycle)
89+ * - Drop the frame (do not send)
90+ *
91+ * @param[in] frame Video frame information before sending
92+ * @param[in] ctx User-defined context
93+ *
94+ * @return
95+ * - 0 Proceed with sending (using either original or modified data)
96+ * - Others Drop the frame
97+ */
98+ int (* on_video_send )(esp_peer_video_frame_t * frame , void * ctx );
8299} esp_webrtc_peer_cfg_t ;
83100
84101/**
Original file line number Diff line number Diff line change @@ -145,7 +145,17 @@ static void _media_send(void *ctx)
145145 .data = video_frame .data ,
146146 .size = video_frame .size ,
147147 };
148- esp_peer_send_video (rtc -> pc , & video_send_frame );
148+ // Call the video send callback if provided (for SEI injection, etc.)
149+ bool should_send = true;
150+ if (rtc -> rtc_cfg .peer_cfg .on_video_send ) {
151+ ret = rtc -> rtc_cfg .peer_cfg .on_video_send (& video_send_frame , rtc -> rtc_cfg .peer_cfg .ctx );
152+ if (ret != ESP_CAPTURE_ERR_OK ) {
153+ should_send = false;
154+ }
155+ }
156+ if (should_send ) {
157+ esp_peer_send_video (rtc -> pc , & video_send_frame );
158+ }
149159 }
150160 esp_capture_sink_release_frame (rtc -> capture_path , & video_frame );
151161 rtc -> vid_send_pts = video_frame .pts ;
You can’t perform that action at this time.
0 commit comments