nihed-cros-libva: convert surface query status to enum
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 20 Oct 2023 16:33:27 +0000 (18:33 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 20 Oct 2023 16:33:27 +0000 (18:33 +0200)
nihed-cros-libva/src/lib.rs
nihed-cros-libva/src/picture.rs
nihed-cros-libva/src/status.rs
nihed-cros-libva/src/surface.rs

index 83b459a5fbb0a83d262ad0bd78ca7c7190f44407..953b57c75da64c1dfd8d8a7b9b8c0c7ed6f666f4 100644 (file)
@@ -29,7 +29,6 @@ pub use bindings::VAImageFormat;
 pub use bindings::VAProfile;
 pub use bindings::VASurfaceAttribType;
 pub use bindings::VASurfaceID;
-pub use bindings::VASurfaceStatus;
 pub use buffer::*;
 pub use config::*;
 pub use context::*;
index adf6a9457ebbd726cfbd0b91f1f05bc69d93a9ae..0d28b517edace6d979468f410464572a9e62f5b5 100644 (file)
@@ -219,7 +219,7 @@ impl Picture<PictureEnd> {
     ///
     /// This call can be used to implement a non-blocking path, wherein a decoder queries the status
     /// of the surface after each decode operation instead of blocking on it.
-    pub fn query_status(&self) -> VAResult<bindings::VASurfaceStatus::Type> {
+    pub fn query_status(&self) -> VAResult<VASurfaceStatus> {
         self.inner.surface.borrow_mut().query_status()
     }
 }
index 0cf3f5b0596767d44812d12e0905ddd53533691b..5dac0bf84765f312d6bb6a56e5d994215294738e 100644 (file)
@@ -132,3 +132,25 @@ impl ConvertStatus for bindings::VAStatus {
         }
     }
 }
+
+/// Surface status.
+#[repr(u32)]
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum VASurfaceStatus {
+    /// Rendering in progress.
+    Rendering = 1,
+    /// Displaying in progress (not safe to render into it).
+    ///
+    /// This status is useful if surface is used as the source of an overlay.
+    Displaying = 2,
+    /// Not being rendered or displayed.
+    Ready = 3,
+    /// Indicate a skipped frame during encode.
+    Skipped = 8,
+}
+
+impl std::fmt::Display for VASurfaceStatus {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        write!(f, "{:?}", self)
+    }
+}
index ddc1f157d3b591bc7091c087baa647fa94f9e9f3..fe1174908439a448627dc5d1d0a8f1ae7f19ca0d 100644 (file)
@@ -111,14 +111,20 @@ impl Surface {
     }
 
     /// Wrapper over `vaQuerySurfaceStatus` to find out any pending ops on the render target.
-    pub fn query_status(&self) -> VAResult<bindings::VASurfaceStatus::Type> {
+    pub fn query_status(&self) -> VAResult<VASurfaceStatus> {
         let mut status: bindings::VASurfaceStatus::Type = 0;
         // Safe because `self` represents a valid VASurface.
         (unsafe {
             bindings::vaQuerySurfaceStatus(self.display.handle(), self.id, &mut status)
         })
         .check()?;
-        Ok(status)
+        match status {
+            bindings::VASurfaceStatus::VASurfaceRendering => Ok(VASurfaceStatus::Rendering),
+            bindings::VASurfaceStatus::VASurfaceDisplaying => Ok(VASurfaceStatus::Displaying),
+            bindings::VASurfaceStatus::VASurfaceReady => Ok(VASurfaceStatus::Ready),
+            bindings::VASurfaceStatus::VASurfaceSkipped => Ok(VASurfaceStatus::Skipped),
+            _ => Err(VAError::Unknown),
+        }
     }
 
     /// Returns the ID of this surface.