mirror of
https://github.com/storytold/soundcraft.git
synced 2026-12-02 20:22:27 -05:00
Tests: assert the H.264 release request budget
This commit is contained in:
1 parent
9365546f0c
commit
c0d7ac3064
2 files changed
+14
-8
No files matched your search
@@ -148,7 +148,7 @@ pub struct Movie {
|
||||
pub decoded: u64,
|
||||
/// Unit tests can shrink the workload without bypassing the request guard.
|
||||
#[cfg(test)]
|
||||
pub(crate) max_request_bytes: usize,
|
||||
pub(crate) request_bytes_override: Option<usize>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Movie {
|
||||
@@ -287,7 +287,7 @@ impl Movie {
|
||||
thumbs: Lru::new(256),
|
||||
decoded: 0,
|
||||
#[cfg(test)]
|
||||
max_request_bytes: Self::MAX_REQUEST_BYTES,
|
||||
request_bytes_override: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -488,6 +488,15 @@ impl Movie {
|
||||
/// at most 16, so a stream that produces nothing for this long will produce nothing.
|
||||
const MAX_SAMPLES_WITHOUT_PICTURE: usize = 256;
|
||||
|
||||
/// The request budget: [`Self::MAX_REQUEST_BYTES`], or a smaller one a unit test sets.
|
||||
pub(crate) fn max_request_bytes(&self) -> usize {
|
||||
#[cfg(test)]
|
||||
if let Some(bytes) = self.request_bytes_override {
|
||||
return bytes;
|
||||
}
|
||||
Self::MAX_REQUEST_BYTES
|
||||
}
|
||||
|
||||
fn decode_h264(&mut self, index: usize) -> Result<Arc<Frame>> {
|
||||
let Codec::H264 { avcc } = &self.codec else { return Err(VideoError::Unsupported("not H.264".into())) };
|
||||
let target = self.order.get(index).copied().ok_or(VideoError::OutOfRange)?;
|
||||
@@ -503,10 +512,7 @@ impl Movie {
|
||||
}
|
||||
let total = self.order.len();
|
||||
let mut last_err: Option<String> = None;
|
||||
#[cfg(not(test))]
|
||||
let max_request_bytes = Self::MAX_REQUEST_BYTES;
|
||||
#[cfg(test)]
|
||||
let max_request_bytes = self.max_request_bytes;
|
||||
let max_request_bytes = self.max_request_bytes();
|
||||
let (mut fed, mut without_picture) = (0usize, 0usize);
|
||||
// Bounded: each iteration feeds one sample, or flushes once at the end.
|
||||
for _ in 0..=total.saturating_add(1) {
|
||||
|
||||
@@ -182,8 +182,8 @@ fn one_frame_request_reads_a_bounded_amount_of_samples() {
|
||||
}
|
||||
let src = Arc::new(PaddedSource { bytes, len: 3 << 30, largest: AtomicUsize::new(0), reads: AtomicUsize::new(0) });
|
||||
let mut m = Movie::open_source(src.clone()).unwrap();
|
||||
assert_eq!(m.max_request_bytes, 2 << 30);
|
||||
m.max_request_bytes = 64 * SAMPLE_BYTES as usize;
|
||||
assert_eq!(m.max_request_bytes(), 2 << 30);
|
||||
m.request_bytes_override = Some(64 * SAMPLE_BYTES as usize);
|
||||
src.reads.store(0, Ordering::Relaxed); // Don't count reads made when opening the movie.
|
||||
let r = m.frame(64);
|
||||
assert!(matches!(&r, Err(VideoError::Decode(e)) if e.contains("needs more than 2048 MiB of samples")), "{r:?}");
|
||||
|
||||
Reference in new issue
Block a user