content/media/VideoFrameContainer.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef VIDEOFRAMECONTAINER_H_
     8 #define VIDEOFRAMECONTAINER_H_
    10 #include "mozilla/Mutex.h"
    11 #include "mozilla/TimeStamp.h"
    12 #include "gfxPoint.h"
    13 #include "nsCOMPtr.h"
    14 #include "nsAutoPtr.h"
    16 namespace mozilla {
    18 namespace dom {
    19 class HTMLMediaElement;
    20 }
    22 namespace layers {
    23 class Image;
    24 class ImageContainer;
    25 }
    27 /**
    28  * This object is used in the decoder backend threads and the main thread
    29  * to manage the "current video frame" state. This state includes timing data
    30  * and an intrinsic size (see below).
    31  * This has to be a thread-safe object since it's accessed by resource decoders
    32  * and other off-main-thread components. So we can't put this state in the media
    33  * element itself ... well, maybe we could, but it could be risky and/or
    34  * confusing.
    35  */
    36 class VideoFrameContainer {
    37 public:
    38   typedef layers::ImageContainer ImageContainer;
    39   typedef layers::Image Image;
    41   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoFrameContainer)
    43   VideoFrameContainer(dom::HTMLMediaElement* aElement,
    44                       already_AddRefed<ImageContainer> aContainer);
    45   ~VideoFrameContainer();
    47   // Call on any thread
    48   void SetCurrentFrame(const gfxIntSize& aIntrinsicSize, Image* aImage,
    49                        TimeStamp aTargetTime);
    50   void ClearCurrentFrame(bool aResetSize = false);
    51   // Reset the VideoFrameContainer
    52   void Reset();
    53   // Time in seconds by which the last painted video frame was late by.
    54   // E.g. if the last painted frame should have been painted at time t,
    55   // but was actually painted at t+n, this returns n in seconds. Threadsafe.
    56   double GetFrameDelay();
    57   // Call on main thread
    58   enum {
    59     INVALIDATE_DEFAULT,
    60     INVALIDATE_FORCE
    61   };
    62   void Invalidate() { InvalidateWithFlags(INVALIDATE_DEFAULT); }
    63   void InvalidateWithFlags(uint32_t aFlags);
    64   ImageContainer* GetImageContainer();
    65   void ForgetElement() { mElement = nullptr; }
    67 protected:
    68   // Non-addreffed pointer to the element. The element calls ForgetElement
    69   // to clear this reference when the element is destroyed.
    70   dom::HTMLMediaElement* mElement;
    71   nsRefPtr<ImageContainer> mImageContainer;
    73   // mMutex protects all the fields below.
    74   Mutex mMutex;
    75   // The intrinsic size is the ideal size which we should render the
    76   // ImageContainer's current Image at.
    77   // This can differ from the Image's actual size when the media resource
    78   // specifies that the Image should be stretched to have the correct aspect
    79   // ratio.
    80   gfxIntSize mIntrinsicSize;
    81   // The time at which the current video frame should have been painted.
    82   // Access protected by mVideoUpdateLock.
    83   TimeStamp mPaintTarget;
    84   // The delay between the last video frame being presented and it being
    85   // painted. This is time elapsed after mPaintTarget until the most recently
    86   // painted frame appeared on screen.
    87   TimeDuration mPaintDelay;
    88   // True when the intrinsic size has been changed by SetCurrentFrame() since
    89   // the last call to Invalidate().
    90   // The next call to Invalidate() will recalculate
    91   // and update the intrinsic size on the element, request a frame reflow and
    92   // then reset this flag.
    93   bool mIntrinsicSizeChanged;
    94   // True when the Image size has changed since the last time Invalidate() was
    95   // called. When set, the next call to Invalidate() will ensure that the
    96   // frame is fully invalidated instead of just invalidating for the image change
    97   // in the ImageLayer.
    98   bool mImageSizeChanged;
    99 };
   101 }
   103 #endif /* VIDEOFRAMECONTAINER_H_ */

mercurial