2013-09-27 09:22:37 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_SOURCEBUFFERRESOURCE_H_
|
|
|
|
#define MOZILLA_SOURCEBUFFERRESOURCE_H_
|
|
|
|
|
2017-08-15 07:13:00 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2013-09-27 09:22:37 +04:00
|
|
|
#include "MediaResource.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2017-08-15 07:13:00 +03:00
|
|
|
#include "ResourceQueue.h"
|
2014-08-22 06:14:36 +04:00
|
|
|
|
2015-01-15 20:58:48 +03:00
|
|
|
#define UNIMPLEMENTED() { /* Logging this is too spammy to do by default */ }
|
2013-09-27 09:22:37 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-06-15 07:37:13 +03:00
|
|
|
class MediaByteBuffer;
|
2017-05-31 12:08:06 +03:00
|
|
|
class TaskQueue;
|
2013-09-27 09:22:37 +04:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class SourceBuffer;
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2017-05-31 12:08:06 +03:00
|
|
|
// SourceBufferResource is not thread safe.
|
2015-03-21 19:28:04 +03:00
|
|
|
class SourceBufferResource final : public MediaResource
|
2013-09-27 09:22:37 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-26 16:39:16 +03:00
|
|
|
SourceBufferResource();
|
2017-08-07 13:09:56 +03:00
|
|
|
nsresult Close();
|
2017-05-31 11:45:51 +03:00
|
|
|
already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsresult ReadAt(int64_t aOffset,
|
|
|
|
char* aBuffer,
|
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t* aBytes) override;
|
2017-06-02 05:27:17 +03:00
|
|
|
// Memory-based and no locks, caching discouraged.
|
|
|
|
bool ShouldCacheReads() override { return false; }
|
2016-01-18 06:46:10 +03:00
|
|
|
int64_t Tell() override { return mOffset; }
|
|
|
|
void Pin() override { UNIMPLEMENTED(); }
|
|
|
|
void Unpin() override { UNIMPLEMENTED(); }
|
|
|
|
int64_t GetLength() override { return mInputBuffer.GetLength(); }
|
2017-05-31 11:45:51 +03:00
|
|
|
int64_t GetNextCachedData(int64_t aOffset) override
|
|
|
|
{
|
2017-05-31 12:08:06 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2014-08-25 10:05:48 +04:00
|
|
|
MOZ_ASSERT(aOffset >= 0);
|
|
|
|
if (uint64_t(aOffset) < mInputBuffer.GetOffset()) {
|
|
|
|
return mInputBuffer.GetOffset();
|
|
|
|
} else if (aOffset == GetLength()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return aOffset;
|
|
|
|
}
|
2017-05-31 11:45:51 +03:00
|
|
|
int64_t GetCachedDataEnd(int64_t aOffset) override
|
|
|
|
{
|
2017-05-29 05:51:08 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
|
|
|
MOZ_ASSERT(aOffset >= 0);
|
|
|
|
if (uint64_t(aOffset) < mInputBuffer.GetOffset() ||
|
|
|
|
aOffset >= GetLength()) {
|
|
|
|
// aOffset is outside of the buffered range.
|
|
|
|
return aOffset;
|
|
|
|
}
|
|
|
|
return GetLength();
|
2017-05-31 11:45:51 +03:00
|
|
|
}
|
2016-01-18 06:46:10 +03:00
|
|
|
bool IsDataCachedToEndOfResource(int64_t aOffset) override { return false; }
|
2017-05-31 11:45:51 +03:00
|
|
|
nsresult ReadFromCache(char* aBuffer,
|
|
|
|
int64_t aOffset,
|
|
|
|
uint32_t aCount) override;
|
2016-01-18 06:46:10 +03:00
|
|
|
|
|
|
|
nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override
|
2013-09-27 09:22:37 +04:00
|
|
|
{
|
2017-05-31 12:08:06 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2014-07-04 12:31:20 +04:00
|
|
|
if (mInputBuffer.GetLength()) {
|
2015-11-24 12:16:52 +03:00
|
|
|
aRanges += MediaByteRange(mInputBuffer.GetOffset(),
|
|
|
|
mInputBuffer.GetLength());
|
2014-07-04 12:31:20 +04:00
|
|
|
}
|
2013-09-27 09:22:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:46:10 +03:00
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
|
2014-03-06 01:31:04 +04:00
|
|
|
{
|
2017-05-31 12:08:06 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2014-03-06 01:31:04 +04:00
|
|
|
|
|
|
|
size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
size += mInputBuffer.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:46:10 +03:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
|
2014-03-06 01:31:04 +04:00
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2015-01-27 10:25:44 +03:00
|
|
|
// Used by SourceBuffer.
|
2015-06-15 07:37:13 +03:00
|
|
|
void AppendData(MediaByteBuffer* aData);
|
2013-09-27 09:22:37 +04:00
|
|
|
void Ended();
|
2015-02-02 03:41:43 +03:00
|
|
|
bool IsEnded()
|
|
|
|
{
|
2017-05-31 12:08:06 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2015-02-02 03:41:43 +03:00
|
|
|
return mEnded;
|
|
|
|
}
|
2016-03-19 00:26:56 +03:00
|
|
|
// Remove data from resource if it holds more than the threshold reduced by
|
|
|
|
// the given number of bytes. Returns amount evicted.
|
|
|
|
uint32_t EvictData(uint64_t aPlaybackOffset, int64_t aThresholdReduct,
|
2015-05-25 14:50:15 +03:00
|
|
|
ErrorResult& aRv);
|
2014-02-28 04:54:48 +04:00
|
|
|
|
|
|
|
// Remove data from resource before the given offset.
|
2015-05-25 14:50:15 +03:00
|
|
|
void EvictBefore(uint64_t aOffset, ErrorResult& aRv);
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2015-01-16 06:14:56 +03:00
|
|
|
// Remove all data from the resource
|
|
|
|
uint32_t EvictAll();
|
|
|
|
|
2014-09-09 13:12:00 +04:00
|
|
|
// Returns the amount of data currently retained by this resource.
|
2017-05-31 11:45:51 +03:00
|
|
|
int64_t GetSize()
|
|
|
|
{
|
2017-05-31 12:08:06 +03:00
|
|
|
MOZ_ASSERT(OnTaskQueue());
|
2014-09-09 13:12:00 +04:00
|
|
|
return mInputBuffer.GetLength() - mInputBuffer.GetOffset();
|
|
|
|
}
|
|
|
|
|
2014-09-12 02:47:06 +04:00
|
|
|
#if defined(DEBUG)
|
2017-05-31 11:45:51 +03:00
|
|
|
void Dump(const char* aPath)
|
|
|
|
{
|
2014-09-12 02:47:06 +04:00
|
|
|
mInputBuffer.Dump(aPath);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
private:
|
2015-07-15 03:15:30 +03:00
|
|
|
virtual ~SourceBufferResource();
|
2017-05-31 11:45:51 +03:00
|
|
|
nsresult ReadAtInternal(int64_t aOffset,
|
|
|
|
char* aBuffer,
|
|
|
|
uint32_t aCount,
|
2017-05-31 12:08:06 +03:00
|
|
|
uint32_t* aBytes);
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2017-05-31 12:08:06 +03:00
|
|
|
#if defined(DEBUG)
|
|
|
|
const RefPtr<TaskQueue> mTaskQueue;
|
|
|
|
// TaskQueue methods and objects.
|
|
|
|
AbstractThread* GetTaskQueue() const;
|
|
|
|
bool OnTaskQueue() const;
|
|
|
|
#endif
|
2013-09-27 09:22:37 +04:00
|
|
|
|
2014-08-20 12:14:00 +04:00
|
|
|
// The buffer holding resource data.
|
2014-02-28 04:54:48 +04:00
|
|
|
ResourceQueue mInputBuffer;
|
|
|
|
|
|
|
|
uint64_t mOffset;
|
2013-09-27 09:22:37 +04:00
|
|
|
bool mClosed;
|
|
|
|
bool mEnded;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2014-08-22 06:14:36 +04:00
|
|
|
|
|
|
|
#undef UNIMPLEMENTED
|
|
|
|
|
2013-09-27 09:22:37 +04:00
|
|
|
#endif /* MOZILLA_SOURCEBUFFERRESOURCE_H_ */
|