servo_media_traits/
lib.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use std::num::NonZeroU32;
6use std::sync::mpsc::Sender;
7/// An ID for clients to track instances of Players and AudioContexts belonging to the same tab and mute them simultaneously.
8/// Current tuple implementation matches one of Servo's BrowsingContextId.
9#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]
10pub struct ClientContextId(u32, NonZeroU32);
11
12impl ClientContextId {
13    pub fn build(a: u32, b: u32) -> ClientContextId {
14        ClientContextId(a, NonZeroU32::new(b).unwrap())
15    }
16}
17
18/// Common functionality for all high level media instances
19/// These currently are WebAudio AudioContexts and Players.
20pub trait MediaInstance: Send {
21    fn get_id(&self) -> usize;
22    fn mute(&self, val: bool) -> Result<(), ()>;
23    fn suspend(&self) -> Result<(), ()>;
24    fn resume(&self) -> Result<(), ()>;
25}
26
27pub enum BackendMsg {
28    /// Message to notify about a media instance shutdown.
29    /// The given `usize` is the media instance ID.
30    Shutdown {
31        context: ClientContextId,
32        id: usize,
33        tx_ack: Sender<()>,
34    },
35}