Bug 1894110 - Graceful failure path for soundtouch sandbox creation failure r=glandium,media-playback-reviewers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D208947
This commit is contained in:
Shravan Narayan 2024-05-13 20:40:24 +00:00
parent ded46257b8
commit c16c8e0871
5 changed files with 31 additions and 7 deletions

View File

@ -7,6 +7,7 @@ _ZN7mozilla15RLBoxSoundTouch13setSampleRateEj
_ZN7mozilla15RLBoxSoundTouch14receiveSamplesEPfj
_ZN7mozilla15RLBoxSoundTouch18resizeSampleBufferEj
_ZN7mozilla15RLBoxSoundTouch21numUnprocessedSamplesEv
_ZN7mozilla15RLBoxSoundTouch4InitEv
_ZN7mozilla15RLBoxSoundTouch5flushEv
_ZN7mozilla15RLBoxSoundTouch7setRateEd
_ZN7mozilla15RLBoxSoundTouch8setPitchEd

View File

@ -168,7 +168,12 @@ size_t AudioStream::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
nsresult AudioStream::EnsureTimeStretcherInitialized() {
AssertIsOnAudioThread();
if (!mTimeStretcher) {
mTimeStretcher = new RLBoxSoundTouch();
auto timestretcher = MakeUnique<RLBoxSoundTouch>();
if (!timestretcher || !timestretcher->Init()) {
return NS_ERROR_FAILURE;
}
mTimeStretcher = timestretcher.release();
mTimeStretcher->setSampleRate(mAudioClock.GetInputRate());
mTimeStretcher->setChannels(mOutChannels);
mTimeStretcher->setPitch(1.0);

View File

@ -621,6 +621,9 @@ void AudioDecoderInputTrack::EnsureTimeStretcher() {
AssertOnGraphThread();
if (!mTimeStretcher) {
mTimeStretcher = new RLBoxSoundTouch();
MOZ_RELEASE_ASSERT(mTimeStretcher);
MOZ_RELEASE_ASSERT(mTimeStretcher->Init());
mTimeStretcher->setSampleRate(Graph()->GraphRate());
mTimeStretcher->setChannels(GetChannelCountForTimeStretcher());
mTimeStretcher->setPitch(1.0);

View File

@ -10,24 +10,36 @@ using namespace rlbox;
using namespace mozilla;
using namespace soundtouch;
RLBoxSoundTouch::RLBoxSoundTouch() {
RLBoxSoundTouch::RLBoxSoundTouch() {}
bool RLBoxSoundTouch::Init() {
#ifdef MOZ_WASM_SANDBOXING_SOUNDTOUCH
mSandbox.create_sandbox(true /* infallible */);
const bool success = mSandbox.create_sandbox(false /* infallible */);
#else
const bool success = true;
mSandbox.create_sandbox();
#endif
if (!success){
return false;
}
mTimeStretcher = mSandbox.invoke_sandbox_function(createSoundTouchObj);
// Allocate buffer in sandbox to receive samples.
mSampleBuffer = mSandbox.malloc_in_sandbox<AudioDataValue>(mSampleBufferSize);
MOZ_RELEASE_ASSERT(mSampleBuffer);
mCreated = true;
return true;
}
RLBoxSoundTouch::~RLBoxSoundTouch() {
mSandbox.free_in_sandbox(mSampleBuffer);
mSandbox.invoke_sandbox_function(destroySoundTouchObj, mTimeStretcher);
mTimeStretcher = nullptr;
mSandbox.destroy_sandbox();
if (mCreated) {
mSandbox.free_in_sandbox(mSampleBuffer);
mSandbox.invoke_sandbox_function(destroySoundTouchObj, mTimeStretcher);
mTimeStretcher = nullptr;
mSandbox.destroy_sandbox();
}
}
void RLBoxSoundTouch::setSampleRate(uint aRate) {

View File

@ -48,6 +48,8 @@ class RLBoxSoundTouch {
RLBOX_SOUNDTOUCH_API
RLBoxSoundTouch();
RLBOX_SOUNDTOUCH_API
bool Init();
RLBOX_SOUNDTOUCH_API
~RLBoxSoundTouch();
RLBOX_SOUNDTOUCH_API
@ -76,6 +78,7 @@ class RLBoxSoundTouch {
void flush();
private:
bool mCreated{false};
uint mChannels{0};
rlbox_sandbox_soundtouch mSandbox;
tainted_soundtouch<mozilla::AudioDataValue*> mSampleBuffer{nullptr};