Clippy fixes
This commit is contained in:
parent
4ac111214a
commit
59a8fdc9a4
@ -50,7 +50,7 @@ impl Decoder {
|
||||
}
|
||||
|
||||
pub unsafe fn decode_pkt(&mut self, pkt: *mut AVPacket) -> Result<usize, Error> {
|
||||
let stream_index = (*pkt).stream_index as i32;
|
||||
let stream_index = (*pkt).stream_index;
|
||||
let stream = (*pkt).opaque as *mut AVStream;
|
||||
assert_eq!(
|
||||
stream_index,
|
||||
@ -65,13 +65,13 @@ impl Decoder {
|
||||
"Codec parameters are missing from stream"
|
||||
);
|
||||
|
||||
if !self.codecs.contains_key(&stream_index) {
|
||||
if let std::collections::hash_map::Entry::Vacant(e) = self.codecs.entry(stream_index) {
|
||||
let codec = avcodec_find_decoder((*codec_par).codec_id);
|
||||
if codec == ptr::null_mut() {
|
||||
if codec.is_null() {
|
||||
return Err(Error::msg("Failed to find codec"));
|
||||
}
|
||||
let mut context = avcodec_alloc_context3(ptr::null());
|
||||
if context == ptr::null_mut() {
|
||||
let context = avcodec_alloc_context3(ptr::null());
|
||||
if context.is_null() {
|
||||
return Err(Error::msg("Failed to alloc context"));
|
||||
}
|
||||
if avcodec_parameters_to_context(context, codec_par) != 0 {
|
||||
@ -80,12 +80,10 @@ impl Decoder {
|
||||
if avcodec_open2(context, codec, ptr::null_mut()) < 0 {
|
||||
return Err(Error::msg("Failed to open codec"));
|
||||
}
|
||||
self.codecs
|
||||
.insert(stream_index, CodecContext { context, codec });
|
||||
e.insert(CodecContext { context, codec });
|
||||
}
|
||||
if let Some(ctx) = self.codecs.get_mut(&stream_index) {
|
||||
let mut ret = -1;
|
||||
ret = avcodec_send_packet(ctx.context, pkt);
|
||||
let mut ret = avcodec_send_packet(ctx.context, pkt);
|
||||
av_packet_unref(pkt);
|
||||
if ret < 0 {
|
||||
return Err(Error::msg(format!("Failed to decode packet {}", ret)));
|
||||
@ -115,7 +113,7 @@ impl Decoder {
|
||||
}
|
||||
|
||||
pub fn process(&mut self) -> Result<usize, Error> {
|
||||
while let Ok(pkg) = self.chan_in.try_recv() {
|
||||
if let Ok(pkg) = self.chan_in.try_recv() {
|
||||
return if let PipelinePayload::AvPacket(_, pkt) = pkg {
|
||||
unsafe {
|
||||
let frames = self.decode_pkt(pkt)?;
|
||||
|
@ -40,9 +40,9 @@ unsafe extern "C" fn read_data(
|
||||
size: libc::c_int,
|
||||
) -> libc::c_int {
|
||||
let chan = opaque as *mut UnboundedReceiver<Bytes>;
|
||||
if let Some(mut data) = (*chan).blocking_recv() {
|
||||
if let Some(data) = (*chan).blocking_recv() {
|
||||
let buff_len = data.len();
|
||||
let mut len = size.min(buff_len as libc::c_int);
|
||||
let len = size.min(buff_len as libc::c_int);
|
||||
|
||||
if len > 0 {
|
||||
memcpy(
|
||||
@ -121,7 +121,7 @@ impl Demuxer {
|
||||
av_find_best_stream(self.ctx, AVMEDIA_TYPE_AUDIO, -1, -1, ptr::null_mut(), 0) as usize;
|
||||
if audio_stream_index != AVERROR_STREAM_NOT_FOUND as usize {
|
||||
let audio_stream = *(*self.ctx).streams.add(audio_stream_index);
|
||||
let codec_copy = unsafe {
|
||||
let _codec_copy = unsafe {
|
||||
let ptr = avcodec_parameters_alloc();
|
||||
avcodec_parameters_copy(ptr, (*audio_stream).codecpar);
|
||||
ptr
|
||||
|
@ -4,23 +4,20 @@ use std::mem::transmute;
|
||||
use std::ptr;
|
||||
|
||||
use anyhow::Error;
|
||||
use ffmpeg_sys_next::{AV_CH_LAYOUT_STEREO, av_channel_layout_default, av_dump_format, av_get_sample_fmt, av_interleaved_write_frame, av_opt_set, AVChannelLayout, AVChannelLayout__bindgen_ty_1, avcodec_parameters_from_context, AVCodecContext, avformat_alloc_output_context2, avformat_free_context, avformat_new_stream, avformat_write_header, AVFormatContext, AVPacket, AVRational};
|
||||
use ffmpeg_sys_next::{AV_CH_LAYOUT_STEREO, av_dump_format, av_get_sample_fmt, av_interleaved_write_frame, av_opt_set, AVChannelLayout, AVChannelLayout__bindgen_ty_1, avcodec_parameters_from_context, AVCodecContext, avformat_alloc_output_context2, avformat_free_context, avformat_new_stream, avformat_write_header, AVFormatContext, AVPacket, AVRational};
|
||||
use ffmpeg_sys_next::AVChannelOrder::AV_CHANNEL_ORDER_NATIVE;
|
||||
use ffmpeg_sys_next::AVColorSpace::AVCOL_SPC_BT709;
|
||||
use ffmpeg_sys_next::AVMediaType::{AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_VIDEO};
|
||||
use ffmpeg_sys_next::AVPixelFormat::AV_PIX_FMT_YUV420P;
|
||||
use futures_util::StreamExt;
|
||||
use itertools::Itertools;
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::mpsc::{UnboundedReceiver};
|
||||
use uuid::{Bytes, Uuid, Variant};
|
||||
use tokio::sync::mpsc::UnboundedReceiver;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::demux::info::{DemuxStreamInfo, StreamChannelType};
|
||||
use crate::fraction::Fraction;
|
||||
use crate::pipeline::PipelinePayload;
|
||||
use crate::utils::{get_ffmpeg_error_msg, id_ref_to_uuid};
|
||||
use crate::variant::{VariantStream, VideoVariant};
|
||||
use crate::variant::VariantStream;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct HLSEgressConfig {
|
||||
@ -31,7 +28,7 @@ pub struct HLSEgressConfig {
|
||||
impl Display for HLSEgressConfig {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "HLS: out_dir={}", self.out_dir)?;
|
||||
if self.variants.len() > 0 {
|
||||
if !self.variants.is_empty() {
|
||||
write!(f, "\n\tStreams: ")?;
|
||||
for v in &self.variants {
|
||||
write!(f, "\n\t\t{}", v)?;
|
||||
@ -135,7 +132,6 @@ impl HlsEgress {
|
||||
}
|
||||
let stream_map = stream_map
|
||||
.values()
|
||||
.into_iter()
|
||||
.map(|v| v.join(","))
|
||||
.join(" ");
|
||||
|
||||
@ -153,7 +149,7 @@ impl HlsEgress {
|
||||
match var {
|
||||
VariantStream::Video(vs) => {
|
||||
let stream = avformat_new_stream(ctx, ptr::null());
|
||||
if stream == ptr::null_mut() {
|
||||
if stream.is_null() {
|
||||
return Err(Error::msg("Failed to add stream to output"));
|
||||
}
|
||||
|
||||
@ -178,7 +174,7 @@ impl HlsEgress {
|
||||
}
|
||||
VariantStream::Audio(va) => {
|
||||
let stream = avformat_new_stream(ctx, ptr::null());
|
||||
if stream == ptr::null_mut() {
|
||||
if stream.is_null() {
|
||||
return Err(Error::msg("Failed to add stream to output"));
|
||||
}
|
||||
|
||||
@ -204,7 +200,6 @@ impl HlsEgress {
|
||||
opaque: ptr::null_mut(),
|
||||
};
|
||||
}
|
||||
_ => return Err(Error::msg("Invalid config")),
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,7 +225,7 @@ impl HlsEgress {
|
||||
}
|
||||
|
||||
let stream = *(*self.ctx).streams.add(variant.unwrap().dst_index());
|
||||
let idx = (*stream).index as i32;
|
||||
let idx = (*stream).index;
|
||||
(*pkt).stream_index = idx;
|
||||
if !self.stream_init.contains(&idx) {
|
||||
let encoder = (*pkt).opaque as *mut AVCodecContext;
|
||||
@ -250,7 +245,7 @@ impl HlsEgress {
|
||||
while let Ok(pkg) = self.chan_in.try_recv() {
|
||||
match pkg {
|
||||
PipelinePayload::AvPacket(_, pkt) => unsafe {
|
||||
if self.ctx == ptr::null_mut() {
|
||||
if self.ctx.is_null() {
|
||||
self.setup_muxer()?;
|
||||
}
|
||||
self.process_pkt(pkt)?;
|
||||
|
@ -71,15 +71,15 @@ where
|
||||
}
|
||||
|
||||
unsafe fn setup_encoder(&mut self, frame: *mut AVFrame) -> Result<(), Error> {
|
||||
if self.ctx == ptr::null_mut() {
|
||||
if self.ctx.is_null() {
|
||||
let codec = self.variant.codec;
|
||||
let encoder = avcodec_find_encoder(transmute(codec as i32));
|
||||
if encoder == ptr::null_mut() {
|
||||
if encoder.is_null() {
|
||||
return Err(Error::msg("Encoder not found"));
|
||||
}
|
||||
|
||||
let ctx = avcodec_alloc_context3(encoder);
|
||||
if ctx == ptr::null_mut() {
|
||||
if ctx.is_null() {
|
||||
return Err(Error::msg("Failed to allocate encoder context"));
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ where
|
||||
|
||||
// setup audio FIFO
|
||||
let fifo = av_audio_fifo_alloc((*ctx).sample_fmt, 2, 1);
|
||||
if fifo == ptr::null_mut() {
|
||||
if fifo.is_null() {
|
||||
return Err(Error::msg("Failed to allocate audio FiFO buffer"));
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ where
|
||||
return Err(Error::msg("Failed to write samples to FIFO"));
|
||||
}
|
||||
|
||||
if dst_samples != ptr::null_mut() {
|
||||
if !dst_samples.is_null() {
|
||||
av_freep(dst_samples.add(0) as *mut libc::c_void);
|
||||
}
|
||||
|
||||
|
@ -51,15 +51,15 @@ where
|
||||
}
|
||||
|
||||
unsafe fn setup_encoder(&mut self, frame: *mut AVFrame) -> Result<(), Error> {
|
||||
if self.ctx == ptr::null_mut() {
|
||||
if self.ctx.is_null() {
|
||||
let codec = self.variant.codec;
|
||||
let encoder = avcodec_find_encoder(transmute(codec as i32));
|
||||
if encoder == ptr::null_mut() {
|
||||
if encoder.is_null() {
|
||||
return Err(Error::msg("Encoder not found"));
|
||||
}
|
||||
|
||||
let ctx = avcodec_alloc_context3(encoder);
|
||||
if ctx == ptr::null_mut() {
|
||||
if ctx.is_null() {
|
||||
return Err(Error::msg("Failed to allocate encoder context"));
|
||||
}
|
||||
|
||||
|
@ -16,13 +16,13 @@ fn gcd(mut a: usize, mut b: usize) -> usize {
|
||||
a = b;
|
||||
b = temp % b;
|
||||
}
|
||||
return a;
|
||||
a
|
||||
}
|
||||
|
||||
impl From<(usize, usize)> for Fraction {
|
||||
fn from(value: (usize, usize)) -> Self {
|
||||
let mut num = value.0;
|
||||
let mut den = value.1;
|
||||
let num = value.0;
|
||||
let den = value.1;
|
||||
|
||||
let gcd = gcd(num, den);
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use futures_util::{StreamExt, TryStreamExt};
|
||||
use log::{info, warn};
|
||||
use srt_tokio::{SrtListener, SrtSocket};
|
||||
use srt_tokio::SrtListener;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
use crate::ingress::ConnectionInfo;
|
||||
use crate::pipeline::builder::PipelineBuilder;
|
||||
use crate::pipeline::runner::PipelineRunner;
|
||||
|
||||
pub async fn listen(addr: String, builder: PipelineBuilder) -> Result<(), anyhow::Error> {
|
||||
let (_binding, mut packets) = SrtListener::builder().bind(addr.clone()).await?;
|
||||
|
@ -1,16 +1,12 @@
|
||||
use std::io;
|
||||
|
||||
use bytes::BytesMut;
|
||||
use futures_util::{StreamExt, TryStreamExt};
|
||||
use log::{error, info, warn};
|
||||
use srt_tokio::{SrtListener, SrtSocket};
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::net::{TcpListener, TcpSocket};
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
use crate::ingress::ConnectionInfo;
|
||||
use crate::pipeline::builder::PipelineBuilder;
|
||||
use crate::pipeline::runner::PipelineRunner;
|
||||
|
||||
pub async fn listen(addr: String, builder: PipelineBuilder) -> Result<(), anyhow::Error> {
|
||||
let listener = TcpListener::bind(addr.clone()).await.unwrap();
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use anyhow::Error;
|
||||
use ffmpeg_sys_next::{av_frame_clone, av_frame_copy_props, av_frame_free, av_packet_clone, av_packet_copy_props, av_packet_free, AVFrame, AVPacket};
|
||||
@ -34,6 +33,7 @@ impl Display for EgressType {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
|
||||
pub struct PipelineConfig {
|
||||
pub id: uuid::Uuid,
|
||||
@ -44,13 +44,13 @@ pub struct PipelineConfig {
|
||||
impl Display for PipelineConfig {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\nPipeline Config ID={}", self.id)?;
|
||||
if self.recording.len() > 0 {
|
||||
if !self.recording.is_empty() {
|
||||
write!(f, "\nRecording:")?;
|
||||
for r in &self.recording {
|
||||
write!(f, "\n\t{}", r)?;
|
||||
}
|
||||
}
|
||||
if self.egress.len() > 0 {
|
||||
if !self.egress.is_empty() {
|
||||
write!(f, "\nEgress:")?;
|
||||
for e in &self.egress {
|
||||
write!(f, "\n\t{}", e)?;
|
||||
@ -91,7 +91,7 @@ impl Clone for PipelinePayload {
|
||||
PipelinePayload::AvFrame(t, p, idx) => unsafe {
|
||||
let new_frame = av_frame_clone(*p);
|
||||
av_frame_copy_props(new_frame, *p);
|
||||
PipelinePayload::AvFrame(t.clone(), new_frame, idx.clone())
|
||||
PipelinePayload::AvFrame(t.clone(), new_frame, *idx)
|
||||
},
|
||||
PipelinePayload::SourceInfo(i) => PipelinePayload::SourceInfo(i.clone()),
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
use std::ops::Add;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use anyhow::Error;
|
||||
use itertools::Itertools;
|
||||
use log::info;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::sync::broadcast;
|
||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
|
||||
|
||||
@ -114,7 +112,7 @@ impl PipelineRunner {
|
||||
.iter()
|
||||
.find(|s| s.channel_type == StreamChannelType::Video);
|
||||
|
||||
if let Some(ref vs) = video_stream {
|
||||
if let Some(_vs) = video_stream {
|
||||
for eg in &self.config.egress {
|
||||
match eg {
|
||||
EgressType::HLS(cfg) => {
|
||||
@ -154,12 +152,6 @@ impl PipelineRunner {
|
||||
)),
|
||||
});
|
||||
}
|
||||
c => {
|
||||
return Err(Error::msg(format!(
|
||||
"Variant config not supported {:?}",
|
||||
c
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,7 +160,7 @@ impl PipelineRunner {
|
||||
}
|
||||
}
|
||||
|
||||
if self.egress.len() == 0 {
|
||||
if self.egress.is_empty() {
|
||||
Err(Error::msg("No egress config, pipeline misconfigured!"))
|
||||
} else {
|
||||
Ok(())
|
||||
|
@ -53,7 +53,7 @@ impl Scaler {
|
||||
unsafe fn process_frame(&mut self, frame: *mut AVFrame, src_index: usize) -> Result<(), Error> {
|
||||
let dst_fmt = transmute((*frame).format);
|
||||
|
||||
if self.ctx == ptr::null_mut() {
|
||||
if self.ctx.is_null() {
|
||||
let ctx = sws_getContext(
|
||||
(*frame).width,
|
||||
(*frame).height,
|
||||
@ -66,7 +66,7 @@ impl Scaler {
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
);
|
||||
if ctx == ptr::null_mut() {
|
||||
if ctx.is_null() {
|
||||
return Err(Error::msg("Failed to create scalar context"));
|
||||
}
|
||||
self.ctx = ctx;
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::ffi::CStr;
|
||||
use std::ptr;
|
||||
|
||||
use anyhow::Error;
|
||||
use ffmpeg_sys_next::{av_buffer_allocz, av_make_error_string, AVBufferRef, memcpy};
|
||||
@ -37,7 +36,6 @@ pub fn variant_id_ref(var: &VariantStream) -> Result<*mut AVBufferRef, Error> {
|
||||
);
|
||||
Ok(buf)
|
||||
}
|
||||
_ => return Err(Error::msg("Cannot assign pkt stream index")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,10 +66,10 @@ pub fn audio_variant_id_ref(var: &AudioVariant) -> *mut AVBufferRef {
|
||||
|
||||
pub fn id_ref_to_uuid(buf: *mut AVBufferRef) -> Result<Uuid, Error> {
|
||||
unsafe {
|
||||
if buf == ptr::null_mut() {
|
||||
if buf.is_null() {
|
||||
return Err(Error::msg("Buffer was null"));
|
||||
}
|
||||
let binding = Bytes::from(*((*buf).data as *const [u8; 16]));
|
||||
Ok(Uuid::from_bytes_ref(&binding).clone())
|
||||
Ok(*Uuid::from_bytes_ref(&binding))
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::demux::info::{DemuxStreamInfo, StreamChannelType};
|
||||
@ -19,7 +17,7 @@ impl Webhook {
|
||||
Self { config }
|
||||
}
|
||||
|
||||
pub async fn start(&self, connection_info: ConnectionInfo) -> Result<(), anyhow::Error> {
|
||||
pub async fn start(&self, _connection_info: ConnectionInfo) -> Result<(), anyhow::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user