Bug 1159974 - Mirror mPlaybackRate. r=jww

This commit is contained in:
Bobby Holley 2015-05-01 11:39:42 -07:00
Родитель 49578f1914
Коммит d594a72f36
5 изменённых файлов: 27 добавлений и 24 удалений

Просмотреть файл

@ -600,7 +600,7 @@ MediaDecoder::MediaDecoder() :
mPlaybackPosition(0),
mCurrentTime(0.0),
mVolume(AbstractThread::MainThread(), 0.0, "MediaDecoder::mVolume (Canonical)"),
mInitialPlaybackRate(1.0),
mPlaybackRate(AbstractThread::MainThread(), 1.0, "MediaDecoder::mPlaybackRate (Canonical)"),
mInitialPreservesPitch(true),
mDuration(-1),
mMediaSeekable(true),
@ -750,7 +750,6 @@ void MediaDecoder::SetStateMachineParameters()
if (GetDecodedStream()) {
mDecoderStateMachine->SetAudioCaptured();
}
SetPlaybackRate(mInitialPlaybackRate);
mDecoderStateMachine->SetPreservesPitch(mInitialPreservesPitch);
if (mMinimizePreroll) {
mDecoderStateMachine->SetMinimizePrerollUntilPlaybackStarts();
@ -1546,11 +1545,10 @@ bool MediaDecoder::OnStateMachineTaskQueue() const
void MediaDecoder::SetPlaybackRate(double aPlaybackRate)
{
if (aPlaybackRate == 0.0) {
mPlaybackRate = aPlaybackRate;
if (mPlaybackRate == 0.0) {
mPausedForPlaybackRateNull = true;
mInitialPlaybackRate = aPlaybackRate;
Pause();
return;
} else if (mPausedForPlaybackRateNull) {
// Play() uses mPausedForPlaybackRateNull value, so must reset it first
mPausedForPlaybackRateNull = false;
@ -1560,12 +1558,6 @@ void MediaDecoder::SetPlaybackRate(double aPlaybackRate)
Play();
}
}
if (mDecoderStateMachine) {
mDecoderStateMachine->SetPlaybackRate(aPlaybackRate);
} else {
mInitialPlaybackRate = aPlaybackRate;
}
}
void MediaDecoder::SetPreservesPitch(bool aPreservesPitch)

Просмотреть файл

@ -1086,8 +1086,11 @@ public:
protected:
// PlaybackRate and pitch preservation status we should start at.
// Readable/Writeable from the main thread.
double mInitialPlaybackRate;
Canonical<double> mPlaybackRate;
public:
AbstractCanonical<double>* CanonicalPlaybackRate() { return &mPlaybackRate; }
protected:
bool mInitialPreservesPitch;
// Duration of the media resource. Set to -1 if unknown.

Просмотреть файл

@ -228,6 +228,7 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mDecodedVideoEndTime(-1),
mVolume(mTaskQueue, 1.0, "MediaDecoderStateMachine::mVolume (Mirror)"),
mPlaybackRate(1.0),
mLogicalPlaybackRate(mTaskQueue, 1.0, "MediaDecoderStateMachine::mLogicalPlaybackRate (Mirror)"),
mPreservesPitch(true),
mLowAudioThresholdUsecs(detail::LOW_AUDIO_USECS),
mAmpleAudioThresholdUsecs(detail::AMPLE_AUDIO_USECS),
@ -308,11 +309,13 @@ MediaDecoderStateMachine::InitializationTask()
mPlayState.Connect(mDecoder->CanonicalPlayState());
mNextPlayState.Connect(mDecoder->CanonicalNextPlayState());
mVolume.Connect(mDecoder->CanonicalVolume());
mLogicalPlaybackRate.Connect(mDecoder->CanonicalPlaybackRate());
// Initialize watchers.
mWatchManager.Watch(mState, &MediaDecoderStateMachine::UpdateNextFrameStatus);
mWatchManager.Watch(mAudioCompleted, &MediaDecoderStateMachine::UpdateNextFrameStatus);
mWatchManager.Watch(mVolume, &MediaDecoderStateMachine::VolumeChanged);
mWatchManager.Watch(mLogicalPlaybackRate, &MediaDecoderStateMachine::LogicalPlaybackRateChanged);
}
@ -2548,6 +2551,7 @@ MediaDecoderStateMachine::FinishShutdown()
mPlayState.DisconnectIfConnected();
mNextPlayState.DisconnectIfConnected();
mVolume.DisconnectIfConnected();
mLogicalPlaybackRate.DisconnectIfConnected();
mNextFrameStatus.DisconnectAll();
// Shut down the watch manager before shutting down our task queue.
@ -3383,14 +3387,14 @@ bool MediaDecoderStateMachine::IsStateMachineScheduled() const
return mDispatchedStateMachine || mDelayedScheduler.IsScheduled();
}
void MediaDecoderStateMachine::SetPlaybackRate(double aPlaybackRate)
void
MediaDecoderStateMachine::LogicalPlaybackRateChanged()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
NS_ASSERTION(aPlaybackRate != 0,
"PlaybackRate == 0 should be handled before this function.");
MOZ_ASSERT(OnTaskQueue());
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
if (mPlaybackRate == aPlaybackRate) {
if (mLogicalPlaybackRate == 0) {
// This case is handled in MediaDecoder by pausing playback.
return;
}
@ -3404,7 +3408,7 @@ void MediaDecoderStateMachine::SetPlaybackRate(double aPlaybackRate)
SetPlayStartTime(TimeStamp::Now());
}
mPlaybackRate = aPlaybackRate;
mPlaybackRate = mLogicalPlaybackRate;
if (mAudioSink) {
mAudioSink->SetPlaybackRate(mPlaybackRate);
}

Просмотреть файл

@ -306,7 +306,6 @@ public:
return mReader->GetBuffered(aBuffered);
}
void SetPlaybackRate(double aPlaybackRate);
void SetPreservesPitch(bool aPreservesPitch);
size_t SizeOfVideoQueue() {
@ -445,6 +444,7 @@ protected:
already_AddRefed<VideoData> PopVideo();
void VolumeChanged();
void LogicalPlaybackRateChanged();
class WakeDecoderRunnable : public nsRunnable {
public:
@ -1010,9 +1010,13 @@ protected:
// Volume of playback. 0.0 = muted. 1.0 = full volume.
Mirror<double> mVolume;
// Playback rate. 1.0 : normal speed, 0.5 : two times slower. Synchronized via
// decoder monitor.
// Playback rate. 1.0 : normal speed, 0.5 : two times slower.
//
// The separation between mPlaybackRate and mLogicalPlaybackRate is a kludge
// to preserve existing fragile logic while converting this setup to state-
// mirroring. Some hero should clean this up.
double mPlaybackRate;
Mirror<double> mLogicalPlaybackRate;
// Pitch preservation for the playback rate. Synchronized via decoder monitor.
bool mPreservesPitch;

Просмотреть файл

@ -52,8 +52,8 @@ MediaOmxCommonDecoder::SetPlatformCanOffloadAudio(bool aCanOffloadAudio)
bool
MediaOmxCommonDecoder::CheckDecoderCanOffloadAudio()
{
return (mCanOffloadAudio && !mFallbackToStateMachine && !mOutputStreams.Length() &&
mInitialPlaybackRate == 1.0);
return (mCanOffloadAudio && !mFallbackToStateMachine &&
!mOutputStreams.Length() && mPlaybackRate == 1.0);
}
void