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 "MediaResource.h"
9 #include "ByteStream.h"
10 #include "mozilla/RefPtr.h"
11 
12 namespace mozilla {
13 
14 DDLoggedTypeDeclNameAndBase(ResourceStream, ByteStream);
15 
16 class ResourceStream : public ByteStream,
17                        public DecoderDoctorLifeLogger<ResourceStream> {
18  public:
19   explicit ResourceStream(mozilla::MediaResource* aResource);
20 
21   virtual bool ReadAt(int64_t offset, void* aBuffer, size_t aCount,
22                       size_t* aBytesRead) override;
23   virtual bool CachedReadAt(int64_t aOffset, void* aBuffer, size_t aCount,
24                             size_t* aBytesRead) override;
25   virtual bool Length(int64_t* size) override;
26 
Pin()27   void Pin() {
28     mResource.GetResource()->Pin();
29     ++mPinCount;
30   }
31 
Unpin()32   void Unpin() {
33     mResource.GetResource()->Unpin();
34     MOZ_ASSERT(mPinCount);
35     --mPinCount;
36   }
37 
38  protected:
39   virtual ~ResourceStream();
40 
41  private:
42   mozilla::MediaResourceIndex mResource;
43   uint32_t mPinCount;
44 };
45 
46 }  // namespace mozilla
47 
48 #endif  // RESOURCESTREAM_H_
49