@@ -339,6 +339,36 @@ 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+ if (data -> is_streaming ) {
349+ video_esp32_set_stream (dev , false);
350+ }
351+ if (data -> active_vbuf ) {
352+ k_fifo_put (& data -> fifo_out , data -> active_vbuf );
353+ data -> active_vbuf = NULL ;
354+ }
355+ while ((vbuf = k_fifo_get (& data -> fifo_in , K_NO_WAIT )) != NULL ) {
356+ k_fifo_put (& data -> fifo_out , vbuf );
357+ #ifdef CONFIG_POLL
358+ if (data -> signal_out ) {
359+ k_poll_signal_raise (data -> signal_out , VIDEO_BUF_ABORTED );
360+ }
361+ #endif
362+ }
363+ } else {
364+ while (!k_fifo_is_empty (& data -> fifo_in )) {
365+ k_sleep (K_MSEC (1 ));
366+ }
367+ }
368+
369+ return 0 ;
370+ }
371+
342372#ifdef CONFIG_POLL
343373int video_esp32_set_signal (const struct device * dev , enum video_endpoint_id ep ,
344374 struct k_poll_signal * sig )
@@ -401,7 +431,7 @@ static DEVICE_API(video, esp32_driver_api) = {
401431 /* optional callbacks */
402432 .enqueue = video_esp32_enqueue ,
403433 .dequeue = video_esp32_dequeue ,
404- .flush = NULL ,
434+ .flush = video_esp32_flush ,
405435 .set_ctrl = video_esp32_set_ctrl ,
406436 .get_ctrl = video_esp32_get_ctrl ,
407437#ifdef CONFIG_POLL
0 commit comments