tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MediaDecoderOwner.h (7775B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 #ifndef MediaDecoderOwner_h_
      7 #define MediaDecoderOwner_h_
      8 
      9 #include "MediaInfo.h"
     10 #include "MediaSegment.h"
     11 #include "mozilla/AbstractThread.h"
     12 #include "mozilla/DefineEnum.h"
     13 #include "mozilla/UniquePtr.h"
     14 #include "nsSize.h"
     15 
     16 namespace mozilla {
     17 
     18 class CDMProxy;
     19 class GMPCrashHelper;
     20 class VideoFrameContainer;
     21 class MediaInfo;
     22 class MediaResult;
     23 enum class RFPTarget : uint64_t;
     24 
     25 namespace dom {
     26 class Document;
     27 class HTMLMediaElement;
     28 }  // namespace dom
     29 
     30 class MediaDecoderOwner {
     31 public:
     32  // Called by the media decoder to indicate that the download is progressing.
     33  virtual void DownloadProgressed() = 0;
     34 
     35  // Queue a task to fire an event targeted at the decoder owner
     36  virtual void QueueEvent(const nsAString& aName) = 0;
     37 
     38  // Triggers a recomputation of readyState.
     39  virtual void UpdateReadyState() = 0;
     40 
     41  // Called by the decoder object to notify owner might need to dispatch the
     42  // `timeupdate` event due to current time changes.
     43  virtual void MaybeQueueTimeupdateEvent() = 0;
     44 
     45  // Return true if decoding should be paused
     46  virtual bool GetPaused() = 0;
     47 
     48  // Called by the video decoder object, on the main thread,
     49  // when it has read the metadata containing video dimensions,
     50  // etc.
     51  // Must take ownership of MetadataTags aTags argument.
     52  virtual void MetadataLoaded(const MediaInfo* aInfo,
     53                              UniquePtr<const MetadataTags> aTags) = 0;
     54 
     55  // Called by the decoder object, on the main thread,
     56  // when it has read the first frame of the video or audio.
     57  virtual void FirstFrameLoaded() = 0;
     58 
     59  // Called by the decoder object, on the main thread,
     60  // when the resource has a network error during loading.
     61  // The decoder owner should call Shutdown() on the decoder and drop the
     62  // reference to the decoder to prevent further calls into the decoder.
     63  virtual void NetworkError(const MediaResult& aError) = 0;
     64 
     65  // Called by the decoder object, on the main thread, when the
     66  // resource has a decode error during metadata loading or decoding.
     67  // The decoder owner should call Shutdown() on the decoder and drop the
     68  // reference to the decoder to prevent further calls into the decoder.
     69  virtual void DecodeError(const MediaResult& aError) = 0;
     70 
     71  // Called by the decoder object, on the main thread, when the
     72  // resource has a decode issue during metadata loading or decoding, but can
     73  // continue decoding.
     74  virtual void DecodeWarning(const MediaResult& aError) = 0;
     75 
     76  // Return true if media element error attribute is not null.
     77  virtual bool HasError() const = 0;
     78 
     79  // Called by the video decoder object, on the main thread, when the
     80  // resource load has been cancelled.
     81  virtual void LoadAborted() = 0;
     82 
     83  // Called by the video decoder object, on the main thread,
     84  // when the video playback has ended.
     85  virtual void PlaybackEnded() = 0;
     86 
     87  // Called by the video decoder object, on the main thread,
     88  // when the resource has started seeking.
     89  virtual void SeekStarted() = 0;
     90 
     91  // Called by the video decoder object, on the main thread,
     92  // when the resource has completed seeking.
     93  virtual void SeekCompleted() = 0;
     94 
     95  // Called by the video decoder object, on the main thread,
     96  // when the resource has aborted seeking.
     97  virtual void SeekAborted() = 0;
     98 
     99  // Called by the media stream, on the main thread, when the download
    100  // has been suspended by the cache or because the element itself
    101  // asked the decoder to suspend the download.
    102  virtual void DownloadSuspended() = 0;
    103 
    104  // Called by the media decoder to indicate whether the media cache has
    105  // suspended the channel.
    106  virtual void NotifySuspendedByCache(bool aSuspendedByCache) = 0;
    107 
    108  // called to notify that the principal of the decoder's media resource has
    109  // changed.
    110  virtual void NotifyDecoderPrincipalChanged() = 0;
    111 
    112  // The status of the next frame which might be available from the decoder
    113  MOZ_DEFINE_ENUM_WITH_TOSTRING_AT_CLASS_SCOPE(
    114      NextFrameStatus, (NEXT_FRAME_AVAILABLE, NEXT_FRAME_UNAVAILABLE_BUFFERING,
    115                        NEXT_FRAME_UNAVAILABLE_SEEKING, NEXT_FRAME_UNAVAILABLE,
    116                        NEXT_FRAME_UNINITIALIZED));
    117 
    118  // Called by media decoder when the audible state changed
    119  virtual void SetAudibleState(bool aAudible) = 0;
    120 
    121  // Notified by the decoder that XPCOM shutdown has begun.
    122  // The decoder owner should call Shutdown() on the decoder and drop the
    123  // reference to the decoder to prevent further calls into the decoder.
    124  virtual void NotifyXPCOMShutdown() = 0;
    125 
    126  // Dispatches a "encrypted" event to the HTMLMediaElement, with the
    127  // provided init data. Actual dispatch may be delayed until HAVE_METADATA.
    128  // Main thread only.
    129  virtual void DispatchEncrypted(const nsTArray<uint8_t>& aInitData,
    130                                 const nsAString& aInitDataType) = 0;
    131 
    132  // Notified by the decoder that a decryption key is required before emitting
    133  // further output.
    134  virtual void NotifyWaitingForKey() {}
    135 
    136  /*
    137   * Methods that are used only in Gecko go here. We provide defaul
    138   * implementations so they can compile in Servo without modification.
    139   */
    140  // Return an abstract thread on which to run main thread runnables.
    141  static AbstractThread* AbstractMainThread() {
    142    return AbstractThread::MainThread();
    143  }
    144 
    145  // Get the HTMLMediaElement object if the decoder is being used from an
    146  // HTML media element, and null otherwise.
    147  virtual dom::HTMLMediaElement* GetMediaElement() { return nullptr; }
    148 
    149  // Called by the media decoder and the video frame to get the
    150  // ImageContainer containing the video data.
    151  virtual VideoFrameContainer* GetVideoFrameContainer() { return nullptr; }
    152 
    153  // Return the decoder owner's owner document.
    154  virtual mozilla::dom::Document* GetDocument() const { return nullptr; }
    155 
    156  // Called by the media decoder to create a GMPCrashHelper.
    157  virtual already_AddRefed<GMPCrashHelper> CreateGMPCrashHelper() {
    158    return nullptr;
    159  }
    160 
    161  // Called by the frame container to notify the layout engine that the
    162  // size of the image has changed, or the video needs to be be repainted
    163  // for some other reason.
    164  enum class ImageSizeChanged { No, Yes };
    165  enum class ForceInvalidate { No, Yes };
    166  virtual void Invalidate(ImageSizeChanged aImageSizeChanged,
    167                          const Maybe<nsIntSize>& aNewIntrinsicSize,
    168                          ForceInvalidate aForceInvalidate) {}
    169 
    170  // Called after the MediaStream we're playing rendered a frame to aContainer
    171  // with a different principalHandle than the previous frame.
    172  virtual void PrincipalHandleChangedForVideoFrameContainer(
    173      VideoFrameContainer* aContainer,
    174      const PrincipalHandle& aNewPrincipalHandle) {}
    175 
    176  // Called after the MediaDecoder has installed the given secondary video
    177  // container and render potential frames to it.
    178  virtual void OnSecondaryVideoContainerInstalled(
    179      const RefPtr<VideoFrameContainer>& aSecondaryContainer) {}
    180 
    181  // Return true is the owner is actually invisible to users.
    182  virtual bool IsActuallyInvisible() const = 0;
    183 
    184  // Returns true if the owner should resist fingerprinting.
    185  virtual bool ShouldResistFingerprinting(RFPTarget aTarget) const = 0;
    186 
    187 #ifdef MOZ_WMF_CDM
    188  // Return CDMProxy if exists.
    189  virtual CDMProxy* GetCDMProxy() const { return nullptr; }
    190 #endif
    191 
    192  /*
    193   * Servo only methods go here. Please provide default implementations so they
    194   * can build in Gecko without any modification.
    195   */
    196 };
    197 
    198 }  // namespace mozilla
    199 
    200 #endif