Skip to content

driver: video: esp32: add video_flush() callback #86915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

epc-ake
Copy link
Contributor

@epc-ake epc-ake commented Mar 11, 2025

This PR adds the video_flush() callback to the drivers API.

  • If cancel is true, streaming is stopped and all buffers in the input FIFO are moved to the output FIFO.
  • If cancel is false, video_flush() blocks until all enqueued input buffers are filled with incoming data

The application can then call video_dequeue() until no buffers remain enqueued.

uLipe
uLipe previously approved these changes Mar 11, 2025
wmrsouza
wmrsouza previously approved these changes Mar 11, 2025
josuah
josuah previously approved these changes Mar 11, 2025
@epc-ake epc-ake dismissed stale reviews from josuah, wmrsouza, and uLipe via ffe7675 March 12, 2025 07:47
@epc-ake epc-ake force-pushed the feature/video_flush branch 3 times, most recently from 0c58b49 to 86a5d96 Compare March 12, 2025 08:22
Copy link
Collaborator

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some typo, for the rest, LGTM.
Thanks for the edits!

Adding missing `video_flush()` callback to driver.

Signed-off-by: Armin Kessler <[email protected]>
@epc-ake epc-ake force-pushed the feature/video_flush branch from 86a5d96 to b232bf6 Compare March 12, 2025 12:14
@kartben kartben merged commit 4bb5ffd into zephyrproject-rtos:main Mar 13, 2025
21 checks passed

if (cancel) {
if (data->is_streaming) {
video_esp32_set_stream(dev, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to comment a bit late when this is just merged but when video_esp32_flush() is called (by video_stream_stop()), the video_esp32_set_stream() is already called. This is the same error as in video_emul driver which I fixed here.

static inline int video_stream_stop(const struct device *dev)
{
	const struct video_driver_api *api = (const struct video_driver_api *)dev->api;
	int ret;

	if (api->set_stream == NULL) {
		return -ENOSYS;
	}

	ret = api->set_stream(dev, false);
	video_flush(dev, VIDEO_EP_ALL, true);

	return ret;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the driver's flush() does not perform the needed "stop" actions, then the user should always call video_stream_stop() before video_flush()... But as video_stream_stop() already calls video_flush(), that suggests that video_flush() should be deprecated in the long run?

There remain the need to handle bool cancel... In that case, set_stream() would need to be a more generic operation maybe... Like set_stream(START), set_stream(STOP), set_stream(CANCEL) etc.

Maybe this comes as part of the video control framework PR, in which case I'll just wait patiently. :)

Copy link
Collaborator

@ngphibang ngphibang Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the driver's flush() does not perform the needed "stop" actions, then the user should always call video_stream_stop() before video_flush()...

No, here we talk only the case cancel = true that means the flush callback is surely called by video_stream_stop() and in video_stream_stop(), set_stream(false) is already called before calling the flush, so no need to call it again.

Copy link
Collaborator

@ngphibang ngphibang Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a broader scope of discussion about video_flush(), there's my long comment here.

Firstly, I think we need to agree on what to do to "flush" when stopping stream. It then depends on what we agree on what to do to restart. As widely adopted in Linux as a general rule (in my quoted comment), restart is like a new start, user needs to (re-)enqueue buffers. So, when flushing, both fifo_in and fifo_out need to be emptied / cleaned so that everything can be restarted again.

However, current implementation of flush callback in some Zephyr drivers like esp32, csi, sw_generator is just taking all the buffers in the fifo_in and put them to fifo_out. It needs to be rethinked.

Another difficulty is low level drivers (which Zephyr drivers are based on) do it differently, for example, the CSI low level driver puts all the buffers in fifo_out into the fifo_in (contracdictory with what Zephyr driver does) as it expected to be able to restart right away without re-enqueuing buffer (by user).

And Linux does not expose flushing API to driver but does it implicitly in the v4l2 framework ...

So it's a bit complicated. I will try to address this because it is also related to removing the video_endpoint_id in flushing API.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I don't see any usecase / need to force a flush when stream is on-going (cancel = false) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will pursue on this PR if that makes sense...
#87070 (comment)

Thank you for your in-depth answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Video Video subsystem platform: ESP32 Espressif ESP32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants