Commit 400696fb authored by Sebastian Dröge's avatar Sebastian Dröge 🍵
Browse files

Minor cleanup and make mutability more restricted

parent e43f247b
......@@ -62,10 +62,10 @@ impl Sink for FileSink {
}
fn get_uri(&self) -> Option<String> {
match self.location {
None => None,
Some(ref location) => Url::from_file_path(&location).map(|u| u.into_string()).ok()
}
self.location.as_ref()
.map(|l| Url::from_file_path(l).ok())
.and_then(|i| i) // join()
.map(|u| u.into_string())
}
fn start(&mut self) -> bool {
......@@ -96,7 +96,7 @@ impl Sink for FileSink {
true
}
fn render(&mut self, data: &mut [u8]) -> GstFlowReturn {
fn render(&mut self, data: &[u8]) -> GstFlowReturn {
match self.file {
None => return GstFlowReturn::Error,
Some(ref mut f) => {
......
use libc::{c_char};
use libc::c_char;
use std::ffi::{CStr, CString};
use std::slice;
use std::ptr;
......@@ -10,7 +10,7 @@ pub trait Sink {
fn get_uri(&self) -> Option<String>;
fn start(&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]
......@@ -26,8 +26,8 @@ pub extern "C" fn sink_set_uri(ptr: *mut Box<Sink>, uri_ptr: *const c_char) -> G
}
#[no_mangle]
pub extern "C" fn sink_get_uri(ptr: *mut Box<Sink>) -> *mut c_char {
let source: &mut Box<Sink> = unsafe { &mut *ptr };
pub extern "C" fn sink_get_uri(ptr: *const Box<Sink>) -> *mut c_char {
let source: &Box<Sink> = unsafe { &*ptr };
match source.get_uri() {
Some(ref uri) =>
......@@ -38,10 +38,10 @@ pub extern "C" fn sink_get_uri(ptr: *mut Box<Sink>) -> *mut c_char {
}
#[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 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)
}
......
use libc::{c_char};
use libc::c_char;
use std::ffi::{CStr, CString};
use std::slice;
use std::ptr;
......@@ -63,8 +63,8 @@ pub extern "C" fn source_fill(ptr: *mut Box<Source>, offset: u64, data_ptr: *mut
}
#[no_mangle]
pub extern "C" fn source_get_size(ptr: *mut Box<Source>) -> u64 {
let source: &mut Box<Source> = unsafe { &mut *ptr };
pub extern "C" fn source_get_size(ptr: *const Box<Source>) -> u64 {
let source: &Box<Source> = unsafe { & *ptr };
return source.get_size();
}
......@@ -84,8 +84,8 @@ pub extern "C" fn source_stop(ptr: *mut Box<Source>) -> GBoolean {
}
#[no_mangle]
pub extern "C" fn source_is_seekable(ptr: *mut Box<Source>) -> GBoolean {
let source: &mut Box<Source> = unsafe { &mut *ptr };
pub extern "C" fn source_is_seekable(ptr: *const Box<Source>) -> GBoolean {
let source: &Box<Source> = unsafe { & *ptr };
GBoolean::from_bool(source.is_seekable())
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment