Skip to content

Commit

Permalink
Fixed decoder needing flush in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepbansal authored and ralfbiedert committed Oct 15, 2022
1 parent a6edb04 commit ac13495
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions openh264/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::Error;
use openh264_sys2::{
videoFormatI420, ISVCDecoder, ISVCDecoderVtbl, SBufferInfo, SDecodingParam, SParserBsInfo, SSysMEMBuffer, WelsCreateDecoder,
WelsDestroyDecoder, DECODER_OPTION, DECODER_OPTION_ERROR_CON_IDC, DECODER_OPTION_NUM_OF_THREADS, DECODER_OPTION_TRACE_LEVEL,
DECODING_STATE, WELS_LOG_DETAIL, WELS_LOG_QUIET,
DECODING_STATE, WELS_LOG_DETAIL, WELS_LOG_QUIET, DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER,
};
use std::os::raw::{c_int, c_long, c_uchar, c_void};
use std::ptr::{addr_of_mut, null, null_mut};
Expand Down Expand Up @@ -186,8 +186,17 @@ impl Decoder {
.decode_frame_no_delay(packet.as_ptr(), packet.len() as i32, &mut dst as *mut _, &mut buffer_info)
.ok()?;

if !buffer_info.iBufferStatus == 1 {
return Err(Error::msg("Buffer status not valid"));
if buffer_info.iBufferStatus != 1 {
let mut num_frames: DECODER_OPTION = 0;
self.raw_api().get_option(DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER,
addr_of_mut!(num_frames).cast()).ok()?;
if num_frames > 0 {
self.raw_api().flush_frame(&mut dst as *mut _, &mut buffer_info).ok()?;

if buffer_info.iBufferStatus != 1 {
return Err(Error::msg("Buffer status not valid"));
}
}
}

let info = buffer_info.UsrData.sSystemBuffer;
Expand Down

0 comments on commit ac13495

Please sign in to comment.