14
Hyunjun Ko [email protected] VA-API binding to Rust

VA-API rust-binding (GStreamer Conference 2017)

  • Upload
    igalia

  • View
    79

  • Download
    0

Embed Size (px)

Citation preview

Page 1: VA-API rust-binding (GStreamer Conference 2017)

Hyunjun [email protected]

VA-API bindingto Rust

Page 2: VA-API rust-binding (GStreamer Conference 2017)

Who is Hyunjun Ko (zzoon)

● Working on GStreamer since 2013.

● Regular contributor to Gstreamer VA-API

● Joined Igalia Apr, 2016.

● IRC : zzoon

Page 3: VA-API rust-binding (GStreamer Conference 2017)

GStreamer VA-API, what is it?

● A set of Gstreamer elements● vaapisink, vaapipostproc, vaapiXXXdec,

vaapiXXXenc.

● Uses VA-API software stack(libva) for hardware accelerated video processing

Page 4: VA-API rust-binding (GStreamer Conference 2017)

Rust, why?

● Safety, safety and Safety● Prevent from memory corruption and race

condition.● Doesn’t lose performance.

Page 5: VA-API rust-binding (GStreamer Conference 2017)

VA-API binding to Rust

● Name: libva-rust● https://github.com/zzoon/libva-rust● Produce FFI(Foreign Function Interface) to

libva.● Provide Rust structures and APIs for VADisplay,

VAContext, VASurface, VAImage…● Define Traits for Decoder, Encoder, Renderer..

Page 6: VA-API rust-binding (GStreamer Conference 2017)

What exists?● FFI generated by rust-bindgen 0.20

● Need to be re-generated by the latest one.

● Structures and APIs

pub struct VADisplay { disp: ffi::VADisplay, native_disp: *const VANativeDisplay, ...}

impl VADisplay { pub fn initialize(native_disp: *mut VANativeDisplay) -> Result<VADisplay, ()> pub fn get_profiles(&self) -> Box<Vec<VAProfile>> pub fn get_entrypoints(&self, profile: VAProfile) -> Vec<VAEntrypoint> …}

Page 7: VA-API rust-binding (GStreamer Conference 2017)

What exists?● Structures and APIs

pub struct VAImage { image: ffi::VAImage, } impl VAImage { pub fn new(...) pub fn put_image(&self, va_disp: &VADisplay) pub fn get_buffer(&self, va_disp: &VADisplay) pub fn get_num_planes(&self) pub fn get_offset(&self, idx: usize) pub fn get_stride(&self, idx: usize) }

pub struct VASurface { id: ffi::VASurfaceID, format: c_uint, width: c_uint, height: c_uint, num_surfaces: c_uint,}

Impl VASurface { pub fn new() pub fn put_surface() pub fn derive_image() pub fn sync() ...}

Page 8: VA-API rust-binding (GStreamer Conference 2017)

What exists?● Traits

● VARenderer

● VARendererX11

● Needs more traits for Decoder, Encoder, PostProc..

pub trait VARenderer: Send + 'static { fn open(&mut self) -> Option<u8>; fn close(&mut self) -> Option<u8>; fn set_resolution(&mut self, width: u32, height: u32) -> Option<u8>; fn render(&self, data: &[u8], len: usize) -> Option<u8>;}

impl VARenderer for VARendererX11 { fn open fn close fn set_resolution fn render}

Page 9: VA-API rust-binding (GStreamer Conference 2017)

Implement Gstreamer plugin

● Fork gst-plugin-rs (https://github.com/sdroege/gst-plugin-rs)

● Create new branch ‘vaapi’

● Implements rsvaapisink based on RsBaseSink.

Page 10: VA-API rust-binding (GStreamer Conference 2017)

Implement Gstreamer plugin● Code

extern crate libva_rust;

use libva_rust::va::*;use libva_rust::renderer::*;use libva_rust::renderer_x11::*;

Page 11: VA-API rust-binding (GStreamer Conference 2017)

Implement Gstreamer plugin● Code

impl VAapiSink { pub fn new(_sink: &RsBaseSink) -> VAapiSink {

…. let va_disp = VADisplay::initialize(native_display as *mut VANativeDisplay).unwrap(); let va_renderer = VARendererX11::new(va_disp, 0, 0).unwrap();

VAapiSink { va_renderer: va_renderer,

…. } }}

Page 12: VA-API rust-binding (GStreamer Conference 2017)

Implement Gstreamer plugin

● Code

● Example ● gst-inspect-1.0 rsvaapisink● gst-launch-1.0 videotestsrc ! video/x-

raw,format=NV12 ! rsvaapisink

fn render(&mut self, sink: &RsBaseSink, buffer: &gst::BufferRef) -> Result<(), FlowError> {

let map = match buffer.map_readable() { …

}; let data = map.as_slice();

self.va_renderer.render(&data, data.len());…

}

Page 13: VA-API rust-binding (GStreamer Conference 2017)

Plan

● Make it rusty more!● Implements Decoder/Encoder/VPP● Handle VASurface Memory by Caps● Support to share VADisplay from each element.

Page 14: VA-API rust-binding (GStreamer Conference 2017)

Q & A