1 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
6 #ifndef mozilla_dom_media_CloneableWithRangeMediaResource_h
7 #define mozilla_dom_media_CloneableWithRangeMediaResource_h
9 #include "BaseMediaResource.h"
10 #include "nsICloneableInputStream.h"
14 class CloneableWithRangeMediaResource
: public BaseMediaResource
{
16 CloneableWithRangeMediaResource(MediaResourceCallback
* aCallback
,
17 nsIChannel
* aChannel
, nsIURI
* aURI
,
18 nsIInputStream
* aStream
, uint64_t aSize
)
19 : BaseMediaResource(aCallback
, aChannel
, aURI
),
20 mStream(do_QueryInterface(aStream
)),
26 ~CloneableWithRangeMediaResource() = default;
29 nsresult
Open(nsIStreamListener
** aStreamListener
) override
;
30 RefPtr
<GenericPromise
> Close() override
;
31 void Suspend(bool aCloseImmediately
) override
{}
32 void Resume() override
{}
33 already_AddRefed
<nsIPrincipal
> GetCurrentPrincipal() override
;
34 bool HadCrossOriginRedirects() override
;
35 nsresult
ReadFromCache(char* aBuffer
, int64_t aOffset
,
36 uint32_t aCount
) override
;
38 // These methods are called off the main thread.
41 void SetReadMode(MediaCacheStream::ReadMode aMode
) override
{}
42 void SetPlaybackRate(uint32_t aBytesPerSecond
) override
{}
43 nsresult
ReadAt(int64_t aOffset
, char* aBuffer
, uint32_t aCount
,
44 uint32_t* aBytes
) override
;
45 // (Probably) file-based, caching recommended.
46 bool ShouldCacheReads() override
{ return true; }
49 void Pin() override
{}
50 void Unpin() override
{}
52 double GetDownloadRate(bool* aIsReliable
) override
{
53 // The data's all already here
55 return 100 * 1024 * 1024; // arbitray, use 100MB/s
58 int64_t GetLength() override
{
63 int64_t GetNextCachedData(int64_t aOffset
) override
{
65 return (aOffset
< (int64_t)mSize
) ? aOffset
: -1;
68 int64_t GetCachedDataEnd(int64_t aOffset
) override
{
70 return std::max(aOffset
, (int64_t)mSize
);
73 bool IsDataCachedToEndOfResource(int64_t aOffset
) override
{ return true; }
74 bool IsTransportSeekable() override
{ return true; }
76 nsresult
GetCachedRanges(MediaByteRangeSet
& aRanges
) override
;
78 size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
) const override
{
79 return BaseMediaResource::SizeOfExcludingThis(aMallocSizeOf
);
82 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const override
{
83 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf
);
87 void MaybeInitialize();
89 // Input stream for the media data. This can be used from any
91 nsCOMPtr
<nsICloneableInputStreamWithRange
> mStream
;
99 } // namespace mozilla
101 #endif // mozilla_dom_media_CloneableWithRangeMediaResource_h