content/media/mediasource/MediaSource.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

     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_MediaSource_h_
     8 #define mozilla_dom_MediaSource_h_
    10 #include "MediaSourceDecoder.h"
    11 #include "js/RootingAPI.h"
    12 #include "mozilla/Assertions.h"
    13 #include "mozilla/Attributes.h"
    14 #include "mozilla/DOMEventTargetHelper.h"
    15 #include "mozilla/dom/MediaSourceBinding.h"
    16 #include "nsAutoPtr.h"
    17 #include "nsCOMPtr.h"
    18 #include "nsCycleCollectionNoteChild.h"
    19 #include "nsCycleCollectionParticipant.h"
    20 #include "nsID.h"
    21 #include "nsISupports.h"
    22 #include "nscore.h"
    24 struct JSContext;
    25 class JSObject;
    26 class nsPIDOMWindow;
    28 namespace mozilla {
    30 class ErrorResult;
    31 template <typename T> class AsyncEventRunner;
    33 namespace dom {
    35 class GlobalObject;
    36 class SourceBuffer;
    37 class SourceBufferList;
    38 template <typename T> class Optional;
    40 #define MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID \
    41   { 0x3839d699, 0x22c5, 0x439f, \
    42   { 0x94, 0xca, 0x0e, 0x0b, 0x26, 0xf9, 0xca, 0xbf } }
    44 class MediaSource MOZ_FINAL : public DOMEventTargetHelper
    45 {
    46 public:
    47   /** WebIDL Methods. */
    48   static already_AddRefed<MediaSource>
    49   Constructor(const GlobalObject& aGlobal,
    50               ErrorResult& aRv);
    52   SourceBufferList* SourceBuffers();
    53   SourceBufferList* ActiveSourceBuffers();
    54   MediaSourceReadyState ReadyState();
    56   double Duration();
    57   void SetDuration(double aDuration, ErrorResult& aRv);
    59   already_AddRefed<SourceBuffer> AddSourceBuffer(const nsAString& aType, ErrorResult& aRv);
    60   void RemoveSourceBuffer(SourceBuffer& aSourceBuffer, ErrorResult& aRv);
    62   void EndOfStream(const Optional<MediaSourceEndOfStreamError>& aError, ErrorResult& aRv);
    63   static bool IsTypeSupported(const GlobalObject&, const nsAString& aType);
    64   /** End WebIDL Methods. */
    66   NS_DECL_ISUPPORTS_INHERITED
    67   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaSource, DOMEventTargetHelper)
    68   NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
    70   nsPIDOMWindow* GetParentObject() const;
    72   JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    74   // Attach this MediaSource to Decoder aDecoder.  Returns false if already attached.
    75   bool Attach(MediaSourceDecoder* aDecoder);
    76   void Detach();
    78   // Set mReadyState to aState and fire the required events at the MediaSource.
    79   void SetReadyState(MediaSourceReadyState aState);
    81  // Used by SourceBuffer to call CreateSubDecoder.
    82   MediaSourceDecoder* GetDecoder()
    83   {
    84     return mDecoder;
    85   }
    87   // Called by SourceBuffers to notify this MediaSource that data has
    88   // been evicted from the buffered data. The start and end times
    89   // that were evicted are provided.
    90   void NotifyEvicted(double aStart, double aEnd);
    92 private:
    93   explicit MediaSource(nsPIDOMWindow* aWindow);
    95   friend class AsyncEventRunner<MediaSource>;
    96   void DispatchSimpleEvent(const char* aName);
    97   void QueueAsyncSimpleEvent(const char* aName);
    99   void DurationChange(double aNewDuration, ErrorResult& aRv);
   101   double mDuration;
   103   nsRefPtr<SourceBufferList> mSourceBuffers;
   104   nsRefPtr<SourceBufferList> mActiveSourceBuffers;
   106   nsRefPtr<MediaSourceDecoder> mDecoder;
   108   MediaSourceReadyState mReadyState;
   109 };
   111 NS_DEFINE_STATIC_IID_ACCESSOR(MediaSource, MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
   113 } // namespace dom
   115 } // namespace mozilla
   116 #endif /* mozilla_dom_MediaSource_h_ */

mercurial