Commit caaa2804 authored by Gerald Squelart's avatar Gerald Squelart
Browse files

Bug 1369322 - MediaResource::ShouldCacheReads to indicate usefulness of caching - r=cpearce

This hint will inform readers if caching is discouraged (e.g., for
SourceBufferResource) or recommmended (e.g., for MediaCache-backed
ChannelMediaResource).

MozReview-Commit-ID: 7hopNS0s5tE

--HG--
extra : rebase_source : 681646cc904229e8513adb148baa085254508049
parent 22160c03
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -68,6 +68,9 @@ private:
    mOffset = aOffset + *aBytes;
    mOffset = aOffset + *aBytes;
    return NS_OK;
    return NS_OK;
  }
  }
  // Memory-based and no locks, caching discouraged.
  bool ShouldCacheReads() override { return false; }

  int64_t Tell() override { return mOffset; }
  int64_t Tell() override { return mOffset; }


  void Pin() override {}
  void Pin() override {}
+2 −0
Original line number Original line Diff line number Diff line
@@ -1177,6 +1177,8 @@ public:
  void     SetPlaybackRate(uint32_t aBytesPerSecond) override {}
  void     SetPlaybackRate(uint32_t aBytesPerSecond) override {}
  nsresult ReadAt(int64_t aOffset, char* aBuffer,
  nsresult ReadAt(int64_t aOffset, char* aBuffer,
                  uint32_t aCount, uint32_t* aBytes) override;
                  uint32_t aCount, uint32_t* aBytes) override;
  // (Probably) file-based, caching recommended.
  bool ShouldCacheReads() override { return true; }
  already_AddRefed<MediaByteBuffer> MediaReadAt(int64_t aOffset, uint32_t aCount) override;
  already_AddRefed<MediaByteBuffer> MediaReadAt(int64_t aOffset, uint32_t aCount) override;
  int64_t  Tell() override;
  int64_t  Tell() override;


+7 −0
Original line number Original line Diff line number Diff line
@@ -201,6 +201,11 @@ public:
  // results and requirements are the same as per the Read method.
  // results and requirements are the same as per the Read method.
  virtual nsresult ReadAt(int64_t aOffset, char* aBuffer,
  virtual nsresult ReadAt(int64_t aOffset, char* aBuffer,
                          uint32_t aCount, uint32_t* aBytes) = 0;
                          uint32_t aCount, uint32_t* aBytes) = 0;
  // Indicate whether caching data in advance of reads is worth it.
  // E.g. Caching lockless and memory-based MediaResource subclasses would be a
  // waste, but caching lock/IO-bound resources means reducing the impact of
  // each read.
  virtual bool ShouldCacheReads() = 0;
  // This method returns nullptr if anything fails.
  // This method returns nullptr if anything fails.
  // Otherwise, it returns an owned buffer.
  // Otherwise, it returns an owned buffer.
  // MediaReadAt may return fewer bytes than requested if end of stream is
  // MediaReadAt may return fewer bytes than requested if end of stream is
@@ -578,6 +583,8 @@ public:
  void     SetPlaybackRate(uint32_t aBytesPerSecond) override;
  void     SetPlaybackRate(uint32_t aBytesPerSecond) override;
  nsresult ReadAt(int64_t offset, char* aBuffer,
  nsresult ReadAt(int64_t offset, char* aBuffer,
                  uint32_t aCount, uint32_t* aBytes) override;
                  uint32_t aCount, uint32_t* aBytes) override;
  // Data stored in IO&lock-encumbered MediaCacheStream, caching recommended.
  bool ShouldCacheReads() override { return true; }
  already_AddRefed<MediaByteBuffer> MediaReadAt(int64_t aOffset, uint32_t aCount) override;
  already_AddRefed<MediaByteBuffer> MediaReadAt(int64_t aOffset, uint32_t aCount) override;
  int64_t Tell() override;
  int64_t Tell() override;


+2 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,8 @@ public:
  void SetPlaybackRate(uint32_t aBytesPerSecond) override {}
  void SetPlaybackRate(uint32_t aBytesPerSecond) override {}
  nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount,
  nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount,
                  uint32_t* aBytes) override;
                  uint32_t* aBytes) override;
  // Data stored in file, caching recommended.
  bool ShouldCacheReads() override { return true; }
  int64_t Tell() override { return 0; }
  int64_t Tell() override { return 0; }
  void Pin() override {}
  void Pin() override {}
  void Unpin() override {}
  void Unpin() override {}
+1 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ public:
  void SetReadMode(MediaCacheStream::ReadMode aMode) override { UNIMPLEMENTED(); }
  void SetReadMode(MediaCacheStream::ReadMode aMode) override { UNIMPLEMENTED(); }
  void SetPlaybackRate(uint32_t aBytesPerSecond) override  { UNIMPLEMENTED(); }
  void SetPlaybackRate(uint32_t aBytesPerSecond) override  { UNIMPLEMENTED(); }
  nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
  nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
  bool ShouldCacheReads() override { UNIMPLEMENTED(); return false; }
  int64_t Tell() override { UNIMPLEMENTED(); return -1; }
  int64_t Tell() override { UNIMPLEMENTED(); return -1; }
  void Pin() override { UNIMPLEMENTED(); }
  void Pin() override { UNIMPLEMENTED(); }
  void Unpin() override { UNIMPLEMENTED(); }
  void Unpin() override { UNIMPLEMENTED(); }
Loading