content/media/VideoFrameContainer.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial