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/Forward.h"
41 #include "wtf/RefCounted.h"
42 #include "wtf/text/WTFString.h"
47 class FileReaderLoader;
48 class GenericEventQueue;
52 class WebSourceBuffer;
54 class SourceBuffer FINAL : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<SourceBuffer>, public ActiveDOMObject, public EventTargetWithInlineData, public FileReaderLoaderClient, public WebSourceBufferClient {
55 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<SourceBuffer>);
56 DEFINE_WRAPPERTYPEINFO();
57 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(SourceBuffer);
59 static SourceBuffer* create(PassOwnPtr<WebSourceBuffer>, MediaSource*, GenericEventQueue*);
60 static const AtomicString& segmentsKeyword();
61 static const AtomicString& sequenceKeyword();
63 virtual ~SourceBuffer();
65 // SourceBuffer.idl methods
66 const AtomicString& mode() const { return m_mode; }
67 void setMode(const AtomicString&, ExceptionState&);
68 bool updating() const { return m_updating; }
69 PassRefPtrWillBeRawPtr<TimeRanges> buffered(ExceptionState&) const;
70 double timestampOffset() const;
71 void setTimestampOffset(double, ExceptionState&);
72 void appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState&);
73 void appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState&);
74 void appendStream(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&);
75 void appendStream(PassRefPtrWillBeRawPtr<Stream>, unsigned long long maxSize, ExceptionState&);
76 void abort(ExceptionState&);
77 void remove(double start, double end, ExceptionState&);
78 double appendWindowStart() const;
79 void setAppendWindowStart(double, ExceptionState&);
80 double appendWindowEnd() const;
81 void setAppendWindowEnd(double, ExceptionState&);
83 void abortIfUpdating();
84 void removedFromMediaSource();
86 // ActiveDOMObject interface
87 virtual bool hasPendingActivity() const OVERRIDE;
88 virtual void suspend() OVERRIDE;
89 virtual void resume() OVERRIDE;
90 virtual void stop() OVERRIDE;
92 // EventTarget interface
93 virtual ExecutionContext* executionContext() const OVERRIDE;
94 virtual const AtomicString& interfaceName() const OVERRIDE;
96 // WebSourceBufferClient interface
97 virtual void initializationSegmentReceived() OVERRIDE;
99 virtual void trace(Visitor*) OVERRIDE;
102 SourceBuffer(PassOwnPtr<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<WebSourceBuffer> m_webSourceBuffer;
124 Member<MediaSource> m_source;
125 GenericEventQueue* m_asyncEventQueue;
129 double m_timestampOffset;
130 double m_appendWindowStart;
131 double m_appendWindowEnd;
132 bool m_firstInitializationSegmentReceived;
134 Vector<unsigned char> m_pendingAppendData;
135 size_t m_pendingAppendDataOffset;
136 AsyncMethodRunner<SourceBuffer> m_appendBufferAsyncPartRunner;
138 double m_pendingRemoveStart;
139 double m_pendingRemoveEnd;
140 AsyncMethodRunner<SourceBuffer> m_removeAsyncPartRunner;
142 bool m_streamMaxSizeValid;
143 unsigned long long m_streamMaxSize;
144 AsyncMethodRunner<SourceBuffer> m_appendStreamAsyncPartRunner;
145 RefPtrWillBeMember<Stream> m_stream;
146 OwnPtr<FileReaderLoader> m_loader;
151 #endif // SourceBuffer_h