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
),
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
) {
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.
54 HTMLMediaElement
* element
= mList
->GetMediaElement();
56 element
->NotifyMediaTrackEnabled(this);
59 HTMLMediaElement
* element
= mList
->GetMediaElement();
61 element
->NotifyMediaTrackDisabled(this);
65 if (!(aFlags
& MediaTrack::FIRE_NO_EVENTS
)) {
66 mList
->CreateAndDispatchChangeEvent();
70 } // namespace mozilla::dom