Bug 1324629. Part 4 - clean up some functions and comments. r?kaku
MozReview-Commit-ID: HP2Tp8KbRoq
--- a/dom/media/MediaDecoderReaderWrapper.h
+++ b/dom/media/MediaDecoderReaderWrapper.h
@@ -12,22 +12,16 @@
#include "mozilla/Variant.h"
#include "nsISupportsImpl.h"
#include "MediaDecoderReader.h"
#include "MediaEventSource.h"
namespace mozilla {
-typedef MozPromise<bool, bool, /* isExclusive = */ false> HaveStartTimePromise;
-
-typedef Variant<MediaData*, MediaResult> AudioCallbackData;
-typedef Variant<Tuple<MediaData*, TimeStamp>, MediaResult> VideoCallbackData;
-typedef Variant<MediaData::Type, WaitForDataRejectValue> WaitCallbackData;
-
/**
* A wrapper around MediaDecoderReader to offset the timestamps of Audio/Video
* samples by the start time to ensure MDSM can always assume zero start time.
* It also adjusts the seek target passed to Seek() to ensure correct seek time
* is passed to the underlying reader.
*/
class MediaDecoderReaderWrapper {
typedef MediaDecoderReader::MetadataPromise MetadataPromise;
@@ -39,23 +33,21 @@ class MediaDecoderReaderWrapper {
public:
MediaDecoderReaderWrapper(AbstractThread* aOwnerThread,
MediaDecoderReader* aReader);
media::TimeUnit StartTime() const;
RefPtr<MetadataPromise> ReadMetadata();
- // NOTE: please set callbacks before requesting audio/video data!
RefPtr<MediaDataPromise> RequestAudioData();
RefPtr<MediaDataPromise>
RequestVideoData(bool aSkipToNextKeyframe, media::TimeUnit aTimeThreshold);
- // NOTE: please set callbacks before invoking WaitForData()!
RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType);
RefPtr<SeekPromise> Seek(const SeekTarget& aTarget);
RefPtr<ShutdownPromise> Shutdown();
void ReleaseResources();
void ResetDecode(TrackSet aTracks);
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2180,18 +2180,16 @@ ShutdownState::Enter()
master->mVideoDecodeSuspendTimer.Reset();
master->mCDMProxyPromise.DisconnectIfExists();
if (master->IsPlaying()) {
master->StopPlayback();
}
- // To break the cycle-reference between MediaDecoderReaderWrapper and MDSM.
- master->CancelMediaDecoderReaderWrapperCallback();
master->mAudioDataRequest.DisconnectIfExists();
master->mVideoDataRequest.DisconnectIfExists();
master->mAudioWaitRequest.DisconnectIfExists();
master->mVideoWaitRequest.DisconnectIfExists();
master->Reset();
master->mMediaSink->Shutdown();
@@ -2345,19 +2343,16 @@ MediaDecoderStateMachine::Initialization
mWatchManager.Watch(mExplicitDuration, &MediaDecoderStateMachine::RecomputeDuration);
mWatchManager.Watch(mObservedDuration, &MediaDecoderStateMachine::RecomputeDuration);
mWatchManager.Watch(mPlayState, &MediaDecoderStateMachine::PlayStateChanged);
if (MediaPrefs::MDSMSuspendBackgroundVideoEnabled()) {
mIsVisible.Connect(aDecoder->CanonicalIsVisible());
mWatchManager.Watch(mIsVisible, &MediaDecoderStateMachine::VisibilityChanged);
}
-
- // Configure MediaDecoderReaderWrapper.
- SetMediaDecoderReaderWrapperCallback();
}
void
MediaDecoderStateMachine::AudioAudibleChanged(bool aAudible)
{
mIsAudioDataAudible = aAudible;
}
@@ -2573,35 +2568,28 @@ MediaDecoderStateMachine::OnVideoPopped(
mPlaybackOffset = std::max(mPlaybackOffset.Ref(), aSample->mOffset);
DispatchVideoDecodeTaskIfNeeded();
}
void
MediaDecoderStateMachine::OnAudioNotDecoded(const MediaResult& aError)
{
MOZ_ASSERT(OnTaskQueue());
+ SAMPLE_LOG("OnAudioNotDecoded aError=%u", aError.Code());
mAudioDataRequest.Complete();
- OnNotDecoded(MediaData::AUDIO_DATA, aError);
+ mStateObj->HandleNotDecoded(MediaData::AUDIO_DATA, aError);
}
void
MediaDecoderStateMachine::OnVideoNotDecoded(const MediaResult& aError)
{
MOZ_ASSERT(OnTaskQueue());
+ SAMPLE_LOG("OnVideoNotDecoded aError=%u", aError.Code());
mVideoDataRequest.Complete();
- OnNotDecoded(MediaData::VIDEO_DATA, aError);
-}
-
-void
-MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType,
- const MediaResult& aError)
-{
- MOZ_ASSERT(OnTaskQueue());
- SAMPLE_LOG("OnNotDecoded (aType=%u, aError=%u)", aType, aError.Code());
- mStateObj->HandleNotDecoded(aType, aError);
+ mStateObj->HandleNotDecoded(MediaData::VIDEO_DATA, aError);
}
void
MediaDecoderStateMachine::OnVideoDecoded(MediaData* aVideo,
TimeStamp aDecodeStartTime)
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(aVideo);
@@ -2708,28 +2696,16 @@ nsresult MediaDecoderStateMachine::Init(
auto s = new DecodeMetadataState(self);
self->mStateObj.reset(s);
s->Enter();
}));
return NS_OK;
}
-void
-MediaDecoderStateMachine::SetMediaDecoderReaderWrapperCallback()
-{
- MOZ_ASSERT(OnTaskQueue());
-}
-
-void
-MediaDecoderStateMachine::CancelMediaDecoderReaderWrapperCallback()
-{
- MOZ_ASSERT(OnTaskQueue());
-}
-
void MediaDecoderStateMachine::StopPlayback()
{
MOZ_ASSERT(OnTaskQueue());
DECODER_LOG("StopPlayback()");
mOnPlaybackEvent.Notify(MediaEventType::PlaybackStopped);
if (IsPlaying()) {
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -143,19 +143,16 @@ class MediaDecoderStateMachine
public:
typedef MediaDecoderOwner::NextFrameStatus NextFrameStatus;
typedef mozilla::layers::ImageContainer::FrameID FrameID;
MediaDecoderStateMachine(MediaDecoder* aDecoder,
MediaDecoderReader* aReader);
nsresult Init(MediaDecoder* aDecoder);
- void SetMediaDecoderReaderWrapperCallback();
- void CancelMediaDecoderReaderWrapperCallback();
-
// Enumeration for the valid decoding states
enum State {
DECODER_STATE_DECODING_METADATA,
DECODER_STATE_WAIT_FOR_CDM,
DECODER_STATE_DORMANT,
DECODER_STATE_DECODING_FIRSTFRAME,
DECODER_STATE_DECODING,
DECODER_STATE_SEEKING,
@@ -326,17 +323,16 @@ private:
// Returns true if we're currently playing. The decoder monitor must
// be held.
bool IsPlaying() const;
void OnAudioDecoded(MediaData* aAudio);
void OnVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStartTime);
void OnAudioNotDecoded(const MediaResult& aError);
void OnVideoNotDecoded(const MediaResult& aError);
- void OnNotDecoded(MediaData::Type aType, const MediaResult& aError);
void OnAudioWaited(MediaData::Type aType);
void OnVideoWaited(MediaData::Type aType);
void OnNotWaited(const WaitForDataRejectValue& aRejection);
// Resets all state related to decoding and playback, emptying all buffers
// and aborting all pending operations on the decode task queue.
void Reset(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack,
TrackInfo::kVideoTrack));
@@ -464,21 +460,19 @@ protected:
// Dispatch a task to decode audio if there is not.
void EnsureAudioDecodeTaskQueued();
// Dispatch a task to decode video if there is not.
void EnsureVideoDecodeTaskQueued();
// Start a task to decode audio.
- // The decoder monitor must be held.
void RequestAudioData();
// Start a task to decode video.
- // The decoder monitor must be held.
void RequestVideoData(bool aSkipToNextKeyframe,
const media::TimeUnit& aCurrentTime);
void WaitForData(MediaData::Type aType);
bool IsRequestingAudioData() const { return mAudioDataRequest.Exists(); }
bool IsRequestingVideoData() const { return mVideoDataRequest.Exists(); }
bool IsWaitingAudioData() const { return mAudioWaitRequest.Exists(); }