Merge pull request #887 from vangel76/fix-886-unsupported-video-notice
#886: say why footage the decoders can't read shows no picture # Conflicts: # crates/media/src/pool.rs # crates/media/tests/footage.rs # crates/render/src/lib.rs
This commit is contained in:
@@ -208,6 +208,9 @@ struct Inner {
|
||||
/// audio is read from the decoder instead of trying again on every read.
|
||||
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
|
||||
conform_failed: Mutex<HashSet<std::path::PathBuf>>,
|
||||
/// Movies that failed to open or decode (path to a readable reason; see
|
||||
/// [`FootageSource::problem`]). The first failure of a file is logged, later ones are not.
|
||||
problems: Mutex<HashMap<Arc<str>, String>>,
|
||||
}
|
||||
|
||||
/// Decodes footage for the renderer: stills, image sequences and movies (FilmCraft codecs), plus
|
||||
@@ -277,6 +280,7 @@ impl MediaPool {
|
||||
conform: Mutex::default(),
|
||||
conforming: Mutex::default(),
|
||||
conform_failed: Mutex::default(),
|
||||
problems: Mutex::default(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -324,6 +328,7 @@ impl MediaPool {
|
||||
pub fn clear(&self) {
|
||||
self.clear_frames();
|
||||
lock(&self.inner.sources).clear();
|
||||
lock(&self.inner.problems).clear();
|
||||
}
|
||||
|
||||
/// Forget a file (after it changed on disk, or to retry a file that failed to open).
|
||||
@@ -331,6 +336,7 @@ impl MediaPool {
|
||||
lock(&self.inner.sources).remove(path);
|
||||
lock(&self.inner.models).remove(path);
|
||||
lock(&self.inner.gifs).remove(path);
|
||||
lock(&self.inner.problems).remove(path);
|
||||
let mut c = lock(&self.inner.cache);
|
||||
let keys: Vec<Key> = c.lru.map.keys().filter(|k| &*k.path == path).cloned().collect();
|
||||
for k in keys {
|
||||
@@ -361,8 +367,11 @@ impl MediaPool {
|
||||
Ok(img) => Some(img),
|
||||
// nobody wants the frame any more (`cancellable`): not an error
|
||||
Err(MediaError::Cancelled) => None,
|
||||
// (a movie's failure is logged once per file, when it is recorded)
|
||||
Err(e) => {
|
||||
log::warn!("media: frame of {} at {:?}: {e}", footage.path, t);
|
||||
if lock(&self.inner.problems).get(footage.path.as_str()).is_none() {
|
||||
log::warn!("media: frame of {} at {:?}: {e}", footage.path, t);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -605,7 +614,7 @@ impl Inner {
|
||||
match opened {
|
||||
Ok(s) => Some(s),
|
||||
Err(e) => {
|
||||
log::warn!("media: cannot open {path}: {e}");
|
||||
self.note_problem(path, "", &e);
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -613,6 +622,19 @@ impl Inner {
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Remember why the movie at `path` cannot be shown (`codec` is the footage's, when known)
|
||||
/// and log it the first time. I/O errors (missing or unreadable file) are not decoder
|
||||
/// problems and are left to the missing-footage handling.
|
||||
fn note_problem(&self, path: &Arc<str>, codec: &str, e: &MediaError) {
|
||||
if matches!(e, MediaError::Io(_)) {
|
||||
return;
|
||||
}
|
||||
let reason = describe_problem(codec, e);
|
||||
if lock(&self.problems).insert(path.clone(), reason.clone()).is_none() {
|
||||
log::warn!("media: {path}: {reason}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The decoded frames of the animated GIF or WebP at `path`. The first caller decodes it, outside the
|
||||
/// map's lock; callers asking for the same file meanwhile wait for that.
|
||||
fn gif(&self, path: &Arc<str>) -> Result<Arc<Anim>> {
|
||||
@@ -785,7 +807,10 @@ impl Inner {
|
||||
}
|
||||
Some(mt) => {
|
||||
let (src, turn) = self.opened(path).ok_or_else(|| MediaError::Io(format!("{path}: cannot open")))?;
|
||||
let vf = src.video_frame(FrameRequest::full(filmcraft_time::Tick(mt.0))).map_err(MediaError::from)?;
|
||||
let vf = src
|
||||
.video_frame(FrameRequest::full(filmcraft_time::Tick(mt.0)))
|
||||
.map_err(MediaError::from)
|
||||
.inspect_err(|e| self.note_problem(path, &footage.codec, e))?;
|
||||
// A movie shown turned a quarter (a phone held upright): the footage's size and
|
||||
// the render's are the turned picture's, the decoded frame's are the file's.
|
||||
let side = |(w, h): (u32, u32)| if crate::probe::swaps_sides(turn) { (h, w) } else { (w, h) };
|
||||
@@ -843,6 +868,13 @@ impl FootageSource for MediaPool {
|
||||
self.frame_sized(item, footage, t, size, float)
|
||||
}
|
||||
|
||||
fn problem(&self, footage: &Footage) -> Option<String> {
|
||||
if footage.missing || footage.kind != FootageKind::Video {
|
||||
return None;
|
||||
}
|
||||
lock(&self.inner.problems).get(footage.path.as_str()).cloned()
|
||||
}
|
||||
|
||||
fn vector_frame(&self, _item: ItemId, footage: &Footage, scale: f64) -> Option<Arc<Image>> {
|
||||
if footage.missing || !effectcraft_render::is_vector_footage(footage) {
|
||||
return None;
|
||||
@@ -890,6 +922,20 @@ fn read_stereo(src: &SharedSource, s0: i64, frames: usize, rate: u32) -> std::re
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// The one-line reason a movie shows no picture: its `codec` (the probe's, e.g. "H.264 (High
|
||||
/// 4:2:2)") and what the decoder said, without the error wrappers it passed through.
|
||||
fn describe_problem(codec: &str, e: &MediaError) -> String {
|
||||
let (MediaError::Io(s) | MediaError::Unsupported(s) | MediaError::Decode(s)) = e;
|
||||
let mut detail = s.as_str();
|
||||
let mut unsupported = matches!(e, MediaError::Unsupported(_));
|
||||
while let Some(rest) = ["decode error: ", "unsupported media: ", "unsupported: ", "I/O error: "].iter().find_map(|p| detail.strip_prefix(p)) {
|
||||
unsupported |= detail.starts_with("unsupported");
|
||||
detail = rest;
|
||||
}
|
||||
let what = if codec.is_empty() { "This video" } else { codec };
|
||||
if unsupported { format!("{what} isn't supported by the built-in decoder: {detail}") } else { format!("{what} can't be decoded: {detail}") }
|
||||
}
|
||||
|
||||
fn lock<T>(m: &Mutex<T>) -> std::sync::MutexGuard<'_, T> {
|
||||
m.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
@@ -1044,3 +1044,32 @@ fn a_called_off_read_does_not_decode() {
|
||||
let img = got.expect("decoded once wanted again");
|
||||
assert_eq!((img.width, img.height), (1920, 1080));
|
||||
}
|
||||
|
||||
/// H.264 High 4:2:2 10-bit: the software decoder lacks it; the pool says why, once, and the
|
||||
/// footage reports it (not a black frame without a word).
|
||||
#[test]
|
||||
fn an_unsupported_stream_reports_why_it_shows_no_picture() {
|
||||
let Some(p) = ffmpeg_fixture(
|
||||
"h264_high422_10bit.mp4",
|
||||
&["-f", "lavfi", "-i", "testsrc=size=320x180:rate=24:duration=1", "-c:v", "libx264", "-profile:v", "high422", "-pix_fmt", "yuv422p10le"],
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
let f = probe(&p).expect("probe");
|
||||
let pool = MediaPool::new();
|
||||
assert_eq!(pool.problem(&f), None, "nothing is wrong before a frame was asked for");
|
||||
if pool.frame(ItemId(1), &f, Tick::ZERO).is_some() {
|
||||
// a decoder that handles 4:2:2 (FilmCraft's, or a hardware one): no notice
|
||||
assert_eq!(pool.problem(&f), None);
|
||||
return;
|
||||
}
|
||||
let why = pool.problem(&f).expect("a failed frame leaves a reason");
|
||||
assert!(why.contains("4:2:2"), "names the stream: {why}");
|
||||
assert!(why.contains("isn't supported"), "says it is unsupported: {why}");
|
||||
assert!(!why.contains("decode error"), "no error wrappers: {why}");
|
||||
// it stays for the other frames, and is dropped when the file is forgotten
|
||||
assert!(pool.frame(ItemId(1), &f, Tick::from_seconds_f64(0.5)).is_none());
|
||||
assert_eq!(pool.problem(&f).as_deref(), Some(why.as_str()));
|
||||
pool.forget(&f.path);
|
||||
assert_eq!(pool.problem(&f), None);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user