1/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2011-2017 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
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#if ENABLE(VIDEO_TRACK)
30
31#include "TrackBase.h"
32#include "VideoTrackPrivate.h"
33
34namespace WebCore {
35
36class MediaDescription;
37class VideoTrack;
38
39class VideoTrackClient {
40public:
41 virtual ~VideoTrackClient() = default;
42 virtual void videoTrackSelectedChanged(VideoTrack&) = 0;
43};
44
45class VideoTrack final : public MediaTrackBase, private VideoTrackPrivateClient {
46public:
47 static Ref<VideoTrack> create(VideoTrackClient& client, VideoTrackPrivate& trackPrivate)
48 {
49 return adoptRef(*new VideoTrack(client, trackPrivate));
50 }
51 virtual ~VideoTrack();
52
53 static const AtomicString& alternativeKeyword();
54 static const AtomicString& captionsKeyword();
55 static const AtomicString& mainKeyword();
56 static const AtomicString& signKeyword();
57 static const AtomicString& subtitlesKeyword();
58 static const AtomicString& commentaryKeyword();
59
60 bool selected() const { return m_selected; }
61 virtual void setSelected(const bool);
62
63 void clearClient() final { m_client = nullptr; }
64 VideoTrackClient* client() const { return m_client; }
65
66 size_t inbandTrackIndex();
67
68#if ENABLE(MEDIA_SOURCE)
69 void setKind(const AtomicString&) final;
70 void setLanguage(const AtomicString&) final;
71#endif
72
73 const MediaDescription& description() const;
74
75 void setPrivate(VideoTrackPrivate&);
76 void setMediaElement(HTMLMediaElement*) override;
77
78private:
79 VideoTrack(VideoTrackClient&, VideoTrackPrivate&);
80
81 bool isValidKind(const AtomicString&) const final;
82
83 // VideoTrackPrivateClient
84 void selectedChanged(bool) final;
85
86 // TrackPrivateBaseClient
87 void idChanged(const AtomicString&) final;
88 void labelChanged(const AtomicString&) final;
89 void languageChanged(const AtomicString&) final;
90 void willRemove() final;
91
92 bool enabled() const final { return selected(); }
93
94 void updateKindFromPrivate();
95
96#if !RELEASE_LOG_DISABLED
97 const char* logClassName() const final { return "VideoTrack"; }
98#endif
99
100 VideoTrackClient* m_client { nullptr };
101 Ref<VideoTrackPrivate> m_private;
102 bool m_selected { false };
103};
104
105} // namespace WebCore
106
107SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::VideoTrack)
108 static bool isType(const WebCore::TrackBase& track) { return track.type() == WebCore::TrackBase::VideoTrack; }
109SPECIALIZE_TYPE_TRAITS_END()
110
111#endif
112