[vlc-devel] [RFC Patch v2 1/2] libvlc: Add Rust API for writing modules in rust

Romain Vimont rom1v at videolabs.io
Wed Sep 16 21:46:50 CEST 2020


On Tue, Sep 15, 2020 at 08:04:09PM +0530, Kartik Ohri wrote:
> On Tue, Sep 15, 2020 at 1:54 PM Alexandre Janniaux <ajanni at videolabs.io>
> wrote:
> > > +    pub fn vlc_stream_vaControl(s: *mut stream_t, query: c_int, ...) ->
> > c_int;
> >
> > After checking [1], you probably need the following code instead:
> >
> >     extern "C" {
> >         pub unsafe fn vlc_stream_vaControl(s: *mut stream_t, query: c_int,
> > ap: VaList) -> c_int;
> >     }
> >     pub unsafe fn vlc_stream_Control(s: *mut stream_t, query: c_int, mut
> > args: ...) -> c_int {
> >         vlc_stream_vaControl(s, query, args)
> >     }
> >
> > Otherwise, as far as I understand this document, va_start/va_end might not
> > be called correctly.

I confirm (by calling stream.len() for example):

    ==1868204==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7f6b314acd28 bp 0x7f6b1e058710 sp 0x7f6b1e0585a0 T18)
    ==1868204==The signal is caused by a READ memory access.
    ==1868204==Hint: this fault was caused by a dereference of a high value address (see register values below).  Dissassemble the provided pc to learn which register was used.
        #0 0x7f6b314acd28 in FileControl ../../modules/access/file.c:328
        #1 0x7f6b4c5a4c3a in vlc_stream_vaControl ../../src/input/stream.c:703
        #2 0x7f6b4c4fc775 in AStreamControl ../../src/input/access.c:281
        #3 0x7f6b4c5a4c3a in vlc_stream_vaControl ../../src/input/stream.c:703
        #4 0x7f6b314703a9 in AStreamControl ../../modules/stream_filter/cache_read.c:470
        #5 0x7f6b4c5a4c3a in vlc_stream_vaControl ../../src/input/stream.c:703
        #6 0x7f6b3078b635 in vlccore_rs::stream::Stream::len::h283ec41cb769dee5 (/home/rom/projects/vlc-rust/buildasan/modules/.libs/libcuesheet_plugin.so+0x10635)
        #7 ...

> > I haven't checked in details though, and it needs the
> > #![feature(c_variadic)] attribute.
> >
> > [1]
> > https://github.com/rust-lang/rfcs/blob/26197104b7bb9a5a35db243d639aee6e46d35d75/text/2137-variadic.md
> >
> >
> You are probably right. In that case, the RFC is not yet stabilized so
> should we drop this part till then from the patch ?

With this patch to expose the variadic vlc_stream_Control():
https://mailman.videolan.org/pipermail/vlc-devel/2020-September/137598.html

And calling it from Rust instead of the va_list version, it works:

--------8<-------------------------------------------------------------
diff --git a/src/vlccore-rs/src/stream.rs b/src/vlccore-rs/src/stream.rs
index 0725a8fe6e..8d1b8c297e 100644
--- a/src/vlccore-rs/src/stream.rs
+++ b/src/vlccore-rs/src/stream.rs
@@ -71,7 +71,7 @@ impl Stream {
     pub fn len(&self) -> std::result::Result<u64, Error> {
         let size: u64 = 0;
         const STREAM_GET_SIZE: i32 = 6;
-        let result = unsafe { ffi::vlc_stream_vaControl(self.stream, STREAM_GET_SIZE, &size) };
+        let result = unsafe { ffi::vlc_stream_Control(self.stream, STREAM_GET_SIZE, &size) };
         if result != 0 {
             return Err(Error::new(
                 ErrorKind::Other,
@@ -102,7 +102,7 @@ impl Stream {
         const STREAM_GET_CONTENT_TYPE: i32 = 0;
         let result: *mut c_char = null_mut();
         unsafe {
-            if ffi::vlc_stream_vaControl(self.stream, STREAM_GET_CONTENT_TYPE, result) != 0 {
+            if ffi::vlc_stream_Control(self.stream, STREAM_GET_CONTENT_TYPE, result) != 0 {
                 return None;
             } else if result.is_null() {
                 return None;
diff --git a/src/vlccore-sys/src/stream.rs b/src/vlccore-sys/src/stream.rs
index c9e8d5f0b3..331b6c81b6 100644
--- a/src/vlccore-sys/src/stream.rs
+++ b/src/vlccore-sys/src/stream.rs
@@ -16,7 +16,7 @@ extern "C" {
 
     pub fn vlc_stream_Seek(s: *mut stream_t, offset: u64) -> c_int;
 
-    pub fn vlc_stream_vaControl(s: *mut stream_t, query: c_int, ...) -> c_int;
+    pub fn vlc_stream_Control(s: *mut stream_t, query: c_int, ...) -> c_int;
 
     pub fn vlc_stream_Delete(s: *mut stream_t);
 
--------8<-------------------------------------------------------------

I noticed a problem during testing: src/vlccore-rs and src/vlccore-sys
are not rebuilt when sources are modified. Cargo should probably be
called everytime to check if it must rebuild things.

Regards


More information about the vlc-devel mailing list