1/*
2 * Copyright (C) 2011-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#if ENABLE(VIDEO_TRACK)
29
30#include <wtf/LoggerHelper.h>
31#include <wtf/text/AtomString.h>
32
33namespace WebCore {
34
35class Element;
36class HTMLMediaElement;
37class SourceBuffer;
38
39class TrackBase
40 : public RefCounted<TrackBase>
41#if !RELEASE_LOG_DISABLED
42 , private LoggerHelper
43#endif
44{
45public:
46 virtual ~TrackBase() = default;
47
48 enum Type { BaseTrack, TextTrack, AudioTrack, VideoTrack };
49 Type type() const { return m_type; }
50
51 virtual void setMediaElement(HTMLMediaElement*);
52 HTMLMediaElement* mediaElement() { return m_mediaElement; }
53 virtual Element* element();
54
55 virtual AtomString id() const { return m_id; }
56 virtual void setId(const AtomString& id) { m_id = id; }
57
58 AtomString label() const { return m_label; }
59 void setLabel(const AtomString& label) { m_label = label; }
60
61 AtomString validBCP47Language() const;
62 AtomString language() const { return m_language; }
63 virtual void setLanguage(const AtomString&);
64
65 virtual void clearClient() = 0;
66
67 virtual int uniqueId() const { return m_uniqueId; }
68
69#if ENABLE(MEDIA_SOURCE)
70 SourceBuffer* sourceBuffer() const { return m_sourceBuffer; }
71 void setSourceBuffer(SourceBuffer* buffer) { m_sourceBuffer = buffer; }
72#endif
73
74 virtual bool enabled() const = 0;
75
76#if !RELEASE_LOG_DISABLED
77 const Logger& logger() const final { ASSERT(m_logger); return *m_logger.get(); }
78 const void* logIdentifier() const final { return m_logIdentifier; }
79 WTFLogChannel& logChannel() const final;
80#endif
81
82protected:
83 TrackBase(Type, const AtomString& id, const AtomString& label, const AtomString& language);
84
85 HTMLMediaElement* m_mediaElement { nullptr };
86
87#if ENABLE(MEDIA_SOURCE)
88 SourceBuffer* m_sourceBuffer { nullptr };
89#endif
90
91private:
92 Type m_type;
93 int m_uniqueId;
94 AtomString m_id;
95 AtomString m_label;
96 AtomString m_language;
97 AtomString m_validBCP47Language;
98#if !RELEASE_LOG_DISABLED
99 RefPtr<const Logger> m_logger;
100 const void* m_logIdentifier;
101#endif
102};
103
104class MediaTrackBase : public TrackBase {
105public:
106 const AtomString& kind() const { return m_kind; }
107 virtual void setKind(const AtomString&);
108
109protected:
110 MediaTrackBase(Type, const AtomString& id, const AtomString& label, const AtomString& language);
111
112 void setKindInternal(const AtomString&);
113
114private:
115 virtual bool isValidKind(const AtomString&) const = 0;
116
117 AtomString m_kind;
118};
119
120} // namespace WebCore
121
122#endif
123