mirror of
https://github.com/v0l/zap-stream-core.git
synced 2025-06-19 04:44:58 +00:00
Remove opaque pointers in pkts
This commit is contained in:
@ -3,14 +3,14 @@ use std::ptr;
|
||||
|
||||
use anyhow::Error;
|
||||
use ffmpeg_sys_next::{
|
||||
av_buffer_ref, av_frame_alloc, av_frame_copy_props, AVBufferRef, AVFrame,
|
||||
SWS_BILINEAR, sws_freeContext, sws_getContext, sws_scale_frame, SwsContext,
|
||||
av_frame_alloc, av_frame_copy_props, AVBufferRef, AVFrame, SWS_BILINEAR,
|
||||
sws_freeContext, sws_getContext, sws_scale_frame, SwsContext,
|
||||
};
|
||||
use tokio::sync::broadcast;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use crate::pipeline::{PipelinePayload, PipelineProcessor};
|
||||
use crate::utils::{get_ffmpeg_error_msg, video_variant_id_ref};
|
||||
use crate::pipeline::{AVFrameSource, PipelinePayload, PipelineProcessor};
|
||||
use crate::utils::{get_ffmpeg_error_msg};
|
||||
use crate::variant::VideoVariant;
|
||||
|
||||
pub struct Scaler {
|
||||
@ -18,7 +18,6 @@ pub struct Scaler {
|
||||
ctx: *mut SwsContext,
|
||||
chan_in: broadcast::Receiver<PipelinePayload>,
|
||||
chan_out: UnboundedSender<PipelinePayload>,
|
||||
var_id_ref: *mut AVBufferRef,
|
||||
}
|
||||
|
||||
unsafe impl Send for Scaler {}
|
||||
@ -40,17 +39,19 @@ impl Scaler {
|
||||
chan_out: UnboundedSender<PipelinePayload>,
|
||||
variant: VideoVariant,
|
||||
) -> Self {
|
||||
let id_ref = video_variant_id_ref(&variant);
|
||||
Self {
|
||||
chan_in,
|
||||
chan_out,
|
||||
variant,
|
||||
ctx: ptr::null_mut(),
|
||||
var_id_ref: id_ref,
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn process_frame(&mut self, frame: *mut AVFrame, src_index: usize) -> Result<(), Error> {
|
||||
unsafe fn process_frame(
|
||||
&mut self,
|
||||
frame: *mut AVFrame,
|
||||
src: &AVFrameSource,
|
||||
) -> Result<(), Error> {
|
||||
let dst_fmt = transmute((*frame).format);
|
||||
|
||||
if self.ctx.is_null() {
|
||||
@ -83,14 +84,8 @@ impl Scaler {
|
||||
return Err(Error::msg(get_ffmpeg_error_msg(ret)));
|
||||
}
|
||||
|
||||
(*dst_frame).opaque = (*frame).opaque;
|
||||
(*dst_frame).opaque_ref = av_buffer_ref(self.var_id_ref);
|
||||
|
||||
self.chan_out.send(PipelinePayload::AvFrame(
|
||||
"Scaler frame".to_owned(),
|
||||
dst_frame,
|
||||
src_index,
|
||||
))?;
|
||||
self.chan_out
|
||||
.send(PipelinePayload::AvFrame(dst_frame, src.clone()))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -99,9 +94,15 @@ impl PipelineProcessor for Scaler {
|
||||
fn process(&mut self) -> Result<(), Error> {
|
||||
while let Ok(pkg) = self.chan_in.try_recv() {
|
||||
match pkg {
|
||||
PipelinePayload::AvFrame(_, frm, idx) => unsafe {
|
||||
if self.variant.src_index == idx {
|
||||
self.process_frame(frm, idx)?;
|
||||
PipelinePayload::AvFrame(frm, ref src) => unsafe {
|
||||
let idx = match src {
|
||||
AVFrameSource::Decoder(s) => (**s).index,
|
||||
_ => {
|
||||
return Err(Error::msg(format!("Cannot process frame from: {:?}", src)))
|
||||
}
|
||||
};
|
||||
if self.variant.src_index == idx as usize {
|
||||
self.process_frame(frm, src)?;
|
||||
}
|
||||
},
|
||||
_ => return Err(Error::msg("Payload not supported payload")),
|
||||
|
Reference in New Issue
Block a user