Skip to content

Commit

Permalink
Bug 1863799 return a Span from AudioChunk::ChannelData() to forbid ns…
Browse files Browse the repository at this point in the history
…TArray::Clone() r=padenot

Clone() often allocates unnecessarily, so this prevents copying of a Clone()
pattern to a caller.

An alternative might be to return CopyableAutoTArray& where Clone() is
deleted, but that could still be implicitly cast to a base class where Clone()
is available.  The reinterpret_cast on the channel pointer array pointer feels
a little less precarious than on the CopyableAutoTArray.

Explicit template arguments are added because they are not deduced with the
implicit nsTArray to Span conversions.

Differential Revision: https://phabricator.services.mozilla.com/D193167

UltraBlame original commit: 5fcc529533b87c657e0dd95ea8cdd37f7cbac5c0
  • Loading branch information
marco-c committed Nov 10, 2023
1 parent ba9616d commit 25387fc
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 39 deletions.
5 changes: 2 additions & 3 deletions dom/media/AudibilityMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,13 @@ GetDuration
void
ProcessPlanar
(
const
nsTArray
Span
<
const
float
*
const
>
&
aPlanar
TrackTime
aFrames
Expand Down
33 changes: 20 additions & 13 deletions dom/media/AudioSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,13 @@ DestT
void
DownmixAndInterleave
(
const
nsTArray
Span
<
const
SrcT
*
const
>
&
aChannelData
int32_t
aDuration
Expand Down Expand Up @@ -1634,14 +1633,13 @@ template
typename
T
>
const
nsTArray
Span
<
const
T
*
const
>
&
ChannelData
(
)
Expand All @@ -1662,22 +1660,28 @@ mBufferFormat
)
;
return
*
Span
(
reinterpret_cast
<
const
AutoTArray
<
const
T
*
GUESS_AUDIO_CHANNELS
>
const
*
>
(
&
mChannelData
.
Elements
(
)
)
mChannelData
.
Length
(
)
)
;
}
Expand Down Expand Up @@ -3737,6 +3741,9 @@ Down
mix
.
DownmixAndInterleave
<
SrcT
>
(
channelData
aChunk
Expand Down
10 changes: 4 additions & 6 deletions dom/media/driftcontrol/DynamicResampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,14 +1524,13 @@ DynamicResampler
:
AppendInput
(
const
nsTArray
Span
<
const
float
*
const
>
&
aInBuffer
uint32_t
aInFrames
Expand All @@ -1558,14 +1557,13 @@ DynamicResampler
:
AppendInput
(
const
nsTArray
Span
<
const
int16_t
*
const
>
&
aInBuffer
uint32_t
aInFrames
Expand Down
14 changes: 6 additions & 8 deletions dom/media/driftcontrol/DynamicResampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,13 @@ place
void
AppendInput
(
const
nsTArray
Span
<
const
float
*
const
>
&
aInBuffer
uint32_t
aInFrames
Expand All @@ -563,14 +562,13 @@ aInFrames
void
AppendInput
(
const
nsTArray
Span
<
const
int16_t
*
const
>
&
aInBuffer
uint32_t
aInFrames
Expand Down Expand Up @@ -1027,12 +1025,12 @@ T
void
AppendInputInternal
(
const
nsTArray
Span
<
const
T
*
const
>
&
aInBuffer
Expand Down
3 changes: 3 additions & 0 deletions dom/media/encoder/TrackEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,9 @@ aOutputChannels
)
{
DownmixAndInterleave
<
T
>
(
aInput
aDuration
Expand Down
9 changes: 1 addition & 8 deletions dom/media/webaudio/AudioNodeExternalInputTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,7 @@ blockChannels
}
else
{
const
nsTArray
<
const
T
*
>
&
Span
inputChannels
=
aInput
Expand Down
11 changes: 10 additions & 1 deletion dom/media/webaudio/DelayBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,15 @@ mLastReadChunk
aNewReadChunk
;
mUpmixChannels
=
.
ClearAndRetainStorage
(
)
;
mUpmixChannels
.
AppendElements
(
mChunks
[
aNewReadChunk
Expand All @@ -1504,6 +1512,7 @@ float
>
(
)
)
;
MOZ_ASSERT
(
Expand Down
4 changes: 4 additions & 0 deletions dom/media/webaudio/blink/Reverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ float
4
>
irChannels
;
irChannels
.
AppendElements
(
impulseResponse
.
Expand Down

0 comments on commit 25387fc

Please sign in to comment.