fix: catalog and init_track names conflicting due to different audio/video streams

This commit is contained in:
Wanjohi
2024-02-01 09:35:31 +03:00
parent 758888b2f8
commit 973c2bb92d

View File

@@ -297,7 +297,7 @@ impl AudioStream {
}
}
fn setup_appsink(appsink: &gst_app::AppSink, mut broadcast: broadcast::Publisher, _is_video: bool) {
fn setup_appsink(appsink: &gst_app::AppSink, mut broadcast: broadcast::Publisher, is_video: bool) {
let state = Arc::new(Mutex::new(State {
ftyp_atom: None,
broadcast: broadcast.to_owned(),
@@ -415,11 +415,13 @@ fn setup_appsink(appsink: &gst_app::AppSink, mut broadcast: broadcast::Publisher
let moov = mp4::MoovBox::read_box(&mut reader, header.size)
.expect("could not read the moov box");
let uuid = Uuid::new_v4();
let type_name = if is_video { "video"} else { "audio"};
let init_name = format!("{}.mp4", uuid);
// Create the catalog track with a single segment.
if !state.init.is_some() {
let init_name = format!("{}.mp4", type_name);
let mut init_track = broadcast
.create_track(&init_name)
.expect("could not create the init broadcast track");
@@ -437,9 +439,7 @@ fn setup_appsink(appsink: &gst_app::AppSink, mut broadcast: broadcast::Publisher
.final_fragment(VarInt::ZERO)
.expect("could not create the init fragment");
init_fragment.chunk(init.into()).expect(
"could not insert the moov+ftyp box into the init fragment",
);
init_fragment.chunk(init.into()).expect("could not insert the moov+ftyp box into the init fragment");
let mut tracks = HashMap::new();
@@ -463,9 +463,7 @@ fn setup_appsink(appsink: &gst_app::AppSink, mut broadcast: broadcast::Publisher
tracks.insert(id, track);
}
let uuid = Uuid::new_v4();
let catalog_name = format!(".catalog.{}", uuid);
let catalog_name = format!(".catalog_{}", type_name);
let mut catalog = broadcast
.create_track(&catalog_name)
@@ -480,6 +478,7 @@ fn setup_appsink(appsink: &gst_app::AppSink, mut broadcast: broadcast::Publisher
state.init = Some(init_track);
state.tracks = Some(tracks);
}
}
ATOM_TYPE_MOOF => {
// state.moof_atom = Some(atom);
// println!("moof_atom");