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) {
|
pub fn data_loop(&mut self) {
|
||||||
self.muxer.spawn_read_loops();
|
self.muxer.spawn_read_loops();
|
||||||
loop {
|
loop {
|
||||||
match self.muxer.get_segment(self.curr_segment_idx) {
|
match self.muxer.get_segment(self.curr_segment_idx, self.args.segment_time) {
|
||||||
None => (),
|
None => (),
|
||||||
Some(segment) => {
|
Some(segment) => {
|
||||||
let del_list = self.new_segment(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 (mut v, mut a) = (self.v.take().unwrap(), self.a.take().unwrap());
|
||||||
let v_queue = self.v_samples.clone();
|
let v_queue = self.v_samples.clone();
|
||||||
let a_queue = self.a_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 || {
|
thread::spawn(move || {
|
||||||
let mut i = 1;
|
let mut i = 1;
|
||||||
|
@ -50,7 +49,7 @@ impl mp4::MP4Muxer {
|
||||||
match v.recv() {
|
match v.recv() {
|
||||||
Ok(x) => {v_queue.push(x.packet_data, if i % 30 == 0 {0x02000000} else {0x01010000});},
|
Ok(x) => {v_queue.push(x.packet_data, if i % 30 == 0 {0x02000000} else {0x01010000});},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
util::thread_freeze(err_in1, Box::new(util::MuxerError::EOF));
|
thread::park();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +61,7 @@ impl mp4::MP4Muxer {
|
||||||
match a.recv() {
|
match a.recv() {
|
||||||
Ok(x) => {a_queue.push(x.packet_data, 0x01010000);},
|
Ok(x) => {a_queue.push(x.packet_data, 0x01010000);},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
util::thread_freeze(err_in2, Box::new(util::MuxerError::EOF));
|
thread::park();
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,8 +69,15 @@ impl mp4::MP4Muxer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_segment(&mut self, idx: usize) -> Option<segments::Segment> {
|
pub fn get_segment(&mut self, idx: usize, time: usize) -> Option<segments::Segment> {
|
||||||
todo!();
|
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 std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use crate::muxer::hls::segments;
|
||||||
|
|
||||||
pub struct Sample {
|
pub struct Sample {
|
||||||
pub data: Vec<u8>,
|
pub data: Vec<u8>,
|
||||||
pub size: u32,
|
pub size: u32,
|
||||||
|
@ -20,4 +22,13 @@ impl SampleQueue {
|
||||||
flags: flags,
|
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;
|
use crate::muxer::hls::mp4::samples;
|
||||||
|
|
||||||
pub struct Segment {
|
pub struct Segment {
|
||||||
segment_idx: usize,
|
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
segment_video: Vec<samples::Sample>,
|
pub segment_video: Vec<samples::Sample>,
|
||||||
segment_audio: Vec<samples::Sample>,
|
pub segment_audio: Vec<samples::Sample>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Segment {
|
impl Segment {
|
||||||
|
|
Loading…
Reference in a new issue