hlssink3: Use fragment duration from splitmuxsink if available

splitmuxsink now reports fragment offset and duration in the
splitmuxsink-fragment-closed message. Use this duration value
for the MediaSegment when available.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1728>
This commit is contained in:
Sanchayan Maity 2024-08-19 20:36:22 +05:30 committed by GStreamer Marge Bot
parent 4cf93ccbdb
commit 320f36a462
2 changed files with 27 additions and 12 deletions

View file

@ -466,7 +466,7 @@ impl BinImpl for HlsSink3 {
"splitmuxsink-fragment-closed" => {
let s = msg.structure().unwrap();
if let Ok(fragment_closed_at) = s.get::<gst::ClockTime>("running-time") {
self.on_fragment_closed(fragment_closed_at);
self.on_fragment_closed(s, fragment_closed_at);
}
}
_ => {}
@ -543,7 +543,7 @@ impl HlsSink3 {
Ok(segment_file_location)
}
fn on_fragment_closed(&self, closed_at: gst::ClockTime) {
fn on_fragment_closed(&self, s: &gst::StructureRef, closed_at: gst::ClockTime) {
let mut state = self.state.lock().unwrap();
let location = match state.current_segment_location.take() {
Some(location) => location,
@ -553,15 +553,30 @@ impl HlsSink3 {
}
};
let opened_at = match state.fragment_opened_at.take() {
Some(opened_at) => opened_at,
None => {
gst::error!(CAT, imp = self, "Unknown segment duration");
return;
let (duration, duration_msec) = {
if let Ok(fragment_duration) = s.get::<gst::ClockTime>("fragment-duration") {
(
fragment_duration,
fragment_duration.mseconds() as f32 / 1_000f32,
)
} else {
let opened_at = match state.fragment_opened_at.take() {
Some(opened_at) => opened_at,
None => {
gst::error!(CAT, imp = self, "Unknown segment duration");
return;
}
};
let fragment_duration = closed_at - opened_at;
(
fragment_duration,
fragment_duration.mseconds() as f32 / 1_000f32,
)
}
};
let duration = closed_at - opened_at;
let running_time = state.fragment_running_time;
drop(state);
@ -574,7 +589,7 @@ impl HlsSink3 {
duration,
MediaSegment {
uri,
duration: duration.mseconds() as f32 / 1_000f32,
duration: duration_msec,
..Default::default()
},
);

View file

@ -267,9 +267,9 @@ fn test_hlssink3_element_with_video_content() -> Result<(), ()> {
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:4
#EXTINF:2,
#EXTINF:1.999,
segment00003.ts
#EXTINF:0.3,
#EXTINF:0.333,
segment00004.ts
#EXT-X-ENDLIST
"###,
@ -488,7 +488,7 @@ fn test_hlssink3_write_correct_playlist_content() -> Result<(), ()> {
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:15
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:1.633,
#EXTINF:1.666,
segments/my-own-filename-000.ts
#EXT-X-ENDLIST
"###,