From f5e2ba19abe7a96f0de4c802890c07f9d5f51289 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 6 Oct 2023 16:03:07 +0500 Subject: [PATCH] use metadata as Arc pointer to move around easier --- src/demux/input.rs | 6 +++--- src/demux/mod.rs | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/demux/input.rs b/src/demux/input.rs index b5843d5..58e2640 100644 --- a/src/demux/input.rs +++ b/src/demux/input.rs @@ -1,7 +1,7 @@ use std::error::Error; use std::io; use std::io::Read; -use std::sync::mpsc; +use std::sync::{mpsc, Arc}; use crate::util; use crate::demux::flv; @@ -9,9 +9,9 @@ use crate::demux::flv; pub trait FileReader { fn init(&mut self) -> Result>; fn read_nalu(&mut self, metadata: &util::Metadata) -> Result>; - fn data_loop(&mut self, v_in: mpsc::Sender, a_in: mpsc::Sender, metadata: &util::Metadata, err_in: mpsc::Sender>) { + fn data_loop(&mut self, v_in: mpsc::Sender, a_in: mpsc::Sender, metadata: Arc, err_in: mpsc::Sender>) { loop { - let nalu = match self.read_nalu(metadata) { + let nalu = match self.read_nalu(&metadata) { Ok(x) => x, Err(err) => {util::thread_freeze(err_in, err); return} }; diff --git a/src/demux/mod.rs b/src/demux/mod.rs index 8985850..1334195 100644 --- a/src/demux/mod.rs +++ b/src/demux/mod.rs @@ -4,6 +4,7 @@ mod flv; use std::sync::mpsc; use std::error::Error; use std::thread; +use std::sync::Arc; use crate::util; use crate::demux::input::FileReader; @@ -12,18 +13,19 @@ pub fn spawn() -> Result< ( mpsc::Receiver, mpsc::Receiver, - util::Metadata, + Arc, mpsc::Receiver> ), Box > { let mut reader = input::new_reader()?; - let metadata = reader.init()?; + let metadata = Arc::new(reader.init()?); let (v_in, v_out) = mpsc::channel(); let (a_in, a_out) = mpsc::channel(); let (err_in, err_out) = mpsc::channel(); + let metadata_ptr = metadata.clone(); thread::spawn(move || { - reader.data_loop(v_in, a_in, &metadata, err_in); + reader.data_loop(v_in, a_in, metadata_ptr, err_in); }); return Ok((v_out, a_out, metadata, err_out)); }