2012-11-23 01:44:20 +04:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#if !defined(BufferMediaResource_h_)
|
|
|
|
# define BufferMediaResource_h_
|
|
|
|
|
|
|
|
# include "MediaResource.h"
|
|
|
|
# include "nsISeekableStream.h"
|
|
|
|
# include <algorithm>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
DDLoggedTypeDeclNameAndBase(BufferMediaResource, MediaResource);
|
|
|
|
|
2012-11-23 01:44:20 +04:00
|
|
|
// A simple MediaResource based on an in memory buffer. This class accepts
|
|
|
|
// the address and the length of the buffer, and simulates a read/seek API
|
|
|
|
// on top of it. The Read implementation involves copying memory, which is
|
|
|
|
// unfortunate, but the MediaResource interface mandates that.
|
Bug 1407810 - Use DDLogger in media stack - r=jwwang
Mostly-mechanical additions:
- Log constructions&destructions, usually by just inheriting from
DecoderDoctorLifeLogger, otherwise with explicit log commands (for internal
classes for which DecoderDoctorTraits can't be specialized),
- Log links between most objects, e.g.: Media element -> decoder -> state
machine -> reader -> demuxer -> resource, etc.
And logging some important properties and events (JS events, duration change,
frames being decoded, etc.)
More will be added later on, from just converting MOZ_LOGs, and as needed.
MozReview-Commit-ID: KgNhHSz35t0
--HG--
extra : rebase_source : dd7206e350e32671adc6f3b9e54ebf777251de2c
2017-10-10 09:55:27 +03:00
|
|
|
class BufferMediaResource
|
|
|
|
: public MediaResource,
|
|
|
|
public DecoderDoctorLifeLogger<BufferMediaResource> {
|
2012-11-23 01:44:20 +04:00
|
|
|
public:
|
2017-08-24 12:04:59 +03:00
|
|
|
BufferMediaResource(const uint8_t* aBuffer, uint32_t aLength)
|
2017-06-26 16:39:16 +03:00
|
|
|
: mBuffer(aBuffer), mLength(aLength) {}
|
2012-11-23 01:44:20 +04:00
|
|
|
|
2014-07-15 19:37:45 +04:00
|
|
|
protected:
|
2012-11-23 01:44:20 +04:00
|
|
|
virtual ~BufferMediaResource() {}
|
|
|
|
|
2014-07-15 19:37:45 +04:00
|
|
|
private:
|
2012-11-23 01:44:20 +04:00
|
|
|
// These methods are called off the main thread.
|
2016-01-18 06:50:29 +03:00
|
|
|
nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount,
|
|
|
|
uint32_t* aBytes) override {
|
2015-08-13 04:15:48 +03:00
|
|
|
if (aOffset < 0 || aOffset > mLength) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-11-23 01:44:20 +04:00
|
|
|
}
|
2015-08-13 04:15:48 +03:00
|
|
|
*aBytes = std::min(mLength - static_cast<uint32_t>(aOffset), aCount);
|
|
|
|
memcpy(aBuffer, mBuffer + aOffset, *aBytes);
|
2012-11-23 01:44:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-06-02 05:27:17 +03:00
|
|
|
// Memory-based and no locks, caching discouraged.
|
|
|
|
bool ShouldCacheReads() override { return false; }
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
void Pin() override {}
|
|
|
|
void Unpin() override {}
|
|
|
|
int64_t GetLength() override { return mLength; }
|
|
|
|
int64_t GetNextCachedData(int64_t aOffset) override { return aOffset; }
|
2017-06-01 02:30:14 +03:00
|
|
|
int64_t GetCachedDataEnd(int64_t aOffset) override {
|
|
|
|
return std::max(aOffset, int64_t(mLength));
|
|
|
|
}
|
2016-01-18 06:50:29 +03:00
|
|
|
bool IsDataCachedToEndOfResource(int64_t aOffset) override { return true; }
|
|
|
|
nsresult ReadFromCache(char* aBuffer, int64_t aOffset,
|
|
|
|
uint32_t aCount) override {
|
2012-11-23 01:44:20 +04:00
|
|
|
if (aOffset < 0) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bytes = std::min(mLength - static_cast<uint32_t>(aOffset), aCount);
|
|
|
|
memcpy(aBuffer, mBuffer + aOffset, bytes);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override {
|
2015-11-24 12:37:21 +03:00
|
|
|
aRanges += MediaByteRange(0, int64_t(mLength));
|
2012-11-23 01:44:20 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const uint8_t* mBuffer;
|
|
|
|
uint32_t mLength;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2012-11-23 01:44:20 +04:00
|
|
|
|
|
|
|
#endif
|