use metadata as Arc pointer to move around easier
This commit is contained in:
parent
9942dca4fb
commit
f5e2ba19ab
2 changed files with 8 additions and 6 deletions
|
@ -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<util::Metadata, Box<dyn Error>>;
|
||||
fn read_nalu(&mut self, metadata: &util::Metadata) -> Result<util::NALUPacket, Box<dyn Error + Send + Sync>>;
|
||||
fn data_loop(&mut self, v_in: mpsc::Sender<util::NALUPacket>, a_in: mpsc::Sender<util::NALUPacket>, metadata: &util::Metadata, err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>) {
|
||||
fn data_loop(&mut self, v_in: mpsc::Sender<util::NALUPacket>, a_in: mpsc::Sender<util::NALUPacket>, metadata: Arc<util::Metadata>, err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>) {
|
||||
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}
|
||||
};
|
||||
|
|
|
@ -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<util::NALUPacket>,
|
||||
mpsc::Receiver<util::NALUPacket>,
|
||||
util::Metadata,
|
||||
Arc<util::Metadata>,
|
||||
mpsc::Receiver<Box<dyn Error + Send + Sync>>
|
||||
),
|
||||
Box<dyn Error>
|
||||
> {
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue