mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-20 14:46:24 +00:00
Fill buffer from Rust code
This commit is contained in:
parent
ca18a73253
commit
76a5226f79
2 changed files with 20 additions and 5 deletions
|
@ -5,7 +5,7 @@
|
|||
/* Declarations for Rust code */
|
||||
extern void * filesrc_new (void);
|
||||
extern void filesrc_drop (void * filesrc);
|
||||
extern GstFlowReturn filesrc_fill (void * filesrc);
|
||||
extern GstFlowReturn filesrc_fill (void * filesrc, void * data, size_t data_len);
|
||||
extern void filesrc_set_location (void * filesrc, const char *location);
|
||||
extern char * filesrc_get_location (void * filesrc);
|
||||
extern uint64_t filesrc_get_size (void * filesrc);
|
||||
|
@ -138,8 +138,14 @@ gst_rsfile_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
|||
GstBuffer * buf)
|
||||
{
|
||||
GstRsfileSrc *src = GST_RSFILE_SRC (basesrc);
|
||||
GstMapInfo map;
|
||||
GstFlowReturn ret;
|
||||
|
||||
return filesrc_fill (src->instance);
|
||||
gst_buffer_map (buf, &map, GST_MAP_READWRITE);
|
||||
ret = filesrc_fill (src->instance, map.data, map.size);
|
||||
gst_buffer_unmap (buf, &map);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use libc::{c_char};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ptr;
|
||||
use std::{ptr, mem};
|
||||
use std::u64;
|
||||
use std::slice;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FileSrc {
|
||||
|
@ -72,10 +73,15 @@ pub extern "C" fn filesrc_get_location(ptr: *mut FileSrc) -> *mut c_char {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn filesrc_fill(ptr: *mut FileSrc) -> GstFlowReturn {
|
||||
pub extern "C" fn filesrc_fill(ptr: *mut FileSrc, data_ptr: *mut u8, data_len: usize) -> GstFlowReturn {
|
||||
let filesrc: &mut FileSrc = unsafe { &mut *ptr };
|
||||
|
||||
println!("{:?}", filesrc);
|
||||
let mut data = unsafe { slice::from_raw_parts_mut(data_ptr, data_len) };
|
||||
|
||||
for i in 0..data.len() - 1 {
|
||||
data[i] = 1;
|
||||
}
|
||||
|
||||
return GstFlowReturn::Ok;
|
||||
}
|
||||
|
@ -91,7 +97,10 @@ pub extern "C" fn filesrc_get_size(ptr: *mut FileSrc) -> u64 {
|
|||
pub extern "C" fn filesrc_start(ptr: *mut FileSrc) -> GBoolean {
|
||||
let filesrc: &mut FileSrc = unsafe { &mut *ptr };
|
||||
|
||||
return GBoolean::True;
|
||||
match filesrc.location {
|
||||
None => GBoolean::False,
|
||||
Some(_) => GBoolean::True
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
Loading…
Reference in a new issue