Giter VIP home page Giter VIP logo

cros-libva's People

Contributors

bgrzesik avatar dwlsalmeida avatar gnurou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cros-libva's Issues

Rewrite boilerplate code in `buffer.rs`

Per @bgrzesik on #10:

We could use a private trait in favor of BufferType enum. Something like:

trait BufferElement: Into<Self::RawType> {
    const TYPE: bindings::VABufferType::Type;
    type RawType;

    fn raw_element_size() -> usize {
        std::mem::size_of::<Self::RawType>()
    }
}

Replace tuple structs with strongly typed and documented copy of raw struct. It would have to be converted to raw when added to the picture (or prior vaRenderPicture), but during this step we could clone Rc<>s to dependencies (like surfaces and EncCodedBuffer) to Picture<> so those wouldn't get dropped before sync. It would clean up some cros-codecs code.

Also Picture::add_buffer could accept a trait that would wrap our use cases. Like so:

trait BufferContents {
    const TYPE: bindings::VABufferType::Type;

    fn element_size(&self) -> usize;

    fn num_elements(&self) -> usize;

    unsafe fn data_ptr(&mut self) -> *mut std::ffi::c_void;
}

// Or just use slice somehow
pub struct BufferArray<T>
where
    T: BufferElement,
{
    array: Vec<T::RawType>,
    // ... deps
}

impl<T> BufferContents for BufferArray<T>
where
    T: BufferElement,
{
 // ...
}

impl<T> BufferContents for Box<T> // Or just T
where
    T: BufferElement,
{
 // ...
}

impl BufferContents for SliceData
{
 // ...
}

In this way we could handle buffer arrays and single element buffers transparently.
On top of that we maybe could look into doing some validations.

Thread-safe `cros_libva::Display`

Libva mentions the following:

All VAAPI functions implemented in libva are thread-safe. For any VAAPI function that requires the implementation of a backend (e.g. hardware driver), the backend must ensure that its implementation is also thread-safe. If the backend implementation of a VAAPI function is not thread-safe then this should be considered as a bug against the backend implementation.

It is assumed that none of the VAAPI functions will be called from signal handlers.

Thread-safety in this context means that when VAAPI is being called by multiple concurrent threads, it will not crash or hang the OS, and VAAPI internal data structures will not be corrupted. When multiple threads are operating on the same VAAPI objects, it is the application's responsibility to synchronize these operations in order to generate the expected results. For example, using a single VAContext from multiple threads may generate unexpected results.

I think it's safe to implement Send + Sync for cros_libva::Display, although I haven't yet tested it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.