Skip to main content

moq_ext_player/player/
audio.rs

1//! The player's audio task: one rendition into the player's output.
2
3use std::{
4    borrow::Cow,
5    collections::VecDeque,
6    sync::Arc,
7    time::{Duration, Instant},
8};
9
10#[cfg(feature = "playback")]
11use moq_audio::playback;
12use moq_ext_sources::{AudioFormat, ByPtr, Error, SlotState, send_if_changed};
13use moq_mux::container::Delay;
14use n0_future::task::{AbortOnDropHandle, spawn};
15use tokio::sync::{broadcast, watch};
16use tracing::{Instrument, debug, info, info_span, warn};
17
18use super::{Controls, PlaybackRecorder, PlayerStatus, PlayoutClock, clock::AudioClock};
19use crate::{
20    RemoteBroadcast,
21    clean_close::CleanClose as _,
22    stats::{AudioPlaybackStats, FrameTiming, MediaKind},
23};
24
25/// How long after audio ended or failed the catalog is read again.
26const RETRY_AFTER: Duration = Duration::from_secs(2);
27
28/// How far the speaker may fall behind the playout clock before it skips.
29///
30/// Within this, the speaker slows down for a short buffer. Past it, the
31/// speaker skips the audio that trails.
32#[cfg(feature = "playback")]
33const STRETCH: Duration = Duration::from_secs(2);
34
35/// How many decoded frames an [`AudioFrames`] reader may fall behind before it skips.
36///
37/// One second of 20 ms Opus frames.
38pub(crate) const AUDIO_FRAMES_BACKLOG: usize = 50;
39
40/// How much decoded audio [`AudioPlaybackStats::rms`] is measured across.
41const LEVEL_WINDOW: Duration = Duration::from_millis(100);
42
43/// How long after the last decoded frame the audio level reads as unknown.
44pub(crate) const LEVEL_STALE: Duration = Duration::from_millis(300);
45
46/// One block of decoded audio, from [`Player::audio_frames`](crate::Player::audio_frames).
47#[derive(Debug, Clone)]
48pub struct AudioFrame {
49    /// The presentation timestamp of the first sample, on the publisher's broadcast clock.
50    pub timestamp: moq_net::Timestamp,
51    /// The sample rate and the channel layout of [`samples`](Self::samples).
52    pub format: AudioFormat,
53    /// The samples, interleaved, from -1.0 to 1.0.
54    pub samples: Arc<[f32]>,
55}
56
57impl AudioFrame {
58    /// Returns how long the frame plays.
59    #[must_use]
60    pub fn duration(&self) -> Duration {
61        play_length(self.format, self.samples.len())
62    }
63}
64
65/// Returns how long `samples` interleaved samples of `format` play.
66fn play_length(format: AudioFormat, samples: usize) -> Duration {
67    let per_channel = samples / format.layout.channels().max(1) as usize;
68    Duration::from_secs_f64(per_channel as f64 / f64::from(format.sample_rate.max(1)))
69}
70
71/// The decoded audio of a player, in the order it decodes.
72///
73/// Returned by [`Player::audio_frames`](crate::Player::audio_frames). Each
74/// handle reads every frame decoded after it was created. A handle that falls
75/// more than a second behind loses the oldest frames, so the decoder never
76/// waits for a reader.
77#[derive(Debug)]
78pub struct AudioFrames {
79    rx: broadcast::Receiver<AudioFrame>,
80}
81
82impl AudioFrames {
83    /// Creates a handle that reads what `tx` sends from now on.
84    pub(crate) fn new(tx: &broadcast::Sender<AudioFrame>) -> Self {
85        Self { rx: tx.subscribe() }
86    }
87
88    /// Waits for the next decoded frame.
89    ///
90    /// Frames decoded before the player was dropped are still returned, up to
91    /// the backlog a handle keeps. Returns `None` once the player is dropped
92    /// and this handle has read them. Cancellation safe.
93    pub async fn next(&mut self) -> Option<AudioFrame> {
94        loop {
95            match self.rx.recv().await {
96                Ok(frame) => return Some(frame),
97                Err(broadcast::error::RecvError::Lagged(skipped)) => {
98                    debug!(skipped, "an audio frames reader fell behind and skipped");
99                }
100                Err(broadcast::error::RecvError::Closed) => return None,
101            }
102        }
103    }
104}
105
106/// The audio task's inputs.
107pub(crate) struct Inputs {
108    pub broadcast: RemoteBroadcast,
109    /// The speaker, or `None` to decode without playing.
110    #[cfg(feature = "playback")]
111    pub speaker: Option<playback::Engine>,
112    /// Where each decoded frame goes, for [`AudioFrames`] readers.
113    pub frames: broadcast::Sender<AudioFrame>,
114    pub controls: Arc<Controls>,
115    pub status: watch::Sender<PlayerStatus>,
116    pub clock: PlayoutClock,
117    pub stats: PlaybackRecorder,
118}
119
120/// Plays the broadcast's audio until the player is dropped or the broadcast closes.
121///
122/// Reopens on a new catalog or a new route. Audio then follows a publisher
123/// that restarts its microphone, and a subscription that changes path.
124pub(crate) async fn run(inputs: Inputs) {
125    let Inputs {
126        broadcast,
127        #[cfg(feature = "playback")]
128        speaker,
129        frames,
130        controls,
131        status,
132        clock,
133        stats,
134    } = inputs;
135    let mut catalog = broadcast.catalog();
136    let mut epoch = broadcast.epoch();
137    let mut volume = controls.volume.subscribe();
138
139    loop {
140        // What to play: the first audio rendition, over the current route.
141        let opened = {
142            let known = catalog.borrow_and_update().clone();
143            let consumer = epoch.borrow_and_update().consumer.clone();
144            known.zip(consumer).and_then(|(known, consumer)| {
145                let (name, config) = known.audio.renditions.first_key_value()?;
146                Some((name.clone(), config.clone(), consumer))
147            })
148        };
149        let mut reader = match opened {
150            Some((name, config, consumer)) => {
151                send_if_changed(&status, |status| status.audio = SlotState::Starting);
152                let delay = *controls.latency.borrow();
153                let opened: Result<Job, Error> = async {
154                    let decoder = open(&name, &config, &consumer, delay).await?;
155                    let format = AudioFormat {
156                        sample_rate: decoder.sample_rate(),
157                        layout: decoder.layout(),
158                    };
159                    #[cfg(feature = "playback")]
160                    let sink = speaker
161                        .as_ref()
162                        .map(|engine| sink(engine, format))
163                        .transpose()?;
164                    Ok(Job {
165                        name: name.clone(),
166                        format,
167                        frames: frames.clone(),
168                        decoder,
169                        #[cfg(feature = "playback")]
170                        sink,
171                        clock: clock.register_audio(),
172                        level: LevelMeter::default(),
173                        #[cfg(feature = "playback")]
174                        target: Target {
175                            latency: controls.latency.subscribe(),
176                            floor: delay.min.unwrap_or_default(),
177                            catalog: broadcast.catalog(),
178                        },
179                        stats: stats.clone(),
180                    })
181                }
182                .await;
183                match opened {
184                    Ok(job) => {
185                        let control = job.control();
186                        set_volume(control.as_ref(), *volume.borrow());
187                        info!(rendition = %name, "audio playing");
188                        send_if_changed(&status, |status| status.audio = SlotState::Running);
189                        Some((
190                            AbortOnDropHandle::new(spawn(
191                                job.run()
192                                    .instrument(info_span!("decode", rendition = %name)),
193                            )),
194                            control,
195                        ))
196                    }
197                    // The session closed while the track opened. The epoch
198                    // or the catalog changes next, or the broadcast closes,
199                    // and nothing failed.
200                    Err(err @ Error::Closed { .. }) => {
201                        debug!(error = %err, rendition = %name, "audio closed before it opened");
202                        send_if_changed(&status, |status| status.audio = SlotState::Ended);
203                        None
204                    }
205                    Err(err) => {
206                        warn!(error = format_args!("{err:#}"), rendition = %name, "audio failed to open");
207                        send_if_changed(&status, |status| {
208                            status.audio = SlotState::Failed(ByPtr::new(err))
209                        });
210                        None
211                    }
212                }
213            }
214            None => None,
215        };
216
217        // Wait for the reader to end, or for a reason to reopen. Without a
218        // reader, the catalog is also read again after a pause. A publisher
219        // that replaced its audio may have sent the new catalog before the old
220        // track ended here, and no later update follows.
221        let mut retry = std::pin::pin!(tokio::time::sleep(RETRY_AFTER));
222        loop {
223            let reading = reader.is_some();
224            tokio::select! {
225                // The task holds the broadcast, so the watches below never
226                // close, and only this tells it that nothing comes back.
227                () = broadcast.closed() => {
228                    debug!("the broadcast closed, so the audio is over");
229                    drop(reader);
230                    stats.audio.update(|audio| *audio = None);
231                    send_if_changed(&status, |status| {
232                        if matches!(status.audio, SlotState::Running | SlotState::Starting) {
233                            status.audio = SlotState::Ended;
234                        }
235                    });
236                    return;
237                }
238                result = async { (&mut reader.as_mut().expect("guarded").0).await }, if reading => {
239                    reader = None;
240                    stats.audio.update(|audio| *audio = None);
241                    retry.as_mut().reset(tokio::time::Instant::now() + RETRY_AFTER);
242                    match result {
243                        Ok(Ok(())) => send_if_changed(&status, |status| status.audio = SlotState::Ended),
244                        Ok(Err(err)) => {
245                            warn!(error = format_args!("{err:#}"), "audio stopped");
246                            send_if_changed(&status, |status| status.audio = SlotState::Failed(ByPtr::new(err)));
247                        }
248                        Err(err) => warn!(error = %err, "the audio task panicked"),
249                    }
250                }
251                changed = catalog.changed() => {
252                    if changed.is_err() {
253                        return;
254                    }
255                    // A running track keeps playing across a catalog update.
256                    // Only a track that ended or never opened is tried again.
257                    if !reading {
258                        break;
259                    }
260                }
261                changed = epoch.changed() => {
262                    if changed.is_err() {
263                        return;
264                    }
265                    debug!("the broadcast moved to a new route, reopening audio");
266                    break;
267                }
268                () = &mut retry, if !reading => break,
269                changed = volume.changed() => {
270                    if changed.is_err() {
271                        return;
272                    }
273                    if let Some((_, control)) = &reader {
274                        set_volume(control.as_ref(), *volume.borrow());
275                    }
276                }
277            }
278        }
279    }
280}
281
282/// Opens the decoder for one rendition.
283async fn open(
284    name: &str,
285    config: &hang::catalog::AudioConfig,
286    consumer: &moq_net::broadcast::Consumer,
287    delay: Delay,
288) -> Result<moq_audio::decode::Consumer, Error> {
289    let mut options = moq_audio::decode::Options::new();
290    options.output.format = moq_audio::Format::F32;
291    options.delay = delay;
292    // Start at the live edge. The backlog a track holds is behind it.
293    options.start = moq_audio::decode::Start::Latest;
294    let decoder = moq_audio::decode::Consumer::new(consumer, config, name, options)
295        .await
296        .map_err(|err| {
297            if err.is_clean_close() {
298                n0_error::e!(Error::Closed)
299            } else {
300                Error::decoder(err)
301            }
302        })?;
303    Ok(decoder)
304}
305
306/// Adds a stream to the speaker's mix, taking PCM in `format`.
307#[cfg(feature = "playback")]
308fn sink(engine: &playback::Engine, format: AudioFormat) -> Result<playback::Sink, Error> {
309    let mut input = playback::Input::default();
310    input.format = moq_audio::Format::F32;
311    input.sample_rate = format.sample_rate;
312    input.layout = format.layout;
313    engine.sink(input).map_err(Error::device)
314}
315
316/// Sets the gain of a speaker stream, where 1.0 is unattenuated.
317fn set_volume(control: Option<&Control>, volume: f32) {
318    #[cfg(feature = "playback")]
319    if let Some(control) = control {
320        control.set_volume(volume);
321    }
322    #[cfg(not(feature = "playback"))]
323    let _ = (control, volume);
324}
325
326/// The gain and level handle of a speaker stream.
327#[cfg(feature = "playback")]
328type Control = playback::Control;
329/// No speaker stream exists without the `playback` feature.
330#[cfg(not(feature = "playback"))]
331type Control = std::convert::Infallible;
332
333/// One rendition being decoded into the output.
334struct Job {
335    name: String,
336    /// What the decoder delivers: interleaved `f32` at its own rate and layout.
337    format: AudioFormat,
338    /// Where each decoded frame goes, for [`AudioFrames`] readers.
339    frames: broadcast::Sender<AudioFrame>,
340    decoder: moq_audio::decode::Consumer,
341    /// The stream into the speaker, `None` when the audio is only decoded.
342    #[cfg(feature = "playback")]
343    sink: Option<playback::Sink>,
344    /// The audio path's hold on the playout clock.
345    clock: AudioClock,
346    /// The level of the decoded audio, for the stats.
347    level: LevelMeter,
348    /// What the audio's playout target follows.
349    #[cfg(feature = "playback")]
350    target: Target,
351    stats: PlaybackRecorder,
352}
353
354/// What the audio's playout target follows besides the decoder.
355#[cfg(feature = "playback")]
356struct Target {
357    /// The latency asked for now, which may differ from the one the decoder opened with.
358    latency: watch::Receiver<Delay>,
359    /// The latency minimum the decoder opened with, which floors its measured target.
360    floor: Duration,
361    /// The catalog, for the rendition's `delay`.
362    catalog: watch::Receiver<Option<Arc<hang::catalog::Catalog>>>,
363}
364
365#[cfg(feature = "playback")]
366impl Target {
367    /// Returns the playout delay the audio asks the clock for, given the decoder's measured `target`.
368    ///
369    /// A measured target at the decoder's floor says only that the jitter is
370    /// no larger, so it does not hold a lower latency asked for since.
371    fn get(&self, rendition: &str, measured: Duration) -> Duration {
372        let delay = self
373            .catalog
374            .borrow()
375            .as_ref()
376            .and_then(|catalog| catalog.audio.renditions.get(rendition))
377            .and_then(|config| config.delay);
378        let measured = Some(measured).filter(|measured| *measured > self.floor);
379        super::track_target(&self.latency.borrow(), delay, measured)
380    }
381}
382
383impl Job {
384    /// Decodes until the track ends or is closed.
385    ///
386    /// The read is the only await, and only the task's end cancels it. The
387    /// decoder is never polled again after a dropped read.
388    async fn run(mut self) -> Result<(), Error> {
389        self.stats.audio.update(|audio| {
390            *audio = Some(AudioPlaybackStats {
391                rendition: self.name.clone(),
392                ..AudioPlaybackStats::default()
393            });
394        });
395        loop {
396            let read = match self.decoder.read().await {
397                Ok(Some(read)) => read,
398                Ok(None) => break,
399                Err(err) if err.is_clean_close() => {
400                    debug!(error = %err, "audio track closed");
401                    return Ok(());
402                }
403                Err(err) => return Err(Error::decoder(err)),
404            };
405            // A gap or an end carries no samples. The sink plays on from what
406            // it has queued, so only decoded audio is written.
407            let moq_audio::decode::Read::Frame(frame) = read else {
408                continue;
409            };
410            let decoded = Instant::now();
411            let channels = self.format.layout.channels();
412            let samples = match moq_audio::Format::F32.as_interleaved_f32(&frame.data, channels) {
413                Ok(samples) => samples,
414                Err(err) => {
415                    debug!(error = %err, "a decoded audio frame is not whole f32 samples");
416                    Cow::Borrowed(&[][..])
417                }
418            };
419            self.level
420                .push(&samples, play_length(self.format, samples.len()));
421            self.clock.received(frame.timestamp);
422            let buffered = self.buffered();
423            #[cfg(feature = "playback")]
424            {
425                let end = self.end_of(&frame);
426                if let Some(sink) = &mut self.sink {
427                    // Played audio holds the clock back by its measured jitter,
428                    // as upstream's `moq play` does, so the pictures wait for
429                    // the sound.
430                    let target = self.target.get(&self.name, self.decoder.delay());
431                    if self.clock.set_target(target) {
432                        debug!(?target, "audio moved the playout delay");
433                    }
434                    sink.write(&frame.data).map(drop).map_err(Error::device)?;
435                    // The speaker follows the shared clock: it stretches toward
436                    // the time the sound of `end` is due, as the pictures do.
437                    if let Some(at) = self.clock.anchor(end) {
438                        sink.due(at, STRETCH);
439                    }
440                }
441            }
442            self.share(frame.timestamp, &samples);
443            self.stats.audio_log.push(FrameTiming {
444                kind: MediaKind::Audio,
445                pts: crate::duration(frame.timestamp),
446                arrived: None,
447                decoded,
448                presented: Instant::now() + buffered,
449            });
450            let peak = self.peak();
451            let rms = self.level.rms();
452            self.stats.audio.update(|audio| {
453                if let Some(audio) = audio.as_mut() {
454                    audio.frames += 1;
455                    audio.buffered = buffered;
456                    audio.peak = peak;
457                    audio.rms = rms;
458                }
459            });
460        }
461        debug!("audio track ended");
462        Ok(())
463    }
464
465    /// Returns the handle that sets the speaker stream's gain, if there is one.
466    fn control(&self) -> Option<Control> {
467        #[cfg(feature = "playback")]
468        return self.sink.as_ref().map(playback::Sink::control);
469        #[cfg(not(feature = "playback"))]
470        None
471    }
472
473    /// Returns how much audio is queued ahead of the speaker.
474    fn buffered(&self) -> Duration {
475        #[cfg(feature = "playback")]
476        if let Some(sink) = &self.sink {
477            return sink.buffered();
478        }
479        Duration::ZERO
480    }
481
482    /// Returns the most recent peak level, for a meter.
483    ///
484    /// That is the speaker stream's peak after the volume, or without a
485    /// speaker the peak of the decoded audio the level is measured across.
486    fn peak(&self) -> f32 {
487        #[cfg(feature = "playback")]
488        if let Some(sink) = &self.sink {
489            return sink.control().peak();
490        }
491        self.level.peak()
492    }
493
494    /// Returns the media time at the end of `frame`'s samples.
495    #[cfg(feature = "playback")]
496    fn end_of(&self, frame: &moq_audio::Frame) -> Duration {
497        let samples = frame.data.len() / std::mem::size_of::<f32>();
498        crate::duration(frame.timestamp) + play_length(self.format, samples)
499    }
500
501    /// Hands the frame at `timestamp` to the [`AudioFrames`] readers, if there are any.
502    fn share(&self, timestamp: moq_net::Timestamp, samples: &[f32]) {
503        if self.frames.receiver_count() == 0 || samples.is_empty() {
504            return;
505        }
506        let _ = self.frames.send(AudioFrame {
507            timestamp,
508            format: self.format,
509            samples: samples.into(),
510        });
511    }
512}
513
514/// The level of the last [`LEVEL_WINDOW`] of decoded audio.
515///
516/// The level is of every channel together, before the speaker's volume.
517#[derive(Debug, Default)]
518struct LevelMeter {
519    /// The frames the window spans, oldest first.
520    frames: VecDeque<FrameLevel>,
521}
522
523/// The measurements of one decoded frame.
524#[derive(Debug, Clone, Copy)]
525struct FrameLevel {
526    /// How long the frame plays.
527    length: Duration,
528    /// The sum of the squares of its samples.
529    squares: f64,
530    /// How many samples it has, across all channels.
531    samples: usize,
532    /// The largest absolute sample.
533    peak: f32,
534}
535
536impl LevelMeter {
537    /// Adds a frame of interleaved `samples` that plays for `length`.
538    ///
539    /// Drops the oldest frames that the window no longer needs.
540    fn push(&mut self, samples: &[f32], length: Duration) {
541        if samples.is_empty() {
542            return;
543        }
544        let squares = samples
545            .iter()
546            .map(|sample| f64::from(*sample) * f64::from(*sample))
547            .sum();
548        let peak = samples
549            .iter()
550            .fold(0.0f32, |peak, sample| peak.max(sample.abs()));
551        self.frames.push_back(FrameLevel {
552            length,
553            squares,
554            samples: samples.len(),
555            peak,
556        });
557        let mut spanned: Duration = self.frames.iter().map(|frame| frame.length).sum();
558        while let Some(oldest) = self.frames.front()
559            && spanned.saturating_sub(oldest.length) >= LEVEL_WINDOW
560        {
561            spanned -= oldest.length;
562            self.frames.pop_front();
563        }
564    }
565
566    /// Returns the RMS level across the window, `None` before the first frame.
567    fn rms(&self) -> Option<f32> {
568        let samples: usize = self.frames.iter().map(|frame| frame.samples).sum();
569        if samples == 0 {
570            return None;
571        }
572        let squares: f64 = self.frames.iter().map(|frame| frame.squares).sum();
573        Some((squares / samples as f64).sqrt().min(1.0) as f32)
574    }
575
576    /// Returns the largest absolute sample across the window, `0.0` before the first frame.
577    fn peak(&self) -> f32 {
578        self.frames
579            .iter()
580            .fold(0.0f32, |peak, frame| peak.max(frame.peak))
581            .min(1.0)
582    }
583}
584
585#[cfg(test)]
586mod tests {
587    use super::*;
588
589    /// Returns 20 ms of a mono square wave at `amplitude`, at 48 kHz.
590    fn square(amplitude: f32) -> Vec<f32> {
591        (0..960)
592            .map(|n| if n % 2 == 0 { amplitude } else { -amplitude })
593            .collect()
594    }
595
596    /// The meter reads the RMS and the peak of the audio it holds.
597    #[test]
598    fn the_level_is_the_rms_of_the_decoded_audio() {
599        let mut meter = LevelMeter::default();
600        assert_eq!(meter.rms(), None);
601        assert_eq!(meter.peak(), 0.0);
602        meter.push(&square(0.5), ms(20));
603        assert_eq!(meter.rms(), Some(0.5));
604        assert_eq!(meter.peak(), 0.5);
605        // A sine at 0.5 has an RMS of 0.5 / sqrt(2).
606        let mut meter = LevelMeter::default();
607        let sine: Vec<f32> = (0..960)
608            .map(|n| 0.5 * (n as f32 * std::f32::consts::TAU / 48.0).sin())
609            .collect();
610        meter.push(&sine, ms(20));
611        let rms = meter.rms().expect("a level");
612        assert!((rms - 0.5 / 2f32.sqrt()).abs() < 0.001, "{rms}");
613    }
614
615    /// Audio older than the window no longer counts.
616    #[test]
617    fn the_level_forgets_audio_older_than_its_window() {
618        let mut meter = LevelMeter::default();
619        meter.push(&square(1.0), ms(20));
620        for _ in 0..4 {
621            meter.push(&square(0.0), ms(20));
622        }
623        assert_eq!(meter.peak(), 1.0, "100 ms still hold the loud frame");
624        meter.push(&square(0.0), ms(20));
625        assert_eq!(meter.rms(), Some(0.0));
626        assert_eq!(meter.peak(), 0.0);
627    }
628
629    const fn ms(millis: u64) -> Duration {
630        Duration::from_millis(millis)
631    }
632
633    /// Returns a catalog with one audio rendition `name` that advertises `delay`.
634    #[cfg(feature = "playback")]
635    fn catalog(name: &str, delay: Option<Duration>) -> Arc<hang::catalog::Catalog> {
636        let mut config =
637            hang::catalog::AudioConfig::new(hang::catalog::AudioCodec::Opus, 48_000, 1);
638        config.delay = delay;
639        let mut catalog = hang::catalog::Catalog::default();
640        catalog.audio.renditions.insert(name.to_string(), config);
641        Arc::new(catalog)
642    }
643
644    /// The audio asks for its catalog `delay` plus the jitter its decoder measured.
645    ///
646    /// A measured target at the decoder's floor does not hold a lower latency
647    /// asked for after the decoder opened.
648    #[cfg(feature = "playback")]
649    #[test]
650    fn the_audio_target_adds_the_catalog_delay_to_the_measured_jitter() {
651        let opened = Delay {
652            min: Some(ms(100)),
653            max: Some(ms(400)),
654        };
655        let (latency, latency_rx) = watch::channel(opened);
656        let (_catalog, catalog_rx) = watch::channel(Some(catalog("opus", Some(ms(20)))));
657        let target = Target {
658            latency: latency_rx,
659            floor: ms(100),
660            catalog: catalog_rx,
661        };
662        assert_eq!(target.get("opus", ms(100)), ms(120));
663        assert_eq!(target.get("opus", ms(180)), ms(200), "the jitter raises it");
664        assert_eq!(
665            target.get("other", ms(180)),
666            ms(180),
667            "no delay for another rendition"
668        );
669
670        latency.send_replace(Delay {
671            min: Some(ms(50)),
672            max: Some(ms(400)),
673        });
674        assert_eq!(target.get("opus", ms(100)), ms(70), "the old floor lets go");
675        assert_eq!(target.get("opus", ms(180)), ms(200));
676        latency.send_replace(crate::IMMEDIATE_LATENCY);
677        assert_eq!(
678            target.get("opus", ms(180)),
679            Duration::ZERO,
680            "unpaced holds nothing"
681        );
682    }
683}