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
Родитель ded46257b8
Коммит c16c8e0871
5 изменённых файлов: 31 добавлений и 7 удалений

1
config/external/lgpllibs/lgpllibs.symbols поставляемый
Просмотреть файл

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

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

@ -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);

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

@ -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);

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

@ -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) {

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

@ -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};