Repository navigation
Enable metadata with a single click on Windows - #5678
Conversation
576c072 to
a3307ad
Compare
| "software synchronization between different\n" | ||
| "camera streams.\n" | ||
| "It must be explicitly enabled on Windows OS\n"; | ||
| last_progress_time = system_clock::now(); |
There was a problem hiding this comment.
Is draw_progress_bar() called at all? Where is this last_progress_time being used? If not used, is the inheritance from process_notification_model needed? Maybe inherit directly from notification_model?
| enable_dismiss = true; | ||
| update_state = 0; | ||
| pinned = true; | ||
| message = "Frame Metadata is device feature allowing\n" |
|
|
||
| bool operator==(const device_id& a, const device_id& b) | ||
| { | ||
| return (to_lower(a.pid) == to_lower(b.pid) && |
There was a problem hiding this comment.
strcasecmp() would compare just as well without all the extra allocations/transformations
| public: | ||
| static bool parse_device_id(std::string id, device_id* res) | ||
| { | ||
| static const std::regex regex("[\\s\\S]*pid_([0-9a-fA-F]+)&mi_([0-9]+)#[0-9]&([0-9a-fA-F]+)&[\\s\\S]*\\{([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})\\}[\\s\\S]*"); |
There was a problem hiding this comment.
Isn't "[\s\S]" the same as "."? And is not needed at the beginning/end of the regex if we use regex_search() instead of regex_match()?
If we're using a-fA-F, then no need to use to_lower(), and then can pass the string in with 'const &'?
There was a problem hiding this comment.
Isn't "[\s\S]" the same as "."?
Apparently no, I had problems matching special symbols with .*
And is not needed at the beginning/end of the regex if we use regex_search() instead of regex_match()
Make sense, I'll give it a try
If we're using a-fA-F, then no need to use to_lower()
Ultimately, to_lower is only used for comparisons. If we switch all comparisons to strcasecmp as you suggested it may be redundant
There was a problem hiding this comment.
Isn't "[\s\S]" the same as "."?
Apparently no, I had problems matching special symbols with .*
According to this, ". doesn't catch line terminators (like new line) by default" but I don't think that would cover your difficulties. I wonder what kind of special characters...
But OK, keep it at [/s/S] but please comment so the next wise-guy like me won't try to "optimize" :)
| return false; | ||
| } | ||
|
|
||
| static void do_foreach_device(std::vector<device_id> devices, |
| NULL, | ||
| NULL, | ||
| &ftLastWriteTime); | ||
| if (retCode == ERROR_SUCCESS) |
There was a problem hiding this comment.
In case of errors, do we usually LOG_DEBUG() it?
What about the successes? Do we want to debug-log any of this so we can see what happened?
| if (rdid == did) | ||
| { | ||
| std::wstringstream ss; | ||
| ss << ws << "\\" << ke << "\\#GLOBAL\\Device Parameters"; |
There was a problem hiding this comment.
I think you can build the whole key path here instead of building ws ahead of time, so it'll be:
ss << "SYSTEM\\CurrentControlSet\\Control\\DeviceClasses\\{" << guid << "}"
<< "\\" << ke << "\\#GLOBAL\\Device Parameters";
That way it's clearer (and ws doesn't get re-defined inside this block).
| { | ||
| std::wstringstream ss; | ||
| ss << ws << "\\" << ke << "\\#GLOBAL\\Device Parameters"; | ||
| auto s = ss.str(); |
There was a problem hiding this comment.
Isn't this a wstring? Why do we need ws on the next line?
| // Heuristic that determines how many media-pins UVC device is expected to have | ||
| static int number_of_mediapins(std::string pid, std::string mi) | ||
| { | ||
| if (mi == "00") |
There was a problem hiding this comment.
This whole function is very confusing unless you know things by heart.
Isn't there a way to programmatically get all these magic numbers (which could conceivably change in the future)?
If not programmatically, isn't there a header somewhere with constants that will make this both more understandable and easier to maintain?
The way I understand it, "media pins" is the same as the streams that a device sensor exposes?
| std::wstring wcmd(cmd_line.begin(), cmd_line.end()); | ||
| sei.lpParameters = wcmd.c_str(); | ||
|
|
||
| ShellExecuteEx(&sei); // not checking return code - what you are going to do? retry? why? |
There was a problem hiding this comment.
At the very least, I think this should be logged somehow?
| } | ||
|
|
||
| static void do_foreach_device(std::vector<device_id> devices, | ||
| std::function<void(device_id&, std::wstring)> action) |
There was a problem hiding this comment.
It's not clear what the wstring is representing... it's a device path, right? Can we name the argument? There might be an issue with the compiler (it's ambiguous in the standard, so depends on the compiler)...
Maybe name the function 'foreach_device_path'?
The device_id should be passed as 'const &'.
| DWORD MetadataBufferSizeInKB = 5; | ||
| RegSetValueEx(key, metadatakey.c_str(), 0, REG_DWORD, | ||
| (const BYTE*)&MetadataBufferSizeInKB, sizeof(DWORD)); | ||
| // What to do if failed??? |
| // Enable metadata for all connected devices | ||
| virtual void enable_metadata() { } | ||
|
|
||
| static std::string get_command_line_param() { return "--enable_metadata"; } |
There was a problem hiding this comment.
// This is the command-line parameter that gets passed to another process (running as admin) in order to enable metadata -- see WinMain
| virtual bool is_enabled(std::string id) const { return true; } | ||
|
|
||
| // Enable metadata for all connected devices | ||
| virtual void enable_metadata() { } |
There was a problem hiding this comment.
Technically, it could fail, so I'd suggest to return a bool, even if the implementation always "succeeds"
| if (s == rs2::metadata_helper::get_command_line_param()) | ||
| { | ||
| rs2::metadata_helper::instance().enable_metadata(); | ||
| exit(0); |
There was a problem hiding this comment.
Exit 1 on failure (if you change the return value)
| public: | ||
| static metadata_helper& instance(); | ||
|
|
||
| // Check if metadata is enabled using Physical Port ID |
There was a problem hiding this comment.
I think it'd help readability if we gave an example of a port ID string here, and explained is can be retrieved with device::get_info(RS2_CAMERA_INFO_PHYSICAL_PORT)
| std::string product = dev.get_info(RS2_CAMERA_INFO_PRODUCT_LINE); | ||
| std::string id = dev.get_info(RS2_CAMERA_INFO_PHYSICAL_PORT); | ||
| bool has_metadata = rs2::metadata_helper::instance().is_enabled(id) || | ||
| !(product == "D400" || product == "SR300" || product == "L500"); |
There was a problem hiding this comment.
Can we abstract these product names into the metadata_helper class, such that we can simply ask:
auto & metadata = rs2::metadata_helper::instance();
bool has_metadata = metadata.is_enabled( dev );
That way, the product names will be local to the helper class and this information is contained centrally.
…h to not forget to merge
| (LPBYTE)(&MetadataBufferSizeInKB), | ||
| &len); | ||
| &len) != ERROR_SUCCESS) | ||
| rs2::log(RS2_LOG_SEVERITY_DEBUG, "Unable to read metadata registry key!"); |
There was a problem hiding this comment.
Might want to include the key path in the message, otherwise it lacks context and will be repetitive if it happens multiple times
| } | ||
|
|
||
| static void foreach_device_path(const std::vector<device_id>& devices, | ||
| std::function<void(device_id&, /* matched device */ |
There was a problem hiding this comment.
Any special reason device_id is not const?
| { | ||
| try | ||
| { | ||
| DebugBreak(); |
|
|
||
| if (ImGui::IsItemHovered()) | ||
| { | ||
| ImGui::SetTooltip("%s", "You will be prompted to enabled metadata on the device"); |
There was a problem hiding this comment.
"to enable" (there's an extra d in there)
May I suggest:
"Enables metadata on connected devices (you may be prompted for administrator privileges)"
| // (can be retrieved with device::get_info(RS2_CAMERA_INFO_PHYSICAL_PORT)) | ||
| virtual bool is_enabled(std::string id) const { return true; } | ||
|
|
||
| // Enable metadata for all connected devices |
There was a problem hiding this comment.
Please add that it will throw a runtime_error on failure
maloel
left a comment
There was a problem hiding this comment.
Looks good, see comments above
UVC frame metadata on Windows is causing a lot of questions and confusion, adding a single click solution that would be applicable from within the Viewer.
Alternative solution is to download and install Intel-RealSense-D400-Series-Universal-Windows-Platform-UWP-Driver-for-Windows but from our experience a lot of users don't do this.
Related to #5669