Title: [265216] trunk/Source/WebCore
- Revision
- 265216
- Author
- [email protected]
- Date
- 2020-08-03 14:01:16 -0700 (Mon, 03 Aug 2020)
Log Message
MediaRecorderPrivateWriter should ensure its writer input is ready for more data before appending new samples
https://bugs.webkit.org/show_bug.cgi?id=215081
Reviewed by Eric Carlson.
After r265192, we were checking whether the writer input was ready.
If so, we were pushing pending samples and then the new sample.
The issue is that pushing pending samples might make the writer input no longer ready.
Update the code to enqueue the sample if its writer input is not ready.
Add an ASSERT in appendCompressedVideoSampleBuffer to make sure this is the case.
Also make sure that we only enqueue the end of segment sample if video writer input is ready.
Make sure flushCompressedSampleBuffers is called directly by stopRecording only if not already flushing samples.
If we are not flushing, we proceed with the stop steps.
If not, we wait for the end of flushCompressedSampleBuffers to proceed with the stop steps.
* platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h:
* platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm:
(WebCore::MediaRecorderPrivateWriter::appendCompressedAudioSampleBufferIfPossible):
(WebCore::MediaRecorderPrivateWriter::appendCompressedVideoSampleBufferIfPossible):
(WebCore::MediaRecorderPrivateWriter::appendCompressedVideoSampleBuffer):
(WebCore::MediaRecorderPrivateWriter::flushCompressedSampleBuffers):
(WebCore::MediaRecorderPrivateWriter::stopRecording):
(WebCore::MediaRecorderPrivateWriter::finishedFlushingSamples):
(WebCore::MediaRecorderPrivateWriter::doStopRecording):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (265215 => 265216)
--- trunk/Source/WebCore/ChangeLog 2020-08-03 20:59:41 UTC (rev 265215)
+++ trunk/Source/WebCore/ChangeLog 2020-08-03 21:01:16 UTC (rev 265216)
@@ -1,3 +1,32 @@
+2020-08-03 Youenn Fablet <[email protected]>
+
+ MediaRecorderPrivateWriter should ensure its writer input is ready for more data before appending new samples
+ https://bugs.webkit.org/show_bug.cgi?id=215081
+
+ Reviewed by Eric Carlson.
+
+ After r265192, we were checking whether the writer input was ready.
+ If so, we were pushing pending samples and then the new sample.
+ The issue is that pushing pending samples might make the writer input no longer ready.
+ Update the code to enqueue the sample if its writer input is not ready.
+ Add an ASSERT in appendCompressedVideoSampleBuffer to make sure this is the case.
+
+ Also make sure that we only enqueue the end of segment sample if video writer input is ready.
+
+ Make sure flushCompressedSampleBuffers is called directly by stopRecording only if not already flushing samples.
+ If we are not flushing, we proceed with the stop steps.
+ If not, we wait for the end of flushCompressedSampleBuffers to proceed with the stop steps.
+
+ * platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h:
+ * platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm:
+ (WebCore::MediaRecorderPrivateWriter::appendCompressedAudioSampleBufferIfPossible):
+ (WebCore::MediaRecorderPrivateWriter::appendCompressedVideoSampleBufferIfPossible):
+ (WebCore::MediaRecorderPrivateWriter::appendCompressedVideoSampleBuffer):
+ (WebCore::MediaRecorderPrivateWriter::flushCompressedSampleBuffers):
+ (WebCore::MediaRecorderPrivateWriter::stopRecording):
+ (WebCore::MediaRecorderPrivateWriter::finishedFlushingSamples):
+ (WebCore::MediaRecorderPrivateWriter::doStopRecording):
+
2020-08-03 Clark Wang <[email protected]>
Added AudioBuffer Constructor
Modified: trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h (265215 => 265216)
--- trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h 2020-08-03 20:59:41 UTC (rev 265215)
+++ trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h 2020-08-03 21:01:16 UTC (rev 265216)
@@ -96,6 +96,8 @@
void finishAppendingCompressedVideoSampleBuffers(CompletionHandler<void()>&&);
void flushCompressedSampleBuffers(CompletionHandler<void()>&&);
+ void finishedFlushingSamples();
+
bool m_hasAudio { false };
bool m_hasVideo { false };
@@ -124,6 +126,7 @@
Deque<RetainPtr<CMSampleBufferRef>> m_pendingAudioSampleQueue;
bool m_isFlushingSamples { false };
+ bool m_shouldStopAfterFlushingSamples { false };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm (265215 => 265216)
--- trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm 2020-08-03 20:59:41 UTC (rev 265215)
+++ trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm 2020-08-03 21:01:16 UTC (rev 265216)
@@ -252,14 +252,19 @@
if (!buffer)
return false;
- if (m_isFlushingSamples || ![m_videoAssetWriterInput isReadyForMoreMediaData]) {
+ if (m_isFlushingSamples) {
m_pendingAudioSampleQueue.append(WTFMove(buffer));
- return false;
+ return true;
}
- while (!m_pendingAudioSampleQueue.isEmpty() && [m_videoAssetWriterInput isReadyForMoreMediaData])
+ while (!m_pendingAudioSampleQueue.isEmpty() && [m_audioAssetWriterInput isReadyForMoreMediaData])
[m_audioAssetWriterInput.get() appendSampleBuffer:m_pendingAudioSampleQueue.takeFirst().get()];
+ if (![m_audioAssetWriterInput isReadyForMoreMediaData]) {
+ m_pendingAudioSampleQueue.append(WTFMove(buffer));
+ return true;
+ }
+
[m_audioAssetWriterInput.get() appendSampleBuffer:buffer.get()];
return true;
}
@@ -273,14 +278,19 @@
if (!buffer)
return false;
- if (m_isFlushingSamples || ![m_videoAssetWriterInput isReadyForMoreMediaData]) {
+ if (m_isFlushingSamples) {
m_pendingVideoSampleQueue.append(WTFMove(buffer));
- return false;
+ return true;
}
while (!m_pendingVideoSampleQueue.isEmpty() && [m_videoAssetWriterInput isReadyForMoreMediaData])
appendCompressedVideoSampleBuffer(m_pendingVideoSampleQueue.takeFirst().get());
+ if (![m_videoAssetWriterInput isReadyForMoreMediaData]) {
+ m_pendingVideoSampleQueue.append(WTFMove(buffer));
+ return true;
+ }
+
appendCompressedVideoSampleBuffer(buffer.get());
return true;
}
@@ -287,6 +297,7 @@
void MediaRecorderPrivateWriter::appendCompressedVideoSampleBuffer(CMSampleBufferRef buffer)
{
+ ASSERT([m_videoAssetWriterInput isReadyForMoreMediaData]);
m_lastVideoPresentationTime = CMSampleBufferGetPresentationTimeStamp(buffer);
m_lastVideoDecodingTime = CMSampleBufferGetDecodeTimeStamp(buffer);
m_hasEncodedVideoSamples = true;
@@ -345,7 +356,7 @@
while (!videoSampleQueue.isEmpty() && [m_videoAssetWriterInput isReadyForMoreMediaData])
appendCompressedVideoSampleBuffer(videoSampleQueue.takeFirst().get());
- if (!audioSampleQueue.isEmpty() || !videoSampleQueue.isEmpty())
+ if (!audioSampleQueue.isEmpty() || !videoSampleQueue.isEmpty() || (hasPendingVideoSamples && ![m_videoAssetWriterInput isReadyForMoreMediaData]))
return;
if (hasPendingAudioSamples)
@@ -356,6 +367,7 @@
}
m_isFlushingSamples = false;
completionHandler();
+ finishedFlushingSamples();
});
if (hasPendingAudioSamples)
@@ -446,8 +458,19 @@
m_audioCompressor->addSampleBuffer(sampleBuffer.get());
}
+void MediaRecorderPrivateWriter::finishedFlushingSamples()
+{
+ if (m_shouldStopAfterFlushingSamples)
+ stopRecording();
+}
+
void MediaRecorderPrivateWriter::stopRecording()
{
+ if (m_isFlushingSamples) {
+ m_shouldStopAfterFlushingSamples = true;
+ return;
+ }
+
if (m_isStopped)
return;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes