2012-02-15 08:35:01 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef VIDEOFRAMECONTAINER_H_
|
|
|
|
#define VIDEOFRAMECONTAINER_H_
|
|
|
|
|
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "gfxPoint.h"
|
2012-08-21 08:06:46 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2015-07-03 13:13:48 +03:00
|
|
|
#include "ImageContainer.h"
|
2016-02-04 04:27:09 +03:00
|
|
|
#include "MediaSegment.h"
|
2015-12-24 05:43:28 +03:00
|
|
|
#include "MediaStreamVideoSink.h"
|
|
|
|
#include "VideoSegment.h"
|
2012-02-15 08:35:01 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
namespace dom {
|
|
|
|
class HTMLMediaElement;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2013-03-19 16:23:54 +04:00
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
/**
|
|
|
|
* This object is used in the decoder backend threads and the main thread
|
|
|
|
* to manage the "current video frame" state. This state includes timing data
|
|
|
|
* and an intrinsic size (see below).
|
|
|
|
* This has to be a thread-safe object since it's accessed by resource decoders
|
|
|
|
* and other off-main-thread components. So we can't put this state in the media
|
|
|
|
* element itself ... well, maybe we could, but it could be risky and/or
|
|
|
|
* confusing.
|
|
|
|
*/
|
2015-12-24 05:43:28 +03:00
|
|
|
class VideoFrameContainer : public MediaStreamVideoSink {
|
|
|
|
virtual ~VideoFrameContainer();
|
2014-06-20 15:08:24 +04:00
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
public:
|
2013-03-19 16:23:54 +04:00
|
|
|
typedef layers::ImageContainer ImageContainer;
|
|
|
|
typedef layers::Image Image;
|
2012-02-15 08:35:01 +04:00
|
|
|
|
2013-03-19 16:23:54 +04:00
|
|
|
VideoFrameContainer(dom::HTMLMediaElement* aElement,
|
2012-08-21 08:06:46 +04:00
|
|
|
already_AddRefed<ImageContainer> aContainer);
|
2012-08-10 19:42:53 +04:00
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
// Call on any thread
|
2015-12-24 05:43:28 +03:00
|
|
|
virtual void SetCurrentFrames(const VideoSegment& aSegment) override;
|
|
|
|
virtual void ClearFrames() override;
|
|
|
|
void SetCurrentFrame(const gfx::IntSize& aIntrinsicSize, Image* aImage,
|
|
|
|
const TimeStamp& aTargetTime);
|
2016-02-04 04:27:09 +03:00
|
|
|
// Returns the last principalHandle we notified mElement about.
|
|
|
|
PrincipalHandle GetLastPrincipalHandle();
|
2016-07-25 05:01:26 +03:00
|
|
|
PrincipalHandle GetLastPrincipalHandleLocked();
|
2016-02-04 04:27:09 +03:00
|
|
|
// We will notify mElement that aPrincipalHandle has been applied when all
|
|
|
|
// FrameIDs prior to aFrameID have been flushed out.
|
|
|
|
// aFrameID is ignored if aPrincipalHandle already is our pending principalHandle.
|
|
|
|
void UpdatePrincipalHandleForFrameID(const PrincipalHandle& aPrincipalHandle,
|
|
|
|
const ImageContainer::FrameID& aFrameID);
|
2016-07-25 05:01:26 +03:00
|
|
|
void UpdatePrincipalHandleForFrameIDLocked(const PrincipalHandle& aPrincipalHandle,
|
|
|
|
const ImageContainer::FrameID& aFrameID);
|
2015-09-23 21:49:05 +03:00
|
|
|
void SetCurrentFrames(const gfx::IntSize& aIntrinsicSize,
|
2015-03-30 08:11:37 +03:00
|
|
|
const nsTArray<ImageContainer::NonOwningImage>& aImages);
|
2015-09-23 21:49:05 +03:00
|
|
|
void ClearCurrentFrame(const gfx::IntSize& aIntrinsicSize)
|
2015-03-30 07:51:32 +03:00
|
|
|
{
|
2015-03-30 08:11:37 +03:00
|
|
|
SetCurrentFrames(aIntrinsicSize, nsTArray<ImageContainer::NonOwningImage>());
|
2015-03-30 07:51:32 +03:00
|
|
|
}
|
2015-12-24 05:43:28 +03:00
|
|
|
VideoFrameContainer* AsVideoFrameContainer() override { return this; }
|
2015-03-30 07:51:32 +03:00
|
|
|
|
2015-03-23 13:45:35 +03:00
|
|
|
void ClearCurrentFrame();
|
2015-08-31 14:33:53 +03:00
|
|
|
// Make the current frame the only frame in the container, i.e. discard
|
|
|
|
// all future frames.
|
|
|
|
void ClearFutureFrames();
|
2012-02-15 08:35:01 +04:00
|
|
|
// Time in seconds by which the last painted video frame was late by.
|
|
|
|
// E.g. if the last painted frame should have been painted at time t,
|
|
|
|
// but was actually painted at t+n, this returns n in seconds. Threadsafe.
|
|
|
|
double GetFrameDelay();
|
2015-08-07 02:37:08 +03:00
|
|
|
|
2016-09-05 09:38:43 +03:00
|
|
|
// Clear any resources that are not immediately necessary.
|
|
|
|
void ClearCachedResources();
|
|
|
|
|
2015-08-07 02:37:08 +03:00
|
|
|
// Returns a new frame ID for SetCurrentFrames(). The client must either
|
|
|
|
// call this on only one thread or provide barriers. Do not use together
|
|
|
|
// with SetCurrentFrame().
|
|
|
|
ImageContainer::FrameID NewFrameID()
|
|
|
|
{
|
|
|
|
return ++mFrameID;
|
|
|
|
}
|
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
// Call on main thread
|
2013-10-02 07:05:34 +04:00
|
|
|
enum {
|
|
|
|
INVALIDATE_DEFAULT,
|
|
|
|
INVALIDATE_FORCE
|
|
|
|
};
|
2015-12-24 05:43:28 +03:00
|
|
|
void Invalidate() override { InvalidateWithFlags(INVALIDATE_DEFAULT); }
|
2016-04-07 19:50:01 +03:00
|
|
|
void InvalidateWithFlags(uint32_t aFlags);
|
|
|
|
ImageContainer* GetImageContainer();
|
2012-07-30 18:20:58 +04:00
|
|
|
void ForgetElement() { mElement = nullptr; }
|
2012-02-15 08:35:01 +04:00
|
|
|
|
2015-12-04 03:33:21 +03:00
|
|
|
uint32_t GetDroppedImageCount() { return mImageContainer->GetDroppedImageCount(); }
|
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
protected:
|
2015-09-23 21:49:05 +03:00
|
|
|
void SetCurrentFramesLocked(const gfx::IntSize& aIntrinsicSize,
|
2015-03-30 08:11:37 +03:00
|
|
|
const nsTArray<ImageContainer::NonOwningImage>& aImages);
|
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
// Non-addreffed pointer to the element. The element calls ForgetElement
|
|
|
|
// to clear this reference when the element is destroyed.
|
2013-03-19 16:23:54 +04:00
|
|
|
dom::HTMLMediaElement* mElement;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageContainer> mImageContainer;
|
2012-02-15 08:35:01 +04:00
|
|
|
|
|
|
|
// mMutex protects all the fields below.
|
|
|
|
Mutex mMutex;
|
2015-12-24 05:43:28 +03:00
|
|
|
// Once the frame is forced to black, we initialize mBlackImage for following
|
|
|
|
// frames.
|
|
|
|
RefPtr<Image> mBlackImage;
|
2012-02-15 08:35:01 +04:00
|
|
|
// The intrinsic size is the ideal size which we should render the
|
|
|
|
// ImageContainer's current Image at.
|
|
|
|
// This can differ from the Image's actual size when the media resource
|
|
|
|
// specifies that the Image should be stretched to have the correct aspect
|
|
|
|
// ratio.
|
2015-09-23 21:49:05 +03:00
|
|
|
gfx::IntSize mIntrinsicSize;
|
2015-08-07 02:37:08 +03:00
|
|
|
// We maintain our own mFrameID which is auto-incremented at every
|
|
|
|
// SetCurrentFrame() or NewFrameID() call.
|
2015-07-03 13:13:48 +03:00
|
|
|
ImageContainer::FrameID mFrameID;
|
2015-12-24 05:43:28 +03:00
|
|
|
// We record the last played video frame to avoid playing the frame again
|
|
|
|
// with a different frame id.
|
|
|
|
VideoFrame mLastPlayedVideoFrame;
|
2012-02-15 08:35:01 +04:00
|
|
|
// True when the intrinsic size has been changed by SetCurrentFrame() since
|
|
|
|
// the last call to Invalidate().
|
|
|
|
// The next call to Invalidate() will recalculate
|
|
|
|
// and update the intrinsic size on the element, request a frame reflow and
|
|
|
|
// then reset this flag.
|
|
|
|
bool mIntrinsicSizeChanged;
|
|
|
|
// True when the Image size has changed since the last time Invalidate() was
|
|
|
|
// called. When set, the next call to Invalidate() will ensure that the
|
|
|
|
// frame is fully invalidated instead of just invalidating for the image change
|
|
|
|
// in the ImageLayer.
|
|
|
|
bool mImageSizeChanged;
|
2016-02-04 04:27:09 +03:00
|
|
|
// The last PrincipalHandle we notified mElement about.
|
|
|
|
PrincipalHandle mLastPrincipalHandle;
|
|
|
|
// The PrincipalHandle the client has notified us is changing with FrameID
|
|
|
|
// mFrameIDForPendingPrincipalHandle.
|
|
|
|
PrincipalHandle mPendingPrincipalHandle;
|
|
|
|
// The FrameID for which mPendingPrincipal is first valid.
|
|
|
|
ImageContainer::FrameID mFrameIDForPendingPrincipalHandle;
|
2012-02-15 08:35:01 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2012-02-15 08:35:01 +04:00
|
|
|
|
|
|
|
#endif /* VIDEOFRAMECONTAINER_H_ */
|