Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/VideoTrack.cpp
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
#include "mozilla/dom/HTMLMediaElement.h"
8
#include "mozilla/dom/VideoStreamTrack.h"
9
#include "mozilla/dom/VideoTrack.h"
10
#include "mozilla/dom/VideoTrackBinding.h"
11
#include "mozilla/dom/VideoTrackList.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
VideoTrack::VideoTrack(nsIGlobalObject* aOwnerGlobal,
17
                       const nsAString& aId,
18
                       const nsAString& aKind,
19
                       const nsAString& aLabel,
20
                       const nsAString& aLanguage,
21
                       VideoStreamTrack* aStreamTarck)
22
  : MediaTrack(aOwnerGlobal, aId, aKind, aLabel, aLanguage)
23
  , mSelected(false)
24
  , mVideoStreamTrack(aStreamTarck)
25
0
{
26
0
}
27
28
VideoTrack::~VideoTrack()
29
0
{
30
0
}
31
32
NS_IMPL_CYCLE_COLLECTION_INHERITED(VideoTrack, MediaTrack, mVideoStreamTrack)
33
34
NS_IMPL_ADDREF_INHERITED(VideoTrack, MediaTrack)
35
NS_IMPL_RELEASE_INHERITED(VideoTrack, MediaTrack)
36
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VideoTrack)
37
0
NS_INTERFACE_MAP_END_INHERITING(MediaTrack)
38
39
JSObject*
40
VideoTrack::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
41
0
{
42
0
  return VideoTrack_Binding::Wrap(aCx, this, aGivenProto);
43
0
}
44
45
void VideoTrack::SetSelected(bool aSelected)
46
0
{
47
0
  SetEnabledInternal(aSelected, MediaTrack::DEFAULT);
48
0
}
49
50
void
51
VideoTrack::SetEnabledInternal(bool aEnabled, int aFlags)
52
0
{
53
0
  if (aEnabled == mSelected) {
54
0
    return;
55
0
  }
56
0
57
0
  mSelected = aEnabled;
58
0
59
0
  // If this VideoTrack is no longer in its original VideoTrackList, then
60
0
  // whether it is selected or not has no effect on its original list.
61
0
  if (!mList) {
62
0
    return;
63
0
  }
64
0
65
0
  VideoTrackList& list = static_cast<VideoTrackList&>(*mList);
66
0
  if (mSelected) {
67
0
    uint32_t curIndex = 0;
68
0
69
0
    // Unselect all video tracks except the current one.
70
0
    for (uint32_t i = 0; i < list.Length(); ++i) {
71
0
      if (list[i] == this) {
72
0
        curIndex = i;
73
0
        continue;
74
0
      }
75
0
76
0
      VideoTrack* track = list[i];
77
0
      track->SetSelected(false);
78
0
    }
79
0
80
0
    // Set the index of selected video track to the current's index.
81
0
    list.mSelectedIndex = curIndex;
82
0
83
0
    HTMLMediaElement* element = mList->GetMediaElement();
84
0
    if (element) {
85
0
      element->NotifyMediaTrackEnabled(this);
86
0
    }
87
0
  } else {
88
0
    list.mSelectedIndex = -1;
89
0
90
0
    HTMLMediaElement* element = mList->GetMediaElement();
91
0
    if (element) {
92
0
      element->NotifyMediaTrackDisabled(this);
93
0
    }
94
0
  }
95
0
96
0
  // Fire the change event at selection changes on this video track, shall
97
0
  // propose a spec change later.
98
0
  if (!(aFlags & MediaTrack::FIRE_NO_EVENTS)) {
99
0
    list.CreateAndDispatchChangeEvent();
100
0
  }
101
0
}
102
103
} // namespace dom
104
} //namespace mozilla