1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/mediasource/SourceBuffer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,160 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_SourceBuffer_h_ 1.11 +#define mozilla_dom_SourceBuffer_h_ 1.12 + 1.13 +#include "MediaDecoderReader.h" 1.14 +#include "MediaSource.h" 1.15 +#include "js/RootingAPI.h" 1.16 +#include "mozilla/Assertions.h" 1.17 +#include "mozilla/Attributes.h" 1.18 +#include "mozilla/dom/SourceBufferBinding.h" 1.19 +#include "mozilla/dom/TypedArray.h" 1.20 +#include "mozilla/DOMEventTargetHelper.h" 1.21 +#include "mozilla/mozalloc.h" 1.22 +#include "nsAutoPtr.h" 1.23 +#include "nsCOMPtr.h" 1.24 +#include "nsCycleCollectionNoteChild.h" 1.25 +#include "nsCycleCollectionParticipant.h" 1.26 +#include "nsISupports.h" 1.27 +#include "nsStringGlue.h" 1.28 +#include "nscore.h" 1.29 + 1.30 +class JSObject; 1.31 +struct JSContext; 1.32 + 1.33 +namespace mozilla { 1.34 + 1.35 +class ContainerParser; 1.36 +class ErrorResult; 1.37 +class SourceBufferResource; 1.38 +class SubBufferDecoder; 1.39 +template <typename T> class AsyncEventRunner; 1.40 + 1.41 +namespace dom { 1.42 + 1.43 +class TimeRanges; 1.44 + 1.45 +class SourceBuffer MOZ_FINAL : public DOMEventTargetHelper 1.46 +{ 1.47 +public: 1.48 + /** WebIDL Methods. */ 1.49 + SourceBufferAppendMode Mode() const 1.50 + { 1.51 + return mAppendMode; 1.52 + } 1.53 + 1.54 + void SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv); 1.55 + 1.56 + bool Updating() const 1.57 + { 1.58 + return mUpdating; 1.59 + } 1.60 + 1.61 + already_AddRefed<TimeRanges> GetBuffered(ErrorResult& aRv); 1.62 + 1.63 + double TimestampOffset() const 1.64 + { 1.65 + return mTimestampOffset; 1.66 + } 1.67 + 1.68 + void SetTimestampOffset(double aTimestampOffset, ErrorResult& aRv); 1.69 + 1.70 + double AppendWindowStart() const 1.71 + { 1.72 + return mAppendWindowStart; 1.73 + } 1.74 + 1.75 + void SetAppendWindowStart(double aAppendWindowStart, ErrorResult& aRv); 1.76 + 1.77 + double AppendWindowEnd() const 1.78 + { 1.79 + return mAppendWindowEnd; 1.80 + } 1.81 + 1.82 + void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv); 1.83 + 1.84 + void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv); 1.85 + void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv); 1.86 + 1.87 + void Abort(ErrorResult& aRv); 1.88 + 1.89 + void Remove(double aStart, double aEnd, ErrorResult& aRv); 1.90 + /** End WebIDL Methods. */ 1.91 + 1.92 + NS_DECL_ISUPPORTS_INHERITED 1.93 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBuffer, DOMEventTargetHelper) 1.94 + 1.95 + static already_AddRefed<SourceBuffer> Create(MediaSource* aMediaSource, const nsACString& aType); 1.96 + ~SourceBuffer(); 1.97 + 1.98 + MediaSource* GetParentObject() const; 1.99 + 1.100 + JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.101 + 1.102 + // Notify the SourceBuffer that it has been detached from the 1.103 + // MediaSource's sourceBuffer list. 1.104 + void Detach(); 1.105 + bool IsAttached() const 1.106 + { 1.107 + return mMediaSource != nullptr; 1.108 + } 1.109 + 1.110 + void Ended(); 1.111 + 1.112 + // Evict data in the source buffer in the given time range. 1.113 + void Evict(double aStart, double aEnd); 1.114 + 1.115 + // Returns true if the data in the source buffer contains the given time. 1.116 + bool ContainsTime(double aTime); 1.117 + 1.118 +private: 1.119 + SourceBuffer(MediaSource* aMediaSource, const nsACString& aType); 1.120 + 1.121 + friend class AsyncEventRunner<SourceBuffer>; 1.122 + void DispatchSimpleEvent(const char* aName); 1.123 + void QueueAsyncSimpleEvent(const char* aName); 1.124 + 1.125 + // Create a new decoder for mType, add it to mDecoders and update mCurrentDecoder. 1.126 + bool InitNewDecoder(); 1.127 + 1.128 + // Update mUpdating and fire the appropriate events. 1.129 + void StartUpdating(); 1.130 + void StopUpdating(); 1.131 + void AbortUpdating(); 1.132 + 1.133 + // Shared implementation of AppendBuffer overloads. 1.134 + void AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv); 1.135 + 1.136 + // Provide the minimum start time and maximum end time that is available 1.137 + // in the data buffered by this SourceBuffer. 1.138 + void GetBufferedStartEndTime(double* aStart, double* aEnd); 1.139 + 1.140 + nsRefPtr<MediaSource> mMediaSource; 1.141 + 1.142 + const nsAutoCString mType; 1.143 + 1.144 + nsAutoPtr<ContainerParser> mParser; 1.145 + 1.146 + // XXX: We only want to keep the current decoder alive, but need a way to 1.147 + // query @buffered for everything this SourceBuffer is responsible for. 1.148 + nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders; 1.149 + nsRefPtr<SubBufferDecoder> mCurrentDecoder; 1.150 + 1.151 + double mAppendWindowStart; 1.152 + double mAppendWindowEnd; 1.153 + 1.154 + double mTimestampOffset; 1.155 + 1.156 + SourceBufferAppendMode mAppendMode; 1.157 + bool mUpdating; 1.158 +}; 1.159 + 1.160 +} // namespace dom 1.161 + 1.162 +} // namespace mozilla 1.163 +#endif /* mozilla_dom_SourceBuffer_h_ */