content/media/mediasource/SourceBuffer.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial