tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AudioTrack.cpp (2278B)


      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/. */
      6 
      7 #include "mozilla/dom/AudioTrack.h"
      8 
      9 #include "mozilla/dom/AudioStreamTrack.h"
     10 #include "mozilla/dom/AudioTrackBinding.h"
     11 #include "mozilla/dom/AudioTrackList.h"
     12 #include "mozilla/dom/HTMLMediaElement.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 AudioTrack::AudioTrack(nsIGlobalObject* aOwnerGlobal, const nsAString& aId,
     17                       const nsAString& aKind, const nsAString& aLabel,
     18                       const nsAString& aLanguage, bool aEnabled,
     19                       AudioStreamTrack* aStreamTrack)
     20    : MediaTrack(aOwnerGlobal, aId, aKind, aLabel, aLanguage),
     21      mEnabled(aEnabled),
     22      mAudioStreamTrack(aStreamTrack) {}
     23 
     24 AudioTrack::~AudioTrack() = default;
     25 
     26 NS_IMPL_CYCLE_COLLECTION_INHERITED(AudioTrack, MediaTrack, mAudioStreamTrack)
     27 
     28 NS_IMPL_ADDREF_INHERITED(AudioTrack, MediaTrack)
     29 NS_IMPL_RELEASE_INHERITED(AudioTrack, MediaTrack)
     30 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioTrack)
     31 NS_INTERFACE_MAP_END_INHERITING(MediaTrack)
     32 
     33 JSObject* AudioTrack::WrapObject(JSContext* aCx,
     34                                 JS::Handle<JSObject*> aGivenProto) {
     35  return AudioTrack_Binding::Wrap(aCx, this, aGivenProto);
     36 }
     37 
     38 void AudioTrack::SetEnabled(bool aEnabled) {
     39  SetEnabledInternal(aEnabled, MediaTrack::DEFAULT);
     40 }
     41 
     42 void AudioTrack::SetEnabledInternal(bool aEnabled, int aFlags) {
     43  if (aEnabled == mEnabled) {
     44    return;
     45  }
     46  mEnabled = aEnabled;
     47 
     48  // If this AudioTrack is no longer in its original AudioTrackList, then
     49  // whether it is enabled or not has no effect on its original list.
     50  if (!mList) {
     51    return;
     52  }
     53 
     54  if (mEnabled) {
     55    HTMLMediaElement* element = mList->GetMediaElement();
     56    if (element) {
     57      element->NotifyMediaTrackEnabled(this);
     58    }
     59  } else {
     60    HTMLMediaElement* element = mList->GetMediaElement();
     61    if (element) {
     62      element->NotifyMediaTrackDisabled(this);
     63    }
     64  }
     65 
     66  if (!(aFlags & MediaTrack::FIRE_NO_EVENTS)) {
     67    mList->CreateAndDispatchChangeEvent();
     68  }
     69 }
     70 
     71 }  // namespace mozilla::dom