Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/MediaTrackList.h
Line
Count
Source (jump to first uncovered line)
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_MediaTrackList_h
8
#define mozilla_dom_MediaTrackList_h
9
10
#include "mozilla/DOMEventTargetHelper.h"
11
12
namespace mozilla {
13
class DOMMediaStream;
14
15
namespace dom {
16
17
class HTMLMediaElement;
18
class MediaTrack;
19
class AudioTrackList;
20
class VideoTrackList;
21
class AudioTrack;
22
class VideoTrack;
23
class VideoStreamTrack;
24
25
/**
26
 * Base class of AudioTrackList and VideoTrackList. The AudioTrackList and
27
 * VideoTrackList objects represent a dynamic list of zero or more audio and
28
 * video tracks respectively.
29
 *
30
 * When a media element is to forget its media-resource-specific tracks, its
31
 * audio track list and video track list will be emptied.
32
 */
33
class MediaTrackList : public DOMEventTargetHelper
34
{
35
public:
36
  MediaTrackList(nsPIDOMWindowInner* aOwnerWindow, HTMLMediaElement* aMediaElement);
37
38
  NS_DECL_ISUPPORTS_INHERITED
39
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaTrackList, DOMEventTargetHelper)
40
41
  using DOMEventTargetHelper::DispatchTrustedEvent;
42
43
  // The return value is non-null, assert an error if aIndex is out of bound
44
  // for array mTracks.
45
  MediaTrack* operator[](uint32_t aIndex);
46
47
  // The track must be from the same Window as this MediaTrackList.
48
  void AddTrack(MediaTrack* aTrack);
49
50
  // In remove track case, the VideoTrackList::mSelectedIndex should be updated
51
  // due to mTracks changed. No need to take care this in add track case.
52
  virtual void RemoveTrack(const RefPtr<MediaTrack>& aTrack);
53
54
  void RemoveTracks();
55
56
  static already_AddRefed<AudioTrack>
57
  CreateAudioTrack(nsIGlobalObject* aOwnerGlobal,
58
                   const nsAString& aId,
59
                   const nsAString& aKind,
60
                   const nsAString& aLabel,
61
                   const nsAString& aLanguage,
62
                   bool aEnabled);
63
64
  // For the case of src of HTMLMediaElement is non-MediaStream, leave the
65
  // aVideoTrack as default(nullptr).
66
  static already_AddRefed<VideoTrack>
67
  CreateVideoTrack(nsIGlobalObject* aOwnerGlobal,
68
                   const nsAString& aId,
69
                   const nsAString& aKind,
70
                   const nsAString& aLabel,
71
                   const nsAString& aLanguage,
72
                   VideoStreamTrack* aVideoTrack = nullptr);
73
74
  virtual void EmptyTracks();
75
76
  void CreateAndDispatchChangeEvent();
77
78
  // WebIDL
79
  MediaTrack* IndexedGetter(uint32_t aIndex, bool& aFound);
80
81
  MediaTrack* GetTrackById(const nsAString& aId);
82
83
  bool IsEmpty() const
84
  {
85
    return mTracks.IsEmpty();
86
  }
87
88
  uint32_t Length() const
89
0
  {
90
0
    return mTracks.Length();
91
0
  }
92
93
  IMPL_EVENT_HANDLER(change)
94
  IMPL_EVENT_HANDLER(addtrack)
95
  IMPL_EVENT_HANDLER(removetrack)
96
97
  friend class AudioTrack;
98
  friend class VideoTrack;
99
100
protected:
101
  virtual ~MediaTrackList();
102
103
  void CreateAndDispatchTrackEventRunner(MediaTrack* aTrack,
104
                                         const nsAString& aEventName);
105
106
  virtual AudioTrackList* AsAudioTrackList() { return nullptr; }
107
108
  virtual VideoTrackList* AsVideoTrackList() { return nullptr; }
109
110
  HTMLMediaElement* GetMediaElement() { return mMediaElement; }
111
112
  nsTArray<RefPtr<MediaTrack>> mTracks;
113
  RefPtr<HTMLMediaElement> mMediaElement;
114
};
115
116
} // namespace dom
117
} // namespace mozilla
118
119
#endif // mozilla_dom_MediaTrackList_h