Support MediaRecorder.onstart
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jun 2020 18:32:10 +0000 (18:32 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jun 2020 18:32:10 +0000 (18:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=213720

Reviewed by Darin Adler.

Source/WebCore:

Fire start event if MediaRecorder.start is successful.
Do some WebIDL clean-up, in particular change timeSlice from long to unsigned long, as per spec.
Covered by added test.

* Modules/mediarecorder/MediaRecorder.cpp:
(WebCore::MediaRecorder::startRecording):
* Modules/mediarecorder/MediaRecorder.h:
* Modules/mediarecorder/MediaRecorder.idl:

LayoutTests:

* http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt:
* http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263671 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt
LayoutTests/http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediarecorder/MediaRecorder.cpp
Source/WebCore/Modules/mediarecorder/MediaRecorder.h
Source/WebCore/Modules/mediarecorder/MediaRecorder.idl

index 29f8baf..c69994d 100644 (file)
@@ -1,3 +1,13 @@
+2020-06-29  Youenn Fablet  <youenn@apple.com>
+
+        Support MediaRecorder.onstart
+        https://bugs.webkit.org/show_bug.cgi?id=213720
+
+        Reviewed by Darin Adler.
+
+        * http/wpt/mediarecorder/MediaRecorder-start-timeSlice-expected.txt:
+        * http/wpt/mediarecorder/MediaRecorder-start-timeSlice.html:
+
 2020-06-29  Karl Rackler  <rackler@apple.com>
 
         Remove expectation for imported/w3c/web-platform-tests/css/css-scoping/stylesheet-title-001.html as they are passing. 
index 8c06b54..59c4610 100644 (file)
@@ -1,3 +1,4 @@
 
 PASS Make sure that MediaRecorder timeSlice triggers regular ondataavailable events 
+PASS Make sure that MediaRecorder fires onstart on successful start call 
 
index 8111a45..a0c014b 100644 (file)
         promise = new Promise(resolve => recorder.ondataavailable = resolve);
         await promise;
     }, 'Make sure that MediaRecorder timeSlice triggers regular ondataavailable events');
+
+    promise_test(async t => {
+        const video = await navigator.mediaDevices.getUserMedia({ audio : true, video : true });
+        const recorder = new MediaRecorder(video);
+
+       let promise = new Promise(resolve => recorder.onstart = resolve);
+        // We cover the case of invalid ignored timeSlice value by passing -1 here.
+        recorder.start(-1);
+
+        return promise;
+    }, 'Make sure that MediaRecorder fires onstart on successful start call');
 </script>
 </body>
 </html>
index 8761ab0..da3c224 100644 (file)
@@ -1,3 +1,19 @@
+2020-06-29  Youenn Fablet  <youenn@apple.com>
+
+        Support MediaRecorder.onstart
+        https://bugs.webkit.org/show_bug.cgi?id=213720
+
+        Reviewed by Darin Adler.
+
+        Fire start event if MediaRecorder.start is successful.
+        Do some WebIDL clean-up, in particular change timeSlice from long to unsigned long, as per spec.
+        Covered by added test.
+
+        * Modules/mediarecorder/MediaRecorder.cpp:
+        (WebCore::MediaRecorder::startRecording):
+        * Modules/mediarecorder/MediaRecorder.h:
+        * Modules/mediarecorder/MediaRecorder.idl:
+
 2020-06-29  Chris Dumez  <cdumez@apple.com>
 
         On load from back/forward cache, call checkCompleted() for ALL frames inside FrameLoader::commitProvisionalLoad()
index b56c5de..cba2081 100644 (file)
@@ -126,7 +126,7 @@ const char* MediaRecorder::activeDOMObjectName() const
     return "MediaRecorder";
 }
 
-ExceptionOr<void> MediaRecorder::startRecording(Optional<int> timeSlice)
+ExceptionOr<void> MediaRecorder::startRecording(Optional<unsigned> timeSlice)
 {
     if (!m_isActive)
         return Exception { InvalidStateError, "The MediaRecorder is not active"_s };
@@ -141,11 +141,16 @@ ExceptionOr<void> MediaRecorder::startRecording(Optional<int> timeSlice)
         return Exception { NotSupportedError, "The MediaRecorder is unsupported on this platform"_s };
 
     m_private->startRecording([this, pendingActivity = makePendingActivity(*this)](auto&& exception) mutable {
-        if (!m_isActive || !exception)
+        if (!m_isActive)
             return;
 
-        stopRecordingInternal();
-        dispatchError(WTFMove(*exception));
+        if (exception) {
+            stopRecordingInternal();
+            dispatchError(WTFMove(*exception));
+            return;
+        }
+
+        dispatchEvent(Event::create(eventNames().startEvent, Event::CanBubble::No, Event::IsCancelable::No));
     });
 
     for (auto& track : m_tracks)
index fc79e86..4299e88 100644 (file)
@@ -69,7 +69,7 @@ public:
     using RefCounted::ref;
     using RefCounted::deref;
     
-    ExceptionOr<void> startRecording(Optional<int>);
+    ExceptionOr<void> startRecording(Optional<unsigned>);
     ExceptionOr<void> stopRecording();
     ExceptionOr<void> requestData();
 
@@ -117,7 +117,7 @@ private:
     std::unique_ptr<MediaRecorderPrivate> m_private;
     RecordingState m_state { RecordingState::Inactive };
     Vector<Ref<MediaStreamTrackPrivate>> m_tracks;
-    Optional<int> m_timeSlice;
+    Optional<unsigned> m_timeSlice;
     Timer m_timeSliceTimer;
     
     bool m_isActive { true };
index 4baebf2..43432ea 100644 (file)
@@ -32,11 +32,12 @@ enum RecordingState { "inactive", "recording", "paused" };
 ] interface MediaRecorder : EventTarget {
     [CallWith=Document, MayThrowException] constructor(MediaStream stream, optional MediaRecorderOptions options);
 
-    readonly attribute RecordingState state;
+    // FIXME: Implement commented out methods/attributes.
+
     readonly attribute MediaStream stream;
-    // FIXME: Implement these:
     // readonly attribute DOMString mimeType;
-    // attribute EventHandler onstart;
+    readonly attribute RecordingState state;
+    attribute EventHandler onstart;
     attribute EventHandler onstop;
     attribute EventHandler ondataavailable;
     // attribute EventHandler onpause;
@@ -44,8 +45,9 @@ enum RecordingState { "inactive", "recording", "paused" };
     attribute EventHandler onerror;
     // readonly attribute unsigned long videoBitsPerSecond;
     // readonly attribute unsigned long audioBitsPerSecond;
+    // readonly attribute BitrateMode audioBitrateMode;
 
-    [MayThrowException, ImplementedAs=startRecording] void start(optional long timeslice);
+    [MayThrowException, ImplementedAs=startRecording] void start(optional unsigned long timeslice);
     [ImplementedAs=stopRecording] void stop();
     // void pause();
     // void resume();