content/media/mediasource/SourceBuffer.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_SourceBuffer_h_
michael@0 8 #define mozilla_dom_SourceBuffer_h_
michael@0 9
michael@0 10 #include "MediaDecoderReader.h"
michael@0 11 #include "MediaSource.h"
michael@0 12 #include "js/RootingAPI.h"
michael@0 13 #include "mozilla/Assertions.h"
michael@0 14 #include "mozilla/Attributes.h"
michael@0 15 #include "mozilla/dom/SourceBufferBinding.h"
michael@0 16 #include "mozilla/dom/TypedArray.h"
michael@0 17 #include "mozilla/DOMEventTargetHelper.h"
michael@0 18 #include "mozilla/mozalloc.h"
michael@0 19 #include "nsAutoPtr.h"
michael@0 20 #include "nsCOMPtr.h"
michael@0 21 #include "nsCycleCollectionNoteChild.h"
michael@0 22 #include "nsCycleCollectionParticipant.h"
michael@0 23 #include "nsISupports.h"
michael@0 24 #include "nsStringGlue.h"
michael@0 25 #include "nscore.h"
michael@0 26
michael@0 27 class JSObject;
michael@0 28 struct JSContext;
michael@0 29
michael@0 30 namespace mozilla {
michael@0 31
michael@0 32 class ContainerParser;
michael@0 33 class ErrorResult;
michael@0 34 class SourceBufferResource;
michael@0 35 class SubBufferDecoder;
michael@0 36 template <typename T> class AsyncEventRunner;
michael@0 37
michael@0 38 namespace dom {
michael@0 39
michael@0 40 class TimeRanges;
michael@0 41
michael@0 42 class SourceBuffer MOZ_FINAL : public DOMEventTargetHelper
michael@0 43 {
michael@0 44 public:
michael@0 45 /** WebIDL Methods. */
michael@0 46 SourceBufferAppendMode Mode() const
michael@0 47 {
michael@0 48 return mAppendMode;
michael@0 49 }
michael@0 50
michael@0 51 void SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv);
michael@0 52
michael@0 53 bool Updating() const
michael@0 54 {
michael@0 55 return mUpdating;
michael@0 56 }
michael@0 57
michael@0 58 already_AddRefed<TimeRanges> GetBuffered(ErrorResult& aRv);
michael@0 59
michael@0 60 double TimestampOffset() const
michael@0 61 {
michael@0 62 return mTimestampOffset;
michael@0 63 }
michael@0 64
michael@0 65 void SetTimestampOffset(double aTimestampOffset, ErrorResult& aRv);
michael@0 66
michael@0 67 double AppendWindowStart() const
michael@0 68 {
michael@0 69 return mAppendWindowStart;
michael@0 70 }
michael@0 71
michael@0 72 void SetAppendWindowStart(double aAppendWindowStart, ErrorResult& aRv);
michael@0 73
michael@0 74 double AppendWindowEnd() const
michael@0 75 {
michael@0 76 return mAppendWindowEnd;
michael@0 77 }
michael@0 78
michael@0 79 void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv);
michael@0 80
michael@0 81 void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv);
michael@0 82 void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv);
michael@0 83
michael@0 84 void Abort(ErrorResult& aRv);
michael@0 85
michael@0 86 void Remove(double aStart, double aEnd, ErrorResult& aRv);
michael@0 87 /** End WebIDL Methods. */
michael@0 88
michael@0 89 NS_DECL_ISUPPORTS_INHERITED
michael@0 90 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBuffer, DOMEventTargetHelper)
michael@0 91
michael@0 92 static already_AddRefed<SourceBuffer> Create(MediaSource* aMediaSource, const nsACString& aType);
michael@0 93 ~SourceBuffer();
michael@0 94
michael@0 95 MediaSource* GetParentObject() const;
michael@0 96
michael@0 97 JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 98
michael@0 99 // Notify the SourceBuffer that it has been detached from the
michael@0 100 // MediaSource's sourceBuffer list.
michael@0 101 void Detach();
michael@0 102 bool IsAttached() const
michael@0 103 {
michael@0 104 return mMediaSource != nullptr;
michael@0 105 }
michael@0 106
michael@0 107 void Ended();
michael@0 108
michael@0 109 // Evict data in the source buffer in the given time range.
michael@0 110 void Evict(double aStart, double aEnd);
michael@0 111
michael@0 112 // Returns true if the data in the source buffer contains the given time.
michael@0 113 bool ContainsTime(double aTime);
michael@0 114
michael@0 115 private:
michael@0 116 SourceBuffer(MediaSource* aMediaSource, const nsACString& aType);
michael@0 117
michael@0 118 friend class AsyncEventRunner<SourceBuffer>;
michael@0 119 void DispatchSimpleEvent(const char* aName);
michael@0 120 void QueueAsyncSimpleEvent(const char* aName);
michael@0 121
michael@0 122 // Create a new decoder for mType, add it to mDecoders and update mCurrentDecoder.
michael@0 123 bool InitNewDecoder();
michael@0 124
michael@0 125 // Update mUpdating and fire the appropriate events.
michael@0 126 void StartUpdating();
michael@0 127 void StopUpdating();
michael@0 128 void AbortUpdating();
michael@0 129
michael@0 130 // Shared implementation of AppendBuffer overloads.
michael@0 131 void AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv);
michael@0 132
michael@0 133 // Provide the minimum start time and maximum end time that is available
michael@0 134 // in the data buffered by this SourceBuffer.
michael@0 135 void GetBufferedStartEndTime(double* aStart, double* aEnd);
michael@0 136
michael@0 137 nsRefPtr<MediaSource> mMediaSource;
michael@0 138
michael@0 139 const nsAutoCString mType;
michael@0 140
michael@0 141 nsAutoPtr<ContainerParser> mParser;
michael@0 142
michael@0 143 // XXX: We only want to keep the current decoder alive, but need a way to
michael@0 144 // query @buffered for everything this SourceBuffer is responsible for.
michael@0 145 nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders;
michael@0 146 nsRefPtr<SubBufferDecoder> mCurrentDecoder;
michael@0 147
michael@0 148 double mAppendWindowStart;
michael@0 149 double mAppendWindowEnd;
michael@0 150
michael@0 151 double mTimestampOffset;
michael@0 152
michael@0 153 SourceBufferAppendMode mAppendMode;
michael@0 154 bool mUpdating;
michael@0 155 };
michael@0 156
michael@0 157 } // namespace dom
michael@0 158
michael@0 159 } // namespace mozilla
michael@0 160 #endif /* mozilla_dom_SourceBuffer_h_ */

mercurial