segment writing success
This commit is contained in:
parent
fc7ecd62bd
commit
8849808c1e
5 changed files with 34 additions and 6 deletions
|
@ -3,6 +3,7 @@ use std::sync::{mpsc, Arc};
|
|||
use std::time;
|
||||
use std::thread;
|
||||
use std::fs;
|
||||
use std::cmp::max;
|
||||
|
||||
use crate::util;
|
||||
use crate::muxer::hls::mp4;
|
||||
|
@ -36,7 +37,7 @@ impl HLSHandler {
|
|||
fn new_segment(&mut self, segment: segments::Segment) -> std::vec::Drain<String> {
|
||||
segment.dump();
|
||||
self.curr_segments.push(segment.filename);
|
||||
self.curr_segments.drain(..self.curr_segments.len() - self.args.max_segments)
|
||||
self.curr_segments.drain(..max(self.curr_segments.len() - self.args.max_segments, 0))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1145,9 +1145,9 @@ impl MP4Atom for SampleData {
|
|||
}
|
||||
}
|
||||
|
||||
struct MDAT {
|
||||
v_samples: Vec<u8>,
|
||||
a_samples: Vec<u8>,
|
||||
pub struct MDAT {
|
||||
pub v_samples: Vec<u8>,
|
||||
pub a_samples: Vec<u8>,
|
||||
}
|
||||
|
||||
impl MP4Atom for MDAT {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod mp4muxer;
|
||||
mod atoms;
|
||||
pub mod atoms;
|
||||
pub mod samples;
|
||||
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
|
|
|
@ -73,6 +73,7 @@ impl mp4::MP4Muxer {
|
|||
if self.v_samples.segment_ready(time) && self.a_samples.segment_ready(time) {
|
||||
return Some(segments::Segment {
|
||||
filename: idx.to_string() + ".m4s",
|
||||
idx: idx,
|
||||
segment_video: self.v_samples.get_segment_samples(time),
|
||||
sample_duration_v: self.v_samples.default_duration,
|
||||
segment_audio: self.a_samples.get_segment_samples(time),
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
use std::time;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use crate::muxer::hls::mp4::samples;
|
||||
use crate::muxer::hls::mp4::atoms;
|
||||
use crate::muxer::hls::mp4::atoms::MP4Atom;
|
||||
|
||||
pub struct Segment {
|
||||
pub filename: String,
|
||||
pub idx: usize,
|
||||
pub segment_video: Vec<samples::Sample>,
|
||||
pub sample_duration_v: u32,
|
||||
pub segment_audio: Vec<samples::Sample>,
|
||||
|
@ -11,6 +17,26 @@ pub struct Segment {
|
|||
|
||||
impl Segment {
|
||||
pub fn dump(&self) {
|
||||
todo!();
|
||||
let mdat = self.new_mdat();
|
||||
let moof = atoms::new_moof(&self.segment_video, self.sample_duration_v, &self.segment_audio, self.sample_duration_a, 0, mdat.v_samples.len(), self.idx);
|
||||
let mut segment_bytes = moof.marshall();
|
||||
segment_bytes.append(&mut mdat.marshall());
|
||||
|
||||
let mut f = File::create(&self.filename).unwrap();
|
||||
f.write_all(&segment_bytes);
|
||||
}
|
||||
|
||||
fn new_mdat(&self) -> atoms::MDAT {
|
||||
let (mut v_samples, mut a_samples) = (Vec::new(), Vec::new());
|
||||
for sample in &self.segment_video {
|
||||
v_samples.extend_from_slice(sample.data.as_slice());
|
||||
}
|
||||
for sample in &self.segment_audio {
|
||||
a_samples.extend_from_slice(sample.data.as_slice());
|
||||
}
|
||||
atoms::MDAT {
|
||||
v_samples: v_samples,
|
||||
a_samples: a_samples,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue