@@ -339,6 +339,35 @@ static int video_esp32_get_ctrl(const struct device *dev, unsigned int cid, void
339339 return video_get_ctrl (cfg -> source_dev , cid , value );
340340}
341341
342+ static int video_esp32_flush (const struct device * dev , enum video_endpoint_id ep , bool cancel )
343+ {
344+ struct video_esp32_data * data = dev -> data ;
345+ struct video_buffer * vbuf = NULL ;
346+
347+ if (cancel ) {
348+ video_esp32_set_stream (dev , false);
349+ if (data -> active_vbuf ) {
350+ k_fifo_put (& data -> fifo_out , data -> active_vbuf );
351+ data -> active_vbuf = NULL ;
352+ }
353+ while (vbuf = k_fifo_get (& data -> fifo_in , K_NO_WAIT ) != NULL ) {
354+ k_fifo_put (& data -> fifo_out , vbuf );
355+ #ifdef CONFIG_POLL
356+ if (data -> signal_out ) {
357+ k_poll_signal_raise (data -> signal_out , VIDEO_BUF_ABORTED );
358+ }
359+ #endif
360+ }
361+ }
362+ } else {
363+ while (!k_fifo_is_empty (& data -> fifo_in )) {
364+ k_sleep (K_MSEC (1 ));
365+ }
366+ }
367+
368+ return 0 ;
369+ }
370+
342371#ifdef CONFIG_POLL
343372int video_esp32_set_signal (const struct device * dev , enum video_endpoint_id ep ,
344373 struct k_poll_signal * sig )
@@ -401,7 +430,7 @@ static DEVICE_API(video, esp32_driver_api) = {
401430 /* optional callbacks */
402431 .enqueue = video_esp32_enqueue ,
403432 .dequeue = video_esp32_dequeue ,
404- .flush = NULL ,
433+ .flush = video_esp32_flush ,
405434 .set_ctrl = video_esp32_set_ctrl ,
406435 .get_ctrl = video_esp32_get_ctrl ,
407436#ifdef CONFIG_POLL
0 commit comments