Bug 1309162 - part2 : remove audio channel code from media element. r=jwwang
Remove the audio channel related codes. MozReview-Commit-ID: Fc09gDDF21a
This commit is contained in:
@@ -2519,10 +2519,6 @@ HTMLMediaElement::Seek(double aTime,
|
||||
// MediaDecoderReaders.
|
||||
|
||||
mPlayingBeforeSeek = IsPotentiallyPlaying();
|
||||
// Set the Variable if the Seekstarted while active playing
|
||||
if (mPlayingThroughTheAudioChannel) {
|
||||
mPlayingThroughTheAudioChannelBeforeSeek = true;
|
||||
}
|
||||
|
||||
// The media backend is responsible for dispatching the timeupdate
|
||||
// event if it changes the playback position as a result of the seek.
|
||||
@@ -3458,14 +3454,11 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
|
||||
mAutoplayEnabled(true),
|
||||
mPaused(true),
|
||||
mMuted(0),
|
||||
mAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED),
|
||||
mStatsShowing(false),
|
||||
mAllowCasting(false),
|
||||
mIsCasting(false),
|
||||
mAudioCaptured(false),
|
||||
mAudioCapturedByWindow(false),
|
||||
mPlayingBeforeSeek(false),
|
||||
mPlayingThroughTheAudioChannelBeforeSeek(false),
|
||||
mPausedForInactiveDocumentOrChannel(false),
|
||||
mEventDeliveryPaused(false),
|
||||
mIsRunningLoadMethod(false),
|
||||
@@ -3487,14 +3480,11 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
|
||||
mWaitingForKey(NOT_WAITING_FOR_KEY),
|
||||
mDownloadSuspendedByCache(false, "HTMLMediaElement::mDownloadSuspendedByCache"),
|
||||
mAudioChannel(AudioChannelService::GetDefaultAudioChannel()),
|
||||
mAudioChannelVolume(1.0),
|
||||
mPlayingThroughTheAudioChannel(false),
|
||||
mDisableVideo(false),
|
||||
mHasUserInteraction(false),
|
||||
mFirstFrameLoaded(false),
|
||||
mDefaultPlaybackStartPosition(0.0),
|
||||
mIsAudioTrackAudible(false),
|
||||
mAudible(IsAudible()),
|
||||
mVisibilityState(Visibility::APPROXIMATELY_NONVISIBLE),
|
||||
mErrorSink(new ErrorSink(this)),
|
||||
mAudioChannelWrapper(new AudioChannelAgentCallback(this, mAudioChannel))
|
||||
@@ -3516,7 +3506,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
|
||||
mWatchManager.Watch(mReadyState, &HTMLMediaElement::UpdateReadyStateInternal);
|
||||
|
||||
mShutdownObserver->Subscribe(this);
|
||||
MaybeCreateAudioChannelAgent();
|
||||
}
|
||||
|
||||
HTMLMediaElement::~HTMLMediaElement()
|
||||
@@ -3557,7 +3546,6 @@ HTMLMediaElement::~HTMLMediaElement()
|
||||
}
|
||||
|
||||
WakeLockRelease();
|
||||
mAudioChannelAgent = nullptr;
|
||||
}
|
||||
|
||||
void HTMLMediaElement::StopSuspendingAfterFirstFrame()
|
||||
@@ -5093,8 +5081,6 @@ void HTMLMediaElement::SeekCompleted()
|
||||
if (mCurrentPlayRangeStart == -1.0) {
|
||||
mCurrentPlayRangeStart = CurrentTime();
|
||||
}
|
||||
// Unset the variable on seekend
|
||||
mPlayingThroughTheAudioChannelBeforeSeek = false;
|
||||
}
|
||||
|
||||
void HTMLMediaElement::NotifySuspendedByCache(bool aIsSuspended)
|
||||
@@ -6337,74 +6323,6 @@ ImageContainer* HTMLMediaElement::GetImageContainer()
|
||||
return container ? container->GetImageContainer() : nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::MaybeCreateAudioChannelAgent()
|
||||
{
|
||||
if (mAudioChannelAgent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mAudioChannelAgent = new AudioChannelAgent();
|
||||
nsresult rv = mAudioChannelAgent->InitWithWeakCallback(OwnerDoc()->GetInnerWindow(),
|
||||
static_cast<int32_t>(mAudioChannel),
|
||||
this);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
mAudioChannelAgent = nullptr;
|
||||
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
||||
("HTMLMediaElement, Fail to initialize the audio channel agent,"
|
||||
" this = %p\n", this));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::IsPlayingThroughTheAudioChannel() const
|
||||
{
|
||||
// If we have an error, we are not playing.
|
||||
if (mErrorSink->mError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// It might be resumed from remote, we should keep the audio channel agent.
|
||||
if (IsSuspendedByAudioChannel()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Are we paused
|
||||
if (mPaused) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We should consider any bfcached page or inactive document as non-playing.
|
||||
if (!IsActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A loop always is playing
|
||||
if (HasAttr(kNameSpaceID_None, nsGkAtoms::loop)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we are actually playing...
|
||||
if (IsCurrentlyPlaying()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we are seeking, we consider it as playing
|
||||
if (mPlayingThroughTheAudioChannelBeforeSeek) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we are playing an external stream.
|
||||
if (mSrcAttrStream) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::UpdateAudioChannelPlayingState(bool aForcePlaying)
|
||||
{
|
||||
@@ -6413,177 +6331,6 @@ HTMLMediaElement::UpdateAudioChannelPlayingState(bool aForcePlaying)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::NotifyAudioChannelAgent(bool aPlaying)
|
||||
{
|
||||
if (aPlaying) {
|
||||
// The reason we don't call NotifyStartedPlaying after the media element
|
||||
// really becomes audible is because there is another case needs to block
|
||||
// element as early as we can, we would hear sound leaking if we block it
|
||||
// too late. In that case (block autoplay in non-visited-tab), we need to
|
||||
// create a connection before decoding, because we don't want user hearing
|
||||
// any sound.
|
||||
AudioPlaybackConfig config;
|
||||
nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config,
|
||||
IsAudible());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
||||
WindowVolumeChanged(config.mVolume, config.mMuted);
|
||||
WindowSuspendChanged(config.mSuspend);
|
||||
} else {
|
||||
mAudioChannelAgent->NotifyStoppedPlaying();
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLMediaElement::WindowVolumeChanged(float aVolume, bool aMuted)
|
||||
{
|
||||
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
||||
("HTMLMediaElement, WindowVolumeChanged, this = %p, "
|
||||
"aVolume = %f, aMuted = %d\n", this, aVolume, aMuted));
|
||||
|
||||
if (mAudioChannelVolume != aVolume) {
|
||||
mAudioChannelVolume = aVolume;
|
||||
SetVolumeInternal();
|
||||
}
|
||||
|
||||
if (aMuted && !ComputedMuted()) {
|
||||
SetMutedInternal(mMuted | MUTED_BY_AUDIO_CHANNEL);
|
||||
} else if (!aMuted && ComputedMuted()) {
|
||||
SetMutedInternal(mMuted & ~MUTED_BY_AUDIO_CHANNEL);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLMediaElement::WindowSuspendChanged(SuspendTypes aSuspend)
|
||||
{
|
||||
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
||||
("HTMLMediaElement, WindowSuspendChanged, this = %p, "
|
||||
"aSuspend = %d\n", this, aSuspend));
|
||||
|
||||
switch (aSuspend) {
|
||||
case nsISuspendedTypes::NONE_SUSPENDED:
|
||||
ResumeFromAudioChannel();
|
||||
break;
|
||||
case nsISuspendedTypes::SUSPENDED_PAUSE:
|
||||
case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
|
||||
PauseByAudioChannel(aSuspend);
|
||||
break;
|
||||
case nsISuspendedTypes::SUSPENDED_BLOCK:
|
||||
BlockByAudioChannel();
|
||||
break;
|
||||
case nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE:
|
||||
SetAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED);
|
||||
Pause();
|
||||
break;
|
||||
default:
|
||||
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
||||
("HTMLMediaElement, WindowSuspendChanged, this = %p, "
|
||||
"Error : unknown suspended type!\n", this));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::ResumeFromAudioChannel()
|
||||
{
|
||||
if (!IsSuspendedByAudioChannel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mAudioChannelSuspended) {
|
||||
case nsISuspendedTypes::SUSPENDED_PAUSE:
|
||||
case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
|
||||
ResumeFromAudioChannelPaused(mAudioChannelSuspended);
|
||||
break;
|
||||
case nsISuspendedTypes::SUSPENDED_BLOCK:
|
||||
ResumeFromAudioChannelBlocked();
|
||||
break;
|
||||
default:
|
||||
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
||||
("HTMLMediaElement, ResumeFromAudioChannel, this = %p, "
|
||||
"Error : resume without suspended!\n", this));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::ResumeFromAudioChannelPaused(SuspendTypes aSuspend)
|
||||
{
|
||||
MOZ_ASSERT(mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
|
||||
mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE);
|
||||
|
||||
SetAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED);
|
||||
nsresult rv = Play();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptend"));
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::ResumeFromAudioChannelBlocked()
|
||||
{
|
||||
MOZ_ASSERT(mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_BLOCK);
|
||||
|
||||
SetAudioChannelSuspended(nsISuspendedTypes::NONE_SUSPENDED);
|
||||
nsresult rv = Play();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::PauseByAudioChannel(SuspendTypes aSuspend)
|
||||
{
|
||||
if (IsSuspendedByAudioChannel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetAudioChannelSuspended(aSuspend);
|
||||
Pause();
|
||||
DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptbegin"));
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::BlockByAudioChannel()
|
||||
{
|
||||
if (IsSuspendedByAudioChannel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetAudioChannelSuspended(nsISuspendedTypes::SUSPENDED_BLOCK);
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::SetAudioChannelSuspended(SuspendTypes aSuspend)
|
||||
{
|
||||
if (mAudioChannelSuspended == aSuspend) {
|
||||
return;
|
||||
}
|
||||
|
||||
MaybeNotifyMediaResumed(aSuspend);
|
||||
mAudioChannelSuspended = aSuspend;
|
||||
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
|
||||
("HTMLMediaElement, SetAudioChannelSuspended, this = %p, "
|
||||
"aSuspend = %d\n", this, aSuspend));
|
||||
|
||||
NotifyAudioPlaybackChanged(
|
||||
AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::IsSuspendedByAudioChannel() const
|
||||
{
|
||||
return (mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
|
||||
mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE ||
|
||||
mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_BLOCK);
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::IsAllowedToPlay()
|
||||
{
|
||||
@@ -6611,36 +6358,6 @@ HTMLMediaElement::IsAllowedToPlay()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::IsAllowedToPlayByAudioChannel()
|
||||
{
|
||||
// The media element has already been paused or blocked, so it can't start
|
||||
// playback again by script or user's intend until resuming by audio channel.
|
||||
if (mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
|
||||
mAudioChannelSuspended == nsISuspendedTypes::SUSPENDED_BLOCK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the tab hasn't been activated yet, the media element in that tab can't
|
||||
// be playback now until the tab goes to foreground first time or user clicks
|
||||
// the unblocking tab icon.
|
||||
if (MaybeCreateAudioChannelAgent() && !IsTabActivated()) {
|
||||
// Even we haven't start playing yet, we still need to notify the audio
|
||||
// channe system because we need to receive the resume notification later.
|
||||
UpdateAudioChannelPlayingState(true /* force to start */);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::IsTabActivated() const
|
||||
{
|
||||
MOZ_ASSERT(mAudioChannelAgent);
|
||||
return !mAudioChannelAgent->ShouldBlockMedia();
|
||||
}
|
||||
|
||||
static const char* VisibilityString(Visibility aVisibility) {
|
||||
switch(aVisibility) {
|
||||
case Visibility::UNTRACKED: {
|
||||
@@ -6922,17 +6639,6 @@ HTMLMediaElement::CannotDecryptWaitingForKey()
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged(bool aCapture)
|
||||
{
|
||||
MOZ_ASSERT(mAudioChannelAgent);
|
||||
|
||||
if (mAudioCapturedByWindow != aCapture) {
|
||||
mAudioCapturedByWindow = aCapture;
|
||||
AudioCaptureStreamChangeIfNeeded();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
AudioTrackList*
|
||||
HTMLMediaElement::AudioTracks()
|
||||
{
|
||||
@@ -7056,59 +6762,6 @@ HTMLMediaElement::NotifyAudioPlaybackChanged(AudibleChangedReasons aReason)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::IsAudible() const
|
||||
{
|
||||
// Muted or the volume should not be ~0
|
||||
if (Muted() || (std::fabs(Volume()) <= 1e-7)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// No sound can be heard during suspending.
|
||||
if (IsSuspendedByAudioChannel()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Silent audio track.
|
||||
if (!mIsAudioTrackAudible) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::MaybeNotifyMediaResumed(SuspendTypes aSuspend)
|
||||
{
|
||||
// In fennec, we should send the notification when media is resumed from the
|
||||
// pause-disposable which was called by media control.
|
||||
if (mAudioChannelSuspended != nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE &&
|
||||
aSuspend != nsISuspendedTypes::NONE_SUSPENDED) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mAudioChannelAgent);
|
||||
uint64_t windowID = mAudioChannelAgent->WindowID();
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction([windowID]() -> void {
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
services::GetObserverService();
|
||||
if (NS_WARN_IF(!observerService)) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupportsPRUint64> wrapper =
|
||||
do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID);
|
||||
if (NS_WARN_IF(!wrapper)) {
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper->SetData(windowID);
|
||||
observerService->NotifyObservers(wrapper,
|
||||
"media-playback-resumed",
|
||||
u"active");
|
||||
}));
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLMediaElement::ShouldElementBePaused()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user