1#![forbid(unsafe_code)]
4mod event;
5mod renderer;
6pub use event::{MediaEvent, MediaSubscription};
7pub use ferroui_base::rendering::composition::frames;
8pub use renderer::*;
9use std::{future::Future, pin::Pin};
10pub type MediaFuture<T> = Pin<Box<dyn Future<Output = Result<T, MediaError>>>>;
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct MediaError {
13 pub kind: MediaErrorKind,
14 pub message: String,
15}
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17pub enum MediaErrorKind {
18 Unsupported,
19 InvalidSource,
20 Permission,
21 NativeFailure,
22 DeviceLost,
23 Cancelled,
24 AutoplayDenied,
25}
26impl MediaError {
27 pub fn new(kind: MediaErrorKind, message: impl Into<String>) -> Self {
28 Self {
29 kind,
30 message: message.into(),
31 }
32 }
33 pub fn cancelled() -> Self {
34 Self::new(
35 MediaErrorKind::Cancelled,
36 "Source or operation was replaced",
37 )
38 }
39}
40impl std::fmt::Display for MediaError {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 f.write_str(&self.message)
43 }
44}
45impl std::error::Error for MediaError {}
46
47pub fn allocate_source_id() -> u64 {
50 use std::sync::atomic::{AtomicU64, Ordering};
51 static NEXT: AtomicU64 = AtomicU64::new(1);
52 NEXT.fetch_update(Ordering::AcqRel, Ordering::Acquire, |v| v.checked_add(1))
53 .expect("media source identity exhausted")
54}