Skip to content

Commit 8aca9f7

Browse files
authored
Pass precise position timestamp within PlayerEvent (#460)
The following `PlayerEvent::PositionChanged/SeekDone` events should contains the precise position timestamps to pass them to back to client, otherwise there are no possibility to identify timestamp changes between two `PositionChanged` events on the client side. gst (5.104499333) -> servo (5) gst (5.153333333) -> servo (5) Signed-off-by: Andrei Volykhin <[email protected]>
1 parent 5b788a9 commit 8aca9f7

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

backends/gstreamer/player.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,15 @@ impl GStreamerPlayer {
581581
let observer = self.observer.clone();
582582
// Handle `position-update` signal.
583583
signal_adapter.connect_position_updated(move |_, position| {
584-
if let Some(seconds) = position.map(|p| p.seconds()) {
584+
if let Some(seconds) = position.map(|p| p.seconds_f64()) {
585585
let _ = notify!(observer, PlayerEvent::PositionChanged(seconds));
586586
}
587587
});
588588

589589
let observer = self.observer.clone();
590590
// Handle `seek-done` signal.
591591
signal_adapter.connect_seek_done(move |_, position| {
592-
let _ = notify!(observer, PlayerEvent::SeekDone(position.seconds()));
592+
let _ = notify!(observer, PlayerEvent::SeekDone(position.seconds_f64()));
593593
});
594594

595595
// Handle `media-info-updated` signal.

examples/muted_player.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ fn run_example(servo_media: Arc<ServoMedia>) {
107107
},
108108
PlayerEvent::VideoFrameUpdated => eprint!("."),
109109
PlayerEvent::PositionChanged(p) => {
110-
if p == 2 && !muted {
110+
if p as u64 == 2 && !muted {
111111
println!("\nPosition is at 2sec, muting, 1 second of silence incoming");
112112
servo_media.mute(&context_id, true);
113113
muted = true;
114-
} else if p == 3 && muted {
114+
} else if p as u64 == 3 && muted {
115115
println!("\nPosition is at 3sec, unmuting");
116116
servo_media.mute(&context_id, false);
117117
muted = false;

examples/play_media_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn run_example(servo_media: Arc<ServoMedia>) {
6262
},
6363
PlayerEvent::VideoFrameUpdated => eprint!("."),
6464
PlayerEvent::PositionChanged(p) => {
65-
if p == 4 {
65+
if p as u64 == 4 {
6666
break;
6767
}
6868
println!("Position changed {:?}", p)

examples/player/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ pub fn main_loop(mut app: App) -> Result<glutin::WindowedContext<glutin::Possibl
437437
}
438438
},
439439
player::PlayerEvent::VideoFrameUpdated => frameupdated = true,
440-
player::PlayerEvent::PositionChanged(pos) => playerstate.pos = pos as f64,
440+
player::PlayerEvent::PositionChanged(pos) => playerstate.pos = pos,
441441
_ => (),
442442
}
443443
}

examples/simple_player.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn run_example(servo_media: Arc<ServoMedia>) {
141141
PlayerEvent::VideoFrameUpdated => eprint!("."),
142142
PlayerEvent::PositionChanged(p) => {
143143
let player = player.lock().unwrap();
144-
if p == 4 && !seek_requested {
144+
if p as u64 == 4 && !seek_requested {
145145
println!("\nPosition changed to 4sec, seeking back to 0sec");
146146
if let Err(e) = player.seek(0.) {
147147
eprintln!("{:?}", e);

player/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ pub enum PlayerEvent {
6969
/// The internal player queue is running out of data. The client should start
7070
/// pushing more data.
7171
NeedData,
72-
PositionChanged(u64),
73-
/// The player needs the data to perform a seek to the given offset.
72+
PositionChanged(f64),
73+
/// The player needs the data to perform a seek to the given offset in bytes.
7474
/// The next push_data should get the buffers from the new offset.
7575
/// The player will be blocked until the user unlocks it through
7676
/// the given SeekLock instance.
7777
/// This event is only received for seekable stream types.
7878
SeekData(u64, SeekLock),
79-
/// The player has performed a seek to the given offset.
80-
SeekDone(u64),
79+
/// The player has performed a seek to the given time offset in seconds.
80+
SeekDone(f64),
8181
StateChanged(PlaybackState),
8282
}
8383

0 commit comments

Comments
 (0)