| 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/AtomicString.h> |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | class Element; |
| 36 | class HTMLMediaElement; |
| 37 | class SourceBuffer; |
| 38 | |
| 39 | class TrackBase |
| 40 | : public RefCounted<TrackBase> |
| 41 | #if !RELEASE_LOG_DISABLED |
| 42 | , private LoggerHelper |
| 43 | #endif |
| 44 | { |
| 45 | public: |
| 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 AtomicString id() const { return m_id; } |
| 56 | virtual void setId(const AtomicString& id) { m_id = id; } |
| 57 | |
| 58 | AtomicString label() const { return m_label; } |
| 59 | void setLabel(const AtomicString& label) { m_label = label; } |
| 60 | |
| 61 | AtomicString validBCP47Language() const; |
| 62 | AtomicString language() const { return m_language; } |
| 63 | virtual void setLanguage(const AtomicString&); |
| 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 | |
| 82 | protected: |
| 83 | TrackBase(Type, const AtomicString& id, const AtomicString& label, const AtomicString& language); |
| 84 | |
| 85 | HTMLMediaElement* m_mediaElement { nullptr }; |
| 86 | |
| 87 | #if ENABLE(MEDIA_SOURCE) |
| 88 | SourceBuffer* m_sourceBuffer { nullptr }; |
| 89 | #endif |
| 90 | |
| 91 | private: |
| 92 | Type m_type; |
| 93 | int m_uniqueId; |
| 94 | AtomicString m_id; |
| 95 | AtomicString m_label; |
| 96 | AtomicString m_language; |
| 97 | AtomicString m_validBCP47Language; |
| 98 | #if !RELEASE_LOG_DISABLED |
| 99 | RefPtr<const Logger> m_logger; |
| 100 | const void* m_logIdentifier; |
| 101 | #endif |
| 102 | }; |
| 103 | |
| 104 | class MediaTrackBase : public TrackBase { |
| 105 | public: |
| 106 | const AtomicString& kind() const { return m_kind; } |
| 107 | virtual void setKind(const AtomicString&); |
| 108 | |
| 109 | protected: |
| 110 | MediaTrackBase(Type, const AtomicString& id, const AtomicString& label, const AtomicString& language); |
| 111 | |
| 112 | void setKindInternal(const AtomicString&); |
| 113 | |
| 114 | private: |
| 115 | virtual bool isValidKind(const AtomicString&) const = 0; |
| 116 | |
| 117 | AtomicString m_kind; |
| 118 | }; |
| 119 | |
| 120 | } // namespace WebCore |
| 121 | |
| 122 | #endif |
| 123 | |