summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/html/track/audio_track.cc
blob: 53484fa1333c63619e29d3dbba9dbb9f2e19fa1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/html/track/audio_track.h"

#include "third_party/blink/renderer/core/html/media/html_media_element.h"

namespace blink {

AudioTrack::AudioTrack(const String& id,
                       const AtomicString& kind,
                       const AtomicString& label,
                       const AtomicString& language,
                       bool enabled)
    : TrackBase(WebMediaPlayer::kAudioTrack,
                IsValidKindKeyword(kind) ? kind : g_empty_atom,
                label,
                language,
                id),
      enabled_(enabled) {}

AudioTrack::~AudioTrack() = default;

void AudioTrack::Trace(Visitor* visitor) {
  ScriptWrappable::Trace(visitor);
  TrackBase::Trace(visitor);
}

void AudioTrack::setEnabled(bool enabled) {
  if (enabled == enabled_)
    return;

  enabled_ = enabled;

  if (MediaElement())
    MediaElement()->AudioTrackChanged(this);
}

const AtomicString& AudioTrack::AlternativeKeyword() {
  DEFINE_STATIC_LOCAL(const AtomicString, keyword, ("alternative"));
  return keyword;
}

const AtomicString& AudioTrack::DescriptionsKeyword() {
  DEFINE_STATIC_LOCAL(const AtomicString, keyword, ("descriptions"));
  return keyword;
}

const AtomicString& AudioTrack::MainKeyword() {
  DEFINE_STATIC_LOCAL(const AtomicString, keyword, ("main"));
  return keyword;
}

const AtomicString& AudioTrack::MainDescriptionsKeyword() {
  DEFINE_STATIC_LOCAL(const AtomicString, keyword, ("main-desc"));
  return keyword;
}

const AtomicString& AudioTrack::TranslationKeyword() {
  DEFINE_STATIC_LOCAL(const AtomicString, keyword, ("translation"));
  return keyword;
}

const AtomicString& AudioTrack::CommentaryKeyword() {
  DEFINE_STATIC_LOCAL(const AtomicString, keyword, ("commentary"));
  return keyword;
}

bool AudioTrack::IsValidKindKeyword(const String& kind) {
  return kind == AlternativeKeyword() || kind == DescriptionsKeyword() ||
         kind == MainKeyword() || kind == MainDescriptionsKeyword() ||
         kind == TranslationKeyword() || kind == CommentaryKeyword() ||
         kind == g_empty_atom;
}

}  // namespace blink