Initial file reading without error handling, etc

This commit is contained in:
Sebastian Dröge 2016-05-13 19:04:10 +03:00
parent 8f3d49be31
commit 99070d0a9f

View file

@ -3,6 +3,9 @@ use std::ffi::{CStr, CString};
use std::ptr; use std::ptr;
use std::u64; use std::u64;
use std::slice; use std::slice;
use std::io::Read;
use std::fs::File;
use std::path::Path;
#[repr(C)] #[repr(C)]
pub enum GstFlowReturn { pub enum GstFlowReturn {
@ -32,11 +35,12 @@ impl GBoolean {
#[derive(Debug)] #[derive(Debug)]
pub struct FileSrc { pub struct FileSrc {
location: Option<String>, location: Option<String>,
file: Option<File>,
} }
impl FileSrc { impl FileSrc {
fn new() -> FileSrc { fn new() -> FileSrc {
FileSrc { location: None } FileSrc { location: None, file: None }
} }
fn set_location(&mut self, location: &Option<String>) { fn set_location(&mut self, location: &Option<String>) {
@ -56,22 +60,28 @@ impl FileSrc {
} }
fn start(&mut self) -> bool { fn start(&mut self) -> bool {
match self.location { if self.location.is_none() { return false; }
None => false,
Some(_) => true self.file = Some(File::open(Path::new(&self.location.clone().unwrap())).unwrap());
}
return true;
} }
fn stop(&mut self) -> bool { fn stop(&mut self) -> bool {
self.file = None;
true true
} }
fn fill(&mut self, data: &mut [u8]) -> GstFlowReturn { fn fill(&mut self, data: &mut [u8]) -> GstFlowReturn {
for i in 0..data.len() - 1 { match self.file {
data[i] = 1; None => return GstFlowReturn::Error,
Some(ref mut f) => {
// FIXME: Need to return the actual size, handle EOF, etc
f.read(data);
return GstFlowReturn::Ok;
},
} }
return GstFlowReturn::Ok;
} }
} }