diff --git a/LayoutTests/fast/mediastream/mediarecorder-close-expected.txt b/LayoutTests/fast/mediastream/mediarecorder-close-expected.txt
new file mode 100644
index 000000000000..081825bb809d
--- /dev/null
+++ b/LayoutTests/fast/mediastream/mediarecorder-close-expected.txt
@@ -0,0 +1 @@
+PASS if not crashing
diff --git a/LayoutTests/fast/mediastream/mediarecorder-close.html b/LayoutTests/fast/mediastream/mediarecorder-close.html
new file mode 100644
index 000000000000..e80efe21d8e2
--- /dev/null
+++ b/LayoutTests/fast/mediastream/mediarecorder-close.html
@@ -0,0 +1,20 @@
+
+
+
+PASS if not crashing
+
+
+
diff --git a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp
index e6f4c5afe3ce..53e6f127981c 100644
--- a/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp
+++ b/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp
@@ -75,6 +75,7 @@ MediaRecorderPrivateAVFImpl::MediaRecorderPrivateAVFImpl(Refclose();
}
void MediaRecorderPrivateAVFImpl::startRecording(StartRecordingCallback&& callback)
diff --git a/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h b/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h
index 535066d28d4b..4961aaadd92c 100644
--- a/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h
+++ b/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h
@@ -80,6 +80,8 @@ class WEBCORE_EXPORT MediaRecorderPrivateWriter : public ThreadSafeRefCountedAnd
unsigned audioBitRate() const;
unsigned videoBitRate() const;
+ void close();
+
private:
MediaRecorderPrivateWriter(bool hasAudio, bool hasVideo);
diff --git a/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm b/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm
index 8d282507b7ba..a81770e72b90 100644
--- a/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm
+++ b/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm
@@ -132,6 +132,8 @@ - (void)close
MediaRecorderPrivateWriter::~MediaRecorderPrivateWriter()
{
ASSERT(isMainThread());
+ ASSERT(!m_audioCompressor);
+ ASSERT(!m_videoCompressor);
m_pendingAudioSampleQueue.clear();
m_pendingVideoFrameQueue.clear();
@@ -147,6 +149,12 @@ - (void)close
completionHandler(nullptr, 0);
}
+void MediaRecorderPrivateWriter::close()
+{
+ m_audioCompressor = nullptr;
+ m_videoCompressor = nullptr;
+}
+
bool MediaRecorderPrivateWriter::initialize(const MediaRecorderPrivateOptions& options)
{
NSError *error = nil;
diff --git a/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp b/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp
index 92cd53fd7c56..170a683c1ff1 100644
--- a/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp
+++ b/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp
@@ -62,6 +62,7 @@ RemoteMediaRecorder::RemoteMediaRecorder(GPUConnectionToWebProcess& gpuConnectio
RemoteMediaRecorder::~RemoteMediaRecorder()
{
+ m_writer->close();
}
void RemoteMediaRecorder::audioSamplesStorageChanged(ConsumerSharedCARingBuffer::Handle&& handle, const WebCore::CAAudioStreamDescription& description)