mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-02 00:11:01 +00:00
dav1ddec: Move decoder init from start() to set_format()
We need a successful LATENCY query to be able to correctly initialise max frame delay, so let's defer decoder init until we know upstream is readier for it. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/698>
This commit is contained in:
parent
05258756ce
commit
5d01bfcb79
1 changed files with 57 additions and 67 deletions
|
@ -25,8 +25,7 @@ const DEFAULT_MAX_FRAME_DELAY: i64 = -1;
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
decoder: dav1d::Decoder,
|
decoder: dav1d::Decoder,
|
||||||
input_state:
|
input_state: gst_video::VideoCodecState<'static, gst_video::video_codec_state::Readable>,
|
||||||
Option<gst_video::VideoCodecState<'static, gst_video::video_codec_state::Readable>>,
|
|
||||||
output_info: Option<gst_video::VideoInfo>,
|
output_info: Option<gst_video::VideoInfo>,
|
||||||
video_meta_supported: bool,
|
video_meta_supported: bool,
|
||||||
n_cpus: usize,
|
n_cpus: usize,
|
||||||
|
@ -161,11 +160,11 @@ impl Dav1dDec {
|
||||||
pic.height()
|
pic.height()
|
||||||
);
|
);
|
||||||
|
|
||||||
let input_state = state.input_state.as_ref().cloned();
|
let input_state = state.input_state.clone();
|
||||||
drop(state_guard);
|
drop(state_guard);
|
||||||
|
|
||||||
let output_state =
|
let output_state =
|
||||||
element.set_output_state(format, pic.width(), pic.height(), input_state.as_ref())?;
|
element.set_output_state(format, pic.width(), pic.height(), Some(&input_state))?;
|
||||||
element.negotiate(output_state)?;
|
element.negotiate(output_state)?;
|
||||||
let out_state = element.output_state().unwrap();
|
let out_state = element.output_state().unwrap();
|
||||||
|
|
||||||
|
@ -668,8 +667,20 @@ impl VideoDecoderImpl for Dav1dDec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
||||||
{
|
{
|
||||||
|
let mut state_guard = self.state.borrow_mut();
|
||||||
|
*state_guard = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.parent_stop(element)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_format(
|
||||||
|
&self,
|
||||||
|
element: &Self::Type,
|
||||||
|
input_state: &gst_video::VideoCodecState<'static, gst_video::video_codec_state::Readable>,
|
||||||
|
) -> Result<(), gst::LoggableError> {
|
||||||
let mut state_guard = self.state.borrow_mut();
|
let mut state_guard = self.state.borrow_mut();
|
||||||
let settings = self.settings.lock().unwrap();
|
let settings = self.settings.lock().unwrap();
|
||||||
let mut decoder_settings = dav1d::Settings::new();
|
let mut decoder_settings = dav1d::Settings::new();
|
||||||
|
@ -703,43 +714,16 @@ impl VideoDecoderImpl for Dav1dDec {
|
||||||
decoder_settings.set_max_frame_delay(max_frame_delay);
|
decoder_settings.set_max_frame_delay(max_frame_delay);
|
||||||
|
|
||||||
let decoder = dav1d::Decoder::with_settings(&decoder_settings).map_err(|err| {
|
let decoder = dav1d::Decoder::with_settings(&decoder_settings).map_err(|err| {
|
||||||
gst::error_msg!(
|
gst::loggable_error!(CAT, "Failed to create decoder instance: {}", err)
|
||||||
gst::LibraryError::Init,
|
|
||||||
["Failed to create decoder instance: {}", err]
|
|
||||||
)
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
*state_guard = Some(State {
|
*state_guard = Some(State {
|
||||||
decoder,
|
decoder,
|
||||||
input_state: None,
|
input_state: input_state.clone(),
|
||||||
output_info: None,
|
output_info: None,
|
||||||
video_meta_supported: false,
|
video_meta_supported: false,
|
||||||
n_cpus,
|
n_cpus,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
self.parent_start(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
|
||||||
{
|
|
||||||
let mut state_guard = self.state.borrow_mut();
|
|
||||||
*state_guard = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.parent_stop(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_format(
|
|
||||||
&self,
|
|
||||||
element: &Self::Type,
|
|
||||||
input_state: &gst_video::VideoCodecState<'static, gst_video::video_codec_state::Readable>,
|
|
||||||
) -> Result<(), gst::LoggableError> {
|
|
||||||
{
|
|
||||||
let mut state_guard = self.state.borrow_mut();
|
|
||||||
let state = state_guard.as_mut().unwrap();
|
|
||||||
state.input_state = Some(input_state.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.parent_set_format(element, input_state)
|
self.parent_set_format(element, input_state)
|
||||||
}
|
}
|
||||||
|
@ -779,9 +763,11 @@ impl VideoDecoderImpl for Dav1dDec {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut state_guard = self.state.borrow_mut();
|
let mut state_guard = self.state.borrow_mut();
|
||||||
|
if state_guard.is_some() {
|
||||||
self.flush_decoder(element, &mut state_guard);
|
self.flush_decoder(element, &mut state_guard);
|
||||||
self.drop_decoded_pictures(element, &mut state_guard);
|
self.drop_decoded_pictures(element, &mut state_guard);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -791,9 +777,11 @@ impl VideoDecoderImpl for Dav1dDec {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut state_guard = self.state.borrow_mut();
|
let mut state_guard = self.state.borrow_mut();
|
||||||
|
if state_guard.is_some() {
|
||||||
self.flush_decoder(element, &mut state_guard);
|
self.flush_decoder(element, &mut state_guard);
|
||||||
let _state_guard = self.forward_pending_pictures(element, state_guard)?;
|
let _state_guard = self.forward_pending_pictures(element, state_guard)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.parent_drain(element)
|
self.parent_drain(element)
|
||||||
}
|
}
|
||||||
|
@ -803,9 +791,11 @@ impl VideoDecoderImpl for Dav1dDec {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut state_guard = self.state.borrow_mut();
|
let mut state_guard = self.state.borrow_mut();
|
||||||
|
if state_guard.is_some() {
|
||||||
self.flush_decoder(element, &mut state_guard);
|
self.flush_decoder(element, &mut state_guard);
|
||||||
let _state_guard = self.forward_pending_pictures(element, state_guard)?;
|
let _state_guard = self.forward_pending_pictures(element, state_guard)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.parent_finish(element)
|
self.parent_finish(element)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue