2010-04-01 20:03:07 -07: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 04:12:37 -07: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/. */
|
2010-04-27 01:53:44 -07:00
|
|
|
/*
|
2011-07-11 20:39:39 -07:00
|
|
|
Each video element for a media file has two threads:
|
2010-04-27 01:53:44 -07:00
|
|
|
|
|
|
|
1) The Audio thread writes the decoded audio data to the audio
|
2011-07-11 20:39:39 -07:00
|
|
|
hardware. This is done in a separate thread to ensure that the
|
2010-04-27 01:53:44 -07:00
|
|
|
audio hardware gets a constant stream of data without
|
|
|
|
interruption due to decoding or display. At some point
|
2013-03-18 21:12:36 -07:00
|
|
|
AudioStream will be refactored to have a callback interface
|
2010-04-27 01:53:44 -07:00
|
|
|
where it asks for data and an extra thread will no longer be
|
|
|
|
needed.
|
|
|
|
|
|
|
|
2) The decode thread. This thread reads from the media stream and
|
2011-07-11 20:39:39 -07:00
|
|
|
decodes the Theora and Vorbis data. It places the decoded data into
|
|
|
|
queues for the other threads to pull from.
|
|
|
|
|
|
|
|
All file reads, seeks, and all decoding must occur on the decode thread.
|
|
|
|
Synchronisation of state between the thread is done via a monitor owned
|
2012-11-14 11:46:40 -08:00
|
|
|
by MediaDecoder.
|
2011-07-11 20:39:39 -07:00
|
|
|
|
|
|
|
The lifetime of the decode and audio threads is controlled by the state
|
|
|
|
machine when it runs on the shared state machine thread. When playback
|
|
|
|
needs to occur they are created and events dispatched to them to run
|
|
|
|
them. These events exit when decoding/audio playback is completed or
|
|
|
|
no longer required.
|
|
|
|
|
|
|
|
A/V synchronisation is handled by the state machine. It examines the audio
|
|
|
|
playback time and compares this to the next frame in the queue of video
|
|
|
|
frames. If it is time to play the video frame it is then displayed, otherwise
|
|
|
|
it schedules the state machine to run again at the time of the next frame.
|
2010-04-27 01:53:44 -07:00
|
|
|
|
|
|
|
Frame skipping is done in the following ways:
|
|
|
|
|
2011-07-11 20:39:39 -07:00
|
|
|
1) The state machine will skip all frames in the video queue whose
|
2010-04-27 01:53:44 -07:00
|
|
|
display time is less than the current audio time. This ensures
|
|
|
|
the correct frame for the current time is always displayed.
|
|
|
|
|
|
|
|
2) The decode thread will stop decoding interframes and read to the
|
|
|
|
next keyframe if it determines that decoding the remaining
|
|
|
|
interframes will cause playback issues. It detects this by:
|
|
|
|
a) If the amount of audio data in the audio queue drops
|
|
|
|
below a threshold whereby audio may start to skip.
|
|
|
|
b) If the video queue drops below a threshold where it
|
|
|
|
will be decoding video data that won't be displayed due
|
|
|
|
to the decode thread dropping the frame immediately.
|
|
|
|
|
2011-07-11 20:39:39 -07:00
|
|
|
When hardware accelerated graphics is not available, YCbCr conversion
|
|
|
|
is done on the decode thread when video frames are decoded.
|
2010-04-27 01:53:44 -07:00
|
|
|
|
|
|
|
The decode thread pushes decoded audio and videos frames into two
|
|
|
|
separate queues - one for audio and one for video. These are kept
|
2011-08-15 22:19:51 -07:00
|
|
|
separate to make it easy to constantly feed audio data to the audio
|
2010-04-27 01:53:44 -07:00
|
|
|
hardware while allowing frame skipping of video data. These queues are
|
2011-07-11 20:39:39 -07:00
|
|
|
threadsafe, and neither the decode, audio, or state machine should
|
2010-04-27 01:53:44 -07:00
|
|
|
be able to monopolize them, and cause starvation of the other threads.
|
|
|
|
|
|
|
|
Both queues are bounded by a maximum size. When this size is reached
|
|
|
|
the decode thread will no longer decode video or audio depending on the
|
2011-07-11 20:39:39 -07:00
|
|
|
queue that has reached the threshold. If both queues are full, the decode
|
|
|
|
thread will wait on the decoder monitor.
|
|
|
|
|
|
|
|
When the decode queues are full (they've reaced their maximum size) and
|
|
|
|
the decoder is not in PLAYING play state, the state machine may opt
|
|
|
|
to shut down the decode thread in order to conserve resources.
|
2010-04-27 01:53:44 -07:00
|
|
|
|
|
|
|
During playback the audio thread will be idle (via a Wait() on the
|
2011-07-11 20:39:39 -07:00
|
|
|
monitor) if the audio queue is empty. Otherwise it constantly pops
|
2011-08-15 22:19:51 -07:00
|
|
|
audio data off the queue and plays it with a blocking write to the audio
|
2013-03-18 21:12:36 -07:00
|
|
|
hardware (via AudioStream).
|
2010-04-27 01:53:44 -07:00
|
|
|
|
|
|
|
*/
|
2012-11-14 11:46:40 -08:00
|
|
|
#if !defined(MediaDecoderStateMachine_h__)
|
|
|
|
#define MediaDecoderStateMachine_h__
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-04-01 20:03:07 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2012-11-14 11:46:40 -08:00
|
|
|
#include "MediaDecoder.h"
|
|
|
|
#include "AudioAvailableEventManager.h"
|
2011-04-29 12:21:57 -07:00
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
2011-07-11 20:39:32 -07:00
|
|
|
#include "nsITimer.h"
|
2012-04-29 20:12:42 -07:00
|
|
|
#include "AudioSegment.h"
|
|
|
|
#include "VideoSegment.h"
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2012-11-14 11:45:33 -08:00
|
|
|
namespace mozilla {
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2012-11-14 11:46:40 -08:00
|
|
|
class MediaDecoderReader;
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2010-04-01 20:03:07 -07:00
|
|
|
/*
|
2011-07-11 20:39:39 -07:00
|
|
|
The state machine class. This manages the decoding and seeking in the
|
2012-11-14 11:46:40 -08:00
|
|
|
MediaDecoderReader on the decode thread, and A/V sync on the shared
|
2010-04-01 20:03:07 -07:00
|
|
|
state machine thread, and controls the audio "push" thread.
|
|
|
|
|
2011-07-11 20:39:39 -07:00
|
|
|
All internal state is synchronised via the decoder monitor. State changes
|
|
|
|
are either propagated by NotifyAll on the monitor (typically when state
|
|
|
|
changes need to be propagated to non-state machine threads) or by scheduling
|
|
|
|
the state machine to run another cycle on the shared state machine thread.
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2012-11-14 11:46:40 -08:00
|
|
|
See MediaDecoder.h for more details.
|
2010-04-01 20:03:07 -07:00
|
|
|
*/
|
2012-11-14 11:46:40 -08:00
|
|
|
class MediaDecoderStateMachine : public nsRunnable
|
2010-04-01 20:03:07 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-11-14 11:46:40 -08:00
|
|
|
typedef MediaDecoder::DecodedStreamData DecodedStreamData;
|
|
|
|
MediaDecoderStateMachine(MediaDecoder* aDecoder,
|
|
|
|
MediaDecoderReader* aReader,
|
2012-11-14 11:45:33 -08:00
|
|
|
bool aRealTime = false);
|
2012-11-14 11:46:40 -08:00
|
|
|
~MediaDecoderStateMachine();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2010-04-27 01:53:44 -07:00
|
|
|
// nsDecoderStateMachine interface
|
2012-11-14 11:46:40 -08:00
|
|
|
nsresult Init(MediaDecoderStateMachine* aCloneDonor);
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Enumeration for the valid decoding states
|
|
|
|
enum State {
|
|
|
|
DECODER_STATE_DECODING_METADATA,
|
|
|
|
DECODER_STATE_DECODING,
|
|
|
|
DECODER_STATE_SEEKING,
|
|
|
|
DECODER_STATE_BUFFERING,
|
|
|
|
DECODER_STATE_COMPLETED,
|
|
|
|
DECODER_STATE_SHUTDOWN
|
|
|
|
};
|
|
|
|
|
|
|
|
State GetState() {
|
2011-04-29 12:21:57 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2012-11-06 14:33:01 -08:00
|
|
|
return mState;
|
2010-05-05 19:31:02 -07:00
|
|
|
}
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Set the audio volume. The decoder monitor must be obtained before
|
|
|
|
// calling this.
|
2012-11-06 14:33:02 -08:00
|
|
|
void SetVolume(double aVolume);
|
|
|
|
void SetAudioCaptured(bool aCapture);
|
|
|
|
void Shutdown();
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Called from the main thread to get the duration. The decoder monitor
|
|
|
|
// must be obtained before calling this. It is in units of microseconds.
|
2012-11-06 14:33:02 -08:00
|
|
|
int64_t GetDuration();
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Called from the main thread to set the duration of the media resource
|
|
|
|
// if it is able to be obtained via HTTP headers. Called from the
|
|
|
|
// state machine thread to set the duration if it is obtained from the
|
|
|
|
// media metadata. The decoder monitor must be obtained before calling this.
|
|
|
|
// aDuration is in microseconds.
|
2012-11-06 14:33:02 -08:00
|
|
|
void SetDuration(int64_t aDuration);
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Called while decoding metadata to set the end time of the media
|
|
|
|
// resource. The decoder monitor must be obtained before calling this.
|
|
|
|
// aEndTime is in microseconds.
|
2012-11-19 07:11:21 -08:00
|
|
|
void SetMediaEndTime(int64_t aEndTime);
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Functions used by assertions to ensure we're calling things
|
|
|
|
// on the appropriate threads.
|
2012-11-06 14:33:02 -08:00
|
|
|
bool OnDecodeThread() const {
|
2010-04-27 01:53:44 -07:00
|
|
|
return IsCurrentThread(mDecodeThread);
|
|
|
|
}
|
2012-11-06 14:33:02 -08:00
|
|
|
bool OnStateMachineThread() const;
|
|
|
|
bool OnAudioThread() const {
|
|
|
|
return IsCurrentThread(mAudioThread);
|
|
|
|
}
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2012-11-14 11:45:31 -08:00
|
|
|
MediaDecoderOwner::NextFrameStatus GetNextFrameStatus();
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Cause state transitions. These methods obtain the decoder monitor
|
|
|
|
// to synchronise the change of state, and to notify other threads
|
|
|
|
// that the state has changed.
|
2012-11-06 14:33:02 -08:00
|
|
|
void Play();
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Seeks to aTime in seconds.
|
2012-11-06 14:33:02 -08:00
|
|
|
void Seek(double aTime);
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Returns the current playback position in seconds.
|
|
|
|
// Called from the main thread to get the current frame time. The decoder
|
|
|
|
// monitor must be obtained before calling this.
|
2012-11-06 14:33:02 -08:00
|
|
|
double GetCurrentTime() const;
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Clear the flag indicating that a playback position change event
|
|
|
|
// is currently queued. This is called from the main thread and must
|
|
|
|
// be called with the decode monitor held.
|
2012-11-06 14:33:02 -08:00
|
|
|
void ClearPositionChangeFlag();
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2012-11-30 05:17:54 -08:00
|
|
|
// Called from the main thread or the decoder thread to set whether the media
|
|
|
|
// resource can seek into unbuffered ranges. The decoder monitor must be
|
|
|
|
// obtained before calling this.
|
|
|
|
void SetTransportSeekable(bool aSeekable);
|
|
|
|
|
|
|
|
// Called from the main thread or the decoder thread to set whether the media
|
|
|
|
// can seek to random location. This is not true for chained ogg and WebM
|
|
|
|
// media without index. The decoder monitor must be obtained before calling
|
|
|
|
// this.
|
|
|
|
void SetMediaSeekable(bool aSeekable);
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Update the playback position. This can result in a timeupdate event
|
|
|
|
// and an invalidate of the frame being dispatched asynchronously if
|
|
|
|
// there is no such event currently queued.
|
|
|
|
// Only called on the decoder thread. Must be called with
|
|
|
|
// the decode monitor held.
|
2012-11-06 14:33:02 -08:00
|
|
|
void UpdatePlaybackPosition(int64_t aTime);
|
2012-11-06 14:33:02 -08:00
|
|
|
|
|
|
|
// Causes the state machine to switch to buffering state, and to
|
|
|
|
// immediately stop playback and buffer downloaded data. Must be called
|
|
|
|
// with the decode monitor held. Called on the state machine thread and
|
|
|
|
// the main thread.
|
2012-11-06 14:33:02 -08:00
|
|
|
void StartBuffering();
|
2010-05-05 19:31:02 -07:00
|
|
|
|
2011-07-11 20:39:34 -07:00
|
|
|
// State machine thread run function. Defers to RunStateMachine().
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
|
|
|
// This is called on the state machine thread and audio thread.
|
|
|
|
// The decoder monitor must be obtained before calling this.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasAudio() const {
|
2011-04-29 12:21:57 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2011-03-23 20:53:03 -07:00
|
|
|
return mInfo.mHasAudio;
|
2010-04-01 20:03:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is called on the state machine thread and audio thread.
|
|
|
|
// The decoder monitor must be obtained before calling this.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasVideo() const {
|
2011-04-29 12:21:57 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2011-03-23 20:53:03 -07:00
|
|
|
return mInfo.mHasVideo;
|
2010-04-01 20:03:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should be called by main thread.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HaveNextFrameData() const;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
|
|
|
// Must be called with the decode monitor held.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsBuffering() const {
|
2011-04-29 12:21:57 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2012-11-06 14:33:02 -08:00
|
|
|
return mState == DECODER_STATE_BUFFERING;
|
2010-04-01 20:03:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Must be called with the decode monitor held.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsSeeking() const {
|
2011-04-29 12:21:57 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2012-11-06 14:33:02 -08:00
|
|
|
return mState == DECODER_STATE_SEEKING;
|
2012-11-06 16:36:49 -08:00
|
|
|
}
|
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
nsresult GetBuffered(TimeRanges* aBuffered);
|
2010-08-05 00:40:35 -07:00
|
|
|
|
2012-11-22 02:38:28 -08:00
|
|
|
void SetPlaybackRate(double aPlaybackRate);
|
|
|
|
void SetPreservesPitch(bool aPreservesPitch);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t VideoQueueMemoryInUse() {
|
2011-07-21 20:17:23 -07:00
|
|
|
if (mReader) {
|
|
|
|
return mReader->VideoQueueMemoryInUse();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t AudioQueueMemoryInUse() {
|
2011-07-21 20:17:23 -07:00
|
|
|
if (mReader) {
|
|
|
|
return mReader->AudioQueueMemoryInUse();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
|
2010-09-13 01:45:50 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t GetEndMediaTime() const {
|
2011-04-29 12:21:57 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2010-10-06 15:58:36 -07:00
|
|
|
return mEndTime;
|
|
|
|
}
|
|
|
|
|
2012-11-30 05:17:54 -08:00
|
|
|
bool IsTransportSeekable() {
|
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
return mTransportSeekable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsMediaSeekable() {
|
2011-05-08 14:10:28 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2012-11-30 05:17:54 -08:00
|
|
|
return mMediaSeekable;
|
2011-05-08 14:10:28 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 14:15:45 -07:00
|
|
|
// Sets the current frame buffer length for the MozAudioAvailable event.
|
|
|
|
// Accessed on the main and state machine threads.
|
2012-11-06 14:33:02 -08:00
|
|
|
void SetFrameBufferLength(uint32_t aLength);
|
2011-04-11 14:15:45 -07:00
|
|
|
|
2011-07-11 20:39:34 -07:00
|
|
|
// Returns the shared state machine thread.
|
|
|
|
static nsIThread* GetStateMachineThread();
|
|
|
|
|
2012-04-29 20:12:42 -07:00
|
|
|
// Calls ScheduleStateMachine() after taking the decoder lock. Also
|
|
|
|
// notifies the decoder thread in case it's waiting on the decoder lock.
|
|
|
|
void ScheduleStateMachineWithLockAndWakeDecoder();
|
|
|
|
|
2011-07-11 20:39:34 -07:00
|
|
|
// Schedules the shared state machine thread to run the state machine
|
2011-07-11 20:39:32 -07:00
|
|
|
// in aUsecs microseconds from now, if it's not already scheduled to run
|
|
|
|
// earlier, in which case the request is discarded.
|
2012-12-18 20:48:32 -08:00
|
|
|
nsresult ScheduleStateMachine(int64_t aUsecs = 0);
|
2011-07-11 20:39:32 -07:00
|
|
|
|
2012-01-19 10:30:29 -08:00
|
|
|
// Creates and starts a new decode thread. Don't call this directly,
|
|
|
|
// request a new decode thread by calling
|
|
|
|
// StateMachineTracker::RequestCreateDecodeThread().
|
|
|
|
// The decoder monitor must not be held. Called on the state machine thread.
|
|
|
|
nsresult StartDecodeThread();
|
|
|
|
|
2011-07-11 20:39:34 -07:00
|
|
|
// Timer function to implement ScheduleStateMachine(aUsecs).
|
|
|
|
void TimeoutExpired();
|
|
|
|
|
2011-08-24 16:42:23 -07:00
|
|
|
// Set the media fragment end time. aEndTime is in microseconds.
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetFragmentEndTime(int64_t aEndTime);
|
2011-08-24 16:42:23 -07:00
|
|
|
|
2011-09-21 00:01:00 -07:00
|
|
|
// Drop reference to decoder. Only called during shutdown dance.
|
2012-07-30 07:20:58 -07:00
|
|
|
void ReleaseDecoder() { mDecoder = nullptr; }
|
2011-09-21 00:01:00 -07:00
|
|
|
|
2011-11-21 16:34:21 -08:00
|
|
|
// Called when a "MozAudioAvailable" event listener is added to the media
|
|
|
|
// element. Called on the main thread.
|
|
|
|
void NotifyAudioAvailableListener();
|
|
|
|
|
2012-04-29 20:12:42 -07:00
|
|
|
// Copy queued audio/video data in the reader to any output MediaStreams that
|
|
|
|
// need it.
|
2012-07-31 05:17:22 -07:00
|
|
|
void SendStreamData();
|
|
|
|
void FinishStreamData();
|
2012-08-22 08:56:38 -07:00
|
|
|
bool HaveEnoughDecodedAudio(int64_t aAmpleAudioUSecs);
|
2012-04-29 20:12:42 -07:00
|
|
|
bool HaveEnoughDecodedVideo();
|
|
|
|
|
2012-11-06 14:33:01 -08:00
|
|
|
// Returns true if the state machine has shutdown or is in the process of
|
|
|
|
// shutting down. The decoder monitor must be held while calling this.
|
2012-11-06 14:33:02 -08:00
|
|
|
bool IsShutdown();
|
2012-11-06 14:33:01 -08:00
|
|
|
|
2012-12-27 07:21:30 -08:00
|
|
|
void QueueMetadata(int64_t aPublishTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags);
|
2012-11-30 05:17:54 -08:00
|
|
|
|
2012-11-27 18:34:53 -08:00
|
|
|
protected:
|
|
|
|
virtual uint32_t GetAmpleVideoFrames() { return mAmpleVideoFrames; }
|
|
|
|
|
2012-11-06 14:33:02 -08:00
|
|
|
private:
|
2012-07-31 05:17:22 -07:00
|
|
|
class WakeDecoderRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-14 11:46:40 -08:00
|
|
|
WakeDecoderRunnable(MediaDecoderStateMachine* aSM)
|
2012-07-31 05:17:22 -07:00
|
|
|
: mMutex("WakeDecoderRunnable"), mStateMachine(aSM) {}
|
2013-05-29 13:43:41 -07:00
|
|
|
NS_IMETHOD Run() MOZ_OVERRIDE
|
2012-07-31 05:17:22 -07:00
|
|
|
{
|
2012-11-14 11:46:40 -08:00
|
|
|
nsRefPtr<MediaDecoderStateMachine> stateMachine;
|
2012-07-31 05:17:22 -07:00
|
|
|
{
|
|
|
|
// Don't let Run() (called by media stream graph thread) race with
|
|
|
|
// Revoke() (called by decoder state machine thread)
|
2012-11-14 11:45:33 -08:00
|
|
|
MutexAutoLock lock(mMutex);
|
2012-07-31 05:17:22 -07:00
|
|
|
if (!mStateMachine)
|
|
|
|
return NS_OK;
|
|
|
|
stateMachine = mStateMachine;
|
|
|
|
}
|
|
|
|
stateMachine->ScheduleStateMachineWithLockAndWakeDecoder();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
void Revoke()
|
|
|
|
{
|
2012-11-14 11:45:33 -08:00
|
|
|
MutexAutoLock lock(mMutex);
|
2012-07-31 05:17:22 -07:00
|
|
|
mStateMachine = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-14 11:45:33 -08:00
|
|
|
Mutex mMutex;
|
2012-07-31 05:17:22 -07:00
|
|
|
// Protected by mMutex.
|
|
|
|
// We don't use an owning pointer here, because keeping mStateMachine alive
|
|
|
|
// would mean in some cases we'd have to destroy mStateMachine from this
|
2012-11-14 11:46:40 -08:00
|
|
|
// object, which would be problematic since MediaDecoderStateMachine can
|
2012-07-31 05:17:22 -07:00
|
|
|
// only be destroyed on the main thread whereas this object can be destroyed
|
|
|
|
// on the media stream graph thread.
|
2012-11-14 11:46:40 -08:00
|
|
|
MediaDecoderStateMachine* mStateMachine;
|
2012-07-31 05:17:22 -07:00
|
|
|
};
|
|
|
|
WakeDecoderRunnable* GetWakeDecoderRunnable();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// Returns true if we've got less than aAudioUsecs microseconds of decoded
|
2011-04-13 15:12:23 -07:00
|
|
|
// and playable data. The decoder monitor must be held.
|
2012-08-22 08:56:38 -07:00
|
|
|
bool HasLowDecodedData(int64_t aAudioUsecs) const;
|
2011-03-23 15:28:57 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// Returns true if we're running low on data which is not yet decoded.
|
2011-03-23 15:28:57 -07:00
|
|
|
// The decoder monitor must be held.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasLowUndecodedData() const;
|
2011-03-23 15:28:57 -07:00
|
|
|
|
2011-04-13 15:12:23 -07:00
|
|
|
// Returns the number of microseconds of undecoded data available for
|
2011-03-23 15:28:57 -07:00
|
|
|
// decoding. The decoder monitor must be held.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t GetUndecodedData() const;
|
2010-11-28 12:06:38 -08:00
|
|
|
|
2011-04-13 15:12:23 -07:00
|
|
|
// Returns the number of unplayed usecs of audio we've got decoded and/or
|
2010-09-14 16:24:47 -07:00
|
|
|
// pushed to the hardware waiting to play. This is how much audio we can
|
2011-03-23 15:28:57 -07:00
|
|
|
// play without having to run the audio decoder. The decoder monitor
|
|
|
|
// must be held.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t AudioDecodedUsecs() const;
|
2010-09-14 16:24:47 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// Returns true when there's decoded audio waiting to play.
|
2010-05-12 17:59:42 -07:00
|
|
|
// The decoder monitor must be held.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasFutureAudio() const;
|
2010-05-12 17:59:42 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// Returns true if we recently exited "quick buffering" mode.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool JustExitedQuickBuffering();
|
2011-03-23 15:28:57 -07:00
|
|
|
|
2011-04-29 12:21:57 -07:00
|
|
|
// Waits on the decoder ReentrantMonitor for aUsecs microseconds. If the decoder
|
2011-04-13 15:12:23 -07:00
|
|
|
// monitor is awoken by a Notify() call, we'll continue waiting, unless
|
|
|
|
// we've moved into shutdown state. This enables us to ensure that we
|
2011-05-11 19:02:34 -07:00
|
|
|
// wait for a specified time, and that the myriad of Notify()s we do on
|
|
|
|
// the decoder monitor don't cause the audio thread to be starved. aUsecs
|
|
|
|
// values of less than 1 millisecond are rounded up to 1 millisecond
|
2011-07-11 20:39:39 -07:00
|
|
|
// (see bug 651023). The decoder monitor must be held. Called only on the
|
|
|
|
// audio thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
void Wait(int64_t aUsecs);
|
2010-04-01 20:03:07 -07:00
|
|
|
|
|
|
|
// Dispatches an asynchronous event to update the media element's ready state.
|
|
|
|
void UpdateReadyState();
|
|
|
|
|
2011-07-11 20:39:25 -07:00
|
|
|
// Resets playback timing data. Called when we seek, on the decode thread.
|
2010-04-01 20:03:07 -07:00
|
|
|
void ResetPlayback();
|
|
|
|
|
|
|
|
// Returns the audio clock, if we have audio, or -1 if we don't.
|
|
|
|
// Called on the state machine thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t GetAudioClock();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2012-11-22 02:38:28 -08:00
|
|
|
// Get the video stream position, taking the |playbackRate| change into
|
|
|
|
// account. This is a position in the media, not the duration of the playback
|
|
|
|
// so far.
|
|
|
|
int64_t GetVideoStreamPosition();
|
|
|
|
|
|
|
|
// Return the current time, either the audio clock if available (if the media
|
|
|
|
// has audio, and the playback is possible), or a clock for the video.
|
|
|
|
// Called on the state machine thread.
|
|
|
|
int64_t GetClock();
|
|
|
|
|
2011-09-26 20:31:18 -07:00
|
|
|
// Returns the presentation time of the first audio or video frame in the
|
|
|
|
// media. If the media has video, it returns the first video frame. The
|
|
|
|
// decoder monitor must be held with exactly one lock count. Called on the
|
|
|
|
// state machine thread.
|
2010-04-01 20:03:07 -07:00
|
|
|
VideoData* FindStartTime();
|
|
|
|
|
2011-01-31 18:57:13 -08:00
|
|
|
// Update only the state machine's current playback position (and duration,
|
|
|
|
// if unknown). Does not update the playback position on the decoder or
|
|
|
|
// media element -- use UpdatePlaybackPosition for that. Called on the state
|
|
|
|
// machine thread, caller must hold the decoder lock.
|
2012-08-22 08:56:38 -07:00
|
|
|
void UpdatePlaybackPositionInternal(int64_t aTime);
|
2011-01-31 18:57:13 -08:00
|
|
|
|
2011-07-11 20:39:39 -07:00
|
|
|
// Pushes the image down the rendering pipeline. Called on the shared state
|
|
|
|
// machine thread. The decoder monitor must *not* be held when calling this.
|
2011-06-23 15:08:54 -07:00
|
|
|
void RenderVideoFrame(VideoData* aData, TimeStamp aTarget);
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2010-04-01 20:03:07 -07:00
|
|
|
// If we have video, display a video frame if it's time for display has
|
2011-09-26 20:31:18 -07:00
|
|
|
// arrived, otherwise sleep until it's time for the next frame. Update the
|
|
|
|
// current frame time as appropriate, and trigger ready state update. The
|
|
|
|
// decoder monitor must be held with exactly one lock count. Called on the
|
|
|
|
// state machine thread.
|
2010-04-01 20:03:07 -07:00
|
|
|
void AdvanceFrame();
|
|
|
|
|
2011-09-26 20:31:18 -07:00
|
|
|
// Write aFrames of audio frames of silence to the audio hardware. Returns
|
|
|
|
// the number of frames actually written. The write size is capped at
|
|
|
|
// SILENCE_BYTES_CHUNK (32kB), so must be called in a loop to write the
|
|
|
|
// desired number of frames. This ensures that the playback position
|
|
|
|
// advances smoothly, and guarantees that we don't try to allocate an
|
|
|
|
// impossibly large chunk of memory in order to play back silence. Called
|
|
|
|
// on the audio thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t PlaySilence(uint32_t aFrames,
|
|
|
|
uint32_t aChannels,
|
|
|
|
uint64_t aFrameOffset);
|
2010-08-12 19:28:15 -07:00
|
|
|
|
|
|
|
// Pops an audio chunk from the front of the audio queue, and pushes its
|
2011-09-26 20:31:18 -07:00
|
|
|
// audio data to the audio hardware. MozAudioAvailable data is also queued
|
|
|
|
// here. Called on the audio thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t PlayFromAudioQueue(uint64_t aFrameOffset, uint32_t aChannels);
|
2010-08-12 19:28:15 -07:00
|
|
|
|
2012-01-19 10:30:29 -08:00
|
|
|
// Stops the decode thread, and if we have a pending request for a new
|
|
|
|
// decode thread it is canceled. The decoder monitor must be held with exactly
|
2010-04-01 20:03:07 -07:00
|
|
|
// one lock count. Called on the state machine thread.
|
2011-07-11 20:39:10 -07:00
|
|
|
void StopDecodeThread();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-07-11 20:39:10 -07:00
|
|
|
// Stops the audio thread. The decoder monitor must be held with exactly
|
2010-04-01 20:03:07 -07:00
|
|
|
// one lock count. Called on the state machine thread.
|
2011-07-11 20:39:10 -07:00
|
|
|
void StopAudioThread();
|
|
|
|
|
2012-01-19 10:30:29 -08:00
|
|
|
// Ensures the decode thread is running if it already exists, or requests
|
|
|
|
// a new decode thread be started if there currently is no decode thread.
|
|
|
|
// The decoder monitor must be held with exactly one lock count. Called on
|
|
|
|
// the state machine thread.
|
|
|
|
nsresult ScheduleDecodeThread();
|
2011-07-11 20:39:10 -07:00
|
|
|
|
|
|
|
// Starts the audio thread. The decoder monitor must be held with exactly
|
|
|
|
// one lock count. Called on the state machine thread.
|
|
|
|
nsresult StartAudioThread();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
|
|
|
// The main loop for the audio thread. Sent to the thread as
|
2010-04-20 16:21:35 -07:00
|
|
|
// an nsRunnableMethod. This continually does blocking writes to
|
2010-04-01 20:03:07 -07:00
|
|
|
// to audio stream to play audio data.
|
|
|
|
void AudioLoop();
|
|
|
|
|
2011-07-11 20:39:30 -07:00
|
|
|
// Sets internal state which causes playback of media to pause.
|
2012-11-22 02:38:28 -08:00
|
|
|
// The decoder monitor must be held. Called on the state machine,
|
2011-07-11 20:39:30 -07:00
|
|
|
// and decode threads.
|
|
|
|
void StopPlayback();
|
|
|
|
|
|
|
|
// Sets internal state which causes playback of media to begin or resume.
|
|
|
|
// Must be called with the decode monitor held. Called on the state machine
|
|
|
|
// and decode threads.
|
2010-04-01 20:03:07 -07:00
|
|
|
void StartPlayback();
|
|
|
|
|
2011-03-23 15:28:57 -07:00
|
|
|
// Moves the decoder into decoding state. Called on the state machine
|
|
|
|
// thread. The decoder monitor must be held.
|
|
|
|
void StartDecoding();
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// Returns true if we're currently playing. The decoder monitor must
|
2010-04-01 20:03:07 -07:00
|
|
|
// be held.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsPlaying();
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2010-09-14 16:24:47 -07:00
|
|
|
// Returns the "media time". This is the absolute time which the media
|
|
|
|
// playback has reached. i.e. this returns values in the range
|
|
|
|
// [mStartTime, mEndTime], and mStartTime will not be 0 if the media does
|
|
|
|
// not start at 0. Note this is different to the value returned
|
|
|
|
// by GetCurrentTime(), which is in the range [0,duration].
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t GetMediaTime() const {
|
2011-04-29 12:21:57 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
2010-09-14 16:24:47 -07:00
|
|
|
return mStartTime + mCurrentFrameTime;
|
|
|
|
}
|
|
|
|
|
2011-04-13 15:12:23 -07:00
|
|
|
// Returns an upper bound on the number of microseconds of audio that is
|
|
|
|
// decoded and playable. This is the sum of the number of usecs of audio which
|
|
|
|
// is decoded and in the reader's audio queue, and the usecs of unplayed audio
|
2011-01-12 17:06:15 -08:00
|
|
|
// which has been pushed to the audio hardware for playback. Note that after
|
|
|
|
// calling this, the audio hardware may play some of the audio pushed to
|
|
|
|
// hardware, so this can only be used as a upper bound. The decoder monitor
|
2011-07-11 20:39:39 -07:00
|
|
|
// must be held when calling this. Called on the decode thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t GetDecodedAudioDuration();
|
2011-01-12 17:06:15 -08:00
|
|
|
|
2011-07-11 20:39:23 -07:00
|
|
|
// Load metadata. Called on the decode thread. The decoder monitor
|
|
|
|
// must be held with exactly one lock count.
|
|
|
|
nsresult DecodeMetadata();
|
|
|
|
|
2011-07-11 20:39:25 -07:00
|
|
|
// Seeks to mSeekTarget. Called on the decode thread. The decoder monitor
|
|
|
|
// must be held with exactly one lock count.
|
|
|
|
void DecodeSeek();
|
|
|
|
|
|
|
|
// Decode loop, decodes data until EOF or shutdown.
|
|
|
|
// Called on the decode thread.
|
|
|
|
void DecodeLoop();
|
|
|
|
|
|
|
|
// Decode thread run function. Determines which of the Decode*() functions
|
|
|
|
// to call.
|
|
|
|
void DecodeThreadRun();
|
|
|
|
|
2012-04-29 20:12:42 -07:00
|
|
|
// Copy audio from an AudioData packet to aOutput. This may require
|
|
|
|
// inserting silence depending on the timing of the audio packet.
|
2012-07-31 05:17:22 -07:00
|
|
|
void SendStreamAudio(AudioData* aAudio, DecodedStreamData* aStream,
|
|
|
|
AudioSegment* aOutput);
|
2012-04-29 20:12:42 -07:00
|
|
|
|
2011-07-11 20:39:34 -07:00
|
|
|
// State machine thread run function. Defers to RunStateMachine().
|
|
|
|
nsresult CallRunStateMachine();
|
|
|
|
|
|
|
|
// Performs one "cycle" of the state machine. Polls the state, and may send
|
|
|
|
// a video frame to be displayed, and generally manages the decode. Called
|
|
|
|
// periodically via timer to ensure the video stays in sync.
|
|
|
|
nsresult RunStateMachine();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsStateMachineScheduled() const {
|
2011-07-11 20:39:34 -07:00
|
|
|
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
|
|
|
|
return !mTimeout.IsNull() || mRunAgain;
|
2011-07-11 20:39:32 -07:00
|
|
|
}
|
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// Returns true if we're not playing and the decode thread has filled its
|
2011-07-11 20:39:37 -07:00
|
|
|
// decode buffers and is waiting. We can shut the decode thread down in this
|
|
|
|
// case as it may not be needed again.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsPausedAndDecoderWaiting();
|
2011-07-11 20:39:37 -07:00
|
|
|
|
2011-09-21 00:01:00 -07:00
|
|
|
// The decoder object that created this state machine. The state machine
|
|
|
|
// holds a strong reference to the decoder to ensure that the decoder stays
|
|
|
|
// alive once media element has started the decoder shutdown process, and has
|
|
|
|
// dropped its reference to the decoder. This enables the state machine to
|
|
|
|
// keep using the decoder's monitor until the state machine has finished
|
|
|
|
// shutting down, without fear of the monitor being destroyed. After
|
|
|
|
// shutting down, the state machine will then release this reference,
|
|
|
|
// causing the decoder to be destroyed. This is accessed on the decode,
|
|
|
|
// state machine, audio and main threads.
|
2012-11-14 11:46:40 -08:00
|
|
|
nsRefPtr<MediaDecoder> mDecoder;
|
2011-09-21 00:01:00 -07:00
|
|
|
|
|
|
|
// The decoder monitor must be obtained before modifying this state.
|
|
|
|
// NotifyAll on the monitor must be called when the state is changed so
|
|
|
|
// that interested threads can wake up and alter behaviour if appropriate
|
|
|
|
// Accessed on state machine, audio, main, and AV thread.
|
|
|
|
State mState;
|
|
|
|
|
2010-04-01 20:03:07 -07:00
|
|
|
// Thread for pushing audio onto the audio hardware.
|
|
|
|
// The "audio push thread".
|
|
|
|
nsCOMPtr<nsIThread> mAudioThread;
|
|
|
|
|
|
|
|
// Thread for decoding video in background. The "decode thread".
|
|
|
|
nsCOMPtr<nsIThread> mDecodeThread;
|
|
|
|
|
2011-07-11 20:39:32 -07:00
|
|
|
// Timer to call the state machine Run() method. Used by
|
|
|
|
// ScheduleStateMachine(). Access protected by decoder monitor.
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
|
|
|
|
// Timestamp at which the next state machine Run() method will be called.
|
|
|
|
// If this is non-null, a call to Run() is scheduled, either by a timer,
|
|
|
|
// or via an event. Access protected by decoder monitor.
|
|
|
|
TimeStamp mTimeout;
|
|
|
|
|
2011-02-17 18:30:33 -08:00
|
|
|
// The time that playback started from the system clock. This is used for
|
|
|
|
// timing the presentation of video frames when there's no audio.
|
2010-04-01 20:03:07 -07:00
|
|
|
// Accessed only via the state machine thread.
|
|
|
|
TimeStamp mPlayStartTime;
|
|
|
|
|
2012-11-22 02:38:28 -08:00
|
|
|
// When the playbackRate changes, and there is no audio clock, it is necessary
|
|
|
|
// to reset the mPlayStartTime. This is done next time the clock is queried,
|
|
|
|
// when this member is true. Access protected by decoder monitor.
|
|
|
|
bool mResetPlayStartTime;
|
|
|
|
|
2010-04-01 20:03:07 -07:00
|
|
|
// The amount of time we've spent playing already the media. The current
|
2011-02-17 18:30:33 -08:00
|
|
|
// playback position is therefore |Now() - mPlayStartTime +
|
|
|
|
// mPlayDuration|, which must be adjusted by mStartTime if used with media
|
|
|
|
// timestamps. Accessed only via the state machine thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mPlayDuration;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
|
|
|
// Time that buffering started. Used for buffering timeout and only
|
2011-01-17 16:53:18 -08:00
|
|
|
// accessed on the state machine thread. This is null while we're not
|
|
|
|
// buffering.
|
2010-04-01 20:03:07 -07:00
|
|
|
TimeStamp mBufferingStart;
|
|
|
|
|
2011-04-13 15:12:23 -07:00
|
|
|
// Start time of the media, in microseconds. This is the presentation
|
2011-09-26 20:31:18 -07:00
|
|
|
// time of the first frame decoded from the media, and is used to calculate
|
2011-07-11 20:39:39 -07:00
|
|
|
// duration and as a bounds for seeking. Accessed on state machine, decode,
|
|
|
|
// and main threads. Access controlled by decoder monitor.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mStartTime;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-26 20:31:18 -07:00
|
|
|
// Time of the last frame in the media, in microseconds. This is the
|
|
|
|
// end time of the last frame in the media. Accessed on state
|
2011-07-11 20:39:39 -07:00
|
|
|
// machine, decode, and main threads. Access controlled by decoder monitor.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mEndTime;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-04-13 15:12:23 -07:00
|
|
|
// Position to seek to in microseconds when the seek state transition occurs.
|
2010-04-01 20:03:07 -07:00
|
|
|
// The decoder monitor lock must be obtained before reading or writing
|
2011-07-11 20:39:39 -07:00
|
|
|
// this value. Accessed on main and decode thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mSeekTime;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-08-24 16:42:23 -07:00
|
|
|
// Media Fragment end time in microseconds. Access controlled by decoder monitor.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mFragmentEndTime;
|
2011-08-24 16:42:23 -07:00
|
|
|
|
2011-07-11 20:39:30 -07:00
|
|
|
// The audio stream resource. Used on the state machine, and audio threads.
|
|
|
|
// This is created and destroyed on the audio thread, while holding the
|
|
|
|
// decoder monitor, so if this is used off the audio thread, you must
|
|
|
|
// first acquire the decoder monitor and check that it is non-null.
|
2012-11-21 19:38:39 -08:00
|
|
|
nsAutoPtr<AudioStream> mAudioStream;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2010-05-05 19:31:02 -07:00
|
|
|
// The reader, don't call its methods with the decoder monitor held.
|
|
|
|
// This is created in the play state machine's constructor, and destroyed
|
|
|
|
// in the play state machine's destructor.
|
2012-11-14 11:46:40 -08:00
|
|
|
nsAutoPtr<MediaDecoderReader> mReader;
|
2010-05-05 19:31:02 -07:00
|
|
|
|
2012-07-31 05:17:22 -07:00
|
|
|
// Accessed only on the state machine thread.
|
|
|
|
// Not an nsRevocableEventPtr since we must Revoke() it well before
|
|
|
|
// this object is destroyed, anyway.
|
|
|
|
// Protected by decoder monitor except during the SHUTDOWN state after the
|
|
|
|
// decoder thread has been stopped.
|
|
|
|
nsRevocableEventPtr<WakeDecoderRunnable> mPendingWakeDecoder;
|
|
|
|
|
2011-04-13 15:12:23 -07:00
|
|
|
// The time of the current frame in microseconds. This is referenced from
|
2010-04-01 20:03:07 -07:00
|
|
|
// 0 which is the initial playback position. Set by the state machine
|
|
|
|
// thread, and read-only from the main thread to get the current
|
|
|
|
// time value. Synchronised via decoder monitor.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mCurrentFrameTime;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-26 20:31:18 -07:00
|
|
|
// The presentation time of the first audio frame that was played in
|
2011-04-13 15:12:23 -07:00
|
|
|
// microseconds. We can add this to the audio stream position to determine
|
|
|
|
// the current audio time. Accessed on audio and state machine thread.
|
|
|
|
// Synchronized by decoder monitor.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mAudioStartTime;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-26 20:31:18 -07:00
|
|
|
// The end time of the last audio frame that's been pushed onto the audio
|
2011-04-13 15:12:23 -07:00
|
|
|
// hardware in microseconds. This will approximately be the end time of the
|
2011-09-26 20:31:18 -07:00
|
|
|
// audio stream, unless another frame is pushed to the hardware.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mAudioEndTime;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-04-13 15:12:23 -07:00
|
|
|
// The presentation end time of the last video frame which has been displayed
|
|
|
|
// in microseconds. Accessed from the state machine thread.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mVideoFrameEndTime;
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2010-04-01 20:03:07 -07:00
|
|
|
// Volume of playback. 0.0 = muted. 1.0 = full volume. Read/Written
|
|
|
|
// from the state machine and main threads. Synchronised via decoder
|
|
|
|
// monitor.
|
2011-01-16 19:03:00 -08:00
|
|
|
double mVolume;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2012-11-22 02:38:28 -08:00
|
|
|
// Playback rate. 1.0 : normal speed, 0.5 : two times slower. Synchronized via
|
|
|
|
// decoder monitor.
|
|
|
|
double mPlaybackRate;
|
|
|
|
|
|
|
|
// Pitch preservation for the playback rate. Synchronized via decoder monitor.
|
|
|
|
bool mPreservesPitch;
|
|
|
|
|
|
|
|
// Position at which the last playback rate change occured, used to compute
|
|
|
|
// the actual position in the stream when the playback rate changes and there
|
|
|
|
// is no audio to be sync-ed to. Synchronized via decoder monitor.
|
|
|
|
int64_t mBasePosition;
|
|
|
|
|
2011-03-23 15:28:57 -07:00
|
|
|
// Time at which we started decoding. Synchronised via decoder monitor.
|
|
|
|
TimeStamp mDecodeStartTime;
|
|
|
|
|
2012-08-15 23:07:26 -07:00
|
|
|
// The maximum number of second we spend buffering when we are short on
|
|
|
|
// unbuffered data.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mBufferingWait;
|
|
|
|
int64_t mLowDataThresholdUsecs;
|
2012-08-15 23:07:26 -07:00
|
|
|
|
2012-09-28 10:34:03 -07:00
|
|
|
// If we've got more than mAmpleVideoFrames decoded video frames waiting in
|
|
|
|
// the video queue, we will not decode any more video frames until some have
|
|
|
|
// been consumed by the play state machine thread.
|
|
|
|
uint32_t mAmpleVideoFrames;
|
2012-04-29 20:12:42 -07:00
|
|
|
// True if we shouldn't play our audio (but still write it to any capturing
|
2012-12-04 02:59:36 -08:00
|
|
|
// streams). When this is true, mStopAudioThread is always true and
|
|
|
|
// the audio thread will never start again after it has stopped.
|
2012-04-29 20:12:42 -07:00
|
|
|
bool mAudioCaptured;
|
|
|
|
|
2012-11-30 05:17:54 -08:00
|
|
|
// True if the media resource can be seeked on a transport level. Accessed
|
|
|
|
// from the state machine and main threads. Synchronised via decoder monitor.
|
|
|
|
bool mTransportSeekable;
|
|
|
|
|
|
|
|
// True if the media can be seeked. Accessed from the state machine and main
|
|
|
|
// threads. Synchronised via decoder monitor.
|
|
|
|
bool mMediaSeekable;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True if an event to notify about a change in the playback
|
|
|
|
// position has been queued, but not yet run. It is set to false when
|
2010-04-01 20:03:07 -07:00
|
|
|
// the event is run. This allows coalescing of these events as they can be
|
|
|
|
// produced many times per second. Synchronised via decoder monitor.
|
|
|
|
// Accessed on main and state machine threads.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mPositionChangeQueued;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True if the audio playback thread has finished. It is finished
|
2011-09-26 20:31:18 -07:00
|
|
|
// when either all the audio frames in the Vorbis bitstream have completed
|
2010-04-01 20:03:07 -07:00
|
|
|
// playing, or we've moved into shutdown state, and the threads are to be
|
|
|
|
// destroyed. Written by the audio playback thread and read and written by
|
|
|
|
// the state machine thread. Synchronised via decoder monitor.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAudioCompleted;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True if mDuration has a value obtained from an HTTP header, or from
|
2010-10-06 15:58:36 -07:00
|
|
|
// the media index/metadata. Accessed on the state machine thread.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mGotDurationFromMetaData;
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// False while decode thread should be running. Accessed state machine
|
2011-07-11 20:39:10 -07:00
|
|
|
// and decode threads. Syncrhonised by decoder monitor.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mStopDecodeThread;
|
2011-07-11 20:39:10 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True when the decode thread run function has finished, but the thread
|
2011-07-11 20:39:25 -07:00
|
|
|
// has not necessarily been shut down yet. This can happen if we switch
|
|
|
|
// from COMPLETED state to SEEKING before the state machine has a chance
|
|
|
|
// to run in the COMPLETED state and shutdown the decode thread.
|
|
|
|
// Synchronised by the decoder monitor.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDecodeThreadIdle;
|
2011-07-11 20:39:25 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// False while audio thread should be running. Accessed state machine
|
2011-07-11 20:39:10 -07:00
|
|
|
// and audio threads. Syncrhonised by decoder monitor.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mStopAudioThread;
|
2010-04-01 20:03:07 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// If this is true while we're in buffering mode, we can exit early,
|
2011-03-23 15:28:57 -07:00
|
|
|
// as it's likely we may be able to playback. This happens when we enter
|
|
|
|
// buffering mode soon after the decode starts, because the decode-ahead
|
|
|
|
// ran fast enough to exhaust all data while the download is starting up.
|
|
|
|
// Synchronised via decoder monitor.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mQuickBuffering;
|
2011-03-23 15:28:57 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True if the shared state machine thread is currently running this
|
2011-07-11 20:39:34 -07:00
|
|
|
// state machine.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsRunning;
|
2011-07-11 20:39:34 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True if we should run the state machine again once the current
|
2011-07-11 20:39:34 -07:00
|
|
|
// state machine run has finished.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mRunAgain;
|
2011-07-11 20:39:34 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True if we've dispatched an event to run the state machine. It's
|
2011-07-11 20:39:34 -07:00
|
|
|
// imperative that we don't dispatch multiple events to run the state
|
|
|
|
// machine at the same time, as our code assume all events are synchronous.
|
|
|
|
// If we dispatch multiple events, the second event can run while the
|
|
|
|
// first is shutting down a thread, causing inconsistent state.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDispatchedRunEvent;
|
2011-07-11 20:39:34 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True if the decode thread has gone filled its buffers and is now
|
2011-07-11 20:39:37 -07:00
|
|
|
// waiting to be awakened before it continues decoding. Synchronized
|
|
|
|
// by the decoder monitor.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDecodeThreadWaiting;
|
2011-07-11 20:39:37 -07:00
|
|
|
|
2011-09-29 16:34:37 -07:00
|
|
|
// True is we are decoding a realtime stream, like a camera stream
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mRealTime;
|
2012-01-19 10:30:29 -08:00
|
|
|
|
2012-04-29 20:12:42 -07:00
|
|
|
// Record whether audio and video decoding were throttled during the
|
|
|
|
// previous iteration of DecodeLooop. When we transition from
|
|
|
|
// throttled to not-throttled we need to pump decoding.
|
|
|
|
bool mDidThrottleAudioDecoding;
|
|
|
|
bool mDidThrottleVideoDecoding;
|
|
|
|
|
2012-01-19 10:30:29 -08:00
|
|
|
// True if we've requested a new decode thread, but it has not yet been
|
|
|
|
// created. Synchronized by the decoder monitor.
|
|
|
|
bool mRequestedNewDecodeThread;
|
2012-11-06 14:33:02 -08:00
|
|
|
|
2010-08-25 06:10:00 -07:00
|
|
|
// Manager for queuing and dispatching MozAudioAvailable events. The
|
|
|
|
// event manager is accessed from the state machine and audio threads,
|
|
|
|
// and takes care of synchronizing access to its internal queue.
|
2012-11-14 11:46:40 -08:00
|
|
|
AudioAvailableEventManager mEventManager;
|
2011-03-23 20:53:03 -07:00
|
|
|
|
|
|
|
// Stores presentation info required for playback. The decoder monitor
|
|
|
|
// must be held when accessing this.
|
2012-11-28 11:40:07 -08:00
|
|
|
VideoInfo mInfo;
|
2012-11-30 05:17:54 -08:00
|
|
|
|
|
|
|
mozilla::MediaMetadataManager mMetadataManager;
|
2012-12-18 20:48:32 -08:00
|
|
|
|
|
|
|
MediaDecoderOwner::NextFrameStatus mLastFrameStatus;
|
2010-08-25 06:10:00 -07:00
|
|
|
};
|
2010-08-18 10:04:31 -07:00
|
|
|
|
2012-11-14 11:45:33 -08:00
|
|
|
} // namespace mozilla;
|
2010-04-01 20:03:07 -07:00
|
|
|
#endif
|