Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/audio: Preparations for SampleDataEvent work #14165

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/avm2/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub struct SystemClasses<'gc> {
pub contextmenuevent: ClassObject<'gc>,
pub font: ClassObject<'gc>,
pub textline: ClassObject<'gc>,
pub sampledataevent: ClassObject<'gc>,
}

impl<'gc> SystemClasses<'gc> {
Expand Down Expand Up @@ -296,6 +297,7 @@ impl<'gc> SystemClasses<'gc> {
contextmenuevent: object,
font: object,
textline: object,
sampledataevent: object,
}
}
}
Expand Down Expand Up @@ -824,6 +826,7 @@ fn load_playerglobal<'gc>(
("flash.filters", "GradientBevelFilter", gradientbevelfilter),
("flash.filters", "GradientGlowFilter", gradientglowfilter),
("flash.filters", "ShaderFilter", shaderfilter),
("flash.events", "SampleDataEvent", sampledataevent),
]
);

Expand Down
17 changes: 1 addition & 16 deletions core/src/backend/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,8 @@ pub trait AudioBackend: Downcast {

/// Starts playing a "stream" sound, which is an audio stream that is distributed
/// among the frames of a Flash MovieClip.
///
/// NOTE: `stream_handle` and `clip_frame` are no longer used on any
/// backends.
fn start_stream(
&mut self,
stream_handle: Option<SoundHandle>,
clip_frame: u16,
clip_data: crate::tag_utils::SwfSlice,
handle: &swf::SoundStreamHead,
) -> Result<SoundInstanceHandle, DecodeError>;
Expand Down Expand Up @@ -159,11 +154,6 @@ pub trait AudioBackend: Downcast {

fn get_sound_peak(&mut self, instance: SoundInstanceHandle) -> Option<[f32; 2]>;

// TODO: Eventually remove this/move it to library.
fn is_loading_complete(&self) -> bool {
true
}

/// Allows the audio backend to update.
///
/// Runs once per event loop iteration.
Expand Down Expand Up @@ -274,8 +264,6 @@ impl AudioBackend for NullAudioBackend {

fn start_stream(
&mut self,
_stream_handle: Option<SoundHandle>,
_clip_frame: u16,
_clip_data: crate::tag_utils::SwfSlice,
_handle: &swf::SoundStreamHead,
) -> Result<SoundInstanceHandle, DecodeError> {
Expand Down Expand Up @@ -538,16 +526,13 @@ impl<'gc> AudioManager<'gc> {
pub fn start_stream(
&mut self,
audio: &mut dyn AudioBackend,
stream_handle: Option<SoundHandle>,
movie_clip: MovieClip<'gc>,
clip_frame: u16,
data: crate::tag_utils::SwfSlice,
stream_info: &swf::SoundStreamHead,
) -> Option<SoundInstanceHandle> {
if self.sounds.len() < Self::MAX_SOUNDS {
let handle = audio
.start_stream(stream_handle, clip_frame, data, stream_info)
.ok()?;
let handle = audio.start_stream(data, stream_info).ok()?;
let instance = SoundInstance {
sound: None,
instance: handle,
Expand Down
7 changes: 1 addition & 6 deletions core/src/backend/audio/mixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,6 @@ impl AudioMixer {
/// Starts a timeline audio stream.
pub fn start_stream(
&mut self,
_stream_handle: Option<SoundHandle>,
_clip_frame: u16,
clip_data: SwfSlice,
stream_info: &swf::SoundStreamHead,
) -> Result<SoundInstanceHandle, DecodeError> {
Expand Down Expand Up @@ -1090,13 +1088,10 @@ macro_rules! impl_audio_mixer_backend {
#[inline]
fn start_stream(
&mut self,
stream_handle: Option<SoundHandle>,
clip_frame: u16,
clip_data: $crate::tag_utils::SwfSlice,
stream_info: &swf::SoundStreamHead,
) -> Result<SoundInstanceHandle, DecodeError> {
self.$mixer
.start_stream(stream_handle, clip_frame, clip_data, stream_info)
self.$mixer.start_stream(clip_data, stream_info)
}

#[inline]
Expand Down
11 changes: 2 additions & 9 deletions core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,13 @@ impl<'a, 'gc> UpdateContext<'a, 'gc> {

pub fn start_stream(
&mut self,
stream_handle: Option<SoundHandle>,
movie_clip: MovieClip<'gc>,
frame: u16,
data: crate::tag_utils::SwfSlice,
stream_info: &swf::SoundStreamHead,
) -> Option<SoundInstanceHandle> {
self.audio_manager.start_stream(
self.audio,
stream_handle,
movie_clip,
frame,
data,
stream_info,
)
self.audio_manager
.start_stream(self.audio, movie_clip, frame, data, stream_info)
}

pub fn set_sound_transforms_dirty(&mut self) {
Expand Down
9 changes: 2 additions & 7 deletions core/src/display_object/movie_clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4364,13 +4364,8 @@ impl<'gc, 'a> MovieClip<'gc> {
.static_data
.swf
.to_start_and_end(mc.tag_stream_pos as usize, mc.tag_stream_len());
let audio_stream = context.start_stream(
mc.static_data.audio_stream_handle,
self,
mc.current_frame(),
slice,
stream_info,
);
let audio_stream =
context.start_stream(self, mc.current_frame(), slice, stream_info);
drop(mc);
self.0.write(context.gc_context).audio_stream = audio_stream;
}
Expand Down
6 changes: 0 additions & 6 deletions core/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,6 @@ impl Player {
}

pub fn tick(&mut self, dt: f64) {
// Don't run until preloading is complete.
// TODO: Eventually we want to stream content similar to the Flash player.
if !self.audio.is_loading_complete() {
return;
}

if self.is_playing() {
self.frame_accumulator += dt;
let frame_rate = self.frame_rate;
Expand Down