/src/mozilla-central/dom/media/VideoTrackList.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "mozilla/dom/VideoTrack.h" |
7 | | #include "mozilla/dom/VideoTrackList.h" |
8 | | #include "mozilla/dom/VideoTrackListBinding.h" |
9 | | |
10 | | namespace mozilla { |
11 | | namespace dom { |
12 | | |
13 | | JSObject* |
14 | | VideoTrackList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
15 | 0 | { |
16 | 0 | return VideoTrackList_Binding::Wrap(aCx, this, aGivenProto); |
17 | 0 | } |
18 | | |
19 | | VideoTrack* |
20 | | VideoTrackList::operator[](uint32_t aIndex) |
21 | 0 | { |
22 | 0 | MediaTrack* track = MediaTrackList::operator[](aIndex); |
23 | 0 | return track->AsVideoTrack(); |
24 | 0 | } |
25 | | |
26 | | void |
27 | | VideoTrackList::RemoveTrack(const RefPtr<MediaTrack>& aTrack) |
28 | 0 | { |
29 | 0 | // we need to find the video track before |MediaTrackList::RemoveTrack|. Or |
30 | 0 | // mSelectedIndex will not be valid. The check of mSelectedIndex == -1 |
31 | 0 | // need to be done after RemoveTrack. Also the call of |
32 | 0 | // |MediaTrackList::RemoveTrack| is necessary even when mSelectedIndex = -1. |
33 | 0 | bool found; |
34 | 0 | VideoTrack* selectedVideoTrack = IndexedGetter(mSelectedIndex, found); |
35 | 0 | MediaTrackList::RemoveTrack(aTrack); |
36 | 0 | if (mSelectedIndex == -1) { |
37 | 0 | // There was no selected track and we don't select another track on removal. |
38 | 0 | return; |
39 | 0 | } |
40 | 0 | MOZ_ASSERT(found, "When mSelectedIndex is set it should point to a track"); |
41 | 0 | MOZ_ASSERT(selectedVideoTrack, "The mSelectedIndex should be set to video track only"); |
42 | 0 |
|
43 | 0 | // Let the caller of RemoveTrack deal with choosing the new selected track if |
44 | 0 | // it removes the currently-selected track. |
45 | 0 | if (aTrack == selectedVideoTrack) { |
46 | 0 | mSelectedIndex = -1; |
47 | 0 | return; |
48 | 0 | } |
49 | 0 | |
50 | 0 | // The removed track was not the selected track and there is a |
51 | 0 | // currently-selected video track. We need to find the new location of the |
52 | 0 | // selected track. |
53 | 0 | for (size_t ix = 0; ix < mTracks.Length(); ix++) { |
54 | 0 | if (mTracks[ix] == selectedVideoTrack) { |
55 | 0 | mSelectedIndex = ix; |
56 | 0 | return; |
57 | 0 | } |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | void |
62 | | VideoTrackList::EmptyTracks() |
63 | 0 | { |
64 | 0 | mSelectedIndex = -1; |
65 | 0 | MediaTrackList::EmptyTracks(); |
66 | 0 | } |
67 | | |
68 | | VideoTrack* VideoTrackList::GetSelectedTrack() |
69 | 0 | { |
70 | 0 | if (mSelectedIndex < 0 || static_cast<size_t>(mSelectedIndex) >= mTracks.Length()) { |
71 | 0 | return nullptr; |
72 | 0 | } |
73 | 0 | |
74 | 0 | return operator[](mSelectedIndex); |
75 | 0 | } |
76 | | |
77 | | VideoTrack* |
78 | | VideoTrackList::IndexedGetter(uint32_t aIndex, bool& aFound) |
79 | 0 | { |
80 | 0 | MediaTrack* track = MediaTrackList::IndexedGetter(aIndex, aFound); |
81 | 0 | return track ? track->AsVideoTrack() : nullptr; |
82 | 0 | } |
83 | | |
84 | | VideoTrack* |
85 | | VideoTrackList::GetTrackById(const nsAString& aId) |
86 | 0 | { |
87 | 0 | MediaTrack* track = MediaTrackList::GetTrackById(aId); |
88 | 0 | return track ? track->AsVideoTrack() : nullptr; |
89 | 0 | } |
90 | | |
91 | | } // namespace dom |
92 | | } // namespace mozilla |