diff --git a/config/system-headers b/config/system-headers index 30ed9024591a..8e73df2f6ff3 100644 --- a/config/system-headers +++ b/config/system-headers @@ -1257,6 +1257,7 @@ X11/Xos.h X11/Xutil.h zmouse.h soundtouch/SoundTouch.h +soundtouch/SoundTouchFactory.h #if MOZ_NATIVE_PNG==1 png.h #endif diff --git a/dom/media/AudioStream.cpp b/dom/media/AudioStream.cpp index b4dfcee7da14..0077edb2824b 100644 --- a/dom/media/AudioStream.cpp +++ b/dom/media/AudioStream.cpp @@ -129,6 +129,7 @@ AudioStream::AudioStream() , mOutChannels(0) , mWritten(0) , mAudioClock(this) + , mTimeStretcher(nullptr) , mLatencyRequest(HighLatency) , mReadPoint(0) , mDumpFile(nullptr) @@ -151,6 +152,9 @@ AudioStream::~AudioStream() if (mDumpFile) { fclose(mDumpFile); } + if (mTimeStretcher) { + soundtouch::destroySoundTouchObj(mTimeStretcher); + } } size_t @@ -173,7 +177,7 @@ nsresult AudioStream::EnsureTimeStretcherInitializedUnlocked() { mMonitor.AssertCurrentThreadOwns(); if (!mTimeStretcher) { - mTimeStretcher = new soundtouch::SoundTouch(); + mTimeStretcher = soundtouch::createSoundTouchObj(); mTimeStretcher->setSampleRate(mInRate); mTimeStretcher->setChannels(mOutChannels); mTimeStretcher->setPitch(1.0); diff --git a/dom/media/AudioStream.h b/dom/media/AudioStream.h index 464548a99588..a552e3e27e12 100644 --- a/dom/media/AudioStream.h +++ b/dom/media/AudioStream.h @@ -15,7 +15,7 @@ #include "mozilla/RefPtr.h" #include "mozilla/UniquePtr.h" #include "CubebUtils.h" -#include "soundtouch/SoundTouch.h" +#include "soundtouch/SoundTouchFactory.h" namespace mozilla { @@ -329,7 +329,7 @@ private: // Number of frames written to the buffers. int64_t mWritten; AudioClock mAudioClock; - nsAutoPtr mTimeStretcher; + soundtouch::SoundTouch* mTimeStretcher; nsRefPtr mLatencyLog; // copy of Latency logger's starting time for offset calculations diff --git a/media/libsoundtouch/src/SoundTouchFactory.cpp b/media/libsoundtouch/src/SoundTouchFactory.cpp new file mode 100644 index 000000000000..b577616fca1c --- /dev/null +++ b/media/libsoundtouch/src/SoundTouchFactory.cpp @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include + +namespace soundtouch +{ + +EXPORT +soundtouch::SoundTouch* +createSoundTouchObj() +{ + return new soundtouch::SoundTouch(); +} + +EXPORT +void +destroySoundTouchObj(soundtouch::SoundTouch* aObj) +{ + // SoundTouch runs deletes in its destructor, meaning they need to be run in + // the DLL context. Gecko should send its SoundTouch obj pointers here to be + // cleaned up. + if (aObj) { + delete aObj; + } +} + +} diff --git a/media/libsoundtouch/src/SoundTouchFactory.h b/media/libsoundtouch/src/SoundTouchFactory.h new file mode 100644 index 000000000000..cea4d9a64993 --- /dev/null +++ b/media/libsoundtouch/src/SoundTouchFactory.h @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// Code for dealing with creating/deleting SoundTouch objects across DLL +// boundaries. + +#include +#include + +namespace soundtouch +{ +EXPORT +soundtouch::SoundTouch* +createSoundTouchObj(); + +EXPORT +void +destroySoundTouchObj(soundtouch::SoundTouch* aObj); +} diff --git a/media/libsoundtouch/src/moz.build b/media/libsoundtouch/src/moz.build index 026a17430475..1c301c40454f 100644 --- a/media/libsoundtouch/src/moz.build +++ b/media/libsoundtouch/src/moz.build @@ -8,6 +8,7 @@ EXPORTS.soundtouch += [ 'FIFOSamplePipe.h', 'SoundTouch.h', 'soundtouch_config.h', + 'SoundTouchFactory.h', 'STTypes.h', ] @@ -21,6 +22,7 @@ UNIFIED_SOURCES += [ 'InterpolateShannon.cpp', 'RateTransposer.cpp', 'SoundTouch.cpp', + 'SoundTouchFactory.cpp', 'TDStretch.cpp', ] diff --git a/media/libsoundtouch/src/soundtouch_perms.h b/media/libsoundtouch/src/soundtouch_perms.h index 855c285ea5b6..0af2fe618311 100644 --- a/media/libsoundtouch/src/soundtouch_perms.h +++ b/media/libsoundtouch/src/soundtouch_perms.h @@ -12,6 +12,7 @@ #pragma GCC visibility push(default) #include "SoundTouch.h" +#include "SoundTouchFactory.h" #pragma GCC visibility pop #endif // MOZILLA_SOUNDTOUCH_PERMS_H