Bug 1397793 - Add asserts for AudioChunk invariants. r=pehrsons

MozReview-Commit-ID: CFqyMPMMHyA

--HG--
extra : rebase_source : 6648d283e6da1cc3ad98616063e62542b9e7346d
extra : histedit_source : 8937ab1b4567fabc3c98802eefede9f00e9684a5
This commit is contained in:
Paul Adenot 2017-11-29 19:22:00 +01:00
Родитель 1c13882dc4
Коммит 93fa5b007c
1 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -187,7 +187,9 @@ struct AudioChunk {
} }
return true; return true;
} }
bool IsNull() const { return mBuffer == nullptr; } bool IsNull() const {
return mBuffer == nullptr;
}
void SetNull(StreamTime aDuration) void SetNull(StreamTime aDuration)
{ {
mBuffer = nullptr; mBuffer = nullptr;
@ -333,13 +335,15 @@ public:
void ResampleChunks(SpeexResamplerState* aResampler, void ResampleChunks(SpeexResamplerState* aResampler,
uint32_t aInRate, uint32_t aInRate,
uint32_t aOutRate); uint32_t aOutRate);
void AppendFrames(already_AddRefed<ThreadSharedObject> aBuffer, void AppendFrames(already_AddRefed<ThreadSharedObject> aBuffer,
const nsTArray<const float*>& aChannelData, const nsTArray<const float*>& aChannelData,
int32_t aDuration, const PrincipalHandle& aPrincipalHandle) int32_t aDuration, const PrincipalHandle& aPrincipalHandle)
{ {
AudioChunk* chunk = AppendChunk(aDuration); AudioChunk* chunk = AppendChunk(aDuration);
chunk->mBuffer = aBuffer; chunk->mBuffer = aBuffer;
MOZ_ASSERT(chunk->mBuffer || aChannelData.IsEmpty(), "Appending invalid data ?");
for (uint32_t channel = 0; channel < aChannelData.Length(); ++channel) { for (uint32_t channel = 0; channel < aChannelData.Length(); ++channel) {
chunk->mChannelData.AppendElement(aChannelData[channel]); chunk->mChannelData.AppendElement(aChannelData[channel]);
} }
@ -355,6 +359,9 @@ public:
{ {
AudioChunk* chunk = AppendChunk(aDuration); AudioChunk* chunk = AppendChunk(aDuration);
chunk->mBuffer = aBuffer; chunk->mBuffer = aBuffer;
MOZ_ASSERT(chunk->mBuffer || aChannelData.IsEmpty(), "Appending invalid data ?");
for (uint32_t channel = 0; channel < aChannelData.Length(); ++channel) { for (uint32_t channel = 0; channel < aChannelData.Length(); ++channel) {
chunk->mChannelData.AppendElement(aChannelData[channel]); chunk->mChannelData.AppendElement(aChannelData[channel]);
} }
@ -363,6 +370,7 @@ public:
chunk->mTimeStamp = TimeStamp::Now(); chunk->mTimeStamp = TimeStamp::Now();
#endif #endif
chunk->mPrincipalHandle = aPrincipalHandle; chunk->mPrincipalHandle = aPrincipalHandle;
} }
// Consumes aChunk, and returns a pointer to the persistent copy of aChunk // Consumes aChunk, and returns a pointer to the persistent copy of aChunk
// in the segment. // in the segment.
@ -371,6 +379,9 @@ public:
AudioChunk* chunk = AppendChunk(aChunk->mDuration); AudioChunk* chunk = AppendChunk(aChunk->mDuration);
chunk->mBuffer = aChunk->mBuffer.forget(); chunk->mBuffer = aChunk->mBuffer.forget();
chunk->mChannelData.SwapElements(aChunk->mChannelData); chunk->mChannelData.SwapElements(aChunk->mChannelData);
MOZ_ASSERT(chunk->mBuffer || aChunk->mChannelData.IsEmpty(), "Appending invalid data ?");
chunk->mVolume = aChunk->mVolume; chunk->mVolume = aChunk->mVolume;
chunk->mBufferFormat = aChunk->mBufferFormat; chunk->mBufferFormat = aChunk->mBufferFormat;
#ifdef MOZILLA_INTERNAL_API #ifdef MOZILLA_INTERNAL_API