Bug 1108950 part.2 - Add VideoMonitorEvent. r?smaug, r?roc draft
authorctai <ctai@mozilla.com>
Tue, 01 Sep 2015 10:18:40 +0800
changeset 289365 40083bf155d1b8f8897df9b1736f3b78af37bcbe
parent 289364 5f16ed0a1b011c934bc94ce232a55f00054ef813
child 289366 0c32eaa61e28c3ffa1fede73aaf21a74d8c63f76
push id4976
push userctai@mozilla.com
push dateTue, 01 Sep 2015 02:32:48 +0000
reviewerssmaug, roc
bugs1108950
milestone43.0a1
Bug 1108950 part.2 - Add VideoMonitorEvent. r?smaug, r?roc
dom/bindings/Bindings.conf
dom/canvas/ImageBitmap.cpp
dom/canvas/ImageBitmap.h
dom/media/VideoProcessEvent.cpp
dom/media/VideoProcessEvent.h
dom/media/moz.build
dom/webidl/VideoProcessEvent.webidl
dom/webidl/moz.build
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1347,16 +1347,20 @@ DOMInterfaces = {
 'VTTCue': {
     'nativeType': 'mozilla::dom::TextTrackCue'
 },
 
 'VTTRegion': {
   'nativeType': 'mozilla::dom::TextTrackRegion',
 },
 
+'VideoMonitorEvent': {
+    'headerFile': 'mozilla/dom/VideoProcessEvent.h',
+},
+
 'WindowClient': {
     'nativeType': 'mozilla::dom::workers::ServiceWorkerWindowClient',
     'headerFile': 'mozilla/dom/workers/bindings/ServiceWorkerWindowClient.h',
 },
 
 'WebGLActiveInfo': {
     'nativeType': 'mozilla::WebGLActiveInfo',
     'headerFile': 'WebGLActiveInfo.h'
--- a/dom/canvas/ImageBitmap.cpp
+++ b/dom/canvas/ImageBitmap.cpp
@@ -1144,16 +1144,23 @@ ImageBitmap::Create(nsIGlobalObject* aGl
 
   if (!aRv.Failed()) {
     AsyncFulfillImageBitmapPromise(promise, imageBitmap);
   }
 
   return promise.forget();
 }
 
+/*static*/ already_AddRefed<ImageBitmap>
+ImageBitmap::Create(nsIGlobalObject* aGlobal, layers::Image* aImage)
+{
+  nsRefPtr<ImageBitmap> bitmap = new ImageBitmap(aGlobal, aImage);
+  return bitmap.forget();
+}
+
 /*static*/ JSObject*
 ImageBitmap::ReadStructuredClone(JSContext* aCx,
                                  JSStructuredCloneReader* aReader,
                                  nsIGlobalObject* aParent,
                                  const nsTArray<nsRefPtr<layers::Image>>& aClonedImages,
                                  uint32_t aIndex)
 {
   MOZ_ASSERT(aCx);
--- a/dom/canvas/ImageBitmap.h
+++ b/dom/canvas/ImageBitmap.h
@@ -87,16 +87,19 @@ public:
    */
   already_AddRefed<gfx::SourceSurface>
   PrepareForDrawTarget(gfx::DrawTarget* aTarget);
 
   static already_AddRefed<Promise>
   Create(nsIGlobalObject* aGlobal, const ImageBitmapSource& aSrc,
          const Maybe<gfx::IntRect>& aCropRect, ErrorResult& aRv);
 
+  static already_AddRefed<ImageBitmap>
+  Create(nsIGlobalObject* aGlobal, layers::Image* aImage);
+
   static JSObject*
   ReadStructuredClone(JSContext* aCx,
                       JSStructuredCloneReader* aReader,
                       nsIGlobalObject* aParent,
                       const nsTArray<nsRefPtr<layers::Image>>& aClonedImages,
                       uint32_t aIndex);
 
   static bool
new file mode 100644
--- /dev/null
+++ b/dom/media/VideoProcessEvent.cpp
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/dom/VideoProcessEvent.h"
+#include "mozilla/dom/VideoProcessEventBinding.h"
+#include "mozilla/dom/ImageBitmap.h"
+#include "ImageContainer.h" // for layers::Image
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(VideoMonitorEvent)
+
+NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(VideoMonitorEvent, Event)
+NS_IMPL_CYCLE_COLLECTION_TRACE_END
+
+NS_IMPL_ADDREF_INHERITED(VideoMonitorEvent, Event)
+NS_IMPL_RELEASE_INHERITED(VideoMonitorEvent, Event)
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(VideoMonitorEvent, Event)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(VideoMonitorEvent, Event)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VideoMonitorEvent)
+NS_INTERFACE_MAP_END_INHERITING(Event)
+
+VideoMonitorEvent::VideoMonitorEvent(EventTarget* aOwner,
+                                     nsPresContext* aPresContext,
+                                     WidgetEvent* aEvent)
+  : Event(aOwner, aPresContext, aEvent)
+  , mInputImageBitmap(nullptr)
+  , mPlaybackTime(0)
+{
+}
+
+JSObject*
+VideoMonitorEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
+{
+  return VideoMonitorEventBinding::Wrap(aCx, this, aGivenProto);
+}
+
+double
+VideoMonitorEvent::PlaybackTime() const
+{
+  return mPlaybackTime;
+}
+
+void
+VideoMonitorEvent::GetTrackId(nsString& aRetVal) const
+{
+  aRetVal = mTrackId;
+}
+
+already_AddRefed<ImageBitmap>
+VideoMonitorEvent::InputImageBitmap() const
+{
+  nsRefPtr<ImageBitmap> bitmap = mInputImageBitmap;
+  return bitmap.forget();
+}
+
+NS_IMETHODIMP
+VideoMonitorEvent::InitEvent(double aPlaybackTime,
+                             const nsAString& aTrackId,
+                             layers::Image* aImage)
+{
+  MOZ_ASSERT(aImage);
+  nsresult rv = Event::InitEvent(NS_LITERAL_STRING("videoprocess"),
+                                 false /* non-bubbling */,
+                                 true /* cancelable */);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  mPlaybackTime = aPlaybackTime;
+  mTrackId = aTrackId;
+  ErrorResult er;
+  mInputImageBitmap = ImageBitmap::Create(mOwner, aImage);
+  MOZ_ASSERT(mInputImageBitmap);
+  return NS_OK;
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/VideoProcessEvent.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_VideoProcessEvent_h
+#define mozilla_dom_VideoProcessEvent_h
+
+#include "mozilla/dom/Event.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/ErrorResult.h"
+#include "nsCycleCollectionParticipant.h"
+#include "nsWrapperCache.h"
+
+#include "MediaSegment.h"
+
+struct JSContext;
+
+namespace mozilla {
+
+namespace layers {
+class Image;
+}
+
+namespace dom {
+
+class ImageBitmap;
+
+class VideoMonitorEvent : public Event
+{
+public:
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(VideoMonitorEvent, Event)
+  NS_FORWARD_TO_EVENT
+
+public:
+  VideoMonitorEvent(EventTarget* aOwner,
+                    nsPresContext* aPresContext,
+                    WidgetEvent* aEvent);
+
+protected:
+  ~VideoMonitorEvent() {}
+
+public:
+  virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+  void GetTrackId(nsString& aRetVal) const;
+
+  double PlaybackTime() const;
+
+  already_AddRefed<ImageBitmap> InputImageBitmap() const;
+
+  bool IsTrusted() const { return true; };
+
+  nsresult InitEvent(double aPlaybackTime,
+                     const nsAString& aTrackId,
+                     layers::Image* aImage);
+
+private:
+  nsRefPtr<ImageBitmap> mInputImageBitmap;
+  nsString mTrackId;
+  double mPlaybackTime;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_VideoProcessEvent_h
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -180,16 +180,17 @@ EXPORTS.mozilla.dom += [
     'MediaStreamError.h',
     'MediaStreamTrack.h',
     'TextTrack.h',
     'TextTrackCue.h',
     'TextTrackCueList.h',
     'TextTrackList.h',
     'TextTrackRegion.h',
     'VideoPlaybackQuality.h',
+    'VideoProcessEvent.h',
     'VideoStreamTrack.h',
     'VideoTrack.h',
     'VideoTrackList.h',
 ]
 
 UNIFIED_SOURCES += [
     'AudioCaptureStream.cpp',
     'AudioChannelFormat.cpp',
@@ -236,16 +237,17 @@ UNIFIED_SOURCES += [
     'TextTrack.cpp',
     'TextTrackCue.cpp',
     'TextTrackCueList.cpp',
     'TextTrackList.cpp',
     'TextTrackRegion.cpp',
     'TrackUnionStream.cpp',
     'VideoFrameContainer.cpp',
     'VideoPlaybackQuality.cpp',
+    'VideoProcessEvent.cpp',
     'VideoSegment.cpp',
     'VideoStreamTrack.cpp',
     'VideoTrack.cpp',
     'VideoTrackList.cpp',
     'VideoUtils.cpp',
     'WebVTTListener.cpp',
 ]
 
new file mode 100644
--- /dev/null
+++ b/dom/webidl/VideoProcessEvent.webidl
@@ -0,0 +1,15 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * The origin of this IDL file is in below link.
+ * http://chiahungtai.github.io/mediacapture-worker/
+ *
+ */
+
+interface VideoMonitorEvent : Event {
+  readonly attribute DOMString   trackId;
+  readonly attribute double      playbackTime;
+  readonly attribute ImageBitmap inputImageBitmap;
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -552,16 +552,17 @@ WEBIDL_FILES = [
     'UndoManager.webidl',
     'URL.webidl',
     'URLSearchParams.webidl',
     'URLUtils.webidl',
     'URLUtilsReadOnly.webidl',
     'USSDSession.webidl',
     'ValidityState.webidl',
     'VideoPlaybackQuality.webidl',
+    'VideoProcessEvent.webidl',
     'VideoStreamTrack.webidl',
     'VideoTrack.webidl',
     'VideoTrackList.webidl',
     'VRDevice.webidl',
     'VTTCue.webidl',
     'VTTRegion.webidl',
     'WaveShaperNode.webidl',
     'WebComponents.webidl',