video: Use static inner lifetime for VideoCodecState<Readable>

It does not borrow from anything else and can be safely stored away.

Only the VideoCodecState<InNegotiation> is actively borrowing from the
element to ensure that it is only modified during negotiation in a safe
way.
This commit is contained in:
Sebastian Dröge 2019-12-23 13:07:05 +02:00
parent d62d788630
commit d2e508eca1
4 changed files with 22 additions and 6 deletions

View file

@ -58,6 +58,14 @@ pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl + Send + Sync + 's
self.parent_set_format(element, state) self.parent_set_format(element, state)
} }
fn set_format_static(
&self,
element: &VideoDecoder,
state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError> {
self.set_format(element, state)
}
fn parse( fn parse(
&self, &self,
element: &VideoDecoder, element: &VideoDecoder,
@ -671,7 +679,7 @@ where
let wrap_state = VideoCodecState::<Readable>::new(state); let wrap_state = VideoCodecState::<Readable>::new(state);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.set_format(&wrap, &wrap_state) { match imp.set_format_static(&wrap, &wrap_state) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&wrap); err.log_with_object(&wrap);

View file

@ -53,6 +53,14 @@ pub trait VideoEncoderImpl: VideoEncoderImplExt + ElementImpl + Send + Sync + 's
self.parent_set_format(element, state) self.parent_set_format(element, state)
} }
fn set_format_static(
&self,
element: &VideoEncoder,
state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError> {
self.set_format(element, state)
}
fn handle_frame( fn handle_frame(
&self, &self,
element: &VideoEncoder, element: &VideoEncoder,
@ -588,7 +596,7 @@ where
let wrap_state = VideoCodecState::<Readable>::new(state); let wrap_state = VideoCodecState::<Readable>::new(state);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.set_format(&wrap, &wrap_state) { match imp.set_format_static(&wrap, &wrap_state) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&wrap); err.log_with_object(&wrap);

View file

@ -57,7 +57,7 @@ pub trait VideoDecoderExtManual: 'static {
fn get_latency(&self) -> (gst::ClockTime, gst::ClockTime); fn get_latency(&self) -> (gst::ClockTime, gst::ClockTime);
fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime); fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime);
fn get_output_state(&self) -> Option<VideoCodecState<Readable>>; fn get_output_state(&self) -> Option<VideoCodecState<'static, Readable>>;
fn set_output_state( fn set_output_state(
&self, &self,
fmt: VideoFormat, fmt: VideoFormat,
@ -233,7 +233,7 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {
} }
} }
fn get_output_state(&self) -> Option<VideoCodecState<Readable>> { fn get_output_state(&self) -> Option<VideoCodecState<'static, Readable>> {
let state = unsafe { let state = unsafe {
gst_video_sys::gst_video_decoder_get_output_state(self.as_ref().to_glib_none().0) gst_video_sys::gst_video_decoder_get_output_state(self.as_ref().to_glib_none().0)
}; };

View file

@ -41,7 +41,7 @@ pub trait VideoEncoderExtManual: 'static {
fn get_latency(&self) -> (gst::ClockTime, gst::ClockTime); fn get_latency(&self) -> (gst::ClockTime, gst::ClockTime);
fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime); fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime);
fn get_output_state(&self) -> Option<VideoCodecState<Readable>>; fn get_output_state(&self) -> Option<VideoCodecState<'static, Readable>>;
fn set_output_state( fn set_output_state(
&self, &self,
caps: gst::Caps, caps: gst::Caps,
@ -166,7 +166,7 @@ impl<O: IsA<VideoEncoder>> VideoEncoderExtManual for O {
} }
} }
fn get_output_state(&self) -> Option<VideoCodecState<Readable>> { fn get_output_state(&self) -> Option<VideoCodecState<'static, Readable>> {
let state = unsafe { let state = unsafe {
gst_video_sys::gst_video_encoder_get_output_state(self.as_ref().to_glib_none().0) gst_video_sys::gst_video_encoder_get_output_state(self.as_ref().to_glib_none().0)
}; };