Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/sync-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ on:
- "crates/enc-mediafoundation/**"
- "crates/timestamp/**"
- "crates/rendering/**"
- "crates/video-decode/**"
- "crates/d3d-adapter/**"
- "crates/render-farm/**"
- "crates/editor/**"
- "crates/export/**"
Expand Down Expand Up @@ -156,6 +158,19 @@ jobs:
cargo test --locked -p cap-rendering -- --nocapture --skip zoom_spring::tests::precompute_cost_is_bounded_for_long_projects --skip decoder::model::
cargo test --locked -p cap-rendering --lib zoom_spring::tests::precompute_cost_is_bounded_for_long_projects -- --exact --nocapture --test-threads=1

# The hosted runner has no video-capable D3D11 adapter, so these tests
# force plain WARP and exercise the software Media Foundation path. The
# required flags turn a missing device or decoder into a failure instead
# of a silent skip.
- name: Media Foundation decoder tests (Windows)
if: runner.os == 'Windows'
shell: bash
env:
CAP_FORCE_WARP_TESTS: "1"
CAP_REQUIRE_D3D11_TESTS: "1"
CAP_REQUIRE_MF_TESTS: "1"
run: cargo test --locked -p cap-video-decode --lib -- --nocapture --test-threads=1

- name: Editor audio playback and export regressions
shell: bash
run: |
Expand Down
50 changes: 9 additions & 41 deletions crates/rendering/src/decoder/media_foundation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,14 @@ impl MFDecoder {
)
},
|data| {
DecodedFrame::new_nv12_with_arc(
DecodedFrame::new_nv12_with_mapped(
data.data,
video_width,
video_height,
data.y_stride,
data.uv_stride,
)
.with_storage_epoch(data.storage_epoch)
.with_matrix(matrix)
},
));
Expand Down Expand Up @@ -246,9 +247,6 @@ impl MFDecoder {
Step::Seek(frame) => match decoder.seek(frame_to_100ns(frame, fps)) {
Ok(()) => {
requests.seeked(frame);
for retired in requests.take_retired() {
decoder.recycle_nv12_buffer(retired.data);
}
Vec::new()
}
Err(e) => {
Expand All @@ -262,15 +260,11 @@ impl MFDecoder {
Ok(Some(sample)) => {
health.record_success(decode_start.elapsed());
let bytes = sample.data.data.len();
let answers = requests.decoded(
requests.decoded(
pts_100ns_to_frame(sample.pts, fps),
sample.data,
bytes,
);
for retired in requests.take_retired() {
decoder.recycle_nv12_buffer(retired.data);
}
answers
)
}
Ok(None) => requests.stopped(),
Err(e) => {
Expand Down Expand Up @@ -324,7 +318,6 @@ struct FrameRequests<T, R> {
// below a frame is the stream's newest sample there.
cache: BTreeMap<u32, (T, usize)>,
cache_bytes: usize,
retired: Vec<T>,
waiting: Vec<(u32, R)>,
seeked_to: Option<u32>,
readahead_frames: u32,
Expand All @@ -336,7 +329,6 @@ impl<T: Clone, R> FrameRequests<T, R> {
Self {
cache: BTreeMap::new(),
cache_bytes: 0,
retired: Vec::new(),
waiting: Vec::new(),
seeked_to: None,
readahead_frames,
Expand Down Expand Up @@ -411,19 +403,11 @@ impl<T: Clone, R> FrameRequests<T, R> {
}

fn seeked(&mut self, frame: u32) {
self.retired.extend(
std::mem::take(&mut self.cache)
.into_values()
.map(|(sample, _)| sample),
);
self.cache.clear();
self.cache_bytes = 0;
self.seeked_to = Some(frame);
}

fn take_retired(&mut self) -> Vec<T> {
std::mem::take(&mut self.retired)
}

// A waiting frame the decoder jumped past has no sample at or below it since the seek, so
// it gets the first one after.
fn decoded(&mut self, frame: u32, sample: T, bytes: usize) -> Vec<Answer<T, R>> {
Expand All @@ -439,17 +423,15 @@ impl<T: Clone, R> FrameRequests<T, R> {
})
.collect();

if let Some((replaced, bytes)) = self.cache.remove(&frame) {
self.retired.push(replaced);
self.cache_bytes -= bytes;
if let Some((_, replaced)) = self.cache.remove(&frame) {
self.cache_bytes -= replaced;
}
while !self.cache.is_empty()
&& (self.cache.len() >= FRAME_CACHE_SIZE
|| self.cache_bytes + bytes > MAX_FRAME_CACHE_BYTES)
{
if let Some((_, (evicted, bytes))) = self.cache.pop_first() {
self.retired.push(evicted);
self.cache_bytes -= bytes;
if let Some((_, (_, evicted))) = self.cache.pop_first() {
self.cache_bytes -= evicted;
}
}
self.cache.insert(frame, (sample, bytes));
Expand Down Expand Up @@ -488,20 +470,6 @@ mod tests {
assert_eq!(pts_100ns_to_frame(10_000_000, 30), 30);
}

#[test]
fn cache_replacements_evictions_and_seeks_retire_samples() {
let mut requests = FrameRequests::<usize, ()>::new(0);
requests.decoded(0, 1, 1);
requests.decoded(0, 2, 1);
assert_eq!(requests.take_retired(), [1]);

requests.decoded(1, 3, MAX_FRAME_CACHE_BYTES);
assert_eq!(requests.take_retired(), [2]);

requests.seeked(10);
assert_eq!(requests.take_retired(), [3]);
}

// Samples are their index in `frames`, which holds the frame each one rounds to.
struct FakeStream {
frames: Vec<u32>,
Expand Down
Loading
Loading