chore: Ensure all `NetStream` code is working in milliseconds.
AVM `NetStream` reports and accepts values in seconds, so all the unit conversions went there now.
This commit is contained in:
parent
a0a762ccfc
commit
c23f346665
|
@ -102,7 +102,7 @@ fn seek<'gc>(
|
||||||
.unwrap_or(Value::Undefined)
|
.unwrap_or(Value::Undefined)
|
||||||
.coerce_to_f64(activation)?;
|
.coerce_to_f64(activation)?;
|
||||||
|
|
||||||
ns.seek(&mut activation.context, offset);
|
ns.seek(&mut activation.context, offset * 1000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
|
|
|
@ -124,7 +124,7 @@ pub fn seek<'gc>(
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(ns) = this.as_netstream() {
|
if let Some(ns) = this.as_netstream() {
|
||||||
let offset = args.get_f64(activation, 0)?;
|
let offset = args.get_f64(activation, 0)?;
|
||||||
ns.seek(&mut activation.context, offset);
|
ns.seek(&mut activation.context, offset * 1000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
|
@ -136,7 +136,7 @@ pub fn get_time<'gc>(
|
||||||
_args: &[Value<'gc>],
|
_args: &[Value<'gc>],
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(ns) = this.as_netstream() {
|
if let Some(ns) = this.as_netstream() {
|
||||||
return Ok(ns.time().into());
|
return Ok((ns.time() / 1000.0).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Value::Undefined)
|
Ok(Value::Undefined)
|
||||||
|
|
|
@ -204,10 +204,10 @@ pub struct NetStreamData<'gc> {
|
||||||
#[collect(require_static)]
|
#[collect(require_static)]
|
||||||
stream_type: Option<NetStreamType>,
|
stream_type: Option<NetStreamType>,
|
||||||
|
|
||||||
/// The current seek offset in the stream.
|
/// The current seek offset in the stream in milliseconds.
|
||||||
stream_time: f64,
|
stream_time: f64,
|
||||||
|
|
||||||
/// The next queued seek offset.
|
/// The next queued seek offset in milliseconds.
|
||||||
///
|
///
|
||||||
/// Seeks are only executed on the next stream tick.
|
/// Seeks are only executed on the next stream tick.
|
||||||
queued_seek_time: Option<f64>,
|
queued_seek_time: Option<f64>,
|
||||||
|
@ -343,13 +343,15 @@ impl<'gc> NetStream<'gc> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Queue a seek to be executed on the next frame tick.
|
/// Queue a seek to be executed on the next frame tick.
|
||||||
|
///
|
||||||
|
/// `offset` is in milliseconds.
|
||||||
pub fn seek(self, context: &mut UpdateContext<'_, 'gc>, offset: f64) {
|
pub fn seek(self, context: &mut UpdateContext<'_, 'gc>, offset: f64) {
|
||||||
self.0.write(context.gc_context).queued_seek_time = Some(offset);
|
self.0.write(context.gc_context).queued_seek_time = Some(offset);
|
||||||
|
|
||||||
if context.is_action_script_3() {
|
if context.is_action_script_3() {
|
||||||
let trigger = AvmString::new_utf8(
|
let trigger = AvmString::new_utf8(
|
||||||
context.gc_context,
|
context.gc_context,
|
||||||
format!("Start Seeking {}", (offset * 1000.0) as u64),
|
format!("Start Seeking {}", offset as u64),
|
||||||
);
|
);
|
||||||
self.trigger_status_event(
|
self.trigger_status_event(
|
||||||
context,
|
context,
|
||||||
|
@ -373,8 +375,7 @@ impl<'gc> NetStream<'gc> {
|
||||||
/// algorithm will need to detect out-of-buffer seeks and trigger fresh
|
/// algorithm will need to detect out-of-buffer seeks and trigger fresh
|
||||||
/// downloads.
|
/// downloads.
|
||||||
///
|
///
|
||||||
/// Note that `offset` is in seconds, unlike `tick`'s `dt` parameter which
|
/// `offset` is in milliseconds.
|
||||||
/// is milliseconds.
|
|
||||||
///
|
///
|
||||||
/// This function should be run during stream ticks and *not* called by AVM
|
/// This function should be run during stream ticks and *not* called by AVM
|
||||||
/// code to service seek requests.
|
/// code to service seek requests.
|
||||||
|
@ -391,7 +392,6 @@ impl<'gc> NetStream<'gc> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let offset = offset * 1000.0;
|
|
||||||
let mut write = self.0.write(context.gc_context);
|
let mut write = self.0.write(context.gc_context);
|
||||||
|
|
||||||
if let Some(sound) = write.sound_instance {
|
if let Some(sound) = write.sound_instance {
|
||||||
|
@ -1028,6 +1028,9 @@ impl<'gc> NetStream<'gc> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Process stream data.
|
||||||
|
///
|
||||||
|
/// `dt` is in milliseconds.
|
||||||
pub fn tick(self, context: &mut UpdateContext<'_, 'gc>, dt: f64) {
|
pub fn tick(self, context: &mut UpdateContext<'_, 'gc>, dt: f64) {
|
||||||
#![allow(clippy::explicit_auto_deref)] //Erroneous lint
|
#![allow(clippy::explicit_auto_deref)] //Erroneous lint
|
||||||
|
|
||||||
|
@ -1076,7 +1079,7 @@ impl<'gc> NetStream<'gc> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let tag = tag.expect("valid tag");
|
let tag = tag.expect("valid tag");
|
||||||
is_lookahead_tag = tag.timestamp as f64 >= end_time;
|
is_lookahead_tag = tag.timestamp as f64 >= end_time; //FLV timestamps are also ms
|
||||||
if is_lookahead_tag && max_lookahead_audio_tags == 0 {
|
if is_lookahead_tag && max_lookahead_audio_tags == 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue