media-converter: Use the test pattern video even without dump/transcoded files.

So the game won't trip over lack of media when shader pre-cacheing is
disabled in Steam.

CW-Bug-Id: #21524
This commit is contained in:
Arkadiusz Hiler 2022-11-08 20:51:10 +02:00
parent e2493e2dfd
commit 8e67412fcc

View file

@ -303,18 +303,28 @@ struct VideoConvState {
} }
impl VideoConvState { impl VideoConvState {
fn new() -> Result<VideoConvState, gst::LoggableError> { fn new() -> VideoConvState {
let read_fozdb_path = std::env::var("MEDIACONV_VIDEO_TRANSCODED_FILE").map_err(|_| { let read_fozdb_path = std::env::var("MEDIACONV_VIDEO_TRANSCODED_FILE");
loggable_error!(CAT, "MEDIACONV_VIDEO_TRANSCODED_FILE is not set!")
})?;
let read_fozdb = match fossilize::StreamArchive::new(&read_fozdb_path, OpenOptions::new().read(true), true /* read-only? */, VIDEOCONV_FOZ_NUM_TAGS) { if read_fozdb_path.is_err() {
Ok(s) => Some(s), gst::error!(CAT, "MEDIACONV_VIDEO_TRANSCODED_FILE is not set!")
Err(_) => None, }
let read_fozdb = match read_fozdb_path {
Ok(path) => match fossilize::StreamArchive::new(&path,
OpenOptions::new().read(true),
true /* read-only? */,
VIDEOCONV_FOZ_NUM_TAGS)
{
Ok(s) => Some(s),
Err(_) => None
},
Err(_) => None
}; };
Ok(VideoConvState {
VideoConvState {
transcode_hash: None, transcode_hash: None,
read_fozdb, read_fozdb,
@ -325,7 +335,7 @@ impl VideoConvState {
transcoded_tag: VIDEOCONV_FOZ_TAG_MKVDATA, transcoded_tag: VIDEOCONV_FOZ_TAG_MKVDATA,
need_stream_start: true, need_stream_start: true,
}) }
} }
/* true if the file is transcoded; false if not */ /* true if the file is transcoded; false if not */
@ -511,10 +521,7 @@ impl ElementImpl for VideoConv {
gst::StateChange::NullToReady => { gst::StateChange::NullToReady => {
/* do runtime setup */ /* do runtime setup */
let new_state = VideoConvState::new().map_err(|err| { let new_state = VideoConvState::new();
err.log();
gst::StateChangeError
})?;
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
assert!((*state).is_none()); assert!((*state).is_none());
@ -653,10 +660,7 @@ impl VideoConv {
return false; return false;
} }
if self.init_transcode(state).is_err() { self.init_transcode(state);
gst::error!(CAT, "Failed to init transcode");
return false;
}
match state.transcoded_tag { match state.transcoded_tag {
VIDEOCONV_FOZ_TAG_MKVDATA => gst::Caps::builder("video/x-matroska").build(), VIDEOCONV_FOZ_TAG_MKVDATA => gst::Caps::builder("video/x-matroska").build(),
@ -776,10 +780,7 @@ impl VideoConv {
Ok(()) Ok(())
} }
fn init_transcode( fn init_transcode(&self, state: &mut VideoConvState) {
&self,
state: &mut VideoConvState
) -> Result<(), gst::LoggableError> {
if state.transcode_hash.is_none() { if state.transcode_hash.is_none() {
(*DUMP_FOZDB).lock().unwrap().discard_transcoded(); (*DUMP_FOZDB).lock().unwrap().discard_transcoded();
@ -788,12 +789,13 @@ impl VideoConv {
if let Ok(hash) = hash { if let Ok(hash) = hash {
if !state.begin_transcode(hash) { if !state.begin_transcode(hash) {
self.dump_upstream_data(hash).map_err(|_| loggable_error!(CAT, "Dumping file to disk failed"))?; match self.dump_upstream_data(hash) {
Ok(_) => { },
Err(e) => { gst::error!(CAT, "{}", e.to_string())}
}
} }
} }
} }
Ok(())
} }
fn src_activatemode( fn src_activatemode(
@ -813,7 +815,7 @@ impl VideoConv {
* released before calling */ * released before calling */
match &mut *self.state.lock().unwrap() { match &mut *self.state.lock().unwrap() {
Some(state) => { Some(state) => {
self.init_transcode(state)?; self.init_transcode(state);
need_stream_start = state.need_stream_start; need_stream_start = state.need_stream_start;
hash = state.transcode_hash; hash = state.transcode_hash;
}, },