nihed-cros-libva: use simple error enum instead of anyhow crate
[nihav-player.git] / nihed-cros-libva / src / picture.rs
index acb41b8eee01ce1123f103d8935f0ee6eb15857f..adf6a9457ebbd726cfbd0b91f1f05bc69d93a9ae 100644 (file)
@@ -8,14 +8,11 @@ use std::cell::RefMut;
 use std::marker::PhantomData;
 use std::rc::Rc;
 
-use anyhow::anyhow;
-use anyhow::Result;
-
 use crate::bindings;
 use crate::buffer::Buffer;
 use crate::context::Context;
 use crate::display::Display;
-use crate::status::Status;
+use crate::status::*;
 use crate::surface::Surface;
 
 // Use the sealed trait pattern to make sure that new states are not created in caller code. More
@@ -143,10 +140,10 @@ impl Picture<PictureNew> {
     }
 
     /// Wrapper around `vaBeginPicture`.
-    pub fn begin(self) -> Result<Picture<PictureBegin>> {
+    pub fn begin(self) -> VAResult<Picture<PictureBegin>> {
         // Safe because `self.inner.context` represents a valid VAContext and
         // `self.inner.surface` represents a valid VASurface.
-        Status(unsafe {
+        (unsafe {
             bindings::vaBeginPicture(
                 self.inner.context.display().handle(),
                 self.inner.context.id(),
@@ -164,12 +161,12 @@ impl Picture<PictureNew> {
 
 impl Picture<PictureBegin> {
     /// Wrapper around `vaRenderPicture`.
-    pub fn render(self) -> Result<Picture<PictureRender>> {
+    pub fn render(self) -> VAResult<Picture<PictureRender>> {
         // Safe because `self.inner.context` represents a valid `VAContext` and `self.inner.surface`
         // represents a valid `VASurface`. `buffers` point to a Rust struct and the vector length is
         // passed to the C function, so it is impossible to write past the end of the vector's
         // storage by mistake.
-        Status(unsafe {
+        (unsafe {
             bindings::vaRenderPicture(
                 self.inner.context.display().handle(),
                 self.inner.context.id(),
@@ -188,9 +185,9 @@ impl Picture<PictureBegin> {
 
 impl Picture<PictureRender> {
     /// Wrapper around `vaEndPicture`.
-    pub fn end(self) -> Result<Picture<PictureEnd>> {
+    pub fn end(self) -> VAResult<Picture<PictureEnd>> {
         // Safe because `self.inner.context` represents a valid `VAContext`.
-        Status(unsafe {
+        (unsafe {
             bindings::vaEndPicture(
                 self.inner.context.display().handle(),
                 self.inner.context.id(),
@@ -206,7 +203,7 @@ impl Picture<PictureRender> {
 
 impl Picture<PictureEnd> {
     /// Syncs the picture, ensuring that all pending operations are complete when this call returns.
-    pub fn sync(self) -> std::result::Result<Picture<PictureSync>, (anyhow::Error, Self)> {
+    pub fn sync(self) -> std::result::Result<Picture<PictureSync>, (VAError, Self)> {
         let res = self.inner.surface.borrow().sync();
 
         match res {
@@ -222,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) -> Result<bindings::VASurfaceStatus::Type> {
+    pub fn query_status(&self) -> VAResult<bindings::VASurfaceStatus::Type> {
         self.inner.surface.borrow_mut().query_status()
     }
 }
@@ -252,10 +249,10 @@ impl<S: PictureState> Picture<S> {
 impl<S: PictureReclaimableSurface> Picture<S> {
     /// Reclaim ownership of the Surface this picture has been created from, consuming the picture
     /// in the process. Useful if the Surface is part of a pool.
-    pub fn take_surface(self) -> Result<Surface> {
+    pub fn take_surface(self) -> VAResult<Surface> {
         match Rc::try_unwrap(self.inner.surface) {
             Ok(surface) => Ok(surface.into_inner()),
-            Err(_) => Err(anyhow!("Surface still in use")),
+            Err(_) => Err(VAError::SurfaceBusy),
         }
     }