Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / media / AudioTrack.cpp
blobe6ee43a0f891d33b29959c53c6266faf7427f9df
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 et tw=78: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/AudioStreamTrack.h"
8 #include "mozilla/dom/AudioTrack.h"
9 #include "mozilla/dom/AudioTrackBinding.h"
10 #include "mozilla/dom/AudioTrackList.h"
11 #include "mozilla/dom/HTMLMediaElement.h"
13 namespace mozilla::dom {
15 AudioTrack::AudioTrack(nsIGlobalObject* aOwnerGlobal, const nsAString& aId,
16 const nsAString& aKind, const nsAString& aLabel,
17 const nsAString& aLanguage, bool aEnabled,
18 AudioStreamTrack* aStreamTrack)
19 : MediaTrack(aOwnerGlobal, aId, aKind, aLabel, aLanguage),
20 mEnabled(aEnabled),
21 mAudioStreamTrack(aStreamTrack) {}
23 AudioTrack::~AudioTrack() = default;
25 NS_IMPL_CYCLE_COLLECTION_INHERITED(AudioTrack, MediaTrack, mAudioStreamTrack)
27 NS_IMPL_ADDREF_INHERITED(AudioTrack, MediaTrack)
28 NS_IMPL_RELEASE_INHERITED(AudioTrack, MediaTrack)
29 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioTrack)
30 NS_INTERFACE_MAP_END_INHERITING(MediaTrack)
32 JSObject* AudioTrack::WrapObject(JSContext* aCx,
33 JS::Handle<JSObject*> aGivenProto) {
34 return AudioTrack_Binding::Wrap(aCx, this, aGivenProto);
37 void AudioTrack::SetEnabled(bool aEnabled) {
38 SetEnabledInternal(aEnabled, MediaTrack::DEFAULT);
41 void AudioTrack::SetEnabledInternal(bool aEnabled, int aFlags) {
42 if (aEnabled == mEnabled) {
43 return;
45 mEnabled = aEnabled;
47 // If this AudioTrack is no longer in its original AudioTrackList, then
48 // whether it is enabled or not has no effect on its original list.
49 if (!mList) {
50 return;
53 if (mEnabled) {
54 HTMLMediaElement* element = mList->GetMediaElement();
55 if (element) {
56 element->NotifyMediaTrackEnabled(this);
58 } else {
59 HTMLMediaElement* element = mList->GetMediaElement();
60 if (element) {
61 element->NotifyMediaTrackDisabled(this);
65 if (!(aFlags & MediaTrack::FIRE_NO_EVENTS)) {
66 mList->CreateAndDispatchChangeEvent();
70 } // namespace mozilla::dom