Bug 1228564 - part 2 : check audio capturing when the agent is registered/unregistered. r=baku.

This commit is contained in:
Alastor Wu
2015-12-24 17:28:45 +08:00
parent eb69386b37
commit b238891922
12 changed files with 75 additions and 65 deletions

View File

@@ -114,31 +114,18 @@ using mozilla::net::nsMediaFragmentURIParser;
class MOZ_STACK_CLASS AutoNotifyAudioChannelAgent
{
RefPtr<mozilla::dom::HTMLMediaElement> mElement;
bool mShouldNotify;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER;
public:
AutoNotifyAudioChannelAgent(mozilla::dom::HTMLMediaElement* aElement,
bool aNotify
AutoNotifyAudioChannelAgent(mozilla::dom::HTMLMediaElement* aElement
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mElement(aElement)
, mShouldNotify(aNotify)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
if (mShouldNotify) {
// The audio channel agent may not exist now.
if (mElement->MaybeCreateAudioChannelAgent()) {
mElement->NotifyAudioChannelAgent(false);
}
}
}
~AutoNotifyAudioChannelAgent()
{
if (mShouldNotify) {
// The audio channel agent is destroyed at this point.
if (mElement->MaybeCreateAudioChannelAgent()) {
mElement->NotifyAudioChannelAgent(true);
}
}
mElement->UpdateAudioChannelPlayingState();
}
};
@@ -3399,10 +3386,7 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
// If the element is gaining or losing an audio track, we need to notify
// the audio channel agent so that the correct audio-playback events will
// get dispatched.
bool audioTrackChanging = mMediaInfo.HasAudio() != aInfo->HasAudio();
AutoNotifyAudioChannelAgent autoNotify(this,
audioTrackChanging &&
mPlayingThroughTheAudioChannel);
AutoNotifyAudioChannelAgent autoNotify(this);
mMediaInfo = *aInfo;
mIsEncrypted = aInfo->IsEncrypted()
@@ -4761,6 +4745,11 @@ HTMLMediaElement::IsPlayingThroughTheAudioChannel() const
return false;
}
// If this element doesn't have any audio tracks.
if (!HasAudio()) {
return false;
}
// The volume should not be ~0
if (std::fabs(Volume()) <= 1e-7) {
return false;
@@ -4816,15 +4805,6 @@ HTMLMediaElement::UpdateAudioChannelPlayingState()
void
HTMLMediaElement::NotifyAudioChannelAgent(bool aPlaying)
{
// Don't do anything if this element doesn't have any audio tracks.
if (!HasAudio()) {
return;
}
// Immediately check if this should go to the MSG instead of the normal
// media playback route.
WindowAudioCaptureChanged();
// This is needed to pass nsContentUtils::IsCallerChrome().
// AudioChannel API should not called from content but it can happen that
// this method has some content JS in its stack.
@@ -4995,17 +4975,17 @@ HTMLMediaElement::GetTopLevelPrincipal()
}
#endif // MOZ_EME
NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged()
NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged(bool aCapture)
{
MOZ_ASSERT(mAudioChannelAgent);
MOZ_ASSERT(HasAudio());
if (!OwnerDoc()->GetInnerWindow()) {
return NS_OK;
}
bool captured = OwnerDoc()->GetInnerWindow()->GetAudioCaptured();
if (captured != mAudioCapturedByWindow) {
if (captured) {
if (aCapture != mAudioCapturedByWindow) {
if (aCapture) {
mAudioCapturedByWindow = true;
nsCOMPtr<nsPIDOMWindow> window =
do_QueryInterface(OwnerDoc()->GetParentObject());
@@ -5041,7 +5021,7 @@ NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged()
}
}
return NS_OK;
return NS_OK;
}
AudioTrackList*