Skip to content

Commit

Permalink
Bug 1907438 - Support planar -> interleaved copy. r=chunmin
Browse files Browse the repository at this point in the history
  • Loading branch information
padenot committed Jul 17, 2024
1 parent 5b01df9 commit 5559cfb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
7 changes: 0 additions & 7 deletions dom/media/webcodecs/AudioData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ struct CopyToSpec {
const uint32_t mFrameOffset;
const uint32_t mPlaneIndex;
const AudioSampleFormat mFormat;
// False if this is used internally, and this copy call doesn't come from
// script.
DebugOnly<bool> mFromScript = true;
};

bool IsInterleaved(const AudioSampleFormat& aFormat) {
Expand Down Expand Up @@ -435,7 +432,6 @@ void CopySamples(Span<S> aSource, Span<D> aDest, uint32_t aSourceChannelCount,
}

if (!IsInterleaved(aSourceFormat) && IsInterleaved(aCopyToSpec.mFormat)) {
MOZ_ASSERT(!aCopyToSpec.mFromScript);
// Planar to interleaved -- copy of all channels of the source into the
// destination buffer.
MOZ_ASSERT(aCopyToSpec.mPlaneIndex == 0);
Expand Down Expand Up @@ -722,9 +718,6 @@ RefPtr<mozilla::AudioData> AudioData::ToAudioData() const {
storageNeeded.value());

CopyToSpec spec(mNumberOfFrames, 0, 0, AudioSampleFormat::F32);
#ifdef DEBUG
spec.mFromScript = false;
#endif

DoCopy(data, storage, mNumberOfChannels, mAudioSampleFormat.value(), spec);

Expand Down
16 changes: 16 additions & 0 deletions dom/media/webcodecs/crashtests/1907438.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script>
let a = new ArrayBuffer(4096);
let b = new AudioData({
"format": "s16-planar",
"sampleRate": 2.75e+38,
"numberOfFrames": 88,
"numberOfChannels": 20,
"timestamp": 97.5,
"data": a,
}):
let c = new Uint8ClampedArray(61932);
b.copyTo(c, {
"planeIndex": 0,
"format": "s16"
});
</script>
1 change: 1 addition & 0 deletions dom/media/webcodecs/crashtests/crashtests.list
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ skip-if(Android) pref(dom.media.webcodecs.enabled,true) pref(media.ffmpeg.encode
skip-if(Android) pref(dom.media.webcodecs.enabled,true) pref(media.ffmpeg.encoder.enabled,true) load 1897631.html
skip-if(Android) pref(dom.media.webcodecs.enabled,true) load 1902555.html
skip-if(Android) pref(dom.media.webcodecs.enabled,true) load 1905399.html
skip-if(Android) pref(dom.media.webcodecs.enabled,true) load 1907438.html
15 changes: 14 additions & 1 deletion testing/web-platform/tests/webcodecs/audio-data.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const TEST_TEMPLATE = {
// For each test, copy this template and replace the number by the appropriate
// number for this type
testInput: [MIN, BIAS, MAX, MIN, HALF, NEGATIVE_HALF, BIAS, MAX, BIAS, BIAS],
testInterleavedResult: [MIN, NEGATIVE_HALF, BIAS, BIAS, MAX, MAX, MIN, BIAS, HALF, BIAS],
testVectorInterleavedResult: [
[MIN, MAX, HALF, BIAS, BIAS],
[BIAS, MIN, NEGATIVE_HALF, MAX, BIAS],
Expand Down Expand Up @@ -274,6 +275,10 @@ function get_type_values(type) {
cloned.testInput,
idx => TEST_VALUES[type][idx]
);
cloned.testInterleavedResult = Array.from(
cloned.testInterleavedResult,
idx => TEST_VALUES[type][idx]
);
cloned.testVectorInterleavedResult = Array.from(
cloned.testVectorInterleavedResult,
c => {
Expand Down Expand Up @@ -418,7 +423,15 @@ function conversionTest(sourceType, destinationType) {
"planar channel 1",
assert_func
);
// Planar to interleaved isn't supported
// Copy to interleaved from planar: all channels are copied
data.copyTo(destInterleaved, {planeIndex: 0, format: destinationType});
check_array_equality(
destInterleaved,
result.testInterleavedResult,
sourceType,
"planar to interleaved",
assert_func
);
}, `Test conversion of ${sourceType} to ${destinationType}`);
}

Expand Down

0 comments on commit 5559cfb

Please sign in to comment.