mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 00:26:31 +00:00
Implement std::io::Read on Adapter
Patch based on the one from Thibault Saunier for gst-plugin-rs's Adapter
This commit is contained in:
parent
95204c2294
commit
2f7ee30aa1
1 changed files with 26 additions and 0 deletions
|
@ -10,6 +10,7 @@ use ffi;
|
|||
use glib::translate::*;
|
||||
use gst;
|
||||
use Adapter;
|
||||
use std::io;
|
||||
|
||||
impl Adapter {
|
||||
pub fn copy(&self, offset: usize, dest: &mut [u8]) {
|
||||
|
@ -30,3 +31,28 @@ impl Adapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Read for Adapter {
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
|
||||
let mut len = self.available();
|
||||
|
||||
if len == 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::WouldBlock,
|
||||
format!(
|
||||
"Missing data: requesting {} but only got {}.",
|
||||
buf.len(),
|
||||
len
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
if buf.len() < len {
|
||||
len = buf.len();
|
||||
}
|
||||
|
||||
self.copy(0, &mut buf[0..len]);
|
||||
self.flush(len);
|
||||
Ok(len)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue