Add location property handling

This commit is contained in:
Sebastian Dröge 2016-05-13 18:02:19 +03:00
parent 833148cef6
commit 0b67ffc9c7
4 changed files with 36 additions and 7 deletions

View file

@ -5,6 +5,7 @@ authors = ["Sebastian Dröge <sebastian@centricular.com>"]
build = "build.rs"
[dependencies]
libc = "0.2"
[build-dependencies]
gcc = "0.3"

View file

@ -1,3 +1,5 @@
#![crate_type="dylib"]
extern crate libc;
pub mod rsfilesrc;

View file

@ -4,6 +4,8 @@
extern void * filesrc_new (void);
extern void filesrc_drop (void * filesrc);
extern int filesrc_fill (void * filesrc);
extern void filesrc_set_location (void * filesrc, const gchar *location);
extern gchar * filesrc_get_location (void * filesrc);
GST_DEBUG_CATEGORY_STATIC (gst_rsfile_src_debug);
#define GST_CAT_DEFAULT gst_rsfile_src_debug
@ -89,7 +91,6 @@ gst_rsfile_src_finalize (GObject * object)
GstRsfileSrc *src = GST_RSFILE_SRC (object);
filesrc_drop (src->instance);
g_free (src->location);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -102,9 +103,7 @@ gst_rsfile_src_set_property (GObject * object, guint prop_id,
switch (prop_id) {
case PROP_LOCATION:
if (src->location)
g_free (src->location);
src->location = g_value_dup_string (value);
filesrc_set_location (src->instance, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -120,7 +119,7 @@ gst_rsfile_src_get_property (GObject * object, guint prop_id, GValue * value,
switch (prop_id) {
case PROP_LOCATION:
g_value_set_string (value, src->location);
g_value_take_string (value, filesrc_get_location (src->instance));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);

View file

@ -1,3 +1,7 @@
use libc::{c_char};
use std::ffi::{CStr, CString};
use std::ptr;
#[no_mangle]
pub extern "C" fn filesrc_new() -> *mut FileSrc {
let instance = Box::new(FileSrc::new());
@ -9,12 +13,35 @@ pub extern "C" fn filesrc_drop(ptr: *mut FileSrc) {
unsafe { Box::from_raw(ptr) };
}
#[no_mangle]
pub extern "C" fn filesrc_set_location(ptr: *mut FileSrc, location_ptr: *const c_char) {
let filesrc: &mut FileSrc = unsafe { &mut *ptr };
if location_ptr.is_null() {
filesrc.location = None;
} else {
let location = unsafe { CStr::from_ptr(location_ptr) };
filesrc.location = Some(String::from(location.to_str().unwrap()));
}
}
#[no_mangle]
pub extern "C" fn filesrc_get_location(ptr: *mut FileSrc) -> *mut c_char {
let filesrc: &mut FileSrc = unsafe { &mut *ptr };
match filesrc.location {
Some(ref location) =>
CString::new(location.clone().into_bytes()).unwrap().into_raw(),
None =>
ptr::null_mut()
}
}
#[no_mangle]
pub extern "C" fn filesrc_fill(ptr: *mut FileSrc) {
let filesrc: &mut FileSrc = unsafe { &mut *ptr };
println!("fill");
filesrc.location = Some(String::from("bla"));
println!("fill {:?}", filesrc);
}
#[derive(Debug)]