Skip to content

Commit

Permalink
encode() -> PacketProducer
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgesten committed May 1, 2024
1 parent 5ee5afd commit c78bd18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::ptr;

use tracing::Level;


use super::{sys, av_log_set_callback, set_log_level, log_callback, Codec, Error, CodecKind, err_code_to_string, FrameRef, Packet};
use super::sys::AVPixelFormat as PixelFormat;
use super::{av_log_set_callback, err_code_to_string, log_callback, set_log_level};
use super::{sys, Codec, CodecKind, Error, FrameRef, Packet};
use super::{RawFrame, RawPacket};

pub struct Encoder {
Expand Down Expand Up @@ -139,10 +139,7 @@ impl Encoder {
unsafe { Codec::from_ptr(self.codec) }
}

pub fn encode(
&mut self,
frame: &dyn FrameRef,
) -> Result<impl Iterator<Item = Result<Packet, Error>>, Error> {
pub fn encode(&mut self, frame: &dyn FrameRef) -> Result<PacketProducer, Error> {
let pts = self.pts_counter;
self.pts_counter += 1;

Expand All @@ -155,22 +152,20 @@ impl Encoder {
}
}

Ok(EncoderIterator {
Ok(PacketProducer {
enc: self,
pkt: Some(RawPacket::new()),
})
}
}

struct EncoderIterator<'a> {
pub struct PacketProducer<'a> {
enc: &'a mut Encoder,
pkt: Option<RawPacket>,
}

impl<'a> Iterator for EncoderIterator<'a> {
type Item = Result<Packet<'a>, Error>;

fn next(&mut self) -> Option<Self::Item> {
impl<'a> PacketProducer<'a> {
pub fn next<'b>(&'b mut self) -> Option<Result<Packet<'b>, Error>> {
let pkt = self.pkt.as_mut()?;

unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod sys;
use sys::AVPixelFormat as PixelFormat;

mod encoder;
pub use encoder::{Encoder, EncoderConfig, EncoderProfile};
pub use encoder::{Encoder, EncoderConfig, EncoderProfile, PacketProducer};
mod error;
pub use error::Error;

Expand Down

0 comments on commit c78bd18

Please sign in to comment.