mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Keep shared and js channels in sync
This commit is contained in:
parent
346d705c66
commit
138c739205
1 changed files with 15 additions and 7 deletions
|
@ -117,13 +117,19 @@ impl AudioBuffer {
|
||||||
for (i, channel) in self.js_channels.borrow_mut().iter().enumerate() {
|
for (i, channel) in self.js_channels.borrow_mut().iter().enumerate() {
|
||||||
if !channel.get().is_null() {
|
if !channel.get().is_null() {
|
||||||
// Already have data in JS array.
|
// Already have data in JS array.
|
||||||
|
// We may have called GetChannelData, and web content may have modified
|
||||||
|
// js_channels. So make sure that shared_channels contains the same data as
|
||||||
|
// js_channels.
|
||||||
|
typedarray!(in(cx) let array: Float32Array = channel.get());
|
||||||
|
if let Ok(array) = array {
|
||||||
|
(*self.shared_channels.borrow_mut()).buffers[i] = array.to_vec();
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the channel data from shared_channels to js_channels.
|
// Copy the channel data from shared_channels to js_channels.
|
||||||
rooted!(in (cx) let mut array = ptr::null_mut::<JSObject>());
|
rooted!(in (cx) let mut array = ptr::null_mut::<JSObject>());
|
||||||
let shared_channel = &(*self.shared_channels.borrow_mut()).buffers[i];
|
if Float32Array::create(cx, CreateWith::Slice(&(*self.shared_channels.borrow_mut()).buffers[i]), array.handle_mut())
|
||||||
if Float32Array::create(cx, CreateWith::Slice(shared_channel), array.handle_mut())
|
|
||||||
.is_err()
|
.is_err()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -289,12 +295,14 @@ impl AudioBufferMethods for AudioBuffer {
|
||||||
unsafe {
|
unsafe {
|
||||||
let data = &source.as_slice()[0..bytes_to_copy];
|
let data = &source.as_slice()[0..bytes_to_copy];
|
||||||
// Update shared channel.
|
// Update shared channel.
|
||||||
|
{
|
||||||
let mut shared_channels = self.shared_channels.borrow_mut();
|
let mut shared_channels = self.shared_channels.borrow_mut();
|
||||||
let shared_channel = shared_channels.data_chan_mut(channel_number as u8);
|
let shared_channel = shared_channels.data_chan_mut(channel_number as u8);
|
||||||
let (_, mut shared_channel) = shared_channel.split_at_mut(start_in_channel as usize);
|
let (_, mut shared_channel) = shared_channel.split_at_mut(start_in_channel as usize);
|
||||||
shared_channel[0..bytes_to_copy].copy_from_slice(data);
|
shared_channel[0..bytes_to_copy].copy_from_slice(data);
|
||||||
|
}
|
||||||
// Update js channel.
|
// Update js channel.
|
||||||
js_channel.update(data);
|
js_channel.update(self.shared_channels.borrow().buffers[channel_number as usize].as_slice());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::IndexSize);
|
return Err(Error::IndexSize);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue