Extracts a string attribute from a Media Foundation device
(attr: &IMFActivate, guid: GUID)
| 164 | |
| 165 | /// Extracts a string attribute from a Media Foundation device |
| 166 | unsafe fn get_attribute_string(attr: &IMFActivate, guid: GUID) -> String { |
| 167 | let mut value = MaybeUninit::uninit(); |
| 168 | let mut length = MaybeUninit::uninit(); |
| 169 | |
| 170 | // Attempt to retrieve the string attribute. |
| 171 | if attr |
| 172 | .GetAllocatedString(&guid, value.as_mut_ptr(), length.as_mut_ptr()) |
| 173 | .is_err() |
| 174 | { |
| 175 | return String::new(); |
| 176 | } |
| 177 | |
| 178 | let value = value.assume_init(); |
| 179 | let length = length.assume_init(); |
| 180 | |
| 181 | let result = { |
| 182 | let slice = std::slice::from_raw_parts(value.as_ptr(), length as usize); |
| 183 | String::from_utf16(slice).unwrap_or_else(|_| String::from_utf16_lossy(slice).to_owned()) |
| 184 | }; |
| 185 | |
| 186 | // The memory was allocated by COM and must be freed with CoTaskMemFree. |
| 187 | CoTaskMemFree(Some(value.as_ptr() as *const _)); |
| 188 | |
| 189 | result |
| 190 | } |
| 191 | |
| 192 | /// Opens a camera device and negotiates the video format based on configuration |
| 193 | /// |
no test coverage detected