Skip to content

Commit af9f952

Browse files
committed
Add pending frame flag to Stream::next
1 parent 6ef8ead commit af9f952

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/io/dmabuf/stream.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ impl<'a> Stream where Self: CaptureStream<'a> {
132132
let meta = self.buf_meta[index];
133133
Ok((buf, meta))
134134
}
135+
136+
/// Waits for a buffer to be ready
137+
pub fn wait(&self) -> Result<(), io::Error>{
138+
if self.handle.poll(libc::POLLIN, -1)? == 0 {
139+
// This condition can only happen if there was a timeout.
140+
// A timeout is only possible if the `timeout` value is non-zero, meaning we should
141+
// propagate it to the caller.
142+
return Err(io::Error::new(io::ErrorKind::TimedOut, "Blocking poll"));
143+
}
144+
Ok(())
145+
}
146+
147+
/// Waits for a buffer to be ready
148+
pub fn is_ready(&self) -> Result<bool, io::Error>{
149+
Ok(self.handle.poll(libc::POLLIN, 0)? > 0)
150+
}
135151
}
136152

137153
impl Drop for Stream {
@@ -236,7 +252,7 @@ impl<'a> CaptureStream<'a> for Stream {
236252
Ok(self.arena_index)
237253
}
238254

239-
fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata)> {
255+
fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata, bool)> {
240256
if !self.active {
241257
// Enqueue all buffers once on stream start
242258
for index in 0..self.arena.bufs.len() {
@@ -254,6 +270,6 @@ impl<'a> CaptureStream<'a> for Stream {
254270
// will always be valid.
255271
let bytes = &mut self.arena.bufs[self.arena_index].as_ref().unwrap();
256272
let meta = &self.buf_meta[self.arena_index];
257-
Ok((bytes, meta))
273+
Ok((bytes, meta, self.is_ready()?))
258274
}
259275
}

src/io/mmap/stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'b> CaptureStream<'b> for Stream<'a> {
187187
Ok(self.arena_index)
188188
}
189189

190-
fn next(&'b mut self) -> io::Result<(&Self::Item, &Metadata)> {
190+
fn next(&'b mut self) -> io::Result<(&Self::Item, &Metadata, bool)> {
191191
if !self.active {
192192
// Enqueue all buffers once on stream start
193193
for index in 0..self.arena.bufs.len() {
@@ -205,7 +205,7 @@ impl<'a, 'b> CaptureStream<'b> for Stream<'a> {
205205
// will always be valid.
206206
let bytes = &self.arena.bufs[self.arena_index];
207207
let meta = &self.buf_meta[self.arena_index];
208-
Ok((bytes, meta))
208+
Ok((bytes, meta, false))
209209
}
210210
}
211211

src/io/traits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ pub trait CaptureStream<'a>: Stream {
2222

2323
/// Fetch a new frame by first queueing and then dequeueing.
2424
/// First time initialization is performed if necessary.
25-
fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata)>;
25+
/// The last item in the tuple is True if another frame is pending.
26+
fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata, bool)>;
2627
}
2728

2829
pub trait OutputStream<'a>: Stream {

src/io/userptr/stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'a> CaptureStream<'a> for Stream {
191191
Ok(self.arena_index)
192192
}
193193

194-
fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata)> {
194+
fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata, bool)> {
195195
if !self.active {
196196
// Enqueue all buffers once on stream start
197197
for index in 0..self.arena.bufs.len() {
@@ -209,6 +209,6 @@ impl<'a> CaptureStream<'a> for Stream {
209209
// will always be valid.
210210
let bytes = &mut self.arena.bufs[self.arena_index];
211211
let meta = &self.buf_meta[self.arena_index];
212-
Ok((bytes, meta))
212+
Ok((bytes, meta, false))
213213
}
214214
}

0 commit comments

Comments
 (0)