write whole files

This commit is contained in:
2020-02-22 17:23:22 +01:00
parent 8f1196aefe
commit f449efe273

View File

@@ -6,10 +6,12 @@ use gstreamer_audio::{prelude::*, AudioDecoder, AudioEncoder};
use gstreamer_base::prelude::*; use gstreamer_base::prelude::*;
use std::borrow::Cow; use std::borrow::Cow;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::io::Error as StdIoError;
#[derive(Debug)] #[derive(Debug)]
enum Error { enum Error {
Str(Cow<'static, str>), Str(Cow<'static, str>),
StdIoError(StdIoError),
GBoolError(GBoolError), GBoolError(GBoolError),
GError(GError), GError(GError),
} }
@@ -32,6 +34,12 @@ impl From<GBoolError> for Error {
} }
} }
impl From<StdIoError> for Error {
fn from(err: StdIoError) -> Error {
Error::StdIoError(err)
}
}
impl From<GError> for Error { impl From<GError> for Error {
fn from(err: GError) -> Error { fn from(err: GError) -> Error {
Error::GError(err) Error::GError(err)
@@ -117,8 +125,11 @@ async fn transcode(src: &Path, dest: &Path) -> Result<(), Error> {
let src_gstring = glib::GString::ForeignOwned(Some(src_cstring)); let src_gstring = glib::GString::ForeignOwned(Some(src_cstring));
file_src.set_property("location", &src_gstring)?; file_src.set_property("location", &src_gstring)?;
let original_dest = dest;
let dest = dest.with_extension("tmp");
let file_dest: gstreamer_base::BaseSink = gmake("filesink")?; let file_dest: gstreamer_base::BaseSink = gmake("filesink")?;
let dest_cstring = ToGlibPtr::<*const libc::c_char>::to_glib_none(dest).1; let dest_cstring = ToGlibPtr::<*const libc::c_char>::to_glib_none(&dest).1;
let dest_gstring = glib::GString::ForeignOwned(Some(dest_cstring)); let dest_gstring = glib::GString::ForeignOwned(Some(dest_cstring));
file_dest.set_property("location", &dest_gstring)?; file_dest.set_property("location", &dest_gstring)?;
file_dest.set_sync(false); file_dest.set_sync(false);
@@ -175,5 +186,7 @@ async fn transcode(src: &Path, dest: &Path) -> Result<(), Error> {
.set_state(gstreamer::State::Null) .set_state(gstreamer::State::Null)
.map_err(|_| "Unable to set the pipeline to the `Null` state")?; .map_err(|_| "Unable to set the pipeline to the `Null` state")?;
std::fs::rename(dest, original_dest)?;
Ok(()) Ok(())
} }