ResourceStream.h (1243B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef RESOURCESTREAM_H_ 6 #define RESOURCESTREAM_H_ 7 8 #include "ByteStream.h" 9 #include "MediaResource.h" 10 11 namespace mozilla { 12 13 DDLoggedTypeDeclNameAndBase(ResourceStream, ByteStream); 14 15 class ResourceStream : public ByteStream, 16 public DecoderDoctorLifeLogger<ResourceStream> { 17 public: 18 explicit ResourceStream(mozilla::MediaResource* aResource); 19 20 virtual nsresult ReadAt(int64_t offset, void* aBuffer, size_t aCount, 21 size_t* aBytesRead) override; 22 virtual nsresult CachedReadAt(int64_t aOffset, void* aBuffer, size_t aCount, 23 size_t* aBytesRead) override; 24 virtual bool Length(int64_t* size) override; 25 26 void Pin() { 27 mResource.GetResource()->Pin(); 28 ++mPinCount; 29 } 30 31 void Unpin() { 32 mResource.GetResource()->Unpin(); 33 MOZ_ASSERT(mPinCount); 34 --mPinCount; 35 } 36 37 protected: 38 virtual ~ResourceStream(); 39 40 private: 41 mozilla::MediaResourceIndex mResource; 42 uint32_t mPinCount; 43 }; 44 45 } // namespace mozilla 46 47 #endif // RESOURCESTREAM_H_