1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/VideoFrameContainer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef VIDEOFRAMECONTAINER_H_ 1.11 +#define VIDEOFRAMECONTAINER_H_ 1.12 + 1.13 +#include "mozilla/Mutex.h" 1.14 +#include "mozilla/TimeStamp.h" 1.15 +#include "gfxPoint.h" 1.16 +#include "nsCOMPtr.h" 1.17 +#include "nsAutoPtr.h" 1.18 + 1.19 +namespace mozilla { 1.20 + 1.21 +namespace dom { 1.22 +class HTMLMediaElement; 1.23 +} 1.24 + 1.25 +namespace layers { 1.26 +class Image; 1.27 +class ImageContainer; 1.28 +} 1.29 + 1.30 +/** 1.31 + * This object is used in the decoder backend threads and the main thread 1.32 + * to manage the "current video frame" state. This state includes timing data 1.33 + * and an intrinsic size (see below). 1.34 + * This has to be a thread-safe object since it's accessed by resource decoders 1.35 + * and other off-main-thread components. So we can't put this state in the media 1.36 + * element itself ... well, maybe we could, but it could be risky and/or 1.37 + * confusing. 1.38 + */ 1.39 +class VideoFrameContainer { 1.40 +public: 1.41 + typedef layers::ImageContainer ImageContainer; 1.42 + typedef layers::Image Image; 1.43 + 1.44 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoFrameContainer) 1.45 + 1.46 + VideoFrameContainer(dom::HTMLMediaElement* aElement, 1.47 + already_AddRefed<ImageContainer> aContainer); 1.48 + ~VideoFrameContainer(); 1.49 + 1.50 + // Call on any thread 1.51 + void SetCurrentFrame(const gfxIntSize& aIntrinsicSize, Image* aImage, 1.52 + TimeStamp aTargetTime); 1.53 + void ClearCurrentFrame(bool aResetSize = false); 1.54 + // Reset the VideoFrameContainer 1.55 + void Reset(); 1.56 + // Time in seconds by which the last painted video frame was late by. 1.57 + // E.g. if the last painted frame should have been painted at time t, 1.58 + // but was actually painted at t+n, this returns n in seconds. Threadsafe. 1.59 + double GetFrameDelay(); 1.60 + // Call on main thread 1.61 + enum { 1.62 + INVALIDATE_DEFAULT, 1.63 + INVALIDATE_FORCE 1.64 + }; 1.65 + void Invalidate() { InvalidateWithFlags(INVALIDATE_DEFAULT); } 1.66 + void InvalidateWithFlags(uint32_t aFlags); 1.67 + ImageContainer* GetImageContainer(); 1.68 + void ForgetElement() { mElement = nullptr; } 1.69 + 1.70 +protected: 1.71 + // Non-addreffed pointer to the element. The element calls ForgetElement 1.72 + // to clear this reference when the element is destroyed. 1.73 + dom::HTMLMediaElement* mElement; 1.74 + nsRefPtr<ImageContainer> mImageContainer; 1.75 + 1.76 + // mMutex protects all the fields below. 1.77 + Mutex mMutex; 1.78 + // The intrinsic size is the ideal size which we should render the 1.79 + // ImageContainer's current Image at. 1.80 + // This can differ from the Image's actual size when the media resource 1.81 + // specifies that the Image should be stretched to have the correct aspect 1.82 + // ratio. 1.83 + gfxIntSize mIntrinsicSize; 1.84 + // The time at which the current video frame should have been painted. 1.85 + // Access protected by mVideoUpdateLock. 1.86 + TimeStamp mPaintTarget; 1.87 + // The delay between the last video frame being presented and it being 1.88 + // painted. This is time elapsed after mPaintTarget until the most recently 1.89 + // painted frame appeared on screen. 1.90 + TimeDuration mPaintDelay; 1.91 + // True when the intrinsic size has been changed by SetCurrentFrame() since 1.92 + // the last call to Invalidate(). 1.93 + // The next call to Invalidate() will recalculate 1.94 + // and update the intrinsic size on the element, request a frame reflow and 1.95 + // then reset this flag. 1.96 + bool mIntrinsicSizeChanged; 1.97 + // True when the Image size has changed since the last time Invalidate() was 1.98 + // called. When set, the next call to Invalidate() will ensure that the 1.99 + // frame is fully invalidated instead of just invalidating for the image change 1.100 + // in the ImageLayer. 1.101 + bool mImageSizeChanged; 1.102 +}; 1.103 + 1.104 +} 1.105 + 1.106 +#endif /* VIDEOFRAMECONTAINER_H_ */