mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-26 13:31:00 +00:00
hlssink3: Use Path API for getting file name
Current implementation does not support Windows path separator. Use Path API instead. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1306>
This commit is contained in:
parent
7f16ac3915
commit
c4d371d163
1 changed files with 7 additions and 25 deletions
|
@ -374,13 +374,18 @@ impl HlsSink3 {
|
|||
|
||||
fn segment_filename(&self, state: &mut StartedState) -> String {
|
||||
assert!(state.current_segment_location.is_some());
|
||||
let segment_filename = path_basename(state.current_segment_location.take().unwrap());
|
||||
let name = state.current_segment_location.take().unwrap();
|
||||
let segment_filename = path::Path::new(&name)
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap();
|
||||
|
||||
let settings = self.settings.lock().unwrap();
|
||||
if let Some(playlist_root) = &settings.playlist_root {
|
||||
format!("{playlist_root}/{segment_filename}")
|
||||
} else {
|
||||
segment_filename
|
||||
segment_filename.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1006,26 +1011,3 @@ impl ElementImpl for HlsSink3 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The content of the last item of a path separated by `/` character.
|
||||
fn path_basename(name: impl AsRef<str>) -> String {
|
||||
name.as_ref().split('/').last().unwrap().to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn can_extract_basenames() {
|
||||
for (input, output) in [
|
||||
("", ""),
|
||||
("value", "value"),
|
||||
("/my/nice/path.ts", "path.ts"),
|
||||
("file.ts", "file.ts"),
|
||||
("https://localhost/output/file.vtt", "file.vtt"),
|
||||
] {
|
||||
assert_eq!(path_basename(input), output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue