Skip to content

Update and improve video capture sample #72633

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

Conversation

ngphibang
Copy link
Collaborator

@ngphibang ngphibang commented May 12, 2024

As mt9m114 and ov5640 camera shields have been merged. The sample needs to be updated too.
Some improvements on the video capture sample are also made:

  • Display frames on LCD panel instead of just discarding them
  • Add support for RT1170-evk and video sw generator

This PR is split from #69810 to ease the review process as required by @loicpoulain.
This PR depends on #72434 and #72435

@josuah
Copy link
Collaborator

josuah commented May 12, 2024

Nice to see some complete device-to-device workflow.

This looks fairly similar to this pull request: #71463
Would it make more sense to split the "capture-only" or "capture to display" like this other pull request does?

@ngphibang
Copy link
Collaborator Author

ngphibang commented May 12, 2024

Thanks, I am not aware of the PR you pointed out. BTW, this PR is part of the series #71463 which I did last year and first pushed the complete series on March 5, 2024.

About the "capture-only" vs "captue-to-display", I think

  • It does not make much sense if we only capture frames and discard them. The original video capture sample normally should display the frame, but I think for some reasons, it was not done at that time.
  • This PR itself already allows capture-only or capture to display depending on the availability of the hardwares, so we don't need 2 separate samples, I think.

@josuah
Copy link
Collaborator

josuah commented May 12, 2024

Thank you for explaining, I was curious... The other sample uses LVGL: not the same strategy.

@mmahadevan108
Copy link
Collaborator

Has this been tested on 1064_evk after the updates to the sample?

@ngphibang
Copy link
Collaborator Author

@mmahadevan108 : yes, it's tested on 1064_evk, 1170_evk and evkb.

@kartben
Copy link
Collaborator

kartben commented May 23, 2024

cc @CharlesDias

@ngphibang ngphibang force-pushed the improve_video_capture_sample branch 2 times, most recently from 5789394 to fb3479a Compare May 27, 2024 23:19
@ngphibang
Copy link
Collaborator Author

CI failures are not due to the PR changes.

@ngphibang ngphibang force-pushed the improve_video_capture_sample branch 2 times, most recently from b1c9246 to 1a0d684 Compare June 6, 2024 15:44
@dleach02 dleach02 added this to the v3.7.0 milestone Jun 10, 2024
@ngphibang ngphibang changed the title Improve video capture sample Update and improve video capture sample Jun 11, 2024
@ngphibang ngphibang force-pushed the improve_video_capture_sample branch from 1a0d684 to 643fc82 Compare June 12, 2024 15:57
@ngphibang
Copy link
Collaborator Author

ngphibang commented Jun 12, 2024

  • Updated the documentation to use a display shield for RT1064 because display stuffs WILL be removed from RT1064 EVK by this PR (which should be merged first although there is no direct dependency)

  • Reorganisation of some commits.

@loicpoulain @danieldegrasse Could you revisit this ?

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.

Glad to see all this past work making it all the way to the user-facing samples!

Comment on lines 25 to 27
#ifdef CONFIG_MCUX_ELCDIF_PXP
#define BUFFER_ALIGN 64
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good thing that this introduces alignment requirements: users might try the example and fail because alignment is required by their hardware. This gives a hint that this might need to be investigated.

Maybe some day in the future, alignment could be turned into a Kconfig option, so that each driver can check if the selected alignment value is high enough for their need...

Copy link
Collaborator Author

@ngphibang ngphibang Jun 12, 2024

Choose a reason for hiding this comment

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

yes, it's better with a Kconfig option in case that the hardware (e.g. PxP) really requires buffer alignment to work, and the driver uses it in code. But here, aligment is not mandatory (PxP driver does not use the aligment in code so I don't know how to define and check this Kconfig alignment option in PxP driver) though PxP performance could be improved if the buffer is (64B) aligned.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@josuah : Finally, I found and used the CONFIG_VIDEO_BUFFER_POOL_ALIGN which is available in the video subsystem (it is there but no one uses it :) ). This way, we can avoid platform specific stuffs in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great news! Putting it in the example also brings some context and visibility for it. Two birds one stone.

return 0;
}
#else
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the #else really required? It looks like the device name is a built-time constant, so resolving the name at runtime with device_get_binding() is not required?
I am still unsure about which one to choose in which context.
An alternative would be adding an empty #else block with #error to hint the user about using a chosen block.

Copy link
Collaborator Author

@ngphibang ngphibang Jun 12, 2024

Choose a reason for hiding this comment

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

I think #else is required because if we don't have a real video hardware, the software generator is used, but if we have one, the video hardware is used, not both.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought the software generator could have been selected in the "chosen" block by default, and be modified/overrided by extra provided user app.overlay, or a snippet.

Having the fallback happen inline in the example makes sense too. I understand the rationale now. Thank you!

capabilities.supported_pixel_formats, capabilities.current_pixel_format,
capabilities.current_orientation);

display_set_pixel_format(display_dev, DISPLAY_FORMAT);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the reasoning behind setting the format here? Some displays will likely want to use a different format than the one this sample sets- it is really that we need the camera format and display format to match, right?

I suppose maybe what we need to do is only enable the display if the camera format is RGB565? I suppose we could also enable XRGB888 via the ARGB8888 display format

Copy link
Collaborator Author

@ngphibang ngphibang Jun 12, 2024

Choose a reason for hiding this comment

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

What is the reasoning behind setting the format here? Some displays will likely want to use a different format than the one this sample sets- it is really that we need the camera format and display format to match, right?

Yes, the camera and display formats must match. Normally, it is the (human) user who needs to look at both camera and display default formats (and capabilities) then sets the format. But here, we want the sample work "out-of-the-box", for RT1170 case, the camera output format is XRGB so we need to set the display (we have many displays in the world but here in this sample, it is eLCDIF & rk055hdmi4ma0) to this format.

I suppose maybe what we need to do is only enable the display if the camera format is RGB565?

I think it will be a big pity if we do that. The camera output on RT1170 is XRGB8888 and we cannot have camera frames displayed on LCD just because of the mismatch of the default formats between camera and display ? I know that you want to be generic but the sample supports RT1064 and RT1170 as reference boards, we can always set the display format to match these cases, no ? Also, through this, it will give some hints to people that we could "always" match the camera / display formats for their own camera / display set-up.

I suppose we could also enable XRGB888 via the ARGB8888 display format

Yes, XRGB is more generic than ARGB and we can use both alternatively. But because there is no PIXEL_FORMAT_XRGB_8888 defined in display.h, I used the other.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it will be a big pity if we do that. The camera output on RT1170 is XRGB8888 and we cannot have camera frames displayed on LCD just because of the mismatch of the default formats between camera and display ? I know that you want to be generic but the sample supports RT1064 and RT1170 as reference boards, we can always set the display format to match these cases, no ? Also, through this, it will give some hints to people that we could "always" match the camera / display formats for their own camera / display set-up.

I think I'm missing something here. I guess the PXP will convert the XRGB8888 data to RGB565 for the LCD? Ideally, the display pipeline would report its format at XRGB8888 in this case. From my understanding, the application either requires that the format of the buffer that is output from the video pipeline and input to the display pipeline be the same, or the application converts the buffer to a new format manually.

Copy link
Collaborator Author

@ngphibang ngphibang Jun 12, 2024

Choose a reason for hiding this comment

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

I think I'm missing something here. I guess the PXP will convert the XRGB8888 data to RGB565 for the LCD ?

No, as you can see, the current PxP driver does nothing apart from rotation. It's the eLCDIF itself who can support XRGB format (via this PR which was merged sometimes ago).

From my understanding, the application either requires that the format of the buffer that is output from the video pipeline and input to the display pipeline be the same,

I don't think so, as you can see, display controller (like eLCDIF) can support various formats, so application can set the display format at runtime, it does not require that the camera output format is the same as the default display format. It is the actual situation.

or the application converts the buffer to a new format manually.

Yes, this is another way. Application can use software or hardware like PxP to do so (we are working on a new PxP driver with more features).

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, as you can see, the current PxP driver does nothing apart from rotation. It's the eLCDIF itself who can support XRGB format (via #69250 which was merged sometimes ago).

Sure- sorry, I remembered seeing something for this, but wasn't sure where we added the support.

I don't think so, as you can see, display controller (like eLCDIF) can support various formats, so application can set the display format at runtime, it does not require that the camera output format is the same as the default display format. It is the actual situation.

Yes, I follow that. To be clear, what I am asking for here is the following code:

/* Set display pixel format to match the one in use by the camera */
switch (capabilities.current_pixel_format) {
case VIDEO_PIX_FMT_RGB565:
    display_set_pixel_format(display_dev, PIXEL_FORMAT_BGR_565);
case VIDEO_PIX_FMT_XRGB32:
    display_set_pixel_format(display_dev, PIXEL_FORMAT_ARGB_8888);
default:
    return -ENOTSUP;
}

My understanding is that the Sensor->CSI pipeline on the RT1064 would output VIDEO_PIX_FMT_RGB565 as the current format, and the Sensor->CSI2RX->CSI pipeline on the RT1170 would output VIDEO_PIX_FMT_XRGB32 as the current format. Is that incorrect?

Copy link
Collaborator Author

@ngphibang ngphibang Jun 13, 2024

Choose a reason for hiding this comment

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

Yes, this is definitely more elegant :). Thanks, done. FYI, I also removed BUFFER_ALIGN to avoid platform-specific stuffs as much as possible in the code. I used CONFIG_VIDEO_BUFFER_POOL_ALIGN which is available in the video subsystem.

@ngphibang
Copy link
Collaborator Author

ngphibang commented Jun 13, 2024

CI twister test failure on RT1064 is because the zephyr,display chosen node is left and the node is disabled when display stuffs are already moved to a shield by this PR. I fixed this by this PR

The mt9m114 camera shield is now added. There are also some changes in
the mt9m114 camera driver, e.g. frame rate, default format, capabilities.
Update the sample document and test to reflect these changes.

Signed-off-by: Phi Bang Nguyen <[email protected]>
Run clang-format on the file before making any changes

Signed-off-by: Phi Bang Nguyen <[email protected]>
There are some compatibilty situations where carriage return does not
work (e.g. on Serial Monitor in VSCode). Moreover, keeping the
timestamps logs on the console would help to have an idea about the
frame rate. So, it's better to use line feed instead of carriage return
in this case.

Signed-off-by: Phi Bang Nguyen <[email protected]>
In order to be generic, use a chosen node for camera so that the sample
is not specific to NXP SoCs. Also, always favorite a real video device
unless it is unavailable.

Signed-off-by: Phi Bang Nguyen <[email protected]>
Improve the sample application by displaying the captured frames instead
of just discarding them.

Signed-off-by: Phi Bang Nguyen <[email protected]>
@ngphibang ngphibang force-pushed the improve_video_capture_sample branch from 7655fbe to ba7c780 Compare June 13, 2024 23:00
Add support for i.MX RT1170 EVK

Signed-off-by: Phi Bang Nguyen <[email protected]>
@ngphibang ngphibang force-pushed the improve_video_capture_sample branch from ba7c780 to 7676e4b Compare June 13, 2024 23:07
@ngphibang ngphibang requested a review from danieldegrasse June 13, 2024 23:26
Copy link
Collaborator

@danieldegrasse danieldegrasse left a comment

Choose a reason for hiding this comment

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

One minor nit- otherwise lgtm. Going to approve given the time constraints of the merge window

@@ -37,6 +38,23 @@ static inline int display_setup(const struct device *const display_dev)
capabilities.supported_pixel_formats, capabilities.current_pixel_format,
capabilities.current_orientation);

/* Set display pixel format to match the one in use by the camera */
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change should probably be in the prior commit, right?

Copy link
Collaborator Author

@ngphibang ngphibang Jun 14, 2024

Choose a reason for hiding this comment

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

I thought about this. I think both ways are ok. The previous commit adds support for display for the current supported board RT1064 which actually works without the need of this change because the default format of camera and display on RT1064 already matches. This change is needed essentially when we add support for RT1170 EVK.

@aescolar aescolar merged commit 727f04b into zephyrproject-rtos:main Jun 14, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants