Skip to content

Commit

Permalink
Auto merge of #305 - sreeise:set_audio_video_tracks, r=ferjm
Browse files Browse the repository at this point in the history
Updated player for setting audio and video tracks

This pull request is for being able to set video and audio tracks and is part of Servo issue [22799](servo/servo#22799).

Servo should be able to set multiple audio tracks at one time but the work here only allows for one. If anyone has any advice on how to set multiple audio tracks that would be great!
  • Loading branch information
bors-servo authored Sep 11, 2019
2 parents 6e864ed + 8c8103b commit f9aed4e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backends/dummy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ impl Player for DummyPlayer {
fn render_use_gl(&self) -> bool {
false
}
fn set_audio_track(&self, _: i32, _: bool) -> Result<(), PlayerError> { Ok(()) }
fn set_video_track(&self, _: i32, _: bool) -> Result<(), PlayerError> { Ok(()) }
}

impl WebRtcBackend for DummyBackend {
Expand Down
30 changes: 30 additions & 0 deletions backends/gstreamer/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ impl PlayerInner {
}
Err(PlayerError::SetStreamFailed)
}

fn set_audio_track(&mut self, stream_index: i32, enabled: bool) -> Result<(), PlayerError> {
self.player
.set_audio_track(stream_index)
.map_err(|_| PlayerError::SetTrackFailed)?;
self.player.set_audio_track_enabled(enabled);
Ok(())
}

fn set_video_track(&mut self, stream_index: i32, enabled: bool) -> Result<(), PlayerError> {
self.player
.set_video_track(stream_index)
.map_err(|_| PlayerError::SetTrackFailed)?;
self.player.set_video_track_enabled(enabled);
Ok(())
}
}

macro_rules! notify(
Expand Down Expand Up @@ -785,6 +801,20 @@ impl Player for GStreamerPlayer {
let mut inner = inner.as_ref().unwrap().lock().unwrap();
inner.set_stream(stream, only_stream)
}

fn set_audio_track(&self, stream_index: i32, enabled: bool) -> Result<(), PlayerError> {
self.setup()?;
let inner = self.inner.borrow();
let mut inner = inner.as_ref().unwrap().lock().unwrap();
inner.set_audio_track(stream_index, enabled)
}

fn set_video_track(&self, stream_index: i32, enabled: bool) -> Result<(), PlayerError> {
self.setup()?;
let inner = self.inner.borrow();
let mut inner = inner.as_ref().unwrap().lock().unwrap();
inner.set_video_track(stream_index, enabled)
}
}

impl MediaInstance for GStreamerPlayer {
Expand Down
4 changes: 4 additions & 0 deletions player/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub enum PlayerError {
/// Setting an audio or video stream failed.
/// Possibly because the type of source is not PlayerSource::Stream.
SetStreamFailed,
// Setting an audio or video track failed.
SetTrackFailed,
}

pub type SeekLockMsg = (bool, IpcSender<()>);
Expand Down Expand Up @@ -111,4 +113,6 @@ pub trait Player: Send + MediaInstance {
fn set_stream(&self, stream: &MediaStreamId, only_stream: bool) -> Result<(), PlayerError>;
/// If player's rendering draws using GL textures
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>;
}

0 comments on commit f9aed4e

Please sign in to comment.