libav_ng/avformat/
streams_iter.rs1
2use crate::{avformat::FormatContext, avstream::Stream};
3
4pub struct FormatStreamsIter<'a> {
5 position: usize,
6 count: usize,
7 format_ctx: &'a mut FormatContext,
8}
9
10impl<'a> FormatStreamsIter<'a> {
11 pub fn new(format_ctx: &'a mut FormatContext) -> Self {
12 let count = unsafe { format_ctx.raw().nb_streams } as usize;
13
14 Self {
15 position: 0,
16 count,
17 format_ctx,
18 }
19 }
20}
21
22impl Iterator for FormatStreamsIter<'_> {
23 type Item = Stream;
24
25 fn next(&mut self) -> Option<Self::Item> {
26 if self.position >= self.count {
27 return None;
28 }
29
30 let stream = unsafe { self.format_ctx.raw().streams.add(self.position).read() };
31
32 self.position += 1;
33
34 Some(Stream { _stream: stream })
35 }
36}