Commit 2824a885 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[webaudio] Replace uses of deprecatedLengthAsUnsigned

As the size ByteLength field of ArrayBuffers is now size_t, I changed
the implementation of AudioBuffer::copyFromChannel and
AudioBuffer::copyToChannel to be able to handle size_t buffer offsets.

R=rtoy@chromium.org

Bug: chromium:1008840
Change-Id: Iaf3a336a6fdc9c4af44708335a91b50de9d43783
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1975718Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726455}
parent 31c1924e
...@@ -220,7 +220,7 @@ void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination, ...@@ -220,7 +220,7 @@ void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination,
void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination, void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination,
int32_t channel_number, int32_t channel_number,
uint32_t buffer_offset, size_t buffer_offset,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (channel_number < 0 || if (channel_number < 0 ||
static_cast<uint32_t>(channel_number) >= channels_.size()) { static_cast<uint32_t>(channel_number) >= channels_.size()) {
...@@ -237,23 +237,24 @@ void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination, ...@@ -237,23 +237,24 @@ void AudioBuffer::copyFromChannel(NotShared<DOMFloat32Array> destination,
DOMFloat32Array* channel_data = channels_[channel_number].Get(); DOMFloat32Array* channel_data = channels_[channel_number].Get();
if (buffer_offset >= channel_data->deprecatedLengthAsUnsigned()) { size_t data_length = channel_data->lengthAsSizeT();
if (buffer_offset >= data_length) {
// Nothing to copy if the buffer offset is past the end of the AudioBuffer. // Nothing to copy if the buffer offset is past the end of the AudioBuffer.
return; return;
} }
unsigned int count = size_t count = data_length - buffer_offset;
channel_data->deprecatedLengthAsUnsigned() - buffer_offset;
count = std::min(destination.View()->deprecatedLengthAsUnsigned(), count); count = std::min(destination.View()->lengthAsSizeT(), count);
const float* src = channel_data->Data(); const float* src = channel_data->Data();
float* dst = destination.View()->Data(); float* dst = destination.View()->Data();
DCHECK(src); DCHECK(src);
DCHECK(dst); DCHECK(dst);
DCHECK_LE(count, channel_data->deprecatedLengthAsUnsigned()); DCHECK_LE(count, data_length);
DCHECK_LE(buffer_offset + count, channel_data->deprecatedLengthAsUnsigned()); DCHECK_LE(buffer_offset + count, data_length);
memcpy(dst, src + buffer_offset, count * sizeof(*src)); memcpy(dst, src + buffer_offset, count * sizeof(*src));
} }
...@@ -266,7 +267,7 @@ void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source, ...@@ -266,7 +267,7 @@ void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source,
void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source, void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source,
int32_t channel_number, int32_t channel_number,
uint32_t buffer_offset, size_t buffer_offset,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (channel_number < 0 || if (channel_number < 0 ||
static_cast<uint32_t>(channel_number) >= channels_.size()) { static_cast<uint32_t>(channel_number) >= channels_.size()) {
...@@ -282,22 +283,21 @@ void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source, ...@@ -282,22 +283,21 @@ void AudioBuffer::copyToChannel(NotShared<DOMFloat32Array> source,
DOMFloat32Array* channel_data = channels_[channel_number].Get(); DOMFloat32Array* channel_data = channels_[channel_number].Get();
if (buffer_offset >= channel_data->deprecatedLengthAsUnsigned()) { if (buffer_offset >= channel_data->lengthAsSizeT()) {
// Nothing to copy if the buffer offset is past the end of the AudioBuffer. // Nothing to copy if the buffer offset is past the end of the AudioBuffer.
return; return;
} }
unsigned int count = size_t count = channel_data->lengthAsSizeT() - buffer_offset;
channel_data->deprecatedLengthAsUnsigned() - buffer_offset;
count = std::min(source.View()->deprecatedLengthAsUnsigned(), count); count = std::min(source.View()->lengthAsSizeT(), count);
const float* src = source.View()->Data(); const float* src = source.View()->Data();
float* dst = channel_data->Data(); float* dst = channel_data->Data();
DCHECK(src); DCHECK(src);
DCHECK(dst); DCHECK(dst);
DCHECK_LE(buffer_offset + count, channel_data->deprecatedLengthAsUnsigned()); DCHECK_LE(buffer_offset + count, channel_data->lengthAsSizeT());
DCHECK_LE(count, source.View()->deprecatedLengthAsUnsigned()); DCHECK_LE(count, source.View()->lengthAsSizeT());
memcpy(dst + buffer_offset, src, count * sizeof(*dst)); memcpy(dst + buffer_offset, src, count * sizeof(*dst));
} }
......
...@@ -95,14 +95,14 @@ class MODULES_EXPORT AudioBuffer final : public ScriptWrappable { ...@@ -95,14 +95,14 @@ class MODULES_EXPORT AudioBuffer final : public ScriptWrappable {
ExceptionState&); ExceptionState&);
void copyFromChannel(NotShared<DOMFloat32Array>, void copyFromChannel(NotShared<DOMFloat32Array>,
int32_t channel_number, int32_t channel_number,
uint32_t buffer_offset, size_t buffer_offset,
ExceptionState&); ExceptionState&);
void copyToChannel(NotShared<DOMFloat32Array>, void copyToChannel(NotShared<DOMFloat32Array>,
int32_t channel_number, int32_t channel_number,
ExceptionState&); ExceptionState&);
void copyToChannel(NotShared<DOMFloat32Array>, void copyToChannel(NotShared<DOMFloat32Array>,
int32_t channel_number, int32_t channel_number,
uint32_t buffer_offset, size_t buffer_offset,
ExceptionState&); ExceptionState&);
void Zero(); void Zero();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment