Minor cleanup and make mutability more restricted

This commit is contained in:
Sebastian Dröge 2016-05-15 17:43:13 +03:00
parent e43f247be3
commit 400696fbf8
3 changed files with 16 additions and 16 deletions

View file

@ -62,10 +62,10 @@ impl Sink for FileSink {
} }
fn get_uri(&self) -> Option<String> { fn get_uri(&self) -> Option<String> {
match self.location { self.location.as_ref()
None => None, .map(|l| Url::from_file_path(l).ok())
Some(ref location) => Url::from_file_path(&location).map(|u| u.into_string()).ok() .and_then(|i| i) // join()
} .map(|u| u.into_string())
} }
fn start(&mut self) -> bool { fn start(&mut self) -> bool {
@ -96,7 +96,7 @@ impl Sink for FileSink {
true true
} }
fn render(&mut self, data: &mut [u8]) -> GstFlowReturn { fn render(&mut self, data: &[u8]) -> GstFlowReturn {
match self.file { match self.file {
None => return GstFlowReturn::Error, None => return GstFlowReturn::Error,
Some(ref mut f) => { Some(ref mut f) => {

View file

@ -1,4 +1,4 @@
use libc::{c_char}; use libc::c_char;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::slice; use std::slice;
use std::ptr; use std::ptr;
@ -10,7 +10,7 @@ pub trait Sink {
fn get_uri(&self) -> Option<String>; fn get_uri(&self) -> Option<String>;
fn start(&mut self) -> bool; fn start(&mut self) -> bool;
fn stop(&mut self) -> bool; fn stop(&mut self) -> bool;
fn render(&mut self, data: &mut [u8]) -> GstFlowReturn; fn render(&mut self, data: &[u8]) -> GstFlowReturn;
} }
#[no_mangle] #[no_mangle]
@ -26,8 +26,8 @@ pub extern "C" fn sink_set_uri(ptr: *mut Box<Sink>, uri_ptr: *const c_char) -> G
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn sink_get_uri(ptr: *mut Box<Sink>) -> *mut c_char { pub extern "C" fn sink_get_uri(ptr: *const Box<Sink>) -> *mut c_char {
let source: &mut Box<Sink> = unsafe { &mut *ptr }; let source: &Box<Sink> = unsafe { &*ptr };
match source.get_uri() { match source.get_uri() {
Some(ref uri) => Some(ref uri) =>
@ -38,10 +38,10 @@ pub extern "C" fn sink_get_uri(ptr: *mut Box<Sink>) -> *mut c_char {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn sink_render(ptr: *mut Box<Sink>, data_ptr: *mut u8, data_len: usize) -> GstFlowReturn { pub extern "C" fn sink_render(ptr: *mut Box<Sink>, data_ptr: *const u8, data_len: usize) -> GstFlowReturn {
let source: &mut Box<Sink> = unsafe { &mut *ptr }; let source: &mut Box<Sink> = unsafe { &mut *ptr };
let mut data = unsafe { slice::from_raw_parts_mut(data_ptr, data_len) }; let data = unsafe { slice::from_raw_parts(data_ptr, data_len) };
source.render(data) source.render(data)
} }

View file

@ -1,4 +1,4 @@
use libc::{c_char}; use libc::c_char;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::slice; use std::slice;
use std::ptr; use std::ptr;
@ -63,8 +63,8 @@ pub extern "C" fn source_fill(ptr: *mut Box<Source>, offset: u64, data_ptr: *mut
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn source_get_size(ptr: *mut Box<Source>) -> u64 { pub extern "C" fn source_get_size(ptr: *const Box<Source>) -> u64 {
let source: &mut Box<Source> = unsafe { &mut *ptr }; let source: &Box<Source> = unsafe { & *ptr };
return source.get_size(); return source.get_size();
} }
@ -84,8 +84,8 @@ pub extern "C" fn source_stop(ptr: *mut Box<Source>) -> GBoolean {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn source_is_seekable(ptr: *mut Box<Source>) -> GBoolean { pub extern "C" fn source_is_seekable(ptr: *const Box<Source>) -> GBoolean {
let source: &mut Box<Source> = unsafe { &mut *ptr }; let source: &Box<Source> = unsafe { & *ptr };
GBoolean::from_bool(source.is_seekable()) GBoolean::from_bool(source.is_seekable())
} }