Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / media / MediaTrackList.h
blob5ad08b0f65f90f35a97913f386370111b8e1f8f3
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 #ifndef mozilla_dom_MediaTrackList_h
8 #define mozilla_dom_MediaTrackList_h
10 #include "mozilla/DOMEventTargetHelper.h"
12 namespace mozilla {
13 class DOMMediaStream;
15 namespace dom {
17 class AudioStreamTrack;
18 class AudioTrack;
19 class AudioTrackList;
20 class HTMLMediaElement;
21 class MediaTrack;
22 class VideoStreamTrack;
23 class VideoTrack;
24 class VideoTrackList;
26 /**
27 * Base class of AudioTrackList and VideoTrackList. The AudioTrackList and
28 * VideoTrackList objects represent a dynamic list of zero or more audio and
29 * video tracks respectively.
31 * When a media element is to forget its media-resource-specific tracks, its
32 * audio track list and video track list will be emptied.
34 class MediaTrackList : public DOMEventTargetHelper {
35 public:
36 MediaTrackList(nsIGlobalObject* aOwnerObject,
37 HTMLMediaElement* aMediaElement);
39 NS_DECL_ISUPPORTS_INHERITED
40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaTrackList, DOMEventTargetHelper)
42 using DOMEventTargetHelper::DispatchTrustedEvent;
44 // The return value is non-null, assert an error if aIndex is out of bound
45 // for array mTracks.
46 MediaTrack* operator[](uint32_t aIndex);
48 // The track must be from the same Window as this MediaTrackList.
49 void AddTrack(MediaTrack* aTrack);
51 // In remove track case, the VideoTrackList::mSelectedIndex should be updated
52 // due to mTracks changed. No need to take care this in add track case.
53 virtual void RemoveTrack(const RefPtr<MediaTrack>& aTrack);
55 void RemoveTracks();
57 // For the case of src of HTMLMediaElement is non-MediaStream, leave the
58 // aAudioTrack as default(nullptr).
59 static already_AddRefed<AudioTrack> CreateAudioTrack(
60 nsIGlobalObject* aOwnerGlobal, const nsAString& aId,
61 const nsAString& aKind, const nsAString& aLabel,
62 const nsAString& aLanguage, bool aEnabled,
63 AudioStreamTrack* aAudioTrack = nullptr);
65 // For the case of src of HTMLMediaElement is non-MediaStream, leave the
66 // aVideoTrack as default(nullptr).
67 static already_AddRefed<VideoTrack> CreateVideoTrack(
68 nsIGlobalObject* aOwnerGlobal, const nsAString& aId,
69 const nsAString& aKind, const nsAString& aLabel,
70 const nsAString& aLanguage, VideoStreamTrack* aVideoTrack = nullptr);
72 virtual void EmptyTracks();
74 void CreateAndDispatchChangeEvent();
76 // WebIDL
77 MediaTrack* IndexedGetter(uint32_t aIndex, bool& aFound);
79 MediaTrack* GetTrackById(const nsAString& aId);
81 bool IsEmpty() const { return mTracks.IsEmpty(); }
83 uint32_t Length() const { return mTracks.Length(); }
85 IMPL_EVENT_HANDLER(change)
86 IMPL_EVENT_HANDLER(addtrack)
87 IMPL_EVENT_HANDLER(removetrack)
89 friend class AudioTrack;
90 friend class VideoTrack;
92 protected:
93 virtual ~MediaTrackList();
95 void CreateAndDispatchTrackEventRunner(MediaTrack* aTrack,
96 const nsAString& aEventName);
98 virtual AudioTrackList* AsAudioTrackList() { return nullptr; }
100 virtual VideoTrackList* AsVideoTrackList() { return nullptr; }
102 HTMLMediaElement* GetMediaElement() { return mMediaElement; }
104 nsTArray<RefPtr<MediaTrack>> mTracks;
105 RefPtr<HTMLMediaElement> mMediaElement;
108 } // namespace dom
109 } // namespace mozilla
111 #endif // mozilla_dom_MediaTrackList_h