2013-09-27 05:22:37 +00: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_
|
|
|
|
|
|
|
|
#include "MediaCache.h"
|
|
|
|
#include "MediaResource.h"
|
2014-08-20 08:14:00 +00:00
|
|
|
#include "ResourceQueue.h"
|
2013-09-27 05:22:37 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/ReentrantMonitor.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2014-08-20 08:14:00 +00:00
|
|
|
#include "nsString.h"
|
2013-09-27 05:22:37 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nscore.h"
|
2014-08-22 02:14:36 +00:00
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
extern PRLogModuleInfo* GetMediaSourceLog();
|
|
|
|
extern PRLogModuleInfo* GetMediaSourceAPILog();
|
|
|
|
|
|
|
|
#define MSE_DEBUG(...) PR_LOG(GetMediaSourceLog(), PR_LOG_DEBUG, (__VA_ARGS__))
|
|
|
|
#else
|
|
|
|
#define MSE_DEBUG(...)
|
|
|
|
#endif
|
|
|
|
|
2014-08-25 06:05:48 +00:00
|
|
|
#define UNIMPLEMENTED() MSE_DEBUG("SourceBufferResource(%p): UNIMPLEMENTED FUNCTION at %s:%d", this, __FILE__, __LINE__)
|
2013-09-27 05:22:37 +00:00
|
|
|
|
|
|
|
class nsIStreamListener;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class MediaDecoder;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class SourceBuffer;
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
class SourceBufferResource MOZ_FINAL : public MediaResource
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 03:50:23 +00:00
|
|
|
explicit SourceBufferResource(const nsACString& aType);
|
2013-09-27 05:22:38 +00:00
|
|
|
virtual nsresult Close() MOZ_OVERRIDE;
|
2014-08-22 02:14:36 +00:00
|
|
|
virtual void Suspend(bool aCloseImmediately) MOZ_OVERRIDE { UNIMPLEMENTED(); }
|
|
|
|
virtual void Resume() MOZ_OVERRIDE { UNIMPLEMENTED(); }
|
2014-08-25 06:05:48 +00:00
|
|
|
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal() MOZ_OVERRIDE { UNIMPLEMENTED(); return nullptr; }
|
|
|
|
virtual already_AddRefed<MediaResource> CloneData(MediaDecoder* aDecoder) MOZ_OVERRIDE { UNIMPLEMENTED(); return nullptr; }
|
2014-08-22 02:14:36 +00:00
|
|
|
virtual void SetReadMode(MediaCacheStream::ReadMode aMode) MOZ_OVERRIDE { UNIMPLEMENTED(); }
|
|
|
|
virtual void SetPlaybackRate(uint32_t aBytesPerSecond) MOZ_OVERRIDE { UNIMPLEMENTED(); }
|
2013-09-27 05:22:38 +00:00
|
|
|
virtual nsresult Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult Seek(int32_t aWhence, int64_t aOffset) MOZ_OVERRIDE;
|
|
|
|
virtual int64_t Tell() MOZ_OVERRIDE { return mOffset; }
|
2014-08-22 02:14:36 +00:00
|
|
|
virtual void Pin() MOZ_OVERRIDE { UNIMPLEMENTED(); }
|
|
|
|
virtual void Unpin() MOZ_OVERRIDE { UNIMPLEMENTED(); }
|
|
|
|
virtual double GetDownloadRate(bool* aIsReliable) MOZ_OVERRIDE { UNIMPLEMENTED(); *aIsReliable = false; return 0; }
|
2014-02-28 00:54:48 +00:00
|
|
|
virtual int64_t GetLength() MOZ_OVERRIDE { return mInputBuffer.GetLength(); }
|
2014-08-25 06:05:48 +00:00
|
|
|
virtual int64_t GetNextCachedData(int64_t aOffset) MOZ_OVERRIDE {
|
2014-09-09 09:12:00 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
2014-08-25 06:05:48 +00:00
|
|
|
MOZ_ASSERT(aOffset >= 0);
|
|
|
|
if (uint64_t(aOffset) < mInputBuffer.GetOffset()) {
|
|
|
|
return mInputBuffer.GetOffset();
|
|
|
|
} else if (aOffset == GetLength()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return aOffset;
|
|
|
|
}
|
|
|
|
virtual int64_t GetCachedDataEnd(int64_t aOffset) MOZ_OVERRIDE { UNIMPLEMENTED(); return -1; }
|
|
|
|
virtual bool IsDataCachedToEndOfResource(int64_t aOffset) MOZ_OVERRIDE { return false; }
|
2014-08-22 02:14:36 +00:00
|
|
|
virtual bool IsSuspendedByCache() MOZ_OVERRIDE { UNIMPLEMENTED(); return false; }
|
|
|
|
virtual bool IsSuspended() MOZ_OVERRIDE { UNIMPLEMENTED(); return false; }
|
2013-09-27 05:22:38 +00:00
|
|
|
virtual nsresult ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount) MOZ_OVERRIDE;
|
2014-08-22 02:14:36 +00:00
|
|
|
virtual bool IsTransportSeekable() MOZ_OVERRIDE { UNIMPLEMENTED(); return true; }
|
|
|
|
virtual nsresult Open(nsIStreamListener** aStreamListener) MOZ_OVERRIDE { UNIMPLEMENTED(); return NS_ERROR_FAILURE; }
|
2013-09-27 05:22:38 +00:00
|
|
|
|
|
|
|
virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) MOZ_OVERRIDE
|
2013-09-27 05:22:37 +00:00
|
|
|
{
|
2014-09-09 09:12:00 +00:00
|
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
2014-07-04 08:31:20 +00:00
|
|
|
if (mInputBuffer.GetLength()) {
|
|
|
|
aRanges.AppendElement(MediaByteRange(mInputBuffer.GetOffset(),
|
|
|
|
mInputBuffer.GetLength()));
|
|
|
|
}
|
2013-09-27 05:22:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-09-27 05:22:38 +00:00
|
|
|
virtual const nsCString& GetContentType() const MOZ_OVERRIDE { return mType; }
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2014-03-05 21:31:04 +00:00
|
|
|
virtual size_t SizeOfExcludingThis(
|
|
|
|
MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
|
|
|
|
|
|
|
size_t size = MediaResource::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
size += mType.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
size += mInputBuffer.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual size_t SizeOfIncludingThis(
|
|
|
|
MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
// Used by SourceBuffer.
|
|
|
|
void AppendData(const uint8_t* aData, uint32_t aLength);
|
|
|
|
void Ended();
|
2014-02-28 00:54:48 +00:00
|
|
|
// Remove data from resource if it holds more than the threshold
|
2014-09-09 09:12:00 +00:00
|
|
|
// number of bytes. Returns amount evicted.
|
|
|
|
uint32_t EvictData(uint32_t aThreshold);
|
2014-02-28 00:54:48 +00:00
|
|
|
|
|
|
|
// Remove data from resource before the given offset.
|
|
|
|
void EvictBefore(uint64_t aOffset);
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2014-09-09 09:12:00 +00:00
|
|
|
// Returns the amount of data currently retained by this resource.
|
|
|
|
int64_t GetSize() {
|
|
|
|
ReentrantMonitorAutoEnter mon(mMonitor);
|
|
|
|
return mInputBuffer.GetLength() - mInputBuffer.GetOffset();
|
|
|
|
}
|
|
|
|
|
2014-09-11 22:47:06 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Dump(const char* aPath) {
|
|
|
|
mInputBuffer.Dump(aPath);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
private:
|
2014-08-20 08:14:00 +00:00
|
|
|
~SourceBufferResource();
|
2014-08-13 13:41:00 +00:00
|
|
|
nsresult SeekInternal(int64_t aOffset);
|
|
|
|
|
2014-05-08 02:22:27 +00:00
|
|
|
const nsCString mType;
|
2013-09-27 05:22:37 +00:00
|
|
|
|
|
|
|
// Provides synchronization between SourceBuffers and InputAdapters.
|
2013-09-27 05:22:38 +00:00
|
|
|
// Protects all of the member variables below. Read() will await a
|
|
|
|
// Notify() (from Seek, AppendData, Ended, or Close) when insufficient
|
|
|
|
// data is available in mData.
|
2014-03-05 21:31:04 +00:00
|
|
|
mutable ReentrantMonitor mMonitor;
|
2013-09-27 05:22:37 +00:00
|
|
|
|
2014-08-20 08:14:00 +00:00
|
|
|
// The buffer holding resource data.
|
2014-02-28 00:54:48 +00:00
|
|
|
ResourceQueue mInputBuffer;
|
|
|
|
|
|
|
|
uint64_t mOffset;
|
2013-09-27 05:22:37 +00:00
|
|
|
bool mClosed;
|
|
|
|
bool mEnded;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2014-08-22 02:14:36 +00:00
|
|
|
|
|
|
|
#undef UNIMPLEMENTED
|
|
|
|
|
2013-09-27 05:22:37 +00:00
|
|
|
#endif /* MOZILLA_SOURCEBUFFERRESOURCE_H_ */
|