From d7b925a1f7bfe34efd2037635469d4e26cba9d6b Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Sun, 16 May 2021 22:09:45 +0200 Subject: [PATCH] Use .into_write() instead of implementing it again --- src/imp.rs | 14 +++++++------- src/lib.rs | 1 - src/output.rs | 20 -------------------- 3 files changed, 7 insertions(+), 28 deletions(-) delete mode 100644 src/output.rs diff --git a/src/imp.rs b/src/imp.rs index e74d000..523d2a0 100644 --- a/src/imp.rs +++ b/src/imp.rs @@ -4,7 +4,7 @@ use gst::prelude::*; use gst::subclass::prelude::*; use gst::{gst_debug, gst_error, gst_info, gst_trace, gst_warning}; -use crate::{output::StreamWriter, playlist::PlaylistRenderState}; +use crate::playlist::PlaylistRenderState; use m3u8_rs::playlist::{MediaPlaylist, MediaPlaylistType, MediaSegment}; use once_cell::sync::Lazy; use std::fs; @@ -182,7 +182,7 @@ impl FlexHlsSink { &self, element: &super::FlexHlsSink, location: &P, - ) -> Result + ) -> Result where P: AsRef, { @@ -204,7 +204,7 @@ impl FlexHlsSink { element.post_error_message(error_msg); err.to_string() })?; - Ok(gio::WriteOutputStream::new(file)) + Ok(gio::WriteOutputStream::new(file).upcast()) } fn write_playlist( @@ -272,12 +272,12 @@ impl FlexHlsSink { playlist.media_sequence = *playlist_index as i32 - playlist.segments.len() as i32; // TODO: this should be a call to the signal exposed by this plugin - let playlist_file = self + let mut playlist_file = self .new_file_stream(&element, &playlist_location) - .map_err(|_| gst::StateChangeError)?; + .map_err(|_| gst::StateChangeError)? + .into_write(); - let mut playlist_stream = StreamWriter(playlist_file); - playlist.write_to(&mut playlist_stream).map_err(|err| { + playlist.write_to(&mut playlist_file).map_err(|err| { gst_error!( CAT, "Could not write new playlist file: {}", diff --git a/src/lib.rs b/src/lib.rs index f89ef13..53deffc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ use glib::prelude::*; mod imp; -mod output; mod playlist; glib::wrapper! { diff --git a/src/output.rs b/src/output.rs deleted file mode 100644 index 93ce33a..0000000 --- a/src/output.rs +++ /dev/null @@ -1,20 +0,0 @@ -use gio::prelude::*; -use std::io; - -pub(crate) struct StreamWriter(pub gio::WriteOutputStream); - -impl io::Write for StreamWriter { - fn write(&mut self, buf: &[u8]) -> io::Result { - Ok(self - .0 - .write(buf, gio::NONE_CANCELLABLE) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))? as usize) - } - - fn flush(&mut self) -> std::io::Result<()> { - Ok(self - .0 - .flush(gio::NONE_CANCELLABLE) - .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?) - } -}