content/media/mediasource/SourceBufferList.cpp

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 #include "SourceBufferList.h"
michael@0 8
michael@0 9 #include "AsyncEventRunner.h"
michael@0 10 #include "mozilla/ErrorResult.h"
michael@0 11 #include "mozilla/dom/SourceBufferListBinding.h"
michael@0 12 #include "mozilla/mozalloc.h"
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nsIEventTarget.h"
michael@0 15 #include "nsIRunnable.h"
michael@0 16 #include "nsStringGlue.h"
michael@0 17 #include "nsThreadUtils.h"
michael@0 18 #include "prlog.h"
michael@0 19
michael@0 20 struct JSContext;
michael@0 21 class JSObject;
michael@0 22
michael@0 23 #ifdef PR_LOGGING
michael@0 24 extern PRLogModuleInfo* gMediaSourceLog;
michael@0 25 #define MSE_DEBUG(...) PR_LOG(gMediaSourceLog, PR_LOG_DEBUG, (__VA_ARGS__))
michael@0 26 #else
michael@0 27 #define MSE_DEBUG(...)
michael@0 28 #endif
michael@0 29
michael@0 30 namespace mozilla {
michael@0 31
michael@0 32 namespace dom {
michael@0 33
michael@0 34 SourceBuffer*
michael@0 35 SourceBufferList::IndexedGetter(uint32_t aIndex, bool& aFound)
michael@0 36 {
michael@0 37 aFound = aIndex < mSourceBuffers.Length();
michael@0 38 return aFound ? mSourceBuffers[aIndex] : nullptr;
michael@0 39 }
michael@0 40
michael@0 41 uint32_t
michael@0 42 SourceBufferList::Length()
michael@0 43 {
michael@0 44 return mSourceBuffers.Length();
michael@0 45 }
michael@0 46
michael@0 47 void
michael@0 48 SourceBufferList::Append(SourceBuffer* aSourceBuffer)
michael@0 49 {
michael@0 50 mSourceBuffers.AppendElement(aSourceBuffer);
michael@0 51 QueueAsyncSimpleEvent("addsourcebuffer");
michael@0 52 }
michael@0 53
michael@0 54 void
michael@0 55 SourceBufferList::Remove(SourceBuffer* aSourceBuffer)
michael@0 56 {
michael@0 57 MOZ_ALWAYS_TRUE(mSourceBuffers.RemoveElement(aSourceBuffer));
michael@0 58 aSourceBuffer->Detach();
michael@0 59 QueueAsyncSimpleEvent("removesourcebuffer");
michael@0 60 }
michael@0 61
michael@0 62 bool
michael@0 63 SourceBufferList::Contains(SourceBuffer* aSourceBuffer)
michael@0 64 {
michael@0 65 return mSourceBuffers.Contains(aSourceBuffer);
michael@0 66 }
michael@0 67
michael@0 68 void
michael@0 69 SourceBufferList::Clear()
michael@0 70 {
michael@0 71 for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
michael@0 72 mSourceBuffers[i]->Detach();
michael@0 73 }
michael@0 74 mSourceBuffers.Clear();
michael@0 75 QueueAsyncSimpleEvent("removesourcebuffer");
michael@0 76 }
michael@0 77
michael@0 78 bool
michael@0 79 SourceBufferList::IsEmpty()
michael@0 80 {
michael@0 81 return mSourceBuffers.IsEmpty();
michael@0 82 }
michael@0 83
michael@0 84 bool
michael@0 85 SourceBufferList::AnyUpdating()
michael@0 86 {
michael@0 87 for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
michael@0 88 if (mSourceBuffers[i]->Updating()) {
michael@0 89 return true;
michael@0 90 }
michael@0 91 }
michael@0 92 return false;
michael@0 93 }
michael@0 94
michael@0 95 void
michael@0 96 SourceBufferList::Remove(double aStart, double aEnd, ErrorResult& aRv)
michael@0 97 {
michael@0 98 for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
michael@0 99 mSourceBuffers[i]->Remove(aStart, aEnd, aRv);
michael@0 100 if (aRv.Failed()) {
michael@0 101 return;
michael@0 102 }
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 void
michael@0 107 SourceBufferList::Evict(double aStart, double aEnd)
michael@0 108 {
michael@0 109 for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
michael@0 110 mSourceBuffers[i]->Evict(aStart, aEnd);
michael@0 111 }
michael@0 112 }
michael@0 113
michael@0 114 bool
michael@0 115 SourceBufferList::AllContainsTime(double aTime)
michael@0 116 {
michael@0 117 for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
michael@0 118 if (!mSourceBuffers[i]->ContainsTime(aTime)) {
michael@0 119 return false;
michael@0 120 }
michael@0 121 }
michael@0 122 return mSourceBuffers.Length() > 0;
michael@0 123 }
michael@0 124
michael@0 125 void
michael@0 126 SourceBufferList::Ended()
michael@0 127 {
michael@0 128 for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
michael@0 129 mSourceBuffers[i]->Ended();
michael@0 130 }
michael@0 131 }
michael@0 132
michael@0 133 void
michael@0 134 SourceBufferList::DispatchSimpleEvent(const char* aName)
michael@0 135 {
michael@0 136 MSE_DEBUG("%p Dispatching event %s to SourceBufferList", this, aName);
michael@0 137 DispatchTrustedEvent(NS_ConvertUTF8toUTF16(aName));
michael@0 138 }
michael@0 139
michael@0 140 void
michael@0 141 SourceBufferList::QueueAsyncSimpleEvent(const char* aName)
michael@0 142 {
michael@0 143 MSE_DEBUG("%p Queuing event %s to SourceBufferList", this, aName);
michael@0 144 nsCOMPtr<nsIRunnable> event = new AsyncEventRunner<SourceBufferList>(this, aName);
michael@0 145 NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
michael@0 146 }
michael@0 147
michael@0 148 SourceBufferList::SourceBufferList(MediaSource* aMediaSource)
michael@0 149 : DOMEventTargetHelper(aMediaSource->GetParentObject())
michael@0 150 , mMediaSource(aMediaSource)
michael@0 151 {
michael@0 152 MOZ_ASSERT(aMediaSource);
michael@0 153 }
michael@0 154
michael@0 155 MediaSource*
michael@0 156 SourceBufferList::GetParentObject() const
michael@0 157 {
michael@0 158 return mMediaSource;
michael@0 159 }
michael@0 160
michael@0 161 JSObject*
michael@0 162 SourceBufferList::WrapObject(JSContext* aCx)
michael@0 163 {
michael@0 164 return SourceBufferListBinding::Wrap(aCx, this);
michael@0 165 }
michael@0 166
michael@0 167 NS_IMPL_CYCLE_COLLECTION_INHERITED(SourceBufferList, DOMEventTargetHelper,
michael@0 168 mMediaSource, mSourceBuffers)
michael@0 169
michael@0 170 NS_IMPL_ADDREF_INHERITED(SourceBufferList, DOMEventTargetHelper)
michael@0 171 NS_IMPL_RELEASE_INHERITED(SourceBufferList, DOMEventTargetHelper)
michael@0 172
michael@0 173 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SourceBufferList)
michael@0 174 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
michael@0 175
michael@0 176 } // namespace dom
michael@0 177
michael@0 178 } // namespace mozilla

mercurial