Skip to content

Commit e552530

Browse files
authored
dedicated handle-needs-input error (#1057)
* dedicated handle-needs-input error * use error enum
1 parent 1e2e94b commit e552530

File tree

1 file changed

+31
-7
lines changed
  • crates/enc-mediafoundation/src/video

1 file changed

+31
-7
lines changed

crates/enc-mediafoundation/src/video/h264.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ pub enum NewVideoEncoderError {
7878
InputType(windows::core::Error),
7979
}
8080

81+
#[derive(Clone, Debug, thiserror::Error)]
82+
pub enum HandleNeedsInputError {
83+
#[error("ProcessTexture: {0}")]
84+
ProcessTexture(windows::core::Error),
85+
#[error("CreateSurfaceBuffer: {0}")]
86+
CreateSurfaceBuffer(windows::core::Error),
87+
#[error("CreateSample: {0}")]
88+
CreateSample(windows::core::Error),
89+
#[error("AddBuffer: {0}")]
90+
AddBuffer(windows::core::Error),
91+
#[error("SetSampleTime: {0}")]
92+
SetSampleTime(windows::core::Error),
93+
#[error("ProcessInput: {0}")]
94+
ProcessInput(windows::core::Error),
95+
}
96+
8197
unsafe impl Send for H264Encoder {}
8298

8399
impl H264Encoder {
@@ -349,8 +365,10 @@ impl H264Encoder {
349365
&mut self,
350366
texture: &ID3D11Texture2D,
351367
timestamp: TimeSpan,
352-
) -> windows::core::Result<()> {
353-
self.video_processor.process_texture(texture)?;
368+
) -> Result<(), HandleNeedsInputError> {
369+
self.video_processor
370+
.process_texture(texture)
371+
.map_err(HandleNeedsInputError::ProcessTexture)?;
354372

355373
let first_time = self.first_time.get_or_insert(timestamp);
356374

@@ -360,14 +378,20 @@ impl H264Encoder {
360378
self.video_processor.output_texture(),
361379
0,
362380
false,
363-
)?
381+
)
382+
.map_err(HandleNeedsInputError::CreateSurfaceBuffer)?
364383
};
365-
let mf_sample = unsafe { MFCreateSample()? };
384+
let mf_sample = unsafe { MFCreateSample().map_err(HandleNeedsInputError::CreateSample)? };
366385
unsafe {
367-
mf_sample.AddBuffer(&input_buffer)?;
368-
mf_sample.SetSampleTime(timestamp.Duration - first_time.Duration)?;
386+
mf_sample
387+
.AddBuffer(&input_buffer)
388+
.map_err(HandleNeedsInputError::AddBuffer)?;
389+
mf_sample
390+
.SetSampleTime(timestamp.Duration - first_time.Duration)
391+
.map_err(HandleNeedsInputError::SetSampleTime)?;
369392
self.transform
370-
.ProcessInput(self.input_stream_id, &mf_sample, 0)?;
393+
.ProcessInput(self.input_stream_id, &mf_sample, 0)
394+
.map_err(HandleNeedsInputError::ProcessInput)?;
371395
};
372396
Ok(())
373397
}

0 commit comments

Comments
 (0)