more segment impl, removed EOF error to continue execution for now
This commit is contained in:
parent
3889ed32e8
commit
f70f8c05cb
4 changed files with 25 additions and 9 deletions
|
@ -20,7 +20,7 @@ impl HLSHandler {
|
|||
pub fn data_loop(&mut self) {
|
||||
self.muxer.spawn_read_loops();
|
||||
loop {
|
||||
match self.muxer.get_segment(self.curr_segment_idx) {
|
||||
match self.muxer.get_segment(self.curr_segment_idx, self.args.segment_time) {
|
||||
None => (),
|
||||
Some(segment) => {
|
||||
let del_list = self.new_segment(segment);
|
||||
|
|
|
@ -42,7 +42,6 @@ impl mp4::MP4Muxer {
|
|||
let (mut v, mut a) = (self.v.take().unwrap(), self.a.take().unwrap());
|
||||
let v_queue = self.v_samples.clone();
|
||||
let a_queue = self.a_samples.clone();
|
||||
let (err_in1, err_in2) = (self.err_in.clone(), self.err_in.clone());
|
||||
|
||||
thread::spawn(move || {
|
||||
let mut i = 1;
|
||||
|
@ -50,7 +49,7 @@ impl mp4::MP4Muxer {
|
|||
match v.recv() {
|
||||
Ok(x) => {v_queue.push(x.packet_data, if i % 30 == 0 {0x02000000} else {0x01010000});},
|
||||
Err(_) => {
|
||||
util::thread_freeze(err_in1, Box::new(util::MuxerError::EOF));
|
||||
thread::park();
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +61,7 @@ impl mp4::MP4Muxer {
|
|||
match a.recv() {
|
||||
Ok(x) => {a_queue.push(x.packet_data, 0x01010000);},
|
||||
Err(_) => {
|
||||
util::thread_freeze(err_in2, Box::new(util::MuxerError::EOF));
|
||||
thread::park();
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -70,8 +69,15 @@ impl mp4::MP4Muxer {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn get_segment(&mut self, idx: usize) -> Option<segments::Segment> {
|
||||
todo!();
|
||||
pub fn get_segment(&mut self, idx: usize, time: usize) -> Option<segments::Segment> {
|
||||
if self.v_samples.segment_ready(time) && self.a_samples.segment_ready(time) {
|
||||
return Some(segments::Segment {
|
||||
filename: idx.to_string() + ".m4s",
|
||||
segment_video: self.v_samples.get_segment_samples(time),
|
||||
segment_audio: self.a_samples.get_segment_samples(time),
|
||||
})
|
||||
}
|
||||
return None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::muxer::hls::segments;
|
||||
|
||||
pub struct Sample {
|
||||
pub data: Vec<u8>,
|
||||
pub size: u32,
|
||||
|
@ -20,4 +22,13 @@ impl SampleQueue {
|
|||
flags: flags,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn segment_ready(&self, time: usize) -> bool {
|
||||
self.queue.lock().unwrap().len() >= time * self.samples_per_sec
|
||||
}
|
||||
|
||||
pub fn get_segment_samples(&self, time: usize) -> Vec<Sample> {
|
||||
let samples_to_drain = time * self.samples_per_sec;
|
||||
self.queue.lock().unwrap().drain(..samples_to_drain).collect()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,9 @@ use std::time;
|
|||
use crate::muxer::hls::mp4::samples;
|
||||
|
||||
pub struct Segment {
|
||||
segment_idx: usize,
|
||||
pub filename: String,
|
||||
segment_video: Vec<samples::Sample>,
|
||||
segment_audio: Vec<samples::Sample>,
|
||||
pub segment_video: Vec<samples::Sample>,
|
||||
pub segment_audio: Vec<samples::Sample>,
|
||||
}
|
||||
|
||||
impl Segment {
|
||||
|
|
Loading…
Reference in a new issue