LCOV - code coverage report
Current view: top level - dom/media/mediasource - SourceBufferResource.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 54 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : #ifndef MOZILLA_SOURCEBUFFERRESOURCE_H_
       8             : #define MOZILLA_SOURCEBUFFERRESOURCE_H_
       9             : 
      10             : #include "MediaCache.h"
      11             : #include "MediaResource.h"
      12             : #include "ResourceQueue.h"
      13             : #include "mozilla/Attributes.h"
      14             : #include "nsCOMPtr.h"
      15             : #include "nsError.h"
      16             : #include "nsIPrincipal.h"
      17             : #include "nsTArray.h"
      18             : #include "nscore.h"
      19             : #include "mozilla/Logging.h"
      20             : 
      21             : #define UNIMPLEMENTED() { /* Logging this is too spammy to do by default */ }
      22             : 
      23             : class nsIStreamListener;
      24             : 
      25             : namespace mozilla {
      26             : 
      27             : class MediaDecoder;
      28             : class MediaByteBuffer;
      29             : class TaskQueue;
      30             : 
      31             : namespace dom {
      32             : 
      33             : class SourceBuffer;
      34             : 
      35             : } // namespace dom
      36             : 
      37             : // SourceBufferResource is not thread safe.
      38             : class SourceBufferResource final : public MediaResource
      39             : {
      40             : public:
      41             :   SourceBufferResource();
      42             :   nsresult Close() override;
      43           0 :   void Suspend(bool aCloseImmediately) override { UNIMPLEMENTED(); }
      44           0 :   void Resume() override { UNIMPLEMENTED(); }
      45           0 :   already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override
      46             :   {
      47             :     UNIMPLEMENTED();
      48           0 :     return nullptr;
      49             :   }
      50           0 :   void SetReadMode(MediaCacheStream::ReadMode aMode) override
      51             :   {
      52             :     UNIMPLEMENTED();
      53           0 :   }
      54           0 :   void SetPlaybackRate(uint32_t aBytesPerSecond) override { UNIMPLEMENTED(); }
      55             :   nsresult ReadAt(int64_t aOffset,
      56             :                   char* aBuffer,
      57             :                   uint32_t aCount,
      58             :                   uint32_t* aBytes) override;
      59             :   // Memory-based and no locks, caching discouraged.
      60           0 :   bool ShouldCacheReads() override { return false; }
      61           0 :   int64_t Tell() override { return mOffset; }
      62           0 :   void Pin() override { UNIMPLEMENTED(); }
      63           0 :   void Unpin() override { UNIMPLEMENTED(); }
      64           0 :   double GetDownloadRate(bool* aIsReliable) override
      65             :   {
      66             :     UNIMPLEMENTED();
      67           0 :     *aIsReliable = false;
      68           0 :     return 0;
      69             :   }
      70           0 :   int64_t GetLength() override { return mInputBuffer.GetLength(); }
      71           0 :   int64_t GetNextCachedData(int64_t aOffset) override
      72             :   {
      73           0 :     MOZ_ASSERT(OnTaskQueue());
      74           0 :     MOZ_ASSERT(aOffset >= 0);
      75           0 :     if (uint64_t(aOffset) < mInputBuffer.GetOffset()) {
      76           0 :       return mInputBuffer.GetOffset();
      77           0 :     } else if (aOffset == GetLength()) {
      78           0 :       return -1;
      79             :     }
      80           0 :     return aOffset;
      81             :   }
      82           0 :   int64_t GetCachedDataEnd(int64_t aOffset) override
      83             :   {
      84           0 :     MOZ_ASSERT(OnTaskQueue());
      85           0 :     MOZ_ASSERT(aOffset >= 0);
      86           0 :     if (uint64_t(aOffset) < mInputBuffer.GetOffset() ||
      87           0 :         aOffset >= GetLength()) {
      88             :       // aOffset is outside of the buffered range.
      89           0 :       return aOffset;
      90             :     }
      91           0 :     return GetLength();
      92             :   }
      93           0 :   bool IsDataCachedToEndOfResource(int64_t aOffset) override { return false; }
      94           0 :   bool IsSuspendedByCache() override
      95             :   {
      96             :     UNIMPLEMENTED();
      97           0 :     return false;
      98             :   }
      99           0 :   bool IsSuspended() override
     100             :   {
     101             :     UNIMPLEMENTED();
     102           0 :     return false;
     103             :   }
     104             :   nsresult ReadFromCache(char* aBuffer,
     105             :                          int64_t aOffset,
     106             :                          uint32_t aCount) override;
     107           0 :   bool IsTransportSeekable() override
     108             :   {
     109             :     UNIMPLEMENTED();
     110           0 :     return true;
     111             :   }
     112           0 :   nsresult Open(nsIStreamListener** aStreamListener) override
     113             :   {
     114             :     UNIMPLEMENTED();
     115           0 :     return NS_ERROR_FAILURE;
     116             :   }
     117             : 
     118           0 :   nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override
     119             :   {
     120           0 :     MOZ_ASSERT(OnTaskQueue());
     121           0 :     if (mInputBuffer.GetLength()) {
     122           0 :       aRanges += MediaByteRange(mInputBuffer.GetOffset(),
     123           0 :                                 mInputBuffer.GetLength());
     124             :     }
     125           0 :     return NS_OK;
     126             :   }
     127             : 
     128           0 :   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
     129             :   {
     130           0 :     MOZ_ASSERT(OnTaskQueue());
     131             : 
     132           0 :     size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
     133           0 :     size += mInputBuffer.SizeOfExcludingThis(aMallocSizeOf);
     134             : 
     135           0 :     return size;
     136             :   }
     137             : 
     138           0 :   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
     139             :   {
     140           0 :     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
     141             :   }
     142             : 
     143           0 :   bool IsExpectingMoreData() override
     144             :   {
     145           0 :     return false;
     146             :   }
     147             : 
     148             :   // Used by SourceBuffer.
     149             :   void AppendData(MediaByteBuffer* aData);
     150             :   void Ended();
     151             :   bool IsEnded()
     152             :   {
     153             :     MOZ_ASSERT(OnTaskQueue());
     154             :     return mEnded;
     155             :   }
     156             :   // Remove data from resource if it holds more than the threshold reduced by
     157             :   // the given number of bytes. Returns amount evicted.
     158             :   uint32_t EvictData(uint64_t aPlaybackOffset, int64_t aThresholdReduct,
     159             :                      ErrorResult& aRv);
     160             : 
     161             :   // Remove data from resource before the given offset.
     162             :   void EvictBefore(uint64_t aOffset, ErrorResult& aRv);
     163             : 
     164             :   // Remove all data from the resource
     165             :   uint32_t EvictAll();
     166             : 
     167             :   // Returns the amount of data currently retained by this resource.
     168             :   int64_t GetSize()
     169             :   {
     170             :     MOZ_ASSERT(OnTaskQueue());
     171             :     return mInputBuffer.GetLength() - mInputBuffer.GetOffset();
     172             :   }
     173             : 
     174             : #if defined(DEBUG)
     175             :   void Dump(const char* aPath)
     176             :   {
     177             :     mInputBuffer.Dump(aPath);
     178             :   }
     179             : #endif
     180             : 
     181             : private:
     182             :   virtual ~SourceBufferResource();
     183             :   nsresult ReadAtInternal(int64_t aOffset,
     184             :                           char* aBuffer,
     185             :                           uint32_t aCount,
     186             :                           uint32_t* aBytes);
     187             : 
     188             : #if defined(DEBUG)
     189             :   const RefPtr<TaskQueue> mTaskQueue;
     190             :   // TaskQueue methods and objects.
     191             :   AbstractThread* GetTaskQueue() const;
     192             :   bool OnTaskQueue() const;
     193             : #endif
     194             : 
     195             :   // The buffer holding resource data.
     196             :   ResourceQueue mInputBuffer;
     197             : 
     198             :   uint64_t mOffset;
     199             :   bool mClosed;
     200             :   bool mEnded;
     201             : };
     202             : 
     203             : } // namespace mozilla
     204             : 
     205             : #undef UNIMPLEMENTED
     206             : 
     207             : #endif /* MOZILLA_SOURCEBUFFERRESOURCE_H_ */

Generated by: LCOV version 1.13