MediaSourceResource.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef MOZILLA_MEDIASOURCERESOURCE_H_
  6. #define MOZILLA_MEDIASOURCERESOURCE_H_
  7. #include "MediaResource.h"
  8. #include "mozilla/Monitor.h"
  9. #include "mozilla/Logging.h"
  10. extern mozilla::LogModule* GetMediaSourceLog();
  11. #define MSE_DEBUG(arg, ...) MOZ_LOG(GetMediaSourceLog(), mozilla::LogLevel::Debug, ("MediaSourceResource(%p:%s)::%s: " arg, this, mType.get(), __func__, ##__VA_ARGS__))
  12. #define UNIMPLEMENTED() MSE_DEBUG("UNIMPLEMENTED FUNCTION at %s:%d", __FILE__, __LINE__)
  13. namespace mozilla {
  14. class MediaSourceResource final : public MediaResource
  15. {
  16. public:
  17. explicit MediaSourceResource(nsIPrincipal* aPrincipal = nullptr)
  18. : mPrincipal(aPrincipal)
  19. , mMonitor("MediaSourceResource")
  20. , mEnded(false)
  21. {}
  22. nsresult Close() override { return NS_OK; }
  23. void Suspend(bool aCloseImmediately) override { UNIMPLEMENTED(); }
  24. void Resume() override { UNIMPLEMENTED(); }
  25. bool CanClone() override { UNIMPLEMENTED(); return false; }
  26. already_AddRefed<MediaResource> CloneData(MediaResourceCallback*) override { UNIMPLEMENTED(); return nullptr; }
  27. void SetReadMode(MediaCacheStream::ReadMode aMode) override { UNIMPLEMENTED(); }
  28. void SetPlaybackRate(uint32_t aBytesPerSecond) override { UNIMPLEMENTED(); }
  29. nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
  30. int64_t Tell() override { UNIMPLEMENTED(); return -1; }
  31. void Pin() override { UNIMPLEMENTED(); }
  32. void Unpin() override { UNIMPLEMENTED(); }
  33. double GetDownloadRate(bool* aIsReliable) override { UNIMPLEMENTED(); *aIsReliable = false; return 0; }
  34. int64_t GetLength() override { UNIMPLEMENTED(); return -1; }
  35. int64_t GetNextCachedData(int64_t aOffset) override { UNIMPLEMENTED(); return -1; }
  36. int64_t GetCachedDataEnd(int64_t aOffset) override { UNIMPLEMENTED(); return -1; }
  37. bool IsDataCachedToEndOfResource(int64_t aOffset) override { UNIMPLEMENTED(); return false; }
  38. bool IsSuspendedByCache() override { UNIMPLEMENTED(); return false; }
  39. bool IsSuspended() override { UNIMPLEMENTED(); return false; }
  40. nsresult ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
  41. nsresult Open(nsIStreamListener** aStreamListener) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
  42. already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override
  43. {
  44. return RefPtr<nsIPrincipal>(mPrincipal).forget();
  45. }
  46. nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override
  47. {
  48. UNIMPLEMENTED();
  49. aRanges += MediaByteRange(0, GetLength());
  50. return NS_OK;
  51. }
  52. bool IsTransportSeekable() override { return true; }
  53. const nsCString& GetContentType() const override { return mType; }
  54. bool IsLiveStream() override
  55. {
  56. MonitorAutoLock mon(mMonitor);
  57. return !mEnded;
  58. }
  59. void SetEnded(bool aEnded)
  60. {
  61. MonitorAutoLock mon(mMonitor);
  62. mEnded = aEnded;
  63. }
  64. bool IsExpectingMoreData() override
  65. {
  66. MonitorAutoLock mon(mMonitor);
  67. return !mEnded;
  68. }
  69. private:
  70. size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
  71. {
  72. size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
  73. size += mType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
  74. return size;
  75. }
  76. size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
  77. {
  78. return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
  79. }
  80. RefPtr<nsIPrincipal> mPrincipal;
  81. const nsCString mType;
  82. Monitor mMonitor;
  83. bool mEnded; // protected by mMonitor
  84. };
  85. } // namespace mozilla
  86. #undef MSE_DEBUG
  87. #undef UNIMPLEMENTED
  88. #endif /* MOZILLA_MEDIASOURCERESOURCE_H_ */