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 "core/dom/ActiveDOMObject.h"
35 #include "core/fileapi/FileReaderLoaderClient.h"
36 #include "modules/EventTargetModules.h"
37 #include "platform/AsyncMethodRunner.h"
38 #include "platform/weborigin/KURL.h"
39 #include "public/platform/WebSourceBufferClient.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/text/WTFString.h"
46 class DOMArrayBufferView;
48 class FileReaderLoader;
49 class GenericEventQueue;
53 class WebSourceBuffer;
55 class SourceBuffer final : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<SourceBuffer>, public ActiveDOMObject, public EventTargetWithInlineData, public FileReaderLoaderClient, public WebSourceBufferClient {
56 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<SourceBuffer>);
57 DEFINE_WRAPPERTYPEINFO();
58 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(SourceBuffer);
60 static SourceBuffer* create(PassOwnPtr<WebSourceBuffer>, MediaSource*, GenericEventQueue*);
61 static const AtomicString& segmentsKeyword();
62 static const AtomicString& sequenceKeyword();
64 virtual ~SourceBuffer();
66 // SourceBuffer.idl methods
67 const AtomicString& mode() const { return m_mode; }
68 void setMode(const AtomicString&, ExceptionState&);
69 bool updating() const { return m_updating; }
70 PassRefPtrWillBeRawPtr<TimeRanges> buffered(ExceptionState&) const;
71 double timestampOffset() const;
72 void setTimestampOffset(double, ExceptionState&);
73 void appendBuffer(PassRefPtr<DOMArrayBuffer> data, ExceptionState&);
74 void appendBuffer(PassRefPtr<DOMArrayBufferView> data, ExceptionState&);
75 void appendStream(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&);
76 void appendStream(PassRefPtrWillBeRawPtr<Stream>, unsigned long long maxSize, ExceptionState&);
77 void abort(ExceptionState&);
78 void remove(double start, double end, ExceptionState&);
79 double appendWindowStart() const;
80 void setAppendWindowStart(double, ExceptionState&);
81 double appendWindowEnd() const;
82 void setAppendWindowEnd(double, ExceptionState&);
84 void abortIfUpdating();
85 void removedFromMediaSource();
87 // ActiveDOMObject interface
88 virtual bool hasPendingActivity() const override;
89 virtual void suspend() override;
90 virtual void resume() override;
91 virtual void stop() override;
93 // EventTarget interface
94 virtual ExecutionContext* executionContext() const override;
95 virtual const AtomicString& interfaceName() const override;
97 // WebSourceBufferClient interface
98 virtual void initializationSegmentReceived() override;
100 virtual void trace(Visitor*) override;
103 SourceBuffer(PassOwnPtr<WebSourceBuffer>, MediaSource*, GenericEventQueue*);
105 bool isRemoved() const;
106 void scheduleEvent(const AtomicString& eventName);
108 void appendBufferInternal(const unsigned char*, unsigned, ExceptionState&);
109 void appendBufferAsyncPart();
111 void removeAsyncPart();
113 void appendStreamInternal(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&);
114 void appendStreamAsyncPart();
115 void appendStreamDone(bool success);
116 void clearAppendStreamState();
118 // FileReaderLoaderClient interface
119 virtual void didStartLoading() override;
120 virtual void didReceiveDataForClient(const char* data, unsigned dataLength) override;
121 virtual void didFinishLoading() override;
122 virtual void didFail(FileError::ErrorCode) override;
124 OwnPtr<WebSourceBuffer> m_webSourceBuffer;
125 Member<MediaSource> m_source;
126 GenericEventQueue* m_asyncEventQueue;
130 double m_timestampOffset;
131 double m_appendWindowStart;
132 double m_appendWindowEnd;
133 bool m_firstInitializationSegmentReceived;
135 Vector<unsigned char> m_pendingAppendData;
136 size_t m_pendingAppendDataOffset;
137 AsyncMethodRunner<SourceBuffer> m_appendBufferAsyncPartRunner;
139 double m_pendingRemoveStart;
140 double m_pendingRemoveEnd;
141 AsyncMethodRunner<SourceBuffer> m_removeAsyncPartRunner;
143 bool m_streamMaxSizeValid;
144 unsigned long long m_streamMaxSize;
145 AsyncMethodRunner<SourceBuffer> m_appendStreamAsyncPartRunner;
146 RefPtrWillBeMember<Stream> m_stream;
147 OwnPtr<FileReaderLoader> m_loader;
152 #endif // SourceBuffer_h