- Revision
- 263565
- Author
- [email protected]
- Date
- 2020-06-26 09:49:50 -0700 (Fri, 26 Jun 2020)
Log Message
MediaRecorder.start() Method is Ignoring the "timeslice" Parameter
https://bugs.webkit.org/show_bug.cgi?id=202233
<rdar://problem/55720555>
Reviewed by Eric Carlson.
Source/WebCore:
Use a timer to implement timeSlice parameter.
Schedule timer either when start is called or as part of requestData callback.
This should ensure that, if requestData is called by the application, the timer will be rescheduled appropriately.
Test: http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html
* Modules/mediarecorder/MediaRecorder.cpp:
(WebCore::MediaRecorder::MediaRecorder):
(WebCore::MediaRecorder::startRecording):
(WebCore::MediaRecorder::requestData):
* Modules/mediarecorder/MediaRecorder.h:
LayoutTests:
* http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt: Added.
* http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (263564 => 263565)
--- trunk/LayoutTests/ChangeLog 2020-06-26 16:44:31 UTC (rev 263564)
+++ trunk/LayoutTests/ChangeLog 2020-06-26 16:49:50 UTC (rev 263565)
@@ -1,3 +1,14 @@
+2020-06-26 Youenn Fablet <[email protected]>
+
+ MediaRecorder.start() Method is Ignoring the "timeslice" Parameter
+ https://bugs.webkit.org/show_bug.cgi?id=202233
+ <rdar://problem/55720555>
+
+ Reviewed by Eric Carlson.
+
+ * http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt: Added.
+ * http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html: Added.
+
2020-06-26 Jack Lee <[email protected]>
ASSERTION FAILED: (it != m_map.end()) in TreeScopeOrderedMap::remove
Added: trunk/LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt (0 => 263565)
--- trunk/LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt 2020-06-26 16:49:50 UTC (rev 263565)
@@ -0,0 +1,3 @@
+
+PASS Make sure that MediaRecorder timeSlice triggers regular ondataavailable events
+
Added: trunk/LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html (0 => 263565)
--- trunk/LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html (rev 0)
+++ trunk/LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html 2020-06-26 16:49:50 UTC (rev 263565)
@@ -0,0 +1,28 @@
+<!doctype html>
+<html>
+<head>
+ <title>MediaRecorder start timeSlice option</title>
+ <link rel="help" href=""
+ <script src=""
+ <script src=""
+</head>
+<body>
+<canvas id="canvas" width="200" height="200">
+</canvas>
+<script>
+ promise_test(async t => {
+ const video = await navigator.mediaDevices.getUserMedia({ audio : true, video : true });
+ const recorder = new MediaRecorder(video);
+
+ assert_equals(recorder.stream, video);
+
+ let promise = new Promise(resolve => recorder._ondataavailable_ = resolve);
+ recorder.start(100);
+ await promise;
+
+ promise = new Promise(resolve => recorder._ondataavailable_ = resolve);
+ await promise;
+ }, 'Make sure that MediaRecorder timeSlice triggers regular ondataavailable events');
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (263564 => 263565)
--- trunk/Source/WebCore/ChangeLog 2020-06-26 16:44:31 UTC (rev 263564)
+++ trunk/Source/WebCore/ChangeLog 2020-06-26 16:49:50 UTC (rev 263565)
@@ -1,3 +1,23 @@
+2020-06-26 Youenn Fablet <[email protected]>
+
+ MediaRecorder.start() Method is Ignoring the "timeslice" Parameter
+ https://bugs.webkit.org/show_bug.cgi?id=202233
+ <rdar://problem/55720555>
+
+ Reviewed by Eric Carlson.
+
+ Use a timer to implement timeSlice parameter.
+ Schedule timer either when start is called or as part of requestData callback.
+ This should ensure that, if requestData is called by the application, the timer will be rescheduled appropriately.
+
+ Test: http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html
+
+ * Modules/mediarecorder/MediaRecorder.cpp:
+ (WebCore::MediaRecorder::MediaRecorder):
+ (WebCore::MediaRecorder::startRecording):
+ (WebCore::MediaRecorder::requestData):
+ * Modules/mediarecorder/MediaRecorder.h:
+
2020-06-26 Jack Lee <[email protected]>
ASSERTION FAILED: (it != m_map.end()) in TreeScopeOrderedMap::remove
Modified: trunk/Source/WebCore/Modules/mediarecorder/MediaRecorder.cpp (263564 => 263565)
--- trunk/Source/WebCore/Modules/mediarecorder/MediaRecorder.cpp 2020-06-26 16:44:31 UTC (rev 263564)
+++ trunk/Source/WebCore/Modules/mediarecorder/MediaRecorder.cpp 2020-06-26 16:49:50 UTC (rev 263565)
@@ -83,6 +83,7 @@
: ActiveDOMObject(document)
, m_options(WTFMove(option))
, m_stream(WTFMove(stream))
+ , m_timeSliceTimer([this] { requestData(); })
{
m_tracks = WTF::map(m_stream->getTracks(), [] (auto&& track) -> Ref<MediaStreamTrackPrivate> {
return track->privateTrack();
@@ -125,9 +126,8 @@
return "MediaRecorder";
}
-ExceptionOr<void> MediaRecorder::startRecording(Optional<int> timeslice)
+ExceptionOr<void> MediaRecorder::startRecording(Optional<int> timeSlice)
{
- UNUSED_PARAM(timeslice);
if (!m_isActive)
return Exception { InvalidStateError, "The MediaRecorder is not active"_s };
@@ -152,6 +152,9 @@
track->addObserver(*this);
m_state = RecordingState::Recording;
+ m_timeSlice = timeSlice;
+ if (m_timeSlice)
+ m_timeSliceTimer.startOneShot(Seconds::fromMilliseconds(*m_timeSlice));
return { };
}
@@ -181,6 +184,8 @@
if (state() == RecordingState::Inactive)
return Exception { InvalidStateError, "The MediaRecorder's state cannot be inactive"_s };
+ if (m_timeSliceTimer.isActive())
+ m_timeSliceTimer.stop();
m_private->fetchData([this, pendingActivity = makePendingActivity(*this)](auto&& buffer, auto& mimeType) {
queueTaskKeepingObjectAlive(*this, TaskSource::Networking, [this, buffer = WTFMove(buffer), mimeType]() mutable {
if (!m_isActive)
@@ -187,6 +192,9 @@
return;
dispatchEvent(BlobEvent::create(eventNames().dataavailableEvent, Event::CanBubble::No, Event::IsCancelable::No, buffer ? Blob::create(buffer.releaseNonNull(), mimeType) : Blob::create()));
+
+ if (m_timeSlice)
+ m_timeSliceTimer.startOneShot(Seconds::fromMilliseconds(*m_timeSlice));
});
});
return { };
Modified: trunk/Source/WebCore/Modules/mediarecorder/MediaRecorder.h (263564 => 263565)
--- trunk/Source/WebCore/Modules/mediarecorder/MediaRecorder.h 2020-06-26 16:44:31 UTC (rev 263564)
+++ trunk/Source/WebCore/Modules/mediarecorder/MediaRecorder.h 2020-06-26 16:49:50 UTC (rev 263565)
@@ -30,6 +30,7 @@
#include "EventTarget.h"
#include "MediaStream.h"
#include "MediaStreamTrackPrivate.h"
+#include "Timer.h"
#include <wtf/UniqueRef.h>
namespace WebCore {
@@ -116,6 +117,8 @@
std::unique_ptr<MediaRecorderPrivate> m_private;
RecordingState m_state { RecordingState::Inactive };
Vector<Ref<MediaStreamTrackPrivate>> m_tracks;
+ Optional<int> m_timeSlice;
+ Timer m_timeSliceTimer;
bool m_isActive { true };
};