tor-browser

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

MediaTrack.h (2694B)


      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 #ifndef mozilla_dom_MediaTrack_h
      8 #define mozilla_dom_MediaTrack_h
      9 
     10 #include "mozilla/DOMEventTargetHelper.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 class MediaTrackList;
     15 class VideoTrack;
     16 class AudioTrack;
     17 
     18 /**
     19 * Base class of AudioTrack and VideoTrack. The AudioTrack and VideoTrack
     20 * objects represent specific tracks of a media resource. Each track has aspects
     21 * of an identifier, category, label, and language, even if a track is removed
     22 * from its corresponding track list, those aspects do not change.
     23 *
     24 * When fetching the media resource, an audio/video track is created if the
     25 * media resource is found to have an audio/video track. When the UA has learned
     26 * that an audio/video track has ended, this audio/video track will be removed
     27 * from its corresponding track list.
     28 *
     29 * Although AudioTrack and VideoTrack are not EventTargets, TextTrack is, and
     30 * TextTrack inherits from MediaTrack as well (or is going to).
     31 */
     32 class MediaTrack : public DOMEventTargetHelper {
     33 public:
     34  MediaTrack(nsIGlobalObject* aOwnerGlobal, const nsAString& aId,
     35             const nsAString& aKind, const nsAString& aLabel,
     36             const nsAString& aLanguage);
     37 
     38  NS_DECL_ISUPPORTS_INHERITED
     39  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(dom::MediaTrack,
     40                                           DOMEventTargetHelper)
     41 
     42  enum {
     43    DEFAULT = 0,
     44    FIRE_NO_EVENTS = 1 << 0,
     45  };
     46  // The default behavior of enabling an audio track or selecting a video track
     47  // fires a change event and notifies its media resource about the changes.
     48  // It should not fire any events when fetching media resource.
     49  virtual void SetEnabledInternal(bool aEnabled, int aFlags) = 0;
     50 
     51  virtual AudioTrack* AsAudioTrack() { return nullptr; }
     52 
     53  virtual VideoTrack* AsVideoTrack() { return nullptr; }
     54 
     55  const nsString& GetId() const { return mId; }
     56 
     57  // WebIDL
     58  void GetId(nsAString& aId) const { aId = mId; }
     59  void GetKind(nsAString& aKind) const { aKind = mKind; }
     60  void GetLabel(nsAString& aLabel) const { aLabel = mLabel; }
     61  void GetLanguage(nsAString& aLanguage) const { aLanguage = mLanguage; }
     62 
     63  friend class MediaTrackList;
     64 
     65 protected:
     66  virtual ~MediaTrack();
     67 
     68  void SetTrackList(MediaTrackList* aList);
     69 
     70  RefPtr<MediaTrackList> mList;
     71  nsString mId;
     72  nsString mKind;
     73  nsString mLabel;
     74  nsString mLanguage;
     75 };
     76 
     77 }  // namespace mozilla::dom
     78 
     79 #endif  // mozilla_dom_MediaTrack_h