content/media/mediasource/SourceBufferList.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/mediasource/SourceBufferList.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,178 @@
     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 +#include "SourceBufferList.h"
    1.11 +
    1.12 +#include "AsyncEventRunner.h"
    1.13 +#include "mozilla/ErrorResult.h"
    1.14 +#include "mozilla/dom/SourceBufferListBinding.h"
    1.15 +#include "mozilla/mozalloc.h"
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include "nsIEventTarget.h"
    1.18 +#include "nsIRunnable.h"
    1.19 +#include "nsStringGlue.h"
    1.20 +#include "nsThreadUtils.h"
    1.21 +#include "prlog.h"
    1.22 +
    1.23 +struct JSContext;
    1.24 +class JSObject;
    1.25 +
    1.26 +#ifdef PR_LOGGING
    1.27 +extern PRLogModuleInfo* gMediaSourceLog;
    1.28 +#define MSE_DEBUG(...) PR_LOG(gMediaSourceLog, PR_LOG_DEBUG, (__VA_ARGS__))
    1.29 +#else
    1.30 +#define MSE_DEBUG(...)
    1.31 +#endif
    1.32 +
    1.33 +namespace mozilla {
    1.34 +
    1.35 +namespace dom {
    1.36 +
    1.37 +SourceBuffer*
    1.38 +SourceBufferList::IndexedGetter(uint32_t aIndex, bool& aFound)
    1.39 +{
    1.40 +  aFound = aIndex < mSourceBuffers.Length();
    1.41 +  return aFound ? mSourceBuffers[aIndex] : nullptr;
    1.42 +}
    1.43 +
    1.44 +uint32_t
    1.45 +SourceBufferList::Length()
    1.46 +{
    1.47 +  return mSourceBuffers.Length();
    1.48 +}
    1.49 +
    1.50 +void
    1.51 +SourceBufferList::Append(SourceBuffer* aSourceBuffer)
    1.52 +{
    1.53 +  mSourceBuffers.AppendElement(aSourceBuffer);
    1.54 +  QueueAsyncSimpleEvent("addsourcebuffer");
    1.55 +}
    1.56 +
    1.57 +void
    1.58 +SourceBufferList::Remove(SourceBuffer* aSourceBuffer)
    1.59 +{
    1.60 +  MOZ_ALWAYS_TRUE(mSourceBuffers.RemoveElement(aSourceBuffer));
    1.61 +  aSourceBuffer->Detach();
    1.62 +  QueueAsyncSimpleEvent("removesourcebuffer");
    1.63 +}
    1.64 +
    1.65 +bool
    1.66 +SourceBufferList::Contains(SourceBuffer* aSourceBuffer)
    1.67 +{
    1.68 +  return mSourceBuffers.Contains(aSourceBuffer);
    1.69 +}
    1.70 +
    1.71 +void
    1.72 +SourceBufferList::Clear()
    1.73 +{
    1.74 +  for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
    1.75 +    mSourceBuffers[i]->Detach();
    1.76 +  }
    1.77 +  mSourceBuffers.Clear();
    1.78 +  QueueAsyncSimpleEvent("removesourcebuffer");
    1.79 +}
    1.80 +
    1.81 +bool
    1.82 +SourceBufferList::IsEmpty()
    1.83 +{
    1.84 +  return mSourceBuffers.IsEmpty();
    1.85 +}
    1.86 +
    1.87 +bool
    1.88 +SourceBufferList::AnyUpdating()
    1.89 +{
    1.90 +  for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
    1.91 +    if (mSourceBuffers[i]->Updating()) {
    1.92 +      return true;
    1.93 +    }
    1.94 +  }
    1.95 +  return false;
    1.96 +}
    1.97 +
    1.98 +void
    1.99 +SourceBufferList::Remove(double aStart, double aEnd, ErrorResult& aRv)
   1.100 +{
   1.101 +  for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
   1.102 +    mSourceBuffers[i]->Remove(aStart, aEnd, aRv);
   1.103 +    if (aRv.Failed()) {
   1.104 +      return;
   1.105 +    }
   1.106 +  }
   1.107 +}
   1.108 +
   1.109 +void
   1.110 +SourceBufferList::Evict(double aStart, double aEnd)
   1.111 +{
   1.112 +  for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
   1.113 +    mSourceBuffers[i]->Evict(aStart, aEnd);
   1.114 +  }
   1.115 +}
   1.116 +
   1.117 +bool
   1.118 +SourceBufferList::AllContainsTime(double aTime)
   1.119 +{
   1.120 +  for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
   1.121 +    if (!mSourceBuffers[i]->ContainsTime(aTime)) {
   1.122 +      return false;
   1.123 +    }
   1.124 +  }
   1.125 +  return mSourceBuffers.Length() > 0;
   1.126 +}
   1.127 +
   1.128 +void
   1.129 +SourceBufferList::Ended()
   1.130 +{
   1.131 +  for (uint32_t i = 0; i < mSourceBuffers.Length(); ++i) {
   1.132 +    mSourceBuffers[i]->Ended();
   1.133 +  }
   1.134 +}
   1.135 +
   1.136 +void
   1.137 +SourceBufferList::DispatchSimpleEvent(const char* aName)
   1.138 +{
   1.139 +  MSE_DEBUG("%p Dispatching event %s to SourceBufferList", this, aName);
   1.140 +  DispatchTrustedEvent(NS_ConvertUTF8toUTF16(aName));
   1.141 +}
   1.142 +
   1.143 +void
   1.144 +SourceBufferList::QueueAsyncSimpleEvent(const char* aName)
   1.145 +{
   1.146 +  MSE_DEBUG("%p Queuing event %s to SourceBufferList", this, aName);
   1.147 +  nsCOMPtr<nsIRunnable> event = new AsyncEventRunner<SourceBufferList>(this, aName);
   1.148 +  NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
   1.149 +}
   1.150 +
   1.151 +SourceBufferList::SourceBufferList(MediaSource* aMediaSource)
   1.152 +  : DOMEventTargetHelper(aMediaSource->GetParentObject())
   1.153 +  , mMediaSource(aMediaSource)
   1.154 +{
   1.155 +  MOZ_ASSERT(aMediaSource);
   1.156 +}
   1.157 +
   1.158 +MediaSource*
   1.159 +SourceBufferList::GetParentObject() const
   1.160 +{
   1.161 +  return mMediaSource;
   1.162 +}
   1.163 +
   1.164 +JSObject*
   1.165 +SourceBufferList::WrapObject(JSContext* aCx)
   1.166 +{
   1.167 +  return SourceBufferListBinding::Wrap(aCx, this);
   1.168 +}
   1.169 +
   1.170 +NS_IMPL_CYCLE_COLLECTION_INHERITED(SourceBufferList, DOMEventTargetHelper,
   1.171 +                                   mMediaSource, mSourceBuffers)
   1.172 +
   1.173 +NS_IMPL_ADDREF_INHERITED(SourceBufferList, DOMEventTargetHelper)
   1.174 +NS_IMPL_RELEASE_INHERITED(SourceBufferList, DOMEventTargetHelper)
   1.175 +
   1.176 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SourceBufferList)
   1.177 +NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
   1.178 +
   1.179 +} // namespace dom
   1.180 +
   1.181 +} // namespace mozilla

mercurial