Fix various warnings from clippy 1.50

This commit is contained in:
Sebastian Dröge 2021-02-09 18:57:34 +02:00
parent f63c4284c1
commit cbda137fbf
11 changed files with 101 additions and 210 deletions

View file

@ -139,7 +139,7 @@ impl State {
gst::Buffer::from_mut_slice(sealed) gst::Buffer::from_mut_slice(sealed)
} }
fn encrypt_blocks(&mut self, block_size: usize) -> Result<BufferVec, gst::FlowError> { fn encrypt_blocks(&mut self, block_size: usize) -> BufferVec {
assert_ne!(block_size, 0); assert_ne!(block_size, 0);
let mut buffers = BufferVec::new(); let mut buffers = BufferVec::new();
@ -154,7 +154,7 @@ impl State {
buffers.push(out_buf); buffers.push(out_buf);
} }
Ok(buffers) buffers
} }
} }
@ -193,19 +193,7 @@ impl Encrypter {
state.adapter.push(buffer); state.adapter.push(buffer);
// Encrypt the whole blocks, if any, and push them. // Encrypt the whole blocks, if any, and push them.
buffers.extend( buffers.extend(state.encrypt_blocks(state.block_size as usize));
state
.encrypt_blocks(state.block_size as usize)
.map_err(|err| {
// log the error to the bus
gst::element_error!(
element,
gst::ResourceError::Write,
["Failed to decrypt buffer"]
);
err
})?,
);
drop(state_guard); drop(state_guard);
@ -245,17 +233,8 @@ impl Encrypter {
assert!(avail < state.block_size as usize); assert!(avail < state.block_size as usize);
if avail > 0 { if avail > 0 {
match state.encrypt_blocks(avail) { let b = state.encrypt_blocks(avail);
Err(_) => { buffers.extend(b);
gst::element_error!(
element,
gst::ResourceError::Write,
["Failed to encrypt buffers at EOS"]
);
return false;
}
Ok(b) => buffers.extend(b),
}
} }
// drop the lock before pushing into the pad // drop the lock before pushing into the pad

View file

@ -383,13 +383,11 @@ static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
}); });
impl InputSelector { impl InputSelector {
fn unprepare(&self, element: &super::InputSelector) -> Result<(), ()> { fn unprepare(&self, element: &super::InputSelector) {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
gst_debug!(CAT, obj: element, "Unpreparing"); gst_debug!(CAT, obj: element, "Unpreparing");
*state = State::default(); *state = State::default();
gst_debug!(CAT, obj: element, "Unprepared"); gst_debug!(CAT, obj: element, "Unprepared");
Ok(())
} }
} }
@ -574,7 +572,7 @@ impl ElementImpl for InputSelector {
gst_trace!(CAT, obj: element, "Changing state {:?}", transition); gst_trace!(CAT, obj: element, "Changing state {:?}", transition);
if let gst::StateChange::ReadyToNull = transition { if let gst::StateChange::ReadyToNull = transition {
self.unprepare(element).map_err(|_| gst::StateChangeError)?; self.unprepare(element);
} }
let mut success = self.parent_change_state(element, transition)?; let mut success = self.parent_change_state(element, transition)?;

View file

@ -655,22 +655,12 @@ impl Transcriber {
}, },
EventView::FlushStart(_) => { EventView::FlushStart(_) => {
gst_info!(CAT, obj: element, "Received flush start, disconnecting"); gst_info!(CAT, obj: element, "Received flush start, disconnecting");
match self.disconnect(element) { self.disconnect(element);
Err(err) => {
element.post_error_message(err);
false
}
Ok(_) => {
let mut ret = pad.event_default(Some(element), event); let mut ret = pad.event_default(Some(element), event);
match self.srcpad.stop_task() { match self.srcpad.stop_task() {
Err(err) => { Err(err) => {
gst_error!( gst_error!(CAT, obj: element, "Failed to stop srcpad task: {}", err);
CAT,
obj: element,
"Failed to stop srcpad task: {}",
err
);
ret = false; ret = false;
} }
Ok(_) => (), Ok(_) => (),
@ -678,8 +668,6 @@ impl Transcriber {
ret ret
} }
}
}
EventView::FlushStop(_) => { EventView::FlushStop(_) => {
gst_info!(CAT, obj: element, "Received flush stop, restarting task"); gst_info!(CAT, obj: element, "Received flush stop, restarting task");
@ -946,7 +934,7 @@ impl Transcriber {
Ok(()) Ok(())
} }
fn disconnect(&self, element: &super::Transcriber) -> Result<(), gst::ErrorMessage> { fn disconnect(&self, element: &super::Transcriber) {
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
gst_info!(CAT, obj: element, "Unpreparing"); gst_info!(CAT, obj: element, "Unpreparing");
@ -967,8 +955,6 @@ impl Transcriber {
"Unprepared, connected: {}!", "Unprepared, connected: {}!",
state.connected state.connected
); );
Ok(())
} }
} }
@ -1173,10 +1159,7 @@ impl ElementImpl for Transcriber {
match transition { match transition {
gst::StateChange::PausedToReady => { gst::StateChange::PausedToReady => {
self.disconnect(element).map_err(|err| { self.disconnect(element);
element.post_error_message(err);
gst::StateChangeError
})?;
} }
_ => (), _ => (),
} }

View file

@ -60,8 +60,8 @@ impl S3Src {
}; };
} }
fn connect(self: &S3Src, url: &GstS3Url) -> Result<S3Client, gst::ErrorMessage> { fn connect(self: &S3Src, url: &GstS3Url) -> S3Client {
Ok(S3Client::new(url.region.clone())) S3Client::new(url.region.clone())
} }
fn set_uri(self: &S3Src, _: &super::S3Src, url_str: Option<&str>) -> Result<(), glib::Error> { fn set_uri(self: &S3Src, _: &super::S3Src, url_str: Option<&str>) -> Result<(), glib::Error> {
@ -345,7 +345,7 @@ impl BaseSrcImpl for S3Src {
} }
}; };
let s3client = self.connect(&s3url)?; let s3client = self.connect(&s3url);
let size = self.head(src, &s3client, &s3url)?; let size = self.head(src, &s3client, &s3url)?;
*state = StreamingState::Started { *state = StreamingState::Started {

View file

@ -300,7 +300,7 @@ impl JsonGstParse {
state = self.state.lock().unwrap(); state = self.state.lock().unwrap();
} else { } else {
state = self.handle_skipped_line(element, pts, state)?; state = self.handle_skipped_line(element, pts, state);
} }
} }
Ok(Some(Line::Header { format })) => { Ok(Some(Line::Header { format })) => {
@ -343,7 +343,7 @@ impl JsonGstParse {
element: &super::JsonGstParse, element: &super::JsonGstParse,
pts: gst::ClockTime, pts: gst::ClockTime,
mut state: MutexGuard<State>, mut state: MutexGuard<State>,
) -> Result<MutexGuard<State>, gst::FlowError> { ) -> MutexGuard<State> {
if pts >= state.segment.get_start() { if pts >= state.segment.get_start() {
state.seeking = false; state.seeking = false;
state.discont = true; state.discont = true;
@ -355,7 +355,7 @@ impl JsonGstParse {
drop(state); drop(state);
Ok(self.state.lock().unwrap()) self.state.lock().unwrap()
} }
fn sink_activate( fn sink_activate(

View file

@ -158,7 +158,7 @@ impl ElementImpl for CustomSource {
match transition { match transition {
gst::StateChange::ReadyToNull => { gst::StateChange::ReadyToNull => {
self.stop(element)?; self.stop(element);
} }
_ => (), _ => (),
} }
@ -177,9 +177,7 @@ impl BinImpl for CustomSource {
// TODO: Drop stream collection message for now, we only create a simple custom // TODO: Drop stream collection message for now, we only create a simple custom
// one here so that fallbacksrc can know about our streams. It is never // one here so that fallbacksrc can know about our streams. It is never
// forwarded. // forwarded.
if let Err(msg) = self.handle_source_no_more_pads(&bin) { self.handle_source_no_more_pads(&bin);
bin.post_error_message(msg);
}
} }
_ => self.parent_handle_message(bin, msg), _ => self.parent_handle_message(bin, msg),
} }
@ -222,10 +220,7 @@ impl CustomSource {
} }
if !has_sometimes_pads { if !has_sometimes_pads {
if let Err(msg) = self.handle_source_no_more_pads(&element) { self.handle_source_no_more_pads(&element);
element.post_error_message(msg);
return Err(gst::StateChangeError);
}
} else { } else {
gst_debug!(CAT, obj: element, "Found sometimes pads"); gst_debug!(CAT, obj: element, "Found sometimes pads");
@ -249,9 +244,7 @@ impl CustomSource {
}; };
let src = CustomSource::from_instance(&element); let src = CustomSource::from_instance(&element);
if let Err(msg) = src.handle_source_pad_removed(&element, pad) { src.handle_source_pad_removed(&element, pad);
element.post_error_message(msg);
}
}); });
let element_weak = element.downgrade(); let element_weak = element.downgrade();
@ -262,9 +255,7 @@ impl CustomSource {
}; };
let src = CustomSource::from_instance(&element); let src = CustomSource::from_instance(&element);
if let Err(msg) = src.handle_source_no_more_pads(&element) { src.handle_source_no_more_pads(&element);
element.post_error_message(msg);
}
}); });
} }
@ -347,11 +338,7 @@ impl CustomSource {
Ok(()) Ok(())
} }
fn handle_source_pad_removed( fn handle_source_pad_removed(&self, element: &super::CustomSource, pad: &gst::Pad) {
&self,
element: &super::CustomSource,
pad: &gst::Pad,
) -> Result<(), gst::ErrorMessage> {
gst_debug!(CAT, obj: element, "Source removed pad {}", pad.get_name()); gst_debug!(CAT, obj: element, "Source removed pad {}", pad.get_name());
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
@ -361,7 +348,7 @@ impl CustomSource {
.enumerate() .enumerate()
.find(|(_i, p)| &p.source_pad == pad) .find(|(_i, p)| &p.source_pad == pad)
{ {
None => return Ok(()), None => return,
Some(v) => v, Some(v) => v,
}; };
@ -372,14 +359,9 @@ impl CustomSource {
ghost_pad.set_active(false).unwrap(); ghost_pad.set_active(false).unwrap();
let _ = ghost_pad.set_target(None::<&gst::Pad>); let _ = ghost_pad.set_target(None::<&gst::Pad>);
let _ = element.remove_pad(&ghost_pad); let _ = element.remove_pad(&ghost_pad);
Ok(())
} }
fn handle_source_no_more_pads( fn handle_source_no_more_pads(&self, element: &super::CustomSource) {
&self,
element: &super::CustomSource,
) -> Result<(), gst::ErrorMessage> {
gst_debug!(CAT, obj: element, "Source signalled no-more-pads"); gst_debug!(CAT, obj: element, "Source signalled no-more-pads");
let state = self.state.lock().unwrap(); let state = self.state.lock().unwrap();
@ -400,14 +382,9 @@ impl CustomSource {
.src(element) .src(element)
.build(), .build(),
); );
Ok(())
} }
fn stop( fn stop(&self, element: &super::CustomSource) {
&self,
element: &super::CustomSource,
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
gst_debug!(CAT, obj: element, "Stopping"); gst_debug!(CAT, obj: element, "Stopping");
let mut state = self.state.lock().unwrap(); let mut state = self.state.lock().unwrap();
@ -420,7 +397,5 @@ impl CustomSource {
let _ = pad.ghost_pad.set_target(None::<&gst::Pad>); let _ = pad.ghost_pad.set_target(None::<&gst::Pad>);
let _ = element.remove_pad(&pad.ghost_pad); let _ = element.remove_pad(&pad.ghost_pad);
} }
Ok(gst::StateChangeSuccess::Success)
} }
} }

View file

@ -640,7 +640,7 @@ impl ElementImpl for FallbackSrc {
// Change the source state manually here to be able to catch errors. State changes always // Change the source state manually here to be able to catch errors. State changes always
// happen from sink to source, so we do this after chaining up. // happen from sink to source, so we do this after chaining up.
self.change_source_state(element, transition)?; self.change_source_state(element, transition);
// Ignore parent state change return to prevent spurious async/no-preroll return values // Ignore parent state change return to prevent spurious async/no-preroll return values
// due to core state change bugs // due to core state change bugs
@ -649,7 +649,7 @@ impl ElementImpl for FallbackSrc {
Ok(gst::StateChangeSuccess::NoPreroll) Ok(gst::StateChangeSuccess::NoPreroll)
} }
gst::StateChange::ReadyToNull => { gst::StateChange::ReadyToNull => {
self.stop(element)?; self.stop(element);
Ok(gst::StateChangeSuccess::Success) Ok(gst::StateChangeSuccess::Success)
} }
_ => Ok(gst::StateChangeSuccess::Success), _ => Ok(gst::StateChangeSuccess::Success),
@ -689,7 +689,7 @@ impl FallbackSrc {
element: &super::FallbackSrc, element: &super::FallbackSrc,
source: &Source, source: &Source,
buffer_duration: i64, buffer_duration: i64,
) -> Result<gst::Element, gst::StateChangeError> { ) -> gst::Element {
let source = match source { let source = match source {
Source::Uri(ref uri) => { Source::Uri(ref uri) => {
let source = gst::ElementFactory::make("uridecodebin3", Some("uridecodebin")) let source = gst::ElementFactory::make("uridecodebin3", Some("uridecodebin"))
@ -741,14 +741,12 @@ impl FallbackSrc {
}; };
let src = FallbackSrc::from_instance(&element); let src = FallbackSrc::from_instance(&element);
if let Err(msg) = src.handle_source_pad_removed(&element, pad) { src.handle_source_pad_removed(&element, pad);
element.post_error_message(msg);
}
}); });
element.add_many(&[&source]).unwrap(); element.add_many(&[&source]).unwrap();
Ok(source) source
} }
fn create_fallback_video_input( fn create_fallback_video_input(
@ -756,14 +754,11 @@ impl FallbackSrc {
_element: &super::FallbackSrc, _element: &super::FallbackSrc,
min_latency: u64, min_latency: u64,
fallback_uri: Option<&str>, fallback_uri: Option<&str>,
) -> Result<gst::Element, gst::StateChangeError> { ) -> gst::Element {
Ok(VideoFallbackSource::new(fallback_uri, min_latency).upcast()) VideoFallbackSource::new(fallback_uri, min_latency).upcast()
} }
fn create_fallback_audio_input( fn create_fallback_audio_input(&self, _element: &super::FallbackSrc) -> gst::Element {
&self,
_element: &super::FallbackSrc,
) -> Result<gst::Element, gst::StateChangeError> {
let input = gst::Bin::new(Some("fallback_audio")); let input = gst::Bin::new(Some("fallback_audio"));
let audiotestsrc = gst::ElementFactory::make("audiotestsrc", Some("fallback_audiosrc")) let audiotestsrc = gst::ElementFactory::make("audiotestsrc", Some("fallback_audiosrc"))
.expect("No audiotestsrc found"); .expect("No audiotestsrc found");
@ -781,7 +776,7 @@ impl FallbackSrc {
) )
.unwrap(); .unwrap();
Ok(input.upcast()) input.upcast()
} }
fn create_stream( fn create_stream(
@ -791,11 +786,11 @@ impl FallbackSrc {
min_latency: u64, min_latency: u64,
is_audio: bool, is_audio: bool,
fallback_uri: Option<&str>, fallback_uri: Option<&str>,
) -> Result<Stream, gst::StateChangeError> { ) -> Stream {
let fallback_input = if is_audio { let fallback_input = if is_audio {
self.create_fallback_audio_input(element)? self.create_fallback_audio_input(element)
} else { } else {
self.create_fallback_video_input(element, min_latency, fallback_uri)? self.create_fallback_video_input(element, min_latency, fallback_uri)
}; };
let switch = let switch =
@ -865,7 +860,7 @@ impl FallbackSrc {
element.add_pad(&ghostpad).unwrap(); element.add_pad(&ghostpad).unwrap();
Ok(Stream { Stream {
fallback_input, fallback_input,
source_srcpad: None, source_srcpad: None,
source_srcpad_block: None, source_srcpad_block: None,
@ -874,7 +869,7 @@ impl FallbackSrc {
clocksync_queue, clocksync_queue,
switch, switch,
srcpad: ghostpad.upcast(), srcpad: ghostpad.upcast(),
}) }
} }
fn start(&self, element: &super::FallbackSrc) -> Result<(), gst::StateChangeError> { fn start(&self, element: &super::FallbackSrc) -> Result<(), gst::StateChangeError> {
@ -907,8 +902,7 @@ impl FallbackSrc {
let fallback_uri = &settings.fallback_uri; let fallback_uri = &settings.fallback_uri;
// Create main input // Create main input
let source = let source = self.create_main_input(element, &configured_source, settings.buffer_duration);
self.create_main_input(element, &configured_source, settings.buffer_duration)?;
let mut flow_combiner = gst_base::UniqueFlowCombiner::new(); let mut flow_combiner = gst_base::UniqueFlowCombiner::new();
@ -920,7 +914,7 @@ impl FallbackSrc {
settings.min_latency, settings.min_latency,
false, false,
fallback_uri.as_deref(), fallback_uri.as_deref(),
)?; );
flow_combiner.add_pad(&stream.srcpad); flow_combiner.add_pad(&stream.srcpad);
Some(stream) Some(stream)
} else { } else {
@ -930,7 +924,7 @@ impl FallbackSrc {
// Create audio stream // Create audio stream
let audio_stream = if settings.enable_audio { let audio_stream = if settings.enable_audio {
let stream = let stream =
self.create_stream(element, settings.timeout, settings.min_latency, true, None)?; self.create_stream(element, settings.timeout, settings.min_latency, true, None);
flow_combiner.add_pad(&stream.srcpad); flow_combiner.add_pad(&stream.srcpad);
Some(stream) Some(stream)
} else { } else {
@ -964,12 +958,12 @@ impl FallbackSrc {
Ok(()) Ok(())
} }
fn stop(&self, element: &super::FallbackSrc) -> Result<(), gst::StateChangeError> { fn stop(&self, element: &super::FallbackSrc) {
gst_debug!(CAT, obj: element, "Stopping"); gst_debug!(CAT, obj: element, "Stopping");
let mut state_guard = self.state.lock().unwrap(); let mut state_guard = self.state.lock().unwrap();
let mut state = match state_guard.take() { let mut state = match state_guard.take() {
Some(state) => state, Some(state) => state,
None => return Ok(()), None => return,
}; };
drop(state_guard); drop(state_guard);
@ -1018,19 +1012,14 @@ impl FallbackSrc {
} }
gst_debug!(CAT, obj: element, "Stopped"); gst_debug!(CAT, obj: element, "Stopped");
Ok(())
} }
fn change_source_state( fn change_source_state(&self, element: &super::FallbackSrc, transition: gst::StateChange) {
&self,
element: &super::FallbackSrc,
transition: gst::StateChange,
) -> Result<(), gst::StateChangeError> {
gst_debug!(CAT, obj: element, "Changing source state: {:?}", transition); gst_debug!(CAT, obj: element, "Changing source state: {:?}", transition);
let mut state_guard = self.state.lock().unwrap(); let mut state_guard = self.state.lock().unwrap();
let state = match &mut *state_guard { let state = match &mut *state_guard {
Some(state) => state, Some(state) => state,
None => return Ok(()), None => return,
}; };
if transition.current() <= transition.next() && state.source_pending_restart { if transition.current() <= transition.next() && state.source_pending_restart {
@ -1039,7 +1028,7 @@ impl FallbackSrc {
obj: element, obj: element,
"Not starting source because pending restart" "Not starting source because pending restart"
); );
return Ok(()); return;
} else if transition.next() <= gst::State::Ready && state.source_pending_restart { } else if transition.next() <= gst::State::Ready && state.source_pending_restart {
gst_debug!( gst_debug!(
CAT, CAT,
@ -1094,8 +1083,6 @@ impl FallbackSrc {
} }
} }
} }
Ok(())
} }
fn proxy_pad_chain( fn proxy_pad_chain(
@ -1610,11 +1597,7 @@ impl FallbackSrc {
} }
} }
fn handle_source_pad_removed( fn handle_source_pad_removed(&self, element: &super::FallbackSrc, pad: &gst::Pad) {
&self,
element: &super::FallbackSrc,
pad: &gst::Pad,
) -> Result<(), gst::ErrorMessage> {
gst_debug!( gst_debug!(
CAT, CAT,
obj: element, obj: element,
@ -1625,7 +1608,7 @@ impl FallbackSrc {
let mut state_guard = self.state.lock().unwrap(); let mut state_guard = self.state.lock().unwrap();
let state = match &mut *state_guard { let state = match &mut *state_guard {
None => { None => {
return Ok(()); return;
} }
Some(state) => state, Some(state) => state,
}; };
@ -1646,7 +1629,7 @@ impl FallbackSrc {
{ {
stream stream
} else { } else {
return Ok(()); return;
}; };
stream.source_srcpad = None; stream.source_srcpad = None;
@ -1655,8 +1638,6 @@ impl FallbackSrc {
drop(state_guard); drop(state_guard);
element.notify("status"); element.notify("status");
Ok(())
} }
fn handle_buffering(&self, element: &super::FallbackSrc, m: &gst::message::Buffering) { fn handle_buffering(&self, element: &super::FallbackSrc, m: &gst::message::Buffering) {
@ -1992,13 +1973,11 @@ impl FallbackSrc {
// See https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/746 // See https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/746
element.remove(&state.source).unwrap(); element.remove(&state.source).unwrap();
let source = src let source = src.create_main_input(
.create_main_input(
element, element,
&state.configured_source, &state.configured_source,
state.settings.buffer_duration, state.settings.buffer_duration,
) );
.expect("failed to create new source");
( (
source.clone(), source.clone(),

View file

@ -204,7 +204,7 @@ impl ElementImpl for VideoFallbackSource {
match transition { match transition {
gst::StateChange::ReadyToNull => { gst::StateChange::ReadyToNull => {
self.stop(element)?; self.stop(element);
} }
_ => (), _ => (),
} }
@ -220,9 +220,10 @@ impl BinImpl for VideoFallbackSource {
match msg.view() { match msg.view() {
MessageView::Error(err) => { MessageView::Error(err) => {
if !self if self
.got_error .got_error
.compare_and_swap(false, true, Ordering::SeqCst) .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.is_err()
{ {
gst_warning!(CAT, obj: bin, "Got error {:?}", err); gst_warning!(CAT, obj: bin, "Got error {:?}", err);
self.parent_handle_message(bin, msg) self.parent_handle_message(bin, msg)
@ -283,7 +284,7 @@ impl VideoFallbackSource {
element: &super::VideoFallbackSource, element: &super::VideoFallbackSource,
min_latency: u64, min_latency: u64,
uri: Option<&str>, uri: Option<&str>,
) -> Result<gst::Element, gst::StateChangeError> { ) -> gst::Element {
gst_debug!(CAT, obj: element, "Creating source with uri {:?}", uri); gst_debug!(CAT, obj: element, "Creating source with uri {:?}", uri);
let source = gst::Bin::new(None); let source = gst::Bin::new(None);
@ -440,7 +441,7 @@ impl VideoFallbackSource {
) )
.unwrap(); .unwrap();
Ok(source.upcast()) source.upcast()
} }
fn start( fn start(
@ -457,7 +458,7 @@ impl VideoFallbackSource {
let settings = self.settings.lock().unwrap().clone(); let settings = self.settings.lock().unwrap().clone();
let uri = &settings.uri; let uri = &settings.uri;
let source = self.create_source(element, settings.min_latency, uri.as_deref())?; let source = self.create_source(element, settings.min_latency, uri.as_deref());
element.add(&source).unwrap(); element.add(&source).unwrap();
@ -469,16 +470,13 @@ impl VideoFallbackSource {
Ok(gst::StateChangeSuccess::Success) Ok(gst::StateChangeSuccess::Success)
} }
fn stop( fn stop(&self, element: &super::VideoFallbackSource) {
&self,
element: &super::VideoFallbackSource,
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
gst_debug!(CAT, obj: element, "Stopping"); gst_debug!(CAT, obj: element, "Stopping");
let mut state_guard = self.state.lock().unwrap(); let mut state_guard = self.state.lock().unwrap();
let state = match state_guard.take() { let state = match state_guard.take() {
Some(state) => state, Some(state) => state,
None => return Ok(gst::StateChangeSuccess::Success), None => return,
}; };
drop(state_guard); drop(state_guard);
@ -488,7 +486,5 @@ impl VideoFallbackSource {
element.remove(&state.source).unwrap(); element.remove(&state.source).unwrap();
self.got_error.store(false, Ordering::Relaxed); self.got_error.store(false, Ordering::Relaxed);
gst_debug!(CAT, obj: element, "Stopped"); gst_debug!(CAT, obj: element, "Stopped");
Ok(gst::StateChangeSuccess::Success)
} }
} }

View file

@ -214,14 +214,11 @@ impl VideoDecoderImpl for CdgDec {
.is_some() .is_some()
{ {
let pools = allocation.get_allocation_pools(); let pools = allocation.get_allocation_pools();
if let Some((ref pool, _, _, _)) = pools.first() { if let Some((Some(ref pool), _, _, _)) = pools.first() {
if let Some(pool) = pool {
let mut config = pool.get_config(); let mut config = pool.get_config();
config.add_option(&gst_video::BUFFER_POOL_OPTION_VIDEO_META); config.add_option(&gst_video::BUFFER_POOL_OPTION_VIDEO_META);
pool.set_config(config).map_err(|e| { pool.set_config(config)
gst::error_msg!(gst::CoreError::Negotiation, [&e.message]) .map_err(|e| gst::error_msg!(gst::CoreError::Negotiation, [&e.message]))?;
})?;
}
} }
} }
} }

View file

@ -494,18 +494,15 @@ impl VideoDecoderImpl for Dav1dDec {
.is_some() .is_some()
{ {
let pools = allocation.get_allocation_pools(); let pools = allocation.get_allocation_pools();
if let Some((ref pool, _, _, _)) = pools.first() { if let Some((Some(ref pool), _, _, _)) = pools.first() {
if let Some(pool) = pool {
let mut config = pool.get_config(); let mut config = pool.get_config();
config.add_option(&gst_video::BUFFER_POOL_OPTION_VIDEO_META); config.add_option(&gst_video::BUFFER_POOL_OPTION_VIDEO_META);
pool.set_config(config).map_err(|e| { pool.set_config(config)
gst::error_msg!(gst::CoreError::Negotiation, [&e.message]) .map_err(|e| gst::error_msg!(gst::CoreError::Negotiation, [&e.message]))?;
})?;
self.negotiation_infos.lock().unwrap().video_meta_supported = true; self.negotiation_infos.lock().unwrap().video_meta_supported = true;
} }
} }
} }
}
self.parent_decide_allocation(element, query) self.parent_decide_allocation(element, query)
} }

View file

@ -149,7 +149,10 @@ impl ObjectSubclass for FlvDemux {
"Panic activating sink pad with mode" "Panic activating sink pad with mode"
)) ))
}, },
|demux, element| demux.sink_activatemode(pad, element, mode, active), |demux, element| {
demux.sink_activatemode(pad, element, mode, active);
Ok(())
},
) )
}) })
.chain_function(|pad, parent, buffer| { .chain_function(|pad, parent, buffer| {
@ -332,12 +335,9 @@ impl FlvDemux {
element: &super::FlvDemux, element: &super::FlvDemux,
mode: gst::PadMode, mode: gst::PadMode,
active: bool, active: bool,
) -> Result<(), gst::LoggableError> { ) {
if active { if active {
self.start(element, mode).map_err(|err| { self.start(element, mode);
element.post_error_message(err);
gst::loggable_error!(CAT, "Failed to start element with mode {:?}", mode)
})?;
if mode == gst::PadMode::Pull { if mode == gst::PadMode::Pull {
// TODO implement pull mode // TODO implement pull mode
@ -349,26 +349,15 @@ impl FlvDemux {
let _ = self.sinkpad.stop_task(); let _ = self.sinkpad.stop_task();
} }
self.stop(element).map_err(|err| { self.stop(element);
element.post_error_message(err); }
gst::loggable_error!(CAT, "Failed to stop element")
})?;
} }
Ok(()) fn start(&self, _element: &super::FlvDemux, _mode: gst::PadMode) {
}
fn start(
&self,
_element: &super::FlvDemux,
_mode: gst::PadMode,
) -> Result<(), gst::ErrorMessage> {
*self.state.lock().unwrap() = State::NeedHeader; *self.state.lock().unwrap() = State::NeedHeader;
Ok(())
} }
fn stop(&self, element: &super::FlvDemux) -> Result<(), gst::ErrorMessage> { fn stop(&self, element: &super::FlvDemux) {
*self.state.lock().unwrap() = State::Stopped; *self.state.lock().unwrap() = State::Stopped;
self.adapter.lock().unwrap().clear(); self.adapter.lock().unwrap().clear();
@ -384,8 +373,6 @@ impl FlvDemux {
} }
flow_combiner.reset(); flow_combiner.reset();
Ok(())
} }
fn sink_event(&self, pad: &gst::Pad, element: &super::FlvDemux, event: gst::Event) -> bool { fn sink_event(&self, pad: &gst::Pad, element: &super::FlvDemux, event: gst::Event) -> bool {
@ -753,7 +740,7 @@ impl StreamingState {
flavors::TagType::Script => { flavors::TagType::Script => {
gst_trace!(CAT, obj: element, "Found script tag"); gst_trace!(CAT, obj: element, "Found script tag");
self.handle_script_tag(element, &tag_header, adapter) Ok(self.handle_script_tag(element, &tag_header, adapter))
} }
flavors::TagType::Audio => { flavors::TagType::Audio => {
gst_trace!(CAT, obj: element, "Found audio tag"); gst_trace!(CAT, obj: element, "Found audio tag");
@ -774,7 +761,7 @@ impl StreamingState {
element: &super::FlvDemux, element: &super::FlvDemux,
tag_header: &flavors::TagHeader, tag_header: &flavors::TagHeader,
adapter: &mut gst_base::UniqueAdapter, adapter: &mut gst_base::UniqueAdapter,
) -> Result<SmallVec<[Event; 4]>, gst::ErrorMessage> { ) -> SmallVec<[Event; 4]> {
assert!(adapter.available() >= tag_header.data_size as usize); assert!(adapter.available() >= tag_header.data_size as usize);
let mut events = SmallVec::new(); let mut events = SmallVec::new();
@ -827,14 +814,14 @@ impl StreamingState {
drop(data); drop(data);
adapter.flush(tag_header.data_size as usize); adapter.flush(tag_header.data_size as usize);
Ok(events) events
} }
fn update_audio_stream( fn update_audio_stream(
&mut self, &mut self,
element: &super::FlvDemux, element: &super::FlvDemux,
data_header: &flavors::AudioDataHeader, data_header: &flavors::AudioDataHeader,
) -> Result<SmallVec<[Event; 4]>, gst::ErrorMessage> { ) -> SmallVec<[Event; 4]> {
let mut events = SmallVec::new(); let mut events = SmallVec::new();
gst_trace!( gst_trace!(
@ -871,7 +858,7 @@ impl StreamingState {
events.push(Event::HaveAllStreams); events.push(Event::HaveAllStreams);
} }
Ok(events) events
} }
fn handle_aac_audio_packet_header( fn handle_aac_audio_packet_header(
@ -953,7 +940,7 @@ impl StreamingState {
drop(data); drop(data);
adapter.flush(1); adapter.flush(1);
let mut events = self.update_audio_stream(element, &data_header)?; let mut events = self.update_audio_stream(element, &data_header);
// AAC special case // AAC special case
if data_header.sound_format == flavors::SoundFormat::AAC if data_header.sound_format == flavors::SoundFormat::AAC
@ -1004,7 +991,7 @@ impl StreamingState {
&mut self, &mut self,
element: &super::FlvDemux, element: &super::FlvDemux,
data_header: &flavors::VideoDataHeader, data_header: &flavors::VideoDataHeader,
) -> Result<SmallVec<[Event; 4]>, gst::ErrorMessage> { ) -> SmallVec<[Event; 4]> {
let mut events = SmallVec::new(); let mut events = SmallVec::new();
gst_trace!( gst_trace!(
@ -1041,7 +1028,7 @@ impl StreamingState {
events.push(Event::HaveAllStreams); events.push(Event::HaveAllStreams);
} }
Ok(events) events
} }
fn handle_avc_video_packet_header( fn handle_avc_video_packet_header(
@ -1134,7 +1121,7 @@ impl StreamingState {
drop(data); drop(data);
adapter.flush(1); adapter.flush(1);
let mut events = self.update_video_stream(element, &data_header)?; let mut events = self.update_video_stream(element, &data_header);
// AVC/H264 special case // AVC/H264 special case
let cts = if data_header.codec_id == flavors::CodecId::H264 { let cts = if data_header.codec_id == flavors::CodecId::H264 {