-
Notifications
You must be signed in to change notification settings - Fork 31
Remaining ControlId Methods #62
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
Conversation
Im not sure if implementing ControlType would have larger implications on the library as a whole. I could just make an enum that has no linking to ControlValue to fill the gap but that doesn't feel like a proper solution to me. But maybe I am overthinking this decision |
I realized after reading the docs and looking at the source code for libcamera, that they dont actually line up in some cases. For example controltype in the docs does not list every value in the enum. So that helped clear up some confusion I had. For now I have added in a ControlType enum for the time being, I'm not the biggest fan of this solution but it gets the job done. If anyone has any suggestions I'm open to them |
Once you're done make sure to mark the PR as ready, Id love to check whether this resolves my current issues with the crate |
@Swarkin I've been using this branch for a week now with no issues so far. Let me know if you have issues or if something is missing |
Sorry i had not got to this PR, I will have to give it a proper review as its quite big. Thank you for all the work. I also appreciate the example! |
Could you rebase this on main and implement |
@chemicstry changes have been made, that is definitely a better way of doing it and would have saved me a lot of headache a few weeks ago. I will investigate further in to camera manager in a future PR as I need that stop function for some of my projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this quickly, I just left a few more comments
libcamera/src/control.rs
Outdated
String::new() | ||
} else { | ||
let ptr = libcamera_control_id_vendor(ctrl); | ||
if ptr.is_null() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check for null here, c_str()
should never return a null pointer
libcamera-sys/c_api/controls.cpp
Outdated
return control->enumerators().size(); | ||
} | ||
|
||
const char *libcamera_control_id_enumerator_name(libcamera_control_id_t *control, int32_t value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libcamera_control_id_enumerator_name
and libcamera_control_id_enumerator_value
are never used
libcamera-sys/c_api/controls.cpp
Outdated
} | ||
|
||
size_t libcamera_control_id_enumerators_len(libcamera_control_id_t *ctrl) { | ||
if (!ctrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need null check in C shim when we can ensure this by rust type system without any performance cost. For example it should not be possible to have an invalid control id, because ControlId is enum with fixed values, so ControlId::as_ptr() is never null. Maybe add an assert from the rust side instead?
unsafe { libcamera_control_id_size(self.as_ptr()) } | ||
} | ||
|
||
pub fn enumerators_map(&self) -> HashMap<i32, String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would work better as an iterator, see ControlListRefIterator implementation to iterate a C++ map. Current implementation will cost O(2n log n)
to collect everything into hashmap, because std::advance(it, index)
is O(log n)
for C++ map, which is called for each entry twice. I know that this is not a performance critical path, but I would like it to be consistent inside the repo. A separate convenience function can just .collect()
rust iterator into a HashMap<i32, String>
.
Thanks! |
NOTE
Reasoning
At the moment there is no way to get information about a control's read-write permissions pragmatically or the enumerator data. This allows developers to get this information without needing to know what controls are and are not read/writable.
Disruptions to existing code
There should be no disruptions to existing code as these changes only extend the capabilities of ControlId and do not edit, move or remove functionality
Changes
Examples
Next Steps