1521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)/* 2521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 3521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * 4521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * modification, are permitted provided that the following conditions are 6521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * met: 7521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * 8521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 9521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 10521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 11521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 12521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * in the documentation and/or other materials provided with the 13521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * distribution. 14521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 15521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 16521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * this software without specific prior written permission. 17521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * 18521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) */ 30521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 31521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#ifndef SourceBuffer_h 32521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#define SourceBuffer_h 33521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 34521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "core/dom/ActiveDOMObject.h" 3506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)#include "core/fileapi/FileReaderLoaderClient.h" 36d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "modules/EventTargetModules.h" 37f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/AsyncMethodRunner.h" 3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "platform/weborigin/KURL.h" 397242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "public/platform/WebSourceBufferClient.h" 40197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "wtf/Forward.h" 41d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "wtf/RefCounted.h" 42521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/text/WTFString.h" 43521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink { 457757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch 467757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdochclass ExceptionState; 4706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)class FileReaderLoader; 48521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)class GenericEventQueue; 49521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)class MediaSource; 5006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)class Stream; 51521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)class TimeRanges; 52e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)class WebSourceBuffer; 53521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 547242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucciclass SourceBuffer FINAL : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<SourceBuffer>, public ActiveDOMObject, public EventTargetWithInlineData, public FileReaderLoaderClient, public WebSourceBufferClient { 55197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<SourceBuffer>); 567242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci DEFINE_WRAPPERTYPEINFO(); 57d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(SourceBuffer); 58521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)public: 59e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) static SourceBuffer* create(PassOwnPtr<WebSourceBuffer>, MediaSource*, GenericEventQueue*); 6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static const AtomicString& segmentsKeyword(); 6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) static const AtomicString& sequenceKeyword(); 62521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 63521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) virtual ~SourceBuffer(); 64521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 65521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) // SourceBuffer.idl methods 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) const AtomicString& mode() const { return m_mode; } 6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void setMode(const AtomicString&, ExceptionState&); 68521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) bool updating() const { return m_updating; } 69197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch PassRefPtrWillBeRawPtr<TimeRanges> buffered(ExceptionState&) const; 70521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) double timestampOffset() const; 717757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch void setTimestampOffset(double, ExceptionState&); 727757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch void appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState&); 737757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch void appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState&); 74d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void appendStream(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&); 75d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void appendStream(PassRefPtrWillBeRawPtr<Stream>, unsigned long long maxSize, ExceptionState&); 767757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch void abort(ExceptionState&); 7723e46e0f045bc1935a09565578b448d36cfc5b8cBen Murdoch void remove(double start, double end, ExceptionState&); 783c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch double appendWindowStart() const; 793c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch void setAppendWindowStart(double, ExceptionState&); 803c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch double appendWindowEnd() const; 813c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch void setAppendWindowEnd(double, ExceptionState&); 82521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 83521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void abortIfUpdating(); 84521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void removedFromMediaSource(); 85521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 86521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) // ActiveDOMObject interface 87521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) virtual bool hasPendingActivity() const OVERRIDE; 88f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) virtual void suspend() OVERRIDE; 89f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) virtual void resume() OVERRIDE; 90521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) virtual void stop() OVERRIDE; 91521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 92521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) // EventTarget interface 931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) virtual ExecutionContext* executionContext() const OVERRIDE; 94521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) virtual const AtomicString& interfaceName() const OVERRIDE; 95521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // WebSourceBufferClient interface 977242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci virtual void initializationSegmentReceived() OVERRIDE; 987242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci 99d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) virtual void trace(Visitor*) OVERRIDE; 10009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 101521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)private: 102e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) SourceBuffer(PassOwnPtr<WebSourceBuffer>, MediaSource*, GenericEventQueue*); 103521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 104521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) bool isRemoved() const; 105521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void scheduleEvent(const AtomicString& eventName); 106521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 10706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) void appendBufferInternal(const unsigned char*, unsigned, ExceptionState&); 108f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) void appendBufferAsyncPart(); 109521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 110f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) void removeAsyncPart(); 11123e46e0f045bc1935a09565578b448d36cfc5b8cBen Murdoch 112d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void appendStreamInternal(PassRefPtrWillBeRawPtr<Stream>, ExceptionState&); 113f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) void appendStreamAsyncPart(); 11406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) void appendStreamDone(bool success); 11506f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) void clearAppendStreamState(); 11606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) 11706f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) // FileReaderLoaderClient interface 11806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) virtual void didStartLoading() OVERRIDE; 11906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) virtual void didReceiveDataForClient(const char* data, unsigned dataLength) OVERRIDE; 12006f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) virtual void didFinishLoading() OVERRIDE; 12106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) virtual void didFail(FileError::ErrorCode) OVERRIDE; 12206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) 123e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) OwnPtr<WebSourceBuffer> m_webSourceBuffer; 124197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch Member<MediaSource> m_source; 125521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) GenericEventQueue* m_asyncEventQueue; 126521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 12709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) AtomicString m_mode; 128521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) bool m_updating; 129521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) double m_timestampOffset; 1303c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch double m_appendWindowStart; 1313c9e4aeaee9f9b0a9a814da07bcb33319c7ea363Ben Murdoch double m_appendWindowEnd; 1327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci bool m_firstInitializationSegmentReceived; 133521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 134521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) Vector<unsigned char> m_pendingAppendData; 135323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) size_t m_pendingAppendDataOffset; 136f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) AsyncMethodRunner<SourceBuffer> m_appendBufferAsyncPartRunner; 13723e46e0f045bc1935a09565578b448d36cfc5b8cBen Murdoch 13823e46e0f045bc1935a09565578b448d36cfc5b8cBen Murdoch double m_pendingRemoveStart; 13923e46e0f045bc1935a09565578b448d36cfc5b8cBen Murdoch double m_pendingRemoveEnd; 140f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) AsyncMethodRunner<SourceBuffer> m_removeAsyncPartRunner; 14106f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) 14206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) bool m_streamMaxSizeValid; 14306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) unsigned long long m_streamMaxSize; 144f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) AsyncMethodRunner<SourceBuffer> m_appendStreamAsyncPartRunner; 145d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) RefPtrWillBeMember<Stream> m_stream; 14606f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) OwnPtr<FileReaderLoader> m_loader; 147521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)}; 148521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 149c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 150521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) 1517242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#endif // SourceBuffer_h 152