Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 Google 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 are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #ifndef MediaSourceBase_h |
| 32 | #define MediaSourceBase_h |
| 33 | |
| 34 | #include "core/dom/ActiveDOMObject.h" |
| 35 | #include "core/dom/EventTarget.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 36 | #include "core/html/HTMLMediaSource.h" |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 37 | #include "core/html/URLRegistry.h" |
| 38 | #include "core/platform/graphics/MediaSourcePrivate.h" |
| 39 | #include "wtf/PassOwnPtr.h" |
| 40 | #include "wtf/RefCounted.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 41 | #include "wtf/Vector.h" |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 42 | |
| 43 | namespace WebCore { |
| 44 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 45 | class ExceptionState; |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 46 | class GenericEventQueue; |
| 47 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 48 | class MediaSourceBase : public RefCounted<MediaSourceBase>, public HTMLMediaSource, public ActiveDOMObject, public EventTarget { |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 49 | public: |
| 50 | static const AtomicString& openKeyword(); |
| 51 | static const AtomicString& closedKeyword(); |
| 52 | static const AtomicString& endedKeyword(); |
| 53 | |
| 54 | virtual ~MediaSourceBase(); |
| 55 | |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 56 | void addedToRegistry(); |
| 57 | void removedFromRegistry(); |
| 58 | void openIfInEndedState(); |
| 59 | bool isOpen() const; |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 60 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 61 | // HTMLMediaSource |
| 62 | virtual bool attachToElement() OVERRIDE; |
| 63 | virtual void setPrivateAndOpen(PassOwnPtr<MediaSourcePrivate>) OVERRIDE; |
| 64 | virtual void close() OVERRIDE; |
| 65 | virtual bool isClosed() const OVERRIDE; |
| 66 | virtual double duration() const OVERRIDE; |
| 67 | virtual PassRefPtr<TimeRanges> buffered() const OVERRIDE; |
| 68 | virtual void refHTMLMediaSource() OVERRIDE { ref(); } |
| 69 | virtual void derefHTMLMediaSource() OVERRIDE { deref(); } |
| 70 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 71 | void setDuration(double, ExceptionState&); |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 72 | const AtomicString& readyState() const { return m_readyState; } |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 73 | void setReadyState(const AtomicString&); |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 74 | void endOfStream(const AtomicString& error, ExceptionState&); |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 75 | |
| 76 | |
| 77 | // ActiveDOMObject interface |
| 78 | virtual bool hasPendingActivity() const OVERRIDE; |
| 79 | virtual void stop() OVERRIDE; |
| 80 | |
| 81 | // EventTarget interface |
| 82 | virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE; |
| 83 | virtual EventTargetData* eventTargetData() OVERRIDE; |
| 84 | virtual EventTargetData* ensureEventTargetData() OVERRIDE; |
| 85 | virtual void refEventTarget() OVERRIDE { ref(); } |
| 86 | virtual void derefEventTarget() OVERRIDE { deref(); } |
| 87 | |
| 88 | // URLRegistrable interface |
| 89 | virtual URLRegistry& registry() const OVERRIDE; |
| 90 | |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 91 | using RefCounted<MediaSourceBase>::ref; |
| 92 | using RefCounted<MediaSourceBase>::deref; |
| 93 | |
| 94 | protected: |
| 95 | explicit MediaSourceBase(ScriptExecutionContext*); |
| 96 | |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 97 | virtual void onReadyStateChange(const AtomicString& oldState, const AtomicString& newState) = 0; |
| 98 | virtual Vector<RefPtr<TimeRanges> > activeRanges() const = 0; |
| 99 | |
Ben Murdoch | 7757ec2 | 2013-07-23 11:17:36 +0100 | [diff] [blame] | 100 | PassOwnPtr<SourceBufferPrivate> createSourceBufferPrivate(const String& type, const MediaSourcePrivate::CodecsArray&, ExceptionState&); |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 101 | void scheduleEvent(const AtomicString& eventName); |
| 102 | GenericEventQueue* asyncEventQueue() const { return m_asyncEventQueue.get(); } |
| 103 | |
| 104 | private: |
| 105 | OwnPtr<MediaSourcePrivate> m_private; |
| 106 | EventTargetData m_eventTargetData; |
| 107 | AtomicString m_readyState; |
| 108 | OwnPtr<GenericEventQueue> m_asyncEventQueue; |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 109 | bool m_attached; |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } |
| 113 | |
| 114 | #endif |