Skip to content
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

[cscore] SourceImpl waits for any new frame #7572

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mcm001
Copy link
Contributor

@mcm001 mcm001 commented Dec 22, 2024

Pipes the frame time we want to wait for a new frame based on up through cscore. This allows more control for Photon over when frames are dropped or awaited.

https://discord.com/channels/176186766946992128/368993897495527424/1320182740330745896 for context

@github-actions github-actions bot added the component: cscore CameraServer library label Dec 22, 2024
@mcm001
Copy link
Contributor Author

mcm001 commented Dec 23, 2024

Pre-patch:
image

With my patch:
image

Perf from main, and patched: (I'm not sure why they are so different)

perf cscore_main
perf cscore_patched

@mcm001
Copy link
Contributor Author

mcm001 commented Dec 23, 2024

CC @PeterJohnson

@ThadHouse
Copy link
Member

I think we’d want this to be a new function. I feel like the determinism of the existing function in the face of running too long is worth having in most cases.

@mcm001 mcm001 force-pushed the cscore-any-new-frame branch from 23279e0 to 18abf66 Compare December 23, 2024 18:15
@mcm001 mcm001 marked this pull request as ready for review December 23, 2024 18:16
@mcm001 mcm001 requested review from a team as code owners December 23, 2024 18:16
targetBuildTypes 'debug'
targetBuildTypes 'release'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revert before merge

@@ -64,9 +73,12 @@ CS_Sink CreateRawSinkCallback(std::string_view name, bool isCv,

void PutSourceFrame(CS_Source source, const WPI_RawFrame& image,
CS_Status* status);
uint64_t GrabSinkFrame(CS_Sink sink, WPI_RawFrame& image, CS_Status* status);

// TODO - default parameters need to go last, is this OK?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO

@mcm001 mcm001 force-pushed the cscore-any-new-frame branch from 4a98816 to f76c92f Compare December 23, 2024 23:01
@mcm001 mcm001 marked this pull request as draft December 24, 2024 00:42
@mcm001
Copy link
Contributor Author

mcm001 commented Dec 24, 2024

I think we’d want this to be a new function

@ThadHouse The old behavior should be the default except where I've modified examples - should I revert those changes?

@mcm001 mcm001 marked this pull request as ready for review December 24, 2024 00:56
@mcm001
Copy link
Contributor Author

mcm001 commented Dec 27, 2024

I've added a basic smoketest for Java. I don't have a full set of requirements so I focused on making sure that major functionality still works. I could see an argument for why a Java test will sufficiently exercise the C++ api too, since the JNI calls into cs::GrabSinkFrame

* use the current time
* @return Frame time, or 0 on error (call GetError() to obtain the error message)
*/
public long grabFrame(Mat image, long lastFrameTime) {
Copy link
Member

Choose a reason for hiding this comment

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

Because of the way this creates potentially confusing overloads (passing long vs double has quite different meaning here), I think we should name the lastFrameTime functions differently rather than overloading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do this pretty easily in Java land - C++ might be harder without introducing some code duplication. Do we want to expose a normal and a last frame time version of every function, or only the ones I actually need?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just the ones you need for now? This probably needs a bigger refactor to avoid duplication than we want to do right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I can make that happen. It'd also be nice to think about how we can avoid having to go from a native RawFrame -> NewDirectByteBuffer -> CvMat from the bytebuffer -> copy the mat into the user-provided one if we're already providing a parallel API, too

Copy link
Member

Choose a reason for hiding this comment

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

We could give the native function a native pointer, size, stride, etc, to copy into, but the problem is how to handle the case when that doesn’t match the image size it has available, and it still makes a copy of course.

The other approach would be allowing zero copy by returning an object pointing to the internal RawFrame native buffer, and calling close() on that object returns the native buffer to the pool. This puts the onus on the user to do so or have a memory leak.

@mcm001 mcm001 force-pushed the cscore-any-new-frame branch from 32a67e4 to 8690aa8 Compare December 28, 2024 18:46
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.

3 participants