use std::ops::Range;
use std::time::Duration;
pub extern crate ipc_channel;
#[macro_use]
extern crate serde_derive;
extern crate servo_media_streams as streams;
extern crate servo_media_traits;
pub mod audio;
pub mod context;
pub mod metadata;
pub mod video;
use ipc_channel::ipc::{self, IpcSender};
use servo_media_traits::MediaInstance;
use streams::registry::MediaStreamId;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum PlaybackState {
Stopped,
Buffering,
Paused,
Playing,
}
#[derive(Debug, PartialEq)]
pub enum PlayerError {
Backend(String),
BufferPushFailed,
EnoughData,
EOSFailed,
NonSeekableStream,
SeekOutOfRange,
SetStreamFailed,
SetTrackFailed,
}
pub type SeekLockMsg = (bool, IpcSender<()>);
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SeekLock {
pub lock_channel: IpcSender<SeekLockMsg>,
}
impl SeekLock {
pub fn unlock(&self, result: bool) {
let (ack_sender, ack_recv) = ipc::channel::<()>().expect("Could not create IPC channel");
self.lock_channel.send((result, ack_sender)).unwrap();
ack_recv.recv().unwrap()
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum PlayerEvent {
EndOfStream,
EnoughData,
Error(String),
VideoFrameUpdated,
MetadataUpdated(metadata::Metadata),
DurationChanged(Option<Duration>),
NeedData,
PositionChanged(f64),
SeekData(u64, SeekLock),
SeekDone(f64),
StateChanged(PlaybackState),
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum StreamType {
Stream,
Seekable,
}
pub trait Player: Send + MediaInstance {
fn play(&self) -> Result<(), PlayerError>;
fn pause(&self) -> Result<(), PlayerError>;
fn paused(&self) -> bool;
fn can_resume(&self) -> bool;
fn stop(&self) -> Result<(), PlayerError>;
fn seek(&self, time: f64) -> Result<(), PlayerError>;
fn seekable(&self) -> Vec<Range<f64>>;
fn set_mute(&self, muted: bool) -> Result<(), PlayerError>;
fn muted(&self) -> bool;
fn set_volume(&self, volume: f64) -> Result<(), PlayerError>;
fn volume(&self) -> f64;
fn set_input_size(&self, size: u64) -> Result<(), PlayerError>;
fn set_playback_rate(&self, playback_rate: f64) -> Result<(), PlayerError>;
fn playback_rate(&self) -> f64;
fn push_data(&self, data: Vec<u8>) -> Result<(), PlayerError>;
fn end_of_stream(&self) -> Result<(), PlayerError>;
fn buffered(&self) -> Vec<Range<f64>>;
fn set_stream(&self, stream: &MediaStreamId, only_stream: bool) -> Result<(), PlayerError>;
fn render_use_gl(&self) -> bool;
fn set_audio_track(&self, stream_index: i32, enabled: bool) -> Result<(), PlayerError>;
fn set_video_track(&self, stream_index: i32, enabled: bool) -> Result<(), PlayerError>;
}