Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sdroege/gst-plugin-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Laignel <fengalin@free.fr>2021-05-25 17:37:48 +0300
committerFrançois Laignel <fengalin@free.fr>2021-06-05 11:36:21 +0300
commit17feaa8c71a1915e57d05311fe8c1deedb5b97a1 (patch)
tree3b23a29e1aa5da7dc9bacfe720e8fdb06218f589 /audio/csound
parent8dfc872544b26aa5eaf4b12da7d9c5e0361467ca (diff)
audio: migrate to new ClockTime design
Diffstat (limited to 'audio/csound')
-rw-r--r--audio/csound/examples/effect_example.rs2
-rw-r--r--audio/csound/src/filter/imp.rs18
-rw-r--r--audio/csound/tests/csound_filter.rs38
3 files changed, 34 insertions, 24 deletions
diff --git a/audio/csound/examples/effect_example.rs b/audio/csound/examples/effect_example.rs
index 2f8b78ab..050a1680 100644
--- a/audio/csound/examples/effect_example.rs
+++ b/audio/csound/examples/effect_example.rs
@@ -106,7 +106,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Box<dyn Error>> {
.bus()
.expect("Pipeline without bus. Shouldn't happen!");
- for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
+ for msg in bus.iter_timed(gst::ClockTime::NONE) {
use gst::MessageView;
match msg.view() {
diff --git a/audio/csound/src/filter/imp.rs b/audio/csound/src/filter/imp.rs
index 08d207ad..b3c649ae 100644
--- a/audio/csound/src/filter/imp.rs
+++ b/audio/csound/src/filter/imp.rs
@@ -103,11 +103,13 @@ impl State {
self.adapter.available() < self.spin_capacity()
}
- fn samples_to_time(&self, samples: u64) -> gst::ClockTime {
- gst::ClockTime(samples.mul_div_round(gst::SECOND_VAL, self.in_info.rate() as u64))
+ fn samples_to_time(&self, samples: u64) -> Option<gst::ClockTime> {
+ samples
+ .mul_div_round(*gst::ClockTime::SECOND, self.in_info.rate() as u64)
+ .map(gst::ClockTime::from_nseconds)
}
- fn current_pts(&self) -> gst::ClockTime {
+ fn current_pts(&self) -> Option<gst::ClockTime> {
// get the last seen pts and the amount of bytes
// since then
let (prev_pts, distance) = self.adapter.prev_pts();
@@ -117,10 +119,12 @@ impl State {
// can be added to the prev_pts to get the
// pts at the beginning of the adapter.
let samples = distance / self.in_info.bpf() as u64;
- prev_pts + self.samples_to_time(samples)
+ prev_pts
+ .zip(self.samples_to_time(samples))
+ .map(|(prev_pts, time_offset)| prev_pts + time_offset)
}
- fn buffer_duration(&self, buffer_size: u64) -> gst::ClockTime {
+ fn buffer_duration(&self, buffer_size: u64) -> Option<gst::ClockTime> {
let samples = buffer_size / self.out_info.bpf() as u64;
self.samples_to_time(samples)
}
@@ -265,8 +269,8 @@ impl CsoundFilter {
CAT,
obj: element,
"Generating output at: {} - duration: {}",
- pts,
- duration
+ pts.display(),
+ duration.display(),
);
// Get the required amount of bytes to be read from
diff --git a/audio/csound/tests/csound_filter.rs b/audio/csound/tests/csound_filter.rs
index 16907a4d..0cce0ad3 100644
--- a/audio/csound/tests/csound_filter.rs
+++ b/audio/csound/tests/csound_filter.rs
@@ -73,8 +73,10 @@ fn build_harness(src_caps: gst::Caps, sink_caps: gst::Caps, csd: &str) -> gst_ch
h
}
-fn duration_from_samples(num_samples: u64, rate: u64) -> gst::ClockTime {
- gst::ClockTime(num_samples.mul_div_round(gst::SECOND_VAL, rate))
+fn duration_from_samples(num_samples: u64, rate: u64) -> Option<gst::ClockTime> {
+ num_samples
+ .mul_div_round(*gst::ClockTime::SECOND, rate)
+ .map(gst::ClockTime::from_nseconds)
}
// This test verifies the well functioning of the EOS logic,
@@ -116,15 +118,16 @@ fn csound_filter_eos() {
h.play();
// The input buffer pts and duration
- let mut in_pts = gst::ClockTime::zero();
- let in_duration = duration_from_samples(EOS_NUM_SAMPLES as _, sr as _);
+ let mut in_pts = gst::ClockTime::ZERO;
+ let in_duration = duration_from_samples(EOS_NUM_SAMPLES as _, sr as _)
+ .expect("duration defined because sr is > 0");
// The number of samples that were leftover during the previous iteration
let mut samples_offset = 0;
// Output samples and buffers counters
let mut num_samples: usize = 0;
let mut num_buffers = 0;
// The expected pts of output buffers
- let mut expected_pts = gst::ClockTime::zero();
+ let mut expected_pts = gst::ClockTime::ZERO;
for _ in 0..EOS_NUM_BUFFERS {
let mut buffer =
@@ -149,13 +152,14 @@ fn csound_filter_eos() {
buffer.as_ref().duration(),
duration_from_samples(in_process_samples, sr as _)
);
- assert_eq!(buffer.as_ref().pts(), expected_pts);
+ assert_eq!(buffer.as_ref().pts(), Some(expected_pts));
// Get the number of samples that were not processed
samples_offset = in_samples % ksmps as u64;
// Calculates the next output buffer timestamp
- expected_pts =
- in_pts + duration_from_samples(EOS_NUM_SAMPLES as u64 - samples_offset, sr as _);
+ expected_pts = in_pts
+ + duration_from_samples(EOS_NUM_SAMPLES as u64 - samples_offset, sr as _)
+ .expect("duration defined because sr is > 0");
// Calculates the next input buffer timestamp
in_pts += in_duration;
@@ -177,7 +181,7 @@ fn csound_filter_eos() {
let samples_at_eos = (EOS_NUM_BUFFERS * EOS_NUM_SAMPLES) % ksmps;
assert_eq!(
buffer.as_ref().pts(),
- in_pts - duration_from_samples(samples_at_eos as _, sr as _)
+ duration_from_samples(samples_at_eos as _, sr as _).map(|duration| in_pts - duration)
);
let map = buffer.into_mapped_buffer_readable().unwrap();
@@ -226,8 +230,9 @@ fn csound_filter_underflow() {
h.play();
// Input buffers timestamp
- let mut in_pts = gst::ClockTime::zero();
- let in_samples_duration = duration_from_samples(UNDERFLOW_NUM_SAMPLES as _, sr as _);
+ let mut in_pts = gst::ClockTime::ZERO;
+ let in_samples_duration = duration_from_samples(UNDERFLOW_NUM_SAMPLES as _, sr as _)
+ .expect("duration defined because sr is > 0");
for _ in 0..UNDERFLOW_NUM_BUFFERS {
let mut buffer =
@@ -247,21 +252,22 @@ fn csound_filter_underflow() {
let mut num_buffers = 0;
let mut num_samples = 0;
- let expected_duration = duration_from_samples(UNDERFLOW_NUM_SAMPLES as u64 * 2, sr as _);
+ let expected_duration = duration_from_samples(UNDERFLOW_NUM_SAMPLES as u64 * 2, sr as _)
+ .expect("duration defined because sr is > 0");
let expected_buffers = UNDERFLOW_NUM_BUFFERS / 2;
- let mut expected_pts = gst::ClockTime::zero();
+ let mut expected_pts = gst::ClockTime::ZERO;
for _ in 0..expected_buffers {
let buffer = h.pull().unwrap();
let samples = buffer.size() / std::mem::size_of::<f64>();
- assert_eq!(buffer.as_ref().pts(), expected_pts);
- assert_eq!(buffer.as_ref().duration(), expected_duration);
+ assert_eq!(buffer.as_ref().pts(), Some(expected_pts));
+ assert_eq!(buffer.as_ref().duration(), Some(expected_duration));
assert_eq!(samples, UNDERFLOW_NUM_SAMPLES * 2);
// Output data is produced after 2 input buffers
// so that, the next output buffer's PTS should be
// equal to the last PTS plus the duration of 2 input buffers
- expected_pts += in_samples_duration * 2;
+ expected_pts += 2 * in_samples_duration;
num_buffers += 1;
num_samples += samples;