--- src/encoder.rs +++ src/encoder.rs @@ -2,7 +2,7 @@ use std::ptr; use crate::capture::Frame; +use crate::ring::Packet; pub struct VaapiEncoder { codec_ctx: *mut AVCodecContext, @@ -62,6 +62,10 @@ } } - pub fn encode_frame(&mut self, frame: &Frame) -> Result<(), String> { + pub fn codec_ctx(&self) -> *mut AVCodecContext { + self.codec_ctx + } + + pub fn encode_frame(&mut self, frame: &Frame) -> Result, String> { + let mut packets = Vec::new(); unsafe { match frame { @@ -107,8 +111,8 @@ if avcodec_send_frame(self.codec_ctx, hw_frame) >= 0 { let mut pkt = av_packet_alloc(); while avcodec_receive_packet(self.codec_ctx, pkt) >= 0 { - println!("VAAPI: encoded packet of size {}", (*pkt).size); - av_packet_unref(pkt); + let new_pkt = av_packet_alloc(); + av_packet_move_ref(new_pkt, pkt); + packets.push(Packet::new(new_pkt)); } av_packet_free(&mut pkt); } @@ -122,7 +126,7 @@ } } } - Ok(()) + Ok(packets) } }