• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fileapi/FileReaderLoaderClient.h"
37 #include "modules/EventTargetModules.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/RefCounted.h"
44 #include "wtf/RefPtr.h"
45 #include "wtf/text/WTFString.h"
46 
47 namespace blink {
48 class WebSourceBuffer;
49 }
50 
51 namespace WebCore {
52 
53 class ExceptionState;
54 class FileReaderLoader;
55 class GenericEventQueue;
56 class MediaSource;
57 class Stream;
58 class TimeRanges;
59 
60 class SourceBuffer FINAL : public RefCountedWillBeRefCountedGarbageCollected<SourceBuffer>, public ActiveDOMObject, public EventTargetWithInlineData, public ScriptWrappable, public FileReaderLoaderClient {
61     REFCOUNTED_EVENT_TARGET(SourceBuffer);
62     WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(SourceBuffer);
63 public:
64     static PassRefPtrWillBeRawPtr<SourceBuffer> create(PassOwnPtr<blink::WebSourceBuffer>, MediaSource*, GenericEventQueue*);
65     static const AtomicString& segmentsKeyword();
66     static const AtomicString& sequenceKeyword();
67 
68     virtual ~SourceBuffer();
69 
70     // SourceBuffer.idl methods
mode()71     const AtomicString& mode() const { return m_mode; }
72     void setMode(const AtomicString&, ExceptionState&);
updating()73     bool updating() const { return m_updating; }
74     PassRefPtr<TimeRanges> buffered(ExceptionState&) const;
75     double timestampOffset() const;
76     void setTimestampOffset(double, ExceptionState&);
77     void appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState&);
78     void appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState&);
79     void appendStream(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&);
80     void appendStream(PassRefPtrWillBeRawPtr<Stream>, unsigned long long maxSize, ExceptionState&);
81     void abort(ExceptionState&);
82     void remove(double start, double end, ExceptionState&);
83     double appendWindowStart() const;
84     void setAppendWindowStart(double, ExceptionState&);
85     double appendWindowEnd() const;
86     void setAppendWindowEnd(double, ExceptionState&);
87 
88     void abortIfUpdating();
89     void removedFromMediaSource();
90 
91     // ActiveDOMObject interface
92     virtual bool hasPendingActivity() const OVERRIDE;
93     virtual void suspend() OVERRIDE;
94     virtual void resume() OVERRIDE;
95     virtual void stop() OVERRIDE;
96 
97     // EventTarget interface
98     virtual ExecutionContext* executionContext() const OVERRIDE;
99     virtual const AtomicString& interfaceName() const OVERRIDE;
100 
101     virtual void trace(Visitor*) OVERRIDE;
102 
103 private:
104     SourceBuffer(PassOwnPtr<blink::WebSourceBuffer>, MediaSource*, GenericEventQueue*);
105 
106     bool isRemoved() const;
107     void scheduleEvent(const AtomicString& eventName);
108 
109     void appendBufferInternal(const unsigned char*, unsigned, ExceptionState&);
110     void appendBufferAsyncPart();
111 
112     void removeAsyncPart();
113 
114     void appendStreamInternal(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&);
115     void appendStreamAsyncPart();
116     void appendStreamDone(bool success);
117     void clearAppendStreamState();
118 
119     // FileReaderLoaderClient interface
120     virtual void didStartLoading() OVERRIDE;
121     virtual void didReceiveDataForClient(const char* data, unsigned dataLength) OVERRIDE;
122     virtual void didFinishLoading() OVERRIDE;
123     virtual void didFail(FileError::ErrorCode) OVERRIDE;
124 
125     OwnPtr<blink::WebSourceBuffer> m_webSourceBuffer;
126     RawPtrWillBeMember<MediaSource> m_source;
127     GenericEventQueue* m_asyncEventQueue;
128 
129     AtomicString m_mode;
130     bool m_updating;
131     double m_timestampOffset;
132     double m_appendWindowStart;
133     double m_appendWindowEnd;
134 
135     Vector<unsigned char> m_pendingAppendData;
136     size_t m_pendingAppendDataOffset;
137     AsyncMethodRunner<SourceBuffer> m_appendBufferAsyncPartRunner;
138 
139     double m_pendingRemoveStart;
140     double m_pendingRemoveEnd;
141     AsyncMethodRunner<SourceBuffer> m_removeAsyncPartRunner;
142 
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;
148 };
149 
150 } // namespace WebCore
151 
152 #endif
153