Skip to content

Commit

Permalink
Backed out 3 changesets (bug 1673285) for causing build bustages in d…
Browse files Browse the repository at this point in the history
…om/media/AudioStream.cpp CLOSED TREE

Backed out changeset 6c2e3da74c76 (bug 1673285)
Backed out changeset f28e1fe0311f (bug 1673285)
Backed out changeset f66c9e9aad96 (bug 1673285)
  • Loading branch information
Sandor Molnar committed Aug 28, 2023
1 parent 2ce483a commit 2572abb
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 484 deletions.
2 changes: 1 addition & 1 deletion config/recurse.mk
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ endif

ifdef MOZ_USING_WASM_SANDBOXING
security/rlbox/pre-compile: config/external/wasm2c_sandbox_compiler/host
dom/media/ogg/target-objects extensions/spellcheck/hunspell/glue/target-objects gfx/thebes/target-objects parser/expat/target-objects parser/htmlparser/target-objects gfx/ots/src/target-objects dom/media/target-objects dom/media/mediasink/target-objects: security/rlbox/pre-compile
dom/media/ogg/target-objects extensions/spellcheck/hunspell/glue/target-objects gfx/thebes/target-objects parser/expat/target-objects parser/htmlparser/target-objects gfx/ots/src/target-objects: security/rlbox/pre-compile
endif

# Most things are built during compile (target/host), but some things happen during export
Expand Down
56 changes: 21 additions & 35 deletions dom/media/AudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "CallbackThreadRegistry.h"
#include "mozilla/StaticPrefs_media.h"

#include "RLBoxSoundTouch.h"
// Use abort() instead of exception in SoundTouch.
#define ST_NO_EXCEPTION_HANDLING 1
#include "soundtouch/SoundTouchFactory.h"

namespace mozilla {

Expand Down Expand Up @@ -168,7 +170,7 @@ size_t AudioStream::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
nsresult AudioStream::EnsureTimeStretcherInitialized() {
AssertIsOnAudioThread();
if (!mTimeStretcher) {
mTimeStretcher = new RLBoxSoundTouch();
mTimeStretcher = soundtouch::createSoundTouchObj();
mTimeStretcher->setSampleRate(mAudioClock.GetInputRate());
mTimeStretcher->setChannels(mOutChannels);
mTimeStretcher->setPitch(1.0);
Expand Down Expand Up @@ -405,7 +407,7 @@ void AudioStream::ShutDown() {
// After `cubeb_stream_stop` has been called, there is no audio thread
// anymore. We can delete the time stretcher.
if (mTimeStretcher) {
delete mTimeStretcher;
soundtouch::destroySoundTouchObj(mTimeStretcher);
mTimeStretcher = nullptr;
}

Expand Down Expand Up @@ -472,32 +474,23 @@ void AudioStream::GetUnprocessed(AudioBufferWriter& aWriter) {
AssertIsOnAudioThread();
// Flush the timestretcher pipeline, if we were playing using a playback rate
// other than 1.0.
if (mTimeStretcher) {
// Get number of samples and based on this either receive samples or write
// silence. At worst, the attacker can supply weird sound samples or
// result in us writing silence.
auto numSamples = mTimeStretcher->numSamples().unverified_safe_because(
"We only use this to decide whether to receive samples or write "
"silence.");
if (numSamples) {
RLBoxSoundTouch* timeStretcher = mTimeStretcher;
aWriter.Write(
[timeStretcher](AudioDataValue* aPtr, uint32_t aFrames) {
return timeStretcher->receiveSamples(aPtr, aFrames);
},
aWriter.Available());

// TODO: There might be still unprocessed samples in the stretcher.
// We should either remove or flush them so they won't be in the output
// next time we switch a playback rate other than 1.0.
mTimeStretcher->numUnprocessedSamples().copy_and_verify([](auto samples) {
NS_WARNING_ASSERTION(samples == 0, "no samples");
});
}
if (mTimeStretcher && mTimeStretcher->numSamples()) {
auto* timeStretcher = mTimeStretcher;
aWriter.Write(
[timeStretcher](AudioDataValue* aPtr, uint32_t aFrames) {
return timeStretcher->receiveSamples(aPtr, aFrames);
},
aWriter.Available());

// TODO: There might be still unprocessed samples in the stretcher.
// We should either remove or flush them so they won't be in the output
// next time we switch a playback rate other than 1.0.
NS_WARNING_ASSERTION(mTimeStretcher->numUnprocessedSamples() == 0,
"no samples");
} else if (mTimeStretcher) {
// Don't need it anymore: playbackRate is 1.0, and the time stretcher has
// been flushed.
delete mTimeStretcher;
soundtouch::destroySoundTouchObj(mTimeStretcher);
mTimeStretcher = nullptr;
}

Expand All @@ -521,14 +514,7 @@ void AudioStream::GetTimeStretched(AudioBufferWriter& aWriter) {
uint32_t toPopFrames =
ceil(aWriter.Available() * mAudioClock.GetPlaybackRate());

// At each iteration, get number of samples and (based on this) write from
// the data source or silence. At worst, if the number of samples is a lie
// (i.e., under attacker control) we'll either not write anything or keep
// writing noise. This is safe because all the memory operations within the
// loop (and after) are checked.
while (mTimeStretcher->numSamples().unverified_safe_because(
"Only used to decide whether to put samples.") <
aWriter.Available()) {
while (mTimeStretcher->numSamples() < aWriter.Available()) {
// pop into a temp buffer, and put into the stretcher.
AutoTArray<AudioDataValue, 1000> buf;
auto size = CheckedUint32(mOutChannels) * toPopFrames;
Expand Down Expand Up @@ -643,7 +629,7 @@ long AudioStream::DataCallback(void* aBuffer, long aFrames) {
// No more new data in the data source, and the drain has completed. We
// don't need the time stretcher anymore at this point.
if (mTimeStretcher && writer.Available()) {
delete mTimeStretcher;
soundtouch::destroySoundTouchObj(mTimeStretcher);
mTimeStretcher = nullptr;
}
#ifndef XP_MACOSX
Expand Down
8 changes: 6 additions & 2 deletions dom/media/AudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
# include "nsThreadUtils.h"
# include "WavDumper.h"

namespace soundtouch {
class MOZ_EXPORT SoundTouch;
}

namespace mozilla {

struct CubebDestroyPolicy {
Expand All @@ -34,7 +38,6 @@ struct CubebDestroyPolicy {
class AudioStream;
class FrameHistory;
class AudioConfig;
class RLBoxSoundTouch;

// A struct that contains the number of frames serviced or underrun by a
// callback, alongside the sample-rate for this callback (in case of playback
Expand Down Expand Up @@ -325,7 +328,8 @@ class AudioStream final {
bool CheckThreadIdChanged();
void AssertIsOnAudioThread() const;

RLBoxSoundTouch* mTimeStretcher;
soundtouch::SoundTouch* mTimeStretcher;

AudioClock mAudioClock;

WavDumper mDumpFile;
Expand Down
148 changes: 0 additions & 148 deletions dom/media/RLBoxSoundTouch.cpp

This file was deleted.

63 changes: 0 additions & 63 deletions dom/media/RLBoxSoundTouch.h

This file was deleted.

35 changes: 0 additions & 35 deletions dom/media/RLBoxSoundTouchTypes.h

This file was deleted.

Loading

0 comments on commit 2572abb

Please sign in to comment.