2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef SourceBuffer_h
32 #define SourceBuffer_h
34 #include "bindings/v8/ScriptWrappable.h"
35 #include "core/dom/ActiveDOMObject.h"
36 #include "core/events/EventTarget.h"
37 #include "core/fileapi/FileReaderLoaderClient.h"
38 #include "platform/AsyncMethodRunner.h"
39 #include "platform/weborigin/KURL.h"
40 #include "wtf/OwnPtr.h"
41 #include "wtf/PassOwnPtr.h"
42 #include "wtf/PassRefPtr.h"
43 #include "wtf/RefPtr.h"
44 #include "wtf/text/WTFString.h"
47 class WebSourceBuffer;
53 class FileReaderLoader;
54 class GenericEventQueue;
59 class SourceBuffer FINAL : public RefCountedGarbageCollected<SourceBuffer>, public ActiveDOMObject, public EventTargetWithInlineData, public ScriptWrappable, public FileReaderLoaderClient {
60 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedGarbageCollected<SourceBuffer>);
62 static SourceBuffer* create(PassOwnPtr<blink::WebSourceBuffer>, MediaSource*, GenericEventQueue*);
63 static const AtomicString& segmentsKeyword();
64 static const AtomicString& sequenceKeyword();
66 virtual ~SourceBuffer();
68 // SourceBuffer.idl methods
69 const AtomicString& mode() const { return m_mode; }
70 void setMode(const AtomicString&, ExceptionState&);
71 bool updating() const { return m_updating; }
72 PassRefPtr<TimeRanges> buffered(ExceptionState&) const;
73 double timestampOffset() const;
74 void setTimestampOffset(double, ExceptionState&);
75 void appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState&);
76 void appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState&);
77 void appendStream(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&);
78 void appendStream(PassRefPtrWillBeRawPtr<Stream>, unsigned long long maxSize, ExceptionState&);
79 void abort(ExceptionState&);
80 void remove(double start, double end, ExceptionState&);
81 double appendWindowStart() const;
82 void setAppendWindowStart(double, ExceptionState&);
83 double appendWindowEnd() const;
84 void setAppendWindowEnd(double, ExceptionState&);
86 void abortIfUpdating();
87 void removedFromMediaSource();
89 // ActiveDOMObject interface
90 virtual bool hasPendingActivity() const OVERRIDE;
91 virtual void suspend() OVERRIDE;
92 virtual void resume() OVERRIDE;
93 virtual void stop() OVERRIDE;
95 // EventTarget interface
96 virtual ExecutionContext* executionContext() const OVERRIDE;
97 virtual const AtomicString& interfaceName() const OVERRIDE;
102 SourceBuffer(PassOwnPtr<blink::WebSourceBuffer>, MediaSource*, GenericEventQueue*);
104 bool isRemoved() const;
105 void scheduleEvent(const AtomicString& eventName);
107 void appendBufferInternal(const unsigned char*, unsigned, ExceptionState&);
108 void appendBufferAsyncPart();
110 void removeAsyncPart();
112 void appendStreamInternal(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&);
113 void appendStreamAsyncPart();
114 void appendStreamDone(bool success);
115 void clearAppendStreamState();
117 // FileReaderLoaderClient interface
118 virtual void didStartLoading() OVERRIDE;
119 virtual void didReceiveDataForClient(const char* data, unsigned dataLength) OVERRIDE;
120 virtual void didFinishLoading() OVERRIDE;
121 virtual void didFail(FileError::ErrorCode) OVERRIDE;
123 OwnPtr<blink::WebSourceBuffer> m_webSourceBuffer;
124 Member<MediaSource> m_source;
125 GenericEventQueue* m_asyncEventQueue;
129 double m_timestampOffset;
130 double m_appendWindowStart;
131 double m_appendWindowEnd;
133 Vector<unsigned char> m_pendingAppendData;
134 size_t m_pendingAppendDataOffset;
135 AsyncMethodRunner<SourceBuffer> m_appendBufferAsyncPartRunner;
137 double m_pendingRemoveStart;
138 double m_pendingRemoveEnd;
139 AsyncMethodRunner<SourceBuffer> m_removeAsyncPartRunner;
141 bool m_streamMaxSizeValid;
142 unsigned long long m_streamMaxSize;
143 AsyncMethodRunner<SourceBuffer> m_appendStreamAsyncPartRunner;
144 RefPtrWillBeMember<Stream> m_stream;
145 OwnPtr<FileReaderLoader> m_loader;
148 } // namespace WebCore