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 SourceBuffer_h 32 #define SourceBuffer_h 33 34 #include "bindings/v8/ScriptWrappable.h" 35 #include "core/dom/ActiveDOMObject.h" 36 #include "core/dom/EventTarget.h" 37 #include "core/platform/Timer.h" 38 #include "wtf/PassRefPtr.h" 39 #include "wtf/RefCounted.h" 40 #include "wtf/text/WTFString.h" 41 42 namespace WebCore { 43 44 class ExceptionState; 45 class GenericEventQueue; 46 class MediaSource; 47 class SourceBufferPrivate; 48 class TimeRanges; 49 50 class SourceBuffer : public RefCounted<SourceBuffer>, public ActiveDOMObject, public EventTarget, public ScriptWrappable { 51 public: 52 static PassRefPtr<SourceBuffer> create(PassOwnPtr<SourceBufferPrivate>, MediaSource*, GenericEventQueue*); 53 54 virtual ~SourceBuffer(); 55 56 // SourceBuffer.idl methods 57 bool updating() const { return m_updating; } 58 PassRefPtr<TimeRanges> buffered(ExceptionState&) const; 59 double timestampOffset() const; 60 void setTimestampOffset(double, ExceptionState&); 61 void appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState&); 62 void appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState&); 63 void abort(ExceptionState&); 64 void remove(double start, double end, ExceptionState&); 65 double appendWindowStart() const; 66 void setAppendWindowStart(double, ExceptionState&); 67 double appendWindowEnd() const; 68 void setAppendWindowEnd(double, ExceptionState&); 69 70 void abortIfUpdating(); 71 void removedFromMediaSource(); 72 73 // ActiveDOMObject interface 74 virtual bool hasPendingActivity() const OVERRIDE; 75 virtual void stop() OVERRIDE; 76 77 // EventTarget interface 78 virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE; 79 virtual const AtomicString& interfaceName() const OVERRIDE; 80 81 using RefCounted<SourceBuffer>::ref; 82 using RefCounted<SourceBuffer>::deref; 83 84 protected: 85 // EventTarget interface 86 virtual EventTargetData* eventTargetData() OVERRIDE; 87 virtual EventTargetData* ensureEventTargetData() OVERRIDE; 88 virtual void refEventTarget() OVERRIDE { ref(); } 89 virtual void derefEventTarget() OVERRIDE { deref(); } 90 91 private: 92 SourceBuffer(PassOwnPtr<SourceBufferPrivate>, MediaSource*, GenericEventQueue*); 93 94 bool isRemoved() const; 95 void scheduleEvent(const AtomicString& eventName); 96 97 void appendBufferInternal(unsigned char*, unsigned, ExceptionState&); 98 void appendBufferTimerFired(Timer<SourceBuffer>*); 99 100 void removeTimerFired(Timer<SourceBuffer>*); 101 102 OwnPtr<SourceBufferPrivate> m_private; 103 MediaSource* m_source; 104 GenericEventQueue* m_asyncEventQueue; 105 EventTargetData m_eventTargetData; 106 107 bool m_updating; 108 double m_timestampOffset; 109 double m_appendWindowStart; 110 double m_appendWindowEnd; 111 112 Vector<unsigned char> m_pendingAppendData; 113 Timer<SourceBuffer> m_appendBufferTimer; 114 115 double m_pendingRemoveStart; 116 double m_pendingRemoveEnd; 117 Timer<SourceBuffer> m_removeTimer; 118 }; 119 120 } // namespace WebCore 121 122 #endif 123