Skip to content
Open
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
21 changes: 10 additions & 11 deletions crates/enc-mediafoundation/src/video/h264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,22 @@ impl H264Encoder {
// (e.g., hardware encoder transient failures, specific MFT implementations).
// This is a known contract violation by certain Media Foundation Transforms.
// We handle this gracefully by skipping the frame instead of panicking.
let sample = {
let mut output_buffers = [output_buffer];
self.transform
.ProcessOutput(0, &mut output_buffers, &mut status)?;
output_buffers[0].pSample.as_ref().cloned()
};
let mut output_buffers = [output_buffer];
self.transform.ProcessOutput(0, &mut output_buffers, &mut status)?;

if let Some(sample) = sample {
// Use the sample directly without cloning to prevent memory leaks
if let Some(sample) = output_buffers[0].pSample.take() {
consecutive_empty_samples = 0;
on_sample(sample)?;
} else {
consecutive_empty_samples += 1;
if consecutive_empty_samples > MAX_CONSECUTIVE_EMPTY_SAMPLES {
return Err(windows::core::Error::new(
windows::core::HRESULT(0),
"Too many consecutive empty samples",
));
return Err(
windows::core::Error::new(
windows::core::HRESULT(0),
"Too many consecutive empty samples"
)
);
Comment on lines +448 to +453
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use a proper error HRESULT instead of 0.

HRESULT(0) represents S_OK (success), which is semantically incorrect for an error condition. Consider using a standard error code like E_FAIL or E_UNEXPECTED to properly indicate failure.

Apply this diff:

-                                return Err(
-                                    windows::core::Error::new(
-                                        windows::core::HRESULT(0),
-                                        "Too many consecutive empty samples"
-                                    )
-                                );
+                                return Err(windows::core::Error::new(
+                                    windows::Win32::Foundation::E_FAIL,
+                                    "Too many consecutive empty samples",
+                                ));
🤖 Prompt for AI Agents
In crates/enc-mediafoundation/src/video/h264.rs around lines 448 to 453, the
code constructs an error using windows::core::HRESULT(0) (which is S_OK).
Replace the zero HRESULT with a proper failure code (for example
windows::Win32::Foundation::E_FAIL or E_UNEXPECTED) when creating the
windows::core::Error; update imports if necessary so the chosen HRESULT constant
is available and use that constant when constructing the Error to correctly
indicate failure.

}
}
}
Expand Down