Bug 1458538 - Add pause and resume events for MediaRecorder. r=bzbarsky
☠☠ backed out by 3854b4344077 ☠ ☠
authorBumsik Kim <k.bumsik@gmail.com>
Wed, 10 Oct 2018 02:16:32 +0300
changeset 498850 8f0aa41876197fc701ddadb73eee8edaa753af19
parent 498849 c8b420c49253532689f462813d7c9673ba798165
child 498851 983a5ee19bb3844c4d7f00ba55bb958b01e7341c
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1458538
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458538 - Add pause and resume events for MediaRecorder. r=bzbarsky Summary: This resolves the two problems of MediaRecorder: 1. MediaRecorder does not fire pause/resume events when the corresponding methods are called, as mentioned in D7910. 2. The WebIDL for MediaRecorder does not specify onpause/onresume event handler attributes neither. DispatchSimpleEvent() is used because there are no event attributes needed. Test Plan: The MediaRecorderTest.html attached in the bug report will be enough to test if the events work well as intended. Reviewers: jya, bzbarsky Reviewed By: jya, bzbarsky Bug #: 1458538 Differential Revision: https://phabricator.services.mozilla.com/D7971
dom/media/MediaRecorder.cpp
dom/media/MediaRecorder.h
dom/webidl/MediaRecorder.webidl
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -1391,17 +1391,19 @@ MediaRecorder::Pause(ErrorResult& aResul
   }
 
   MOZ_ASSERT(mSessions.Length() > 0);
   nsresult rv = mSessions.LastElement()->Pause();
   if (NS_FAILED(rv)) {
     NotifyError(rv);
     return;
   }
+
   mState = RecordingState::Paused;
+  DispatchSimpleEvent(NS_LITERAL_STRING("pause"));
 }
 
 void
 MediaRecorder::Resume(ErrorResult& aResult)
 {
   LOG(LogLevel::Debug, ("MediaRecorder.Resume"));
   if (mState == RecordingState::Inactive) {
     aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
@@ -1409,17 +1411,19 @@ MediaRecorder::Resume(ErrorResult& aResu
   }
 
   MOZ_ASSERT(mSessions.Length() > 0);
   nsresult rv = mSessions.LastElement()->Resume();
   if (NS_FAILED(rv)) {
     NotifyError(rv);
     return;
   }
+
   mState = RecordingState::Recording;
+  DispatchSimpleEvent(NS_LITERAL_STRING("resume"));
 }
 
 void
 MediaRecorder::RequestData(ErrorResult& aResult)
 {
   if (mState == RecordingState::Inactive) {
     aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
--- a/dom/media/MediaRecorder.h
+++ b/dom/media/MediaRecorder.h
@@ -72,20 +72,20 @@ public:
   // Pause a recording.
   void Pause(ErrorResult& aResult);
   // Resume a paused recording.
   void Resume(ErrorResult& aResult);
   // Extract encoded data Blob from MutableBlobStorage.
   void RequestData(ErrorResult& aResult);
   // Return the The DOMMediaStream passed from UA.
   DOMMediaStream* Stream() const { return mDOMStream; }
+  // Return the current encoding MIME type selected by the MediaEncoder.
+  void GetMimeType(nsString &aMimeType);
   // The current state of the MediaRecorder object.
   RecordingState State() const { return mState; }
-  // Return the current encoding MIME type selected by the MediaEncoder.
-  void GetMimeType(nsString &aMimeType);
 
   static bool IsTypeSupported(GlobalObject& aGlobal, const nsAString& aType);
   static bool IsTypeSupported(const nsAString& aType);
 
   // Construct a recorder with a DOM media stream object as its source.
   static already_AddRefed<MediaRecorder>
   Constructor(const GlobalObject& aGlobal,
               DOMMediaStream& aStream,
@@ -101,20 +101,22 @@ public:
 
   /*
    * Measure the size of the buffer, and heap memory in bytes occupied by
    * mAudioEncoder and mVideoEncoder.
    */
   typedef MozPromise<size_t, size_t, true> SizeOfPromise;
   RefPtr<SizeOfPromise> SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf);
   // EventHandler
-  IMPL_EVENT_HANDLER(dataavailable)
-  IMPL_EVENT_HANDLER(error)
   IMPL_EVENT_HANDLER(start)
   IMPL_EVENT_HANDLER(stop)
+  IMPL_EVENT_HANDLER(dataavailable)
+  IMPL_EVENT_HANDLER(pause)
+  IMPL_EVENT_HANDLER(resume)
+  IMPL_EVENT_HANDLER(error)
   IMPL_EVENT_HANDLER(warning)
 
   NS_DECL_NSIDOCUMENTACTIVITY
 
   uint32_t GetAudioBitrate() { return mAudioBitsPerSecond; }
   uint32_t GetVideoBitrate() { return mVideoBitsPerSecond; }
   uint32_t GetBitrate() { return mBitsPerSecond; }
 protected:
--- a/dom/webidl/MediaRecorder.webidl
+++ b/dom/webidl/MediaRecorder.webidl
@@ -14,28 +14,32 @@ enum RecordingState { "inactive", "recor
 
 [Constructor(MediaStream stream, optional MediaRecorderOptions options),
  Constructor(AudioNode node, optional unsigned long output = 0,
              optional MediaRecorderOptions options)]
 interface MediaRecorder : EventTarget {
 
   readonly attribute MediaStream stream;
 
-  readonly attribute RecordingState state;
-
   readonly attribute DOMString mimeType;
 
-  attribute EventHandler ondataavailable;
-
-  attribute EventHandler onerror;
+  readonly attribute RecordingState state;
 
   attribute EventHandler onstart;
 
   attribute EventHandler onstop;
 
+  attribute EventHandler ondataavailable;
+
+  attribute EventHandler onpause;
+
+  attribute EventHandler onresume;
+
+  attribute EventHandler onerror;
+
   attribute EventHandler onwarning;
 
   [Throws]
   void start(optional long timeSlice);
 
   [Throws]
   void stop();