• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use std::ffi::CStr;
6 
7 use anyhow::anyhow;
8 use anyhow::Result;
9 
10 use crate::bindings;
11 
12 /// Wrapper over `VAStatus`, calling check() returns a Error if the status is not VA_STATUS_SUCCESS.
13 #[must_use = "VAStatus might not be VA_STATUS_SUCCESS."]
14 pub(crate) struct Status(pub bindings::VAStatus);
15 
16 impl Status {
17     /// Returns `Ok(())` if this status is successful, and an error otherwise.
check(&self) -> Result<()>18     pub(crate) fn check(&self) -> Result<()> {
19         if self.0 == bindings::constants::VA_STATUS_SUCCESS as i32 {
20             Ok(())
21         } else {
22             // Safe because `vaErrorStr` will return a pointer to a statically allocated, null
23             // terminated C string. The pointer is guaranteed to never be null.
24             let err_str = unsafe { CStr::from_ptr(bindings::vaErrorStr(self.0)) }
25                 .to_str()
26                 .unwrap();
27             Err(anyhow!("VA-API error: {}: {}", self.0, err_str))
28         }
29     }
30 }
31