Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use std::rc::Rc;
use std::sync::Arc;

use log::error;
use thiserror::Error;
Expand All @@ -16,7 +16,7 @@ use crate::VaError;

/// A configuration for a given [`Display`].
pub struct Config {
display: Rc<Display>,
display: Arc<Display>,
id: bindings::VAConfigID,
}

Expand All @@ -32,7 +32,7 @@ impl Config {
/// Creates a Config by wrapping around the `vaCreateConfig` call. This is just a helper for
/// [`Display::create_config`].
pub(crate) fn new(
display: Rc<Display>,
display: Arc<Display>,
mut attrs: Vec<bindings::VAConfigAttrib>,
profile: bindings::VAProfile::Type,
entrypoint: bindings::VAEntrypoint::Type,
Expand Down
7 changes: 4 additions & 3 deletions lib/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

use std::rc::Rc;
use std::sync::Arc;

use log::error;

Expand All @@ -19,15 +20,15 @@ use crate::VaError;

/// A VA context for a particular [`Display`].
pub struct Context {
display: Rc<Display>,
display: Arc<Display>,
id: bindings::VAContextID,
}

impl Context {
/// Creates a Context by wrapping around a `vaCreateContext` call. This is just a helper for
/// [`Display::create_context`].
pub(crate) fn new<D: SurfaceMemoryDescriptor>(
display: Rc<Display>,
display: Arc<Display>,
config: &Config,
coded_width: u32,
coded_height: u32,
Expand Down Expand Up @@ -69,7 +70,7 @@ impl Context {
}

/// Returns a shared reference to the [`Display`] used by this context.
pub fn display(&self) -> &Rc<Display> {
pub fn display(&self) -> &Arc<Display> {
&self.display
}

Expand Down
24 changes: 15 additions & 9 deletions lib/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::os::unix::io::AsRawFd;
use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;

use thiserror::Error;

Expand Down Expand Up @@ -92,7 +93,7 @@ impl Display {
/// Opens and initializes a specific DRM `Display`.
///
/// `path` is the path to a DRM device that supports VAAPI, e.g. `/dev/dri/renderD128`.
pub fn open_drm_display<P: AsRef<Path>>(path: P) -> Result<Rc<Self>, OpenDrmDisplayError> {
pub fn open_drm_display<P: AsRef<Path>>(path: P) -> Result<Arc<Self>, OpenDrmDisplayError> {
let file = std::fs::File::options()
.read(true)
.write(true)
Expand All @@ -112,7 +113,7 @@ impl Display {
// vaInitialize. The File will close the DRM fd on drop.
va_check(unsafe { bindings::vaInitialize(display, &mut major, &mut minor) })
.map(|()| {
Rc::new(Self {
Arc::new(Self {
handle: display,
drm_file: file,
})
Expand All @@ -124,7 +125,7 @@ impl Display {
///
/// If an error occurs on a given device, it is ignored and the next one is tried until one
/// succeeds or we reach the end of the iterator.
pub fn open() -> Option<Rc<Self>> {
pub fn open() -> Option<Arc<Self>> {
let devices = DrmDeviceIterator::default();

// Try all the DRM devices until one succeeds.
Expand Down Expand Up @@ -263,7 +264,7 @@ impl Display {
/// case of error the `descriptors` will be destroyed. Make sure to duplicate the descriptors
/// if you need something outside of libva to access them.
pub fn create_surfaces<D: SurfaceMemoryDescriptor>(
self: &Rc<Self>,
self: &Arc<Self>,
rt_format: u32,
va_fourcc: Option<u32>,
width: u32,
Expand All @@ -272,7 +273,7 @@ impl Display {
descriptors: Vec<D>,
) -> Result<Vec<Surface<D>>, VaError> {
Surface::new(
Rc::clone(self),
Arc::clone(self),
rt_format,
va_fourcc,
width,
Expand All @@ -292,15 +293,15 @@ impl Display {
/// * `surfaces` - Optional hint for the amount of surfaces tied to the context
/// * `progressive` - Whether only progressive frame pictures are present in the sequence
pub fn create_context<D: SurfaceMemoryDescriptor>(
self: &Rc<Self>,
self: &Arc<Self>,
config: &Config,
coded_width: u32,
coded_height: u32,
surfaces: Option<&Vec<Surface<D>>>,
progressive: bool,
) -> Result<Rc<Context>, VaError> {
Context::new(
Rc::clone(self),
Arc::clone(self),
config,
coded_width,
coded_height,
Expand All @@ -316,12 +317,12 @@ impl Display {
/// [`Display::get_config_attributes`]. Other attributes will take their default values, and
/// `attrs` can be empty in order to obtain a default configuration.
pub fn create_config(
self: &Rc<Self>,
self: &Arc<Self>,
attrs: Vec<bindings::VAConfigAttrib>,
profile: bindings::VAProfile::Type,
entrypoint: bindings::VAEntrypoint::Type,
) -> Result<Config, VaError> {
Config::new(Rc::clone(self), attrs, profile, entrypoint)
Config::new(Arc::clone(self), attrs, profile, entrypoint)
}

/// Returns available image formats for this display by wrapping around `vaQueryImageFormats`.
Expand Down Expand Up @@ -360,3 +361,8 @@ impl Drop for Display {
}
}
}

// Safe because because it only contains a `File` (which is Send+Sync), and a VADisplay handle
// which is also thread-safe. The Drop handler can also be safely called from any thread.
unsafe impl Send for Display {}
unsafe impl Sync for Display {}
6 changes: 3 additions & 3 deletions lib/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use std::rc::Rc;
use std::sync::Arc;

use crate::bindings;
use crate::va_check;
Expand All @@ -17,7 +17,7 @@ use crate::VaError;
/// client memory to a surface.
pub struct Image<'a> {
/// The display from which the image was created, so we can unmap it upon destruction.
display: Rc<Display>,
display: Arc<Display>,
/// The `VAImage` returned by libva.
image: bindings::VAImage,
/// The mapped surface data.
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'a> Image<'a> {
let data =
unsafe { std::slice::from_raw_parts_mut(addr as _, image.data_size as usize) };
Ok(Image {
display: Rc::clone(surface.display()),
display: Arc::clone(surface.display()),
image,
data,
derived,
Expand Down
10 changes: 5 additions & 5 deletions lib/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::any::Any;
use std::os::fd::FromRawFd;
use std::os::fd::OwnedFd;
use std::os::raw::c_void;
use std::rc::Rc;
use std::sync::Arc;

use crate::bindings;
use crate::display::Display;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct SurfaceDecodeMBError {

/// An owned VA surface that is tied to a particular `Display`.
pub struct Surface<D: SurfaceMemoryDescriptor> {
display: Rc<Display>,
display: Arc<Display>,
id: bindings::VASurfaceID,
descriptor: D,
width: u32,
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<D: SurfaceMemoryDescriptor> Surface<D> {
/// Create `Surfaces` by wrapping around a `vaCreateSurfaces` call. This is just a helper for
/// [`Display::create_surfaces`].
pub(crate) fn new(
display: Rc<Display>,
display: Arc<Display>,
rt_format: u32,
va_fourcc: Option<u32>,
width: u32,
Expand Down Expand Up @@ -239,7 +239,7 @@ impl<D: SurfaceMemoryDescriptor> Surface<D> {
)
}) {
Ok(()) => surfaces.push(Self {
display: Rc::clone(&display),
display: Arc::clone(&display),
id: surface_id,
descriptor,
width,
Expand All @@ -252,7 +252,7 @@ impl<D: SurfaceMemoryDescriptor> Surface<D> {
Ok(surfaces)
}

pub(crate) fn display(&self) -> &Rc<Display> {
pub(crate) fn display(&self) -> &Arc<Display> {
&self.display
}

Expand Down