Add interfaces and stubs for audio and video tracks
[WebKit-https.git] / Source / WebCore / html / track / AudioTrack.cpp
1 /*
2  * Copyright (C) 2011 Google Inc.  All rights reserved.
3  * Copyright (C) 2011, 2012, 2013 Apple Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *     * Neither the name of Google Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #include "config.h"
33
34 #if ENABLE(VIDEO_TRACK)
35
36 #include "AudioTrack.h"
37
38 #include "AudioTrackList.h"
39 #include "Event.h"
40 #include "ExceptionCode.h"
41 #include "HTMLMediaElement.h"
42 #include "TrackBase.h"
43
44 namespace WebCore {
45
46 const AtomicString& AudioTrack::alternativeKeyword()
47 {
48     DEFINE_STATIC_LOCAL(const AtomicString, alternative, ("alternative", AtomicString::ConstructFromLiteral));
49     return alternative;
50 }
51
52 const AtomicString& AudioTrack::descriptionKeyword()
53 {
54     DEFINE_STATIC_LOCAL(const AtomicString, description, ("description", AtomicString::ConstructFromLiteral));
55     return description;
56 }
57
58 const AtomicString& AudioTrack::mainKeyword()
59 {
60     DEFINE_STATIC_LOCAL(const AtomicString, main, ("main", AtomicString::ConstructFromLiteral));
61     return main;
62 }
63
64 const AtomicString& AudioTrack::mainDescKeyword()
65 {
66     DEFINE_STATIC_LOCAL(const AtomicString, mainDesc, ("main-desc", AtomicString::ConstructFromLiteral));
67     return mainDesc;
68 }
69
70 const AtomicString& AudioTrack::translationKeyword()
71 {
72     DEFINE_STATIC_LOCAL(const AtomicString, translation, ("translation", AtomicString::ConstructFromLiteral));
73     return translation;
74 }
75
76 const AtomicString& AudioTrack::commentaryKeyword()
77 {
78     DEFINE_STATIC_LOCAL(const AtomicString, commentary, ("commentary", AtomicString::ConstructFromLiteral));
79     return commentary;
80 }
81
82 AudioTrack::AudioTrack(AudioTrackClient* client, PassRefPtr<AudioTrackPrivate> trackPrivate)
83     : TrackBase(TrackBase::AudioTrack, trackPrivate->label(), trackPrivate->language())
84     , m_id(trackPrivate->id())
85     , m_enabled(trackPrivate->enabled())
86     , m_client(client)
87     , m_private(trackPrivate)
88 {
89     m_private->setClient(this);
90
91     switch (m_private->kind()) {
92     case AudioTrackPrivate::Alternative:
93         setKind(AudioTrack::alternativeKeyword());
94         break;
95     case AudioTrackPrivate::Description:
96         setKind(AudioTrack::descriptionKeyword());
97         break;
98     case AudioTrackPrivate::Main:
99         setKind(AudioTrack::mainKeyword());
100         break;
101     case AudioTrackPrivate::MainDesc:
102         setKind(AudioTrack::mainDescKeyword());
103         break;
104     case AudioTrackPrivate::Translation:
105         setKind(AudioTrack::translationKeyword());
106         break;
107     case AudioTrackPrivate::Commentary:
108         setKind(AudioTrack::commentaryKeyword());
109         break;
110     case AudioTrackPrivate::None:
111         setKind(emptyString());
112         break;
113     default:
114         ASSERT_NOT_REACHED();
115         break;
116     }
117 }
118
119 AudioTrack::~AudioTrack()
120 {
121     m_private->setClient(0);
122 }
123
124 bool AudioTrack::isValidKind(const AtomicString& value) const
125 {
126     if (value == alternativeKeyword())
127         return true;
128     if (value == descriptionKeyword())
129         return true;
130     if (value == mainKeyword())
131         return true;
132     if (value == mainDescKeyword())
133         return true;
134     if (value == translationKeyword())
135         return true;
136     if (value == commentaryKeyword())
137         return true;
138
139     return false;
140 }
141
142 void AudioTrack::setEnabled(const bool enabled)
143 {
144     if (m_enabled == enabled)
145         return;
146
147     m_enabled = enabled;
148
149     if (m_client)
150         m_client->audioTrackEnabledChanged(this);
151 }
152
153 size_t AudioTrack::inbandTrackIndex()
154 {
155     ASSERT(m_private);
156     return m_private->audioTrackIndex();
157 }
158
159 void AudioTrack::willRemoveAudioTrackPrivate(AudioTrackPrivate* trackPrivate)
160 {
161     UNUSED_PARAM(trackPrivate);
162     ASSERT(trackPrivate == m_private);
163     mediaElement()->removeAudioTrack(this);
164 }
165
166 } // namespace WebCore
167
168 #endif