Add read-only "recording" property to togglerecord

This signals whether we are actually recording currently or not.
This commit is contained in:
Sebastian Dröge 2017-12-06 14:10:01 +02:00
parent 8873821340
commit 63380e023a

View file

@ -45,7 +45,7 @@ impl Default for Settings {
}
}
static PROPERTIES: [Property; 1] = [
static PROPERTIES: [Property; 2] = [
Property::Boolean(
"record",
"Record",
@ -53,6 +53,13 @@ static PROPERTIES: [Property; 1] = [
DEFAULT_RECORD,
PropertyMutability::ReadWrite,
),
Property::Boolean(
"recording",
"Recording",
"Whether recording is currently taking place",
DEFAULT_RECORD,
PropertyMutability::Readable,
),
];
#[derive(Clone)]
@ -321,6 +328,7 @@ impl ToggleRecord {
fn handle_main_stream(
&self,
element: &Element,
pad: &gst::Pad,
stream: &Stream,
is_keyframe: bool,
@ -456,6 +464,11 @@ impl ToggleRecord {
// Then become Stopped and drop this buffer. We always stop right before
// a keyframe
gst_log!(self.cat, obj: pad, "Dropping buffer (stopped)");
drop(rec_state);
drop(state);
self.notify(&element.clone().upcast(), "recording");
HandleResult::Drop
}
RecordingState::Stopped => {
@ -513,6 +526,11 @@ impl ToggleRecord {
);
gst_log!(self.cat, obj: pad, "Passing buffer (recording)");
drop(rec_state);
drop(state);
self.notify(&element.clone().upcast(), "recording");
HandleResult::Pass
}
}
@ -798,6 +816,7 @@ impl ToggleRecord {
}
self.handle_main_stream(
element,
pad,
&stream,
!buffer.get_flags().contains(gst::BufferFlags::DELTA_UNIT),
@ -968,7 +987,7 @@ impl ToggleRecord {
gst_debug!(self.cat, obj: pad, "Handling Gap event {:?}", event);
let (pts, duration) = e.get();
let handle_result = if stream == self.main_stream {
self.handle_main_stream(pad, &stream, false, pts, duration)
self.handle_main_stream(element, pad, &stream, false, pts, duration)
} else {
self.handle_secondary_stream(pad, &stream, pts, duration)
};
@ -1242,6 +1261,10 @@ impl ObjectImpl<Element> for ToggleRecord {
let settings = self.settings.lock().unwrap();
Ok(settings.record.to_value())
}
Property::Boolean("recording", ..) => {
let rec_state = self.state.lock().unwrap();
Ok((rec_state.recording_state == RecordingState::Recording).to_value())
}
_ => unimplemented!(),
}
}
@ -1290,17 +1313,24 @@ impl ElementImpl<Element> for ToggleRecord {
}
match transition {
gst::StateChange::PausedToReady => for s in self.other_streams
.lock()
.unwrap()
.0
.iter()
.chain(iter::once(&self.main_stream))
{
let mut state = s.state.lock().unwrap();
gst::StateChange::PausedToReady => {
for s in self.other_streams
.lock()
.unwrap()
.0
.iter()
.chain(iter::once(&self.main_stream))
{
let mut state = s.state.lock().unwrap();
state.pending_events.clear();
},
state.pending_events.clear();
}
let mut rec_state = self.state.lock().unwrap();
*rec_state = State::default();
drop(rec_state);
self.notify(&element.clone().upcast(), "recording");
}
_ => (),
}