2008-07-30 10:50:14 +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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2008-07-30 10:50:14 +04:00
|
|
|
/*
|
2012-11-14 23:46:40 +04:00
|
|
|
Each video element based on MediaDecoder has a state machine to manage
|
2011-07-12 07:39:39 +04:00
|
|
|
its play state and keep the current frame up to date. All state machines
|
|
|
|
share time in a single shared thread. Each decoder also has one thread
|
|
|
|
dedicated to decoding audio and video data. This thread is shutdown when
|
|
|
|
playback is paused. Each decoder also has a thread to push decoded audio
|
|
|
|
to the hardware. This thread is not created until playback starts, but
|
|
|
|
currently is not destroyed when paused, only when playback ends.
|
|
|
|
|
|
|
|
The decoder owns the resources for downloading the media file, and the
|
2012-11-07 02:33:02 +04:00
|
|
|
high level state. It holds an owning reference to the state machine that
|
2011-07-12 07:39:39 +04:00
|
|
|
owns all the resources related to decoding data, and manages the low level
|
2012-11-07 02:33:02 +04:00
|
|
|
decoding operations and A/V sync.
|
2011-07-12 07:39:39 +04:00
|
|
|
|
|
|
|
Each state machine runs on the shared state machine thread. Every time some
|
|
|
|
action is required for a state machine, it is scheduled to run on the shared
|
|
|
|
the state machine thread. The state machine runs one "cycle" on the state
|
|
|
|
machine thread, and then returns. If necessary, it will schedule itself to
|
|
|
|
run again in future. While running this cycle, it must not block the
|
|
|
|
thread, as other state machines' events may need to run. State shared
|
|
|
|
between a state machine's threads is synchronised via the monitor owned
|
2012-11-14 23:46:40 +04:00
|
|
|
by its MediaDecoder object.
|
2008-10-19 11:39:21 +04:00
|
|
|
|
|
|
|
The Main thread controls the decode state machine by setting the value
|
2010-04-27 12:53:44 +04:00
|
|
|
of a mPlayState variable and notifying on the monitor based on the
|
|
|
|
high level player actions required (Seek, Pause, Play, etc).
|
2008-10-19 11:39:21 +04:00
|
|
|
|
|
|
|
The player states are the states requested by the client through the
|
|
|
|
DOM API. They represent the desired state of the player, while the
|
|
|
|
decoder's state represents the actual state of the decoder.
|
|
|
|
|
2012-11-07 02:33:02 +04:00
|
|
|
The high level state of the player is maintained via a PlayState value.
|
2008-10-19 11:39:21 +04:00
|
|
|
It can have the following states:
|
|
|
|
|
|
|
|
START
|
|
|
|
The decoder has been initialized but has no resource loaded.
|
|
|
|
PAUSED
|
|
|
|
A request via the API has been received to pause playback.
|
|
|
|
LOADING
|
|
|
|
A request via the API has been received to load a resource.
|
|
|
|
PLAYING
|
|
|
|
A request via the API has been received to start playback.
|
|
|
|
SEEKING
|
|
|
|
A request via the API has been received to start seeking.
|
|
|
|
COMPLETED
|
|
|
|
Playback has completed.
|
|
|
|
SHUTDOWN
|
|
|
|
The decoder is about to be destroyed.
|
|
|
|
|
|
|
|
State transition occurs when the Media Element calls the Play, Seek,
|
2012-11-14 23:46:40 +04:00
|
|
|
etc methods on the MediaDecoder object. When the transition
|
|
|
|
occurs MediaDecoder then calls the methods on the decoder state
|
2011-07-12 07:39:39 +04:00
|
|
|
machine object to cause it to behave as required by the play state.
|
|
|
|
State transitions will likely schedule the state machine to run to
|
|
|
|
affect the change.
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
An implementation of the MediaDecoderStateMachine class is the event
|
2011-07-12 07:39:39 +04:00
|
|
|
that gets dispatched to the state machine thread. Each time the event is run,
|
|
|
|
the state machine must cycle the state machine once, and then return.
|
|
|
|
|
|
|
|
The state machine has the following states:
|
2010-05-06 06:31:02 +04:00
|
|
|
|
|
|
|
DECODING_METADATA
|
|
|
|
The media headers are being loaded, and things like framerate, etc are
|
|
|
|
being determined, and the first frame of audio/video data is being decoded.
|
|
|
|
DECODING
|
2011-07-12 07:39:39 +04:00
|
|
|
The decode has started. If the PlayState is PLAYING, the decode thread
|
|
|
|
should be alive and decoding video and audio frame, the audio thread
|
|
|
|
should be playing audio, and the state machine should run periodically
|
|
|
|
to update the video frames being displayed.
|
2010-05-06 06:31:02 +04:00
|
|
|
SEEKING
|
2011-07-12 07:39:39 +04:00
|
|
|
A seek operation is in progress. The decode thread should be seeking.
|
2010-05-06 06:31:02 +04:00
|
|
|
BUFFERING
|
2011-07-12 07:39:39 +04:00
|
|
|
Decoding is paused while data is buffered for smooth playback. If playback
|
|
|
|
is paused (PlayState transitions to PAUSED) we'll destory the decode thread.
|
2010-05-06 06:31:02 +04:00
|
|
|
COMPLETED
|
2011-07-12 07:39:39 +04:00
|
|
|
The resource has completed decoding, but possibly not finished playback.
|
|
|
|
The decode thread will be destroyed. Once playback finished, the audio
|
|
|
|
thread will also be destroyed.
|
2010-05-06 06:31:02 +04:00
|
|
|
SHUTDOWN
|
2011-07-12 07:39:39 +04:00
|
|
|
The decoder object and its state machine are about to be destroyed.
|
|
|
|
Once the last state machine has been destroyed, the shared state machine
|
|
|
|
thread will also be destroyed. It will be recreated later if needed.
|
2010-05-06 06:31:02 +04:00
|
|
|
|
|
|
|
The following result in state transitions.
|
|
|
|
|
|
|
|
Shutdown()
|
2012-11-14 23:46:40 +04:00
|
|
|
Clean up any resources the MediaDecoderStateMachine owns.
|
2011-03-24 01:28:57 +03:00
|
|
|
Play()
|
|
|
|
Start decoding and playback of media data.
|
2010-05-06 06:31:02 +04:00
|
|
|
Buffer
|
|
|
|
This is not user initiated. It occurs when the
|
|
|
|
available data in the stream drops below a certain point.
|
|
|
|
Complete
|
|
|
|
This is not user initiated. It occurs when the
|
|
|
|
stream is completely decoded.
|
2011-01-17 06:03:00 +03:00
|
|
|
Seek(double)
|
2010-05-06 06:31:02 +04:00
|
|
|
Seek to the time position given in the resource.
|
|
|
|
|
|
|
|
A state transition diagram:
|
|
|
|
|
|
|
|
DECODING_METADATA
|
|
|
|
| |
|
|
|
|
v | Shutdown()
|
|
|
|
| |
|
|
|
|
v -->-------------------->--------------------------|
|
|
|
|
|---------------->----->------------------------| v
|
|
|
|
DECODING | | | | |
|
|
|
|
^ v Seek(t) | | | |
|
2011-03-24 01:28:57 +03:00
|
|
|
| Play() | v | | |
|
2010-05-06 06:31:02 +04:00
|
|
|
^-----------<----SEEKING | v Complete v v
|
|
|
|
| | | | | |
|
|
|
|
| | | COMPLETED SHUTDOWN-<-|
|
|
|
|
^ ^ | |Shutdown() |
|
|
|
|
| | | >-------->-----^
|
2011-03-24 01:28:57 +03:00
|
|
|
| Play() |Seek(t) |Buffer() |
|
2010-05-06 06:31:02 +04:00
|
|
|
-----------<--------<-------BUFFERING |
|
|
|
|
| ^
|
|
|
|
v Shutdown() |
|
|
|
|
| |
|
|
|
|
------------>-----|
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
The following represents the states that the MediaDecoder object
|
|
|
|
can be in, and the valid states the MediaDecoderStateMachine can be in at that
|
2010-05-06 06:31:02 +04:00
|
|
|
time:
|
|
|
|
|
|
|
|
player LOADING decoder DECODING_METADATA
|
|
|
|
player PLAYING decoder DECODING, BUFFERING, SEEKING, COMPLETED
|
|
|
|
player PAUSED decoder DECODING, BUFFERING, SEEKING, COMPLETED
|
|
|
|
player SEEKING decoder SEEKING
|
|
|
|
player COMPLETED decoder SHUTDOWN
|
|
|
|
player SHUTDOWN decoder SHUTDOWN
|
|
|
|
|
2010-04-27 12:53:44 +04:00
|
|
|
The general sequence of events is:
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
1) The video element calls Load on MediaDecoder. This creates the
|
2011-07-12 07:39:39 +04:00
|
|
|
state machine and starts the channel for downloading the
|
2012-11-14 23:46:40 +04:00
|
|
|
file. It instantiates and schedules the MediaDecoderStateMachine. The
|
2010-04-27 12:53:44 +04:00
|
|
|
high level LOADING state is entered, which results in the decode
|
2011-07-12 07:39:39 +04:00
|
|
|
thread being created and starting to decode metadata. These are
|
|
|
|
the headers that give the video size, framerate, etc. Load() returns
|
|
|
|
immediately to the calling video element.
|
|
|
|
|
|
|
|
2) When the metadata has been loaded by the decode thread, the state machine
|
|
|
|
will call a method on the video element object to inform it that this
|
|
|
|
step is done, so it can do the things required by the video specification
|
|
|
|
at this stage. The decode thread then continues to decode the first frame
|
2010-04-27 12:53:44 +04:00
|
|
|
of data.
|
|
|
|
|
2011-07-12 07:39:39 +04:00
|
|
|
3) When the first frame of data has been successfully decoded the state
|
|
|
|
machine calls a method on the video element object to inform it that
|
|
|
|
this step has been done, once again so it can do the required things
|
|
|
|
by the video specification at this stage.
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
This results in the high level state changing to PLAYING or PAUSED
|
|
|
|
depending on any user action that may have occurred.
|
|
|
|
|
2011-07-12 07:39:39 +04:00
|
|
|
While the play state is PLAYING, the decode thread will decode
|
|
|
|
data, and the audio thread will push audio data to the hardware to
|
|
|
|
be played. The state machine will run periodically on the shared
|
2012-11-14 23:45:13 +04:00
|
|
|
state machine thread to ensure video frames are played at the
|
2011-07-12 07:39:39 +04:00
|
|
|
correct time; i.e. the state machine manages A/V sync.
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
The Shutdown method on MediaDecoder closes the download channel, and
|
2011-07-12 07:39:39 +04:00
|
|
|
signals to the state machine that it should shutdown. The state machine
|
|
|
|
shuts down asynchronously, and will release the owning reference to the
|
|
|
|
state machine once its threads are shutdown.
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
The owning object of a MediaDecoder object *MUST* call Shutdown when
|
|
|
|
destroying the MediaDecoder object.
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2008-07-30 10:50:14 +04:00
|
|
|
*/
|
2012-11-14 23:46:40 +04:00
|
|
|
#if !defined(MediaDecoder_h_)
|
|
|
|
#define MediaDecoder_h_
|
2008-07-30 10:50:14 +04:00
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-02-15 08:35:01 +04:00
|
|
|
#include "MediaResource.h"
|
2014-02-09 12:04:38 +04:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2011-04-29 23:21:57 +04:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2013-08-24 10:12:51 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-11-14 23:45:13 +04:00
|
|
|
#include "MediaStreamGraph.h"
|
2014-04-10 15:18:18 +04:00
|
|
|
#include "AudioChannelCommon.h"
|
2012-11-19 19:11:21 +04:00
|
|
|
#include "AbstractMediaDecoder.h"
|
2013-11-12 02:52:33 +04:00
|
|
|
#include "necko-config.h"
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
class nsIStreamListener;
|
|
|
|
class nsIPrincipal;
|
|
|
|
class nsITimer;
|
|
|
|
|
2013-03-02 23:14:44 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class TimeRanges;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
class Image;
|
2012-11-14 23:45:33 +04:00
|
|
|
} //namespace layers
|
2012-08-19 23:33:25 +04:00
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
class VideoFrameContainer;
|
2012-11-14 23:46:40 +04:00
|
|
|
class MediaDecoderStateMachine;
|
2012-11-14 23:45:33 +04:00
|
|
|
class MediaDecoderOwner;
|
2012-11-14 23:45:13 +04:00
|
|
|
|
2013-01-02 21:26:08 +04:00
|
|
|
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
|
|
|
// GetTickCount() and conflicts with MediaDecoder::GetCurrentTime implementation.
|
|
|
|
#ifdef GetCurrentTime
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
|
|
|
|
2014-04-01 07:39:04 +04:00
|
|
|
// Stores the seek target; the time to seek to, and whether an Accurate,
|
|
|
|
// or "Fast" (nearest keyframe) seek was requested.
|
|
|
|
struct SeekTarget {
|
|
|
|
enum Type {
|
|
|
|
Invalid,
|
|
|
|
PrevSyncPoint,
|
|
|
|
Accurate
|
|
|
|
};
|
|
|
|
SeekTarget()
|
|
|
|
: mTime(-1.0)
|
|
|
|
, mType(SeekTarget::Invalid)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
SeekTarget(int64_t aTimeUsecs, Type aType)
|
|
|
|
: mTime(aTimeUsecs)
|
|
|
|
, mType(aType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
bool IsValid() const {
|
|
|
|
return mType != SeekTarget::Invalid;
|
|
|
|
}
|
|
|
|
void Reset() {
|
|
|
|
mTime = -1;
|
|
|
|
mType = SeekTarget::Invalid;
|
|
|
|
}
|
|
|
|
// Seek target time in microseconds.
|
|
|
|
int64_t mTime;
|
|
|
|
// Whether we should seek "Fast", or "Accurate".
|
|
|
|
// "Fast" seeks to the seek point preceeding mTime, whereas
|
|
|
|
// "Accurate" seeks as close as possible to mTime.
|
|
|
|
Type mType;
|
|
|
|
};
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
class MediaDecoder : public nsIObserver,
|
|
|
|
public AbstractMediaDecoder
|
2010-04-27 12:53:44 +04:00
|
|
|
{
|
2012-02-15 08:35:01 +04:00
|
|
|
public:
|
2013-12-02 01:09:06 +04:00
|
|
|
class DecodedStreamGraphListener;
|
|
|
|
|
2013-07-19 06:21:19 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2008-07-30 10:50:14 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// Enumeration for the valid play states (see mPlayState)
|
|
|
|
enum PlayState {
|
|
|
|
PLAY_STATE_START,
|
|
|
|
PLAY_STATE_LOADING,
|
|
|
|
PLAY_STATE_PAUSED,
|
|
|
|
PLAY_STATE_PLAYING,
|
|
|
|
PLAY_STATE_SEEKING,
|
|
|
|
PLAY_STATE_ENDED,
|
|
|
|
PLAY_STATE_SHUTDOWN
|
|
|
|
};
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder();
|
|
|
|
virtual ~MediaDecoder();
|
2012-11-07 02:33:02 +04:00
|
|
|
|
2013-11-20 07:08:10 +04:00
|
|
|
// Reset the decoder and notify the media element that
|
|
|
|
// server connection is closed.
|
|
|
|
virtual void ResetConnectionState();
|
2012-11-14 23:45:13 +04:00
|
|
|
// Create a new decoder of the same type as this one.
|
|
|
|
// Subclasses must implement this.
|
2012-11-14 23:46:40 +04:00
|
|
|
virtual MediaDecoder* Clone() = 0;
|
2012-11-14 23:45:13 +04:00
|
|
|
// Create a new state machine to run this decoder.
|
|
|
|
// Subclasses must implement this.
|
2012-11-14 23:46:40 +04:00
|
|
|
virtual MediaDecoderStateMachine* CreateStateMachine() = 0;
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Call on the main thread only.
|
|
|
|
// Perform any initialization required for the decoder.
|
|
|
|
// Return true on successful initialisation, false
|
|
|
|
// on failure.
|
2012-11-14 23:46:40 +04:00
|
|
|
virtual bool Init(MediaDecoderOwner* aOwner);
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Cleanup internal data structures. Must be called on the main
|
|
|
|
// thread by the owning object before that object disposes of this object.
|
2008-10-30 08:20:08 +03:00
|
|
|
virtual void Shutdown();
|
2012-11-07 02:33:02 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Start downloading the media. Decode the downloaded data up to the
|
|
|
|
// point of the first frame of data.
|
|
|
|
// This is called at most once per decoder, after Init().
|
2013-07-24 13:55:23 +04:00
|
|
|
virtual nsresult Load(nsIStreamListener** aListener,
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoder* aCloneDonor);
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
// Called in |Load| to open mResource.
|
|
|
|
nsresult OpenResource(nsIStreamListener** aStreamListener);
|
2012-09-18 00:45:38 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Called when the video file has completed downloading.
|
|
|
|
virtual void ResourceLoaded();
|
|
|
|
|
|
|
|
// Called if the media file encounters a network error.
|
|
|
|
virtual void NetworkError();
|
|
|
|
|
|
|
|
// Get the current MediaResource being used. Its URI will be returned
|
|
|
|
// by currentSrc. Returns what was passed to Load(), if Load() has been called.
|
2013-05-03 02:59:18 +04:00
|
|
|
// Note: The MediaResource is refcounted, but it outlives the MediaDecoder,
|
|
|
|
// so it's OK to use the reference returned by this function without
|
|
|
|
// refcounting, *unless* you need to store and use the reference after the
|
|
|
|
// MediaDecoder has been destroyed. You might need to do this if you're
|
|
|
|
// wrapping the MediaResource in some kind of byte stream interface to be
|
|
|
|
// passed to a platform decoder.
|
2012-11-19 19:11:21 +04:00
|
|
|
MediaResource* GetResource() const MOZ_FINAL MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return mResource;
|
|
|
|
}
|
2013-07-24 13:55:23 +04:00
|
|
|
void SetResource(MediaResource* aResource)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should only be called on main thread");
|
|
|
|
mResource = aResource;
|
|
|
|
}
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Return the principal of the current URI being played or downloaded.
|
|
|
|
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal();
|
|
|
|
|
|
|
|
// Return the time position in the video stream being
|
|
|
|
// played measured in seconds.
|
|
|
|
virtual double GetCurrentTime();
|
|
|
|
|
|
|
|
// Seek to the time position in (seconds) from the start of the video.
|
2014-04-01 07:39:04 +04:00
|
|
|
// If aDoFastSeek is true, we'll seek to the sync point/keyframe preceeding
|
|
|
|
// the seek target.
|
|
|
|
virtual nsresult Seek(double aTime, SeekTarget::Type aSeekType);
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Enables decoders to supply an enclosing byte range for a seek offset.
|
|
|
|
// E.g. used by ChannelMediaResource to download a whole cluster for
|
|
|
|
// DASH-WebM.
|
|
|
|
virtual nsresult GetByteRangeForSeek(int64_t const aOffset,
|
|
|
|
MediaByteRange &aByteRange) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
// Initialize state machine and schedule it.
|
2012-11-14 23:46:40 +04:00
|
|
|
nsresult InitializeStateMachine(MediaDecoder* aCloneDonor);
|
2012-09-18 00:45:38 +04:00
|
|
|
|
2008-07-30 10:50:14 +04:00
|
|
|
// Start playback of a video. 'Load' must have previously been
|
|
|
|
// called.
|
2008-10-30 08:20:08 +03:00
|
|
|
virtual nsresult Play();
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2013-06-10 16:22:05 +04:00
|
|
|
// Set/Unset dormant state if necessary.
|
|
|
|
// Dormant state is a state to free all scarce media resources
|
|
|
|
// (like hw video codec), did not decoding and stay dormant.
|
|
|
|
// It is used to share scarece media resources in system.
|
|
|
|
virtual void SetDormantIfNecessary(bool aDormant);
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Pause video playback.
|
2008-10-30 08:20:08 +03:00
|
|
|
virtual void Pause();
|
2012-11-14 23:45:13 +04:00
|
|
|
// Adjust the speed of the playback, optionally with pitch correction,
|
2011-01-17 06:03:00 +03:00
|
|
|
virtual void SetVolume(double aVolume);
|
2012-11-14 23:45:13 +04:00
|
|
|
// Sets whether audio is being captured. If it is, we won't play any
|
|
|
|
// of our audio.
|
2012-04-30 07:12:42 +04:00
|
|
|
virtual void SetAudioCaptured(bool aCaptured);
|
|
|
|
|
2014-03-11 07:44:09 +04:00
|
|
|
virtual void NotifyWaitingForResourcesStatusChanged() MOZ_OVERRIDE;
|
|
|
|
|
2014-04-08 19:29:07 +04:00
|
|
|
virtual void SetPlaybackRate(double aPlaybackRate);
|
2012-11-22 14:38:28 +04:00
|
|
|
void SetPreservesPitch(bool aPreservesPitch);
|
|
|
|
|
2014-04-01 07:43:57 +04:00
|
|
|
// Directs the decoder to not preroll extra samples until the media is
|
|
|
|
// played. This reduces the memory overhead of media elements that may
|
|
|
|
// not be played. Note that seeking also doesn't cause us start prerolling.
|
|
|
|
void SetMinimizePrerollUntilPlaybackStarts();
|
|
|
|
|
2012-07-31 16:17:22 +04:00
|
|
|
// All MediaStream-related data is protected by mReentrantMonitor.
|
2012-11-14 23:46:40 +04:00
|
|
|
// We have at most one DecodedStreamData per MediaDecoder. Its stream
|
2012-07-31 16:17:22 +04:00
|
|
|
// is used as the input for each ProcessedMediaStream created by calls to
|
|
|
|
// captureStream(UntilEnded). Seeking creates a new source stream, as does
|
|
|
|
// replaying after the input as ended. In the latter case, the new source is
|
|
|
|
// not connected to streams created by captureStreamUntilEnded.
|
2012-08-21 08:06:46 +04:00
|
|
|
|
2013-12-06 16:01:33 +04:00
|
|
|
struct DecodedStreamData {
|
2014-02-09 12:04:38 +04:00
|
|
|
typedef gfx::IntSize IntSize;
|
|
|
|
|
2012-11-14 23:46:40 +04:00
|
|
|
DecodedStreamData(MediaDecoder* aDecoder,
|
2012-07-31 16:17:22 +04:00
|
|
|
int64_t aInitialTime, SourceMediaStream* aStream);
|
|
|
|
~DecodedStreamData();
|
|
|
|
|
2013-12-02 01:09:06 +04:00
|
|
|
StreamTime GetLastOutputTime() { return mListener->GetLastOutputTime(); }
|
|
|
|
bool IsFinished() { return mListener->IsFinishedOnMainThread(); }
|
|
|
|
|
2012-07-31 16:17:22 +04:00
|
|
|
// The following group of fields are protected by the decoder's monitor
|
2012-11-07 02:33:02 +04:00
|
|
|
// and can be read or written on any thread.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mLastAudioPacketTime; // microseconds
|
|
|
|
int64_t mLastAudioPacketEndTime; // microseconds
|
2012-04-30 07:12:42 +04:00
|
|
|
// Count of audio frames written to the stream
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mAudioFramesWritten;
|
2012-07-31 16:17:22 +04:00
|
|
|
// Saved value of aInitialTime. Timestamp of the first audio and/or
|
|
|
|
// video packet written.
|
|
|
|
int64_t mInitialTime; // microseconds
|
2012-04-30 07:12:42 +04:00
|
|
|
// mNextVideoTime is the end timestamp for the last packet sent to the stream.
|
|
|
|
// Therefore video packets starting at or after this time need to be copied
|
|
|
|
// to the output stream.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mNextVideoTime; // microseconds
|
2013-02-04 14:04:24 +04:00
|
|
|
MediaDecoder* mDecoder;
|
2012-04-30 07:12:42 +04:00
|
|
|
// The last video image sent to the stream. Useful if we need to replicate
|
|
|
|
// the image.
|
2013-11-18 08:22:47 +04:00
|
|
|
nsRefPtr<layers::Image> mLastVideoImage;
|
2014-02-09 12:04:38 +04:00
|
|
|
IntSize mLastVideoImageDisplaySize;
|
2012-04-30 07:12:42 +04:00
|
|
|
// This is set to true when the stream is initialized (audio and
|
|
|
|
// video tracks added).
|
|
|
|
bool mStreamInitialized;
|
|
|
|
bool mHaveSentFinish;
|
|
|
|
bool mHaveSentFinishAudio;
|
|
|
|
bool mHaveSentFinishVideo;
|
2012-07-31 16:17:22 +04:00
|
|
|
|
|
|
|
// The decoder is responsible for calling Destroy() on this stream.
|
|
|
|
// Can be read from any thread.
|
|
|
|
const nsRefPtr<SourceMediaStream> mStream;
|
2013-12-02 01:09:06 +04:00
|
|
|
// Can be read from any thread.
|
|
|
|
nsRefPtr<DecodedStreamGraphListener> mListener;
|
2012-07-31 16:17:22 +04:00
|
|
|
// True when we've explicitly blocked this stream because we're
|
|
|
|
// not in PLAY_STATE_PLAYING. Used on the main thread only.
|
|
|
|
bool mHaveBlockedForPlayState;
|
2013-11-23 13:48:24 +04:00
|
|
|
// We also have an explicit blocker on the stream when
|
|
|
|
// mDecoderStateMachine is non-null and MediaDecoderStateMachine is false.
|
|
|
|
bool mHaveBlockedForStateMachineNotPlaying;
|
2013-12-02 01:09:06 +04:00
|
|
|
};
|
2013-02-04 14:04:24 +04:00
|
|
|
|
2013-12-02 01:09:06 +04:00
|
|
|
class DecodedStreamGraphListener : public MediaStreamListener {
|
|
|
|
public:
|
2013-12-06 16:01:33 +04:00
|
|
|
DecodedStreamGraphListener(MediaStream* aStream, DecodedStreamData* aData);
|
2013-12-02 01:09:06 +04:00
|
|
|
virtual void NotifyOutput(MediaStreamGraph* aGraph, GraphTime aCurrentTime) MOZ_OVERRIDE;
|
2013-12-06 16:01:33 +04:00
|
|
|
virtual void NotifyFinished(MediaStreamGraph* aGraph) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
void DoNotifyFinished();
|
2013-12-02 01:09:06 +04:00
|
|
|
|
|
|
|
StreamTime GetLastOutputTime()
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return mLastOutputTime;
|
|
|
|
}
|
|
|
|
void Forget()
|
|
|
|
{
|
2013-12-06 16:01:33 +04:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Main thread only");
|
|
|
|
mData = nullptr;
|
|
|
|
|
2013-12-02 01:09:06 +04:00
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
mStream = nullptr;
|
|
|
|
}
|
2013-12-06 16:01:33 +04:00
|
|
|
bool SetFinishedOnMainThread(bool aFinished)
|
2013-12-02 01:09:06 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
2013-12-06 16:01:33 +04:00
|
|
|
bool result = !mStreamFinishedOnMainThread;
|
2013-12-02 01:09:06 +04:00
|
|
|
mStreamFinishedOnMainThread = aFinished;
|
2013-12-06 16:01:33 +04:00
|
|
|
return result;
|
2013-12-02 01:09:06 +04:00
|
|
|
}
|
|
|
|
bool IsFinishedOnMainThread()
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
return mStreamFinishedOnMainThread;
|
|
|
|
}
|
|
|
|
private:
|
2013-12-06 16:01:33 +04:00
|
|
|
// Main thread only
|
|
|
|
DecodedStreamData* mData;
|
|
|
|
|
2013-12-02 01:09:06 +04:00
|
|
|
Mutex mMutex;
|
|
|
|
// Protected by mMutex
|
|
|
|
nsRefPtr<MediaStream> mStream;
|
|
|
|
// Protected by mMutex
|
|
|
|
StreamTime mLastOutputTime;
|
|
|
|
// Protected by mMutex
|
|
|
|
bool mStreamFinishedOnMainThread;
|
2012-04-30 07:12:42 +04:00
|
|
|
};
|
2013-12-02 01:09:06 +04:00
|
|
|
|
2012-07-31 16:17:22 +04:00
|
|
|
struct OutputStreamData {
|
|
|
|
void Init(ProcessedMediaStream* aStream, bool aFinishWhenEnded)
|
|
|
|
{
|
|
|
|
mStream = aStream;
|
|
|
|
mFinishWhenEnded = aFinishWhenEnded;
|
|
|
|
}
|
|
|
|
nsRefPtr<ProcessedMediaStream> mStream;
|
|
|
|
// mPort connects mDecodedStream->mStream to our mStream.
|
|
|
|
nsRefPtr<MediaInputPort> mPort;
|
|
|
|
bool mFinishWhenEnded;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Connects mDecodedStream->mStream to aStream->mStream.
|
|
|
|
*/
|
|
|
|
void ConnectDecodedStreamToOutputStream(OutputStreamData* aStream);
|
|
|
|
/**
|
|
|
|
* Disconnects mDecodedStream->mStream from all outputs and clears
|
|
|
|
* mDecodedStream.
|
|
|
|
*/
|
|
|
|
void DestroyDecodedStream();
|
|
|
|
/**
|
|
|
|
* Recreates mDecodedStream. Call this to create mDecodedStream at first,
|
|
|
|
* and when seeking, to ensure a new stream is set up with fresh buffers.
|
|
|
|
* aStartTimeUSecs is relative to the state machine's mStartTime.
|
2013-11-23 13:48:24 +04:00
|
|
|
* Decoder monitor must be held.
|
2012-07-31 16:17:22 +04:00
|
|
|
*/
|
|
|
|
void RecreateDecodedStream(int64_t aStartTimeUSecs);
|
2013-11-23 13:48:24 +04:00
|
|
|
/**
|
|
|
|
* Call this when mDecoderStateMachine or mDecoderStateMachine->IsPlaying() changes.
|
|
|
|
* Decoder monitor must be held.
|
|
|
|
*/
|
|
|
|
void UpdateStreamBlockingForStateMachinePlaying();
|
2012-07-31 16:17:22 +04:00
|
|
|
nsTArray<OutputStreamData>& OutputStreams()
|
2012-04-30 07:12:42 +04:00
|
|
|
{
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
return mOutputStreams;
|
|
|
|
}
|
2012-07-31 16:17:22 +04:00
|
|
|
DecodedStreamData* GetDecodedStream()
|
|
|
|
{
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
return mDecodedStream;
|
|
|
|
}
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Add an output stream. All decoder output will be sent to the stream.
|
|
|
|
// The stream is initially blocked. The decoder is responsible for unblocking
|
|
|
|
// it while it is playing back.
|
2012-07-31 16:17:22 +04:00
|
|
|
virtual void AddOutputStream(ProcessedMediaStream* aStream, bool aFinishWhenEnded);
|
2012-04-30 07:12:42 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Return the duration of the video in seconds.
|
2011-01-17 06:03:00 +03:00
|
|
|
virtual double GetDuration();
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
// Return the duration of the video in seconds.
|
|
|
|
int64_t GetMediaDuration() MOZ_FINAL MOZ_OVERRIDE;
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// A media stream is assumed to be infinite if the metadata doesn't
|
|
|
|
// contain the duration, and range requests are not supported, and
|
|
|
|
// no headers give a hint of a possible duration (Content-Length,
|
|
|
|
// Content-Duration, and variants), and we cannot seek in the media
|
|
|
|
// stream to determine the duration.
|
|
|
|
//
|
|
|
|
// When the media stream ends, we can know the duration, thus the stream is
|
|
|
|
// no longer considered to be infinite.
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual void SetInfinite(bool aInfinite);
|
2011-08-01 22:11:20 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Return true if the stream is infinite (see SetInfinite).
|
|
|
|
virtual bool IsInfinite();
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Called by MediaResource when the "cache suspended" status changes.
|
|
|
|
// If MediaResource::IsSuspendedByCache returns true, then the decoder
|
|
|
|
// should stop buffering or otherwise waiting for download progress and
|
|
|
|
// start consuming data, if possible, because the cache is full.
|
2009-04-01 04:52:56 +04:00
|
|
|
virtual void NotifySuspendedStatusChanged();
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Called by MediaResource when some data has been received.
|
|
|
|
// Call on the main thread only.
|
2009-04-01 04:52:56 +04:00
|
|
|
virtual void NotifyBytesDownloaded();
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Called by nsChannelToPipeListener or MediaResource when the
|
|
|
|
// download has ended. Called on the main thread only. aStatus is
|
|
|
|
// the result from OnStopRequest.
|
2009-02-05 11:02:21 +03:00
|
|
|
virtual void NotifyDownloadEnded(nsresult aStatus);
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Called as data arrives on the stream and is read into the cache. Called
|
|
|
|
// on the main thread only.
|
|
|
|
virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
|
|
|
|
|
|
|
|
// Called by MediaResource when the principal of the resource has
|
|
|
|
// changed. Called on main thread only.
|
2012-04-30 07:12:42 +04:00
|
|
|
virtual void NotifyPrincipalChanged();
|
2012-11-14 23:45:13 +04:00
|
|
|
|
2013-09-18 07:37:23 +04:00
|
|
|
// Called by the MediaResource to keep track of the number of bytes read
|
|
|
|
// from the resource. Called on the main by an event runner dispatched
|
|
|
|
// by the MediaResource read functions.
|
|
|
|
void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE;
|
2012-11-19 19:11:21 +04:00
|
|
|
|
|
|
|
int64_t GetEndMediaTime() const MOZ_FINAL MOZ_OVERRIDE;
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-05-15 09:57:17 +04:00
|
|
|
// Return true if we are currently seeking in the media resource.
|
|
|
|
// Call on the main thread only.
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsSeeking() const;
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// Return true if the decoder has reached the end of playback.
|
2008-12-14 21:02:54 +03:00
|
|
|
// Call on the main thread only.
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsEnded() const;
|
2008-12-14 21:02:54 +03:00
|
|
|
|
2011-04-14 02:12:23 +04:00
|
|
|
// Set the duration of the media resource in units of seconds.
|
2009-02-07 13:10:34 +03:00
|
|
|
// This is called via a channel listener if it can pick up the duration
|
|
|
|
// from a content header. Must be called from the main thread only.
|
2011-04-14 02:12:23 +04:00
|
|
|
virtual void SetDuration(double aDuration);
|
2009-02-07 13:10:34 +03:00
|
|
|
|
2013-09-10 04:45:33 +04:00
|
|
|
// Sets the initial duration of the media. Called while the media metadata
|
|
|
|
// is being read and the decode is being setup.
|
2013-01-29 06:34:27 +04:00
|
|
|
void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
|
2013-09-10 04:45:33 +04:00
|
|
|
// Updates the media duration. This is called while the media is being
|
|
|
|
// played, calls before the media has reached loaded metadata are ignored.
|
|
|
|
// The duration is assumed to be an estimate, and so a degree of
|
|
|
|
// instability is expected; if the incoming duration is not significantly
|
|
|
|
// different from the existing duration, the change request is ignored.
|
|
|
|
// If the incoming duration is significantly different, the duration is
|
|
|
|
// changed, this causes a durationchanged event to fire to the media
|
|
|
|
// element.
|
|
|
|
void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
|
2012-11-19 19:11:21 +04:00
|
|
|
|
2008-11-10 04:38:02 +03:00
|
|
|
// Set a flag indicating whether seeking is supported
|
2012-12-05 02:51:34 +04:00
|
|
|
virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
|
2012-11-30 17:17:54 +04:00
|
|
|
virtual void SetTransportSeekable(bool aTransportSeekable) MOZ_FINAL MOZ_OVERRIDE;
|
|
|
|
// Returns true if this media supports seeking. False for example for WebM
|
|
|
|
// files without an index and chained ogg files.
|
|
|
|
virtual bool IsMediaSeekable() MOZ_FINAL MOZ_OVERRIDE;
|
|
|
|
// Returns true if seeking is supported on a transport level (e.g. the server
|
|
|
|
// supports range requests, we are playing a file, etc.).
|
|
|
|
virtual bool IsTransportSeekable();
|
2011-08-09 14:10:48 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Return the time ranges that can be seeked into.
|
2013-11-18 08:22:47 +04:00
|
|
|
virtual nsresult GetSeekable(dom::TimeRanges* aSeekable);
|
2008-11-10 04:38:02 +03:00
|
|
|
|
2011-08-25 03:42:23 +04:00
|
|
|
// Set the end time of the media resource. When playback reaches
|
|
|
|
// this point the media pauses. aTime is in seconds.
|
2012-11-19 19:11:21 +04:00
|
|
|
virtual void SetFragmentEndTime(double aTime);
|
|
|
|
|
|
|
|
// Set the end time of the media. aTime is in microseconds.
|
|
|
|
void SetMediaEndTime(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE;
|
2011-08-25 03:42:23 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Invalidate the frame.
|
|
|
|
void Invalidate();
|
2013-10-02 07:05:34 +04:00
|
|
|
void InvalidateWithFlags(uint32_t aFlags);
|
2009-02-05 11:02:21 +03:00
|
|
|
|
2009-01-22 02:54:40 +03:00
|
|
|
// Suspend any media downloads that are in progress. Called by the
|
2012-11-14 23:45:13 +04:00
|
|
|
// media element when it is sent to the bfcache, or when we need
|
|
|
|
// to throttle the download. Call on the main thread only. This can
|
|
|
|
// be called multiple times, there's an internal "suspend count".
|
2009-01-22 02:54:40 +03:00
|
|
|
virtual void Suspend();
|
|
|
|
|
|
|
|
// Resume any media downloads that have been suspended. Called by the
|
2012-11-14 23:45:13 +04:00
|
|
|
// media element when it is restored from the bfcache, or when we need
|
|
|
|
// to stop throttling the download. Call on the main thread only.
|
|
|
|
// The download will only actually resume once as many Resume calls
|
|
|
|
// have been made as Suspend calls. When aForceBuffering is true,
|
|
|
|
// we force the decoder to go into buffering state before resuming
|
|
|
|
// playback.
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual void Resume(bool aForceBuffering);
|
2009-01-22 02:54:40 +03:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Moves any existing channel loads into the background, so that they don't
|
|
|
|
// block the load event. This is called when we stop delaying the load
|
|
|
|
// event. Any new loads initiated (for example to seek) will also be in the
|
|
|
|
// background. Implementations of this must call MoveLoadsToBackground() on
|
|
|
|
// their MediaResource.
|
2009-04-10 05:28:24 +04:00
|
|
|
virtual void MoveLoadsToBackground();
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Returns a weak reference to the media decoder owner.
|
2013-11-18 08:22:47 +04:00
|
|
|
MediaDecoderOwner* GetMediaOwner() const;
|
2012-11-14 23:45:13 +04:00
|
|
|
|
2010-04-02 07:03:07 +04:00
|
|
|
// Called by the state machine to notify the decoder that the duration
|
|
|
|
// has changed.
|
|
|
|
void DurationChanged();
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
bool OnStateMachineThread() const MOZ_OVERRIDE;
|
2010-04-27 12:53:44 +04:00
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
bool OnDecodeThread() const MOZ_OVERRIDE;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
|
|
|
// Returns the monitor for other threads to synchronise access to
|
2008-11-18 11:19:32 +03:00
|
|
|
// state.
|
2012-11-19 19:11:21 +04:00
|
|
|
ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// Returns true if the decoder is shut down
|
|
|
|
bool IsShutdown() const MOZ_FINAL MOZ_OVERRIDE;
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2010-08-05 11:40:35 +04:00
|
|
|
// Constructs the time ranges representing what segments of the media
|
|
|
|
// are buffered and playable.
|
2013-11-18 08:22:47 +04:00
|
|
|
virtual nsresult GetBuffered(dom::TimeRanges* aBuffered);
|
2010-08-05 11:40:35 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Returns the size, in bytes, of the heap memory used by the currently
|
|
|
|
// queued decoded video and audio data.
|
2014-03-20 01:33:12 +04:00
|
|
|
size_t SizeOfVideoQueue();
|
2014-01-23 07:14:45 +04:00
|
|
|
size_t SizeOfAudioQueue();
|
2011-07-22 07:17:23 +04:00
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return mVideoFrameContainer;
|
|
|
|
}
|
2013-11-18 08:22:47 +04:00
|
|
|
layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE;
|
2010-09-13 12:45:50 +04:00
|
|
|
|
2008-11-18 11:19:32 +03:00
|
|
|
// Return the current state. Can be called on any thread. If called from
|
|
|
|
// a non-main thread, the decoder monitor must be held.
|
2010-04-02 07:03:07 +04:00
|
|
|
PlayState GetState() {
|
2008-10-19 11:39:21 +04:00
|
|
|
return mPlayState;
|
|
|
|
}
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Fire progress events if needed according to the time and byte
|
|
|
|
// constraints outlined in the specification. aTimer is true
|
|
|
|
// if the method is called as a result of the progress timer rather
|
|
|
|
// than the result of downloaded data.
|
|
|
|
void Progress(bool aTimer);
|
|
|
|
|
|
|
|
// Fire timeupdate events if needed according to the time constraints
|
|
|
|
// outlined in the specification.
|
|
|
|
void FireTimeUpdate();
|
|
|
|
|
2009-01-15 23:26:51 +03:00
|
|
|
// Stop updating the bytes downloaded for progress notifications. Called
|
|
|
|
// when seeking to prevent wild changes to the progress notification.
|
|
|
|
// Must be called with the decoder monitor held.
|
2013-01-29 06:34:28 +04:00
|
|
|
virtual void StopProgressUpdates();
|
2009-01-15 23:26:51 +03:00
|
|
|
|
|
|
|
// Allow updating the bytes downloaded for progress notifications. Must
|
|
|
|
// be called with the decoder monitor held.
|
2013-01-29 06:34:28 +04:00
|
|
|
virtual void StartProgressUpdates();
|
2009-01-15 23:26:51 +03:00
|
|
|
|
2009-04-01 04:52:56 +04:00
|
|
|
// Something has changed that could affect the computed playback rate,
|
|
|
|
// so recompute it. The monitor must be held.
|
2012-12-13 23:42:45 +04:00
|
|
|
virtual void UpdatePlaybackRate();
|
|
|
|
|
|
|
|
// Used to estimate rates of data passing through the decoder's channel.
|
|
|
|
// Records activity stopping on the channel. The monitor must be held.
|
|
|
|
virtual void NotifyPlaybackStarted() {
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
mPlaybackStatistics.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used to estimate rates of data passing through the decoder's channel.
|
|
|
|
// Records activity stopping on the channel. The monitor must be held.
|
|
|
|
virtual void NotifyPlaybackStopped() {
|
|
|
|
GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
mPlaybackStatistics.Stop();
|
|
|
|
}
|
2009-04-01 04:52:56 +04:00
|
|
|
|
|
|
|
// The actual playback rate computation. The monitor must be held.
|
2012-12-13 23:42:45 +04:00
|
|
|
virtual double ComputePlaybackRate(bool* aReliable);
|
2009-04-01 04:52:56 +04:00
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
// Return true when the media is same-origin with the element. The monitor
|
|
|
|
// must be held.
|
|
|
|
bool IsSameOriginMedia();
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Returns true if we can play the entire media through without stopping
|
|
|
|
// to buffer, given the current download and playback rates.
|
|
|
|
bool CanPlayThrough();
|
|
|
|
|
2010-05-06 06:31:02 +04:00
|
|
|
// Make the decoder state machine update the playback position. Called by
|
2012-11-07 02:33:02 +04:00
|
|
|
// the reader on the decoder thread (Assertions for this checked by
|
2010-05-06 06:31:02 +04:00
|
|
|
// mDecoderStateMachine). This must be called with the decode monitor
|
|
|
|
// held.
|
2012-11-19 19:11:21 +04:00
|
|
|
void UpdatePlaybackPosition(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE;
|
2012-11-16 07:25:26 +04:00
|
|
|
|
2014-04-10 15:18:18 +04:00
|
|
|
void SetAudioChannelType(dom::AudioChannelType aType) { mAudioChannelType = aType; }
|
|
|
|
dom::AudioChannelType GetAudioChannelType() { return mAudioChannelType; }
|
2012-11-16 07:25:26 +04:00
|
|
|
|
2012-11-30 17:17:54 +04:00
|
|
|
// Send a new set of metadata to the state machine, to be dispatched to the
|
|
|
|
// main thread to be presented when the |currentTime| of the media is greater
|
|
|
|
// or equal to aPublishTime.
|
|
|
|
void QueueMetadata(int64_t aPublishTime,
|
|
|
|
int aChannels,
|
|
|
|
int aRate,
|
|
|
|
bool aHasAudio,
|
2012-12-27 19:21:30 +04:00
|
|
|
bool aHasVideo,
|
2012-11-30 17:17:54 +04:00
|
|
|
MetadataTags* aTags);
|
|
|
|
|
2012-11-07 02:33:02 +04:00
|
|
|
/******
|
2008-07-30 10:50:14 +04:00
|
|
|
* The following methods must only be called on the main
|
|
|
|
* thread.
|
|
|
|
******/
|
|
|
|
|
2008-11-18 11:19:32 +03:00
|
|
|
// Change to a new play state. This updates the mState variable and
|
|
|
|
// notifies any thread blocking on this object's monitor of the
|
|
|
|
// change. Call on the main thread only.
|
2014-04-08 19:29:07 +04:00
|
|
|
virtual void ChangeState(PlayState aState);
|
2008-11-18 11:19:32 +03:00
|
|
|
|
2013-09-23 13:53:36 +04:00
|
|
|
// Called by |ChangeState|, to update the state machine.
|
|
|
|
// Call on the main thread only and the lock must be obtained.
|
|
|
|
virtual void ApplyStateToStateMachine(PlayState aState);
|
|
|
|
|
2012-12-07 03:27:08 +04:00
|
|
|
// May be called by the reader to notify this decoder that the metadata from
|
|
|
|
// the media file has been read. Call on the decode thread only.
|
2012-11-19 19:11:21 +04:00
|
|
|
void OnReadMetadataCompleted() MOZ_OVERRIDE { }
|
2012-09-18 00:45:38 +04:00
|
|
|
|
|
|
|
// Called when the metadata from the media file has been loaded by the
|
|
|
|
// state machine. Call on the main thread only.
|
2014-04-08 19:29:07 +04:00
|
|
|
virtual void MetadataLoaded(int aChannels,
|
|
|
|
int aRate,
|
|
|
|
bool aHasAudio,
|
|
|
|
bool aHasVideo,
|
|
|
|
MetadataTags* aTags);
|
2008-07-30 10:50:14 +04:00
|
|
|
|
|
|
|
// Called when the first frame has been loaded.
|
|
|
|
// Call on the main thread only.
|
|
|
|
void FirstFrameLoaded();
|
|
|
|
|
2013-09-04 15:13:06 +04:00
|
|
|
// Returns true if the resource has been loaded. Acquires the monitor.
|
2013-01-29 06:34:28 +04:00
|
|
|
// Call from any thread.
|
|
|
|
virtual bool IsDataCachedToEndOfResource();
|
|
|
|
|
2008-07-30 10:50:14 +04:00
|
|
|
// Called when the video has completed playing.
|
|
|
|
// Call on the main thread only.
|
2008-10-19 11:39:21 +04:00
|
|
|
void PlaybackEnded();
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// Seeking has stopped. Inform the element on the main
|
|
|
|
// thread.
|
|
|
|
void SeekingStopped();
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2009-05-31 14:02:17 +04:00
|
|
|
// Seeking has stopped at the end of the resource. Inform the element on the main
|
|
|
|
// thread.
|
|
|
|
void SeekingStoppedAtEnd();
|
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// Seeking has started. Inform the element on the main
|
|
|
|
// thread.
|
|
|
|
void SeekingStarted();
|
|
|
|
|
2008-10-23 12:02:18 +04:00
|
|
|
// Called when the backend has changed the current playback
|
|
|
|
// position. It dispatches a timeupdate event and invalidates the frame.
|
|
|
|
// This must be called on the main thread only.
|
|
|
|
void PlaybackPositionChanged();
|
|
|
|
|
2009-02-11 04:43:45 +03:00
|
|
|
// Calls mElement->UpdateReadyStateForData, telling it whether we have
|
|
|
|
// data for the next frame and if we're buffering. Main thread only.
|
2014-04-08 19:29:07 +04:00
|
|
|
virtual void UpdateReadyStateForData();
|
2009-02-11 04:43:45 +03:00
|
|
|
|
2009-04-01 04:52:56 +04:00
|
|
|
// Find the end of the cached data starting at the current decoder
|
|
|
|
// position.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t GetDownloadPosition();
|
2009-04-01 04:52:56 +04:00
|
|
|
|
2010-04-27 12:53:45 +04:00
|
|
|
// Updates the approximate byte offset which playback has reached. This is
|
|
|
|
// used to calculate the readyState transitions.
|
2012-08-22 19:56:38 +04:00
|
|
|
void UpdatePlaybackOffset(int64_t aOffset);
|
2010-05-06 06:31:02 +04:00
|
|
|
|
|
|
|
// Provide access to the state machine object
|
2012-11-19 19:11:21 +04:00
|
|
|
MediaDecoderStateMachine* GetStateMachine() const;
|
2012-11-07 04:36:49 +04:00
|
|
|
|
2011-09-21 11:01:00 +04:00
|
|
|
// Drop reference to state machine. Only called during shutdown dance.
|
2012-11-07 02:33:02 +04:00
|
|
|
virtual void ReleaseStateMachine();
|
2011-09-21 11:01:00 +04:00
|
|
|
|
2009-09-22 04:08:13 +04:00
|
|
|
// Notifies the element that decoding has failed.
|
2012-09-30 03:29:04 +04:00
|
|
|
virtual void DecodeError();
|
2009-09-22 04:08:13 +04:00
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
// Indicate whether the media is same-origin with the element.
|
|
|
|
void UpdateSameOriginStatus(bool aSameOrigin);
|
|
|
|
|
2013-05-04 14:12:41 +04:00
|
|
|
MediaDecoderOwner* GetOwner() MOZ_OVERRIDE;
|
|
|
|
|
2014-04-01 07:43:57 +04:00
|
|
|
// Returns true if we're logically playing, that is, if the Play() has
|
|
|
|
// been called and Pause() has not or we have not yet reached the end
|
|
|
|
// of media. This is irrespective of the seeking state; if the owner
|
|
|
|
// calls Play() and then Seek(), we still count as logically playing.
|
|
|
|
// The decoder monitor must be held.
|
|
|
|
bool IsLogicallyPlaying();
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
static bool IsRawEnabled();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool IsOggEnabled();
|
|
|
|
static bool IsOpusEnabled();
|
|
|
|
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
static bool IsWaveEnabled();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
static bool IsWebMEnabled();
|
|
|
|
#endif
|
2013-11-12 02:52:33 +04:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 13:53:36 +04:00
|
|
|
static bool IsRtspEnabled();
|
|
|
|
#endif
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
static bool IsGStreamerEnabled();
|
|
|
|
#endif
|
|
|
|
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2012-11-14 23:45:13 +04:00
|
|
|
static bool IsOmxEnabled();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
static bool IsMediaPluginsEnabled();
|
|
|
|
#endif
|
|
|
|
|
2012-12-18 12:49:58 +04:00
|
|
|
#ifdef MOZ_WMF
|
|
|
|
static bool IsWMFEnabled();
|
|
|
|
#endif
|
|
|
|
|
2013-09-14 05:14:42 +04:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
static bool IsAppleMP3Enabled();
|
|
|
|
#endif
|
|
|
|
|
2011-07-12 07:39:34 +04:00
|
|
|
// Schedules the state machine to run one cycle on the shared state
|
|
|
|
// machine thread. Main thread only.
|
|
|
|
nsresult ScheduleStateMachineThread();
|
2011-07-12 07:39:32 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
struct Statistics {
|
|
|
|
// Estimate of the current playback rate (bytes/second).
|
|
|
|
double mPlaybackRate;
|
|
|
|
// Estimate of the current download rate (bytes/second). This
|
|
|
|
// ignores time that the channel was paused by Gecko.
|
|
|
|
double mDownloadRate;
|
|
|
|
// Total length of media stream in bytes; -1 if not known
|
|
|
|
int64_t mTotalBytes;
|
|
|
|
// Current position of the download, in bytes. This is the offset of
|
|
|
|
// the first uncached byte after the decoder position.
|
|
|
|
int64_t mDownloadPosition;
|
|
|
|
// Current position of decoding, in bytes (how much of the stream
|
|
|
|
// has been consumed)
|
|
|
|
int64_t mDecoderPosition;
|
|
|
|
// Current position of playback, in bytes
|
|
|
|
int64_t mPlaybackPosition;
|
|
|
|
// If false, then mDownloadRate cannot be considered a reliable
|
|
|
|
// estimate (probably because the download has only been running
|
|
|
|
// a short time).
|
|
|
|
bool mDownloadRateReliable;
|
|
|
|
// If false, then mPlaybackRate cannot be considered a reliable
|
|
|
|
// estimate (probably because playback has only been running
|
|
|
|
// a short time).
|
|
|
|
bool mPlaybackRateReliable;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return statistics. This is used for progress events and other things.
|
|
|
|
// This can be called from any thread. It's only a snapshot of the
|
|
|
|
// current state, since other threads might be changing the state
|
|
|
|
// at any time.
|
2012-12-13 23:42:45 +04:00
|
|
|
virtual Statistics GetStatistics();
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Frame decoding/painting related performance counters.
|
|
|
|
// Threadsafe.
|
|
|
|
class FrameStatistics {
|
|
|
|
public:
|
|
|
|
|
|
|
|
FrameStatistics() :
|
2012-11-14 23:46:40 +04:00
|
|
|
mReentrantMonitor("MediaDecoder::FrameStats"),
|
2012-11-14 23:45:13 +04:00
|
|
|
mParsedFrames(0),
|
|
|
|
mDecodedFrames(0),
|
|
|
|
mPresentedFrames(0) {}
|
|
|
|
|
|
|
|
// Returns number of frames which have been parsed from the media.
|
|
|
|
// Can be called on any thread.
|
|
|
|
uint32_t GetParsedFrames() {
|
2012-11-14 23:46:40 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-11-14 23:45:13 +04:00
|
|
|
return mParsedFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of parsed frames which have been decoded.
|
|
|
|
// Can be called on any thread.
|
|
|
|
uint32_t GetDecodedFrames() {
|
2012-11-14 23:46:40 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-11-14 23:45:13 +04:00
|
|
|
return mDecodedFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the number of decoded frames which have been sent to the rendering
|
|
|
|
// pipeline for painting ("presented").
|
|
|
|
// Can be called on any thread.
|
|
|
|
uint32_t GetPresentedFrames() {
|
2012-11-14 23:46:40 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-11-14 23:45:13 +04:00
|
|
|
return mPresentedFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increments the parsed and decoded frame counters by the passed in counts.
|
|
|
|
// Can be called on any thread.
|
|
|
|
void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) {
|
|
|
|
if (aParsed == 0 && aDecoded == 0)
|
|
|
|
return;
|
2012-11-14 23:46:40 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-11-14 23:45:13 +04:00
|
|
|
mParsedFrames += aParsed;
|
|
|
|
mDecodedFrames += aDecoded;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increments the presented frame counters.
|
|
|
|
// Can be called on any thread.
|
|
|
|
void NotifyPresentedFrame() {
|
2012-11-14 23:46:40 +04:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
2012-11-14 23:45:13 +04:00
|
|
|
++mPresentedFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ReentrantMonitor to protect access of playback statistics.
|
|
|
|
ReentrantMonitor mReentrantMonitor;
|
|
|
|
|
|
|
|
// Number of frames parsed and demuxed from media.
|
2013-07-24 03:46:43 +04:00
|
|
|
// Access protected by mReentrantMonitor.
|
2012-11-14 23:45:13 +04:00
|
|
|
uint32_t mParsedFrames;
|
|
|
|
|
|
|
|
// Number of parsed frames which were actually decoded.
|
2013-07-24 03:46:43 +04:00
|
|
|
// Access protected by mReentrantMonitor.
|
2012-11-14 23:45:13 +04:00
|
|
|
uint32_t mDecodedFrames;
|
|
|
|
|
|
|
|
// Number of decoded frames which were actually sent down the rendering
|
2013-07-24 03:46:43 +04:00
|
|
|
// pipeline to be painted ("presented"). Access protected by mReentrantMonitor.
|
2012-11-14 23:45:13 +04:00
|
|
|
uint32_t mPresentedFrames;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Return the frame decode/paint related statistics.
|
|
|
|
FrameStatistics& GetFrameStatistics() { return mFrameStats; }
|
|
|
|
|
2012-11-19 19:11:21 +04:00
|
|
|
// Increments the parsed and decoded frame counters by the passed in counts.
|
|
|
|
// Can be called on any thread.
|
2012-12-13 23:42:45 +04:00
|
|
|
virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_OVERRIDE
|
2012-11-19 19:11:21 +04:00
|
|
|
{
|
|
|
|
GetFrameStatistics().NotifyDecodedFrames(aParsed, aDecoded);
|
|
|
|
}
|
|
|
|
|
2013-11-18 08:22:47 +04:00
|
|
|
protected:
|
2008-07-30 10:50:14 +04:00
|
|
|
/******
|
2009-02-05 11:02:21 +03:00
|
|
|
* The following members should be accessed with the decoder lock held.
|
2008-07-30 10:50:14 +04:00
|
|
|
******/
|
2009-02-05 11:02:21 +03:00
|
|
|
|
|
|
|
// Current decoding position in the stream. This is where the decoder
|
2009-04-01 04:52:56 +04:00
|
|
|
// is up to consuming the stream. This is not adjusted during decoder
|
|
|
|
// seek operations, but it's updated at the end when we start playing
|
|
|
|
// back again.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mDecoderPosition;
|
2009-02-05 11:02:21 +03:00
|
|
|
// Current playback position in the stream. This is (approximately)
|
2009-04-01 04:52:56 +04:00
|
|
|
// where we're up to playing back the stream. This is not adjusted
|
|
|
|
// during decoder seek operations, but it's updated at the end when we
|
|
|
|
// start playing back again.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mPlaybackPosition;
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2008-10-23 12:02:18 +04:00
|
|
|
// The current playback position of the media resource in units of
|
|
|
|
// seconds. This is updated approximately at the framerate of the
|
|
|
|
// video (if it is a video) or the callback period of the audio.
|
|
|
|
// It is read and written from the main thread only.
|
2011-01-17 06:03:00 +03:00
|
|
|
double mCurrentTime;
|
2008-10-23 12:02:18 +04:00
|
|
|
|
2008-10-19 11:39:21 +04:00
|
|
|
// Volume that playback should start at. 0.0 = muted. 1.0 = full
|
2010-04-02 07:03:07 +04:00
|
|
|
// volume. Readable/Writeable from the main thread.
|
2011-01-17 06:03:00 +03:00
|
|
|
double mInitialVolume;
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2013-02-26 12:52:23 +04:00
|
|
|
// PlaybackRate and pitch preservation status we should start at.
|
|
|
|
// Readable/Writeable from the main thread.
|
|
|
|
double mInitialPlaybackRate;
|
|
|
|
bool mInitialPreservesPitch;
|
|
|
|
|
2008-11-10 04:38:02 +03:00
|
|
|
// Duration of the media resource. Set to -1 if unknown.
|
2010-05-06 06:31:02 +04:00
|
|
|
// Set when the metadata is loaded. Accessed on the main thread
|
2008-11-10 04:38:02 +03:00
|
|
|
// only.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mDuration;
|
2008-11-10 04:38:02 +03:00
|
|
|
|
2012-04-30 07:12:42 +04:00
|
|
|
// True when playback should start with audio captured (not playing).
|
|
|
|
bool mInitialAudioCaptured;
|
|
|
|
|
2012-11-30 17:17:54 +04:00
|
|
|
// True if the resource is seekable at a transport level (server supports byte
|
|
|
|
// range requests, local file, etc.).
|
|
|
|
bool mTransportSeekable;
|
|
|
|
|
|
|
|
// True if the media is seekable (i.e. supports random access).
|
|
|
|
bool mMediaSeekable;
|
2008-11-10 04:38:02 +03:00
|
|
|
|
2013-07-24 13:55:23 +04:00
|
|
|
// True if the media is same-origin with the element. Data can only be
|
|
|
|
// passed to MediaStreams when this is true.
|
|
|
|
bool mSameOriginMedia;
|
|
|
|
|
2008-07-30 10:50:14 +04:00
|
|
|
/******
|
|
|
|
* The following member variables can be accessed from any thread.
|
|
|
|
******/
|
|
|
|
|
2010-04-02 07:03:07 +04:00
|
|
|
// The state machine object for handling the decoding. It is safe to
|
|
|
|
// call methods of this object from other threads. Its internal data
|
|
|
|
// is synchronised on a monitor. The lifetime of this object is
|
|
|
|
// after mPlayState is LOADING and before mPlayState is SHUTDOWN. It
|
|
|
|
// is safe to access it during this period.
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<MediaDecoderStateMachine> mDecoderStateMachine;
|
2010-04-02 07:03:07 +04:00
|
|
|
|
2012-02-15 08:35:01 +04:00
|
|
|
// Media data resource.
|
2013-02-05 01:34:23 +04:00
|
|
|
nsRefPtr<MediaResource> mResource;
|
2008-07-30 10:50:14 +04:00
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
// |ReentrantMonitor| for detecting when the video play state changes. A call
|
|
|
|
// to |Wait| on this monitor will block the thread until the next state
|
|
|
|
// change.
|
|
|
|
// Using a wrapper class to restrict direct access to the |ReentrantMonitor|
|
2012-11-14 23:46:40 +04:00
|
|
|
// object. Subclasses may override |MediaDecoder|::|GetReentrantMonitor|
|
|
|
|
// e.g. |DASHRepDecoder|::|GetReentrantMonitor| returns the monitor in the
|
|
|
|
// main |DASHDecoder| object. In this case, directly accessing the
|
|
|
|
// member variable mReentrantMonitor in |DASHRepDecoder| is wrong.
|
2012-09-18 00:45:38 +04:00
|
|
|
// The wrapper |RestrictedAccessMonitor| restricts use to the getter
|
|
|
|
// function rather than the object itself.
|
|
|
|
private:
|
|
|
|
class RestrictedAccessMonitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RestrictedAccessMonitor(const char* aName) :
|
|
|
|
mReentrantMonitor(aName)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(RestrictedAccessMonitor);
|
|
|
|
}
|
|
|
|
~RestrictedAccessMonitor()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(RestrictedAccessMonitor);
|
|
|
|
}
|
2008-10-19 11:39:21 +04:00
|
|
|
|
2012-09-18 00:45:38 +04:00
|
|
|
// Returns a ref to the reentrant monitor
|
|
|
|
ReentrantMonitor& GetReentrantMonitor() {
|
|
|
|
return mReentrantMonitor;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
ReentrantMonitor mReentrantMonitor;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The |RestrictedAccessMonitor| member object.
|
|
|
|
RestrictedAccessMonitor mReentrantMonitor;
|
|
|
|
|
2013-11-18 08:22:47 +04:00
|
|
|
protected:
|
2012-04-30 07:12:42 +04:00
|
|
|
// Data about MediaStreams that are being fed by this decoder.
|
2012-07-31 16:17:22 +04:00
|
|
|
nsTArray<OutputStreamData> mOutputStreams;
|
|
|
|
// The SourceMediaStream we are using to feed the mOutputStreams. This stream
|
|
|
|
// is never exposed outside the decoder.
|
|
|
|
// Only written on the main thread while holding the monitor. Therefore it
|
|
|
|
// can be read on any thread while holding the monitor, or on the main thread
|
|
|
|
// without holding the monitor.
|
|
|
|
nsAutoPtr<DecodedStreamData> mDecodedStream;
|
2012-04-30 07:12:42 +04:00
|
|
|
|
2013-06-10 16:22:05 +04:00
|
|
|
// True if this decoder is in dormant state.
|
|
|
|
// Should be true only when PlayState is PLAY_STATE_LOADING.
|
|
|
|
bool mIsDormant;
|
|
|
|
|
2013-08-26 20:11:58 +04:00
|
|
|
// True if this decoder is exiting from dormant state.
|
|
|
|
// Should be true only when PlayState is PLAY_STATE_LOADING.
|
|
|
|
bool mIsExitingDormant;
|
|
|
|
|
2012-05-15 09:57:17 +04:00
|
|
|
// Set to one of the valid play states.
|
|
|
|
// This can only be changed on the main thread while holding the decoder
|
|
|
|
// monitor. Thus, it can be safely read while holding the decoder monitor
|
|
|
|
// OR on the main thread.
|
|
|
|
// Any change to the state on the main thread must call NotifyAll on the
|
|
|
|
// monitor so the decode thread can wake up.
|
2008-10-19 11:39:21 +04:00
|
|
|
PlayState mPlayState;
|
|
|
|
|
2012-05-15 09:57:17 +04:00
|
|
|
// The state to change to after a seek or load operation.
|
|
|
|
// This can only be changed on the main thread while holding the decoder
|
|
|
|
// monitor. Thus, it can be safely read while holding the decoder monitor
|
|
|
|
// OR on the main thread.
|
2008-11-18 11:19:32 +03:00
|
|
|
// Any change to the state must call NotifyAll on the monitor.
|
2012-05-15 09:57:23 +04:00
|
|
|
// This can only be PLAY_STATE_PAUSED or PLAY_STATE_PLAYING.
|
|
|
|
PlayState mNextState;
|
2009-01-15 23:26:51 +03:00
|
|
|
|
2013-09-04 15:13:06 +04:00
|
|
|
// Position to seek to when the seek notification is received by the
|
|
|
|
// decode thread.
|
|
|
|
// This can only be changed on the main thread while holding the decoder
|
|
|
|
// monitor. Thus, it can be safely read while holding the decoder monitor
|
|
|
|
// OR on the main thread.
|
2014-04-01 07:39:04 +04:00
|
|
|
// If the SeekTarget's IsValid() accessor returns false, then no seek has
|
|
|
|
// been requested. When a seek is started this is reset to invalid.
|
|
|
|
SeekTarget mRequestedSeekTarget;
|
2013-09-04 15:13:06 +04:00
|
|
|
|
2009-02-05 11:02:21 +03:00
|
|
|
// True when we have fully loaded the resource and reported that
|
|
|
|
// to the element (i.e. reached NETWORK_LOADED state).
|
|
|
|
// Accessed on the main thread only.
|
2013-01-29 06:34:28 +04:00
|
|
|
bool mCalledResourceLoaded;
|
2009-01-15 23:26:51 +03:00
|
|
|
|
|
|
|
// True when seeking or otherwise moving the play position around in
|
|
|
|
// such a manner that progress event data is inaccurate. This is set
|
2009-02-05 11:02:21 +03:00
|
|
|
// during seek and duration operations to prevent the progress indicator
|
2009-01-15 23:26:51 +03:00
|
|
|
// from jumping around. Read/Write from any thread. Must have decode monitor
|
|
|
|
// locked before accessing.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIgnoreProgressData;
|
2011-08-01 22:11:20 +04:00
|
|
|
|
2011-09-30 03:34:37 +04:00
|
|
|
// True if the stream is infinite (e.g. a webradio).
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mInfiniteStream;
|
2012-07-31 16:17:22 +04:00
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// Start timer to update download progress information.
|
|
|
|
nsresult StartProgress();
|
|
|
|
|
|
|
|
// Stop progress information timer.
|
|
|
|
nsresult StopProgress();
|
|
|
|
|
|
|
|
// Ensures our media stream has been pinned.
|
|
|
|
void PinForSeek();
|
|
|
|
|
|
|
|
// Ensures our media stream has been unpinned.
|
|
|
|
void UnpinForSeek();
|
|
|
|
|
|
|
|
// Timer used for updating progress events
|
|
|
|
nsCOMPtr<nsITimer> mProgressTimer;
|
|
|
|
|
|
|
|
// This should only ever be accessed from the main thread.
|
|
|
|
// It is set in Init and cleared in Shutdown when the element goes away.
|
|
|
|
// The decoder does not add a reference the element.
|
2012-11-14 23:46:40 +04:00
|
|
|
MediaDecoderOwner* mOwner;
|
2012-11-14 23:45:13 +04:00
|
|
|
|
|
|
|
// Counters related to decode and presentation of frames.
|
|
|
|
FrameStatistics mFrameStats;
|
|
|
|
|
|
|
|
nsRefPtr<VideoFrameContainer> mVideoFrameContainer;
|
|
|
|
|
|
|
|
// Time that the last progress event was fired. Read/Write from the
|
|
|
|
// main thread only.
|
|
|
|
TimeStamp mProgressTime;
|
|
|
|
|
|
|
|
// Time that data was last read from the media resource. Used for
|
|
|
|
// computing if the download has stalled and to rate limit progress events
|
|
|
|
// when data is arriving slower than PROGRESS_MS. A value of null indicates
|
|
|
|
// that a stall event has already fired and not to fire another one until
|
|
|
|
// more data is received. Read/Write from the main thread only.
|
|
|
|
TimeStamp mDataTime;
|
|
|
|
|
2012-12-13 23:42:45 +04:00
|
|
|
// Data needed to estimate playback data rate. The timeline used for
|
|
|
|
// this estimate is "decode time" (where the "current time" is the
|
|
|
|
// time of the last decoded video frame).
|
|
|
|
MediaChannelStatistics mPlaybackStatistics;
|
|
|
|
|
2012-11-14 23:45:13 +04:00
|
|
|
// True when our media stream has been pinned. We pin the stream
|
|
|
|
// while seeking.
|
|
|
|
bool mPinnedForSeek;
|
|
|
|
|
|
|
|
// True if the decoder is being shutdown. At this point all events that
|
|
|
|
// are currently queued need to return immediately to prevent javascript
|
|
|
|
// being run that operates on the element and decoder during shutdown.
|
|
|
|
// Read/Write from the main thread only.
|
|
|
|
bool mShuttingDown;
|
2012-11-16 07:25:26 +04:00
|
|
|
|
2012-11-22 14:38:28 +04:00
|
|
|
// True if the playback is paused because the playback rate member is 0.0.
|
|
|
|
bool mPausedForPlaybackRateNull;
|
|
|
|
|
2012-11-16 07:25:26 +04:00
|
|
|
// Be assigned from media element during the initialization and pass to
|
|
|
|
// AudioStream Class.
|
2014-04-10 15:18:18 +04:00
|
|
|
dom::AudioChannelType mAudioChannelType;
|
2014-04-01 07:43:57 +04:00
|
|
|
|
|
|
|
// True if the decoder has been directed to minimize its preroll before
|
|
|
|
// playback starts. After the first time playback starts, we don't attempt
|
|
|
|
// to minimize preroll, as we assume the user is likely to keep playing,
|
|
|
|
// or play the media again.
|
|
|
|
bool mMinimizePreroll;
|
2008-07-30 10:50:14 +04:00
|
|
|
};
|
|
|
|
|
2012-11-14 23:45:33 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2008-07-30 10:50:14 +04:00
|
|
|
#endif
|