Commit 9037731b authored by Chun-Min Chang's avatar Chun-Min Chang
Browse files

Bug 1774302 - Add [Serializable] to VideoFrame r=padenot,smaug

This patch add `Serializable` attribute to `VideoFrame` and add some
necessary changes to make this buildable.

Some expectations of *video-frame-serialization.any.is*'s wpts are
changed to `PASS` since they are implemented in bug 1774300.

The `Verify posting closed frames throws` is currently passed by luck so
the its expectation stays the same.

Depends on D159545

Differential Revision: https://phabricator.services.mozilla.com/D153685
parent eba918d5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ enum StructuredCloneTags : uint32_t {

  SCTAG_DOM_TRANSFORMSTREAM,

  SCTAG_DOM_VIDEOFRAME,

  // IMPORTANT: If you plan to add an new IDB tag, it _must_ be add before the
  // "less stable" tags!
};
+19 −0
Original line number Diff line number Diff line
@@ -1793,6 +1793,25 @@ void VideoFrame::Close() {
  mTimestamp.reset();
}

// https://w3c.github.io/webcodecs/#ref-for-deserialization-steps%E2%91%A0
/* static */
already_AddRefed<VideoFrame> VideoFrame::ReadStructuredClone(
    JSContext* aCx, nsIGlobalObject* aGlobal,
    JSStructuredCloneReader* aReader) {
  return nullptr;
}

// https://w3c.github.io/webcodecs/#ref-for-serialization-steps%E2%91%A0
bool VideoFrame::WriteStructuredClone(JSContext* aCx,
                                      JSStructuredCloneWriter* aWriter) const {
  // TODO: Throw error if this is _detached_ instead of checking resource (bug
  // 1774306).
  if (!mResource) {
    return false;
  }
  return false;
}

/*
 * VideoFrame::Format
 *
+8 −0
Original line number Diff line number Diff line
@@ -136,6 +136,14 @@ class VideoFrame final : public nsISupports, public nsWrapperCache {

  void Close();

  // [Serializable] implementations: {Read, Write}StructuredClone
  static already_AddRefed<VideoFrame> ReadStructuredClone(
      JSContext* aCx, nsIGlobalObject* aGlobal,
      JSStructuredCloneReader* aReader);

  bool WriteStructuredClone(JSContext* aCx,
                            JSStructuredCloneWriter* aWriter) const;

 public:
  // A VideoPixelFormat wrapper providing utilities for VideoFrame.
  class Format final {
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ enum AlphaOption {
  "discard",
};

[Exposed=(Window,DedicatedWorker) /* , Serializable (bug 1774302), Transferable (bug 1774306) */, Pref="dom.media.webcodecs.enabled"]
[Exposed=(Window,DedicatedWorker), Serializable /* Transferable (bug 1774306) */, Pref="dom.media.webcodecs.enabled"]
interface VideoFrame {
  // The constructors should be shorten to:
  //   ```
+3 −16
Original line number Diff line number Diff line
[video-frame-serialization.any.worker.html]
  [Test we can clone a VideoFrame.]
    expected: FAIL

  [Verify closing a frame doesn't affect its clones.]
    expected: FAIL

  [Verify cloning a closed frame throws.]
    expected: FAIL
  prefs: [dom.media.webcodecs.enabled:true]

  [Verify posting closed frames throws.]
    expected: FAIL
@@ -19,16 +12,9 @@


[video-frame-serialization.any.html]
  prefs: [dom.media.webcodecs.enabled:true]
  expected:
    if (os == "android") and fission: [OK, TIMEOUT]
  [Test we can clone a VideoFrame.]
    expected: FAIL

  [Verify closing a frame doesn't affect its clones.]
    expected: FAIL

  [Verify cloning a closed frame throws.]
    expected: FAIL

  [Verify posting closed frames throws.]
    expected: FAIL
@@ -38,3 +24,4 @@

  [Verify transferring frames closes them.]
    expected: FAIL