mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-26 13:31:00 +00:00
adapter: Implement the Read
trait
This commit is contained in:
parent
bf360ebce8
commit
9158c2c8e1
1 changed files with 22 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
use std::collections::VecDeque;
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
|
||||
use gst;
|
||||
use gst::prelude::*;
|
||||
|
@ -255,6 +256,27 @@ impl Adapter {
|
|||
}
|
||||
}
|
||||
|
||||
impl io::Read for Adapter {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
|
||||
let mut len = self.get_available();
|
||||
|
||||
if buf.len() < len {
|
||||
len = buf.len();
|
||||
}
|
||||
|
||||
if self.size == 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::WouldBlock,
|
||||
format!("Missing data: requesting {} but only got {}.",
|
||||
len, self.size)));
|
||||
}
|
||||
|
||||
Self::copy_data(&self.deque, self.skip, buf, len);
|
||||
self.flush(len);
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue